From 20ccbb143766b54006ea048d380f6e4a2e632ea0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 15 Jun 2022 13:17:59 +0000 Subject: [PATCH] REST API: Some documentation and test improvements for `update_post_parent_caches()`: * Make the function description more specific, for consistency with `update_post_author_caches()`. * Add missing `@covers` tags for the unit test. Follow-up to [53506]. See #55593. git-svn-id: https://develop.svn.wordpress.org/trunk@53507 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 5 +++-- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 3 ++- tests/phpunit/tests/rest-api/rest-posts-controller.php | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 97a3fb8f77..07dd58980e 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -7490,16 +7490,17 @@ function update_post_author_caches( $posts ) { } /** - * Prime post parent post caches. + * Updates parent post caches for a list of post objects. * * @since 6.1.0 * - * @param WP_Post[] $posts Array of Post objects. + * @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 ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 87de7a2421..58be931937 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -369,8 +369,9 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $posts = array(); - update_post_parent_caches( $query_result ); update_post_author_caches( $query_result ); + update_post_parent_caches( $query_result ); + if ( post_type_supports( $this->post_type, 'thumbnail' ) ) { update_post_thumbnail_cache( $posts_query ); } diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 54d1cc0167..6a7ceeece6 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -1516,7 +1516,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te /** * @ticket 55592 - * @covers WP_REST_Posts_Controller::get_items() + * @covers WP_REST_Posts_Controller::get_items */ public function test_get_items_with_featured_media() { $file = DIR_TESTDATA . '/images/canola.jpg'; @@ -1789,6 +1789,8 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te /** * @ticket 55593 + * @covers WP_REST_Posts_Controller::get_items + * @covers update_post_parent_caches */ public function test_get_items_parent_ids_primed() { $parent_id1 = self::$post_ids[0];