Formatting: Ensure `wpautop()` isn't run on content generated from blocks.
As `do_blocks()` is run before `wpautop()` in `the_content` filter, we can remove in a Just In Time fashion, before that filter is run. After `wpautop()`s original priority has passed, we can re-add it in a Just Too Late fashion, to ensure it's available if `the_content` filter is run multiple times on a page load. Props pento, nerrad. Fixes #45290. Built from https://develop.svn.wordpress.org/branches/5.0@43879 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43708 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c22a63ec3a
commit
7c19654f33
|
@ -198,10 +198,38 @@ function parse_blocks( $content ) {
|
||||||
* @return string Updated post content.
|
* @return string Updated post content.
|
||||||
*/
|
*/
|
||||||
function do_blocks( $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 );
|
$blocks = parse_blocks( $content );
|
||||||
return _recurse_do_blocks( $blocks, $blocks );
|
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.
|
* Helper function for do_blocks(), to recurse through the block tree.
|
||||||
*
|
*
|
||||||
|
|
|
@ -442,11 +442,6 @@ function wpautop( $pee, $br = true ) {
|
||||||
if ( trim($pee) === '' )
|
if ( trim($pee) === '' )
|
||||||
return '';
|
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.
|
// Just to make things a little easier, pad the end.
|
||||||
$pee = $pee . "\n";
|
$pee = $pee . "\n";
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.0-beta3-43878';
|
$wp_version = '5.0-beta3-43879';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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