block_core_navigation_get_menu_items_at_location( string $location ): array
- Since
- 5.9.0
- Source
wp-includes/blocks/navigation.php:1068
Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$locationstring- The menu location.
Return value
array- Menu items for the location.
Performance profile
How much work a call to block_core_navigation_get_menu_items_at_location() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 4–30
- Plugin surface
- None
- Called by
- 2
Reaches the database via get_term().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 33.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_term()one call below block_core_navigation_get_menu_items_at_location() - hookthird-party callbacks
apply_filters()one call below block_core_navigation_get_menu_items_at_location() - optionoption read or write
get_option()one call below block_core_navigation_get_menu_items_at_location()
Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost block_core_navigation_get_menu_items_at_location() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($location) | 4 | none |
!empty($location) && !isset($locations[$location]) | 9 | get_nav_menu_locations() |
!empty($location) && isset($locations[$location]) | 16 | get_nav_menu_locations(), wp_get_nav_menu_object() |
!empty($location) && isset($locations[$location]) && is_wp_error() | 20 | get_nav_menu_locations(), wp_get_nav_menu_object(), is_wp_error() |
!empty($location) && isset($locations[$location]) && !is_wp_error() | 30 | get_nav_menu_locations(), wp_get_nav_menu_object(), is_wp_error(), wp_get_nav_menu_items(), _wp_menu_item_classes_by_context() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 33 instructions, 4–30 executed per call, 4 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 5
- get_nav_menu_locations()Retrieves all registered navigation menu locations and the menus assigned to them.
- wp_get_nav_menu_object()Returns a navigation menu object.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_get_nav_menu_items()Retrieves all menu items of a navigation menu.
- _wp_menu_item_classes_by_context()Adds the class property classes for the current context, if applicable.
Used by · 2
- WP_Navigation_Block_Renderer::get_inner_blocks()Gets the inner blocks for the navigation block.
- block_core_navigation_get_inner_blocks_from_unstable_location()Gets the inner blocks for the navigation block from the unstable location attribute.
Source code
function block_core_navigation_get_menu_items_at_location( $location ) { if ( empty( $location ) ) { return; } // Build menu data. The following approximates the code in // `wp_nav_menu()` and `gutenberg_output_block_nav_menu`. // Find the location in the list of locations, returning early if the // location can't be found. $locations = get_nav_menu_locations(); if ( ! isset( $locations[ $location ] ) ) { return; } // Get the menu from the location, returning early if there is no // menu or there was an error. $menu = wp_get_nav_menu_object( $locations[ $location ] ); if ( ! $menu || is_wp_error( $menu ) ) { return; } $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); _wp_menu_item_classes_by_context( $menu_items ); return $menu_items; }Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/navigation.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.