How-To include tinyMCE in your WP plugin
While developping ZdMultilang’s new version, I came accross a compatibilty problem with Wordpress 2.7.
In fact, to include the tinyMCE editor you won’t use the same functions between 2.6.3 and 2.7 releases. More interesting is WP2.7 will need one more function to be able to display the editor.
Most of the time you will want to include this editor when working with posts, or when you want to enable your plugin users to enter information with the Wysiwyg editor (newsletter, advanced widgets, etc…)
Wordpress 2.5.x and 2.6.x
Here is how to include the editor in one of your plugin’s admin panel.
- Include this code in the admin_head hook
add_filter('admin_head','zd_multilang_tinymce'); function zd_multilang_tinymce() { wp_admin_css('thickbox'); wp_print_scripts('post'); wp_print_scripts('editor'); add_thickbox(); wp_print_scripts('media-upload'); wp_print_scripts('jquery'); wp_print_scripts('jquery-ui-core'); wp_print_scripts('jquery-ui-tabs'); } - Call the editor anywhere you need it to be displayed
the_editor($content_to_load);
Wordpress 2.7
Here is how to include the editor in one of your plugin’s admin panel.
- Include this code in the admin_head hook
add_filter('admin_head','zd_multilang_tinymce'); function zd_multilang_tinymce() { wp_admin_css('thickbox'); wp_print_scripts('jquery-ui-core'); wp_print_scripts('jquery-ui-tabs'); wp_print_scripts('post'); wp_print_scripts('editor'); add_thickbox(); wp_print_scripts('media-upload'); if (function_exists('wp_tiny_mce')) wp_tiny_mce(); // use the if condition because this function doesn't exist in version prior to 2.7 } - Call the editor anywhere you need it to be displayed
the_editor($content_to_load);
Differences between versions.
As you can see, there is only one difference in the code between both version, but this is a major one as if you don’t call the wp_tiny_mce function, the editor will not work at all.
There are some other differences but mostly in the css classes as the design has been totally revamped. Therefore if you want to mimic the interface on both version you will need to add some classes and divs as you will see when I’ll publish ZdMultilang v1.1.2 ;)
By the way, I’m proud to announce that version 1.1.2 of ZdMultilang will be fully compatible with Wordpress 2.7 and the interface will look much better in 2.6.3 and 2.7 than right now.
Français









Markus
10 November 2008
Hi Anthony,
I’m excited to hear this. If you like you can Email the new Beta version to me and I’ll start some testing for you.
I forgot to ask, where in Canada are you moving? (my guess would be Montreal, Quebec. I lived for over 30 years in Canada myself and have been all over this beautiful country.
Cheers, Markus
Anthony
10 November 2008
Markus, I’ll send you a Beta version during the week, I expect to release next version next week :)
No, I’m not moving to MontrĂ©al, I’m moving to Vancouver :) But your guess was legitimate as I’m french ;)
Chris Respeto
23 February 2009
I have been looking all over for this information, thank you so much, this was very, very helpful.
Jack Lenox
27 February 2009
Hi Anthony,
I’m afraid I don’t quite understand the part about the admin_head hook. Whereabouts do I find this and where do I place the code that you have suggested? Is it in admin-header.php in wp-admin? Can you show what code should be either side of the new bit?
Thanks,
Jack
Peter
18 May 2009
First of all – brilliant post – this is the only place I can find working instructions on using the_editor to its fullest.
I have run into one problem though – After 3 hours of debugging this morning (after months of using this piece of code in client work.. whoops), I found that you need to make sure that when you include the zd_multilang_tinymce() function, there really needs to be a conditional statment to make sure it’s only run on the page you want it to run on. In my case, I used this:
if(get_admin_page_title() == ‘Theme Options’){
//enqueue stuff here
}
The problem comes when this function is run on the edit-post page – the tinymce editor goes wonky, but you don’t notice it until you hit the “kitchen sink” button, and apparently it only happens in firefox (and I only tested FF3). I haven’t taken the time to figure out why it happens, because figuring this out was one of the most infuriating things I’ve ever done, and I’m not sure I can look at another line of code today – but perhaps using wp_enqueue_script instead of print_script would solve the problem?
Regardless, a million thanks for figuring this out the first place – it has been a lifesaver.
Guillaume
24 June 2009
hi! thanks for this usefull tip…
Do you have any update with Wordpress 2.8, I tried and the upload part isn’t working anymore.
Thanks a lot
Anthony
24 June 2009
Yes I do have the answer to your question, and I will update the post soon :D
guigouz
30 June 2009
I do have the same question…. any way to make this work with 2.8 ?