REST API: Prime caches for post parents in post REST API controller.

Prime caches for all post parents in the post REST API controller using the `_prime_post_caches` function. Post parent objects are required as part of the `check_read_permission` method’s permission check in post REST API controller. 

Props spacedmonkey, furi3r, peterwilsoncc, mitogh, madpixels. 
Fixes #55593.
Built from https://develop.svn.wordpress.org/trunk@53506


git-svn-id: http://core.svn.wordpress.org/trunk@53095 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2022-06-15 10:43:10 +00:00
parent ab5cc35046
commit 2c8a6170af
3 changed files with 18 additions and 1 deletions

View File

@ -7489,6 +7489,22 @@ function update_post_author_caches( $posts ) {
cache_users( $author_ids );
}
/**
* Prime post parent post caches.
*
* @since 6.1.0
*
* @param WP_Post[] $posts Array of Post objects.
*/
function update_post_parent_caches( $posts ) {
$parent_ids = wp_list_pluck( $posts, 'post_parent' );
$parent_ids = array_map( 'absint', $parent_ids );
$parent_ids = array_unique( array_filter( $parent_ids ) );
if ( ! empty( $parent_ids ) ) {
_prime_post_caches( $parent_ids, false );
}
}
/**
* Updates metadata cache for a list of post IDs.
*

View File

@ -369,6 +369,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
$posts = array();
update_post_parent_caches( $query_result );
update_post_author_caches( $query_result );
if ( post_type_supports( $this->post_type, 'thumbnail' ) ) {
update_post_thumbnail_cache( $posts_query );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53505';
$wp_version = '6.1-alpha-53506';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.