Using WordPress ‘auto_core_update_email’ PHP filter

The auto_core_update_email WordPress PHP filter allows you to customize the email sent following an automatic background core update.

Usage

add_filter('auto_core_update_email', 'your_custom_function', 10, 4);

function your_custom_function($email, $type, $core_update, $result) {
    // 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. An array of emails can be returned, as handled by wp_mail().
    • subject (string) – The email’s subject.
    • body (string) – The email message body.
    • headers (string) – Any email headers, defaults to no headers.
  • $type (string) – The type of email being sent. Can be one of ‘success’, ‘fail’, ‘manual’, ‘critical’.
  • $core_update (object) – The update offer that was attempted.
  • $result (mixed) – The result for the core update. Can be WP_Error.

More information

See WordPress Developer Resources: auto_core_update_email

Examples

Change the email recipient

Change the email recipient to a custom email address.

add_filter('auto_core_update_email', 'change_auto_update_email_recipient', 10, 4);

function change_auto_update_email_recipient($email, $type, $core_update, $result) {
    $email['to'] = '[email protected]';
    return $email;
}

Modify the email subject

Add the website name to the email subject.

add_filter('auto_core_update_email', 'modify_auto_update_email_subject', 10, 4);

function modify_auto_update_email_subject($email, $type, $core_update, $result) {
    $email['subject'] = get_bloginfo('name') . ' - ' . $email['subject'];
    return $email;
}

Customize the email body

Add a custom message to the email body.

add_filter('auto_core_update_email', 'customize_auto_update_email_body', 10, 4);

function customize_auto_update_email_body($email, $type, $core_update, $result) {
    $email['body'] = "Your custom message goes here.\n\n" . $email['body'];
    return $email;
}

Add custom email headers

Add a custom email header to the email.

add_filter('auto_core_update_email', 'add_custom_email_headers', 10, 4);

function add_custom_email_headers($email, $type, $core_update, $result) {
    $email['headers'] = 'From: Your Name <[email protected]>';
    return $email;
}

Modify email based on update type

Send a different email for ‘success’ and ‘fail’ update types.

add_filter('auto_core_update_email', 'modify_email_based_on_type', 10, 4);

function modify_email_based_on_type($email, $type, $core_update, $result) {
    if ($type === 'success') {
        $email['subject'] = 'Update Success';
        $email['body'] = "The update was successful!";
    } elseif ($type === 'fail') {
        $email['subject'] = 'Update Failed';
        $email['body'] = "Unfortunately, the update has failed.";
    }
    return $email;
}

Disable email for specific update type

Disable sending email for ‘manual’ update type.

add_filter('auto_core_update_email', 'disable_email_for_manual_type', 10, 4);

function disable_email_for_manual_type($email, $type, $core_update, $result) {
    if ($type === 'manual') {
        return false;
    }
    return $email;
}