默认情况下,Wordpress会在提交注册后同时向电子邮件验证电子邮件发送欢迎电子邮件给用户。是否可以在点击该电子邮件验证链接激活其帐户后才发送该欢迎电子邮件?这里是我放入插件的代码; 它在注册后立即发送:
function send_welcome_email_to_new_user($user_id) {
$user = get_userdata($user_id);
$user_email = $user->user_email;
$username = $user->user_login;
$to = $user_email;
$subject = "Welcome to our site!";
$body = '
<h1>Dear ' . $username . ',</h1></br>
<p>Thank you for joining our site. Your account is now active.</p>
<p>Please go ahead and navigate around your account.</p>
<p>Let me know if you have further questions, I am here to help.</p>
<p>Enjoy the rest of your day!</p>
<p>Kind Regards,</p>
<p>Site Administrator</p>
';
$headers = array('Content-Type: text/html; charset=UTF-8');
if (wp_mail($to, $subject, $body, $headers)) {
error_log("email has been successfully sent to user whose email is " . $user_email);
}else{
error_log("email failed to sent to user whose email is " . $user_email);
}
}
add_action('user_register','send_welcome_email_to_new_user');
发布于 2018-06-01 14:23:12
尝试这个 :
function send_welcome_email_to_new_user($user_id) {
$user = get_userdata($user_id);
// get user data
$user_info = get_userdata($user_id);
// create md5 code to verify later
$code = md5(time());
// make it into a code to send it to user via email
$string = array('id'=>$user_id, 'code'=>$code);
// create the activation code and activation status
update_user_meta($user_id, 'is_activated', 0);
update_user_meta($user_id, 'activationcode', $code);
// create the url
$url = get_site_url(). '/sign-in/?p=' .base64_encode( serialize($string));
// basically we will edit here to make this nicer
$html = 'Please click the following links <br/><br/> <a href="'.$url.'">'.$url.'</a>';
// send an email out to user
wc_mail($user_info->user_email, __('Please activate your account'), $html);
}
add_action('user_register', 'send_welcome_email_to_new_user');
// we need this to handle all the getty hacks i made
function my_init(){
// check whether we get the activation message
if(isset($_GET['p'])){
$data = unserialize(base64_decode($_GET['p']));
$code = get_user_meta($data['id'], 'activationcode', true);
// check whether the code given is the same as ours
if($code == $data['code']){
// update the db on the activation process
update_user_meta($data['id'], 'is_activated', 1);
wc_add_notice( __( '<strong>Success:</strong> Your account has been activated! ', 'inkfool' ) );
}else{
wc_add_notice( __( '<strong>Error:</strong> Activation fails, please contact our administrator. ', 'inkfool' ) );
}
}
if(isset($_GET['q'])){
wc_add_notice( __( '<strong>Error:</strong> Your account has to be activated before you can login. Please check your email.', 'inkfool' ) );
}
if(isset($_GET['u'])){
my_user_register($_GET['u']);
wc_add_notice( __( '<strong>Succes:</strong> Your activation email has been resend. Please check your email.', 'inkfool' ) );
}
}
// hooks handler
add_action( 'init', 'my_init' );
https://stackoverflow.com/questions/-100004690
复制相似问题