简体   繁体   English

如何在 WordPress 中为致命错误处理程序 (WSoD) 设置通知 Email

[英]How to Set Notification Email in WordPress for Fatal Error Handler (WSoD)

WordPress 5.2 integrated WSoD protection which by default it will send an email notification to admin when the site encounters some fatal error. WordPress 5.2 集成 WSoD 保护,默认情况下,当站点遇到一些致命错误时,它将向管理员发送 email 通知。 I had built my client a site which I would like to monitor such error in case it happens, but I dont want to insert an admin role in my client site just for this purpose.我已经为我的客户建立了一个站点,我想监控此类错误以防万一,但我不想仅仅为此目的在我的客户站点中插入管理员角色。 Is there any hook which I can also set an additional technical support email if such events occur?如果发生此类事件,是否有任何钩子我还可以设置额外的技术支持 email?

You are looking for the recovery mode hooks.您正在寻找恢复模式挂钩。 The first way, the simpler one, is setting the RECOVERY_MODE_EMAIL constant inside your wp-config.php.第一种更简单的方法是在 wp-config.php 中设置RECOVERY_MODE_EMAIL常量。

define( 'RECOVERY_MODE_EMAIL', 'you@example.com' );

It's also possible to change the Recovery Mode email address through the recovery_mode_email filter:也可以通过recovery_mode_email过滤器更改恢复模式 email 地址:

add_filter( 'recovery_mode_email', function( $email ) {
    $email['to'] = 'you@example.com';
    return $email;
} );

This way you will get the mail instead of your client, client is not scared and you are informed of the issue.这样您将收到邮件而不是您的客户,客户不会害怕并且您会被告知问题。 If you want this sent to multiple addresses, return the emails as an array:如果您希望将其发送到多个地址,请将电子邮件作为数组返回:

add_filter( 'recovery_mode_email', function( $email ) {
    $email['to'] = array('you1@example.com', 'you2@example.com');
    return $email;
} );

It is recommended to place your filter implementation into a separate plugin or mu-plugin to avoid Fatal Errors in theme that would cause the filter to never fire.建议将您的过滤器实现放在单独的插件或 mu-plugin 中,以避免主题中的致命错误导致过滤器永远不会触发。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM