bbp_update_post_author_caches( array $objects = array() )
Prime post author caches.
Description Description
This function uses cache_users() to prepare the object cache for imminent requests to user objects that aren’t naturally cached by the primary WP_Query calls themselves.
This is triggered when a update_post_author_cache
argument is set to true.
Parameters Parameters
- $objects
-
(Optional) Array of objects, fresh from a query
Default value: array()
Return Return
(bool) True if some IDs were cached
Source Source
File: includes/common/functions.php
function bbp_update_post_author_caches( $objects = array() ) { // Bail if no posts if ( empty( $objects ) ) { return false; } // Default value $user_ids = array(); // Get the user IDs (could use wp_list_pluck() if this is ever a bottleneck) foreach ( $objects as $object ) { $object = get_post( $object ); // Skip if post does not have an author ID. if ( empty( $object->post_author ) ) { continue; } // If post exists, add post author to the array. $user_ids[] = (int) $object->post_author; } // Unique, non-zero values $user_ids = bbp_get_unique_array_values( $user_ids ); // Bail if no IDs to prime if ( empty( $user_ids ) ) { return false; } // Try to prime user caches cache_users( $user_ids ); // Return return true; }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |