Created
April 3, 2025 08:30
-
-
Save daniloparrajr/51d20d2cc2e724117d0b12b8e50f381a to your computer and use it in GitHub Desktop.
Restrict access to the locking UI and the Code Editor to Administrators.
This file contains hidden or 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
/** | |
* 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