Skip to content

Instantly share code, notes, and snippets.

@neverything
Last active August 25, 2023 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverything/e35e2ec6f6ec55f133f7f68a1a24ed55 to your computer and use it in GitHub Desktop.
Save neverything/e35e2ec6f6ec55f133f7f68a1a24ed55 to your computer and use it in GitHub Desktop.
WordPress: Disable blocks for all users on certain post types. See details https://silvanhagen.com/writing/disable-wordpress-blocks-for-all-users/
<?php
add_filter( 'allowed_block_types_all', function( $allowed_blocks, $editor_context ) {
if ( in_array( $editor_context->post?->post_type, ['post', 'page'] ) ) {
$blocks = array_diff(
array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ),
[
'core/image',
'core/headline',
'core/buttons',
'core/button',
'core/column',
'core/columns',
'core/more',
'core/nextpage',
'core/text-columns',
'core/comment-template',
'core/cover',
'core/media-text',
'core/freeform',
'core/code',
'core/preformatted',
'core/verse',
'core/query',
'core/archives',
'core/calendar',
'core/categories',
'core/latest-comments',
'core/latest-posts',
'core/search',
'core/tag-cloud',
'core/rss',
]
);
return array_values( $blocks );
}
return $allowed_blocks;
}, 100, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment