* Introduce wp_parse_post_content() and use it in setup_postdata(), get_the_content(), and get_the_remaining_content().
* Add a post ID argument to the_content(), get_the_content(), the_remaining_content(), and get_the_remaining_content(). * Pass the post ID to the the_content filter. * Remove the format_pages global. * Declare format_content and split_content as vars in WP_Post. * phpdoc for the the_content filter that documents the new ID argument and denotes it as not-so-portable. Props gcorne, DrewAPicture, duck_, aaroncampbell see #24330 git-svn-id: http://core.svn.wordpress.org/trunk@24301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
10a5505b64
commit
a2b4bc456f
|
@ -1749,7 +1749,7 @@ function do_trackbacks($post_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty($post->post_excerpt) )
|
if ( empty($post->post_excerpt) )
|
||||||
$excerpt = apply_filters('the_content', $post->post_content);
|
$excerpt = apply_filters('the_content', $post->post_content, $post->ID);
|
||||||
else
|
else
|
||||||
$excerpt = apply_filters('the_excerpt', $post->post_excerpt);
|
$excerpt = apply_filters('the_excerpt', $post->post_excerpt);
|
||||||
$excerpt = str_replace(']]>', ']]>', $excerpt);
|
$excerpt = str_replace(']]>', ']]>', $excerpt);
|
||||||
|
|
|
@ -136,7 +136,7 @@ add_filter( 'the_title', 'convert_chars' );
|
||||||
add_filter( 'the_title', 'trim' );
|
add_filter( 'the_title', 'trim' );
|
||||||
add_filter( 'the_title', '_post_formats_title', 10, 2 );
|
add_filter( 'the_title', '_post_formats_title', 10, 2 );
|
||||||
|
|
||||||
add_filter( 'the_content', 'post_formats_compat', 7 );
|
add_filter( 'the_content', 'post_formats_compat', 7, 2 );
|
||||||
add_filter( 'the_content', 'wptexturize' );
|
add_filter( 'the_content', 'wptexturize' );
|
||||||
add_filter( 'the_content', 'convert_smilies' );
|
add_filter( 'the_content', 'convert_smilies' );
|
||||||
add_filter( 'the_content', 'convert_chars' );
|
add_filter( 'the_content', 'convert_chars' );
|
||||||
|
|
|
@ -866,12 +866,15 @@ function the_post_format_url() {
|
||||||
*
|
*
|
||||||
* @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.
|
||||||
* @return string The content minus the extracted post format content.
|
* @return string The content minus the extracted post format content.
|
||||||
*/
|
*/
|
||||||
function get_the_remaining_content( $more_link_text = null, $strip_teaser = false ) {
|
function get_the_remaining_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
|
||||||
global $more, $page, $format_pages, $multipage, $preview;
|
global $more, $page, $preview;
|
||||||
|
|
||||||
$post = get_post();
|
$post = get_post( $id );
|
||||||
|
|
||||||
|
extract( wp_parse_post_content( $post, true ) );
|
||||||
|
|
||||||
if ( null === $more_link_text )
|
if ( null === $more_link_text )
|
||||||
$more_link_text = __( '(more…)' );
|
$more_link_text = __( '(more…)' );
|
||||||
|
@ -880,13 +883,13 @@ function get_the_remaining_content( $more_link_text = null, $strip_teaser = fals
|
||||||
$has_teaser = false;
|
$has_teaser = false;
|
||||||
|
|
||||||
// If post password required and it doesn't match the cookie.
|
// If post password required and it doesn't match the cookie.
|
||||||
if ( post_password_required() )
|
if ( post_password_required( $post ) )
|
||||||
return get_the_password_form();
|
return get_the_password_form( $post );
|
||||||
|
|
||||||
if ( $page > count( $format_pages ) ) // if the requested page doesn't exist
|
if ( $page > count( $pages ) ) // if the requested page doesn't exist
|
||||||
$page = count( $format_pages ); // give them the highest numbered page that DOES exist
|
$page = count( $pages ); // give them the highest numbered page that DOES exist
|
||||||
|
|
||||||
$content = $format_pages[$page-1];
|
$content = $pages[$page-1];
|
||||||
if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
|
if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
|
||||||
$content = explode( $matches[0], $content, 2 );
|
$content = explode( $matches[0], $content, 2 );
|
||||||
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
|
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
|
||||||
|
@ -931,13 +934,16 @@ function get_the_remaining_content( $more_link_text = null, $strip_teaser = fals
|
||||||
*
|
*
|
||||||
* @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_remaining_content( $more_link_text = null, $strip_teaser = false ) {
|
function the_remaining_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
|
||||||
$extra = get_the_remaining_content( $more_link_text, $strip_teaser );
|
$post = get_post( $id );
|
||||||
|
|
||||||
|
$extra = get_the_remaining_content( $more_link_text, $strip_teaser, $post->ID );
|
||||||
|
|
||||||
remove_filter( 'the_content', 'post_formats_compat', 7 );
|
remove_filter( 'the_content', 'post_formats_compat', 7 );
|
||||||
$content = apply_filters( 'the_content', $extra );
|
$content = apply_filters( 'the_content', $extra, $post->ID );
|
||||||
add_filter( 'the_content', 'post_formats_compat', 7 );
|
add_filter( 'the_content', 'post_formats_compat', 7, 2 );
|
||||||
|
|
||||||
echo str_replace( ']]>', ']]>', $content );
|
echo str_replace( ']]>', ']]>', $content );
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,9 +160,20 @@ 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 ) {
|
function the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
|
||||||
$content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser ) );
|
$post = get_post( $id );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Filter: the_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 );
|
echo str_replace( ']]>', ']]>', $content );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,12 +184,19 @@ function the_content( $more_link_text = null, $strip_teaser = false ) {
|
||||||
*
|
*
|
||||||
* @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 ) {
|
function get_the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
|
||||||
global $more, $page, $pages, $multipage, $preview;
|
global $page, $more, $preview;
|
||||||
|
|
||||||
$post = get_post();
|
$post = get_post( $id );
|
||||||
|
// 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 != $GLOBALS['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…)' );
|
||||||
|
@ -187,8 +205,8 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) {
|
||||||
$has_teaser = false;
|
$has_teaser = false;
|
||||||
|
|
||||||
// If post password required and it doesn't match the cookie.
|
// If post password required and it doesn't match the cookie.
|
||||||
if ( post_password_required() )
|
if ( post_password_required( $post ) )
|
||||||
return get_the_password_form();
|
return get_the_password_form( $post );
|
||||||
|
|
||||||
if ( $page > count( $pages ) ) // if the requested page doesn't exist
|
if ( $page > count( $pages ) ) // if the requested page doesn't exist
|
||||||
$page = count( $pages ); // give them the highest numbered page that DOES exist
|
$page = count( $pages ); // give them the highest numbered page that DOES exist
|
||||||
|
@ -566,7 +584,7 @@ function get_body_class( $class = '' ) {
|
||||||
*
|
*
|
||||||
* @since 2.7.0
|
* @since 2.7.0
|
||||||
*
|
*
|
||||||
* @param int|object $post An optional post. Global $post used if not provided.
|
* @param int|WP_Post $post An optional post. Global $post used if not provided.
|
||||||
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
|
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
|
||||||
*/
|
*/
|
||||||
function post_password_required( $post = null ) {
|
function post_password_required( $post = null ) {
|
||||||
|
@ -1225,11 +1243,11 @@ function prepend_attachment($content) {
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @uses apply_filters() Calls 'the_password_form' filter on output.
|
* @uses apply_filters() Calls 'the_password_form' filter on output.
|
||||||
*
|
* @param int|WP_Post $post Optional. A post id or post object. Defaults to the current post when in The Loop, undefined otherwise.
|
||||||
* @return string HTML content for password form for password protected post.
|
* @return string HTML content for password form for password protected post.
|
||||||
*/
|
*/
|
||||||
function get_the_password_form() {
|
function get_the_password_form( $post = 0 ) {
|
||||||
$post = get_post();
|
$post = get_post( $post );
|
||||||
$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
|
$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
|
||||||
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
|
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
|
||||||
<p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
|
<p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
|
||||||
|
|
|
@ -567,6 +567,26 @@ final class WP_Post {
|
||||||
*/
|
*/
|
||||||
public $filter;
|
public $filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private variable used by post formats to cache parsed content.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
public $format_content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private variable used by post formats to cache parsed content.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
public $split_content;
|
||||||
|
|
||||||
public static function get_instance( $post_id ) {
|
public static function get_instance( $post_id ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
@ -4962,3 +4982,56 @@ 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.
|
||||||
|
* @param bool $remaining Whether to parse post formats from the content. Defaults to false.
|
||||||
|
* @return array An array of values used for paginating the parsed content.
|
||||||
|
*/
|
||||||
|
function wp_parse_post_content( $post, $remaining = false ) {
|
||||||
|
$numpages = 1;
|
||||||
|
|
||||||
|
if ( $remaining ) {
|
||||||
|
$format = get_post_format( $post );
|
||||||
|
if ( $format && in_array( $format, array( 'image', 'audio', 'video', 'quote' ) ) ) {
|
||||||
|
// Call get_the_post_format_*() to set $post->split_content
|
||||||
|
switch ( $format ) {
|
||||||
|
case 'image':
|
||||||
|
get_the_post_format_image( 'full', $post );
|
||||||
|
break;
|
||||||
|
case 'audio':
|
||||||
|
get_the_post_format_media( 'audio', $post, 1 );
|
||||||
|
break;
|
||||||
|
case 'video':
|
||||||
|
get_the_post_format_media( 'video', $post, 1 );
|
||||||
|
break;
|
||||||
|
case 'quote':
|
||||||
|
get_the_post_format_quote( $post );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strpos( $post->post_content, '<!--nextpage-->' ) ) {
|
||||||
|
$multipage = 1;
|
||||||
|
if ( $remaining && isset( $post->split_content ) )
|
||||||
|
$pages = paginate_content( $post->split_content );
|
||||||
|
else
|
||||||
|
$pages = paginate_content( $post->post_content );
|
||||||
|
$numpages = count( $pages );
|
||||||
|
} else {
|
||||||
|
if ( $remaining && isset( $post->split_content ) )
|
||||||
|
$pages = array( $post->split_content );
|
||||||
|
else
|
||||||
|
$pages = array( $post->post_content );
|
||||||
|
$multipage = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return compact( 'multipage', 'pages', 'numpages' );
|
||||||
|
}
|
||||||
|
|
|
@ -3681,8 +3681,8 @@ function get_paged_content( $content = '', $paged = 0 ) {
|
||||||
* @uses do_action_ref_array() Calls 'the_post'
|
* @uses do_action_ref_array() Calls 'the_post'
|
||||||
* @return bool True when finished.
|
* @return bool True when finished.
|
||||||
*/
|
*/
|
||||||
function setup_postdata($post) {
|
function setup_postdata( $post ) {
|
||||||
global $id, $authordata, $currentday, $currentmonth, $page, $pages, $format_pages, $multipage, $more, $numpages;
|
global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
|
||||||
|
|
||||||
$id = (int) $post->ID;
|
$id = (int) $post->ID;
|
||||||
|
|
||||||
|
@ -3692,49 +3692,15 @@ function setup_postdata($post) {
|
||||||
$currentmonth = mysql2date('m', $post->post_date, false);
|
$currentmonth = mysql2date('m', $post->post_date, false);
|
||||||
$numpages = 1;
|
$numpages = 1;
|
||||||
$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;
|
||||||
$split_content = $content = $post->post_content;
|
|
||||||
$format = get_post_format( $post );
|
|
||||||
if ( $format && in_array( $format, array( 'image', 'audio', 'video', 'quote' ) ) ) {
|
|
||||||
switch ( $format ) {
|
|
||||||
case 'image':
|
|
||||||
get_the_post_format_image( 'full', $post );
|
|
||||||
if ( isset( $post->split_content ) )
|
|
||||||
$split_content = $post->split_content;
|
|
||||||
break;
|
|
||||||
case 'audio':
|
|
||||||
get_the_post_format_media( 'audio', $post, 1 );
|
|
||||||
if ( isset( $post->split_content ) )
|
|
||||||
$split_content = $post->split_content;
|
|
||||||
break;
|
|
||||||
case 'video':
|
|
||||||
get_the_post_format_media( 'video', $post, 1 );
|
|
||||||
if ( isset( $post->split_content ) )
|
|
||||||
$split_content = $post->split_content;
|
|
||||||
break;
|
|
||||||
case 'quote':
|
|
||||||
get_the_post_format_quote( $post );
|
|
||||||
if ( isset( $post->split_content ) )
|
|
||||||
$split_content = $post->split_content;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( strpos( $content, '<!--nextpage-->' ) ) {
|
extract( wp_parse_post_content( $post, false ) );
|
||||||
if ( $page > 1 )
|
|
||||||
|
if ( $multipage && ( $page > 1 ) )
|
||||||
$more = 1;
|
$more = 1;
|
||||||
$multipage = 1;
|
|
||||||
$pages = paginate_content( $content );
|
|
||||||
$format_pages = paginate_content( $split_content );
|
|
||||||
$numpages = count( $pages );
|
|
||||||
} else {
|
|
||||||
$pages = array( $post->post_content );
|
|
||||||
$format_pages = array( $split_content );
|
|
||||||
$multipage = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
do_action_ref_array('the_post', array(&$post));
|
do_action_ref_array('the_post', array(&$post));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue