Changeset 6056 for trunk/src/includes/core/cache.php
- Timestamp:
- 06/05/2016 06:27:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/includes/core/cache.php ΒΆ
r6054 r6056 131 131 * 132 132 * @since 2.1.0 bbPress (r4040) 133 * @since 2.6.0 bbPress (r6053) Introduced the `$post_id` parameter.134 133 * 135 * @param int $post_id The post id.136 * @param WP_Post $post The WP_Post object.137 *138 * @uses get_post() To get the post object.139 * @uses bbp_get_forum_post_type() To get the forum post type.140 * @uses bbp_get_topic_post_type() To get the topic post type.141 * @uses bbp_get_reply_post_type() To get the reply post type.142 * @uses wp_cache_delete() To delete the cache item.143 * @uses clean_object_term_cache() To clean the term cache.144 * @uses bbp_clean_post_cache() Recursion.145 134 * @uses do_action() Calls 'bbp_clean_post_cache' on $id 146 * 147 * @return void 135 * @param object|int $_post The post object or ID to remove from the cache 148 136 */ 149 function bbp_clean_post_cache( $ post_id = null, $post = null) {137 function bbp_clean_post_cache( $_post = '' ) { 150 138 151 // Get the post object. 152 if ( null !== $post ) { 153 $post = get_post( $post ); 154 } else { 155 $post = get_post( $post_id ); 156 } 157 158 // Bail if no post. 159 if ( empty( $post ) ) { 139 // Bail if no post 140 $_post = get_post( $_post ); 141 if ( empty( $_post ) ) { 160 142 return; 161 143 } 162 144 163 // Child query types to clean .145 // Child query types to clean 164 146 $post_types = array( 165 147 bbp_get_forum_post_type(), 166 148 bbp_get_topic_post_type(), 167 bbp_get_reply_post_type() ,149 bbp_get_reply_post_type() 168 150 ); 169 151 170 // Bail if not a bbPress post type .171 if ( ! in_array( $ post->post_type, $post_types, true ) ) {152 // Bail if not a bbPress post type 153 if ( ! in_array( $_post->post_type, $post_types, true ) ) { 172 154 return; 173 155 } 174 156 175 // Be sure we haven't recached the post data. 176 wp_cache_delete( $post->ID, 'posts' ); 177 wp_cache_delete( $post->ID, 'post_meta' ); 157 wp_cache_delete( $_post->ID, 'posts' ); 158 wp_cache_delete( $_post->ID, 'post_meta' ); 178 159 179 // Clean the term cache for the given post. 180 clean_object_term_cache( $post->ID, $post->post_type ); 160 clean_object_term_cache( $_post->ID, $_post->post_type ); 181 161 182 // Loop through query types and clean caches. 162 do_action( 'bbp_clean_post_cache', $_post->ID, $_post ); 163 164 // Loop through query types and clean caches 183 165 foreach ( $post_types as $post_type ) { 184 wp_cache_delete( 'bbp_parent_all_' . $ post->ID . '_type_' . $post_type . '_child_ids', 'bbpress_posts' );166 wp_cache_delete( 'bbp_parent_all_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress_posts' ); 185 167 } 186 168 187 /** 188 * Fires immediately after the given post's cache is cleaned. 189 * 190 * @since 2.1.0 191 * 192 * @param int $post_id Post ID. 193 * @param WP_Post $post Post object. 194 */ 195 do_action( 'bbp_clean_post_cache', $post->ID, $post ); 196 197 // Invalidate parent caches. 198 if ( ! empty( $post->post_parent ) ) { 199 bbp_clean_post_cache( $post->post_parent ); 169 // Invalidate parent caches 170 if ( ! empty( $_post->post_parent ) ) { 171 bbp_clean_post_cache( $_post->post_parent ); 200 172 } 201 173 }
Note: See TracChangeset
for help on using the changeset viewer.