Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect Posts Page #8259

Merged
merged 4 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions phpunit/class-admin-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tests isolated from one another? Is this something which should be reverted in a tearDown ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth All MySQL queries in WordPress unit tests use the COMMIT and ROLLBACK approach to ensure that things like update_option are automatically rolled back. See https://github.com/WordPress/wordpress-develop/blob/master/tests/phpunit/includes/testcase.php#L155

$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 ) );
}

/**
Expand Down