Skip to content

Instantly share code, notes, and snippets.

@daniloparrajr
Created April 3, 2025 08:30
Show Gist options
  • Save daniloparrajr/51d20d2cc2e724117d0b12b8e50f381a to your computer and use it in GitHub Desktop.
Save daniloparrajr/51d20d2cc2e724117d0b12b8e50f381a to your computer and use it in GitHub Desktop.
Restrict access to the locking UI and the Code Editor to Administrators.
/**
* Restrict access to the locking UI and the Code Editor
* to Administrators.
*
* @param array $settings Default editor settings.
* @param WP_Block_Editor_Context $context The current block editor context.
*/
function example_theme_restrict_locking_ui( $settings, $context ) {
$is_administrator = current_user_can( 'activate_plugins' );
if ( ! $is_administrator ) {
$settings[ 'canLockBlocks' ] = false;
$settings[ 'codeEditingEnabled' ] = false;
}
return $settings;
}
add_filter( 'block_editor_settings_all', 'example_theme_restrict_locking_ui', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment