我正在處理需要過濾自定義功能內容的場景。我的函數用於發送郵件,但我需要像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) –