wp_verify_nonce()每次都向我显示错误值

时间:2020-09-17 13:17:36

标签: javascript jquery ajax wordpress

我有一个登录表单,可以使用WordPress Ajax调用进行验证。当用户按下“提交”按钮时,由于未激活电子邮件而收到此错误:

echo json_encode(
    array(
        'loggedin'      =>  false, 
        'message'       =>  __("Your email not activated! please <b><a href='#' id='resend_email'>click</a></b> here to active your email", 'listeo_core'),
        'resend_nonce'   => wp_create_nonce('resend_nonce')
    )    
);
die();

因此,上面的代码向我显示了此输出:

您的电子邮件未激活!请单击此处激活您的电子邮件

因此,当用户点击此处链接时,我写了另一个ajax调用:

这是jQuery代码:

$(".notification").on("click", "#resend_email", function (e) { // <-- see second argument of .on
    e.preventDefault();                            
    var user_login = $("#user_login").val();
    var resend_nonce = data.resend_nonce;
                              
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: listeo_login.ajaxurl,
        data: { 
            action: 'resend_action',
            _wpnonce_resend: resend_nonce,
            user_login : user_login
           },
     
        }).done( function( data ) {
            console.log( data );   
        }       
    })
});

现在针对此请求,我正在使用以下PHP代码

// Resend email     
add_action( 'wp_ajax_nopriv_resend_action', array( $this, 'resend_email' ) );

function resend_email () {   
    
    var_dump( wp_verify_nonce( $_REQUEST['_wpnonce_resend'], 'resend_nonce' ) );        
    echo json_encode([
        'okay' => 'I am fine'
    ]);    
    die();      
}

现在,为什么此 var_dump 显示 false 值?有什么理由吗?

0 个答案:

没有答案