From 5f4d2423d91cfc2eb40a0ffbf7a7d4ba13a1f2f1 Mon Sep 17 00:00:00 2001 From: Storm Rockwell Date: Mon, 2 Oct 2023 15:26:56 -0400 Subject: [PATCH] Alter enable_block_editor method to only alter posts that support the gutenbridge --- includes/ConvertToBlocks/ClassicEditorSupport.php | 8 ++++---- .../ConvertToBlocks/ClassicEditorSupportTest.php | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/ConvertToBlocks/ClassicEditorSupport.php b/includes/ConvertToBlocks/ClassicEditorSupport.php index e0c0e23..bbdfab5 100644 --- a/includes/ConvertToBlocks/ClassicEditorSupport.php +++ b/includes/ConvertToBlocks/ClassicEditorSupport.php @@ -45,15 +45,15 @@ public function can_register() { * @return bool */ public function enable_block_editor( $enabled, $post ) { - if ( ! $this->container->post_supports_convert_to_blocks( $post ) ) { + if ( $this->container->has_classic_param() ) { return false; } - if ( $this->container->has_classic_param() ) { - return false; + if ( $this->container->post_supports_convert_to_blocks( $post ) ) { + return true; } - return true; + return $enabled; } } diff --git a/tests/ConvertToBlocks/ClassicEditorSupportTest.php b/tests/ConvertToBlocks/ClassicEditorSupportTest.php index f57da4c..1664d79 100644 --- a/tests/ConvertToBlocks/ClassicEditorSupportTest.php +++ b/tests/ConvertToBlocks/ClassicEditorSupportTest.php @@ -40,11 +40,20 @@ function test_it_can_be_registered_on_admin_pages() { $GLOBALS['current_screen'] = null; } - function test_it_will_disable_block_editor_if_post_does_not_support_gutenbridge() { + function test_it_will_enable_block_editor_if_post_supports_gutenbridge() { + $this->post_supports = true; + $supports_editor = $this->support->enable_block_editor( true, 1 ); + $not_supports_editor = $this->support->enable_block_editor( false, 1 ); + + $this->assertTrue( $supports_editor && $not_supports_editor ); + } + + function test_wont_alter_editor_support_if_post_does_not_support_gutenbridge() { $this->post_supports = false; - $actual = $this->support->enable_block_editor( true, 1 ); + $supports_editor = $this->support->enable_block_editor( true, 1 ); + $not_supports_editor = $this->support->enable_block_editor( false, 1 ); - $this->assertFalse( $actual ); + $this->assertTrue( $supports_editor && ! $not_supports_editor ); } function test_it_will_disable_block_editor_if_classic_query_param_is_present() {