• Hello! I’ve been trying to figure out how to use the TinyMCE in a plugin I’m writing. I would like to have a textarea look identical to a post box for user input in the admin area.

    Older documents say it’s not possible. Newer docs say it is but don’t provide any detail on how to make it happen. One article on a my.opera.com site shows how to do it but it looks terrible and lacks all the features of the MCE embedded in WP.

    So a) is it possible? and b) where can I read how to do it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • a) it is most definitely possible and b) right here ??

    <?php wp_print_scripts( 'quicktags' ); ?><script type="text/javascript">edToolbar();</script>
    <textarea name="TEXTAREA" id="TEXTAREA" rows="10" cols="50"></textarea>
    <script type="text/javascript">var edCanvas = document.getElementById('TEXTAREA');</script>

    That should give you the default buttons for the tinymce editor.

    this is even faster and gives the same results (only with this the textarea gets the default name&id content):
    <?php the_editor( 'CONTENT TO EDIT' ); ?>

    You should probably also insert if ( user_can_richedit() ) wp_enqueue_script('editor'); but as far as I can see that should be in a file that’s like page-new.php (in wp-admin, requiring admin-header.php).
    So far I haven’t been able to get the full tinymce editor with placing that code somewhere else in the page (not developing a plugin with a page like the one I mentioned, so I’m not sure if that works).

    I was just working on this myself a week ago.

    Here is the basic of what I have:

    //
    // 1. Register an admin panel
    //
    add_action('admin_menu', 'myplugin__admin_menu');
    
    function myplugin__admin_menu(){
       // adding the admin panel
       $panel_hook = add_submenu_page('edit.php', 'My Panel', 'My Panel', 9, dirname(__FILE__).'/admin-panel.php');
    
       //
       // 2. Register to add the needed javascript to your admin panel
       //
       add_action('admin-panel.php', 'myplugin__admin_print_scripts');
    
       //
       // 3. Register to add the needed CSS to your admin panel
       //
       add_action('admin_print_styles-admin-panel.php', 'myplugin__admin_print_styles');
    }
    
    function au_chapter_description__admin_print_scripts(){
       //
       // 4. Add the following javascripts to the page
       //
       wp_enqueue_script('jquery');
       wp_enqueue_script('tiny_mce');
       wp_enqueue_script('thickbox');
       // thickbox is not totally required, but you never know
    }
    
    function myplugin__admin_print_styles(){
       //
       // 5.Add the following stylesheets to the page
       //
       wp_enqueue_style('thickbox');
    }

    Then in your admin-panel.php:

    <?php
       // I found that you at least need to have div#editorcontainer
       // wrapping the textarea.
    ?>
    <div id="editorcontainer"><textarea name="myplugin_field" type="text" id="myplugin_field" cols="80" rows="20"><?php print $myplugin_field; ?></textarea></div>
    
    <?php
       // Then run this to turn it into the wysiwyg
    ?>
    <script type="text/javascript">
    tinyMCE.execCommand('mceAddControl', true, 'myplugin_field'); 
    
    	</script>

    This does not add the top bar with insert media and switch html/visual buttons. For what I was doing, I did not need them so I didn’t go any further.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘TinyMCE usage in custom plugin?’ is closed to new replies.