Replace has_blocks with use_block_editor_for_post in is_using_gutenberg #514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 functionhas_blocks
returns false because checking for<!-- wp:
is exactly whathas_blocks
does.This replaces
has_blocks
withuse_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 theuse_block_editor_for_post_type
filter to have this function always return falseAlternate 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:
After
Following the above steps, the Publish button will now be enabled on the destination site
Checklist:
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
withuse_block_editor_for_post
in is_using_gutenberg check