我是在谷歌搜索一个特定的电子邮件问题时被引导到这篇文章的。有趣的是,发布的答案引用了我的一篇博客帖子和我的插件。这真是太棒了——除了我认为在这种情况下,这并不能真正回答OP。
问题是,给管理员的所有通知都需要转到指定的电子邮件地址,除了一个——新用户通知。
我的方法(前提是该过程是WP本地注册)是在wp_mail() (顺便说一句a filter at the end of the entire process).
我会使用该过滤器查看消息的内容,如果是发送给新用户通知的电子邮件,则使用该过滤器更改“收件人”地址。
在此示例中,将检查主题是否包含“新用户注册”,这是WP默认管理员通知电子邮件中主题行的一部分。如果是这种情况,则“收件人”电子邮件地址将更改为所需的地址。否则,所有其他情况都会原封不动地通过过滤器。
add_filter( \'wp_mail\', \'my_wp_mail_filter\' );
function my_wp_mail_filter( $args ) {
// Check the message subject for a known string in the notification email.
if ( strpos( $args[\'subject\'], \'New User Registration\' ) ) {
// This is the notification email, so change the "to" address.
$args[\'to\'] = \'def@hij.td\';
}
return $args;
}