wppaste
WordPress

_wp_ajax_menu_quick_search( array $request = array() )

Since
3.0.0
Source
wp-admin/includes/nav-menu.php:23
Prints the appropriate response to a menu quick search.

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

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
27–93

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 274.

Plugin surface
1 hook

Third-party callbacks on 'wp_ajax_menu_quick_search_args' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
$type !== "get-post-item"27–43preg_match()
$type === "get-post-item" && post_type_exists()27–43post_type_exists()
$type === "get-post-item" && !post_type_exists()29–47post_type_exists(), taxonomy_exists()
$type !== "get-post-item" && preg_match() && !get_post_type_object()39–49preg_match(), get_post_type_object()
$type !== "get-post-item" && preg_match() && empty($terms)44–54preg_match(), taxonomy()
$type === "get-post-item" && post_type_exists() && isset($request) && $response_format === "markup"46–56post_type_exists(), get_post(), array_map()
$response_format !== "markup" && $type === "get-post-item" && post_type_exists() && isset($request) && $response_format === "json"47–57post_type_exists(), get_the_title(), get_post_type(), ID()
$type !== "get-post-item" && preg_match() && !empty($terms)48–62preg_match(), taxonomy(), is_wp_error()
$type !== "get-post-item" && preg_match() && !get_post_type_object() && empty($terms)50–60preg_match(), get_post_type_object(), taxonomy()
$response_format !== "markup" && $type === "get-post-item" && !post_type_exists() && taxonomy_exists() && isset($request) && $response_format === "json"51–61post_type_exists(), taxonomy_exists(), get_term(), ID()
$type === "get-post-item" && !post_type_exists() && taxonomy_exists() && isset($request) && $response_format === "markup"51–61post_type_exists(), taxonomy_exists(), get_term(), array_map()
$type !== "get-post-item" && preg_match() && !get_post_type_object() && !empty($terms)54–68preg_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–83preg_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–86preg_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–90preg_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–93preg_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

PHPCompiledExecutedBranchesNotes
8.6-dev27427–9331
8.527427–9331
8.427427–9331
8.327427–9331
8.227427–9331
8.127427–93311 more instruction than PHP 7.4
7.427327–11531

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:

  1. apply_filters( wp_ajax_menu_quick_search_args )filterline 112 (+89 into the body)

    Filter the menu quick search arguments.

Uses · 15

Show all 15

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.