Is there a hook that actually only fires when a post gets updated and where I can get $post_before and $post_after?
You’re probably looking for the post_updated
hook.
Usage
add_action( 'post_updated', 'wpse_264720_post_updated', 10, 3 );
function wpse_264720_post_updated( $post_ID, $post_after, $post_before ) {
//* Bail if this is an autosave
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
//* Bail if this is a post revision
if( wp_is_post_revision( $post_ID ) ) {
return;
}
//* Bail if not the correct post types
if( ! in_array( $post_after->post_type, [ 'post-type-1', 'post-type-2' ] ) ) {
return;
}
//* If you add/update/delete posts, remove action to avoid infinite loop
remove_action( 'post_updated', 'wpse_264720_post_updated', 10 );
//* Do something useful after the post was updated
//* If the post was updated, remove save_post action
remove_action( 'save_post', 'wpse_264720_save_post', 10, 3 );
}
//* Hypothetical function hooked to save_post
add_action( 'save_post', 'wpse_264720_save_post', 10, 3 );
function wpse_264720_save_post( $post_id, $post, $update ) {
//* Bail if post was an update
if( $update ) {
return;
}
//* Do something useful on save_post
}