WordPress Plugin – Final tweaks

The plugin is now pretty much finished, there are certainly other options that could be added such as page summaries via AJAX, custom image sizes for specific preview etc but for now the only thing that is really left to do is to add a quicktag option so that the plugin can be easily used from the post editor.

This is very simple to do, first I have created a hook to add a script file:

[code lang=”php”]add_action(‘admin_print_scripts’, array(&$this, ‘Admin_Script’));[/code]

This script is only loaded within the admin (hence the action is ‘admin_print_scripts’) and it tells WordPress which function to get the script definition.

The Admin_Script function attaches a simple Javascript file to add the quicktag:

[code lang=”php”]/**
* Load admin javascipt file
*
* @return void
*/
function Admin_Script() {
wp_enqueue_script(‘wp-thumbshot-preview’,
plugin_dir_url(__FILE__) . ‘wp-thumbshot-preview.js’,
array(‘quicktags’),
‘0.1’);
}[/code]

It’s fairly obvious what this does, worth noting that quicktags is a prerequisite (so that the quicktags Javascript functions are loaded first).

The Javascript file ‘wp-thumbshot-preview.js’ contains the quicktag definition:

[code lang=”javascript”]edButtons[edButtons.length] =
new edButton(‘preview’,
‘preview’,
‘[preview]’,
‘[/preview]’,
”);[/code]

Now in the code editor there is a ‘preview’ button so that the plugin’s preview tags can be auto completed!

Share

Leave a Reply