钩子文档

auto_core_update_email

💡 云策文档标注

概述

auto_core_update_email 是一个 WordPress 过滤器,用于自定义自动后台核心更新后发送的电子邮件通知。开发者可以通过此过滤器修改邮件的收件人、主题、正文和头部信息,以适应特定需求。

关键要点

  • 过滤器名称:auto_core_update_email,用于在自动核心更新后自定义电子邮件内容。
  • 参数:$email(数组,包含收件人、主题、正文和头部)、$type(字符串,更新类型,如 'success'、'fail'、'manual'、'critical')、$core_update(对象,更新信息)、$result(混合类型,更新结果,可为 WP_Error)。
  • 用途:允许开发者调整邮件通知的细节,例如添加额外信息或更改收件人列表。
  • 引入版本:WordPress 3.7.0。

代码示例

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

function wpdocs_auto_core_update_email( $email, $type, $core_update, $result ) {
    // 自定义主题行
    $email['subject'] = sprintf( __( 'WordPress Core Update: %s' ), ucfirst( $type ) );

    // 向邮件正文添加更多信息
    $email['body'] .= "nn---n" . __( 'Additional Information:' ) . "n";
    $email['body'] .= sprintf( __( 'Version: %s' ) . "n", $core_update->version );
    $email['body'] .= sprintf( __( 'Update Type: %s' ) . "n", $type );
    $email['body'] .= sprintf( __( 'Update Status: %s' ) . "n", $result ? __( 'Success' ) : __( 'Failure' ) );

    // 返回修改后的邮件数组
    return $email;
}

📄 原文内容

Filters the email sent following an automatic background core update.

Parameters

$emailarray
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.

$typestring
The type of email being sent. Can be one of 'success', 'fail', 'manual', 'critical'.
$core_updateobject
The update offer that was attempted.
$resultmixed
The result for the core update. Can be WP_Error.

Source

$email = apply_filters( 'auto_core_update_email', $email, $type, $core_update, $result );

Changelog

Version Description
3.7.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    The apply_filters( 'auto_core_update_email', array $email, string $type, object $core_update, mixed $result ) filter allows developers to customize the content and recipients of the email notification that WordPress sends after a core update.

    Add the following code to your theme’s functions.php file or in a custom plugin.

    add_filter( 'auto_core_update_email', 'wpdocs_auto_core_update_email', 10, 4 );
    
    function wpdocs_auto_core_update_email( $email, $type, $core_update, $result ) {
        // Customize the subject line
        $email['subject'] = sprintf( __( 'WordPress Core Update: %s' ), ucfirst( $type ) );
    
        // Add more information to the email body
        $email['body'] .= "nn---n" . __( 'Additional Information:' ) . "n";
        $email['body'] .= sprintf( __( 'Version: %s' ) . "n", $core_update->version );
        $email['body'] .= sprintf( __( 'Update Type: %s' ) . "n", $type );
        $email['body'] .= sprintf( __( 'Update Status: %s' ) . "n", $result ? __( 'Success' ) : __( 'Failure' ) );
    
        // Return the modified email
        return $email;
    }