Tips & Tricks

1. Writing WordPress plugins compatible with CKEditor plugin

If you have ever worked on a plugin that used mce_plugins or mce_buttons filters, then you should easily do exactly the same thing with CKEditor.

ckeditor_buttons

Passes in/out a php array with the button names

ckeditor_external_plugins

Passes in/out an associative php array 'plugin_name' => 'plugin_url'. The url should be absolute and on the same domain as your WordPress installation.

Example:

myplugin_wordpress.php

add_filter( 'ckeditor_external_plugins', array(&$myplugin, 'ckeditor_plugin') );
add_filter( 'ckeditor_buttons', array(&$myplugin, 'ckeditor_buttons') );

myplugin_class.php

class myplugin {
    // ... 
    function ckeditor_plugin($plugins) {
        $plugins['myplugin']=$this->plugin_path.'ckeplugin/';
        return $plugins;
    }

    function ckeditor_buttons($buttons) {
        $buttons[]=array('MyButton');
        return $buttons;
    }
    // ...
}

Click here to download a sample plugin for WordPress that adds a button to CKEditor.

Posted at February 23rd, 2010.

Comments are closed.