I have a function on my site that it supposed to run when a new post is published (email push notification), with the exception of the same article updated (i.e publish_to_publish
transition, I don't want to send unnecessary push notifications)
I know that I can use the {old_status} to {new_status} action hooks, but this means that I have to specify all the transitions to publish
(new_to_publish
, draft_to_publish
, etc.).
My question is:
Can I use instead the
publish_post
hook and detect if it waspublish_to_publish
so I can explicitly negate it? something like:function send_email() { if ($transition == 'publish_to_publish') return; //(else) send email } add_action('publish_post', 'send_email', 10, 1);
If not, how do I tie multiple hooks to the same action? Do I just list them like so:
add_action('new_to_publish', 'send_mail', 10, 1); add_action('future_to_publish', 'send_mail', 10, 1); add_action('draft_to_publish', 'send_mail', 10, 1);
Or is there a more elegant way - like passing an array?