Skip to content

Commit

Permalink
feat: add filter to get_block_context_interfaces() (#148)
Browse files Browse the repository at this point in the history
* add filter to `get_block_context_interfaces()`

* chore: add changeset

---------

Co-authored-by: John Parris <john.parris@wpengine.com>
  • Loading branch information
jasonbahl and mindctrl authored Sep 1, 2023
1 parent 2e7f2e8 commit a118662
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit a118662

Please sign in to comment.