How to run a function when post is edited or updated using publish post action?

With the post_updated hook you can trigger an action when the post is updated. He passes 3 parameters:

  • $post_ID (the post ID),
  • $post_after(the post object after the edit),
  • $post_before (the post object before the edit)

Here’s an example:

<?php
function check_values($post_ID, $post_after, $post_before){
    echo 'Post ID:';
    var_dump($post_ID);

    echo 'Post Object AFTER update:';
    var_dump($post_after);

    echo 'Post Object BEFORE update:';
    var_dump($post_before);
}

add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function
?>

See reference Codex