_wp_ajax_menu_quick_search( array $request = array() )
- Since
- 3.0.0
- Source
wp-admin/includes/nav-menu.php:23
Compatibility
- WordPress
- since 3.0.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
$requestarrayoptional- The unsanitized request values.Default:
array()
Performance profile
How much work a call to _wp_ajax_menu_quick_search() 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
- Scales with input
- Instructions
- 27–93
- Plugin surface
- 1 hook
- Called by
- 1
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 274.
Third-party callbacks on 'wp_ajax_menu_quick_search_args' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, 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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_ajax_menu_quick_search() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$type !== "get-post-item" | 27–43 | preg_match() |
$type === "get-post-item" && post_type_exists() | 27–43 | post_type_exists() |
$type === "get-post-item" && !post_type_exists() | 29–47 | post_type_exists(), taxonomy_exists() |
$type !== "get-post-item" && preg_match() && !get_post_type_object() | 39–49 | preg_match(), get_post_type_object() |
$type !== "get-post-item" && preg_match() && empty($terms) | 44–54 | preg_match(), taxonomy() |
$type === "get-post-item" && post_type_exists() && isset($request) && $response_format === "markup" | 46–56 | post_type_exists(), get_post(), array_map() |
$response_format !== "markup" && $type === "get-post-item" && post_type_exists() && isset($request) && $response_format === "json" | 47–57 | post_type_exists(), get_the_title(), get_post_type(), ID() |
$type !== "get-post-item" && preg_match() && !empty($terms) | 48–62 | preg_match(), taxonomy(), is_wp_error() |
$type !== "get-post-item" && preg_match() && !get_post_type_object() && empty($terms) | 50–60 | preg_match(), get_post_type_object(), taxonomy() |
$response_format !== "markup" && $type === "get-post-item" && !post_type_exists() && taxonomy_exists() && isset($request) && $response_format === "json" | 51–61 | post_type_exists(), taxonomy_exists(), get_term(), ID() |
$type === "get-post-item" && !post_type_exists() && taxonomy_exists() && isset($request) && $response_format === "markup" | 51–61 | post_type_exists(), taxonomy_exists(), get_term(), array_map() |
$type !== "get-post-item" && preg_match() && !get_post_type_object() && !empty($terms) | 54–68 | preg_match(), get_post_type_object(), taxonomy(), is_wp_error() |
4 further outcomes, up to 93 instructions
$type !== "get-post-item" && preg_match() && get_post_type_object() && !isset($post_type_obj) && !->have_posts() | 73–83 | preg_match(), get_post_type_object(), get_post_type_object(), _wp_nav_menu_meta_box_object(), apply_filters(), array_merge(), no_found_rows(), ->have_posts() |
$type !== "get-post-item" && preg_match() && get_post_type_object() && !isset($post_type_obj) | 76–86 | preg_match(), get_post_type_object(), get_post_type_object(), _wp_nav_menu_meta_box_object(), apply_filters(), array_merge(), no_found_rows(), ->have_posts(), ->have_posts() |
$type !== "get-post-item" && preg_match() && get_post_type_object() && isset($post_type_obj) && !->have_posts() | 80–90 | preg_match(), get_post_type_object(), get_post_type_object(), _wp_nav_menu_meta_box_object(), apply_filters(), array_merge(), array_merge(), no_found_rows(), ->have_posts() |
$type !== "get-post-item" && preg_match() && get_post_type_object() && isset($post_type_obj) | 83–93 | preg_match(), get_post_type_object(), get_post_type_object(), _wp_nav_menu_meta_box_object(), apply_filters(), array_merge(), array_merge(), no_found_rows(), ->have_posts(), ->have_posts() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 274 | 27–93 | 31 | |
| 8.5 | 274 | 27–93 | 31 | |
| 8.4 | 274 | 27–93 | 31 | |
| 8.3 | 274 | 27–93 | 31 | |
| 8.2 | 274 | 27–93 | 31 | |
| 8.1 | 274 | 27–93 | 31 | 1 more instruction than PHP 7.4 |
| 7.4 | 273 | 27–115 | 31 |
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.
Hooks and filters fired · 1
One hook fires while _wp_ajax_menu_quick_search() runs, in this order:
- apply_filters( wp_ajax_menu_quick_search_args )filterline 112 (+89 into the body)
Filter the menu quick search arguments.
Uses · 15
- post_type_exists()Determines whether a post type is registered.
- walk_nav_menu_tree()Retrieves the HTML list content for nav menu items.
- get_post()Retrieves post data given a post ID or post object.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- get_the_title()Retrieves the post title.
- get_post_type()Retrieves the post type of the current post or of a given post.
- taxonomy_exists()Determines whether the taxonomy name exists.
- get_term()Gets all term data from database by term ID.
- get_post_type_object()Retrieves a post type object by name.
- _wp_nav_menu_meta_box_object()Adds custom arguments to some of the meta box object types.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
Show all 15
- is_wp_error()Checks whether the given variable is a WordPress Error.
- Walker_Nav_Menu_Checklist::__construct()
- WP_Query::__construct()Constructor.
Used by · 1
- wp_ajax_menu_quick_search()Handles menu quick searching via AJAX.
Source code
function _wp_ajax_menu_quick_search( $request = array() ) { $args = array(); $type = $request['type'] ?? ''; $object_type = $request['object_type'] ?? ''; $query = $request['q'] ?? ''; $response_format = $request['response-format'] ?? ''; if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) { $response_format = 'json'; } if ( 'markup' === $response_format ) { $args['walker'] = new Walker_Nav_Menu_Checklist(); } if ( 'get-post-item' === $type ) { if ( post_type_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' === $response_format ) { echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); } elseif ( 'json' === $response_format ) { echo wp_json_encode( array( 'ID' => $object_id, 'post_title' => get_the_title( $object_id ), 'post_type' => get_post_type( $object_id ), ) ); echo "\n"; } } } elseif ( taxonomy_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' === $response_format ) { echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); } elseif ( 'json' === $response_format ) { $post_obj = get_term( $object_id, $object_type ); echo wp_json_encode( array( 'ID' => $object_id, 'post_title' => $post_obj->name, 'post_type' => $object_type, ) ); echo "\n"; } } } } elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z0-9_-]*\b)/', $type, $matches ) ) { if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) { $post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); $query_args = array( 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'posts_per_page' => 10, 'post_type' => $matches[2], 's' => $query, 'search_columns' => array( 'post_title' ), ); /** * Filter the menu quick search arguments. * * @since 6.9.0 * * @param array $args { * Menu quick search arguments. *Changelog
Introduced in 3.0.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-admin/includes/nav-menu.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.