Skip to content

Commit 98f4220

Browse files
committed
Update media with updates from earlier work.
1 parent 6742979 commit 98f4220

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/wp-includes/media.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,14 +5302,10 @@ function get_post_galleries( $post, $html = true, $max_galleries = PHP_INT_MAX )
53025302
}
53035303
}
53045304

5305-
$processor = WP_Block_Processor::create( $post->post_content );
5305+
$processor = new WP_Block_Processor( $post->post_content );
53065306
$found = 0;
53075307

5308-
while ( $processor->next_delimiter() ) {
5309-
if ( ! $processor->opens_block( 'gallery' ) ) {
5310-
continue;
5311-
}
5312-
5308+
while ( $processor->next_block( 'gallery' ) ) {
53135309
/*
53145310
* It’s not clear yet whether this will have inner blocks.
53155311
* Until then, start computing for both paths, then bail
@@ -5321,15 +5317,12 @@ function get_post_galleries( $post, $html = true, $max_galleries = PHP_INT_MAX )
53215317

53225318
$html_chunks = array();
53235319
$top_chunks = array();
5324-
while ( $processor->next_delimiter( 'visit-html' ) && $processor->get_depth() >= $gallery_depth ) {
5325-
if ( $processor->opens_block( 'freeform' ) ) {
5326-
$opener = $processor->get_span();
5327-
$processor->next_delimiter( 'visit-html' );
5328-
$closer = $processor->get_span();
5329-
5330-
$chunk = substr( $post->post_content, $opener->start, $closer->start - $opener->start );
5320+
while ( $processor->next_token() && $processor->get_depth() > $gallery_depth ) {
5321+
if ( $processor->is_html() ) {
5322+
$chunk_span = $processor->get_span();
5323+
$chunk = substr( $post->post_content, $chunk_span->start, $chunk_span->length );
53315324
$html_chunks[] = $chunk;
5332-
if ( $gallery_depth === $processor->get_depth() ) {
5325+
if ( $gallery_depth === $processor->get_depth() - 1 ) {
53335326
$top_chunks[] = $chunk;
53345327
}
53355328
} else {
@@ -5342,13 +5335,10 @@ function get_post_galleries( $post, $html = true, $max_galleries = PHP_INT_MAX )
53425335
if ( $has_inner_blocks && $html ) {
53435336

53445337
// Get the rest of the innerHTML of the Gallery’s direct children.
5345-
while ( $processor->next_delimiter( 'visit-html' ) && $processor->get_depth() >= $gallery_depth ) {
5346-
if ( $processor->opens_block( 'freeform' ) ) {
5347-
$opener = $processor->get_span();
5348-
$processor->next_delimiter( 'visit-html' );
5349-
$closer = $processor->get_span();
5350-
5351-
$html_chunks[] = substr( $post->post_content, $opener->start, $closer->start - $opener->start );
5338+
while ( $processor->next_token() && $processor->get_depth() > $gallery_depth ) {
5339+
if ( $processor->is_html() && $processor->get_depth() === $gallery_depth + 2 ) {
5340+
$chunk_span = $processor->get_span();
5341+
$html_chunks[] = substr( $post->post_content, $chunk_span->start, $chunk_span->length );
53525342
}
53535343
}
53545344

@@ -5382,9 +5372,9 @@ function get_post_galleries( $post, $html = true, $max_galleries = PHP_INT_MAX )
53825372
}
53835373
}
53845374

5385-
while ( $processor->next_delimiter() && $processor->get_depth() >= $gallery_depth ) {
5375+
while ( $processor->next_block() && $processor->get_depth() > $gallery_depth ) {
53865376
// Examine only the direct children of the gallery block.
5387-
if ( $processor->get_depth() === $gallery_depth && $processor->opens_block() ) {
5377+
if ( $processor->get_depth() === $gallery_depth + 1 ) {
53885378
$attrs = $processor->allocate_and_return_parsed_attributes();
53895379
$id = $attrs['id'] ?? null;
53905380
if ( isset( $id ) ) {

0 commit comments

Comments
 (0)