diff --git a/.changeset/odd-files-attend.md b/.changeset/odd-files-attend.md new file mode 100644 index 00000000..9b29bd5f --- /dev/null +++ b/.changeset/odd-files-attend.md @@ -0,0 +1,6 @@ +--- +"@wpengine/wp-graphql-content-blocks": major +--- + +Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` when filtering the post types. +**BREAKING**: Potential schema changes on previously exposed blocks that do not support the block editor. Those blocks will no longer inherit the `editorBlocks` field. diff --git a/includes/Utilities/WPHelpers.php b/includes/Utilities/WPHelpers.php index d417bf32..9662554b 100644 --- a/includes/Utilities/WPHelpers.php +++ b/includes/Utilities/WPHelpers.php @@ -33,11 +33,10 @@ public static function get_supported_post_types(): array { if ( empty( $block_editor_post_types ) || ! is_array( $block_editor_post_types ) ) { return $supported_post_types; } - // Iterate over the post types foreach ( $block_editor_post_types as $block_editor_post_type ) { // If the post type doesn't support the editor, it's not block-editor enabled - if ( ! post_type_supports( $block_editor_post_type->name, 'editor' ) ) { + if ( ! use_block_editor_for_post_type( $block_editor_post_type->name ) ) { continue; } diff --git a/tests/unit/RegistryTestCase.php b/tests/unit/RegistryTestCase.php index 5bc31447..d26ad58a 100644 --- a/tests/unit/RegistryTestCase.php +++ b/tests/unit/RegistryTestCase.php @@ -64,6 +64,42 @@ interfaces { $this->assertTrue( in_array( $contains_interface, $response['data']['__type']['interfaces'] ) ); } + /** + * This test ensures that when disabling the block editor for post types then + * no additional interfaces are included in them. + */ + public function test_no_additional_interfaces_on_block_editor_disabled_block_types() { + add_filter('use_block_editor_for_post_type', '__return_false'); + $query = ' + query GetType($name:String!) { + __type(name: $name) { + interfaces { + name + } + } + } + '; + + $this->instance->init(); + + // Verify the response contains what we put in cache + $response = graphql( + array( + 'query' => $query, + 'variables' => array( + 'name' => 'Post', + ), + ) + ); + $not_included = array( + 'name' => 'NodeWithEditorBlocks', + ); + $this->assertArrayHasKey( 'data', $response, json_encode( $response ) ); + $this->assertNotEmpty( $response['data']['__type']['interfaces'] ); + $this->assertNotContains( $not_included, $response['data']['__type']['interfaces'] ); + remove_filter('use_block_editor_for_post_type', '__return_false'); + } + /** * This test ensures that the `register_interface_types()` method * works as expected when the get_allowed_block_types is used