There are hooks specifically for this, actually. The codex has a pretty good overview.
Essentially every time WordPress saves a post (which it does through wp_insert_post
) or alters the status of the post, it calls wp_transition_post_status
which looks like this:
<?php
// in wp-includes/post.php
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);
}
So, if you want to check for a post moving from publish to publish you could do this…
<?php
add_action('transition_post_status', 'wpse83835_transition', 10, 3);
function wpse83835_transition($new, $old, $post)
{
if ('publish' == $new && 'publish' == $old) {
// do stuff
}
}
Or this…
<?php
add_action('publish_to_publish', 'wpse83835_transition_again');
function wpse83835_transition_again($post)
{
// do stuff.
}