Skip to content

Instantly share code, notes, and snippets.

@carlodaniele
Created December 3, 2016 08:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carlodaniele/0c63b192be42665d4143cdb5412e570a to your computer and use it in GitHub Desktop.
Save carlodaniele/0c63b192be42665d4143cdb5412e570a to your computer and use it in GitHub Desktop.
An example WP plugin to show how to register TinyMCE plugins in WordPress
<?php
/**
* @package TinyMCE_example_plugin
* @version 1.0
*/
/*
Plugin Name: TinyMCE example plugin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Your Name
Version: 1.0
Author URI: http://example.com/
*/
/**
* Filters TinyMCE buttons
*
* @since 2.0.0
*
* @param array $buttons First-row list of buttons
* @param string $editor_id Unique editor identifier, e.g. 'content'.
*/
function example_plugin_register_buttons( $buttons ) {
$buttons[] = 'table';
$buttons[] = 'prism';
return $buttons;
}
// add new buttons to the first row
add_filter( 'mce_buttons', 'example_plugin_register_buttons' );
/**
* Filters the list of TinyMCE external plugins
*
* @since 2.5.0
*
* @param array $external_plugins An array of external TinyMCE plugins
*/
function example_plugin_register_plugin( $plugin_array ) {
$plugin_array['table'] = plugins_url( '/mce/table/plugin.min.js', __FILE__ );
$plugin_array['prism'] = plugins_url( '/mce/prism/plugin.js', __FILE__ );
return $plugin_array;
}
// Load the TinyMCE plugin
add_filter( 'mce_external_plugins', 'example_plugin_register_plugin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment