PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
← All changes | includes/core/cache.php +35 -35 2.2.12.6.6 View file →
@@ -12,9 +12,9 @@
12 12 * @subpackage Cache
13 13 */
14 14
15 15 // Exit if accessed directly
16 -if ( !defined( 'ABSPATH' ) ) exit;
16 +defined( 'ABSPATH' ) || exit;
17 17
18 18 /** Helpers *******************************************************************/
19 19
20 20 /**
@@ -24,9 +24,9 @@
24 24 * or a topic. Without this in place, WordPress will attempt to invalidate all
25 25 * child posts whenever a parent post is modified. This can cause thousands of
26 26 * cache invalidations to occur on a single edit, which is no good for anyone.
27 27 *
28 - * @since bbPress (r4011)
28 + * @since 2.1.0 bbPress (r4011)
29 29 *
30 30 * @package bbPress
31 31 * @subpackage Cache
32 32 */
@@ -46,9 +46,9 @@
46 46
47 47 /**
48 48 * Hook into the 'pre_post_update' action.
49 49 *
50 - * @since bbPress (r4011)
50 + * @since 2.1.0 bbPress (r4011)
51 51 */
52 52 public function __construct() {
53 53 add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
54 54 }
@@ -59,9 +59,9 @@
59 59 * Check that the post being updated is a bbPress post type, saves the
60 60 * post ID to be used later, and adds an action to 'clean_post_cache' that
61 61 * prevents child post caches from being cleared.
62 62 *
63 - * @since bbPress (r4011)
63 + * @since 2.1.0 bbPress (r4011)
64 64 *
65 65 * @param int $post_id The post ID being updated
66 66 * @return If invalid post data
67 67 */
@@ -67,10 +67,11 @@
67 67 */
68 68 public function pre_post_update( $post_id = 0 ) {
69 69
70 70 // Bail if post ID is not a bbPress post type
71 - if ( empty( $post_id ) || ! bbp_is_custom_post_type( $post_id ) )
71 + if ( empty( $post_id ) || ! bbp_is_custom_post_type( $post_id ) ) {
72 72 return;
73 + }
73 74
74 75 // Store the $post_id
75 76 $this->updating_post = $post_id;
76 77
@@ -82,9 +83,9 @@
82 83 /**
83 84 * Skip cache invalidation of related posts if the post ID being invalidated
84 85 * is not the one that was just updated.
85 86 *
86 - * @since bbPress (r4011)
87 + * @since 2.1.0 bbPress (r4011)
87 88 *
88 89 * @param int $post_id The post ID of the cache being invalidated
89 90 * @return If invalid post data
90 91 */
@@ -90,10 +91,11 @@
90 91 */
91 92 public function skip_related_posts( $post_id = 0 ) {
92 93
93 94 // Bail if this post is not the current bbPress post
94 - if ( empty( $post_id ) || ( $this->updating_post !== $post_id ) )
95 + if ( empty( $post_id ) || ( $this->updating_post !== $post_id ) ) {
95 96 return;
97 + }
96 98
97 99 // Stash the current cache invalidation value in a variable, so we can
98 100 // restore back to it nicely in the future.
99 101 global $_wp_suspend_cache_invalidation;
@@ -109,10 +111,9 @@
109 111
110 112 /**
111 113 * Restore the cache invalidation to its previous value.
112 114 *
113 - * @since bbPress (r4011)
114 - * @uses wp_suspend_cache_invalidation()
115 + * @since 2.1.0 bbPress (r4011)
115 116 */
116 117 public function restore_cache_invalidation() {
117 118 wp_suspend_cache_invalidation( $this->original_cache_invalidation );
118 119 }
@@ -125,44 +126,43 @@
125 126 * Will clean a post in the cache.
126 127 *
127 128 * Will call to clean the term object cache associated with the post ID.
128 129 *
129 - * @since bbPress (r4040)
130 + * @since 2.1.0 bbPress (r4040)
131 + * @since 2.6.0 bbPress (r6053) Introduced the `$post_id` parameter.
130 132 *
131 - * @uses do_action() Calls 'bbp_clean_post_cache' on $id
132 - * @param object|int $_post The post object or ID to remove from the cache
133 + * @param int $post_id The post id.
134 + * @param WP_Post $post The WP_Post object.
133 135 */
134 -function bbp_clean_post_cache( $_post = '' ) {
136 +function bbp_clean_post_cache( $post_id = null, $post = null ) {
135 137
136 - // Bail if no post
137 - $_post = get_post( $_post );
138 - if ( empty( $_post ) )
139 - return;
140 -
141 - wp_cache_delete( $_post->ID, 'posts' );
142 - wp_cache_delete( $_post->ID, 'post_meta' );
143 -
144 - clean_object_term_cache( $_post->ID, $_post->post_type );
145 -
146 - do_action( 'bbp_clean_post_cache', $_post->ID, $_post );
147 -
148 138 // Child query types to clean
149 139 $post_types = array(
140 + bbp_get_forum_post_type(),
150 141 bbp_get_topic_post_type(),
151 - bbp_get_forum_post_type(),
152 142 bbp_get_reply_post_type()
153 143 );
154 144
155 - // Loop through query types and clean caches
156 - foreach ( $post_types as $post_type ) {
157 - wp_cache_delete( 'bbp_get_forum_' . $_post->ID . '_reply_id', 'bbpress' );
158 - wp_cache_delete( 'bbp_parent_' . $_post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress' );
159 - wp_cache_delete( 'bbp_parent_' . $_post->ID . '_type_' . $post_type . '_child_count', 'bbpress' );
160 - wp_cache_delete( 'bbp_parent_public_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress' );
161 - wp_cache_delete( 'bbp_parent_all_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress' );
145 + // Bail if not a bbPress post type
146 + if ( ! in_array( $post->post_type, $post_types, true ) ) {
147 + return;
162 148 }
163 149
150 + /**
151 + * Fires immediately after the given post cache is cleaned.
152 + *
153 + * @since 2.1.0
154 + *
155 + * @param int $post_id Post ID.
156 + * @param WP_Post $post Post object.
157 + */
158 + do_action( 'bbp_clean_post_cache', $post->ID, $post );
159 +
164 160 // Invalidate parent caches
165 - if ( ! empty( $_post->post_parent ) ) {
166 - bbp_clean_post_cache( $_post->post_parent );
161 + if ( ! empty( $post->post_parent ) ) {
162 + clean_post_cache( $post->post_parent );
163 +
164 + // Only bump `last_changed` when forum-root is reached
165 + } else {
166 + wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
167 167 }
168 168 }