Skip to content

Instantly share code, notes, and snippets.

@widoz
Created July 8, 2026 16:53
Show Gist options
  • Select an option

  • Save widoz/28b986aff028bb9f48d9a1f40e7c1cce to your computer and use it in GitHub Desktop.

Select an option

Save widoz/28b986aff028bb9f48d9a1f40e7c1cce to your computer and use it in GitHub Desktop.
Allow only Editors and Administrators to lock / unlock blocks
<?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