mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
Posts: Prevent an empty excerpt when groups and nested column blocks are present.
This improves the logic within `excerpt_remove_blocks()` to better handle `innerBlocks`. This prevents an empty excerpt from being returned when `core/columns`, `core/column`, and `core/group` blocks are present. This issue has been surfaced in the Query Loop block, where excerpts can be set to display. Props aristath. Fixes #53604. Built from https://develop.svn.wordpress.org/trunk@51348 git-svn-id: http://core.svn.wordpress.org/trunk@50957 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5ab81a5f38
commit
98579e4495
@ -710,7 +710,13 @@ function excerpt_remove_blocks( $content ) {
|
|||||||
'core/verse',
|
'core/verse',
|
||||||
);
|
);
|
||||||
|
|
||||||
$allowed_blocks = array_merge( $allowed_inner_blocks, array( 'core/columns' ) );
|
$allowed_wrapper_blocks = array(
|
||||||
|
'core/columns',
|
||||||
|
'core/column',
|
||||||
|
'core/group',
|
||||||
|
);
|
||||||
|
|
||||||
|
$allowed_blocks = array_merge( $allowed_inner_blocks, $allowed_wrapper_blocks );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the list of blocks that can contribute to the excerpt.
|
* Filters the list of blocks that can contribute to the excerpt.
|
||||||
@ -729,8 +735,8 @@ function excerpt_remove_blocks( $content ) {
|
|||||||
foreach ( $blocks as $block ) {
|
foreach ( $blocks as $block ) {
|
||||||
if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {
|
if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {
|
||||||
if ( ! empty( $block['innerBlocks'] ) ) {
|
if ( ! empty( $block['innerBlocks'] ) ) {
|
||||||
if ( 'core/columns' === $block['blockName'] ) {
|
if ( in_array( $block['blockName'], $allowed_wrapper_blocks, true ) ) {
|
||||||
$output .= _excerpt_render_inner_columns_blocks( $block, $allowed_inner_blocks );
|
$output .= _excerpt_render_inner_blocks( $block, $allowed_blocks );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,23 +759,28 @@ function excerpt_remove_blocks( $content ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render inner blocks from the `core/columns` block for generating an excerpt.
|
* Render inner blocks from the allowed wrapper blocks
|
||||||
|
* for generating an excerpt.
|
||||||
*
|
*
|
||||||
* @since 5.2.0
|
* @since 5.8
|
||||||
* @access private
|
* @access private
|
||||||
*
|
*
|
||||||
* @param array $columns The parsed columns block.
|
* @param array $parsed_block The parsed block.
|
||||||
* @param array $allowed_blocks The list of allowed inner blocks.
|
* @param array $allowed_blocks The list of allowed inner blocks.
|
||||||
* @return string The rendered inner blocks.
|
* @return string The rendered inner blocks.
|
||||||
*/
|
*/
|
||||||
function _excerpt_render_inner_columns_blocks( $columns, $allowed_blocks ) {
|
function _excerpt_render_inner_blocks( $parsed_block, $allowed_blocks ) {
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
foreach ( $columns['innerBlocks'] as $column ) {
|
foreach ( $parsed_block['innerBlocks'] as $inner_block ) {
|
||||||
foreach ( $column['innerBlocks'] as $inner_block ) {
|
if ( ! in_array( $inner_block['blockName'], $allowed_blocks, true ) ) {
|
||||||
if ( in_array( $inner_block['blockName'], $allowed_blocks, true ) && empty( $inner_block['innerBlocks'] ) ) {
|
continue;
|
||||||
$output .= render_block( $inner_block );
|
}
|
||||||
}
|
|
||||||
|
if ( empty( $inner_block['innerBlocks'] ) ) {
|
||||||
|
$output .= render_block( $inner_block );
|
||||||
|
} else {
|
||||||
|
$output .= _excerpt_render_inner_blocks( $inner_block, $allowed_blocks );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,13 +25,15 @@ function render_block_core_legacy_widget( $attributes ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$id_base = $attributes['idBase'];
|
$id_base = $attributes['idBase'];
|
||||||
if ( method_exists( $wp_widget_factory, 'get_widget_key' ) ) {
|
if ( method_exists( $wp_widget_factory, 'get_widget_key' ) && method_exists( $wp_widget_factory, 'get_widget_object' ) ) {
|
||||||
$widget_key = $wp_widget_factory->get_widget_key( $id_base );
|
$widget_key = $wp_widget_factory->get_widget_key( $id_base );
|
||||||
|
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
|
||||||
} else {
|
} else {
|
||||||
$widget_key = gutenberg_get_widget_key( $id_base );
|
$widget_key = gutenberg_get_widget_key( $id_base );
|
||||||
|
$widget_object = gutenberg_get_widget_object( $id_base );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $widget_key ) {
|
if ( ! $widget_key || ! $widget_object ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +47,13 @@ function render_block_core_legacy_widget( $attributes ) {
|
|||||||
$instance = array();
|
$instance = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'widget_id' => $widget_object->id,
|
||||||
|
'widget_name' => $widget_object->name,
|
||||||
|
);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
the_widget( $widget_key, $instance );
|
the_widget( $widget_key, $instance, $args );
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4207,3 +4207,20 @@ function wp_sensitive_page_meta() {
|
|||||||
<?php
|
<?php
|
||||||
wp_strict_cross_origin_referrer();
|
wp_strict_cross_origin_referrer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render inner blocks from the `core/columns` block for generating an excerpt.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
* @deprecated 5.8.0
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*
|
||||||
|
* @param array $columns The parsed columns block.
|
||||||
|
* @param array $allowed_blocks The list of allowed inner blocks.
|
||||||
|
* @return string The rendered inner blocks.
|
||||||
|
*/
|
||||||
|
function _excerpt_render_inner_columns_blocks( $columns, $allowed_blocks ) {
|
||||||
|
_deprecated_function( __FUNCTION__, '5.8.0', '_excerpt_render_inner_blocks()' );
|
||||||
|
return _excerpt_render_inner_blocks( $columns, $allowed_blocks );
|
||||||
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.9-alpha-51344';
|
$wp_version = '5.9-alpha-51348';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user