Ticket #20486: 20486.2.diff

File 20486.2.diff, 5.4 KB (added by duck_, 13 months ago)
Line 
1Index: wp-includes/comment.php
2===================================================================
3--- wp-includes/comment.php     (revision 20481)
4+++ wp-includes/comment.php     (working copy)
5@@ -1579,7 +1579,7 @@
6        $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
7        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
8 
9-       clean_post_cache( $post_id, $post->post_type );
10+       clean_post_cache( $post );
11 
12        do_action('wp_update_comment_count', $post_id, $new, $old);
13        do_action('edit_post', $post_id, $post);
14Index: wp-includes/post.php
15===================================================================
16--- wp-includes/post.php        (revision 20481)
17+++ wp-includes/post.php        (working copy)
18@@ -1361,7 +1361,7 @@
19        $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
20        $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
21 
22-       clean_post_cache( $post_id, $post_type );
23+       clean_post_cache( $post_id );
24 
25        return $return;
26 }
27@@ -2045,11 +2045,11 @@
28        $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
29        do_action( 'deleted_post', $postid );
30 
31-       clean_post_cache( $postid, $post->post_type );
32+       clean_post_cache( $post );
33 
34        if ( is_post_type_hierarchical( $post->post_type ) ) {
35                foreach ( (array) $children as $child )
36-                       clean_post_cache( $child->ID, $child->post_type );
37+                       clean_post_cache( $child );
38        }
39 
40        wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
41@@ -2628,7 +2628,7 @@
42 
43        $current_guid = get_post_field( 'guid', $post_ID );
44 
45-       clean_post_cache( $post_ID, $data['post_type'] );
46+       clean_post_cache( $post_ID );
47 
48        // Set GUID
49        if ( !$update && '' == $current_guid )
50@@ -3733,7 +3733,7 @@
51        if ( $file )
52                update_attached_file( $post_ID, $file );
53 
54-       clean_post_cache( $post_ID, $post_type );
55+       clean_post_cache( $post_ID );
56 
57        if ( ! empty( $context ) )
58                add_post_meta( $post_ID, '_wp_attachment_context', $context, true );
59@@ -3838,7 +3838,7 @@
60        if ( ! empty($file) )
61                @ unlink($file);
62 
63-       clean_post_cache( $post_id, $post->post_type );
64+       clean_post_cache( $post );
65 
66        return $post;
67 }
68@@ -4319,46 +4319,44 @@
69  *
70  * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
71  *
72- * @param int $id The Post ID in the cache to clean
73- * @param string $post_type The post_type of the post. Defaults to "post"
74+ * @param object $post The post to remove from the cache
75  */
76-function clean_post_cache($id, $post_type = 'post') {
77+function clean_post_cache( $post ) {
78        global $_wp_suspend_cache_invalidation, $wpdb;
79 
80        if ( ! empty( $_wp_suspend_cache_invalidation ) )
81                return;
82 
83-       $id = (int) $id;
84-
85-       if ( 0 === $id )
86+       $post = get_post( $post );
87+       if ( empty( $post ) )
88                return;
89 
90-       wp_cache_delete($id, 'posts');
91-       wp_cache_delete($id, 'post_meta');
92+       wp_cache_delete( $post->ID, 'posts' );
93+       wp_cache_delete( $post->ID, 'post_meta' );
94 
95-       clean_object_term_cache( $id, $post_type );
96+       clean_object_term_cache( $post->ID, $post->post_type );
97 
98        wp_cache_delete( 'wp_get_archives', 'general' );
99 
100-       do_action( 'clean_post_cache', $id, $post_type );
101+       do_action( 'clean_post_cache', $post->ID, $post );
102 
103-       if ( 'page' == $post_type ) {
104+       if ( 'page' == $post->post_type ) {
105                wp_cache_delete( 'all_page_ids', 'posts' );
106                wp_cache_delete( 'get_pages', 'posts' );
107-               do_action( 'clean_page_cache', $id );
108+               do_action( 'clean_page_cache', $post->ID );
109        }
110 
111-       if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
112-               foreach ( $children as $cid ) {
113+       if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $post->ID) ) ) {
114+               foreach ( $children as $child ) {
115                        // Loop detection
116-                       if ( $cid->ID == $id )
117+                       if ( $child->ID == $post->ID )
118                                continue;
119-                       clean_post_cache( $cid->ID, $cid->post_type );
120+                       clean_post_cache( $child );
121                }
122        }
123 
124        if ( is_multisite() )
125-               wp_cache_delete( $wpdb->blogid . '-' . $id, 'global-posts' );
126+               wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' );
127 }
128 
129 /**
130@@ -4563,8 +4561,8 @@
131  * @param int $post_id The ID in the database table for the $post
132  * @param object $post Object type containing the post information
133  */
134-function _save_post_hook($post_id, $post) {
135-       clean_post_cache($post_id, $post->post_type);
136+function _save_post_hook( $post_id, $post ) {
137+       clean_post_cache( $post );
138 }
139 
140 /**
141Index: wp-includes/deprecated.php
142===================================================================
143--- wp-includes/deprecated.php  (revision 20481)
144+++ wp-includes/deprecated.php  (working copy)
145@@ -3150,5 +3150,5 @@
146 function clean_page_cache( $id ) {
147        _deprecated_function( __FUNCTION__, 3.4, 'clean_post_cache()' );
148 
149-       clean_post_cache( $id, 'page' );
150+       clean_post_cache( $id );
151 }
152Index: wp-admin/includes/class-wp-posts-list-table.php
153===================================================================
154--- wp-admin/includes/class-wp-posts-list-table.php     (revision 20481)
155+++ wp-admin/includes/class-wp-posts-list-table.php     (working copy)
156@@ -360,7 +360,7 @@
157                                if ( $page->post_parent == $page->ID ) {
158                                        $page->post_parent = 0;
159                                        $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
160-                                       clean_post_cache( $page->ID, $page->post_type );
161+                                       clean_post_cache( $page );
162                                }
163 
164                                if ( 0 == $page->post_parent )