On this page
WP_Customize_Nav_Menus::ajax_search_available_items()
Ajax handler for searching available menu items.
Source
File: wp-includes/class-wp-customize-nav-menus.php. View all references
public function ajax_search_available_items() {
check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
if ( empty( $_POST['search'] ) ) {
wp_send_json_error( 'nav_menus_missing_search_parameter' );
}
$p = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 0;
if ( $p < 1 ) {
$p = 1;
}
$s = sanitize_text_field( wp_unslash( $_POST['search'] ) );
$items = $this->search_available_items_query(
array(
'pagenum' => $p,
's' => $s,
)
);
if ( empty( $items ) ) {
wp_send_json_error( array( 'message' => __( 'No results found.' ) ) );
} else {
wp_send_json_success( array( 'items' => $items ) );
}
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Customize_Nav_Menus::search_available_items_query() wp-includes/class-wp-customize-nav-menus.php | Performs post queries for available-item searching. |
| sanitize_text_field() wp-includes/formatting.php | Sanitizes a string from user input or from the database. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| __() 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. |
| 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. |
| absint() wp-includes/functions.php | Converts a value to non-negative integer. |
| wp_send_json_success() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/ajax_search_available_items