Using WordPress ‘automatic_updates_debug_email’ PHP filter

The automatic_updates_debug_email WordPress PHP filter allows you to modify the debug email sent after an automatic background core update. It provides an array of email arguments that will be passed to wp_mail().

Usage

add_filter('automatic_updates_debug_email', 'your_custom_function', 10, 3);

function your_custom_function($email, $failures, $results) {
    // your custom code here
    return $email;
}

Parameters

  • $email: (array) Array of email arguments that will be passed to wp_mail().
    • to: (string) The email recipient(s). Can be an array of emails.
    • subject: (string) Email subject.
    • body: (string) Email message body.
    • headers: (string) Any email headers. Default is empty.
  • $failures: (int) The number of failures encountered while upgrading.
  • $results: (mixed) The results of all attempted updates.

More information

See WordPress Developer Resources: automatic_updates_debug_email

Examples

Change the recipient of the debug email

Customize the email recipient for the debug email after automatic updates.

add_filter('automatic_updates_debug_email', 'change_debug_email_recipient', 10, 3);

function change_debug_email_recipient($email, $failures, $results) {
    $email['to'] = '[email protected]'; // Set a new email recipient
    return $email;
}

Modify the email subject

Customize the subject of the debug email after automatic updates.

add_filter('automatic_updates_debug_email', 'modify_debug_email_subject', 10, 3);

function modify_debug_email_subject($email, $failures, $results) {
    $email['subject'] = 'New Subject: Automatic Update Results'; // Set a new email subject
    return $email;
}

Add custom content to the email body

Append custom content to the debug email after automatic updates.

add_filter('automatic_updates_debug_email', 'append_custom_content_to_email_body', 10, 3);

function append_custom_content_to_email_body($email, $failures, $results) {
    $email['body'] .= "\n\nCustom Content: Additional information"; // Add custom content to the email body
    return $email;
}

Add custom headers to the email

Add custom email headers to the debug email after automatic updates.

add_filter('automatic_updates_debug_email', 'add_custom_email_headers', 10, 3);

function add_custom_email_headers($email, $failures, $results) {
    $email['headers'] = 'X-Custom-Header: custom value'; // Add custom email headers
    return $email;
}

Customize the debug email based on the number of failures

Change the email content based on the number of failures encountered during automatic updates.

add_filter('automatic_updates_debug_email', 'customize_email_based_on_failures', 10, 3);

function customize_email_based_on_failures($email, $failures, $results) {
    if ($failures > 0) {
        $email['subject'] = 'Automatic Update Failures Detected';
        $email['body'] = 'There were ' . $failures . ' update failures.' . "\n\n" . $email['body'];
    }
    return $email;
}