预计阅读时间: 3 分钟

从WordPress 5.5开始,如果启用了插件或主题自动更新,当插件或插件自动更新成功或失败时,您将收到一封邮件通知。

如果您管理着多个网站,那么源源不断的自动更新邮件可能会有些讨厌。而且,如果您的网站有多个管理员用户,但是您不希望该类邮件打扰其他用户,那该这么办?

自定义主题和插件自动更新邮件通知的内容和收件人

WordPress 5.5 新增了一个钩子 auto_plugin_theme_update_email 允许我们进行邮件自定义。以下是一个简单的示例:


function myplugin_auto_plugin_theme_update_email( $email, $type, $successful_updates, $failed_updates ) {
    // 修改收件人邮箱
    $email['to'] = 'admin@example.com';
    // 修改【更新失败】的邮件标题
    if ( 'fail' === $type ) {
        $email['subject'] = __( 'ATTN: IT Department – SOME AUTO-UPDATES WENT WRONG!', 'my-plugin' );
    }
 
    return $email;
}
add_filter( 'auto_plugin_theme_update_email', 'myplugin_auto_plugin_theme_update_email', 10, 4 );

截止本文发布,WordPress官方还未添加 auto_plugin_theme_update_email 的帮助文档,如果你要了解更多信息,可以暂且看下 https://wpseek.com/hook/auto_plugin_theme_update_email/

禁用主题和插件自动更新邮件通知

如果你想要彻底禁用主题和插件自动更新的邮件通知,可以使用下面的函数来实现,添加到主题的functions.php 即可生效:


// 禁用插件自动更新邮件通知
add_filter( 'auto_plugin_update_send_email', '__return_false' );
 
// 禁用主题自动更新邮件通知
add_filter( 'auto_theme_update_send_email', '__return_false' );

如果你不懂弄代码,可以通过安装 Disable auto-update Email Notifications 插件来禁用邮件通知。

此文章对你有帮助吗? 已有 2 人说这篇文章是有用的。