[wp-hackers] Adding custom buttons to TinyMCE v3.x
Andrew Ozz
admin at laptoptips.ca
Thu Feb 28 19:03:42 GMT 2008
Viper007Bond wrote:
> So, anyone have any documentation on adding custom buttons to TinyMCE 3?
>
> I'm looking to update my plugin (
> http://wordpress.org/extend/plugins/vipers-video-quicktags/ ) to support the
> next release of WordPress.
I hate to break it to you but TMCE 3 supports adding most video directly
using the "Media" button (on the second row). Pasting the object tag in
HTML mode works good too.
The API for external plugins as well as the structure of plugin's code
is completely changed too. So all TMCE plugins will have to be
rewritten. Good places to start:
http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/devkit
http://wiki.moxiecode.com/index.php/TinyMCE:API
Of course adding a button that will insert some code at the cursor
location is still quite easy. Check the "pagebreak" plugin that does this.
For loading the plugins is best to use the new filter
$mce_external_plugins that takes an array 'name' => 'url' and inserts it
in the zipped TMCE. It's best to use absolute url (with or without the
host name), as using relative needs some settings in the init array to
stay at the default values (that can be changed by a WordPress plugin),
so it would be possible to break the loading of external plugins with
relative url. TMCE would still not load a plugin from another domain.
The gzip compressor has changed too. Now it gathers all parts of TMCE
and outputs the zipped file all in one go. The action "mce_options" is
still supported, but deprecated. The action "tinymce_before_init" is
replaced by a filter "tiny_mce_before_init" that is applied to the php
array with all settings for TMCE. Also the zipped file is cached on disk
to save some memory/server resources. This cache is invalidated by any
change to the init array or by changing the ver=[number] arg when
calling tiny_mce_config. The version is filtered by "tiny_mce_version"
defined in /wp-includes/script-loader.php, so a plugin can change it.
There are changes in loading language files too. The language codes are
only ISO 639-1, which is just the first 2 letters from WordPress locale,
like de, fr, es, etc. TMCE will load langs/[lang].js when a plugin is
loaded and if the plugin has a popup, it will load langs/[lang]_dlg.js
when the popup is opened.
The loading of the default language strings is different too. Now they
all are defined in tinymce/langs/wp-langs.php, so they can be included
in the main .pot file and translated to all languages available in
WordPress. A plugin can use any of the strings there, check the
tinyMCE.i18n js object when TMCE is loaded, to see how to reference them.
Wow what a long email, I'll probably have to add this to the codex. Let
me know if you have more questions, I'll do my best to answer them.
More information about the wp-hackers
mailing list