Remove wp_parse_post_content(), get_paged_content(), paginate_content() from 3.6, and remove the new $id parameters for get_the_content() and the_content().

The content parsing functions are good abstractions, but are no longer needed by core and are too closely tied to legacy globals, rather than paving a new path.

For get_the_content() and the_content(), this only worsens the function prototype. It muddies theme-specific display (more links, etc) with filtered content. `apply_filters( 'the_content', $post->post_content )` is sufficient practice for now.

see #24330, [24301]. see #23625, [23804].



git-svn-id: http://core.svn.wordpress.org/trunk@24598 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-07-09 05:22:50 +00:00
parent b578f36b54
commit 092a33115c
3 changed files with 22 additions and 99 deletions

View File

@ -160,21 +160,12 @@ function get_the_guid( $id = 0 ) {
* *
* @param string $more_link_text Optional. Content for when there is more text. * @param string $more_link_text Optional. Content for when there is more text.
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
* @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
*/ */
function the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { function the_content( $more_link_text = null, $strip_teaser = false) {
$post = get_post( $id ); $content = get_the_content( $more_link_text, $strip_teaser );
$content = apply_filters( 'the_content', $content );
/* $content = str_replace( ']]>', ']]>', $content );
* Filter: the_content echo $content;
*
* param string Post content as returned by get_the_content()
* param int The ID of the post to which the content belongs. This was introduced
* in 3.6.0 and is not reliably passed by all plugins and themes that
* directly apply the_content. As such, it is not considered portable.
*/
$content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser, $post->ID ), $post->ID );
echo str_replace( ']]>', ']]>', $content );
} }
/** /**
@ -184,19 +175,12 @@ function the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
* *
* @param string $more_link_text Optional. Content for when there is more text. * @param string $more_link_text Optional. Content for when there is more text.
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
* @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
* @return string * @return string
*/ */
function get_the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { function get_the_content( $more_link_text = null, $strip_teaser = false ) {
global $page, $more, $preview; global $page, $more, $preview, $pages, $multipage;
$post = get_post( $id ); $post = get_post();
// Avoid parsing again if the post is the same one parsed by setup_postdata().
// The extract() will set up $pages and $multipage.
if ( $post->ID != get_post()->ID )
extract( wp_parse_post_content( $post, false ) );
else
global $pages, $multipage;
if ( null === $more_link_text ) if ( null === $more_link_text )
$more_link_text = __( '(more…)' ); $more_link_text = __( '(more…)' );

View File

@ -4970,28 +4970,3 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache
update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
} }
} }
/**
* Parse post content for pagination
*
* @since 3.6.0
*
* @uses paginate_content()
*
* @param object $post The post object.
* @return array An array of values used for paginating the parsed content.
*/
function wp_parse_post_content( $post ) {
$numpages = 1;
if ( strpos( $post->post_content, '<!--nextpage-->' ) ) {
$multipage = 1;
$pages = paginate_content( $post->post_content );
$numpages = count( $pages );
} else {
$pages = array( $post->post_content );
$multipage = 0;
}
return compact( 'multipage', 'pages', 'numpages' );
}

View File

@ -3629,52 +3629,6 @@ function wp_old_slug_redirect() {
exit; exit;
endif; endif;
} }
/**
* Split the passed content by <!--nextpage-->
*
* @since 3.6.0
*
* @param string $content Content to split.
* @return array Paged content.
*/
function paginate_content( $content ) {
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
return explode( '<!--nextpage-->', $content );
}
/**
* Return content offset by $page
*
* @since 3.6.0
*
* @param string $content
* @param int $paged
* @return string
*/
function get_paged_content( $content = '', $paged = 0 ) {
global $page;
if ( empty( $page ) )
$page = 1;
if ( empty( $paged ) )
$paged = $page;
if ( empty( $content ) ) {
$post = get_post();
if ( empty( $post ) )
return '';
$content = $post->post_content;
}
$pages = paginate_content( $content );
if ( isset( $pages[$paged - 1] ) )
return $pages[$paged - 1];
return reset( $pages );
}
/** /**
* Set up global post data. * Set up global post data.
@ -3695,16 +3649,26 @@ function setup_postdata( $post ) {
$currentday = mysql2date('d.m.y', $post->post_date, false); $currentday = mysql2date('d.m.y', $post->post_date, false);
$currentmonth = mysql2date('m', $post->post_date, false); $currentmonth = mysql2date('m', $post->post_date, false);
$numpages = 1; $numpages = 1;
$multipage = 0;
$page = get_query_var('page'); $page = get_query_var('page');
if ( ! $page ) if ( ! $page )
$page = 1; $page = 1;
if ( is_single() || is_page() || is_feed() ) if ( is_single() || is_page() || is_feed() )
$more = 1; $more = 1;
$content = $post->post_content;
extract( wp_parse_post_content( $post, false ) ); if ( strpos( $content, '<!--nextpage-->' ) ) {
if ( $page > 1 )
if ( $multipage && ( $page > 1 ) )
$more = 1; $more = 1;
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
$pages = explode('<!--nextpage-->', $content);
$numpages = count($pages);
if ( $numpages > 1 )
$multipage = 1;
} else {
$pages = array( $post->post_content );
}
do_action_ref_array('the_post', array(&$post)); do_action_ref_array('the_post', array(&$post));