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

1.7k views Asked by At

WordPress 5.2 integrated WSoD protection which by default it will send an email notification to admin when the site encounters some fatal error. 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?

1

There are 1 answers

4
GeorgeP On BEST ANSWER

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.

define( 'RECOVERY_MODE_EMAIL', '[email protected]' );

It’s also possible to change the Recovery Mode email address through the recovery_mode_email filter:

add_filter( 'recovery_mode_email', function( $email ) {
    $email['to'] = '[email protected]';
    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('[email protected]', '[email protected]');
    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.

Reference