Created
March 25, 2015 21:11
-
-
Save sirchrispy/0573bd685e19fbc4e1cb to your computer and use it in GitHub Desktop.
WP: Modify Visual Editor Toolbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Modify TinyMCE4 configurations & Init. | |
* | |
* @param array $mceInit config | |
* @param int $editor_id | |
* @return array $mceInit | |
* @link Modified from https://github.com/mattheu/wp-editor-talk-demo/blob/master/inc/tinymce-mods.php | |
*/ | |
add_filter( 'tiny_mce_before_init', 'geff_modify_tinyMCE4', 10, 2 ); | |
function geff_modify_tinyMCE4( $mceInit, $editor_id ) { | |
// Set the allowed 'Blog formats' - remove h1 | |
$mceInit['block_formats'] = "Paragraph=p;Header 2=h2;Header 3=h3;Header 4=h4;Header 5=h5;Header 6=h6;Preformatted=pre"; | |
// We could just set the required buttons on each toolbar if we want. | |
// But other plugins may be making modifications so I'm going to and avoid breaking things. | |
// Toolbar buttons are stored as a comma separated list - lets make them an array. | |
$toolbar1 = explode( ',', $mceInit['toolbar1'] ); | |
$toolbar2 = explode( ',', $mceInit['toolbar2'] ); | |
// These are all the buttons we want to completely remove. | |
$remove = array( | |
'underline', // underline | |
'forecolor' // text color | |
); | |
// Remove these buttons if they are found in toolbar1 or toolbar2 | |
foreach ( $remove as $name ) { | |
if ( $key = array_search( $name, $toolbar1 ) ) { | |
unset( $toolbar1[$key] ); | |
} | |
if ( $key = array_search( $name, $toolbar2 ) ) { | |
unset( $toolbar2[$key] ); | |
} | |
} | |
// Convert back to original format. | |
$mceInit['toolbar1'] = implode( ',', $toolbar1 ); | |
$mceInit['toolbar2'] = implode( ',', $toolbar2 ); | |
return $mceInit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment