Skip to content

Instantly share code, notes, and snippets.

@tillkruss
Last active April 2, 2021 11:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tillkruss/5425656 to your computer and use it in GitHub Desktop.
Save tillkruss/5425656 to your computer and use it in GitHub Desktop.
Force the WordPress editor to always paste as plain text.
<?php
// always paste as plain text
foreach ( array( 'tiny_mce_before_init', 'teeny_mce_before_init') as $filter ) {
add_filter( $filter, function( $mceInit ) {
$mceInit[ 'paste_text_sticky' ] = true;
$mceInit[ 'paste_text_sticky_default' ] = true;
return $mceInit;
});
}
// load 'paste' plugin in minimal/pressthis editor
add_filter( 'teeny_mce_plugins', function( $plugins ) {
$plugins[] = 'paste';
return $plugins;
});
// remove "Paste as Plain Text" button from editor
add_filter( 'mce_buttons_2', function( $buttons ) {
if( ( $key = array_search( 'pastetext', $buttons ) ) !== false ) {
unset( $buttons[ $key ] );
}
return $buttons;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment