Skip to content

Instantly share code, notes, and snippets.

@karpstrucking
Last active September 4, 2015 15:48
Show Gist options
  • Save karpstrucking/83f217e9a4c7e5100695 to your computer and use it in GitHub Desktop.
Save karpstrucking/83f217e9a4c7e5100695 to your computer and use it in GitHub Desktop.
Force disabling of the expanded editor option in WordPress
add_action( 'init', 'gowp_disable_editor_expand_setting' );
function gowp_disable_editor_expand_setting() {
global $_updated_user_settings;
$_updated_user_settings['editor_expand'] = 'off';
}
add_action( 'admin_footer', 'gowp_disable_editor_expand_field' );
function gowp_disable_editor_expand_field() {
$screen = get_current_screen();
if ( 'post' == $screen->base ) : ?>
<script type="text/javascript">
jQuery( document ).ready( function() {
jQuery( '#editor-expand-toggle' ).prop( 'disabled', true );
} );
</script>
<?php endif;
}
@karpstrucking
Copy link
Author

Could also add an action to disable the #editor-expand-toggle checkbox in Screen Options since this code will render it useless.

@shackep
Copy link

shackep commented Sep 4, 2015

This is great. Thanks!

@karpstrucking
Copy link
Author

@shackep After a little testing I found that most of the original code is unnecessary, so I've reduced it to a few lines and added a footer action to disable the input as well.

@karpstrucking
Copy link
Author

@shackep also, just found this in core trac, which is cleaner.

add_action( 'admin_init', 'my_deregister_editor_expand' );
function my_deregister_editor_expand() {
    wp_deregister_script('editor-expand');
}

add_filter( 'tiny_mce_before_init', 'my_unset_autoresize_on' );
function my_unset_autoresize_on( $init ) {
    unset( $init['wp_autoresize_on'] );
    return $init;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment