ActiveCampaign / postmark-wordpress

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

add action hook so we can save the messageid after the email is sent #23

Closed aytackokus closed 7 years ago

aytackokus commented 7 years ago

This is an enhancement for the issue #22

This feature will allow us to save MessageID after the email is sent.

If you want to save the MessageID to a POST, then you need to add the post id to the $headers argument of wp_mail function. This will not create any malfunctions with email part, because the headers does get filtered to a new variable ($recognized_headers).

For example: $headers['post_id'] = $post_id;

Arguments sent with the hook: $response = response from postmarkapp API $headers = headers from wp_mail function

So after the email is sent, we can catch the response_data by adding an action hook. add_action('postmark_response', 'handle_postmark_response', 10, 2);

function handle_postmark_response($response_data, $headers) { $response_data = json_decode($response_data['body']); $post_id = $headers['post_id']; $message_id = $response_data->MessageID; }

atheken commented 7 years ago

@aytackokus - This is really great. Since I'm not a wordpress guru, I've struggled with how best to provide this feedback, without breaking the wp_mail convention. This is a really elegant solution to that problem. I think it could also make sense to emit a hook for sending errors. What do you think?

aytackokus commented 7 years ago

@atheken Thanks. I think adding a hook for sending errors is a nice to have feature.

aytackokus commented 7 years ago

@atheken do you want me to add it? or will you do it?

atheken commented 7 years ago

@aytackokus If you have time to take a crack at it, I would appreciate it.

aytackokus commented 7 years ago

@atheken it is done!

aytackokus commented 7 years ago

Hello @atheken, when will you push this changes to the plugin?