<!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>[20423] trunk: Pass post_type to clean_post_cache() instead of attempting to fetch a post object since the post may have been deleted.</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, #logmsg > ol { margin-left: 0; 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/20423">20423</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-04-10 16:09:44 +0000 (Tue, 10 Apr 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Pass post_type to clean_post_cache() instead of attempting to fetch a post object since the post may have been deleted.

Props leewillis77
see <a href="http://core.trac.wordpress.org/ticket/19690">#19690</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswppostslisttablephp">trunk/wp-admin/includes/class-wp-posts-list-table.php</a></li>
<li><a href="#trunkwpincludescommentphp">trunk/wp-includes/comment.php</a></li>
<li><a href="#trunkwpincludesdeprecatedphp">trunk/wp-includes/deprecated.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-posts-list-table.php (20422 => 20423)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-posts-list-table.php        2012-04-10 03:18:48 UTC (rev 20422)
+++ trunk/wp-admin/includes/class-wp-posts-list-table.php        2012-04-10 16:09:44 UTC (rev 20423)
</span><span class="lines">@@ -360,7 +360,7 @@
</span><span class="cx">                                 if ( $page-&gt;post_parent == $page-&gt;ID ) {
</span><span class="cx">                                         $page-&gt;post_parent = 0;
</span><span class="cx">                                         $wpdb-&gt;update( $wpdb-&gt;posts, array( 'post_parent' =&gt; 0 ), array( 'ID' =&gt; $page-&gt;ID ) );
</span><del>-                                        clean_page_cache( $page-&gt;ID );
</del><ins>+                                        clean_post_cache( $page-&gt;ID, $page-&gt;post_type );
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 if ( 0 == $page-&gt;post_parent )
</span></span></pre></div>
<a id="trunkwpincludescommentphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/comment.php (20422 => 20423)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/comment.php        2012-04-10 03:18:48 UTC (rev 20422)
+++ trunk/wp-includes/comment.php        2012-04-10 16:09:44 UTC (rev 20423)
</span><span class="lines">@@ -1583,10 +1583,7 @@
</span><span class="cx">         $new = (int) $wpdb-&gt;get_var( $wpdb-&gt;prepare(&quot;SELECT COUNT(*) FROM $wpdb-&gt;comments WHERE comment_post_ID = %d AND comment_approved = '1'&quot;, $post_id) );
</span><span class="cx">         $wpdb-&gt;update( $wpdb-&gt;posts, array('comment_count' =&gt; $new), array('ID' =&gt; $post_id) );
</span><span class="cx"> 
</span><del>-        if ( 'page' == $post-&gt;post_type )
-                clean_page_cache( $post_id );
-        else
-                clean_post_cache( $post_id );
</del><ins>+        clean_post_cache( $post_id, $post-&gt;post_type );
</ins><span class="cx"> 
</span><span class="cx">         do_action('wp_update_comment_count', $post_id, $new, $old);
</span><span class="cx">         do_action('edit_post', $post_id, $post);
</span></span></pre></div>
<a id="trunkwpincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/deprecated.php (20422 => 20423)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2012-04-10 03:18:48 UTC (rev 20422)
+++ trunk/wp-includes/deprecated.php        2012-04-10 16:09:44 UTC (rev 20423)
</span><span class="lines">@@ -3116,4 +3116,39 @@
</span><span class="cx">         );
</span><span class="cx"> 
</span><span class="cx">         return $theme_data;
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
+
+/**
+ * Alias of update_post_cache().
+ *
+ * @see update_post_cache() Posts and pages are the same, alias is intentional
+ *
+ * @since 1.5.1
+ * @deprecated 3.4.0
+ *
+ * @param array $pages list of page objects
+ */
+function update_page_cache( &amp;$pages ) {
+        _deprecated_function( __FUNCTION__, 3.4, 'update_post_cache()' );
+
+        update_post_cache( $pages );
+}
+
+/**
+ * Will clean the page in the cache.
+ *
+ * Clean (read: delete) page from cache that matches $id. Will also clean cache
+ * associated with 'all_page_ids' and 'get_pages'.
+ *
+ * @since 2.0.0
+ * @deprecated 3.4.0
+ *
+ * @uses do_action() Will call the 'clean_page_cache' hook action.
+ *
+ * @param int $id Page ID to clean
+ */
+function clean_page_cache( $id ) {
+        _deprecated_function( __FUNCTION__, 3.4, 'clean_post_cache()' );
+
+        clean_post_cache( $id, 'page' );
+}
</ins></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (20422 => 20423)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2012-04-10 03:18:48 UTC (rev 20422)
+++ trunk/wp-includes/post.php        2012-04-10 16:09:44 UTC (rev 20423)
</span><span class="lines">@@ -1359,12 +1359,9 @@
</span><span class="cx">         global $wpdb;
</span><span class="cx"> 
</span><span class="cx">         $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
</span><del>-        $return = $wpdb-&gt;update($wpdb-&gt;posts, array('post_type' =&gt; $post_type), array('ID' =&gt; $post_id) );
</del><ins>+        $return = $wpdb-&gt;update( $wpdb-&gt;posts, array('post_type' =&gt; $post_type), array('ID' =&gt; $post_id) );
</ins><span class="cx"> 
</span><del>-        if ( 'page' == $post_type )
-                clean_page_cache($post_id);
-        else
-                clean_post_cache($post_id);
</del><ins>+        clean_post_cache( $post_id, $post_type );
</ins><span class="cx"> 
</span><span class="cx">         return $return;
</span><span class="cx"> }
</span><span class="lines">@@ -2056,15 +2053,11 @@
</span><span class="cx">         $wpdb-&gt;delete( $wpdb-&gt;posts, array( 'ID' =&gt; $postid ) );
</span><span class="cx">         do_action( 'deleted_post', $postid );
</span><span class="cx"> 
</span><del>-        if ( 'page' == $post-&gt;post_type ) {
-                clean_page_cache($postid);
-        } else {
-                clean_post_cache($postid);
-        }
</del><ins>+        clean_post_cache( $postid, $post-&gt;post_type );
</ins><span class="cx"> 
</span><span class="cx">         if ( is_post_type_hierarchical( $post-&gt;post_type ) ) {
</span><span class="cx">                 foreach ( (array) $children as $child )
</span><del>-                        clean_post_cache( $child-&gt;ID );
</del><ins>+                        clean_post_cache( $child-&gt;ID, $child-&gt;post_type );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
</span><span class="lines">@@ -2643,10 +2636,7 @@
</span><span class="cx"> 
</span><span class="cx">         $current_guid = get_post_field( 'guid', $post_ID );
</span><span class="cx"> 
</span><del>-        if ( 'page' == $data['post_type'] )
-                clean_page_cache($post_ID);
-        else
-                clean_post_cache($post_ID);
</del><ins>+        clean_post_cache( $post_ID, $data['post_type'] );
</ins><span class="cx"> 
</span><span class="cx">         // Set GUID
</span><span class="cx">         if ( !$update &amp;&amp; '' == $current_guid )
</span><span class="lines">@@ -3535,7 +3525,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Update cache.
</span><del>-        update_page_cache($pages);
</del><ins>+        update_post_cache( $pages );
</ins><span class="cx"> 
</span><span class="cx">         if ( $child_of || $hierarchical )
</span><span class="cx">                 $pages = &amp; get_page_children($child_of, $pages);
</span><span class="lines">@@ -3751,7 +3741,7 @@
</span><span class="cx">         if ( $file )
</span><span class="cx">                 update_attached_file( $post_ID, $file );
</span><span class="cx"> 
</span><del>-        clean_post_cache($post_ID);
</del><ins>+        clean_post_cache( $post_ID, $post_type );
</ins><span class="cx"> 
</span><span class="cx">         if ( ! empty( $context ) )
</span><span class="cx">                 add_post_meta( $post_ID, '_wp_attachment_context', $context, true );
</span><span class="lines">@@ -3864,7 +3854,7 @@
</span><span class="cx">         if ( ! empty($file) )
</span><span class="cx">                 @ unlink($file);
</span><span class="cx"> 
</span><del>-        clean_post_cache($post_id);
</del><ins>+        clean_post_cache( $post_id, $post-&gt;post_type );
</ins><span class="cx"> 
</span><span class="cx">         return $post;
</span><span class="cx"> }
</span><span class="lines">@@ -4314,20 +4304,18 @@
</span><span class="cx"> /**
</span><span class="cx">  * Updates posts in cache.
</span><span class="cx">  *
</span><del>- * @usedby update_page_cache() Aliased by this function.
- *
</del><span class="cx">  * @package WordPress
</span><span class="cx">  * @subpackage Cache
</span><span class="cx">  * @since 1.5.1
</span><span class="cx">  *
</span><span class="cx">  * @param array $posts Array of post objects
</span><span class="cx">  */
</span><del>-function update_post_cache(&amp;$posts) {
-        if ( !$posts )
</del><ins>+function update_post_cache( &amp;$posts ) {
+        if ( ! $posts )
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">         foreach ( $posts as $post )
</span><del>-                wp_cache_add($post-&gt;ID, $post, 'posts');
</del><ins>+                wp_cache_add( $post-&gt;ID, $post, 'posts' );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -4348,11 +4336,12 @@
</span><span class="cx">  * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
</span><span class="cx">  *
</span><span class="cx">  * @param int $id The Post ID in the cache to clean
</span><ins>+ * @param string $post_type The post_type of the post. Defaults to &quot;post&quot;
</ins><span class="cx">  */
</span><del>-function clean_post_cache($id) {
</del><ins>+function clean_post_cache($id, $post_type = 'post') {
</ins><span class="cx">         global $_wp_suspend_cache_invalidation, $wpdb;
</span><span class="cx"> 
</span><del>-        if ( !empty($_wp_suspend_cache_invalidation) )
</del><ins>+        if ( ! empty( $_wp_suspend_cache_invalidation ) )
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">         $id = (int) $id;
</span><span class="lines">@@ -4360,23 +4349,27 @@
</span><span class="cx">         if ( 0 === $id )
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        $post = get_post( $id );
-
</del><span class="cx">         wp_cache_delete($id, 'posts');
</span><span class="cx">         wp_cache_delete($id, 'post_meta');
</span><span class="cx"> 
</span><del>-        clean_object_term_cache( $id, $post-&gt;post_type );
</del><ins>+        clean_object_term_cache( $id, $post_type );
</ins><span class="cx"> 
</span><span class="cx">         wp_cache_delete( 'wp_get_archives', 'general' );
</span><span class="cx"> 
</span><del>-        do_action('clean_post_cache', $id);
</del><ins>+        do_action( 'clean_post_cache', $id, $post_type );
</ins><span class="cx"> 
</span><del>-        if ( $children = $wpdb-&gt;get_col( $wpdb-&gt;prepare(&quot;SELECT ID FROM $wpdb-&gt;posts WHERE post_parent = %d&quot;, $id) ) ) {
</del><ins>+        if ( 'page' == $post_type ) {
+                wp_cache_delete( 'all_page_ids', 'posts' );
+                wp_cache_delete( 'get_pages', 'posts' );
+                do_action( 'clean_page_cache', $id );
+        }
+
+        if ( $children = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT ID, post_type FROM $wpdb-&gt;posts WHERE post_parent = %d&quot;, $id) ) ) {
</ins><span class="cx">                 foreach ( $children as $cid ) {
</span><span class="cx">                         // Loop detection
</span><del>-                        if ( $cid == $id )
</del><ins>+                        if ( $cid-&gt;ID == $id )
</ins><span class="cx">                                 continue;
</span><del>-                        clean_post_cache( $cid );
</del><ins>+                        clean_post_cache( $cid-&gt;ID, $cid-&gt;post_type );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -4385,44 +4378,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Alias of update_post_cache().
- *
- * @see update_post_cache() Posts and pages are the same, alias is intentional
- *
- * @package WordPress
- * @subpackage Cache
- * @since 1.5.1
- *
- * @param array $pages list of page objects
- */
-function update_page_cache(&amp;$pages) {
-        update_post_cache($pages);
-}
-
-/**
- * Will clean the page in the cache.
- *
- * Clean (read: delete) page from cache that matches $id. Will also clean cache
- * associated with 'all_page_ids' and 'get_pages'.
- *
- * @package WordPress
- * @subpackage Cache
- * @since 2.0.0
- *
- * @uses do_action() Will call the 'clean_page_cache' hook action.
- *
- * @param int $id Page ID to clean
- */
-function clean_page_cache($id) {
-        clean_post_cache($id);
-
-        wp_cache_delete( 'all_page_ids', 'posts' );
-        wp_cache_delete( 'get_pages', 'posts' );
-
-        do_action('clean_page_cache', $id);
-}
-
-/**
</del><span class="cx">  * Call major cache updating functions for list of Post objects.
</span><span class="cx">  *
</span><span class="cx">  * @package WordPress
</span><span class="lines">@@ -4629,11 +4584,7 @@
</span><span class="cx">  * @param object $post Object type containing the post information
</span><span class="cx">  */
</span><span class="cx"> function _save_post_hook($post_id, $post) {
</span><del>-        if ( $post-&gt;post_type == 'page' ) {
-                clean_page_cache($post_id);
-        } else {
-                clean_post_cache($post_id);
-        }
</del><ins>+        clean_post_cache($post_id, $post-&gt;post_type);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -5361,4 +5312,4 @@
</span><span class="cx"> 
</span><span class="cx">                 update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
</span><span class="cx">         }
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
</ins></span></pre>
</div>
</div>

</body>
</html>