Limit the Blocks Authors and Contributors Can Use
Gives authors and contributors a short list of everyday blocks (text, headings, lists, images, quotes, embeds) while editors and administrators keep every block.
Opens WPIDE on
Code
// Blocks available to authors and contributors.
$wpide_role_blocks = array(
'core/paragraph', 'core/heading', 'core/list', 'core/list-item', 'core/quote', 'core/image',
'core/gallery', 'core/embed', 'core/separator', 'core/table', 'core/buttons', 'core/button', 'core/details',
);
add_filter( 'allowed_block_types_all', function ( $allowed, $context ) use ( $wpide_role_blocks ) {
if ( current_user_can( 'edit_others_posts' ) ) {
return $allowed;
}
if ( empty( $context->post ) ) {
return $allowed;
}
return $wpide_role_blocks;
}, 20, 2 );
Notes
Users who can edit others' posts (editors and administrators) are not limited. Edit the block list to fit your site.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.