Publish post when edit post form submitted with enter/return pressed on keyboard

you may add a filter on wp_insert_post_data:

add_filter( 'wp_insert_post_data', 'my_force_publish_post', 10, 2 );

function my_force_publish_post( $data, $postarr ) {
    if ( ! isset($postarr['ID']) || ! $postarr['ID'] ) return $data;
    if ( $postarr['post_type'] !== 'inventory' ) return $data;

    $old = get_post( $postarr['ID'] ); // the post before update
    if( $old->post_status !== 'draft' ) {
        // force a post to be set as published
        $data['post_status'] = 'publish'
    }
    return $data;
}

Leave a Comment