如何在WordPress中停用新用户的「账户已激活」邮件?
如何停用WordPress用户注册后的「账户已激活」邮件
我需要停用WordPress在用户注册后发送的「用户账户已激活」邮件,该邮件内容如下:
Hello XY,
Your account on [BLOG] has been activated! Find your login details below.
Login page: [BLOG/wp-login.php]
Username: XY
Password: Use the password you entered when you registered your account or set a new password using the link below.[BLOG]
This message was sent by [BLOG]
由于我已通过REST API将注册功能与邮件订阅工具对接,并启用了双重选择加入机制,这封邮件显得多余且易造成混淆,但我还没找到停用它的方法,希望能得到解决思路。
我曾尝试在functions.php文件中添加以下函数,但没有效果:
function disable_new_user_notifications() { return false; } add_filter('wp_notify_postauthor', 'disable_new_user_notifications'); add_filter('wp_notify_moderator', 'disable_new_user_notifications'); add_filter('wp_password_change_notification', 'disable_new_user_notifications'); add_filter('wp_new_user_notification', 'disable_new_user_notifications'); add_filter('wpmu_signup_user_notification_subject', 'disable_new_user_notifications');
解决方法
你之前使用的过滤器钩子不对,针对用户激活后的通知邮件,需根据WordPress版本及是否启用多站点,使用对应钩子禁用:
1. 单站点WordPress场景
将以下代码添加到主题的functions.php文件中:
// 禁用发送给新用户的激活通知邮件 add_filter( 'wp_new_user_notification_email', '__return_false', 10, 3 ); // 移除用户注册时触发邮件的默认动作 add_action( 'user_register', function( $user_id ) { remove_action( 'user_register', 'wp_send_new_user_notifications' ); }, 1 );
2. 多站点WordPress场景
如果你的站点是多站点模式,使用以下代码:
// 禁用多站点用户激活通知邮件 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); add_filter( 'wpmu_signup_user_notification', '__return_false' );
补充说明
wp_new_user_notification_email是WordPress 5.3版本后新增的过滤器,返回false即可直接阻止发送给用户的激活通知邮件。wp_send_new_user_notifications是WordPress默认在用户注册时触发的邮件发送函数,移除该动作可从根源阻止相关邮件触发。- 多站点环境下需要针对专属的多站点钩子进行设置,确保邮件被彻底禁用。
内容的提问来源于stack exchange,提问作者waltlin
相关产品推荐
相关产品推荐

