Using WordPress ‘recovery_email_debug_info’ PHP filter

The ‘recovery_email_debug_info’ WordPress PHP filter allows you to customize the debug information that’s included in the fatal error protection email sent by WordPress when a fatal error occurs.

Usage

To use this filter, add the following code snippet to your theme’s functions.php file or a custom plugin:

add_filter( 'recovery_email_debug_info', 'your_custom_function_name' );

function your_custom_function_name( $message ) {
    // Your code to modify the $message array
    return $message;
}

Parameters

  • $message (array): An associative array containing the default debug information.

Examples

Add custom data to the debug information

add_filter( 'recovery_email_debug_info', 'add_custom_data_to_debug_info' );

function add_custom_data_to_debug_info( $message ) {
    $message['custom_data'] = 'Your custom data here';
    return $message;
}

Explanation: This code adds a new key-value pair to the debug information with custom data.

Remove specific data from the debug information

add_filter( 'recovery_email_debug_info', 'remove_specific_data_from_debug_info' );

function remove_specific_data_from_debug_info( $message ) {
    unset( $message['some_key_to_remove'] );
    return $message;
}

Explanation: This code removes a specific key-value pair from the debug information.

Change the debug information entirely

add_filter( 'recovery_email_debug_info', 'replace_debug_info' );

function replace_debug_info( $message ) {
    $new_debug_info = array(
        'new_key_1' => 'New value 1',
        'new_key_2' => 'New value 2',
    );
    return $new_debug_info;
}

Explanation: This code replaces the default debug information with a new custom array.

Add server information to the debug information

add_filter( 'recovery_email_debug_info', 'add_server_info_to_debug_info' );

function add_server_info_to_debug_info( $message ) {
    $message['server_info'] = $_SERVER;
    return $message;
}

Explanation: This code adds the server information from the $_SERVER superglobal to the debug information.

Add current user information to the debug information

add_filter( 'recovery_email_debug_info', 'add_user_info_to_debug_info' );

function add_user_info_to_debug_info( $message ) {
    $current_user = wp_get_current_user();
    $message['user_info'] = array(
        'ID' => $current_user->ID,
        'username' => $current_user->user_login,
        'email' => $current_user->user_email,
    );
    return $message;
}

Explanation: This code adds the current user’s ID, username, and email to the debug information.