Block Editor PHP Beginner

Only Let Administrators Lock Blocks

Remove the Lock option from the block toolbar for everyone except administrators, so editors can't lock or unlock blocks.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 6 lines
add_filter( 'block_editor_settings_all', function ( array $settings ): array {
	if ( ! current_user_can( 'manage_options' ) ) {
		$settings['canLockBlocks'] = false;
	}
	return $settings;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Block locking stops blocks being moved or removed, which is useful for keeping layouts intact. But if editors can lock and unlock blocks themselves, the protection is easy to undo. This snippet keeps locking for administrators only.

How it works

canLockBlocks in the editor settings controls whether the Lock option appears in the block toolbar and List View. The snippet sets it to false for anyone without manage_options. Blocks an administrator has locked stay locked for everyone else.

Things to watch

  • Template locks set in code, such as template_lock on a post type, aren’t affected.

How to test it

Log in as an editor and click a block’s options menu. There should be no Lock option.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only