我已经创建了一个自定义插件来根据需要重写wp_new_user_notification(),并且当从wp-login.php?action=register
表单或nextend-facebook-connect
插件注册新用户时,它工作正常。
此外,我还创建了一个自定义ajax表单来通过admin-ajax.php处理来自主题的注册,并且在这里一切正常,除了wp_new_user_notification(),我认为在这种情况下不会触发。 >
这是我的register_user
函数
add_action('wp_ajax_nopriv_register_user', 'register_user');
function register_user() {
$user_login = sanitize_user($_POST['user_login']);
$first_name = sanitize_text_field($_POST['first_name']);
$last_name = sanitize_text_field($_POST['last_name']);
$user_email = sanitize_email($_POST['user_email']);
$user_pass = $_POST['user_pass'];
$receive_newsletter = $_POST['receive_newsletter'];
$userdata = array(
'user_login' => $user_login,
'first_name' => $first_name,
'last_name' => $last_name,
'user_email' => $user_email,
'user_pass' => $user_pass
);
if($user_id = wp_insert_user($userdata)) {
add_user_meta($user_id, 'receive_newsletter', $receive_newsletter ? 1 : 0);
echo wp_send_json(array('html' => __('<strong>Congratulations</strong>: Your account is created successfully, please check your email for verification link to activate your account.', 'lh')));
exit;
}
}
答案 0 :(得分:0)
您必须自己调用该函数:
if($user_id = wp_insert_user($userdata)) {
add_user_meta($user_id, 'receive_newsletter', $receive_newsletter ? 1 : 0);
wp_new_user_notification($user_id,'','both');// <--- here
echo wp_send_json(array('html' => __('<strong>Congratulations</strong>: Your account is created successfully, please check your email for verification link to activate your account.', 'lh')));
exit;
}