Make WordPress Core


Ignore:
Timestamp:
10/14/2024 10:20:09 PM (7 weeks ago)
Author:
peterwilsoncc
Message:

Media: Account for post ID queries in update_post_thumbnail_cache().

Updates update_post_thumbnail_cache() to account for WP_Query objects that only contain the post ID field rather than the entire post object.

This changes passes the $post value to get_post_thumbnail_id() rather than assuming the presence of the ID property. Additionally, the posts to which the thumbnail is attached are now primed prior to calling the function to avoid numerous unnecessary database queries.

The test WP_Test_REST_Posts_Controller::test_get_items_primes_parent_post_caches() is modified to account for an order of operations change for the priming of post meta caches. The cache is no longer primed in the final call to update_meta_cache() so the tests need to account for the post meta to be primed in any call to the function.

Props antpb, jorbin, khokansardar, linsoftware, mukesh27, oglekler, rajinsharwar, sumitsingh, xendo.
Fixes #59521.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r59120 r59235  
    17131713        rest_get_server()->dispatch( $request );
    17141714
    1715         $args = $filter->get_args();
    1716         $last = end( $args );
    1717         $this->assertIsArray( $last, 'The last value is not an array' );
    1718         $this->assertSameSets( $parent_ids, $last[1] );
     1715        $events = $filter->get_events();
     1716        $args   = wp_list_pluck( $events, 'args' );
     1717        $primed = false;
     1718        sort( $parent_ids );
     1719        foreach ( $args as $arg ) {
     1720            sort( $arg[1] );
     1721            if ( $parent_ids === $arg[1] ) {
     1722                $primed = $arg;
     1723                break;
     1724            }
     1725        }
     1726
     1727        $this->assertIsArray( $primed, 'The last value is not an array' );
     1728        $this->assertSameSets( $parent_ids, $primed[1] );
    17191729    }
    17201730
Note: See TracChangeset for help on using the changeset viewer.