Query: Introduce the `content_pagination` filter, which makes it possible to manipulate how post content is split into "pages" in `WP_Query::setup_postdata()`.

The "pages" — or chunks of post content – are determined by splitting based on the presence of `<!-- nextpage -->` tags in the post content.

Props sirzooro, chriscct7.
Fixes #9911.

Built from https://develop.svn.wordpress.org/trunk@35285


git-svn-id: http://core.svn.wordpress.org/trunk@35251 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Drew Jaynes 2015-10-20 06:33:27 +00:00
parent afe975d754
commit 7771205935
2 changed files with 26 additions and 6 deletions

View File

@ -4771,8 +4771,6 @@ class WP_Query {
$content = $post->post_content; $content = $post->post_content;
if ( false !== strpos( $content, '<!--nextpage-->' ) ) { if ( false !== strpos( $content, '<!--nextpage-->' ) ) {
if ( $page > 1 )
$more = 1;
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content ); $content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content ); $content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content ); $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
@ -4782,13 +4780,35 @@ class WP_Query {
$content = substr( $content, 15 ); $content = substr( $content, 15 );
$pages = explode('<!--nextpage-->', $content); $pages = explode('<!--nextpage-->', $content);
$numpages = count($pages);
if ( $numpages > 1 )
$multipage = 1;
} else { } else {
$pages = array( $post->post_content ); $pages = array( $post->post_content );
} }
/**
* Filter the "pages" derived from splitting the post content.
*
* "Pages" are determined by splitting the post content based on the presence
* of `<!-- nextpage -->` tags.
*
* @since 4.4.0
*
* @param array $pages Array of "pages" derived from the post content.
* of `<!-- nextpage -->` tags..
* @param WP_Post $post Current post object.
*/
$pages = apply_filters( 'content_pagination', $pages, $post );
$numpages = count( $pages );
if ( $numpages > 1 ) {
if ( $page > 1 ) {
$more = 1;
}
$multipage = 1;
} else {
$multipage = 0;
}
/** /**
* Fires once the post data has been setup. * Fires once the post data has been setup.
* *

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-35284'; $wp_version = '4.4-alpha-35285';
/** /**
* 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.