Opened 6 years ago
Last modified 4 years ago
#46004 assigned enhancement
Allow actions based on blocks in the current content
Reported by: | joostdevalk | Owned by: | francina |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Bootstrap/Load | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
We're finding ourselves having to do stuff based on which blocks are in the page, and others are probably experiencing the same thing. So I think it's wise to add an action in the WP bootstrap that allows for people to do something based on which blocks will be on the page. For now only for singular pages, but as Phase 2 of Gutenberg is expanded, this should probably be expanded to other page types.
Attachments (1)
Change History (7)
This ticket was mentioned in Slack in #core-editor by joostdevalk. View the logs.
6 years ago
This ticket was mentioned in Slack in #meta by joostdevalk. View the logs.
6 years ago
#3
@
6 years ago
That sounds interesting.
Few things come to mind:
This would mean doing the block parsing twice on the singular post content, on each page load, since the other parse_blocks()
is in do_blocks()
. I've not profiled parse_blocks()
but I wonder how it scales with the size of the post content?
Blocks can be removed dynamically from the post content, e.g. via the render_block
filter, so in that case there might be some mismatch regarding what blocks are actually displayed on the page and what blocks are seen within the parsed_blocks
action.
I also wonder if has_blocks()
would be useful as a pre condition or e.g. as a second input argument available for parsed_blocks
action callbacks. I can imagine in some cases it would be helpful to know if there are no blocks at all.
If get_post_content()
is used, then one would need to handle cases like when:
- the post content is password protected
- the post content is split up into sub-pages e.g. with
<!--nextpage-->
- ...
I would also think having use cases would help to better understand the need for such an action and what's needed to implement it.
#4
@
4 years ago
- Milestone changed from Awaiting Review to 5.8
- Owner set to francina
- Status changed from new to assigned
First patch