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

Replace has_blocks with use_block_editor_for_post in is_using_gutenberg #514

Merged
merged 3 commits into from
Feb 14, 2020

Conversation

johnwatkins0
Copy link
Member

@johnwatkins0 johnwatkins0 commented Feb 5, 2020

Description of the Change

This would fix the issue described in #512 by providing a more reliable check for whether the Gutenberg editor is enabled for a post.

The issue @dkotter found comes from a specific scenario where a post may be distributed to a Gutenberg-enabled site without having <!-- wp: in the post content. In this case, the core function has_blocks returns false because checking for <!-- wp: is exactly what has_blocks does.

This replaces has_blocks with use_block_editor_for_post, which checks whether the current post's post type has the editor enabled and shows in REST. This works with the Classic Editor plugin because that plugin uses the use_block_editor_for_post_type filter to have this function always return false

Alternate Designs

I can't think of any good alternatives to this small change.

Benefits

After being distributed in draft status, posts with no blocks can be published.

Possible Drawbacks

Verification Process

Before

Adapting Darin's steps to reproduce from #512:

  1. Activate the Classic Editor plugin
  2. Write a new post using the Classic Editor
  3. Disable the Classic Editor plugin
  4. Distribute the post to another site, keeping the post in draft status on the destination site
  5. Notice on the destination site the Publish button is disabled

After

Following the above steps, the Publish button will now be enabled on the destination site

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Note: There were multiple issues with tests. I was unable to run composer install because of missing PHP extensions on my system (can share more details if helpful). I see tests are failing on all the PRs, so I'm going to assume that's not just me.

Applicable Issues

#512

Changelog Entry

Replace has_blocks with use_block_editor_for_post in is_using_gutenberg check

@johnwatkins0 johnwatkins0 self-assigned this Feb 5, 2020
@jeffpaul jeffpaul requested a review from dkotter February 5, 2020 05:15
@jeffpaul jeffpaul added this to the 2.0.0 milestone Feb 5, 2020
@jeffpaul jeffpaul added the type:bug Something isn't working. label Feb 5, 2020
@dkotter
Copy link
Collaborator

dkotter commented Feb 6, 2020

@johnwatkins0 Thanks for this! Tested this and works great, fixes the issue I had run into.

@jeffpaul jeffpaul merged commit 4205b47 into develop Feb 14, 2020
@jeffpaul
Copy link
Member

May also resolve #516

@jeffpaul jeffpaul deleted the fix/is-using-gutenberg-512 branch June 30, 2020 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants