Make WordPress Core


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

REST API: Prime caches for linked objects in menu item REST API controller.

Add a new parameter to WP_Query called update_menu_item_cache that when set to true, primes the caches for linked terms and posts for menu item post objects. This change moves logic
found in wp_get_nav_menu_items into a new function called update_menu_item_cache. Update the menu item REST API controller, to pass the update_menu_item_cache parameter to the
arguments used for the WP_Query run to get menu items.

Props furi3r, TimothyBlynJacobs, spacedmonkey, peterwilsoncc, mitogh.
Fixes #55620.

--This line, and those below, will be ignored--

M src/wp-includes/class-wp-query.php
M src/wp-includes/nav-menu.php
M src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php
M tests/phpunit/tests/post/nav-menu.php

File:
1 edited

Legend:

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

    r53483 r53504  
    757757     *     @type bool            $update_post_meta_cache  Whether to update the post meta cache. Default true.
    758758     *     @type bool            $update_post_term_cache  Whether to update the post term cache. Default true.
     759     *     @type bool            $update_menu_item_cache  Whether to update the menu item cache. Default false.
    759760     *     @type bool            $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
    760761     *                                                    disable cache priming for term meta, so that each
     
    18721873        }
    18731874
     1875        if ( ! isset( $q['update_menu_item_cache'] ) ) {
     1876            $q['update_menu_item_cache'] = false;
     1877        }
     1878
    18741879        if ( ! isset( $q['lazy_load_term_meta'] ) ) {
    18751880            $q['lazy_load_term_meta'] = $q['update_post_term_cache'];
     
    31463151            /** @var WP_Post[] */
    31473152            $this->posts = array_map( 'get_post', $this->posts );
     3153        }
     3154
     3155        if ( ! empty( $this->posts ) && $q['update_menu_item_cache'] ) {
     3156            update_menu_item_cache( $this->posts );
    31483157        }
    31493158
Note: See TracChangeset for help on using the changeset viewer.