diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 615ae3e8ec..0a4c1c9afc 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -710,7 +710,23 @@ function excerpt_remove_blocks( $content ) { 'core/verse', ); - $allowed_blocks = array_merge( $allowed_inner_blocks, array( 'core/columns' ) ); + $allowed_wrapper_blocks = array( + 'core/columns', + 'core/column', + 'core/group', + ); + + /** + * Filters the list of blocks that can be used as wrapper blocks, allowing + * excerpts to be generated from the `innerBlocks` of these wrappers. + * + * @since 5.8.0 + * + * @param array $allowed_wrapper_blocks The list of allowed wrapper blocks. + */ + $allowed_wrapper_blocks = apply_filters( 'excerpt_allowed_wrapper_blocks', $allowed_wrapper_blocks ); + + $allowed_blocks = array_merge( $allowed_inner_blocks, $allowed_wrapper_blocks ); /** * Filters the list of blocks that can contribute to the excerpt. @@ -729,8 +745,8 @@ function excerpt_remove_blocks( $content ) { foreach ( $blocks as $block ) { if ( in_array( $block['blockName'], $allowed_blocks, true ) ) { if ( ! empty( $block['innerBlocks'] ) ) { - if ( 'core/columns' === $block['blockName'] ) { - $output .= _excerpt_render_inner_columns_blocks( $block, $allowed_inner_blocks ); + if ( in_array( $block['blockName'], $allowed_wrapper_blocks, true ) ) { + $output .= _excerpt_render_inner_blocks( $block, $allowed_blocks ); continue; } @@ -753,23 +769,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 * - * @param array $columns The parsed columns block. + * @param array $parsed_block The parsed 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 ) { +function _excerpt_render_inner_blocks( $parsed_block, $allowed_blocks ) { $output = ''; - foreach ( $columns['innerBlocks'] as $column ) { - foreach ( $column['innerBlocks'] as $inner_block ) { - if ( in_array( $inner_block['blockName'], $allowed_blocks, true ) && empty( $inner_block['innerBlocks'] ) ) { - $output .= render_block( $inner_block ); - } + foreach ( $parsed_block['innerBlocks'] as $inner_block ) { + if ( ! in_array( $inner_block['blockName'], $allowed_blocks, true ) ) { + continue; + } + + if ( empty( $inner_block['innerBlocks'] ) ) { + $output .= render_block( $inner_block ); + } else { + $output .= _excerpt_render_inner_blocks( $inner_block, $allowed_blocks ); } } diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 2c5f24bde0..43ced1429e 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -4207,3 +4207,20 @@ function wp_sensitive_page_meta() {