I want to use check_ajax_referer() to verify a WP_nonce field using AJAX. Here you can find my html element.
<input type="hidden" name="login_nonce" value="<?= wp_create_nonce('login_nonce'); ?>"/>
Using jQuery I'm sending all the values from input fields to a POST request:
request = $.ajax({
type: 'POST',
url: 'handle-login.php',
data: {
user: $('input[name="login_username"]').val(),
pass: $('input[name="login_password"]').val(),
security: $('input[name="login_nonce"]').val()
},
dataType: 'json'
});
In handle-login.php I'm try doing the following:
require_once $_SERVER['DOCUMENT_ROOT'].'/wp-load.php';
$return = array();
if( check_ajax_referer( 'login_nonce', $_POST['security'], false ) )
$return['nonce'] = $_POST['login_nonce'];
echo $return
But in return I'll get nothing.. Someone knows what is up?