<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[24301] trunk/wp-includes: * Introduce wp_parse_post_content() and use it in setup_postdata(), get_the_content(), and get_the_remaining_content().</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/24301">24301</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2013-05-20 11:05:50 +0000 (Mon, 20 May 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>* 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 <a href="http://core.trac.wordpress.org/ticket/24330">#24330</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescommentphp">trunk/wp-includes/comment.php</a></li>
<li><a href="#trunkwpincludesdefaultfiltersphp">trunk/wp-includes/default-filters.php</a></li>
<li><a href="#trunkwpincludespostformatsphp">trunk/wp-includes/post-formats.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludescommentphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/comment.php (24300 => 24301)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/comment.php 2013-05-20 04:58:58 UTC (rev 24300)
+++ trunk/wp-includes/comment.php 2013-05-20 11:05:50 UTC (rev 24301)
</span><span class="lines">@@ -1749,7 +1749,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if ( empty($post->post_excerpt) )
</span><del>- $excerpt = apply_filters('the_content', $post->post_content);
</del><ins>+ $excerpt = apply_filters('the_content', $post->post_content, $post->ID);
</ins><span class="cx"> else
</span><span class="cx"> $excerpt = apply_filters('the_excerpt', $post->post_excerpt);
</span><span class="cx"> $excerpt = str_replace(']]>', ']]>', $excerpt);
</span></span></pre></div>
<a id="trunkwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/default-filters.php (24300 => 24301)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/default-filters.php 2013-05-20 04:58:58 UTC (rev 24300)
+++ trunk/wp-includes/default-filters.php 2013-05-20 11:05:50 UTC (rev 24301)
</span><span class="lines">@@ -136,7 +136,7 @@
</span><span class="cx"> add_filter( 'the_title', 'trim' );
</span><span class="cx"> add_filter( 'the_title', '_post_formats_title', 10, 2 );
</span><span class="cx">
</span><del>-add_filter( 'the_content', 'post_formats_compat', 7 );
</del><ins>+add_filter( 'the_content', 'post_formats_compat', 7, 2 );
</ins><span class="cx"> add_filter( 'the_content', 'wptexturize' );
</span><span class="cx"> add_filter( 'the_content', 'convert_smilies' );
</span><span class="cx"> add_filter( 'the_content', 'convert_chars' );
</span></span></pre></div>
<a id="trunkwpincludespostformatsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-formats.php (24300 => 24301)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-formats.php 2013-05-20 04:58:58 UTC (rev 24300)
+++ trunk/wp-includes/post-formats.php 2013-05-20 11:05:50 UTC (rev 24301)
</span><span class="lines">@@ -866,13 +866,16 @@
</span><span class="cx"> *
</span><span class="cx"> * @param string $more_link_text Optional. Content for when there is more text.
</span><span class="cx"> * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
</span><ins>+ * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
</ins><span class="cx"> * @return string The content minus the extracted post format content.
</span><span class="cx"> */
</span><del>-function get_the_remaining_content( $more_link_text = null, $strip_teaser = false ) {
- global $more, $page, $format_pages, $multipage, $preview;
</del><ins>+function get_the_remaining_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
+ global $more, $page, $preview;
</ins><span class="cx">
</span><del>- $post = get_post();
</del><ins>+ $post = get_post( $id );
</ins><span class="cx">
</span><ins>+ extract( wp_parse_post_content( $post, true ) );
+
</ins><span class="cx"> if ( null === $more_link_text )
</span><span class="cx"> $more_link_text = __( '(more…)' );
</span><span class="cx">
</span><span class="lines">@@ -880,13 +883,13 @@
</span><span class="cx"> $has_teaser = false;
</span><span class="cx">
</span><span class="cx"> // If post password required and it doesn't match the cookie.
</span><del>- if ( post_password_required() )
- return get_the_password_form();
</del><ins>+ if ( post_password_required( $post ) )
+ return get_the_password_form( $post );
</ins><span class="cx">
</span><del>- if ( $page > count( $format_pages ) ) // if the requested page doesn't exist
- $page = count( $format_pages ); // give them the highest numbered page that DOES exist
</del><ins>+ if ( $page > count( $pages ) ) // if the requested page doesn't exist
+ $page = count( $pages ); // give them the highest numbered page that DOES exist
</ins><span class="cx">
</span><del>- $content = $format_pages[$page-1];
</del><ins>+ $content = $pages[$page-1];
</ins><span class="cx"> if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
</span><span class="cx"> $content = explode( $matches[0], $content, 2 );
</span><span class="cx"> if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
</span><span class="lines">@@ -931,13 +934,16 @@
</span><span class="cx"> *
</span><span class="cx"> * @param string $more_link_text Optional. Content for when there is more text.
</span><span class="cx"> * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
</span><ins>+ * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
</ins><span class="cx"> */
</span><del>-function the_remaining_content( $more_link_text = null, $strip_teaser = false ) {
- $extra = get_the_remaining_content( $more_link_text, $strip_teaser );
</del><ins>+function the_remaining_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
+ $post = get_post( $id );
</ins><span class="cx">
</span><ins>+ $extra = get_the_remaining_content( $more_link_text, $strip_teaser, $post->ID );
+
</ins><span class="cx"> remove_filter( 'the_content', 'post_formats_compat', 7 );
</span><del>- $content = apply_filters( 'the_content', $extra );
- add_filter( 'the_content', 'post_formats_compat', 7 );
</del><ins>+ $content = apply_filters( 'the_content', $extra, $post->ID );
+ add_filter( 'the_content', 'post_formats_compat', 7, 2 );
</ins><span class="cx">
</span><span class="cx"> echo str_replace( ']]>', ']]>', $content );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (24300 => 24301)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php 2013-05-20 04:58:58 UTC (rev 24300)
+++ trunk/wp-includes/post-template.php 2013-05-20 11:05:50 UTC (rev 24301)
</span><span class="lines">@@ -160,9 +160,20 @@
</span><span class="cx"> *
</span><span class="cx"> * @param string $more_link_text Optional. Content for when there is more text.
</span><span class="cx"> * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
</span><ins>+ * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
</ins><span class="cx"> */
</span><del>-function the_content( $more_link_text = null, $strip_teaser = false ) {
- $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser ) );
</del><ins>+function the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
+ $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 );
</ins><span class="cx"> echo str_replace( ']]>', ']]>', $content );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -173,12 +184,19 @@
</span><span class="cx"> *
</span><span class="cx"> * @param string $more_link_text Optional. Content for when there is more text.
</span><span class="cx"> * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
</span><ins>+ * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>-function get_the_content( $more_link_text = null, $strip_teaser = false ) {
- global $more, $page, $pages, $multipage, $preview;
</del><ins>+function get_the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
+ global $page, $more, $preview;
</ins><span class="cx">
</span><del>- $post = get_post();
</del><ins>+ $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;
</ins><span class="cx">
</span><span class="cx"> if ( null === $more_link_text )
</span><span class="cx"> $more_link_text = __( '(more…)' );
</span><span class="lines">@@ -187,8 +205,8 @@
</span><span class="cx"> $has_teaser = false;
</span><span class="cx">
</span><span class="cx"> // If post password required and it doesn't match the cookie.
</span><del>- if ( post_password_required() )
- return get_the_password_form();
</del><ins>+ if ( post_password_required( $post ) )
+ return get_the_password_form( $post );
</ins><span class="cx">
</span><span class="cx"> if ( $page > count( $pages ) ) // if the requested page doesn't exist
</span><span class="cx"> $page = count( $pages ); // give them the highest numbered page that DOES exist
</span><span class="lines">@@ -566,7 +584,7 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 2.7.0
</span><span class="cx"> *
</span><del>- * @param int|object $post An optional post. Global $post used if not provided.
</del><ins>+ * @param int|WP_Post $post An optional post. Global $post used if not provided.
</ins><span class="cx"> * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
</span><span class="cx"> */
</span><span class="cx"> function post_password_required( $post = null ) {
</span><span class="lines">@@ -1225,11 +1243,11 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 1.0.0
</span><span class="cx"> * @uses apply_filters() Calls 'the_password_form' filter on output.
</span><del>- *
</del><ins>+ * @param int|WP_Post $post Optional. A post id or post object. Defaults to the current post when in The Loop, undefined otherwise.
</ins><span class="cx"> * @return string HTML content for password form for password protected post.
</span><span class="cx"> */
</span><del>-function get_the_password_form() {
- $post = get_post();
</del><ins>+function get_the_password_form( $post = 0 ) {
+ $post = get_post( $post );
</ins><span class="cx"> $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
</span><span class="cx"> $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
</span><span class="cx"> <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (24300 => 24301)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php 2013-05-20 04:58:58 UTC (rev 24300)
+++ trunk/wp-includes/post.php 2013-05-20 11:05:50 UTC (rev 24301)
</span><span class="lines">@@ -567,6 +567,26 @@
</span><span class="cx"> */
</span><span class="cx"> public $filter;
</span><span class="cx">
</span><ins>+ /**
+ * 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;
+
</ins><span class="cx"> public static function get_instance( $post_id ) {
</span><span class="cx"> global $wpdb;
</span><span class="cx">
</span><span class="lines">@@ -4962,3 +4982,56 @@
</span><span class="cx"> update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+/**
+ * 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' );
+}
</ins></span></pre></div>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (24300 => 24301)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php 2013-05-20 04:58:58 UTC (rev 24300)
+++ trunk/wp-includes/query.php 2013-05-20 11:05:50 UTC (rev 24301)
</span><span class="lines">@@ -3681,8 +3681,8 @@
</span><span class="cx"> * @uses do_action_ref_array() Calls 'the_post'
</span><span class="cx"> * @return bool True when finished.
</span><span class="cx"> */
</span><del>-function setup_postdata($post) {
- global $id, $authordata, $currentday, $currentmonth, $page, $pages, $format_pages, $multipage, $more, $numpages;
</del><ins>+function setup_postdata( $post ) {
+ global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
</ins><span class="cx">
</span><span class="cx"> $id = (int) $post->ID;
</span><span class="cx">
</span><span class="lines">@@ -3692,49 +3692,15 @@
</span><span class="cx"> $currentmonth = mysql2date('m', $post->post_date, false);
</span><span class="cx"> $numpages = 1;
</span><span class="cx"> $page = get_query_var('page');
</span><del>- if ( !$page )
</del><ins>+ if ( ! $page )
</ins><span class="cx"> $page = 1;
</span><span class="cx"> if ( is_single() || is_page() || is_feed() )
</span><span class="cx"> $more = 1;
</span><del>- $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;
- }
- }
</del><span class="cx">
</span><del>- if ( strpos( $content, '<!--nextpage-->' ) ) {
- if ( $page > 1 )
</del><ins>+ extract( wp_parse_post_content( $post, false ) );
+
+ if ( $multipage && ( $page > 1 ) )
</ins><span class="cx"> $more = 1;
</span><del>- $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;
- }
</del><span class="cx">
</span><span class="cx"> do_action_ref_array('the_post', array(&$post));
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>