Update WordPress to 5.2

This commit is contained in:
Oliver Davies 2019-05-08 08:05:39 +01:00
parent 489b5a5914
commit e00f87f2f5
599 changed files with 119573 additions and 55990 deletions

View file

@ -125,10 +125,9 @@ function get_dynamic_block_names() {
* @return string The parsed and filtered content.
*/
function excerpt_remove_blocks( $content ) {
$allowed_blocks = array(
$allowed_inner_blocks = array(
// Classic blocks have their blockName set to null.
null,
'core/columns',
'core/freeform',
'core/heading',
'core/html',
@ -141,6 +140,9 @@ function excerpt_remove_blocks( $content ) {
'core/table',
'core/verse',
);
$allowed_blocks = array_merge( $allowed_inner_blocks, array( 'core/columns' ) );
/**
* Filters the list of blocks that can contribute to the excerpt.
*
@ -154,12 +156,55 @@ function excerpt_remove_blocks( $content ) {
$allowed_blocks = apply_filters( 'excerpt_allowed_blocks', $allowed_blocks );
$blocks = parse_blocks( $content );
$output = '';
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 );
continue;
}
// Skip the block if it has disallowed or nested inner blocks.
foreach ( $block['innerBlocks'] as $inner_block ) {
if (
! in_array( $inner_block['blockName'], $allowed_inner_blocks, true ) ||
! empty( $inner_block['innerBlocks'] )
) {
continue 2;
}
}
}
$output .= render_block( $block );
}
}
return $output;
return $output;
}
/**
* Render inner blocks from the `core/columns` block for generating an excerpt.
*
* @since 5.2.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 ) {
$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 );
}
}
}
return $output;
}
/**
@ -262,13 +307,6 @@ function parse_blocks( $content ) {
* @return string Updated post content.
*/
function do_blocks( $content ) {
// If there are blocks in this content, we shouldn't run wpautop() on it later.
$priority = has_filter( 'the_content', 'wpautop' );
if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
remove_filter( 'the_content', 'wpautop', $priority );
add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 );
}
$blocks = parse_blocks( $content );
$output = '';
@ -276,11 +314,18 @@ function do_blocks( $content ) {
$output .= render_block( $block );
}
// If there are blocks in this content, we shouldn't run wpautop() on it later.
$priority = has_filter( 'the_content', 'wpautop' );
if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
remove_filter( 'the_content', 'wpautop', $priority );
add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 );
}
return $output;
}
/**
* If do_blocks() needs to remove wp_autop() from the `the_content` filter, this re-adds it afterwards,
* If do_blocks() needs to remove wpautop() from the `the_content` filter, this re-adds it afterwards,
* for subsequent `the_content` usage.
*
* @access private