-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Blocks: Pass parent block, block index, chunk index to serialize_block(s)
callback argument
#5242
Blocks: Pass parent block, block index, chunk index to serialize_block(s)
callback argument
#5242
Conversation
@gziolo Since we're adding quite a bit of complexity to WDYT? |
serialize_block(s)
callback argumentserialize_block(s)
callback argument
|
I'm afraid we won't be able to share much code between the two -- it's the tradeoff we make for optimizing. (Otherwise, we'd likely end up again with a bunch of extra conditionals in |
I know realized that we are going to add more changes later in the process. That's fine 👍🏻 |
Opened #5246 with the changes discussed in the comments. |
Closing in favor of #5246. |
…_block(s) callback argument See WordPress#5242. Co-authored-by: ockham <ockham@git.wordpress.org>
$block_content .= $chunk; | ||
} else { | ||
$inner_block = $block['innerBlocks'][ $block_index ]; | ||
if ( is_callable( $callback ) ) { |
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 was a fan of your suggestion to split the loop, but without that, we could at least examine the impact of trapping $is_callable = is_callable( $callback )
outside of the loop. it appears like is_callable()
is a function call and not a PHP operand, so it could be notable in its cost, particularly on long posts.
in any case, here it seems a little odd to embed that check since $callback
shouldn't change between iterations and there's no need to recompute it every time.
@@ -887,11 +893,16 @@ function serialize_block( $block, $callback = null ) { | |||
* | |||
* @param array[] $blocks An array of representative arrays of parsed block objects. See serialize_block(). | |||
* @param callable|null $callback Optional. Callback to run on each block in the tree before serialization. Default null. | |||
* It is called with the following arguments: $block, $parent_block, $block_index, $chunk_index. |
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.
this comment appears to directly contradict the code below it
See https://core.trac.wordpress.org/ticket/59313.
TODO:
Trac ticket: TBD
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.