Close WordPress registration/password modification notification email and customized welcome email with three lines of code

» WordPress » Close WordPress registration/password modification notification email and customized welcome email with three lines of code

Use three short sentences of code to close WordPress's built-in email notification of registration, password modification, and write a simple welcome email notification function yourself.

三行代码关闭WordPress注册/密码修改通知邮件及自定义欢迎邮件-极客公园

preface

Registration Notice

In fact, there are two kinds of email notifications. One is to send email notifications to administrators, and the other is to send email notifications to users. I think the two administrator emails are unnecessary and must be closed, because as the website goes by, the webmaster doesn't care too much about registered users. In addition, if you encounter robot spam registration, You will be overwhelmed by these notification emails, so this function can be turned off. The function of sending email notification to users does not matter. If you want to have a better experience, you can keep it. After all, welcome email is needed.

Password modification email

In fact, it doesn't matter whether this function is turned off or not. But if you use a WordPress website like Yunluo's Git theme, which requires you to enter your own password to register, you will find that when you register, the user will receive a password modification email ❓ ❓ What is this operation? Maybe WordPress thinks that the operation of entering a password by itself is to change the password, so in order to avoid this embarrassing situation, we also need to turn off this function. In addition, actually, many users of our small websites do not care about it after they register and change the password....

  • Unless those who think their website is awesome

code

There is so much bullshit above, but actually there are only three lines of code, really three lines.

 add_filter( 'password_change_email', '__return_false' );// Close password modification user email add_filter( 'wp_new_user_notification_email_admin', '__return_false' );// Close the new user registration webmaster email add_filter( 'wp_new_user_notification_email', '__return_false' );// Close the mail of new user registration user
  • It's that simple

Custom Welcome Message

It says to close the registration email, but some people definitely need this function, such as sending a welcome email, but the registration email provided by WordPress is too lame, so we need to modify it. There are ways to customize the registration email, such as the following

https://www.wpdaxue.com/wp_new_user_notification.html

But we only need to welcome the user's email, and the administrator's email should be ignored. In addition, this code is still a bit numerous, so you can change the method of Cloud Cloud, save the country by curve, instead of using the notification hook provided by WordPress, you can directly hang the email function on the registration hook, which is simple

Note: Closing the new user registration code above does not affect the custom welcome email function, and the two have nothing to do with each other.

Welcome mail code

The code can be directly put into the function file of the topic.

 function git_register_mail( $user_id ) { $user = get_user_by( 'id', $user_id ); $user_pass = $_POST['password']; $blogname = get_option('blogname'); $message = '<div class="emailcontent" style="width:100%;max-width:720px;text-align:left;margin:0 auto;padding-top:80px;padding-bottom:20px"><div class="emailtitle"><h1 style="color:#fff; Background: # 51a0e3; line height: 70px; font size: 24px; font weight: 400; padding left: 40px; margin: 0 ">Notification of successful registration</h1><div class=" emailtext "style=" background: # fff; padding: 20px 32px 20px "><div style=" padding: 0; font weight: 700; color: # 6e6e6e; font size: 16px ">Dear '$ user->user_login.', Hello</ div><p style="color:#6e6e6e; Font size: 13px; line height: 24px ">Welcome to register ['. $blogname.'], here is your account information, please keep it properly</ p><table cellpadding="0" cellspacing="0" border="0" style="width:100%; Border top: 1px solid # eee; border left: 1px solid # eee; color: # 6e6e6e; font size: 16px; font weight: normal "><thead><tr><th colspan=" 2 "style=" padding: 10px 0; border right: 1px solid # eee; border bottom: 1px solid # eee; text align: center; background: # f8f8f8 ">Your detailed registration information</th></tr></head><tbody><tr><td style=" padding: 10px 0; Border right: 1px solid # eee; border bottom: 1px solid # eee; text align: center; width: 100px ">Log in to email</td><td style=" padding: 10px 20px 10px 30px; border right: 1px solid # eee; border bottom: 1px solid # eee; line height: 30px ">'$ user->user_email.'</td></tr><tr><td style="padding:10px 0; Border right: 1px solid # eee; border bottom: 1px solid # eee; text align: center ">Login password</td><td style=" padding: 10px 20px 10px 30px; border right: 1px solid # eee; border bottom: 1px solid # eee; line height: 30px ">'$ user_pass.'</td></tr></tbody></table><p style="color:#6e6e6e; Font size: 13px; line height: 24px ">If your account is abnormal, please contact us at the first time at '. get_bloginfo ('admin_email'). '</ p></div><div class="emailad" style="margin-top:4px"><a href="'.home_url().' "><img src=" http://reg.163.com/images/secmail/adv.png " alt="" style="margin:auto; width:100%;max-width:700px;height:auto"></a></div></div></div>'; $headers = "Content-Type:text/html;charset=UTF-8\n"; Wp_mail ($user ->user_email, '['. $blogname. '] Welcome to register'$ blogname, $message , $headers); } add_action( 'user_register', 'git_register_mail');

The renderings are as follows:
三行代码关闭WordPress注册/密码修改通知邮件及自定义欢迎邮件-极客公园

--End--

-- 完 --

Post reply

Your email address will not be disclosed. Required items have been used * tagging

3 Replies to "Close WordPress registration/password modification notification email and customized welcome email with three lines of code"

  1. Hello, when I saw your website, I also created a website to learn more from you. My website domain name is yuedutop.cn. I hope to link with you. If you agree, I hope you can contact me 397423577@qq.com