Change error recovery email in WordPress

WordPress admin in recovery mode

WordPress introduced a new feature in version 5.2, the Fatal Error Recovery Mode https://make.wordpress.org/core/2019/04/16/fatal-error-recovery-mode-in-5-2/

What the Fatal Error Recovery Mode does in case of finding an error that would leave our website blank(WSoD, WordPress White Screen of Death) is to send an email to the administrator with a unique url so he can enter the website and search for the problem.

This functionality is great, but sometimes we are making a quick change to a customer’s website by skipping the process of local => staging => live and we provoke this WSoD that we will fix in a couple of seconds, but the web administrator will have already received the mail and will be asking us the reason for the error.

To avoid this we have a couple of solutions.

Disable Fatal Error Recovery Mode

If we do not want to be notified by mail of errors, because after all, we are already seeing them on the screen, we just have to put a constant in the WordPress configuration file, that is, in the wp-config.php:

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );

Change Fatal Error Recovery Mode mail

The second option is to continue to allow you to send this email, but instead of sending it to the web administrator, you send it to us.

We can do this in two different ways, just like the previous one, with a constant in the WordPress configuration file, that is, in the wp-config.php:

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

The second option is via a filter in our child theme’s functions.php file, in our custom code plugin, or in our must-use-plugin (which are loaded before regular plugins) via the following code:

add_filter( 'recovery_mode_email', function( $email_data ) {
     $email_data['to'] = '[email protected]';
     return $email_data;
 } );

That is all. Remember to leave everything as it was, or if you are going to take care of the maintenance of the site, change the administrator of the site to your user.

Join my superlist ;)

I won't share your details with anyone or bombard you with emails, only when I publish a new post or when I have something interesting to share with you.

Leave a Comment