Created
July 8, 2026 16:53
-
-
Save widoz/28b986aff028bb9f48d9a1f40e7c1cce to your computer and use it in GitHub Desktop.
Allow only Editors and Administrators to lock / unlock blocks
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
| <?php | |
| \add_filter('block_editor_settings_all', static function (array $settings): array { | |
| $currentUserRoles = \wp_get_current_user()->roles; | |
| $allowedUserRoles = ['editor', 'administrator']; | |
| $isUserAllowed = (bool)\array_intersect($currentUserRoles, $allowedUserRoles); | |
| if (!$isUserAllowed) { | |
| $settings['canLockBlocks'] = false; | |
| } | |
| return $settings; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment