• Resolved wuh

    (@wuh)


    Hi all – I know this has been asked before, but it was some time ago, and received no replies. I have developed a WordPress plugin that uses a textarea input for content, what I’d like to be able to do is enable the default wysiwyg controls for this element. I once found a page online that detailed the process for doing this, but I’ve searched high and low and cannot find it again!

    Any help would be appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wuh

    (@wuh)

    Well, with the help of another post I’ve managed to solve the problem, everything works bar the media upload buttons (any suggestions?):

    In your plugin you need to enqueue the following within the admin_print_scripts action:

    wp_enqueue_script('post');
    if ( user_can_richedit() )
      wp_enqueue_script('editor');
    add_thickbox();
    wp_enqueue_script('media-upload');
    wp_enqueue_script('word-count');

    On the page writing your textarea to the page, replace it with the following:

    <div id="poststuff">
      <div id="postdivrich">
        <h3><label for="content">Your Label</label></h3>
        <?php the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2); ?>
      </div>
    </div>

    The parameters for the_editor are:

    $content – content to echo into the textarea
    $id – id to give the textarea element
    $prev_id – not sure what this is, I used an empty string
    $media_buttons – set to false because they don’t work in my implementation
    $tab_index – not sure again, but default value works

    I hope this is of some use ??

    NOTE: If you do not specify ‘content’ as your textarea ID, it will not get initialised correctly!

    I have been having problems getting this to work. I am using WP 2.6.2. I have added a theme page in order to create a page to manage a static table on my website. The theme page addition works fine. What I’m having problems with is getting the WYSIWYG editor to appear — only the HTML editor will come up. When I click on “Visual” nothing happens. Here is the code I’m using:

    wp_enqueue_script('post');
    	if ( user_can_richedit() ) { wp_enqueue_script('editor'); }
    	add_thickbox();
    	wp_enqueue_script('media-upload');
    	wp_enqueue_script('word-count');
    
    	?>
    
    	<div class="wrap">
    
    <div id="postdivrich" class="postarea">
    		<h2>Front Content Settings</h2>
    		<form method="post">
    		<h3><label for="content">Edit Front Content</label></h3>
    		<?php the_editor($updated_value, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2); ?>
    		<p><div class="submit"><input type="submit" name="save_front_content_options" value="<?php _e('Save Options', 'save_youtuber_options') ?>"  style="font-weight:bold;" /></div></p>
           </form>
    </div>

    The function user_can_richedit() returns true.

    Can anybody see what I need to do in order to get the “Visual” editor working correctly?

    Thanks,
    Ryan

    @rhughes2270,

    Hi. The process posted above works great for me in 2.6.2. Here;s the exact code I used:

    add_action( 'init', 'my_plugin_init' );
    function my_plugin_init() {
    		wp_enqueue_script( 'word-count' );
    		wp_enqueue_script('post');
    		if ( user_can_richedit() )
    			wp_enqueue_script('editor');
    		add_thickbox();
    		wp_enqueue_script('media-upload');
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Enable WYSIWYG editor in plugin’ is closed to new replies.