我有一个使用Ajax调用的函数:
function bs_reserve_gift()
{
if (!wp_verify_nonce($_POST[\'_wpnonce\'], \'reserve_gift\')) {
$response[\'status\'] = \'error\';
$response[\'message\'] = __(\'Something went wrong, please try again later!\', \'bs\');
echo json_encode($response);
exit();
} else {
update_post_meta($_POST[\'reserve_gift_id\'], \'gift_status\', \'reserved\');
$response[\'status\'] = \'success\';
$response[\'gift_id\'] = $_POST[\'reserve_gift_id\'];
$response[\'message\'] = __(\'Thank you, the gift was reserved for you!\', \'bs\');
echo json_encode($response);
exit();
}
}
add_action(\'wp_ajax_nopriv_reserve_gift\', \'bs_reserve_gift\');
add_action(\'wp_ajax_reserve_gift\', \'bs_reserve_gift\');
这适用于已登录的用户,但对于未登录的用户,由于某种原因,nonce不会验证。。。
我如何解决这个问题?