diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index f65ddb6c2e..e817286ff7 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -198,10 +198,38 @@ 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 ); return _recurse_do_blocks( $blocks, $blocks ); } +/** + * If do_blocks() needs to remove wp_autop() from the `the_content` filter, this re-adds it afterwards, + * for subsequent `the_content` usage. + * + * @access private + * + * @since 5.0.0 + * + * @param string $content The post content running through this filter. + * @return string The unmodified content. + */ +function _restore_wpautop_hook( $content ) { + global $wp_filter; + $current_priority = $wp_filter['the_content']->current_priority(); + + add_filter( 'the_content', 'wpautop', $current_priority - 1 ); + remove_filter( 'the_content', '_restore_wpautop_hook', $current_priority ); + + return $content; +} + /** * Helper function for do_blocks(), to recurse through the block tree. * diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index efe9563e2f..75a27ab321 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -458,11 +458,6 @@ function wpautop( $pee, $br = true ) { return ''; } - // We don't need to autop posts with blocks in them. - if ( has_blocks( $pee ) ) { - return $pee; - } - // Just to make things a little easier, pad the end. $pee = $pee . "\n"; diff --git a/wp-includes/version.php b/wp-includes/version.php index 194ddc0a63..25d1e1caf2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44225'; +$wp_version = '5.1-alpha-44226'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.