Find us on Facebook

LightBlog
Responsive Ads Here

Thứ Sáu, 29 tháng 12, 2017

What is the way to hook all wordpress email

Question:

I have a wordpress site that have plugins: Contact form 7, WP Mail SMTP Plugin by Mail Bank, Spartpost...All of these plugins are able to send out email by anyway (wp_mail, smtp, http api)...
I am developing another plugin that will do my custom action on each sent out email by any plugin.
Currently, I can do the custom action on contact form 7 email with:
add_action('wpcf7_before_send_mail', 'my_custom_action', 10, 1);
My question: is there any hook, filter or something that is general to wordpress email? Instead of use action/filter of every plugins?

Answer:

Every WordPress email usually uses wp_mail(). Which is actually a wrapper of PHPMailer. Find out this wp_mail() functions documentation and source code, you'll find some hooks there which will be useful to you cases.
But keep it in mind that, those hooks will be applicable only if the mail is sent by using wp_mail(). If any email is send by any other function like the PHP native mail() function then the hooks may not work.

Không có nhận xét nào:

Đăng nhận xét