recovery_mode_email
云策文档标注
概述
recovery_mode_email 是一个 WordPress 过滤器,用于修改恢复模式邮件的发送内容。它允许开发者自定义邮件的收件人、主题、正文等参数,以便在站点进入恢复模式时发送通知。
关键要点
- 过滤器名称:recovery_mode_email,用于过滤恢复模式邮件的构建数组。
- 参数:$email 数组,包含 to、subject、message、headers 和 attachments 键,用于 wp_mail() 调用;$url 字符串,表示进入恢复模式的 URL。
- 用法:通过 apply_filters 调用,开发者可以添加过滤器来修改 $email 数组,例如更改收件人地址。
- 相关函数:WP_Recovery_Mode_Email_Service::send_recovery_mode_email() 负责发送邮件。
- 版本历史:从 WordPress 5.2.0 引入,5.6.0 版本在 $email 参数中增加了 attachments 键。
代码示例
add_filter( 'recovery_mode_email', function( $email ) {
$email['to'] = 'admin@example.com';
return $email;
} );注意事项
- 建议将过滤器实现放在独立的插件或 mu-plugin 中,以避免主题或插件中的致命错误导致过滤器无法触发。
- 可以通过常量 RECOVERY_MODE_EMAIL 来覆盖邮件设置,但过滤器提供了更灵活的修改方式。
原文内容
Filters the contents of the Recovery Mode email.
Parameters
$emailarray-
Used to build a call to wp_mail() .
tostring|arrayArray or comma-separated list of email addresses to send message.subjectstringEmail subjectmessagestringMessage contentsheadersstring|arrayOptional. Additional headers.attachmentsstring|arrayOptional. Files to attach.
$urlstring-
URL to enter recovery mode.
Source
$email = apply_filters( 'recovery_mode_email', $email, $url );
Skip to note 3 content
Ulrich
In addition to using the constant
RECOVERY_MODE_EMAILto override the email the filter can be used.add_filter( 'recovery_mode_email', function( $email ) { $email['to'] = 'admin@example.com'; return $email; } );Skip to note 4 content
Garrett Hyder
It’s recommended to place your filter implementation into a separate plugin or mu-plugin to avoid Fatal Errors in your theme or plugin from causing the filter to never fire.
This was recently experienced in core#47939 – https://core.trac.wordpress.org/ticket/47939