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
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
- Scaling
- Scales with input
- Instructions
- 80–159
- Plugin surface
- 1 hook
- Called by
- 1
Reaches the database via get_terms().
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 255.
Third-party callbacks on 'customize_nav_menu_searched_items' 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_terms()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below WP_Customize_Nav_Menus::search_available_items_query() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($args) | 80–91 | get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters() |
!isset($args) | 86–96 | get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters() |
| always | 86–97 | get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters() |
!empty($front_page) | 89–100 | get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters() |
| always | 92–102 | get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), apply_filters() |
!empty($front_page) | 93–104 | get_post_types(), array_keys(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters() |
!empty($front_page) | 95–105 | get_post_types(), array_keys(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters() |
isset($args) && !empty($front_page) | 95–106 | get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), apply_filters() |
!empty($front_page) | 99–109 | get_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–110 | get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters() |
empty($front_page) | 101–112 | get_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–111 | get_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–116 | get_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–115 | get_post_types(), array_keys(), absint(), ->get_setting(), ->value(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), apply_filters() |
!isset($args) | 105–115 | get_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–117 | get_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–118 | get_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–121 | get_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–122 | get_post_types(), array_keys(), absint(), ->get_setting(), post_type(), array_merge(), get_taxonomies(), taxonomies(), get_option(), get_option(), _x(), mb_stripos(), apply_filters() |
| always | 111–121 | get_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–123 | get_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–125 | get_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–124 | get_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–127 | get_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–129 | get_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–128 | get_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–130 | get_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–131 | get_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–130 | get_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–134 | get_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–135 | get_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–134 | get_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–136 | get_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–136 | get_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–140 | get_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–140 | get_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–142 | get_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–146 | get_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–149 | get_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–153 | get_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–155 | get_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–159 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 267 | 80–165 | 18 | 12 more instructions than PHP 8.5 |
| 8.5 | 255 | 80–159 | 17 | |
| 8.4 | 255 | 80–159 | 17 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 258 | 80–159 | 17 | |
| 8.2 | 258 | 80–159 | 17 | |
| 8.1 | 258 | 80–159 | 17 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 261 | 80–162 | 17 |
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:
- 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
- stripos()
- home_url()Retrieves the URL for the current site where the front end is accessible.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Query::__construct()Constructor.
Used by · 1
- WP_Customize_Nav_Menus::ajax_search_available_items()Ajax handler for searching available menu items.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.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.