Cómo evitar que se publiquen posts basado en un campo personalizado

    Con este snippet podemos comprobar el valor de un custom field y mostrar un error en base al mismo.

    <?php
    add_action( 'pre_post_update', 'intercept_publishing', 10, 2 );
    
    function intercept_publishing( $post_ID, $data ) {
    		$post = get_post( $post_ID );
    
    	if ( ! is_admin() ) {
    		return;
    	}
    
    	if ( 'post' !== get_post_type( $post_ID ) ) {
    		return;
    	}
    
    	//$_REQUEST is for quick edit assuming that the post meta field was added to the quick edit view by you elsewhere
    	if ( isset( $_POST['_adherence_status'] ) ) {
    		$approval_status = $_POST['_approval_status'];
    	} elseif ( isset( $_REQUEST['adherence_status'] ) ) {
    		$approval_status = $_REQUEST['approval_status'];
    	}
    
    	if ( ! isset( $approval_status ) ) {
    		return;
    	}
    
    	$post_status   = isset( $data['post_status'] ) ? $data['post_status'] : get_post_status( $post_ID );
            $edit_type     = isset( $data['post_status'] ) ? 'regular' : 'quick';
    	$error_message = '';
    
    	if ( ( $post_status === 'publish' ) && ( $approval_status !== 'approved' ) ) {
    		//different messages for regular edit vs quick edit
    		if ( $edit_type === 'regular' ) {
    			$error_message = 'Please check the "Approval Status" field before publishing. Posts should only be published if approved by the team editor.';
    		} else {
    			$error_message = 'Please check the "Approval Status" and "Status" fields before clicking "Update". Posts should only be published if approved by the team editor. ';
    		}
    
    		wp_die( '<b>Publishing Error: </b> ' . $error_message, 'Adherence Publishing Error', [ 'back_link' => true ] );
    	}
    }