| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class that adds a TinyMCE button to the Post editor |
| 4 |
* |
| 5 |
*/ |
| 6 |
class add_post_snippets_button { |
| 7 |
var $pluginname = "post_snippets"; |
| 8 |
|
| 9 |
/** |
| 10 |
* Constructor |
| 11 |
*/ |
| 12 |
function add_post_snippets_button() { |
| 13 |
// Modify the version when tinyMCE plugins are changed. |
| 14 |
add_filter('tiny_mce_version', array (&$this, 'change_tinymce_version') ); |
| 15 |
|
| 16 |
// init process for button control |
| 17 |
add_action('init', array (&$this, 'add_buttons') ); |
| 18 |
} |
| 19 |
|
| 20 |
function add_buttons() { |
| 21 |
// Don't bother doing this stuff if the current user lacks permissions |
| 22 |
if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) return; |
| 23 |
|
| 24 |
// Add only in Rich Editor mode |
| 25 |
if ( get_user_option('rich_editing') == 'true') { |
| 26 |
// add the button for wp2.5 in a new way |
| 27 |
add_filter("mce_external_plugins", array (&$this, "add_tinymce_plugin" ), 5); |
| 28 |
add_filter('mce_buttons', array (&$this, 'register_button' ), 5); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
// used to insert button in wordpress 2.5x editor |
| 33 |
function register_button($buttons) { |
| 34 |
array_push($buttons, "separator", $this->pluginname ); |
| 35 |
return $buttons; |
| 36 |
} |
| 37 |
|
| 38 |
// Load the TinyMCE plugin : editor_plugin.js (wp2.5) |
| 39 |
function add_tinymce_plugin($plugin_array) { |
| 40 |
$plugin_array[$this->pluginname] = post_snippets_URLPATH.'tinymce/editor_plugin.js'; |
| 41 |
return $plugin_array; |
| 42 |
} |
| 43 |
|
| 44 |
function change_tinymce_version($version) { |
| 45 |
return ++$version; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
$tinymce_button = new add_post_snippets_button(); |
| 50 |
?> |