On this page
wp_ajax_search_plugins()
Ajax handler for searching plugins.
Source
File: wp-admin/includes/ajax-actions.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| set_current_screen() wp-admin/includes/screen.php | Set the current screen object |
| get_current_screen() wp-admin/includes/screen.php | Get the current screen object |
| WP_List_Table::display() wp-admin/includes/class-wp-list-table.php | Displays the table. |
| WP_List_Table::ajax_user_can() wp-admin/includes/class-wp-list-table.php | Checks the current user’s permissions |
| WP_List_Table::prepare_items() wp-admin/includes/class-wp-list-table.php | Prepares the list of items for displaying. |
| wp_plugin_update_rows() wp-admin/includes/update.php | Adds a callback to display update information for plugins with updates available. |
| _get_list_table() wp-admin/includes/list-table.php | Fetches an instance of a WP_List_Table class. |
| network_admin_url() wp-includes/link-template.php | Retrieves the URL to the admin area for the network. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_unslash() wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. |
| sanitize_key() wp-includes/formatting.php | Sanitizes a string key. |
| check_ajax_referer() wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. |
| wp_send_json_error() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating failure. |
| wp_send_json_success() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. |
| add_query_arg() wp-includes/functions.php | Retrieves a modified URL query string. |
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_ajax_search_plugins