How to add the “Automatically add paragraphs” option to my WordPress widget?

I’m talking about the “Automatically add paragraphs” option that appears under the textarea in the “Text” widget. I swear I’ve done this before, but my Google-fu is failing me and all I can find is tutorials on existing WordPress widgets, nothing about how to code this into your own textarea/widget.

Anyone know how to add this/where in the codex this is? This is my widget now:

    function form($instance) {
        if($instance) {
            $mytext = esc_textarea($instance['mytext']);
        } else {
            $mytext = '';
        }
        ?>
        <p>
        <label for="<?php echo $this->get_field_id('mytext'); ?>"><?php _e('My Text', 'wp_widget_plugin'); ?></label>
        <textarea rows="5" class="widefat" id="<?php echo $this->get_field_id('mytext'); ?>" name="<?php echo $this->get_field_name('mytext'); ?>"><?php echo $mytext; ?></textarea>
        </p>       
        <?php
    }

    function widget($args, $instance) {

        extract($args);
        $mytext = $instance['mytext'];

        echo $before_widget;

        echo '<h1>' . $mytext . '</h1>';

       echo $after_widget;
    }

Related posts

Leave a Reply

2 comments