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

Conversation

wpscholar
Copy link
Member

@wpscholar wpscholar commented Jul 27, 2018

Description

Ensure that Gutenberg is disabled when on the assigned blog page in WordPress. Provides feature parity as per functionality from https://github.com/WordPress/WordPress/blob/master/wp-admin/edit-form-advanced.php#L73).

Fixes #3659

How has this been tested?

Tested manually as follows:

  1. From 'Settings' > 'Reading' in the admin, make sure you configure the 'Your homepage displays' section to have a 'Posts page' configured. (The posts page should have no content on it)
  2. Visit the posts page edit screen in the WordPress admin.
  3. The blog page should not utilize Gutenberg and should show a "You are currently editing the page that shows your latest posts." message.

Added unit tests to ensure the gutenberg_can_edit_post() function returns false when attempting to edit the posts page if it does not have content and returns true when it does have content.

Screenshots

edit_page_ gutenberg _wordpress

Types of changes

Bug fix - adds a check to the gutenberg_can_edit_post() function and returns false if it is the posts page and has no content.

Checklist:

  • [ ✓] My code is tested.
  • [✓ ] My code follows the WordPress code style.
  • [ ✓] My code follows the accessibility standards.
  • [✓ ] My code has proper inline documentation.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Pending approach feedback at #3659 (comment)

lib/register.php Outdated
@@ -269,6 +269,10 @@ function gutenberg_can_edit_post( $post ) {
return false;
}

if ( $post->ID == get_option( 'page_for_posts' ) && empty( $post->post_content ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

  • Needs Yoda condition (see failing build)
  • Should ideally be using strict equality. This isn't codified in the standard, but if we expect it to take a particular value shape, we'd be better off than to allow leniency (prone to false positives)
  • The condition is not self-explanatory, and could do for an inline code comment explaining why it exists.

@aduth aduth added the Backwards Compatibility Issues or PRs that impact backwards compatability label Jul 30, 2018
… `page_for_posts` option as an integer. Added an inline comment.
…n the posts page has content and false when the posts page has no content.
'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

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks good. E2E failures are unrelated and are being investigated separately. Will try restarting Travis to get a passing build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gutenberg doesn't respect "Posts page" behavior (hiding editor) in Twenty Seventeen
2 participants