pre_wp_mail
云策文档标注
概述
pre_wp_mail 是一个 WordPress 过滤器,用于在发送邮件前进行拦截或修改。返回非空值可以短路 wp_mail() 函数,直接返回该值,通常用于控制邮件发送流程。
关键要点
- pre_wp_mail 过滤器允许在 wp_mail() 执行前进行干预,返回非空值(如布尔值)可以指示邮件是否成功发送或直接返回自定义值。
- 过滤器接收两个参数:$return(短路返回值,默认为 null)和 $atts(包含 wp_mail() 参数的数组,如 to、subject、message 等)。
- 该过滤器在 WordPress 5.7.0 版本中引入,常用于插件或主题开发中自定义邮件发送逻辑。
原文内容
Filters whether to preempt sending an email.
Description
Returning a non-null value will short-circuit wp_mail(), returning that value instead. A boolean return value should be used to indicate whether the email was successfully sent.
Parameters
$returnnull|bool-
Short-circuit return value.
$attsarray-
Array of the
wp_mail()arguments.tostring|string[]Array or comma-separated list of email addresses to send message.subjectstringEmail subject.messagestringMessage contents.headersstring|string[]Additional headers.attachmentsstring|string[]Paths to files to attach.embedsstring|string[]Paths to files to embed.
Source
$pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |