How to disable Block Locking in WordPress
Do you want to disable block locking in WordPress?
If yes then in this tutorial we have discussed the step by step process on how can you do this easily.
Block locking or block lock is a feature that was introduced in WordPress 6.0.
And using it you can disable several actions that you can perform on a block such as
- Removal
- Movement
This feature is available for all blocks be it container, individual or reusable.
And in WordPress 6.1, it was further improved to include an option for applying lock settings to inner blocks in container blocks such as cover, group, columns and more.
In case you are wondering where can you find option for locking blocks then let me tell you to lock a block in WordPress you need to click ellipsis menu on the block toolbar.
And it will show you the Lock option.
On clicking this, a popup will appear that will allow you to select the actions that you want to disable.
Additionally, if you are locking a container block then it will show you the option to apply settings to inner blocks as well.
You can select the options based on your requirements and click Apply.
Keeping this in mind, in this tutorial we have covered a complete step by step process on how can you disable block locking in WordPress.
How to disable Block Lock in WordPress
Before we dive into this tutorial, it is important to know that we were unable to find any plugins for this.
Hence, you will have to use a code snippet for this.
Also, we have shared multiple code snippets for different scenarios and you can use the one that fits your needs.
The initial few steps are exactly the same for everyone and using the table of contents below you can navigate to code snippet of your choice.
Login to your WordPress dashboard
To disable block lock feature in WordPress, the first step is to login to your WordPress dashboard.
For this you need to visit https://your-site.com/wp-admin and it will take you to the login page.
Note- In the above URL you need to replace your-site.com with your domain name.
Here you will have to enter your credentials and click Login.
Go to Theme File Editor
Once you are in your WordPress dashboard, the next step is to navigate to the Theme File Editor.
- Classic Theme Users
If you are a classic theme or a customizer based theme user then you will have to click Appearance in the WordPress admin sidebar and then select Theme File Editor.
- Block Theme Users
Block Themes were released in WordPress 5.9 and it introduced a new way of customizing / building your site using the block editor known as the full site editing.
If you are a block theme user then you will find the Theme File Editor under Tools in the WordPress dashboard sidebar.
When you will click this option it will show you all the theme files.
Open functions.php
Now that you are in the theme file editor, the next step is to open to the functions.php file .
And for this you will have to first locate in the list of theme files.
Once found you need to click to open it.
On opening, it will show you all the code.
Add code snippet to disable block locking
After you have successfully opened the functions.php file, the next step is to go down to the bottom of this file, add any of the code snippets mentioned below and save the file.
Disable Block Locking for posts
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
if ( $context->post && $context->post->post_type === 'post' ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable Block Locking for Pages
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
if ( $context->post && $context->post->post_type === 'page' ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable block locking for both pages and posts
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
if ( $context->post && $context->post->post_type === 'page'|| 'post' ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable Block Locking on Custom Post Types (CPT)
In the code snippet below you will have to cpt with the name of the custom post type you have created.
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
if ( $context->post && $context->post->post_type === 'cpt' ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable Block Locking on Pages, Posts and Custom Post Types
In the code snippet below you will have to cpt with the name of the custom post type you have created.
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
if ( $context->post && $context->post->post_type === 'page'||'post'|| 'cpt' ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable Block locking for Specific user
In the code snippet below you will have to replace [email protected] with the registered email address of the user.
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
$user = wp_get_current_user();
if ( in_array( $user->user_email, [ '[email protected]' ], true ) ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable Block locking for multiple users
In the code snippet below you will have to replace [email protected], [email protected] with the registered email address of the users.
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
$user = wp_get_current_user();
if ( in_array( $user->user_email, [ '[email protected]', '[email protected]' ], true ) ) {
$settings['canLockBlocks'] = false;
}
return $settings;
},
10,
2
);
Disable block locking for Authors and Contributors (Allow for Editors and above)
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
$settings['canLockBlocks'] = current_user_can( 'delete_others_posts' );
return $settings;
},
10,
2
);
Allow for Authors
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
$settings['canLockBlocks'] = current_user_can( 'delete_published_posts' );
return $settings;
},
10,
2
);
Allow for Contributors
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
$settings['canLockBlocks'] = current_user_can( 'delete_posts' );
return $settings;
},
10,
2
);
Check if Block Locking is disabled
Once you have added the code and save changes, the next step is to check if block lock is disabled.
For this you need to edit or add a post / page and click the ellipsis menu on the block toolbar.
You will notice that the block locking option is missing.
And that’s it you have successfully disable block locking on your WordPress site.
Having said that,
I hope you will find this tutorial and are able to disable block locking in WordPress.
In case you have any queries, feel free to reach out and we will to happy to help.
To stay up to date with our content we recommend subscribing to our YouTube channel and email list.
Also, don’t forget to join our Facebook group.