Skip to content

Using the 'allowed_block_types_all' hook, it is not possible to search from the Block Directory. #33954

@ddryo

Description

@ddryo

Is there an existing issue for this?

  • I have searched the existing issues

Have you tried deactivating all plugins except Gutenberg?

  • I have tested with all plugins deactivated.

Have you tried replicating the bug using a default theme e.g. Twenty Twenty?

  • I have tested with a default theme.

Description

Using the 'allowed_block_types_all' hook will prevent searching from the Block Directory when searching for blocks.

The reason we are using the 'allowed_block_types_all' hook is that we want to turn off the block for full site editing, which was added in 5.8.

If it is difficult to solve this problem, I would like to see a hook added that allows you to specify 'disallowed blocks' instead of 'allowed blocks'.

Translated with www.DeepL.com/Translator (free version)

Step-by-step reproduction instructions

  1. Use the 'allowed_block_types_all' hook to restrict the block. For example, the following
add_filter( 'allowed_block_types_all', 'test__limit_block_types', 99, 2 );
function test__limit_block_types( $allowed_block_types, $block_editor_context ) {

	// 全ブロック取得
	$all_blocks  = [];
	$block_types = \WP_Block_Type_Registry::get_instance()->get_all_registered();
	foreach ( $block_types as $block_type ) {
		$all_blocks[] = $block_type->name;
	}

	$FSE_blocks = [
		'core/loginout',
		'core/page-list',
		'core/post-content',
		'core/post-date',
		'core/post-excerpt',
		'core/post-featured-image',
		'core/post-terms',
		'core/post-title',
		'core/post-template',
		'core/query-loop',
		'core/query',
		'core/query-pagination',
		'core/query-pagination-next',
		'core/query-pagination-numbers',
		'core/query-pagination-previous',
		'core/query-title',
		'core/site-logo',
		'core/site-title',
		'core/site-tagline',
	];

	$allowed_blocks = array_diff( $all_blocks, $FSE_blocks );
	$allowed_blocks = array_values( $allowed_blocks );
	return $allowed_blocks;
}
  1. Search for blocks. For example, "countdown".

Expected Behavior

スクリーンショット 2021-08-09 22 47 17

Current Behavior

スクリーンショット 2021-08-09 22 37 05

Screenshots or screen recording (optional)

No response

Code snippet (optional)

No response

WordPress Information

No response

Gutenberg Information

No response

What browsers are you seeing the problem on?

No response

Device Information

No response

Operating System Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block DirectoryRelated to the Block Directory, a repository of block plugins[Feature] BlocksOverall functionality of blocks[Feature] ExtensibilityThe ability to extend blocks or the editing experience[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions