Restrict a Post Types Post Status

I wonder if you could use something as simple as this: (similar to the suggestion of @ialocin)

/**
 * Use the "Force" on the post status ;-)
 */

add_action( 'wp_insert_post_data', function( $data, $postarr ){

    $change_post_status = array( 'draft', 'private' ); // Edit to your needs

    if( 'cpt' === $data['post_type'] 
         && in_array( $data['post_status'], $change_post_status, TRUE ) 
    )
        $data['post_status'] = 'publish';

    return $data;

}, PHP_MAX_INT, 2 );

where we just force the post status value when it’s part of the $change_post_status array – before the post is saved.

(… or maybe I’m misunderstanding the setup 😉

Leave a Comment