From fc23abe1db313ff284d71ed6df110e0e5b77561a Mon Sep 17 00:00:00 2001 From: theodesp <328805+theodesp@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:47:19 +0100 Subject: [PATCH 1/4] Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` --- .changeset/odd-files-attend.md | 5 +++++ includes/Utilities/WPHelpers.php | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .changeset/odd-files-attend.md diff --git a/.changeset/odd-files-attend.md b/.changeset/odd-files-attend.md new file mode 100644 index 00000000..0ccab18b --- /dev/null +++ b/.changeset/odd-files-attend.md @@ -0,0 +1,5 @@ +--- +"@wpengine/wp-graphql-content-blocks": patch +--- + +Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` when filtering the post types. \ No newline at end of file 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; } From 3e8cb1a0124e65085ff666bfe1c672e69c06315a Mon Sep 17 00:00:00 2001 From: theodesp <328805+theodesp@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:10:21 +0100 Subject: [PATCH 2/4] Tests: Add unit test for `use_block_editor_for_post_type` --- tests/unit/RegistryTestCase.php | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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 From a9fc17cf09cb227639b5690f8eabac3b62befe22 Mon Sep 17 00:00:00 2001 From: Theofanis Despoudis <328805+theodesp@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:13:20 +0100 Subject: [PATCH 3/4] Update odd-files-attend.md --- .changeset/odd-files-attend.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.changeset/odd-files-attend.md b/.changeset/odd-files-attend.md index 0ccab18b..bca1cb77 100644 --- a/.changeset/odd-files-attend.md +++ b/.changeset/odd-files-attend.md @@ -1,5 +1,6 @@ --- -"@wpengine/wp-graphql-content-blocks": patch +"@wpengine/wp-graphql-content-blocks": major --- -Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` when filtering the post types. \ No newline at end of file +Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` when filtering the post types. +WARNING: Potential BREAKING schema changes on previously exposed blocks that do not support the block editor. Those blocks will no longer inherit the `editorBlocks` field. From c5bedbad23f71217740225314b00b26b4169972f Mon Sep 17 00:00:00 2001 From: Theofanis Despoudis <328805+theodesp@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:28:21 +0100 Subject: [PATCH 4/4] Update .changeset/odd-files-attend.md Co-authored-by: Blake Wilson --- .changeset/odd-files-attend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/odd-files-attend.md b/.changeset/odd-files-attend.md index bca1cb77..9b29bd5f 100644 --- a/.changeset/odd-files-attend.md +++ b/.changeset/odd-files-attend.md @@ -3,4 +3,4 @@ --- Fix: use `use_block_editor_for_post_type` instead of `post_type_supports` when filtering the post types. -WARNING: Potential BREAKING schema changes on previously exposed blocks that do not support the block editor. Those blocks will no longer inherit the `editorBlocks` field. +**BREAKING**: Potential schema changes on previously exposed blocks that do not support the block editor. Those blocks will no longer inherit the `editorBlocks` field.