-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Introduce get_blocks function #9208
Conversation
A convenient wrapper for `gutenberg_parse_blocks()` that can be used as a template tag as well, complimentary to `has_blocks()` and `has_block()`. See #8352.
These test both `get_blocks()` and `gutenberg_parse_blocks()`.
I was thinking about a complimentary Maybe a |
* @since 3.7.0 | ||
* @see gutenberg_parse_blocks() | ||
* | ||
* @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a little too magical for me. Accepting four potential variable types that each mean different things is more confusing than it is helpful.
Given gutenberg_parse_blocks()
already exists for parsing blocks from a string, I'd suggest get_blocks()
should accept a WP_Post
object, $post_id
Post ID, or null (which would default to the global $post
).
What about a |
I'm a bit hesitant on this since "block type" has a special distinct meaning from the "block"; it's the term we use to describe its abstract definition ( |
Re: |
If we want to have some function that magically references the global Other than that, I don't have strong opinions about naming. PHP and WordPress have inconsistent naming patterns as it is, so I imagine we could find prior art in any direction we look. I'd prefer to delegate naming to one or two people over making it a group decision. |
This PR is no longer relevant to Gutenberg plugin now that all the surrounding logic were moved to WordPress core. I'm closing this PR, however, we might still want to open a ticket against WordPress core. What do you think? |
See #8352.
Description
A convenient wrapper for
gutenberg_parse_blocks()
that can be used as a template tag as well, complimentary tohas_blocks()
andhas_block()
.How has this been tested?
Through unit tests, as well as checking the output of
get_blocks()
on'template_redirect'
.Types of changes
Adds a wrapper function for
gutenberg_parse_blocks()
that can be used inside and outside of loops.Checklist: