Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
}
share|improve this question
    
Did you read the related questions here? Look at the sidebar. Tell us what you have tried already and what didn’t work. –  toscho Mar 5 '13 at 13:36
    
Yes, I did read them, but I can't seem to find a simple answer. –  dasmikko Mar 5 '13 at 13:40
add comment

1 Answer

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.

share|improve this answer
    
I'm not sure, what this has to do with my question. –  dasmikko Mar 8 '13 at 8:00
    
Ok, my bad, I thought this was little simpler than it is. I might have a suggestion though. Take a look at the plugin wp-user-frontend and look at how the developer added the editor to pages. You'll find the code in wpuf-editor.php and add-post.php. Hope this helps. –  ItsGeorge Mar 9 '13 at 15:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.