wp_ajax_search_plugins()
- Since
- 4.6.0
- Source
wp-admin/includes/ajax-actions.php:4791
Compatibility
- WordPress
- since 4.6.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_search_plugins() 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
- Moderate
- Scaling
- Constant
- Instructions
- 68–86
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_site_transient(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 87.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below wp_ajax_search_plugins() - transienttransient
get_site_transient()one call below wp_ajax_search_plugins()
Further down the call graph this can also reach cache, option, serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_search_plugins() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) && $pagenow !== "plugins-network" && $pagenow !== "plugins" && ->ajax_user_can() | 68 | check_ajax_referer(), wp_plugin_update_rows(), get_current_screen(), screen(), ->ajax_user_can(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
!isset($value) && ->ajax_user_can() | 69–71 | check_ajax_referer(), wp_plugin_update_rows(), set_current_screen(), get_current_screen(), screen(), ->ajax_user_can(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
isset($value) && $pagenow !== "plugins-network" && $pagenow !== "plugins" && ->ajax_user_can() | 75 | check_ajax_referer(), wp_plugin_update_rows(), sanitize_key(), get_current_screen(), screen(), ->ajax_user_can(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
!isset($value) && $pagenow !== "plugins-network" && $pagenow !== "plugins" && !->ajax_user_can() | 76 | check_ajax_referer(), wp_plugin_update_rows(), get_current_screen(), screen(), ->ajax_user_can(), __(), wp_send_json_error(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
isset($value) && ->ajax_user_can() | 76–78 | check_ajax_referer(), wp_plugin_update_rows(), sanitize_key(), set_current_screen(), get_current_screen(), screen(), ->ajax_user_can(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
!isset($value) && !->ajax_user_can() | 77–79 | check_ajax_referer(), wp_plugin_update_rows(), set_current_screen(), get_current_screen(), screen(), ->ajax_user_can(), __(), wp_send_json_error(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
isset($value) && $pagenow !== "plugins-network" && $pagenow !== "plugins" && !->ajax_user_can() | 83 | check_ajax_referer(), wp_plugin_update_rows(), sanitize_key(), get_current_screen(), screen(), ->ajax_user_can(), __(), wp_send_json_error(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
isset($value) && !->ajax_user_can() | 84–86 | check_ajax_referer(), wp_plugin_update_rows(), sanitize_key(), set_current_screen(), get_current_screen(), screen(), ->ajax_user_can(), __(), wp_send_json_error(), array_diff_key(), network_admin_url(), add_query_arg(), wp_unslash(), ->prepare_items(), ob_start(), ->display(), ob_get_clean(), wp_send_json_success() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 86 | 68–85 | 4 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 87 | 68–86 | 4 | |
| 8.4 | 87 | 68–86 | 4 | |
| 8.3 | 87 | 68–86 | 4 | |
| 8.2 | 87 | 68–86 | 4 | |
| 8.1 | 87 | 68–86 | 4 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 88 | 69–87 | 4 |
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.
Uses · 12
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- wp_plugin_update_rows()Adds a callback to display update information for plugins with updates available.
- sanitize_key()Sanitizes a string key.
- set_current_screen()Set the current screen object
- _get_list_table()Fetches an instance of a WP_List_Table class.
- get_current_screen()Get the current screen object
- __()Retrieves the translation of $text.
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- add_query_arg()Retrieves a modified URL query string.
- network_admin_url()Retrieves the URL to the admin area for the network.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- wp_send_json_success()Sends a JSON response back to an Ajax request, indicating success.
Source code
function wp_ajax_search_plugins() { check_ajax_referer( 'updates' ); // Ensure after_plugin_row_{$plugin_file} gets hooked. wp_plugin_update_rows(); $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : ''; if ( 'plugins-network' === $pagenow || 'plugins' === $pagenow ) { set_current_screen( $pagenow ); } /** @var WP_Plugins_List_Table $wp_list_table */ $wp_list_table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => get_current_screen(), ) ); $status = array(); if ( ! $wp_list_table->ajax_user_can() ) { $status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' ); wp_send_json_error( $status ); } // Set the correct requester, so pagination works. $_SERVER['REQUEST_URI'] = add_query_arg( array_diff_key( $_POST, array( '_ajax_nonce' => null, 'action' => null, ) ), network_admin_url( 'plugins.php', 'relative' ) ); $GLOBALS['s'] = wp_unslash( $_POST['s'] ); $wp_list_table->prepare_items(); ob_start(); $wp_list_table->display(); $status['count'] = count( $wp_list_table->items ); $status['items'] = ob_get_clean(); wp_send_json_success( $status );}Changelog
Introduced in 4.6.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.8.8 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.