Skip to content

Instantly share code, notes, and snippets.

@mattheu
Created March 5, 2014 12:46
Show Gist options
  • Save mattheu/9366497 to your computer and use it in GitHub Desktop.
Save mattheu/9366497 to your computer and use it in GitHub Desktop.
Remove Buttons From TinyMCE 4.0
<?php
add_filter( 'tiny_mce_before_init', function( $mceInit, $editor_id ) {
if ( $editor_id != 'vcl-placeholder-tinymce-id' )
return $mceInit;
$toolbars = array(
'toolbar1' => explode( ',', $mceInit['toolbar1'] ),
'toolbar2' => explode( ',', $mceInit['toolbar2'] ),
'toolbar3' => explode( ',', $mceInit['toolbar3'] ),
'toolbar4' => explode( ',', $mceInit['toolbar4'] ),
);
$remove_buttons = array( 'strikethrough', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'forecolor', 'wp_more', 'wp_fullscreen', 'underline', 'outdent', 'indent', 'fullscreen' );
$insert_buttons = array(
'toolbar2' => array(
array( 'name' => 'strikethrough', 'position' => 1 ),
array( 'name' => 'alignleft', 'position' => 1 ),
array( 'name' => 'aligncenter', 'position' => 1 )
)
);
foreach ( $toolbars as $toolbar_row => &$toolbar ) {
foreach ( $remove_buttons as $remove_button ) {
if ( $i = array_search( $remove_button, $toolbar ) ) {
unset( $toolbar[$i] );
}
}
if ( isset( $insert_buttons[$toolbar_row] ) ) {
foreach ( array_reverse( $insert_buttons[$toolbar_row] ) as $insert_button ) {
array_splice( $toolbar, $insert_button['position'], 0, $insert_button['name'] );
}
}
$mceInit[$toolbar_row] = implode( ',', $toolbar );
}
return $mceInit;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment