<!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>[20569] trunk: Accept a post object in clean_post_cache().</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/20569">20569</a></dd>
<dt>Author</dt> <dd>duck_</dd>
<dt>Date</dt> <dd>2012-04-23 22:04:35 +0000 (Mon, 23 Apr 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Accept a post object in clean_post_cache(). Fixes <a href="http://core.trac.wordpress.org/ticket/20486">#20486</a>.

The post_type can then be accessed to properly clean the taxonomy relationships cache.
The full object is useful in situations when an ID might reference a post that has been
removed from the database (e.g. wp_delete_post()).</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 (20568 => 20569)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-posts-list-table.php        2012-04-23 21:54:30 UTC (rev 20568)
+++ trunk/wp-admin/includes/class-wp-posts-list-table.php        2012-04-23 22:04:35 UTC (rev 20569)
</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_post_cache( $page-&gt;ID, $page-&gt;post_type );
</del><ins>+                                        clean_post_cache( $page );
</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 (20568 => 20569)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/comment.php        2012-04-23 21:54:30 UTC (rev 20568)
+++ trunk/wp-includes/comment.php        2012-04-23 22:04:35 UTC (rev 20569)
</span><span class="lines">@@ -1579,7 +1579,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>-        clean_post_cache( $post_id, $post-&gt;post_type );
</del><ins>+        clean_post_cache( $post );
</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 (20568 => 20569)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2012-04-23 21:54:30 UTC (rev 20568)
+++ trunk/wp-includes/deprecated.php        2012-04-23 22:04:35 UTC (rev 20569)
</span><span class="lines">@@ -3150,5 +3150,5 @@
</span><span class="cx"> function clean_page_cache( $id ) {
</span><span class="cx">         _deprecated_function( __FUNCTION__, 3.4, 'clean_post_cache()' );
</span><span class="cx"> 
</span><del>-        clean_post_cache( $id, 'page' );
</del><ins>+        clean_post_cache( $id );
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (20568 => 20569)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2012-04-23 21:54:30 UTC (rev 20568)
+++ trunk/wp-includes/post.php        2012-04-23 22:04:35 UTC (rev 20569)
</span><span class="lines">@@ -1361,7 +1361,7 @@
</span><span class="cx">         $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
</span><span class="cx">         $return = $wpdb-&gt;update( $wpdb-&gt;posts, array('post_type' =&gt; $post_type), array('ID' =&gt; $post_id) );
</span><span class="cx"> 
</span><del>-        clean_post_cache( $post_id, $post_type );
</del><ins>+        clean_post_cache( $post_id );
</ins><span class="cx"> 
</span><span class="cx">         return $return;
</span><span class="cx"> }
</span><span class="lines">@@ -2045,11 +2045,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>-        clean_post_cache( $postid, $post-&gt;post_type );
</del><ins>+        clean_post_cache( $post );
</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, $child-&gt;post_type );
</del><ins>+                        clean_post_cache( $child );
</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">@@ -2628,7 +2628,7 @@
</span><span class="cx"> 
</span><span class="cx">         $current_guid = get_post_field( 'guid', $post_ID );
</span><span class="cx"> 
</span><del>-        clean_post_cache( $post_ID, $data['post_type'] );
</del><ins>+        clean_post_cache( $post_ID );
</ins><span class="cx"> 
</span><span class="cx">         // Set GUID
</span><span class="cx">         if ( !$update &amp;&amp; '' == $current_guid )
</span><span class="lines">@@ -3733,7 +3733,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, $post_type );
</del><ins>+        clean_post_cache( $post_ID );
</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">@@ -3838,7 +3838,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, $post-&gt;post_type );
</del><ins>+        clean_post_cache( $post );
</ins><span class="cx"> 
</span><span class="cx">         return $post;
</span><span class="cx"> }
</span><span class="lines">@@ -4319,46 +4319,44 @@
</span><span class="cx">  *
</span><span class="cx">  * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
</span><span class="cx">  *
</span><del>- * @param int $id The Post ID in the cache to clean
- * @param string $post_type The post_type of the post. Defaults to &quot;post&quot;
</del><ins>+ * @param object|int $post The post object or ID to remove from the cache
</ins><span class="cx">  */
</span><del>-function clean_post_cache($id, $post_type = 'post') {
</del><ins>+function clean_post_cache( $post ) {
</ins><span class="cx">         global $_wp_suspend_cache_invalidation, $wpdb;
</span><span class="cx"> 
</span><span class="cx">         if ( ! empty( $_wp_suspend_cache_invalidation ) )
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        $id = (int) $id;
-
-        if ( 0 === $id )
</del><ins>+        $post = get_post( $post );
+        if ( empty( $post ) )
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        wp_cache_delete($id, 'posts');
-        wp_cache_delete($id, 'post_meta');
</del><ins>+        wp_cache_delete( $post-&gt;ID, 'posts' );
+        wp_cache_delete( $post-&gt;ID, 'post_meta' );
</ins><span class="cx"> 
</span><del>-        clean_object_term_cache( $id, $post_type );
</del><ins>+        clean_object_term_cache( $post-&gt;ID, $post-&gt;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, $post_type );
</del><ins>+        do_action( 'clean_post_cache', $post-&gt;ID, $post );
</ins><span class="cx"> 
</span><del>-        if ( 'page' == $post_type ) {
</del><ins>+        if ( 'page' == $post-&gt;post_type ) {
</ins><span class="cx">                 wp_cache_delete( 'all_page_ids', 'posts' );
</span><span class="cx">                 wp_cache_delete( 'get_pages', 'posts' );
</span><del>-                do_action( 'clean_page_cache', $id );
</del><ins>+                do_action( 'clean_page_cache', $post-&gt;ID );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( $children = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT ID, post_type FROM $wpdb-&gt;posts WHERE post_parent = %d&quot;, $id) ) ) {
-                foreach ( $children as $cid ) {
</del><ins>+        if ( $children = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT ID, post_type FROM $wpdb-&gt;posts WHERE post_parent = %d&quot;, $post-&gt;ID) ) ) {
+                foreach ( $children as $child ) {
</ins><span class="cx">                         // Loop detection
</span><del>-                        if ( $cid-&gt;ID == $id )
</del><ins>+                        if ( $child-&gt;ID == $post-&gt;ID )
</ins><span class="cx">                                 continue;
</span><del>-                        clean_post_cache( $cid-&gt;ID, $cid-&gt;post_type );
</del><ins>+                        clean_post_cache( $child );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( is_multisite() )
</span><del>-                wp_cache_delete( $wpdb-&gt;blogid . '-' . $id, 'global-posts' );
</del><ins>+                wp_cache_delete( $wpdb-&gt;blogid . '-' . $post-&gt;ID, 'global-posts' );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -4563,8 +4561,8 @@
</span><span class="cx">  * @param int $post_id The ID in the database table for the $post
</span><span class="cx">  * @param object $post Object type containing the post information
</span><span class="cx">  */
</span><del>-function _save_post_hook($post_id, $post) {
-        clean_post_cache($post_id, $post-&gt;post_type);
</del><ins>+function _save_post_hook( $post_id, $post ) {
+        clean_post_cache( $post );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>