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


git-svn-id: https://develop.svn.wordpress.org/trunk@53504 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2022-06-15 10:18:02 +00:00
parent f3441e37ed
commit aef77be627
4 changed files with 115 additions and 37 deletions
@@ -998,6 +998,8 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
}
}
$query_args['update_menu_item_cache'] = true;
return $query_args;
}