/**
  * Sensei_Teacher::save_teacher_meta_box
  *
  * Save the new teacher / author to course and all lessons
  *
  * Hooked into admin_init
  *
  * @since 1.8.0
  * @access public
  * @parameters
  * @return array $users user id array
  */
 public function save_teacher_meta_box($course_id)
 {
     // check if this is a post from saving the teacher, if not exit early
     if (!isset($_POST['sensei-course-teacher-author']) || !isset($_POST['post_ID'])) {
         return;
     }
     //don't fire this hook again
     remove_action('save_post', array($this, 'save_teacher_meta_box'));
     // get the current post object
     $post = get_post($course_id);
     // get the current teacher/author
     $current_author = absint($post->post_author);
     $new_author = absint($_POST['sensei-course-teacher-author']);
     // loop through all post lessons to update their authors as well
     $this->update_course_lessons_author($course_id, $new_author);
     // do not do any processing if the selected author is the same as the current author
     if ($current_author == $new_author) {
         return;
     }
     // save the course  author
     $post_updates = array('ID' => $post->ID, 'post_author' => $new_author);
     wp_update_post($post_updates);
     // ensure the the modules are update so that then new teacher has access to them
     Sensei_Teacher::update_course_modules_author($course_id, $new_author);
     // notify the new teacher
     $this->teacher_course_assigned_notification($new_author, $course_id);
 }
示例#2
0
 /**
  * Testing Sensei_Teacher::update_course_modules_author
  * Test to see if the lessons in the course was assigned to
  * a new author.
  *
  * @since 1.8.0
  */
 public function testUpdateCourseModulesAuthorChangeLessons()
 {
     // setup assertions
     $test_teacher_id = wp_create_user('teacherCourseModulesAuthorLessons', 'teacherCourseModulesAuthorLessons', '*****@*****.**');
     // create test course with current admin as owner
     $test_course_id = $this->factory->get_random_course_id();
     $administrator = get_user_by('email', get_bloginfo('admin_email'));
     wp_update_post(array('ID' => $test_course_id, 'post_author' => $administrator->ID));
     //insert sample module terms
     $test_module_1 = wp_insert_term('Lesson Test Module', 'module');
     $test_module_2 = wp_insert_term('Lesson Test Module 2', 'module');
     // assign sample terms to course
     wp_set_object_terms($test_course_id, array($test_module_1['term_id'], $test_module_2['term_id']), 'module', true);
     // add sample lessons to course and assign them to modules
     $test_lessons = $this->factory->get_lessons();
     foreach ($test_lessons as $lesson_id) {
         update_post_meta($lesson_id, '_lesson_course', intval($test_course_id));
     }
     // split array in 2 and assign each group of lessons to one of the modules
     $array_middle = round((count($test_lessons) + 1) / 2);
     $lesson_in_module_1 = array_slice($test_lessons, 0, $array_middle);
     $lesson_in_module_2 = array_slice($test_lessons, $array_middle);
     // assign lessons to module 1
     foreach ($lesson_in_module_1 as $lesson_id) {
         wp_set_object_terms($lesson_id, $test_module_1['term_id'], 'module', false);
     }
     // assign lessons to module 2
     foreach ($lesson_in_module_2 as $lesson_id) {
         wp_set_object_terms($lesson_id, $test_module_2['term_id'], 'module', false);
     }
     // Do the update changing the author
     Sensei_Teacher::update_course_modules_author($test_course_id, $test_teacher_id);
     // check each lesson
     // do the lessons for module 1 group now belong to ta new module term with the new teacher as owner?
     $expected_module_1_slug = $test_teacher_id . '-' . str_ireplace(' ', '-', strtolower('Lesson Test Module'));
     foreach ($lesson_in_module_1 as $lesson_id) {
         $term_after_update = wp_get_object_terms($lesson_id, 'module');
         $this->assertEquals($expected_module_1_slug, $term_after_update[0]->slug, 'Lesson module was not updated, ID: ' . $lesson_id);
     }
     // do the lessons for module 2 group now belong to ta new module term with the new teacher as owner?
     $expected_module_2_slug = $test_teacher_id . '-' . str_ireplace(' ', '-', strtolower(trim('Lesson Test Module 2')));
     foreach ($lesson_in_module_2 as $lesson_id) {
         $term_after_update = wp_get_object_terms($lesson_id, 'module');
         $this->assertEquals($expected_module_2_slug, $term_after_update[0]->slug, 'Lesson module was not updated, ID: ' . $lesson_id);
     }
 }
示例#3
0
 /**
  * Sensei_Teacher::limit_teacher_edit_screen_post_types
  *
  * Determine if we're in admin and the current logged in use is a teacher
  *
  * @since 1.8.0
  * @access public
  * @parameters array $wp_query
  * @return bool $is_admin_teacher
  */
 public function is_admin_teacher()
 {
     if (!is_user_logged_in()) {
         return false;
     }
     $is_admin_teacher = false;
     if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) {
         $is_admin_teacher = true;
     }
     return $is_admin_teacher;
 }
 /**
  * WooThemes_Sensei_Updates::enhance_teacher_role
  *
  * This runs the update to create the teacher role
  * @access public
  * @since 1.8.0
  * @return void;
  */
 public function enhance_teacher_role()
 {
     require_once 'class-sensei-teacher.php';
     $teacher = new Sensei_Teacher();
     $teacher->create_role();
     return true;
 }
 /**
  * Determine which Sensei template to load based on the
  * current page context.
  *
  * @since 1.0
  *
  * @param string $template
  * @return string $template
  */
 public static function template_loader($template = '')
 {
     global $wp_query, $email_template;
     $find = array('woothemes-sensei.php');
     $file = '';
     if (isset($email_template) && $email_template) {
         $file = 'emails/' . $email_template;
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (is_single() && get_post_type() == 'course') {
         if (Sensei()->check_user_permissions('course-single')) {
             // possible backward compatible template include if theme overrides content-single-course.php
             // this template was removed in 1.9.0 and code all moved into the main single-course.php file
             self::locate_and_load_template_overrides(Sensei()->template_url . 'content-single-course.php', true);
             $file = 'single-course.php';
             $find[] = $file;
             $find[] = Sensei()->template_url . $file;
         } else {
             // No Permissions Page
             return self::get_no_permission_template();
         }
         // End If Statement
     } elseif (is_single() && get_post_type() == 'lesson') {
         if (Sensei()->check_user_permissions('lesson-single')) {
             // possible backward compatible template include if theme overrides content-single-lesson.php
             // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file
             self::locate_and_load_template_overrides(Sensei()->template_url . 'content-single-lesson.php', true);
             $file = 'single-lesson.php';
             $find[] = $file;
             $find[] = Sensei()->template_url . $file;
         } else {
             // No Permissions Page
             return self::get_no_permission_template();
         }
         // End If Statement
     } elseif (is_single() && get_post_type() == 'quiz') {
         if (Sensei()->check_user_permissions('quiz-single')) {
             // possible backward compatible template include if theme overrides content-single-quiz.php
             // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file
             self::locate_and_load_template_overrides(Sensei()->template_url . 'content-single-quiz.php', true);
             $file = 'single-quiz.php';
             $find[] = $file;
             $find[] = Sensei()->template_url . $file;
         } else {
             // No Permissions Page
             return self::get_no_permission_template();
         }
         // End If Statement
     } elseif (is_single() && get_post_type() == 'sensei_message') {
         // possible backward compatible template include if theme overrides content-single-message.php
         // this template was removed in 1.9.0 and code all moved into the main single-message.php file
         self::locate_and_load_template_overrides(Sensei()->template_url . 'content-single-message.php', true);
         $file = 'single-message.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (is_post_type_archive('course') || is_page(Sensei()->get_page_id('courses')) || is_tax('course-category')) {
         // possible backward compatible template include if theme overrides 'taxonomy-course-category'
         // this template was removed in 1.9.0 and replaced by archive-course.php
         self::locate_and_load_template_overrides(Sensei()->template_url . 'taxonomy-course-category.php');
         $file = 'archive-course.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (is_post_type_archive('sensei_message')) {
         $file = 'archive-message.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (is_tax('lesson-tag')) {
         // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php'
         // this template was removed in 1.9.0 and replaced by archive-lesson.php
         self::locate_and_load_template_overrides(Sensei()->template_url . 'taxonomy-lesson-tag.php');
         $file = 'archive-lesson.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (isset($wp_query->query_vars['learner_profile'])) {
         // Override for sites with static home page
         $wp_query->is_home = false;
         $file = 'learner-profile.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (isset($wp_query->query_vars['course_results'])) {
         // Override for sites with static home page
         $wp_query->is_home = false;
         $file = 'course-results.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     } elseif (is_author() && Sensei_Teacher::is_a_teacher(get_query_var('author')) && !user_can(get_query_var('author'), 'manage_options')) {
         $file = 'teacher-archive.php';
         $find[] = $file;
         $find[] = Sensei()->template_url . $file;
     }
     // Load the template file
     if ($file) {
         $template = locate_template($find);
         if (!$template) {
             $template = Sensei()->plugin_path() . '/templates/' . $file;
         }
     }
     // End If Statement
     return $template;
 }