Not every WordPress user needs access to every Gutenberg block.
For example, administrators may need access to all available blocks, while authors and contributors should only have access to a selected set of blocks.
This snippet restricts the Gutenberg block inserter based on the current user’s WordPress role. It allows administrators to configure which blocks are available to Editors, Authors, Contributors, and other custom roles.
How to use
- Add the code to your child theme’s
functions.phpfile or a PHP snippets plugin. - Open the
$role_blocksconfiguration array. - Add or remove block names according to your editorial requirements.
- Log in using different WordPress user accounts.
- Open the Gutenberg editor and check the available blocks in the inserter.
Example configuration
| WordPress role | Block access |
|---|---|
| Administrator | All blocks |
| Editor | All blocks |
| Author | Selected content blocks |
| Contributor | Basic writing blocks |
| Subscriber | No blocks configured |
Adding custom user roles
You can add custom roles to the $role_blocks array.
For example:
'custom_editor' => array(
'core/paragraph',
'core/heading',
'core/image',
),
Replace custom_editor with the actual role slug registered on your website.
Important notes
- Uses the
allowed_block_types_allWordPress filter. - Administrators with the
manage_optionscapability retain their existing block access. - Users with multiple roles receive the combined allowlist, unless one of their configured roles has
nullaccess. - Custom roles not listed in the configuration retain their existing block access.
- Existing restrictions from other filters are respected when they return an array.
- This controls block availability in the editor, not frontend visibility or user permissions to edit published content.
/**
* Restrict available Gutenberg blocks based on user roles.
*/
add_filter(
'allowed_block_types_all',
'alkesh_restrict_gutenberg_blocks_by_role',
20,
2
);
function alkesh_restrict_gutenberg_blocks_by_role(
$allowed_block_types,
$editor_context
) {
// Allow administrators to use all available blocks.
if ( current_user_can( 'manage_options' ) ) {
return $allowed_block_types;
}
$user = wp_get_current_user();
if ( empty( $user->roles ) ) {
return $allowed_block_types;
}
/*
* Configure allowed blocks for each user role.
* Use null to allow all blocks for a particular role.
*/
$role_blocks = array(
'editor' => null,
'author' => array(
'core/paragraph',
'core/heading',
'core/image',
'core/list',
'core/list-item',
'core/quote',
'core/separator',
'core/spacer',
),
'contributor' => array(
'core/paragraph',
'core/heading',
'core/list',
'core/list-item',
'core/quote',
),
'subscriber' => array(),
);
$allowed_for_user = array();
foreach ( $user->roles as $role ) {
if ( ! array_key_exists( $role, $role_blocks ) ) {
continue;
}
// A role with null configuration has unrestricted block access.
if ( null === $role_blocks[ $role ] ) {
return $allowed_block_types;
}
$allowed_for_user = array_merge(
$allowed_for_user,
$role_blocks[ $role ]
);
}
// Remove duplicate block names.
$allowed_for_user = array_unique( $allowed_for_user );
// Respect restrictions applied by other filters.
if ( false === $allowed_block_types ) {
return false;
}
if ( is_array( $allowed_block_types ) ) {
$allowed_for_user = array_intersect(
$allowed_for_user,
$allowed_block_types
);
}
return array_values( $allowed_for_user );
}
Tested on
Reported by the author on October 31, 2026. WPFolks has not verified this.
