Prevent publish status/date saved on transition_post_status hook

I think that hook fires after the post status has been updated. Try this

add_action( 'pre_post_update', 'intercept_adherence_publishing', 10, 2);

    function intercept_adherence_publishing ($post_ID, $data ) {
        if (get_post_type($post_ID) !== 'protocol-adherence') {
            return;
        }
        $post = get_post($post_ID);
        $adherence_status = $_POST['_adherence_status'];

        if ( ( $data['post_status'] === 'publish' ) && ( $post->post_type == 'protocol-adherence' ) && ( $adherence_status !== 'accepted' ) ) {
            error_out('Published post ' . $post_ID . ' intercepted. Post remains unpublished due to adherence not being accepted');
            wp_die( '<b>Adherence Error: </b>Cannot publish adherence that is not accepted. Please save status in "Pending Review" instead of the publish button if the adherence is not accepted yet.', 'Adherence Publishing Error', [ 'back_link' => true ]);
        }
    }
   

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)