Read the Latest Articles:
Integrate tinyMCE into your wordpress plugins

You might remember that I wrote a previous article about the integration of tinyMCE into your wordpress plugins for version 2.5 to 2.7.1.

Following some of your requests and due to the fact that I had to look in order to make ZdMultilang work with the latest Wordpress, Here is the updated article with explanation of how to integrate tinyMCE into your wordpress plugins.

So here is the code you need to include.

add_filter('admin_head','ShowTinyMCE');
function ShowTinyMCE() {
	// conditions here
	wp_enqueue_script( 'common' );
	wp_enqueue_script( 'jquery-color' );
	wp_print_scripts('editor');
	if (function_exists('add_thickbox')) add_thickbox();
	wp_print_scripts('media-upload');
	if (function_exists('wp_tiny_mce')) wp_tiny_mce();
	wp_admin_css();
	wp_enqueue_script('utils');
	do_action("admin_print_styles-post-php");
	do_action('admin_print_styles');
}

Don’t ask me to explain everything, I just found all these details while browsing the admin pages related to posts.



  1. [...] an updated version of this tutorial using Wordpress 2.8, check this post. 15 6 November 2008 Anthony Plugins, Wordpress Development, plugin, Wordpress [...]

  2. jason (Reply) on Tuesday 30, 2009

    does this work in wp 2.8.3? i cant seem to get it to work with just what you have above.

  3. jason (Reply) on Tuesday 30, 2009

    i have a plugin that uses the code you have from above. and i can see the javascript and the stylesheets, however, the form does not display. do i need to put a textbox or an include box on the page with a certain id or name to get it to work? thanks for the help btw.

  4. Antone Roundy (Reply) on Tuesday 30, 2009

    Thanks for posting this code.

    One question — when creating a plugin that you want to have able to run on various WordPress versions, can you use the code shown on this page, or does the plugin need to detect the WordPress version and call the code from your former post if it’s on an old version? If so, do you know how to check the WordPress version (I did some searching and couldn’t find anything).

    One other question: in your previous post, most of the code for the two versions was the same except that the order of the function calls was different — is there any significance to that?

    Thanks again.

  5. Mat_ (Reply) on Tuesday 30, 2009

    Hi !!!
    My tiny_mce is working but i can’t get the media uploader to work correctly. any idea ?

    thanks !
    Mat_´s last blog ..Arnaques aux sites gratuits, faites attention… My ComLuv Profile

  6. Romeo (Reply) on Tuesday 30, 2009

    HI,

    thanks for the code but i’m not getting ride of it.

    What’s the admin_head hook? Can u please tell me what file shoulw i modify and to wich file add the last line to be shown?

    Sorry but im a newbie in coding.. so pls help
    Romeo´s last blog ..Perdor Avatarin Tend [WP Hack] My ComLuv Profile

  7. Boby Ertanto (Reply) on Tuesday 30, 2009

    Your code works, however in the firebug it’s showing error like jQuery is not defined, so I put the printing of the editor after calling enqueue_scripts(“utils”), and it works perfectly now…

    Below is my code :

    function ShowTinyMCE() {
    // conditions here
    wp_enqueue_script( ‘common’ );
    wp_enqueue_script( ‘jquery-color’ );
    if (function_exists(‘add_thickbox’)) add_thickbox();
    wp_print_scripts(‘media-upload’);
    if (function_exists(‘wp_tiny_mce’)) wp_tiny_mce();
    wp_admin_css();
    wp_enqueue_script(‘utils’);
    wp_print_scripts(‘editor’);
    do_action(“admin_print_styles-post-php”);
    do_action(‘admin_print_styles’);
    }

  8. James (Reply) on Tuesday 30, 2009

    Thanks! the info was really helpful. So my question is what pre-processing needs to be done to insert the data retrieved from the the_editor panel when saving the data (to a database), or displaying it.

    In regards to saving the data, I found that I needed to preprocess the data using stripslashes(). To display the data, so far, I have seen that I need to preprocess the data and translate out the shortcodes (saw it, haven’t figured out what the “correct” way to translate it is yet)

    Thanks,
    James

    • Anthony (Reply) on Tuesday 30, 2009

      You’ll have to do the following :
      $content = apply_filters(‘the_content’, $content);
      $content = str_replace(‘]]>’, ‘]]>’, $content);
      then you can echo your $content

  9. Derek (Reply) on Tuesday 30, 2009

    Is there a simple plugin that uses this code that anyone can point to so I can see it in action?

    • Anthony (Reply) on Tuesday 30, 2009

      Derek,

      You can have a look at my ZdMultilang plugin, this is where I extracted the code.

  10. Amit (Reply) on Tuesday 30, 2009

    Hi Anthony,

    I followed your post and tinyMCE shows up well in my plugin for wordpress 2.8. I was earlier using the following statement to save content of my textarea to my DB but now I have no clue how to save tinyMCE’s content to DB…

    $settings["template"] = stripslashes($_POST["textareaContent"]);
    ajaxNewsletter::saveSettings($settings);

    I’ll really appreciate if you may kindly guide me on this…

    Thanks a lot,
    ak