ActiveCampaign / postmark-wordpress

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

wp_mail_from* filters are ignored #48

Open markdwhite opened 5 years ago

markdwhite commented 5 years ago

It looks like only the From headers are used to override whatever is set in postmark_settings, and that wp_mail_from and wp_mail_from_name are ignored. Is this correct?

This would suggest that we need to append to a From header in some way when we are using Postmark with a plugin that adds filters for wp_mail_from and from_name.

Does this sound about right?

pgraham3 commented 5 years ago

Hi @markdwhite,

That is correct - as of right now _wp_mailfrom and _wp_mail_fromname would be ignored with the _wpmail override we do. I can't speak to why that decision was made, as I wasn't involved in the project at the time.

I am hesitant to modify this behavior in case it has some unintended side effects for long time users of the plugin.

Would something like this be what is required to support using those filters with the Postmark for WordPress plugin?

markdwhite commented 5 years ago

@pgraham3

I totally understand about the need to maintain backwards compatibility. So it probably depends what order of precedence is best for correctly identifying $from.

The example code seems to be allowing the substitution of either/or wp_mail_from and wp_mail_from_name which requires the deconstruction of $from from the header. It might be reasonable to assume that the existence of a wp_mail_from allows for inclusion of wp_mail_from_name, otherwise $from from the header is used and wp_mail_from_name is discarded. So all that might be needed is:

$from = $recognized_headers['From'];

$from_email = apply_filters( 'wp_mail_from', $from_email );
if ( !empty( $from_email ) ) {
    $from = "<${from_email}>";
    $from_name = apply_filters( 'wp_mail_from_name', $from_name );
    if (!empty($from_name)) {
        $from = "${from_name} ${from}";
    }
}

And am I right in thinking that Postmark API will swap in the correct sender name from a Sender Signature if the sender email matches a signature? If so, we gain nothing by prepending the $from_name as it will be overwritten. I think I tested it this way, but could be wrong...