HOWTO: add headings tinymce plugin to WYSIWYG

The WYSIWYG module does a great job of centralizing and abstracting the use of various graphical editors in Drupal. Its relative newness means it is poorly and confusingly documented in some respects. I recently had to add the headings plugin for TinyMCE and ran into a lot of confusing information about how to make that happen.

My solution, and the recommended approach, is to use the hook_wywiwyg_plugin() API in a custom module to make the plugin available to WYSIWYG. There were a lot of contradictory examples of the code out there. This is what wound up working for me. Note that I installed the heading plugin in the tinymce plugins directory under sites/all/libraries.

 /** * Implementation of hook_wywiwyg_plugin(). */ function FOOBAR_wysiwyg_plugin($editor, $version=0) { $plugins = array(); switch ($editor) { case 'tinymce': if ($version > 3) { $plugins['heading'] = array( 'type' => 'external', 'title' => t('Headings'), 'description' => t('Provides H1-H6 buttons for tinyMCE'), 'path' => wysiwyg_get_path($editor) . '/jscripts/tiny_mce/plugins/heading/editor_plugin.js', 'buttons' => array( 'h1' => t('H1'), 'h2' => t('H2'), 'h3' => t('H3'), 'h4' => t('H4'), 'h5' => t('H5'), 'h6' => t('H6'), ), 'url' => '', 'load' => TRUE, ); } break; } return $plugins; }