GC_Customize_Nav_Menus::ajax_search_available_items()

最后更新于:2021-11-27 03:42:19

GC_Customize_Nav_Menus::ajax_search_available_items()

Ajax handler for searching available menu items.

源文件

文件: gc-includes/class-gc-customize-nav-menus.php

	public function ajax_search_available_items() {
		check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );

		if ( ! current_user_can( 'edit_theme_options' ) ) {
			gc_die( -1 );
		}

		if ( empty( $_POST['search'] ) ) {
			gc_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( gc_unslash( $_POST['search'] ) );
		$items = $this->search_available_items_query(
			array(
				'pagenum' => $p,
				's'       => $s,
			)
		);

		if ( empty( $items ) ) {
			gc_send_json_error( array( 'message' => __( 'No results found.' ) ) );
		} else {
			gc_send_json_success( array( 'items' => $items ) );
		}
	}