我正在处理需要过滤自定义功能内容的场景。我的函数用于发送邮件,但我需要像wp_mail钩子那样过滤它。WordPress:为自定义功能添加自定义add_filter
这里是我的功能:
function koku_crm_send_sendgrid($sendgrid_api_key, $to, $subject, $text, $html) {
$sendgrid = new \SendGrid($sendgrid_api_key);
$mail = new KCSendGrid\Mail();
$from = new KCSendGrid\Email(get_bloginfo('name'), get_bloginfo('admin_email'));
$mail->setFrom($from);
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$content = new KCSendGrid\Content("text/plain", $text);
$mail->addContent($content);
$content = new KCSendGrid\Content("text/html", $html);
$mail->addContent($content);
$personalization = new KCSendGrid\Personalization();
$to = new KCSendGrid\Email(null, $to);
$personalization->addTo($to);
$mail->addPersonalization($personalization);
$sendgrid->client->mail()->send()->post($mail);
}
我想发送电子邮件之前变量来过滤“以$”。类似于wp_mail filter hook的东西。
我有很多搜索,请在这方面帮助我。提前谢谢你。
所以你想创建自己的过滤器/钩子,然后其他模块可以挂钩来改变邮件发送给谁?如果是这样,研究如何实现自定义挂钩... https://www.google.com/search?q=wordpress+create+own+filters – CBroe
您的意思是apply_filters();函数https://developer.wordpress.org/reference/functions/apply_filters/ –
嗨@ Mo'menMohamed,我想创建类似[wp_mail filter hook](https://codex.wordpress.org/Plugin_API/Filter_Reference/ wp_mail) –