Skip to content

Commit 1db51c0

Browse files
committed
Block Processor: Rename extract_block() method for clearer documentation.
In testing during the release candidacy for WordPress 6.9 it was found that the `extract_block()` method may do more work than is expected based off of its name. This change renames the method to `extract_full_block_and_advance()` to communicate that it does move the Block Processor forward and to hint at the fact that it also encompasses all inner blocks during that advance.
1 parent 4de4b72 commit 1db51c0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/wp-includes/class-wp-block-processor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
* block, and re-serialize it into the original document. It’s possible to do so
195195
* while skipping over the parse of the rest of the document.
196196
*
197-
* {@see self::extract_block()} will scan forward from the current block opener
197+
* {@see self::extract_full_block_and_advance()} will scan forward from the current block opener
198198
* and build the parsed block structure until the current block is closed. It will
199199
* include all inner HTML and inner blocks, and parse all of the inner blocks. It
200200
* can be used to extract a block at any depth in the document, helpful for operating
@@ -207,7 +207,7 @@
207207
* }
208208
*
209209
* $gallery_at = $processor->get_span()->start;
210-
* $gallery_block = $processor->extract_block();
210+
* $gallery_block = $processor->extract_full_block_and_advance();
211211
* $after_gallery = $processor->get_span()->start;
212212
* return (
213213
* substr( $post_content, 0, $gallery_at ) .
@@ -1223,7 +1223,7 @@ public function get_depth(): int {
12231223
* }
12241224
*
12251225
* $gallery_at = $processor->get_span()->start;
1226-
* $gallery = $processor->extract_block();
1226+
* $gallery = $processor->extract_full_block_and_advance();
12271227
* $ends_before = $processor->get_span();
12281228
* $ends_before = $ends_before->start ?? strlen( $post_content );
12291229
*
@@ -1254,7 +1254,7 @@ public function get_depth(): int {
12541254
* }
12551255
* }
12561256
*/
1257-
public function extract_block(): ?array {
1257+
public function extract_full_block_and_advance(): ?array {
12581258
if ( $this->is_html() ) {
12591259
$chunk = $this->get_html_content();
12601260

@@ -1291,7 +1291,7 @@ public function extract_block(): ?array {
12911291
* @todo Use iteration instead of recursion, or at least refactor to tail-call form.
12921292
*/
12931293
if ( $this->opens_block() ) {
1294-
$inner_block = $this->extract_block();
1294+
$inner_block = $this->extract_full_block_and_advance();
12951295
$block['innerBlocks'][] = $inner_block;
12961296
$block['innerContent'][] = null;
12971297
}

tests/phpunit/tests/block-processor/wpBlockProcessor-BlockProcessing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function test_builds_block( $block_content ) {
8686

8787
$extracted = array();
8888
while ( $processor->next_block( '*' ) ) {
89-
$extracted[] = $processor->extract_block();
89+
$extracted[] = $processor->extract_full_block_and_advance();
9090
}
9191

9292
$this->assertSame(

0 commit comments

Comments
 (0)