WordPress 注册/重置密码/更改密码钩子

wordpress在提供邮件提醒的地方都留了hook,方便让开发者自定义。最新在添加第三方登录时遇到虚拟邮箱发信问题,为了防止给指定邮件地址后缀发信,可以利用如下wordpress提供的钩子来实现。

//https://www.wwttl.com/101.html 
//禁止用户注册时发送电子邮件给管理员
add_filter( 'wp_new_user_notification_email_admin', '__return_false' );

// 禁止用户重置修改密码时发送电子邮件给管理员
add_filter( 'wp_password_change_notification_email', '__return_false' );

// 禁止用户注册时发送电子邮件给注册者
add_filter( 'wp_new_user_notification_email', '__return_false' );

// 禁止邮箱地址改变时发送邮件给注册者
add_filter( 'send_email_change_email', '__return_false' );

// 禁止更改密码时发送电子邮件给注册者
add_filter( 'send_password_change_email', '__return_false' );

注册时过滤

//https://www.wwttl.com/101.html
// 注册时过滤有@oauth.com邮箱地址发送注册邮件提醒
function filter_email_recipient( $recipient, $user ) {
    $email = $user->user_email;
    $allowed_domains = array( 'test.com' );
    $email_parts = explode( '@', $email );
    $domain = end( $email_parts );

    if (!in_array( $domain, $allowed_domains ) ) {
        return $recipient;
    }
    return '';
}
add_filter( 'wp_new_user_notification_email', 'filter_email_recipient', 10, 2 );

评论时过滤

//https://www.wwttl.com/101.html
//过滤评论发送邮件地址
function custom_comment_email_filter( $emails, $comment_id ) {
    $blacklisted_domains = array( 'test.com' ); 

    $comment = get_comment( $comment_id );
    $comment_author_email = $comment->comment_author_email;
    $email_parts = explode( '@', $comment_author_email );
    $domain = end( $email_parts );

    if ( in_array( $domain, $blacklisted_domains ) ) {
        $key = array_search( $comment_author_email, $emails );
        if ( false !== $key ) {
            unset( $emails[ $key ] );
        }
    }

    return $emails;
}
add_filter( 'comment_notification_recipients', 'custom_comment_email_filter', 10, 2 );

将代码中的test.com换成你需要过滤的邮件地址后缀即可。

修改邮箱时过滤

//https://www.wwttl.com/101.html
// 禁止修改邮箱地址时发送确认邮件
add_filter( 'send_email_change_email', '__return_false' );

我这里直接禁止,如果想过滤,可以参考上面的过滤代码

修改密码时过滤

//https://www.wwttl.com/101.html
// 禁止修改密码时发送密码重置邮件
add_filter( 'send_password_change_email', '__return_false' );

我这里直接禁止,如果想过滤,可以参考上面的过滤代码

相关推荐

  1. WordPress 注册/密码/更改密码钩子

    2023-12-10 22:56:04       58 阅读
  2. alist密码

    2023-12-10 22:56:04       75 阅读
  3. JIRA 管理员密码

    2023-12-10 22:56:04       61 阅读
  4. gitlab root密码

    2023-12-10 22:56:04       42 阅读
  5. sofether管理员密码

    2023-12-10 22:56:04       39 阅读
  6. Grafana admin 密码

    2023-12-10 22:56:04       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-10 22:56:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-10 22:56:04       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-10 22:56:04       87 阅读
  4. Python语言-面向对象

    2023-12-10 22:56:04       96 阅读

热门阅读

  1. python 记录今日学习按键消息心得

    2023-12-10 22:56:04       56 阅读
  2. linux 关于$-的解释(帖子搜索合集)

    2023-12-10 22:56:04       80 阅读
  3. DockerFile中途执行出错的解决办法

    2023-12-10 22:56:04       59 阅读
  4. C++运算符重载

    2023-12-10 22:56:04       42 阅读
  5. 【Go自学版】01-基础

    2023-12-10 22:56:04       60 阅读
  6. springboot分页查询

    2023-12-10 22:56:04       57 阅读
  7. Python ipaddress模块介绍

    2023-12-10 22:56:04       58 阅读
  8. 2020蓝桥杯c组纸张大小

    2023-12-10 22:56:04       64 阅读
  9. 生活小记录

    2023-12-10 22:56:04       53 阅读
  10. FCN 模型简介及代码

    2023-12-10 22:56:04       48 阅读
  11. PyQt创建界面

    2023-12-10 22:56:04       56 阅读
  12. 数据管理系统-week12-数据库审计(Database Auditing)

    2023-12-10 22:56:04       53 阅读