#51819 closed defect (bug) (fixed)
use_block_editor_for_post() not avaialble by front end
Reported by: | theMikeD | Owned by: | jorbin |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Editor | Keywords: | reporter-feedback add-to-field-guide |
Focuses: | Cc: |
Description
I have a use case where I need to know if a post is using the block editor in front end code. The normal function for this check would be use_block_editor_for_post()
but this is loaded for admin-only, as part of wp-admin/includes/post.php
If there is an alternative I'm all ears, but this would seem to be the right function to use, and the docs give no indication that this is admin-only.
Attachments (1)
Change History (8)
This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.
4 years ago
#4
@
3 years ago
I'm involved in a project that is converting sites to use the Gutenberg editor. In several cases, we need to check at init
if a particular post type is Gutenberg-enabled so that we can disable classic metaboxes and other functionality that we've re-implemented in Gutenberg components, but that is also still in use on non-Gutenberg post types. It's not possible to wait until a later action because these checks often must interact with plugins that we ourselves do not maintain, and which perform their setup at the init
action. Ideally, use_block_editor_for_post()
and use_block_editor_for_post_type()
would be available at that point, which would be possible by moving them to wp-includes
. Neither function depends on other functions that are available only in wp-admin
(other than use_block_editor_for_post()
relying on use_block_editor_for_post_type()
), so moving them to wp-includes
seems both feasible and beneficial.
#5
@
2 years ago
- Milestone changed from Awaiting Review to 6.1
The use case that @ethitter make sense to me. Milestoning so that I can remember to commit it.
Hi
This issue was discussed during a triage session today.
Can you give more details about the use case?
It was not clear if you are displaying an editor on the front, or if you want to know if any post uses blocks.
To find out if a post contains block you can try https://developer.wordpress.org/reference/functions/has_blocks/ or
https://developer.wordpress.org/reference/functions/parse_blocks/