Using WordPress ‘auto_plugin_theme_update_email’ PHP filter

The auto_plugin_theme_update_email WordPress PHP filter allows you to modify the email sent after an automatic background update for plugins and themes.

Usage

add_filter('auto_plugin_theme_update_email', 'customize_update_email', 10, 3);

function customize_update_email($email, $type, $successful_updates, $failed_updates) {
    // 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’, ‘mixed’.
  • $successful_updates (array) – A list of updates that succeeded.
  • $failed_updates (array) – A list of updates that failed.

More information

See WordPress Developer Resources: auto_plugin_theme_update_email

Examples

Change email recipient

Change the recipient of the update email.

function change_email_recipient($email, $type, $successful_updates, $failed_updates) {
    $email['to'] = '[email protected]';
    return $email;
}
add_filter('auto_plugin_theme_update_email', 'change_email_recipient', 10, 4);

Add CC to the email

Add a CC recipient to the update email.

function add_cc_to_update_email($email, $type, $successful_updates, $failed_updates) {
    $email['headers'] = 'Cc: [email protected]';
    return $email;
}
add_filter('auto_plugin_theme_update_email', 'add_cc_to_update_email', 10, 4);

Customize email subject

Modify the subject of the update email.

function customize_email_subject($email, $type, $successful_updates, $failed_updates) {
    $email['subject'] = 'Custom Subject: Plugin/Theme Updates';
    return $email;
}
add_filter('auto_plugin_theme_update_email', 'customize_email_subject', 10, 4);

Add additional content to email body

Add extra content to the email body.

function add_content_to_email_body($email, $type, $successful_updates, $failed_updates) {
    $email['body'] .= "\n\nAdditional content.";
    return $email;
}
add_filter('auto_plugin_theme_update_email', 'add_content_to_email_body', 10, 4);

Include the number of successful and failed updates in the subject

Display the count of successful and failed updates in the email subject.

function update_counts_in_subject($email, $type, $successful_updates, $failed_updates) {
    $email['subject'] = sprintf('Updates: %d successful, %d failed', count($successful_updates), count($failed_updates));
    return $email;
}
add_filter('auto_plugin_theme_update_email', 'update_counts_in_subject', 10, 4);