wppaste
WordPress

WP_Customize_Nav_Menus::search_available_items_query( array $args = array() ): array

Since
4.3.0
Source
wp-includes/class-wp-customize-nav-menus.php:358
Performs post queries for available-item searching.

Description

Based on WP_Editor::wp_link_query().

Compatibility

WordPress
since 4.3.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

$argsarrayoptional
Accepts 'pagenum' and 's' (search) arguments.Default: array()

Return value

array
Menu items.

Performance profile

How much work a call to WP_Customize_Nav_Menus::search_available_items_query() 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_terms().

Scaling
Scales with input

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

Instructions
80–159

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

Plugin surface
1 hook

Third-party callbacks on 'customize_nav_menu_searched_items' 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_terms()called directly
  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below WP_Customize_Nav_Menus::search_available_items_query()
  • serializeserialisationmaybe_unserialize()one call below WP_Customize_Nav_Menus::search_available_items_query()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 42 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Nav_Menus::search_available_items_query() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!isset($args)80–91get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters()
!isset($args)86–96get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters()
always86–97get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters()
!empty($front_page)89–100get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters()
always92–102get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters()
!empty($front_page)93–104get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters()
!empty($front_page)95–105get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters()
isset($args) && !empty($front_page)95–106get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters()
!empty($front_page)99–109get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters()
isset($args) && !empty($front_page)99–110get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters()
empty($front_page)101–112get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && !empty($front_page)101–111get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters()
30 further outcomes, up to 159 instructions
empty($front_page)105–116get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && !empty($front_page)105–115get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters()
!isset($args)105–115get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters()
empty($front_page)107–117get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && empty($front_page)107–118get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), apply_filters()
empty($front_page)111–121get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && empty($front_page)111–122get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters()
always111–121get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters()
isset($args) && empty($front_page)113–123get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), apply_filters()
empty($front_page)114–125get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
!empty($front_page)114–124get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters()
isset($args) && empty($front_page)117–127get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters()
empty($front_page)118–129get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
!empty($front_page)118–128get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters()
empty($front_page)120–130get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
isset($args) && empty($front_page)120–131get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
isset($args) && !empty($front_page)120–130get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters()
empty($front_page)124–134get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
isset($args) && empty($front_page)124–135get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
isset($args) && !empty($front_page)124–134get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters()
isset($args) && empty($front_page)126–136get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
empty($front_page)126–136get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && empty($front_page)130–140get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
empty($front_page)130–140get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && empty($front_page)132–142get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), apply_filters()
isset($args) && empty($front_page)136–146get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters()
empty($front_page)139–149get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
empty($front_page)143–153get_post_types(), array_keys(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
isset($args) && empty($front_page)145–155get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()
isset($args) && empty($front_page)149–159get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), ->value(), auto-draft(), array_merge(), array_merge(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), __(), home_url(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev26780–1651812 more instructions than PHP 8.5
8.525580–15917
8.425580–159173 fewer instructions than PHP 8.3
8.325880–15917
8.225880–15917
8.125880–159173 fewer instructions than PHP 7.4
7.426180–16217

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_Customize_Nav_Menus::search_available_items_query() runs, in this order:

  1. apply_filters( customize_nav_menu_searched_items )filterline 480 (+122 into the body)

    Filters the available menu items during a search request.

Uses · 16

  • get_post_types()Gets a list of all registered post type objects.
  • absint()Converts a value to non-negative integer.
  • __()Retrieves the translation of $text.
  • get_post_states()Retrieves an array of post states from a post.
  • get_bloginfo()Retrieves information about the current site.
  • get_permalink()Retrieves the full permalink for the current post or post ID.
  • get_taxonomies()Retrieves a list of registered taxonomy names or objects.
  • get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
  • get_taxonomy()Retrieves the taxonomy object of $taxonomy.
  • get_term_link()Generates a permalink for a taxonomy term archive.
  • get_option()Retrieves an option value based on an option name.
  • _x()Retrieves translated string with gettext context.
Show all 16

Used by · 1

Source code

	public function search_available_items_query( $args = array() ) {		$items = array(); 		$post_type_objects = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );		$query             = array(			'post_type'              => array_keys( $post_type_objects ),			'suppress_filters'       => true,			'update_post_term_cache' => false,			'update_post_meta_cache' => false,			'post_status'            => 'publish',			'posts_per_page'         => 20,		); 		$args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;		$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0; 		if ( isset( $args['s'] ) ) {			$query['s'] = $args['s'];		} 		$posts = array(); 		// Prepend list of posts with nav_menus_created_posts search results on first page.		$nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );		if ( 1 === $args['pagenum'] && $nav_menus_created_posts_setting && count( $nav_menus_created_posts_setting->value() ) > 0 ) {			$stub_post_query = new WP_Query(				array_merge(					$query,					array(						'post_status'    => 'auto-draft',						'post__in'       => $nav_menus_created_posts_setting->value(),						'posts_per_page' => -1,					)				)			);			$posts           = array_merge( $posts, $stub_post_query->posts );		} 		// Query posts.		$get_posts = new WP_Query( $query );		$posts     = array_merge( $posts, $get_posts->posts ); 		// Create items for posts.		foreach ( $posts as $post ) {			$post_title = $post->post_title;			if ( '' === $post_title ) {				/* translators: %d: ID of a post. */				$post_title = sprintf( __( '#%d (no title)' ), $post->ID );			} 			$post_type_label = $post_type_objects[ $post->post_type ]->labels->singular_name;			$post_states     = get_post_states( $post );			if ( ! empty( $post_states ) ) {				$post_type_label = implode( ',', $post_states );			} 			$items[] = array(				'id'         => 'post-' . $post->ID,				'title'      => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),				'type'       => 'post_type',				'type_label' => $post_type_label,				'object'     => $post->post_type,				'object_id'  => (int) $post->ID,				'url'        => get_permalink( (int) $post->ID ),			);		} 		// Query taxonomy terms.		$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'names' );		$terms      = get_terms(			array(				'taxonomies' => $taxonomies,				'name__like' => $args['s'],				'number'     => 20,				'hide_empty' => false,				'offset'     => 20 * ( $args['pagenum'] - 1 ),			)		); 		// Check if any taxonomies were found.

Changelog

Introduced in 4.3.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 6.9.7 tag, from src/wp-includes/class-wp-customize-nav-menus.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.