wp_ajax_query_themes()
- Since
- 3.9.0
- Source
wp-admin/includes/ajax-actions.php:3650
Compatibility
- WordPress
- since 3.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.
Performance profile
How much work a call to wp_ajax_query_themes() 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
- Expensive
- Scaling
- Scales with input
- Instructions
- 62–72
- Plugin surface
- 1 hook
- Called by
- 0
Reaches an outbound HTTP request via wp_remote_get().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 270.
Third-party callbacks on 'install_themes_table_api_args_{$old_filter}' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - httpoutbound HTTP request
wp_remote_get()one call below wp_ajax_query_themes() - transienttransient
get_site_transient()one call below wp_ajax_query_themes()
Further down the call graph this can also reach option, query, cache and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_query_themes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
current_user_can() && !is_wp_error() | 62–71 | current_user_can(), wp_unslash(), array_merge(), per_page(), apply_filters(), themes_api(), is_wp_error(), network_admin_url(), search_theme_directories(), wp_send_json_success() |
current_user_can() && is_wp_error() | 64–72 | current_user_can(), wp_unslash(), array_merge(), per_page(), apply_filters(), themes_api(), is_wp_error(), wp_send_json_error(), network_admin_url(), search_theme_directories(), wp_send_json_success() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 268 | 62–72 | 20 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 270 | 62–72 | 20 | |
| 8.4 | 270 | 62–72 | 20 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 273 | 62–72 | 20 | |
| 8.2 | 273 | 62–72 | 20 | |
| 8.1 | 273 | 62–72 | 20 | |
| 7.4 | 273 | 62–72 | 20 |
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_query_themes() runs, in this order:
- apply_filters( install_themes_table_api_args_{$old_filter} )filterline 3680 (+30 into the body)
Uses · 25
- current_user_can()Returns whether the current user has the specified capability.
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- wp_parse_args()Merges user defined arguments into defaults array.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- get_user_option()Retrieves user option that can be either per Site or per Network.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- themes_api()Retrieves theme installer pages from the WordPress.org Themes API.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- network_admin_url()Retrieves the URL to the admin area for the network.
- search_theme_directories()Searches all registered theme directories for complete and valid themes.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- add_query_arg()Retrieves a modified URL query string.
Show all 25
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- is_multisite()Determines whether Multisite is enabled.
- admin_url()Retrieves the URL to the admin area for the current site.
- wp_get_theme()Gets a WP_Theme object for a theme.
- wp_customize_url()Returns a URL to load the Customizer.
- wp_kses()Filters text content and strips out disallowed HTML.
- wp_star_rating()Outputs a HTML element with a star rating for a given rating.
- number_format_i18n()Converts float number to format based on the locale.
- set_url_scheme()Sets the scheme for a URL.
- is_wp_version_compatible()Checks compatibility with the current WordPress version.
- is_php_version_compatible()Checks compatibility with the current PHP version.
- wp_send_json_success()Sends a JSON response back to an Ajax request, indicating success.
- wp_get_theme($theme->slug)::is_block_theme()
Source code
function wp_ajax_query_themes() { global $themes_allowedtags, $theme_field_defaults; if ( ! current_user_can( 'install_themes' ) ) { wp_send_json_error(); } $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array( 'per_page' => 20, 'fields' => array_merge( (array) $theme_field_defaults, array( 'reviews_url' => true, // Explicitly request the reviews URL to be linked from the Add Themes screen. ) ), ) ); if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) { $user = get_user_option( 'wporg_favorites' ); if ( $user ) { $args['user'] = $user; } } $old_filter = $args['browse'] ?? 'search'; /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */ $args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args ); $api = themes_api( 'query_themes', $args ); if ( is_wp_error( $api ) ) { wp_send_json_error(); } $update_php = network_admin_url( 'update.php?action=install-theme' ); $installed_themes = search_theme_directories(); if ( false === $installed_themes ) { $installed_themes = array(); } foreach ( $installed_themes as $theme_slug => $theme_data ) { // Ignore child themes. if ( str_contains( $theme_slug, '/' ) ) { unset( $installed_themes[ $theme_slug ] ); } } foreach ( $api->themes as &$theme ) { $theme->install_url = add_query_arg( array( 'theme' => $theme->slug, '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), ), $update_php ); if ( current_user_can( 'switch_themes' ) ) { if ( is_multisite() ) { $theme->activate_url = add_query_arg( array( 'action' => 'enable', '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ), 'theme' => $theme->slug, ), network_admin_url( 'themes.php' ) ); } else { $theme->activate_url = add_query_arg( array( 'action' => 'activate', '_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ), 'stylesheet' => $theme->slug, ), admin_url( 'themes.php' )Changelog
Introduced in 3.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-admin/includes/ajax-actions.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.