mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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:
@@ -756,6 +756,7 @@ class WP_Query {
|
||||
* @type string $title Post title.
|
||||
* @type bool $update_post_meta_cache Whether to update the post meta cache. Default true.
|
||||
* @type bool $update_post_term_cache Whether to update the post term cache. Default true.
|
||||
* @type bool $update_menu_item_cache Whether to update the menu item cache. Default false.
|
||||
* @type bool $lazy_load_term_meta Whether to lazy-load term meta. Setting to false will
|
||||
* disable cache priming for term meta, so that each
|
||||
* get_term_meta() call will hit the database.
|
||||
@@ -1871,6 +1872,10 @@ class WP_Query {
|
||||
$q['update_post_term_cache'] = true;
|
||||
}
|
||||
|
||||
if ( ! isset( $q['update_menu_item_cache'] ) ) {
|
||||
$q['update_menu_item_cache'] = false;
|
||||
}
|
||||
|
||||
if ( ! isset( $q['lazy_load_term_meta'] ) ) {
|
||||
$q['lazy_load_term_meta'] = $q['update_post_term_cache'];
|
||||
}
|
||||
@@ -3147,6 +3152,10 @@ class WP_Query {
|
||||
$this->posts = array_map( 'get_post', $this->posts );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->posts ) && $q['update_menu_item_cache'] ) {
|
||||
update_menu_item_cache( $this->posts );
|
||||
}
|
||||
|
||||
if ( ! $q['suppress_filters'] ) {
|
||||
/**
|
||||
* Filters the raw post results array, prior to status checks.
|
||||
|
||||
Reference in New Issue
Block a user