• Hi,
    I saw your plug-in and then this article (https://ottopress.com/2017/12/) and wanted to do it like you suggests with my own custom plug-in. However I’m at a loss, during the step 4.

    You are saying to migrate the code from the PHP Code Widget with the code my plug-in. I haven’t used the plug-in before, and therefor I’m unsure as to which part of the plug-in code I need.

    – JoPed

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    See this in the plugin in step 4?

    
    function widget( $args, $instance ) {
        extract($args);
        echo $before_widget;
     
        echo '<h2 class="widget-title">Ottopress Widget</h2>';
        echo "<div>Here's my custom stuff.</div>";
         
        echo $after_widget;
    }
    

    See the two “echo” lines in the middle that are set apart from the rest?

    That is the bit of code that echo’s out something. Replace that with the code from your widget.

    Thread Starter Jonas Bj?rn Pedersen

    (@joped)

    Thank you for the answer, however I’m still not quite sure which of the code I should use. Is it the only part, to use? This is the code between the lines of echo $before_widget; and echo after_widget;. In the custom html widget I still can’t use the <?php ?> tags. Sorry for all the questions, but I’m still new to this.

    if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
    			ob_start();
    			eval('?>'.$text);
    			$text = ob_get_contents();
    			ob_end_clean();
    			?>
    			<div class="execphpwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
    		<?php

    EDIT: Figured out how to use the php tags (<php> and </php>, but the widget reads it like normal text). Can you help with this?

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    No, that’s the code from the PHP Code Widget plugin. That’s not what I meant at all. You don’t want that code for anything.

    The PHP Code Widget lets you put a widget on the page, and then type your custom PHP Code into it.

    The goal here is to *not have the PHP Code Widget anymore*. Instead, you’re making a custom plugin to run your custom code. You know, that stuff that you had previously been putting into the widget area.

    That’s the custom code that you’re going to put into your custom plugin.

    Thread Starter Jonas Bj?rn Pedersen

    (@joped)

    Oh I misread your first response.

    So say that I have the following code in the widget:

    <?php bloginfo('name'); ?> - &copy;
    <?php echo date('Y'); ?>

    Is this the code to put in the plugin?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Making my own plug-in’ is closed to new replies.