如果您有一个拥有大量用户的 WordPress 站点,您将对这些新用户注册电子邮件非常熟悉。
这些电子邮件提醒您有新用户访问您的网站可能非常有用,但如果您每天都有用户注册,您可能希望禁用它们。
请务必注意,如果您根本不希望用户在您的 WordPress 网站上注册,您可以禁用该功能。 这是通过前往管理仪表板中的设置/常规来完成的。 从这里简单地取消选中“任何人都可以注册”,这将阻止新用户在您的网站上注册。
本文假设您希望用户注册并且只想禁用电子邮件通知。
今天我将向您展示两种在 WordPress 中禁用新用户注册电子邮件的方法。
使用 WordPress 插件禁用新用户通知电子邮件
在 WordPress 中禁用新用户通知电子邮件的最简单方法是使用管理通知电子邮件插件。 该插件将允许您禁用大量与管理员相关的电子邮件。
安装并激活插件后,您会在“通知电子邮件”设置中看到一个新选项。 在这里,您将能够控制一系列 WordPress 电子邮件选项。
虽然此插件允许您禁用密码更改、向用户发送新用户通知和忘记密码电子邮件等选项,但我们将重点关注页面顶部的管理员用户通知选项。
取消选中“向管理员发送新用户通知”选项将禁用新用户在您的 WordPress 网站上注册时收到的电子邮件。
在 WordPress 中禁用新用户电子邮件的代码片段
如果您不喜欢使用插件,可以使用这里的一些 PHP 代码。
您可以使用Code Snippets之类的插件将此代码片段添加到主题的 function.php 文件或站点。
<?php //Disable the new user notification sent to the site admin function smartwp_disable_new_user_notifications() { //Remove original use created emails remove_action( 'register_new_user', 'wp_send_new_user_notifications' ); remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 ); //Add new function to take over email creation add_action( 'register_new_user', 'smartwp_send_new_user_notifications' ); add_action( 'edit_user_created_user', 'smartwp_send_new_user_notifications', 10, 2 ); } function smartwp_send_new_user_notifications( $user_id, $notify = 'user' ) { if ( empty($notify) || $notify == 'admin' ) { return; }elseif( $notify == 'both' ){ //Only send the new user their email, not the admin $notify = 'user'; } wp_send_new_user_notifications( $user_id, $notify ); } add_action( 'init', 'smartwp_disable_new_user_notifications' );