Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filter to get_block_context_interfaces() #148

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-taxis-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": minor
---

Added new `wpgraphql_content_blocks_should_apply_post_type_editor_blocks_interfaces` filter to allow controlling whether ${PostType}EditorBlock interfaces should be applied.
19 changes: 19 additions & 0 deletions includes/Registry/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ public function get_block_context_interfaces( string $block_name ): array {
// Fetch the list of allowed blocks for the current post type
$supported_blocks_for_post_type_context = get_allowed_block_types( $block_editor_context );

/**
* Filter before applying per-post_type Interfaces to blocks. This allows 3rd parties to control
* whether the interface(s) should or should not be applied based on custom logic.
*
* @param bool $should Whether to apply the ${PostType}EditorBlock Interface. If the filter returns false, the default
* logic will not execute and the ${PostType}EditorBlock will not be applied.
* @param string $block_name The name of the block Interfaces will be applied to
* @param \WP_Block_Editor_Context $block_editor_context The context of the Block Editor
* @param \WP_Post_Type $post_type The Post Type an Interface might be applied to the block for
* @param array $all_registered_blocks Array of all registered blocks
* @param array $supported_blocks_for_post_type_context Array of all supported blocks for the context
* @param array $block_and_graphql_enabled_post_types Array of Post Types that have block editor and GraphQL support
*/
$should_apply_post_type_editor_block_interface = apply_filters( 'wpgraphql_content_blocks_should_apply_post_type_editor_blocks_interfaces', true, $block_name, $block_editor_context, $post_type, $all_registered_blocks, $supported_blocks_for_post_type_context, $block_and_graphql_enabled_post_types );

if ( true !== $should_apply_post_type_editor_block_interface ) {
continue;
}

// If all blocks are supported in this context, we need a list of all the blocks
if ( true === $supported_blocks_for_post_type_context ) {
$supported_blocks_for_post_type_context = $all_registered_blocks;
Expand Down
Loading