How do I use wp_editor() in widget form?

I’m trying to use the built-in Rich-text (wp_editor()) editor in WordPress for my widget, but I can’t seem to find any simple way to use it..

I know you can use it, as Black Studio TinyMCE can do it, but how?

Read More

My form function

function form($instance)
{
    $instance = wp_parse_args((array) $instance, array( 'box1' => '', 'box2' => '', 'box3' => '', 'box4' => '' ));
    $box1 = $instance['box1'];
    $box2 = $instance['box2'];
    $box3 = $instance['box3'];
    $box4 = $instance['box4'];
    $boxqty = $instance['boxqty'];

?>
  <p><label for="<?php echo $this->get_field_id('boxqty'); ?>">Number of blocks: (1-4) <input class="widefat" id="<?php echo $this->get_field_id('boxqty'); ?>" name="<?php echo $this->get_field_name('boxqty'); ?>" type="text" value="<?php echo attribute_escape($boxqty); ?>" /></label></p>  
  <p><label for="<?php echo $this->get_field_id('box1'); ?>">Box 1:
     <textarea class="widefat mceEditor" id="<?php echo $this->get_field_id('box1'); ?>" name="<?php echo $this->get_field_name('box1'); ?>">  <?php echo $box1; ?></textarea>
   </label></p>
   <p><label for="<?php echo $this->get_field_id('box2'); ?>">Box 2: 
      <textarea class="widefat" id="<?php echo $this->get_field_id('box2'); ?>" name="<?php echo $this->get_field_name('box2'); ?>"><?php echo $box2; ?></textarea>
   </p>
   <p><label for="<?php echo $this->get_field_id('box3'); ?>">Box 3: 
<textarea class="widefat" id="<?php echo $this->get_field_id('box3'); ?>" name="<?php echo $this->get_field_name('box3'); ?>"><?php echo $box3; ?></textarea>
   </p>
   <p><label for="<?php echo $this->get_field_id('box4'); ?>">Box 4: 
      <textarea class="widefat" id="<?php echo $this->get_field_id('box4'); ?>" name="<?php echo $this->get_field_name('box4'); ?>"><?php echo $box4; ?>      </textarea>
   </p>
<?php
   wp_editor('Test text', 'test-editor');
}

Related posts

Leave a Reply

1 comment

  1. I stumbled across this solution a while back; this might be what you are looking for:

    I added this to my theme’s functions.php file…

    // First, I created a shortcode for a function, that would typically be inserted in to a template file, so that it could be inserted in to a widget.
    
    add_shortcode('myshortcode', 'myfunction');
    function myfunction() {
      if ( function_exists( 'get_smooth_slider_category' ) ) { get_smooth_slider_category('featured'); }
    }
    
    // Then you can add this to allow shortcodes to be used in widgets.
    
    /* Make shortcodes work in widgets */
    add_filter('widget_text', 'do_shortcode');
    

    Then I just added [myshortcode] to the text widget and viola; I have a function in a widget.