From b26449d863b757237c2daf322d8396624514b17f Mon Sep 17 00:00:00 2001 From: audrasjb Date: Fri, 25 Feb 2022 12:44:04 +0000 Subject: [PATCH] Media: Make `get_post_galleries()` only return galleries. This change makes sure only gallery content is returned by `get_post_galleries()`. It fixes an issue where non gallery block content was also returned by the function. Props BinaryMoon, costdev, glendaviesnz. Fixes #55203. Built from https://develop.svn.wordpress.org/trunk@52797 git-svn-id: http://core.svn.wordpress.org/trunk@52386 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 9 ++++++--- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index afbdf332a2..5ab3cd1913 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -4780,9 +4780,12 @@ function get_post_galleries( $post, $html = true ) { continue; } - // All blocks nested inside non-Gallery blocks should be in the root array. - if ( $has_inner_blocks && 'core/gallery' !== $block['blockName'] ) { - array_push( $post_blocks, ...$block['innerBlocks'] ); + // Skip non-Gallery blocks. + if ( 'core/gallery' !== $block['blockName'] ) { + // Move inner blocks into the root array before skipping. + if ( $has_inner_blocks ) { + array_push( $post_blocks, ...$block['innerBlocks'] ); + } continue; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7923403305..4d6d566658 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52796'; +$wp_version = '6.0-alpha-52797'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.