In \includes\class-client.php:
public function check_ajax_permissions() {
check_ajax_referer(
'searchwp_live_search_client_nonce',
'searchwp_live_search_client_nonce',
true);
}
/**
* Potential (opt-in) performance tweak: skip any plugin that's not SearchWP-related.
*
And this function is used in following function at the same file:
public function search() {
$this->check_ajax_permissions();
if ( empty( $_REQUEST['swpquery'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
die();
}
$this->set_excerpt_length();
if ( Utils::is_searchwp_active() ) {
$this->show_results_searchwp_active();
} else {
$this->show_results_searchwp_not_active();
}
// Short circuit to keep the overhead of an admin-ajax.php call to a minimum.
die();
}
In \includes\class-form.php:
// Set up our parameters.
$params = [
'ajaxurl' => esc_url( $ajaxurl ),
'origin_id' => get_queried_object_id(),
'config' => $this->configs,
'msg_no_config_found' => esc_html__( 'No valid SearchWP Live Search configuration found!', 'searchwp-live-ajax-search' ),
'aria_instructions' => esc_html__( 'When autocomplete results are available use up and down arrows to review and enter to go to the desired page. Touch device users, explore by touch or with swipe gestures.' , 'searchwp-live-ajax-search' ),
'searchwp_live_search_client_nonce' => wp_create_nonce( 'searchwp_live_search_client_nonce' ),
];
// We need to JSON encode the configs.
$encoded_data = [
'l10n_print_after' => 'searchwp_live_search_params = ' . wp_json_encode( $params ) . ';',
];
// Localize and enqueue the script with all the variable goodness.
wp_localize_script( 'swp-live-search-client', 'searchwp_live_search_params', $encoded_data );