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?
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');
}
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…
Then I just added
[myshortcode]
to the text widget and viola; I have a function in a widget.