current_user_can( $capability ) ? wp_create_nonce( self::SEARCHWP_LIVE_SEARCH_PREFIX . 'settings' ) : '', 'prefix' => self::SEARCHWP_LIVE_SEARCH_PREFIX, ]; if ( ! empty( $settings ) && is_array( $settings ) ) { $l10n = array_merge( $l10n , $settings ); } wp_localize_script( $handle, '_SEARCHWP', $l10n ); } /** * Check if the AJAX call has all the necessary permissions (nonce and capability). * * @since 1.7.3 * * @param array $args Arguments to change method's behaviour. * * @return bool */ public static function check_ajax_permissions( $args = [] ) { $defaults = [ 'capability' => Settings_Api::get_capability(), 'query_arg' => false, 'die' => true, ]; $args = wp_parse_args( $args, $defaults ); $result = check_ajax_referer( self::SEARCHWP_LIVE_SEARCH_PREFIX . 'settings', $args['query_arg'], $args['die'] ); if ( $result === false ) { return false; } if ( ! current_user_can( $args['capability'] ) ) { $result = false; } if ( $result === false && $args['die'] ) { wp_die( -1, 403 ); } return (bool) $result; } }