Make WordPress Core


Ignore:
Timestamp:
06/15/2022 10:41:32 AM (3 years ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r53484 r53506  
    74917491
    74927492/**
     7493 * Prime post parent post caches.
     7494 *
     7495 * @since 6.1.0
     7496 *
     7497 * @param WP_Post[] $posts Array of Post objects.
     7498 */
     7499function update_post_parent_caches( $posts ) {
     7500    $parent_ids = wp_list_pluck( $posts, 'post_parent' );
     7501    $parent_ids = array_map( 'absint', $parent_ids );
     7502    $parent_ids = array_unique( array_filter( $parent_ids ) );
     7503    if ( ! empty( $parent_ids ) ) {
     7504        _prime_post_caches( $parent_ids, false );
     7505    }
     7506}
     7507
     7508/**
    74937509 * Updates metadata cache for a list of post IDs.
    74947510 *
Note: See TracChangeset for help on using the changeset viewer.