Block Locking Settings in WordPress 6.0

WordPress 6.0 makes it easier to lock blocks using the new controls modal. The release also includes two new settings to choose who can access this option and when.

BlockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. Editor

The new canLockBlocks setting can disable the feature globally or conditionally. Example:

add_filter(
	'block_editor_settings_all',
	function( $settings, $context ) {
		// Allow for the Editor role and above - https://wordpress.org/support/article/roles-and-capabilities/.
		$settings['canLockBlocks'] = current_user_can( 'delete_others_posts' );

		// Only enable for specific user(s).
		$user = wp_get_current_user();
		if ( in_array( $user->user_email, [ 'user@example.com' ], true ) ) {
			$settings['canLockBlocks'] = false;
		}

		// Disable for posts/pages.
		if ( $context->post && $context->post->post_type === 'page' ) {
			$settings['canLockBlocks'] = false;
		}

		return $settings;
	},
	10,
	2
);

Blocks

The lock property allows hide controls on a block type level. Example:

{
	"apiVersion": 2,
	"supports": {
		"lock": false
	}
}

For more info see #39183.

An earlier post on this blogblog (versus network, site) covers, the Curated experiences with locking APIs & theme.json

#6-0, #dev-notes, #dev-notes-6-0