ActiveCampaign / postmark-wordpress

The Official Postmark Wordpress Plugin
GNU General Public License v2.0
18 stars 17 forks source link

Apply pre_wp_mail filter to wp_mail() override #81

Closed JordanPak closed 2 years ago

JordanPak commented 2 years ago

I'm building an "email whitelist" plugin into a site that I'm working on so staging and local development environments can block all outgoing emails unless they're "To" a recipient(s) in a whitelist managed by the plugin. Out out the box, WordPress' wp_mail() has a pre_wp_mail filter that I can use to short-circuit the message if all of the "To" recipients have been filtered out BEFORE the site tries to send out the message.

The wp_mail() override in the Postmark plugin does not apply/check/honor pre_wp_mail, which means all of my outgoing messages get a "failed" response in the plugin's API log. It'd definitely be better for the site (and I imagine Postmark itself) if those emails with no remaining recipients (because they all weren't on the whitelist) could just be "cancelled" by the plugin before Postmark tries to process it and send it to the API.

Thank you for your time!

davelozier commented 2 years ago

I'd like to second this. It would be nice if we could short-circuit sending and just log the outbound message attempt. https://developer.wordpress.org/reference/hooks/pre_wp_mail/

pgraham3 commented 2 years ago

Hey @JordanPak @davelozier!

I have a PR opened for this request here. Can you please give it a look/test it out to see if it meets your needs?

Thanks!

JordanPak commented 2 years ago

Hey @pgraham3 that looks perfect and worked well in a test I just conducted. Thank you so much!

davelozier commented 2 years ago

@pgraham3 what Jordan said. I wont be able to test until later this evening but the code changes look to be exactly what is needed.

pgraham3 commented 2 years ago

Awesome - appreciate you two taking a look!

JordanPak commented 2 years ago

Thanks again @pgraham3! :)