diff --git a/lib/register.php b/lib/register.php index c32d777bb69c0a..aea273387c0b41 100644 --- a/lib/register.php +++ b/lib/register.php @@ -269,6 +269,11 @@ function gutenberg_can_edit_post( $post ) { return false; } + // Disable the editor if on the blog page and there is no content. + if ( absint( get_option( 'page_for_posts' ) ) === $post->ID && empty( $post->post_content ) ) { + return false; + } + if ( ! gutenberg_can_edit_post_type( $post->post_type ) ) { return false; } diff --git a/phpunit/class-admin-test.php b/phpunit/class-admin-test.php index 12b718178dae87..06fb99a0eff795 100644 --- a/phpunit/class-admin-test.php +++ b/phpunit/class-admin-test.php @@ -75,6 +75,20 @@ function test_gutenberg_can_edit_post() { wp_set_current_user( self::$editor_user_id ); $this->assertTrue( gutenberg_can_edit_post( $generic_post_id ) ); + + $blog_page_without_content = self::factory()->post->create( array( + 'post_title' => 'Blog', + 'post_content' => '', + ) ); + update_option( 'page_for_posts', $blog_page_without_content ); + $this->assertFalse( gutenberg_can_edit_post( $blog_page_without_content ) ); + + $blog_page_with_content = self::factory()->post->create( array( + 'post_title' => 'Blog', + 'post_content' => 'Hello World!', + ) ); + update_option( 'page_for_posts', $blog_page_with_content ); + $this->assertTrue( gutenberg_can_edit_post( $blog_page_with_content ) ); } /**