public function add_new_learners()
 {
     $result = false;
     if (!isset($_POST['add_learner_submit'])) {
         return $result;
     }
     if (!isset($_POST['add_learner_nonce']) || !wp_verify_nonce($_POST['add_learner_nonce'], 'add_learner_to_sensei')) {
         return $result;
     }
     if (!isset($_POST['add_user_id']) || '' == $_POST['add_user_id'] || !isset($_POST['add_post_type']) || !isset($_POST['add_course_id']) || !isset($_POST['add_lesson_id'])) {
         return $result;
     }
     $post_type = $_POST['add_post_type'];
     $user_id = absint($_POST['add_user_id']);
     $course_id = absint($_POST['add_course_id']);
     switch ($post_type) {
         case 'course':
             $result = WooThemes_Sensei_Utils::user_start_course($user_id, $course_id);
             // Complete each lesson if course is set to be completed
             if (isset($_POST['add_complete_course']) && 'yes' == $_POST['add_complete_course']) {
                 $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
                 foreach ($lesson_ids as $id) {
                     WooThemes_Sensei_Utils::sensei_start_lesson($id, $user_id, true);
                 }
                 // Updates the Course status and it's meta data
                 WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id);
                 do_action('sensei_user_course_end', $user_id, $course_id);
             }
             break;
         case 'lesson':
             $lesson_id = absint($_POST['add_lesson_id']);
             $complete = false;
             if (isset($_POST['add_complete_lesson']) && 'yes' == $_POST['add_complete_lesson']) {
                 $complete = true;
             }
             $result = WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id, $complete);
             // Updates the Course status and it's meta data
             WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id);
             break;
     }
     // Set redirect URL after adding user to course/lesson
     $query_args = array('page' => $this->page_slug, 'view' => 'learners');
     if ($result) {
         if ($course_id) {
             $query_args['course_id'] = $course_id;
         }
         if ($lesson_id) {
             $query_args['lesson_id'] = $lesson_id;
         }
         $query_args['message'] = 'success';
     } else {
         $query_args['message'] = 'error';
     }
     $redirect_url = apply_filters('sensei_learners_add_learner_redirect_url', add_query_arg($query_args, admin_url('admin.php')));
     wp_safe_redirect(esc_url_raw($redirect_url));
     exit;
 }
 /**
  * Fires when a lesson has changed to check if the Course status needs changing
  * 
  * @param int $user_id
  * @param int $lesson_id
  */
 public function update_status_after_lesson_change($user_id, $lesson_id)
 {
     if (intval($user_id) > 0 && intval($lesson_id) > 0) {
         $course_id = get_post_meta($lesson_id, '_lesson_course', true);
         if (intval($course_id) > 0) {
             // Updates the Course status and it's meta data
             WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id);
         }
     }
 }