You are right – I totally suck for that. I’m sorry. Here’s what I figured out.
I created a plug-in. The plug-in contains one PHP file and one js file in a folder titled js.
PHP File
This is the relevant code. The file contains some other code as well, such as defining custom colors. (More info here.)
/*
Plugin Name: CW Custom TinyMCE
Description: Customizations for TinyMCE 4
*/
// --- CUSTOM TINY MCE BUTTON ----------------------------
// Use the PHP below in functions.php and also add the javascript in a seperate file in the theme's js folder.
// Hooks your functions into the correct filters
function my_add_mce_button() {
// check user permissions
if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
return;
}
// check if WYSIWYG is enabled
if ( 'true' == get_user_option( 'rich_editing' ) ) {
add_filter( 'mce_external_plugins', 'my_add_tinymce_plugin' );
}
}
add_action('admin_head', 'my_add_mce_button');
// Declare script for new button
function my_add_tinymce_plugin( $plugin_array ) {
// customize for each button
$plugin_array['cw_font_size_btn'] = plugins_url( 'js/tinymce-custom.js', __FILE__ );
return $plugin_array;
}
JS File
My javascript is definitely amateur, but this works for me.
(function() {
tinymce.PluginManager.add('cw_font_size_btn', function( editor, url ) {
editor.addButton( 'cw_font_size_btn', {
type: 'listbox',
text: 'Font Size',// name on the listbox in the ui
icon: false,
classes: 'fixed-width widget btn',// adds classes to the div surrounding the <button>. don't need the 'mce-' prefix
onselect: function(e) {
},
values: [
{text: 'Bigger', onclick : function() {
var selected2 = tinyMCE.activeEditor.selection.getContent();
var content2 = '';
var spantitleclass = ' class="bigger"';
if (selected2 !== '') {
content2 = '<span'+spantitleclass+'>' + selected2 + '</span>';
} else {
content2 = '<span'+spantitleclass+'></span>';
}
tinymce.execCommand('mceInsertContent', false, content2);
}},
{text: 'Big', onclick : function() {
var selected2 = tinyMCE.activeEditor.selection.getContent();
var content2 = '';
var spantitleclass = ' class= "big"';
if (selected2 !== '') {
content2 = '<span'+spantitleclass+'>' + selected2 + '</span>';
} else {
content2 = '<span'+spantitleclass+'></span>';
}
tinymce.execCommand('mceInsertContent', false, content2);
}},
{text: 'Small', onclick : function() {
var selected2 = tinyMCE.activeEditor.selection.getContent();
var content2 = '';
var spantitleclass = ' class= "small"';
if (selected2 !== '') {
content2 = '<span'+spantitleclass+'>' + selected2 + '</span>';
} else {
content2 = '<span'+spantitleclass+'></span>';
}
tinymce.execCommand('mceInsertContent', false, content2);
}},
{text: 'Smaller', onclick : function() {
var selected2 = tinyMCE.activeEditor.selection.getContent();
var content2 = '';
var spantitleclass = ' class= "smaller"';
if (selected2 !== '') {
content2 = '<span'+spantitleclass+'>' + selected2 + '</span>';
} else {
content2 = '<span'+spantitleclass+'></span>';
}
tinymce.execCommand('mceInsertContent', false, content2);
}},
]
});
});
})();
Upload and activate the plug-in.