I want my user pay before every post publishing. I searched for some hooks that triggers before a post publishes, but all these hooks run after a post is successfully published and i don't want this. pre_post_update, publish_post, save_post and wp_insert_post are the available hooks. If there is not an action that runs before publishing post, how can i prevent publishing post is user don't pay when he wants to publish the post ?
Edit: Now i'm using this code for checking if a post is publishing, but this function is not working, i'm using this function in a custom plugin.
function af_check_payment( $new_status, $old_status, $post ) {
if ( $new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'barbershop' ) {
wp_transition_post_status( 'pending', $old_status, $post );
echo 'At least i know its publishing';
}
}
add_action( 'transition_post_status', 'af_check_payment', 10, 3 );
This function does not echo or change any post status.