[wp-hackers] Adding custom buttons to TinyMCE v3.x

Andrew Ozz admin at laptoptips.ca
Sun Mar 9 21:38:40 GMT 2008


There's some info in the codex:
http://codex.wordpress.org/Migrating_Plugins_and_Themes#TinyMCE

The method of adding a plugin hasn't changed that much. In 2.5 there's a
filter mce_external_plugins that takes an array 'pluginname' =>
'path/to/plugin.js' for that. The only difference is that the path has
to include the actual js filename (in 2.3 it was pointing to the
plugin's directory).

It still looks for the [lang].js files in a sub-directory named "langs"
on the same level where the plugin file is. The language codes are only
ISO 639-1, the first 2 letters from WP_LANG, default "en". There is a
difference if a plugin shows TinyMCE type popup. It looks for
[lang]_dlg.js in the "langs" directory.

The plugin's file name can be anything, but the "langs" directory and 
langs/en.js and langs/en_dlg.js have to be present.

Buttons are added the same way as before. Probably best to add extra
buttons to $mce_buttons_3, as on low-res screens TinyMCE's toolbars may
push through on the right.

The js structure of the actual plugin is new too. Example:
http://wiki.moxiecode.com/index.php/TinyMCE:Create_plugin/3.x

API reference:
http://wiki.moxiecode.com/index.php/TinyMCE:API

The action tinymce_before_init is replaced by a filter 
tiny_mce_before_init that passes all init settings as a php
array and can also be used in place of the deprecated mce_options action.

If a WordPress plugin have to support both 2.3.x and 2.5, it will need 
to have 2 TinyMCE plugins, for 2.x and 3.0.

Viper007Bond wrote:
> Ugh, I am horrible with TinyMCE and not much better with Javascript. Trying
> to figure this out is giving me a headache.
> 
> Would anyone be willing to throw together for me the most simple of TinyMCE
> plugins showing how to create a new button that just does an alert() or
> whatever? Just so I can see the basics. I can (probably) expand from there.
> 




More information about the wp-hackers mailing list