Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am building an add-on to an events module that checks for availability, since there wasn't a function for that in that module. Now that I have built the logic, there are three emails I will need to send:

  • One if the post is being submitted for the first time (ie 'New appointment')

  • One if the post has been published by the site admin, as normal users won't be able to publish by themselves (ie 'Your appointment has been approved')

  • One for if the post has been edited, AFTER it has been published already (ie 'Your appointment has been edited')

I have hooked into save_post and publish_post for those first two, but I want an entirely different email sent upon editing a PUBLISHED post. How can I test for whether the post is already published and this is just an edit, versus it being published for the first time?

share|improve this question

1 Answer

up vote 1 down vote accepted

Hook into edit_post to catch changes. And take a look at wp_transition_post_status() which is called on inserts and updates:

function wp_transition_post_status($new_status, $old_status, $post) {
    do_action('transition_post_status', $new_status, $old_status, $post);
    do_action("{$old_status}_to_{$new_status}", $post);
    do_action("{$new_status}_{$post->post_type}", $post->ID, $post);
}

On publish you hook into

  • draft_to_publish,
  • pending_to_publish and
  • auto-draft_to_publish.

For edits hook into publish_to_publish.

share|improve this answer
Yeah, I didn't quite understand how to use those, but that's what I needed to do! Now my emails are finely tuned. Thanks! – fasad Jun 29 '12 at 12:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.