function duplicate($unit_id = '', $course_id = '')
 {
     global $wpdb;
     if ($unit_id == '') {
         $unit_id = $this->id;
     }
     /**
      * Allow Unit duplication to be cancelled when filter returns true.
      *
      * @since 1.2.2
      */
     if (apply_filters('coursepress_unit_cancel_duplicate', false, $unit_id)) {
         /**
          * Perform actions if the duplication was cancelled.
          *
          * @since 1.2.2
          */
         do_action('coursepress_unit_duplicate_cancelled', $unit_id);
         return false;
     }
     /* Duplicate course and change some data */
     $new_unit = $this->get_unit();
     $old_unit_id = $new_unit->ID;
     unset($new_unit->ID);
     unset($new_unit->guid);
     $new_unit->post_author = get_current_user_id();
     $new_unit->post_status = 'private';
     $new_unit->post_parent = $course_id;
     $new_unit_id = wp_insert_post($new_unit);
     /*
      * Duplicate unit post meta
      */
     if (!empty($new_unit_id)) {
         $post_metas = get_post_meta($old_unit_id);
         foreach ($post_metas as $key => $meta_value) {
             $value = array_pop($meta_value);
             $value = maybe_unserialize($value);
             update_post_meta($new_unit_id, $key, $value);
         }
     }
     update_post_meta($new_unit_id, 'course_id', $course_id);
     $unit_modules = $this->get_unit_modules($old_unit_id);
     foreach ($unit_modules as $unit_module) {
         $module = new Unit_Module($unit_module->ID);
         $module->duplicate($unit_module->ID, $new_unit_id);
     }
     /**
      * Perform action when the unit is duplicated.
      *
      * @since 1.2.2
      */
     do_action('coursepress_unit_duplicated', $new_unit_id);
 }