@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Course Results Class |
@@ -21,20 +21,20 @@ discard block |
||
| 21 | 21 | * Constructor. |
| 22 | 22 | * @since 1.4.0 |
| 23 | 23 | */ |
| 24 | - public function __construct () { |
|
| 24 | + public function __construct() { |
|
| 25 | 25 | |
| 26 | 26 | // Setup learner profile URL base |
| 27 | - $this->courses_url_base = apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url slug', 'woothemes-sensei' ) ); |
|
| 27 | + $this->courses_url_base = apply_filters('sensei_course_slug', _x('course', 'post type single url slug', 'woothemes-sensei')); |
|
| 28 | 28 | |
| 29 | 29 | // Setup permalink structure for course results |
| 30 | - add_action( 'init', array( $this, 'setup_permastruct' ) ); |
|
| 31 | - add_filter( 'wp_title', array( $this, 'page_title' ), 10, 2 ); |
|
| 30 | + add_action('init', array($this, 'setup_permastruct')); |
|
| 31 | + add_filter('wp_title', array($this, 'page_title'), 10, 2); |
|
| 32 | 32 | |
| 33 | 33 | // Load course results |
| 34 | - add_action( 'sensei_course_results_content_inside_before', array( $this, 'deprecate_course_result_info_hook' ), 10 ); |
|
| 34 | + add_action('sensei_course_results_content_inside_before', array($this, 'deprecate_course_result_info_hook'), 10); |
|
| 35 | 35 | |
| 36 | 36 | // Add class to body tag |
| 37 | - add_filter( 'body_class', array( $this, 'body_class' ), 10, 1 ); |
|
| 37 | + add_filter('body_class', array($this, 'body_class'), 10, 1); |
|
| 38 | 38 | |
| 39 | 39 | } // End __construct() |
| 40 | 40 | |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | * @return void |
| 45 | 45 | */ |
| 46 | 46 | public function setup_permastruct() { |
| 47 | - add_rewrite_rule( '^' . $this->courses_url_base . '/([^/]*)/results/?', 'index.php?course_results=$matches[1]', 'top' ); |
|
| 48 | - add_rewrite_tag( '%course_results%', '([^&]+)' ); |
|
| 47 | + add_rewrite_rule('^'.$this->courses_url_base.'/([^/]*)/results/?', 'index.php?course_results=$matches[1]', 'top'); |
|
| 48 | + add_rewrite_tag('%course_results%', '([^&]+)'); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | * @param string $sep Seeparator string |
| 55 | 55 | * @return string Modified title |
| 56 | 56 | */ |
| 57 | - public function page_title( $title, $sep = null ) { |
|
| 57 | + public function page_title($title, $sep = null) { |
|
| 58 | 58 | global $wp_query; |
| 59 | - if( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 60 | - $course = get_page_by_path( $wp_query->query_vars['course_results'], OBJECT, 'course' ); |
|
| 61 | - $title = __( 'Course Results: ', 'woothemes-sensei' ) . $course->post_title . ' ' . $sep . ' '; |
|
| 59 | + if (isset($wp_query->query_vars['course_results'])) { |
|
| 60 | + $course = get_page_by_path($wp_query->query_vars['course_results'], OBJECT, 'course'); |
|
| 61 | + $title = __('Course Results: ', 'woothemes-sensei').$course->post_title.' '.$sep.' '; |
|
| 62 | 62 | } |
| 63 | 63 | return $title; |
| 64 | 64 | } |
@@ -69,18 +69,18 @@ discard block |
||
| 69 | 69 | * @param integer $course_id ID of course |
| 70 | 70 | * @return string The course results page permalink |
| 71 | 71 | */ |
| 72 | - public function get_permalink( $course_id = 0 ) { |
|
| 72 | + public function get_permalink($course_id = 0) { |
|
| 73 | 73 | |
| 74 | 74 | $permalink = ''; |
| 75 | 75 | |
| 76 | - if( $course_id > 0 ) { |
|
| 76 | + if ($course_id > 0) { |
|
| 77 | 77 | |
| 78 | - $course = get_post( $course_id ); |
|
| 78 | + $course = get_post($course_id); |
|
| 79 | 79 | |
| 80 | - if ( get_option('permalink_structure') ) { |
|
| 81 | - $permalink = trailingslashit( get_home_url() ) . $this->courses_url_base . '/' . $course->post_name . '/results/'; |
|
| 80 | + if (get_option('permalink_structure')) { |
|
| 81 | + $permalink = trailingslashit(get_home_url()).$this->courses_url_base.'/'.$course->post_name.'/results/'; |
|
| 82 | 82 | } else { |
| 83 | - $permalink = trailingslashit( get_home_url() ) . '?course_results=' . $course->post_name; |
|
| 83 | + $permalink = trailingslashit(get_home_url()).'?course_results='.$course->post_name; |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | * @return void |
| 94 | 94 | */ |
| 95 | 95 | public function content() { |
| 96 | - global $wp_query, $current_user; |
|
| 96 | + global $wp_query, $current_user; |
|
| 97 | 97 | |
| 98 | - if( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 99 | - Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 98 | + if (isset($wp_query->query_vars['course_results'])) { |
|
| 99 | + Sensei_Templates::get_template('course-results/course-info.php'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | } |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | global $course; |
| 112 | 112 | |
| 113 | - $course_status = Sensei_Utils::sensei_user_course_status_message( $course->ID, get_current_user_id()); |
|
| 114 | - echo '<div class="sensei-message ' . $course_status['box_class'] . '">' . $course_status['message'] . '</div>'; |
|
| 113 | + $course_status = Sensei_Utils::sensei_user_course_status_message($course->ID, get_current_user_id()); |
|
| 114 | + echo '<div class="sensei-message '.$course_status['box_class'].'">'.$course_status['message'].'</div>'; |
|
| 115 | 115 | |
| 116 | - sensei_do_deprecated_action( 'sensei_course_results_lessons','1.9.','sensei_course_results_content_inside_after', $course ); |
|
| 116 | + sensei_do_deprecated_action('sensei_course_results_lessons', '1.9.', 'sensei_course_results_content_inside_after', $course); |
|
| 117 | 117 | |
| 118 | - sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 118 | + sensei_do_deprecated_action('sensei_course_results_bottom', '1.9.', 'sensei_course_results_content_inside_after', $course->ID); |
|
| 119 | 119 | |
| 120 | 120 | } |
| 121 | 121 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | public function course_lessons() { |
| 129 | 129 | |
| 130 | 130 | global $course; |
| 131 | - _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 131 | + _deprecated_function('Sensei_modules course_lessons ', '1.9.0'); |
|
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | * @param array $classes Existing classes |
| 138 | 138 | * @return array Modified classes |
| 139 | 139 | */ |
| 140 | - public function body_class( $classes ) { |
|
| 140 | + public function body_class($classes) { |
|
| 141 | 141 | global $wp_query; |
| 142 | - if( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 142 | + if (isset($wp_query->query_vars['course_results'])) { |
|
| 143 | 143 | $classes[] = 'course-results'; |
| 144 | 144 | } |
| 145 | 145 | return $classes; |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @deprecated since 1.9.0 |
| 152 | 152 | */ |
| 153 | - public static function deprecate_sensei_course_results_content_hook(){ |
|
| 153 | + public static function deprecate_sensei_course_results_content_hook() { |
|
| 154 | 154 | |
| 155 | - sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 155 | + sensei_do_deprecated_action('sensei_course_results_content', '1.9.0', 'sensei_course_results_content_before'); |
|
| 156 | 156 | |
| 157 | 157 | } |
| 158 | 158 | |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @since 1.9.0 |
| 163 | 163 | */ |
| 164 | - public static function fire_sensei_message_hook(){ |
|
| 164 | + public static function fire_sensei_message_hook() { |
|
| 165 | 165 | |
| 166 | - do_action( 'sensei_frontend_messages' ); |
|
| 166 | + do_action('sensei_frontend_messages'); |
|
| 167 | 167 | |
| 168 | 168 | } |
| 169 | 169 | |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @since 1.9.0 |
| 174 | 174 | */ |
| 175 | - public static function deprecate_course_result_info_hook(){ |
|
| 175 | + public static function deprecate_course_result_info_hook() { |
|
| 176 | 176 | |
| 177 | - sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 177 | + sensei_do_deprecated_action('sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before'); |
|
| 178 | 178 | |
| 179 | 179 | } |
| 180 | 180 | |
@@ -183,10 +183,10 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @deprecate since 1.9.0 |
| 185 | 185 | */ |
| 186 | - public static function deprecate_course_results_top_hook(){ |
|
| 186 | + public static function deprecate_course_results_top_hook() { |
|
| 187 | 187 | |
| 188 | 188 | global $course; |
| 189 | - sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 189 | + sensei_do_deprecated_action('sensei_course_results_top', '1.9.0', 'sensei_course_results_content_inside_before', $course->ID); |
|
| 190 | 190 | |
| 191 | 191 | } |
| 192 | 192 | |
@@ -195,10 +195,10 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @since 1.8.0 |
| 197 | 197 | */ |
| 198 | - public static function fire_course_image_hook(){ |
|
| 198 | + public static function fire_course_image_hook() { |
|
| 199 | 199 | |
| 200 | 200 | global $course; |
| 201 | - do_action( 'sensei_course_image', $course->ID ); |
|
| 201 | + do_action('sensei_course_image', $course->ID); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -209,4 +209,4 @@ discard block |
||
| 209 | 209 | * for backward compatibility |
| 210 | 210 | * @since 1.9.0 |
| 211 | 211 | */ |
| 212 | -class WooThemes_Sensei_Course_Results extends Sensei_Course_Results{} |
|
| 212 | +class WooThemes_Sensei_Course_Results extends Sensei_Course_Results {} |
|
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Grading Overview List Table Class |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @since 1.3.0 |
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | - public function __construct ( $args = null ) { |
|
| 28 | + public function __construct($args = null) { |
|
| 29 | 29 | |
| 30 | 30 | $defaults = array( |
| 31 | 31 | 'course_id' => 0, |
@@ -33,24 +33,24 @@ discard block |
||
| 33 | 33 | 'user_id' => false, |
| 34 | 34 | 'view' => 'ungraded', |
| 35 | 35 | ); |
| 36 | - $args = wp_parse_args( $args, $defaults ); |
|
| 36 | + $args = wp_parse_args($args, $defaults); |
|
| 37 | 37 | |
| 38 | - $this->course_id = intval( $args['course_id'] ); |
|
| 39 | - $this->lesson_id = intval( $args['lesson_id'] ); |
|
| 40 | - if ( !empty($args['user_id']) ) { |
|
| 41 | - $this->user_id = intval( $args['user_id'] ); |
|
| 38 | + $this->course_id = intval($args['course_id']); |
|
| 39 | + $this->lesson_id = intval($args['lesson_id']); |
|
| 40 | + if ( ! empty($args['user_id'])) { |
|
| 41 | + $this->user_id = intval($args['user_id']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if( !empty( $args['view'] ) && in_array( $args['view'], array( 'in-progress', 'graded', 'ungraded', 'all' ) ) ) { |
|
| 44 | + if ( ! empty($args['view']) && in_array($args['view'], array('in-progress', 'graded', 'ungraded', 'all'))) { |
|
| 45 | 45 | $this->view = $args['view']; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // Load Parent token into constructor |
| 49 | - parent::__construct( 'grading_main' ); |
|
| 49 | + parent::__construct('grading_main'); |
|
| 50 | 50 | |
| 51 | 51 | // Actions |
| 52 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
| 53 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
| 52 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
| 53 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
| 54 | 54 | } // End __construct() |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function get_columns() { |
| 62 | 62 | $columns = array( |
| 63 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
| 64 | - 'course' => __( 'Course', 'woothemes-sensei' ), |
|
| 65 | - 'lesson' => __( 'Lesson', 'woothemes-sensei' ), |
|
| 66 | - 'updated' => __( 'Updated', 'woothemes-sensei' ), |
|
| 67 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
| 68 | - 'user_grade' => __( 'Grade', 'woothemes-sensei' ), |
|
| 63 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
| 64 | + 'course' => __('Course', 'woothemes-sensei'), |
|
| 65 | + 'lesson' => __('Lesson', 'woothemes-sensei'), |
|
| 66 | + 'updated' => __('Updated', 'woothemes-sensei'), |
|
| 67 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
| 68 | + 'user_grade' => __('Grade', 'woothemes-sensei'), |
|
| 69 | 69 | 'action' => '', |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - $columns = apply_filters( 'sensei_grading_default_columns', $columns, $this ); |
|
| 72 | + $columns = apply_filters('sensei_grading_default_columns', $columns, $this); |
|
| 73 | 73 | return $columns; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function get_sortable_columns() { |
| 82 | 82 | $columns = array( |
| 83 | - 'title' => array( 'title', false ), |
|
| 84 | - 'course' => array( 'course', false ), |
|
| 85 | - 'lesson' => array( 'lesson', false ), |
|
| 86 | - 'updated' => array( 'updated', false ), |
|
| 87 | - 'user_status' => array( 'user_status', false ), |
|
| 88 | - 'user_grade' => array( 'user_grade', false ), |
|
| 83 | + 'title' => array('title', false), |
|
| 84 | + 'course' => array('course', false), |
|
| 85 | + 'lesson' => array('lesson', false), |
|
| 86 | + 'updated' => array('updated', false), |
|
| 87 | + 'user_status' => array('user_status', false), |
|
| 88 | + 'user_grade' => array('user_grade', false), |
|
| 89 | 89 | ); |
| 90 | - $columns = apply_filters( 'sensei_grading_default_columns_sortable', $columns, $this ); |
|
| 90 | + $columns = apply_filters('sensei_grading_default_columns_sortable', $columns, $this); |
|
| 91 | 91 | return $columns; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -101,47 +101,47 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // Handle orderby |
| 103 | 103 | $orderby = ''; |
| 104 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 105 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 106 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 104 | + if ( ! empty($_GET['orderby'])) { |
|
| 105 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 106 | + $orderby = esc_html($_GET['orderby']); |
|
| 107 | 107 | } // End If Statement |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Handle order |
| 111 | 111 | $order = 'DESC'; |
| 112 | - if ( !empty( $_GET['order'] ) ) { |
|
| 113 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 112 | + if ( ! empty($_GET['order'])) { |
|
| 113 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Handle search |
| 117 | 117 | $search = false; |
| 118 | - if ( !empty( $_GET['s'] ) ) { |
|
| 119 | - $search = esc_html( $_GET['s'] ); |
|
| 118 | + if ( ! empty($_GET['s'])) { |
|
| 119 | + $search = esc_html($_GET['s']); |
|
| 120 | 120 | } // End If Statement |
| 121 | 121 | $this->search = $search; |
| 122 | 122 | |
| 123 | 123 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
| 124 | - if ( $this->search ) { |
|
| 124 | + if ($this->search) { |
|
| 125 | 125 | $user_args = array( |
| 126 | - 'search' => '*' . $this->search . '*', |
|
| 126 | + 'search' => '*'.$this->search.'*', |
|
| 127 | 127 | 'fields' => 'ID', |
| 128 | 128 | ); |
| 129 | 129 | // Filter for extending |
| 130 | - $user_args = apply_filters( 'sensei_grading_search_users', $user_args ); |
|
| 131 | - if ( !empty( $user_args ) ) { |
|
| 132 | - $learners_search = new WP_User_Query( $user_args ); |
|
| 130 | + $user_args = apply_filters('sensei_grading_search_users', $user_args); |
|
| 131 | + if ( ! empty($user_args)) { |
|
| 132 | + $learners_search = new WP_User_Query($user_args); |
|
| 133 | 133 | // Store for reuse on counts |
| 134 | 134 | $this->user_ids = $learners_search->get_results(); |
| 135 | 135 | } |
| 136 | 136 | } // End If Statement |
| 137 | 137 | |
| 138 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
| 139 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
| 138 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
| 139 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
| 140 | 140 | |
| 141 | 141 | $paged = $this->get_pagenum(); |
| 142 | 142 | $offset = 0; |
| 143 | - if ( !empty($paged) ) { |
|
| 144 | - $offset = $per_page * ( $paged - 1 ); |
|
| 143 | + if ( ! empty($paged)) { |
|
| 144 | + $offset = $per_page * ($paged - 1); |
|
| 145 | 145 | } // End If Statement |
| 146 | 146 | |
| 147 | 147 | $activity_args = array( |
@@ -153,27 +153,27 @@ discard block |
||
| 153 | 153 | 'status' => 'any', |
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | - if( $this->lesson_id ) { |
|
| 156 | + if ($this->lesson_id) { |
|
| 157 | 157 | $activity_args['post_id'] = $this->lesson_id; |
| 158 | 158 | } |
| 159 | - elseif( $this->course_id ) { |
|
| 159 | + elseif ($this->course_id) { |
|
| 160 | 160 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
| 161 | 161 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
| 162 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 163 | - $activity_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' ); |
|
| 162 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 163 | + $activity_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids'); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | // Sub select to group of learners |
| 167 | - if ( $this->user_ids ) { |
|
| 167 | + if ($this->user_ids) { |
|
| 168 | 168 | $activity_args['user_id'] = (array) $this->user_ids; |
| 169 | 169 | } |
| 170 | 170 | // Restrict to a single Learner |
| 171 | - if( $this->user_id ) { |
|
| 171 | + if ($this->user_id) { |
|
| 172 | 172 | $activity_args['user_id'] = $this->user_id; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | - switch( $this->view ) { |
|
| 176 | + switch ($this->view) { |
|
| 177 | 177 | case 'in-progress' : |
| 178 | 178 | $activity_args['status'] = 'in-progress'; |
| 179 | 179 | break; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | break; |
| 184 | 184 | |
| 185 | 185 | case 'graded' : |
| 186 | - $activity_args['status'] = array( 'graded', 'passed', 'failed' ); |
|
| 186 | + $activity_args['status'] = array('graded', 'passed', 'failed'); |
|
| 187 | 187 | break; |
| 188 | 188 | |
| 189 | 189 | case 'all' : |
@@ -192,31 +192,31 @@ discard block |
||
| 192 | 192 | break; |
| 193 | 193 | } // End switch |
| 194 | 194 | |
| 195 | - $activity_args = apply_filters( 'sensei_grading_filter_statuses', $activity_args ); |
|
| 195 | + $activity_args = apply_filters('sensei_grading_filter_statuses', $activity_args); |
|
| 196 | 196 | |
| 197 | 197 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
| 198 | - $total_statuses = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
| 198 | + $total_statuses = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
| 199 | 199 | |
| 200 | 200 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
| 201 | - if ( $total_statuses < $activity_args['offset'] ) { |
|
| 202 | - $new_paged = floor( $total_statuses / $activity_args['number'] ); |
|
| 201 | + if ($total_statuses < $activity_args['offset']) { |
|
| 202 | + $new_paged = floor($total_statuses / $activity_args['number']); |
|
| 203 | 203 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
| 204 | 204 | } |
| 205 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
| 205 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
| 206 | 206 | // Need to always return an array, even with only 1 item |
| 207 | - if ( !is_array($statuses) ) { |
|
| 208 | - $statuses = array( $statuses ); |
|
| 207 | + if ( ! is_array($statuses)) { |
|
| 208 | + $statuses = array($statuses); |
|
| 209 | 209 | } |
| 210 | 210 | $this->total_items = $total_statuses; |
| 211 | 211 | $this->items = $statuses; |
| 212 | 212 | |
| 213 | 213 | $total_items = $this->total_items; |
| 214 | - $total_pages = ceil( $total_items / $per_page ); |
|
| 215 | - $this->set_pagination_args( array( |
|
| 214 | + $total_pages = ceil($total_items / $per_page); |
|
| 215 | + $this->set_pagination_args(array( |
|
| 216 | 216 | 'total_items' => $total_items, |
| 217 | 217 | 'total_pages' => $total_pages, |
| 218 | 218 | 'per_page' => $per_page |
| 219 | - ) ); |
|
| 219 | + )); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -224,73 +224,73 @@ discard block |
||
| 224 | 224 | * @since 1.7.0 |
| 225 | 225 | * @param object $item The current item |
| 226 | 226 | */ |
| 227 | - protected function get_row_data( $item ) { |
|
| 227 | + protected function get_row_data($item) { |
|
| 228 | 228 | global $wp_version; |
| 229 | 229 | |
| 230 | 230 | $grade = ''; |
| 231 | - if( 'complete' == $item->comment_approved ) { |
|
| 232 | - $status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 233 | - $grade = __( 'No Grade', 'woothemes-sensei' ); |
|
| 231 | + if ('complete' == $item->comment_approved) { |
|
| 232 | + $status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>'; |
|
| 233 | + $grade = __('No Grade', 'woothemes-sensei'); |
|
| 234 | 234 | } |
| 235 | - elseif( 'graded' == $item->comment_approved ) { |
|
| 236 | - $status_html = '<span class="graded">' . __( 'Graded', 'woothemes-sensei' ) . '</span>'; |
|
| 237 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
| 235 | + elseif ('graded' == $item->comment_approved) { |
|
| 236 | + $status_html = '<span class="graded">'.__('Graded', 'woothemes-sensei').'</span>'; |
|
| 237 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
| 238 | 238 | } |
| 239 | - elseif( 'passed' == $item->comment_approved ) { |
|
| 240 | - $status_html = '<span class="passed">' . __( 'Passed', 'woothemes-sensei' ) . '</span>'; |
|
| 241 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
| 239 | + elseif ('passed' == $item->comment_approved) { |
|
| 240 | + $status_html = '<span class="passed">'.__('Passed', 'woothemes-sensei').'</span>'; |
|
| 241 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
| 242 | 242 | } |
| 243 | - elseif( 'failed' == $item->comment_approved ) { |
|
| 244 | - $status_html = '<span class="failed">' . __( 'Failed', 'woothemes-sensei' ) . '</span>'; |
|
| 245 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
| 243 | + elseif ('failed' == $item->comment_approved) { |
|
| 244 | + $status_html = '<span class="failed">'.__('Failed', 'woothemes-sensei').'</span>'; |
|
| 245 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
| 246 | 246 | } |
| 247 | - elseif( 'ungraded' == $item->comment_approved ) { |
|
| 248 | - $status_html = '<span class="ungraded">' . __( 'Ungraded', 'woothemes-sensei' ) . '</span>'; |
|
| 249 | - $grade = __( 'N/A', 'woothemes-sensei' ); |
|
| 247 | + elseif ('ungraded' == $item->comment_approved) { |
|
| 248 | + $status_html = '<span class="ungraded">'.__('Ungraded', 'woothemes-sensei').'</span>'; |
|
| 249 | + $grade = __('N/A', 'woothemes-sensei'); |
|
| 250 | 250 | } |
| 251 | 251 | else { |
| 252 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 253 | - $grade = __( 'N/A', 'woothemes-sensei' ); |
|
| 252 | + $status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>'; |
|
| 253 | + $grade = __('N/A', 'woothemes-sensei'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $title = Sensei()->learners->get_learner_full_name( $item->user_id ); |
|
| 256 | + $title = Sensei()->learners->get_learner_full_name($item->user_id); |
|
| 257 | 257 | |
| 258 | 258 | // QuizID to be deprecated |
| 259 | - $quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true ); |
|
| 260 | - $quiz_link = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id ), admin_url( 'admin.php' ) ) ); |
|
| 259 | + $quiz_id = get_post_meta($item->comment_post_ID, '_lesson_quiz', true); |
|
| 260 | + $quiz_link = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id), admin_url('admin.php'))); |
|
| 261 | 261 | |
| 262 | 262 | $grade_link = ''; |
| 263 | - switch( $item->comment_approved ) { |
|
| 263 | + switch ($item->comment_approved) { |
|
| 264 | 264 | case 'ungraded': |
| 265 | - $grade_link = '<a class="button-primary button" href="' . $quiz_link . '">' . __('Grade quiz', 'woothemes-sensei' ) . '</a>'; |
|
| 265 | + $grade_link = '<a class="button-primary button" href="'.$quiz_link.'">'.__('Grade quiz', 'woothemes-sensei').'</a>'; |
|
| 266 | 266 | break; |
| 267 | 267 | |
| 268 | 268 | case 'graded': |
| 269 | 269 | case 'passed': |
| 270 | 270 | case 'failed': |
| 271 | - $grade_link = '<a class="button-secondary button" href="' . $quiz_link . '">' . __('Review grade', 'woothemes-sensei' ) . '</a>'; |
|
| 271 | + $grade_link = '<a class="button-secondary button" href="'.$quiz_link.'">'.__('Review grade', 'woothemes-sensei').'</a>'; |
|
| 272 | 272 | break; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $course_id = get_post_meta( $item->comment_post_ID, '_lesson_course', true ); |
|
| 275 | + $course_id = get_post_meta($item->comment_post_ID, '_lesson_course', true); |
|
| 276 | 276 | $course_title = ''; |
| 277 | - if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) { |
|
| 278 | - $course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>'; |
|
| 277 | + if ( ! empty($course_id) && version_compare($wp_version, '4.1', '>=')) { |
|
| 278 | + $course_title = '<a href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'))).'">'.get_the_title($course_id).'</a>'; |
|
| 279 | 279 | } |
| 280 | - else if ( !empty($course_id) ) { |
|
| 281 | - $course_title = get_the_title( $course_id ); |
|
| 280 | + else if ( ! empty($course_id)) { |
|
| 281 | + $course_title = get_the_title($course_id); |
|
| 282 | 282 | } |
| 283 | - $lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>'; |
|
| 283 | + $lesson_title = '<a href="'.add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID), admin_url('admin.php')).'">'.get_the_title($item->comment_post_ID).'</a>'; |
|
| 284 | 284 | |
| 285 | - $column_data = apply_filters( 'sensei_grading_main_column_data', array( |
|
| 286 | - 'title' => '<strong><a class="row-title" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id ), admin_url( 'admin.php' ) ) ) . '"">' . $title . '</a></strong>', |
|
| 285 | + $column_data = apply_filters('sensei_grading_main_column_data', array( |
|
| 286 | + 'title' => '<strong><a class="row-title" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id), admin_url('admin.php'))).'"">'.$title.'</a></strong>', |
|
| 287 | 287 | 'course' => $course_title, |
| 288 | 288 | 'lesson' => $lesson_title, |
| 289 | 289 | 'updated' => $item->comment_date, |
| 290 | 290 | 'user_status' => $status_html, |
| 291 | 291 | 'user_grade' => $grade, |
| 292 | 292 | 'action' => $grade_link, |
| 293 | - ), $item, $course_id ); |
|
| 293 | + ), $item, $course_id); |
|
| 294 | 294 | |
| 295 | 295 | return $column_data; |
| 296 | 296 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function no_items() { |
| 305 | 305 | |
| 306 | - _e( 'No submissions found.', 'woothemes-sensei' ); |
|
| 306 | + _e('No submissions found.', 'woothemes-sensei'); |
|
| 307 | 307 | |
| 308 | 308 | } // End no_items() |
| 309 | 309 | |
@@ -316,35 +316,35 @@ discard block |
||
| 316 | 316 | global $wp_version; |
| 317 | 317 | |
| 318 | 318 | echo '<div class="grading-selects">'; |
| 319 | - do_action( 'sensei_grading_before_dropdown_filters' ); |
|
| 319 | + do_action('sensei_grading_before_dropdown_filters'); |
|
| 320 | 320 | |
| 321 | - echo '<div class="select-box">' . "\n"; |
|
| 321 | + echo '<div class="select-box">'."\n"; |
|
| 322 | 322 | |
| 323 | - echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">' . "\n"; |
|
| 323 | + echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">'."\n"; |
|
| 324 | 324 | |
| 325 | - echo Sensei()->grading->courses_drop_down_html( $this->course_id ); |
|
| 325 | + echo Sensei()->grading->courses_drop_down_html($this->course_id); |
|
| 326 | 326 | |
| 327 | - echo '</select>' . "\n"; |
|
| 327 | + echo '</select>'."\n"; |
|
| 328 | 328 | |
| 329 | - echo '</div>' . "\n"; |
|
| 329 | + echo '</div>'."\n"; |
|
| 330 | 330 | |
| 331 | - echo '<div class="select-box">' . "\n"; |
|
| 331 | + echo '<div class="select-box">'."\n"; |
|
| 332 | 332 | |
| 333 | - echo '<select id="grading-lesson-options" data-placeholder="← ' . __( 'Select a course', 'woothemes-sensei' ) . '" name="grading_lesson" class="chosen_select widefat">' . "\n"; |
|
| 333 | + echo '<select id="grading-lesson-options" data-placeholder="← '.__('Select a course', 'woothemes-sensei').'" name="grading_lesson" class="chosen_select widefat">'."\n"; |
|
| 334 | 334 | |
| 335 | - echo Sensei()->grading->lessons_drop_down_html( $this->course_id, $this->lesson_id ); |
|
| 335 | + echo Sensei()->grading->lessons_drop_down_html($this->course_id, $this->lesson_id); |
|
| 336 | 336 | |
| 337 | - echo '</select>' . "\n"; |
|
| 337 | + echo '</select>'."\n"; |
|
| 338 | 338 | |
| 339 | - echo '</div>' . "\n"; |
|
| 339 | + echo '</div>'."\n"; |
|
| 340 | 340 | |
| 341 | - if( $this->course_id && $this->lesson_id ) { |
|
| 341 | + if ($this->course_id && $this->lesson_id) { |
|
| 342 | 342 | |
| 343 | - echo '<div class="select-box reset-filter">' . "\n"; |
|
| 343 | + echo '<div class="select-box reset-filter">'."\n"; |
|
| 344 | 344 | |
| 345 | - echo '<a class="button-secondary" href="' . esc_url( remove_query_arg( array( 'lesson_id', 'course_id' ) ) ) . '">' . __( 'Reset filter', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 345 | + echo '<a class="button-secondary" href="'.esc_url(remove_query_arg(array('lesson_id', 'course_id'))).'">'.__('Reset filter', 'woothemes-sensei').'</a>'."\n"; |
|
| 346 | 346 | |
| 347 | - echo '</div>' . "\n"; |
|
| 347 | + echo '</div>'."\n"; |
|
| 348 | 348 | |
| 349 | 349 | } |
| 350 | 350 | |
@@ -359,26 +359,26 @@ discard block |
||
| 359 | 359 | $query_args = array( |
| 360 | 360 | 'page' => $this->page_slug, |
| 361 | 361 | ); |
| 362 | - if( $this->course_id ) { |
|
| 362 | + if ($this->course_id) { |
|
| 363 | 363 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
| 364 | 364 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
| 365 | 365 | $query_args['course_id'] = $this->course_id; |
| 366 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 367 | - $count_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' ); |
|
| 366 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 367 | + $count_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids'); |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | - if( $this->lesson_id ) { |
|
| 370 | + if ($this->lesson_id) { |
|
| 371 | 371 | $query_args['lesson_id'] = $this->lesson_id; |
| 372 | 372 | // Restrict to a single lesson |
| 373 | 373 | $count_args['post_id'] = $this->lesson_id; |
| 374 | 374 | } |
| 375 | - if( $this->search ) { |
|
| 375 | + if ($this->search) { |
|
| 376 | 376 | $query_args['s'] = $this->search; |
| 377 | 377 | } |
| 378 | - if ( !empty($this->user_ids) ) { |
|
| 378 | + if ( ! empty($this->user_ids)) { |
|
| 379 | 379 | $count_args['user_id'] = $this->user_ids; |
| 380 | 380 | } |
| 381 | - if( !empty($this->user_id) ) { |
|
| 381 | + if ( ! empty($this->user_id)) { |
|
| 382 | 382 | $query_args['user_id'] = $this->user_id; |
| 383 | 383 | $count_args['user_id'] = $this->user_id; |
| 384 | 384 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $all_lessons_count = $ungraded_lessons_count = $graded_lessons_count = $inprogress_lessons_count = 0; |
| 387 | 387 | $all_class = $ungraded_class = $graded_class = $inprogress_class = ''; |
| 388 | 388 | |
| 389 | - switch( $this->view ) : |
|
| 389 | + switch ($this->view) : |
|
| 390 | 390 | case 'all': |
| 391 | 391 | $all_class = 'current'; |
| 392 | 392 | break; |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | break; |
| 403 | 403 | endswitch; |
| 404 | 404 | |
| 405 | - $counts = Sensei()->grading->count_statuses( apply_filters( 'sensei_grading_count_statues', $count_args ) ); |
|
| 405 | + $counts = Sensei()->grading->count_statuses(apply_filters('sensei_grading_count_statues', $count_args)); |
|
| 406 | 406 | |
| 407 | 407 | $inprogress_lessons_count = $counts['in-progress']; |
| 408 | 408 | $ungraded_lessons_count = $counts['ungraded']; |
@@ -418,19 +418,19 @@ discard block |
||
| 418 | 418 | $inprogress_args['view'] = 'in-progress'; |
| 419 | 419 | |
| 420 | 420 | $format = '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>'; |
| 421 | - $menu['all'] = sprintf( $format, $all_class, esc_url( add_query_arg( $all_args, admin_url( 'admin.php' ) ) ), __( 'All', 'woothemes-sensei' ), number_format( (int) $all_lessons_count ) ); |
|
| 422 | - $menu['ungraded'] = sprintf( $format, $ungraded_class, esc_url( add_query_arg( $ungraded_args, admin_url( 'admin.php' ) ) ), __( 'Ungraded', 'woothemes-sensei' ), number_format( (int) $ungraded_lessons_count ) ); |
|
| 423 | - $menu['graded'] = sprintf( $format, $graded_class, esc_url( add_query_arg( $graded_args, admin_url( 'admin.php' ) ) ), __( 'Graded', 'woothemes-sensei' ), number_format( (int) $graded_lessons_count ) ); |
|
| 424 | - $menu['in-progress'] = sprintf( $format, $inprogress_class, esc_url( add_query_arg( $inprogress_args, admin_url( 'admin.php' ) ) ), __( 'In Progress', 'woothemes-sensei' ), number_format( (int) $inprogress_lessons_count ) ); |
|
| 425 | - |
|
| 426 | - $menu = apply_filters( 'sensei_grading_sub_menu', $menu ); |
|
| 427 | - if ( !empty($menu) ) { |
|
| 428 | - echo '<ul class="subsubsub">' . "\n"; |
|
| 429 | - foreach ( $menu as $class => $item ) { |
|
| 430 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
| 421 | + $menu['all'] = sprintf($format, $all_class, esc_url(add_query_arg($all_args, admin_url('admin.php'))), __('All', 'woothemes-sensei'), number_format((int) $all_lessons_count)); |
|
| 422 | + $menu['ungraded'] = sprintf($format, $ungraded_class, esc_url(add_query_arg($ungraded_args, admin_url('admin.php'))), __('Ungraded', 'woothemes-sensei'), number_format((int) $ungraded_lessons_count)); |
|
| 423 | + $menu['graded'] = sprintf($format, $graded_class, esc_url(add_query_arg($graded_args, admin_url('admin.php'))), __('Graded', 'woothemes-sensei'), number_format((int) $graded_lessons_count)); |
|
| 424 | + $menu['in-progress'] = sprintf($format, $inprogress_class, esc_url(add_query_arg($inprogress_args, admin_url('admin.php'))), __('In Progress', 'woothemes-sensei'), number_format((int) $inprogress_lessons_count)); |
|
| 425 | + |
|
| 426 | + $menu = apply_filters('sensei_grading_sub_menu', $menu); |
|
| 427 | + if ( ! empty($menu)) { |
|
| 428 | + echo '<ul class="subsubsub">'."\n"; |
|
| 429 | + foreach ($menu as $class => $item) { |
|
| 430 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
| 431 | 431 | } |
| 432 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
| 433 | - echo '</ul>' . "\n"; |
|
| 432 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
| 433 | + echo '</ul>'."\n"; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | } // End data_table_header() |
@@ -451,4 +451,4 @@ discard block |
||
| 451 | 451 | * for backward compatibility |
| 452 | 452 | * @since 1.9.0 |
| 453 | 453 | */ |
| 454 | -class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main{} |
|
| 454 | +class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main {} |
|
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Updates Class |
@@ -27,59 +27,59 @@ discard block |
||
| 27 | 27 | * @param string $parent The main Sensei object by Ref. |
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | - public function __construct ( $parent ) { |
|
| 30 | + public function __construct($parent) { |
|
| 31 | 31 | |
| 32 | 32 | // Setup object data |
| 33 | 33 | $this->parent = $parent; |
| 34 | - $this->updates_run = get_option( $this->token . '-upgrades', array() ); |
|
| 34 | + $this->updates_run = get_option($this->token.'-upgrades', array()); |
|
| 35 | 35 | |
| 36 | 36 | // The list of upgrades to run |
| 37 | - $this->updates = array( '1.1.0' => array( 'auto' => array( 'assign_role_caps' => array( 'title' => __( 'Assign role capabilities', 'woothemes-sensei' ), 'desc' => __( 'Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei' ), 'product' => 'Sensei' ) ), |
|
| 37 | + $this->updates = array('1.1.0' => array('auto' => array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')), |
|
| 38 | 38 | 'manual' => array() |
| 39 | 39 | ), |
| 40 | - '1.3.0' => array( 'auto' => array( 'set_default_quiz_grade_type' => array( 'title' => __( 'Set default quiz grade type', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei' ) ), |
|
| 41 | - 'set_default_question_type' => array( 'title' => __( 'Set default question type', 'woothemes-sensei' ), 'desc' => __( 'Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei' ) ) |
|
| 40 | + '1.3.0' => array('auto' => array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')), |
|
| 41 | + 'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei')) |
|
| 42 | 42 | ), |
| 43 | - 'manual' => array( 'update_question_answer_data' => array( 'title' => __( 'Update question answer data', 'woothemes-sensei' ), 'desc' => __( 'Updates questions to use the new question types structure.', 'woothemes-sensei' ) ) ) |
|
| 43 | + 'manual' => array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei'))) |
|
| 44 | 44 | ), |
| 45 | - '1.4.0' => array( 'auto' => array( 'update_question_grade_points' => array( 'title' => __( 'Update question grade points', 'woothemes-sensei' ), 'desc' => __( 'Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei' ) ) ), |
|
| 45 | + '1.4.0' => array('auto' => array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))), |
|
| 46 | 46 | 'manual' => array() |
| 47 | 47 | ), |
| 48 | - '1.5.0' => array( 'auto' => array( 'convert_essay_paste_questions' => array( 'title' => __( 'Convert essay paste questions into multi-line questions', 'woothemes-sensei' ), 'desc' => __( 'Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei' ) ) ), |
|
| 49 | - 'manual' => array( 'set_random_question_order' => array( 'title' => __( 'Set all quizzes to have a random question order', 'woothemes-sensei' ), 'desc' => __( 'Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei' ) ), |
|
| 50 | - 'set_default_show_question_count' => array( 'title' => __( 'Set all quizzes to show all questions', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei' ) ), |
|
| 51 | - 'remove_deleted_user_activity' => array( 'title' => __( 'Remove Sensei activity for deleted users', 'woothemes-sensei' ), 'desc' => __( 'Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei' ) ) ) |
|
| 48 | + '1.5.0' => array('auto' => array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))), |
|
| 49 | + 'manual' => array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')), |
|
| 50 | + 'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')), |
|
| 51 | + 'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei'))) |
|
| 52 | 52 | ), |
| 53 | - '1.6.0' => array( 'auto' => array( 'add_teacher_role' => array( 'title' => __( 'Add \'Teacher\' role', 'woothemes-sensei' ), 'desc' => __( 'Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei' ) ), |
|
| 54 | - 'add_sensei_caps' => array( 'title' => __( 'Add administrator capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei' ) ), |
|
| 55 | - 'restructure_question_meta' => array( 'title' => __( 'Restructure question meta data', 'woothemes-sensei' ), 'desc' => __( 'Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei' ) ), |
|
| 56 | - 'update_quiz_settings' => array( 'title' => __( 'Add new quiz settings', 'woothemes-sensei' ), 'desc' => __( 'Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei' ) ), |
|
| 57 | - 'reset_lesson_order_meta' => array( 'title' => __( 'Set default order of lessons', 'woothemes-sensei' ), 'desc' => __( 'Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei' ) ), ), |
|
| 53 | + '1.6.0' => array('auto' => array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')), |
|
| 54 | + 'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')), |
|
| 55 | + 'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')), |
|
| 56 | + 'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')), |
|
| 57 | + 'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),), |
|
| 58 | 58 | 'manual' => array() |
| 59 | 59 | ), |
| 60 | - '1.7.0' => array( 'auto' => array( 'add_editor_caps' => array( 'title' => __( 'Add Editor capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei' ) ), ), |
|
| 61 | - 'forced' => array( 'update_question_gap_fill_separators' => array( 'title' => __( 'Update Gap Fill questions', 'woothemes-sensei' ), 'desc' => __( 'Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei' ) ), |
|
| 62 | - 'update_quiz_lesson_relationship' => array( 'title' => __( 'Restructure quiz lesson relationship', 'woothemes-sensei' ), 'desc' => __( 'Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei' ) ), |
|
| 63 | - 'status_changes_fix_lessons' => array( 'title' => __( 'Update lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Update existing lesson statuses.', 'woothemes-sensei' ) ), |
|
| 64 | - 'status_changes_convert_lessons' => array( 'title' => __( 'Convert lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new lesson statuses.', 'woothemes-sensei' ) ), |
|
| 65 | - 'status_changes_convert_courses' => array( 'title' => __( 'Convert course statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new course statuses.', 'woothemes-sensei' ) ), |
|
| 66 | - 'status_changes_convert_questions' => array( 'title' => __( 'Convert question statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new question statuses.', 'woothemes-sensei' ) ), |
|
| 67 | - 'update_legacy_sensei_comments_status' => array( 'title' => __( 'Convert legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei' ) ), |
|
| 68 | - 'update_comment_course_lesson_comment_counts' => array( 'title' => __( 'Update comment counts', 'woothemes-sensei' ), 'desc' => __( 'Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei' ) ), ), |
|
| 60 | + '1.7.0' => array('auto' => array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),), |
|
| 61 | + 'forced' => array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')), |
|
| 62 | + 'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')), |
|
| 63 | + 'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')), |
|
| 64 | + 'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')), |
|
| 65 | + 'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')), |
|
| 66 | + 'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')), |
|
| 67 | + 'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')), |
|
| 68 | + 'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),), |
|
| 69 | 69 | ), |
| 70 | - '1.7.2' => array( 'auto' => array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ), |
|
| 70 | + '1.7.2' => array('auto' => array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),), |
|
| 71 | 71 | /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
| 72 | 72 | ), |
| 73 | - '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 73 | + '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),), |
|
| 74 | 74 | 'manual' => array() |
| 75 | 75 | ), |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | - $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
|
| 79 | - $this->version = get_option( $this->token . '-version' ); |
|
| 78 | + $this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates); |
|
| 79 | + $this->version = get_option($this->token.'-version'); |
|
| 80 | 80 | |
| 81 | 81 | // Manual Update Screen |
| 82 | - add_action('admin_menu', array( $this, 'add_update_admin_screen' ), 50 ); |
|
| 82 | + add_action('admin_menu', array($this, 'add_update_admin_screen'), 50); |
|
| 83 | 83 | |
| 84 | 84 | } // End __construct() |
| 85 | 85 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | 93 | public function add_update_admin_screen() { |
| 94 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 95 | - add_submenu_page( 'sensei', __( 'Sensei Updates', 'woothemes-sensei' ), __( 'Data Updates', 'woothemes-sensei' ), 'manage_options', 'sensei_updates', array( $this, 'sensei_updates_page' ) ); |
|
| 94 | + if (current_user_can('manage_options')) { |
|
| 95 | + add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page')); |
|
| 96 | 96 | } |
| 97 | 97 | } // End add_update_admin_screen() |
| 98 | 98 | |
@@ -106,80 +106,80 @@ discard block |
||
| 106 | 106 | public function sensei_updates_page() { |
| 107 | 107 | |
| 108 | 108 | // Only allow admins to load this page and run the update functions |
| 109 | - if( current_user_can( 'manage_options' ) ) { |
|
| 109 | + if (current_user_can('manage_options')) { |
|
| 110 | 110 | ?> |
| 111 | 111 | <div class="wrap"> |
| 112 | 112 | |
| 113 | 113 | <div id="icon-woothemes-sensei" class="icon32"><br></div> |
| 114 | - <h2><?php _e( 'Sensei Updates', 'woothemes-sensei' ); ?></h2> |
|
| 114 | + <h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2> |
|
| 115 | 115 | |
| 116 | 116 | <?php |
| 117 | - if ( isset( $_GET['action'] ) && $_GET['action'] == 'update' && isset( $_GET['n'] ) && intval( $_GET['n'] ) >= 0 && ( ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) || ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) ) ) { |
|
| 117 | + if (isset($_GET['action']) && $_GET['action'] == 'update' && isset($_GET['n']) && intval($_GET['n']) >= 0 && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
| 118 | 118 | |
| 119 | 119 | // Setup the data variables |
| 120 | - $n = intval( $_GET['n'] ); |
|
| 120 | + $n = intval($_GET['n']); |
|
| 121 | 121 | $functions_list = ''; |
| 122 | 122 | $done_processing = false; |
| 123 | 123 | |
| 124 | 124 | // Check for updates to run |
| 125 | - if ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) { |
|
| 125 | + if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) { |
|
| 126 | 126 | |
| 127 | - foreach ( $_POST['checked'] as $key => $value ) { |
|
| 127 | + foreach ($_POST['checked'] as $key => $value) { |
|
| 128 | 128 | |
| 129 | 129 | // Dynamic function call |
| 130 | - if ( method_exists( $this, $value) ) { |
|
| 131 | - $done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) ); |
|
| 130 | + if (method_exists($this, $value)) { |
|
| 131 | + $done_processing = call_user_func_array(array($this, $value), array(50, $n)); |
|
| 132 | 132 | } else { |
| 133 | - $done_processing = call_user_func_array( $value, array( 50, $n ) ); |
|
| 133 | + $done_processing = call_user_func_array($value, array(50, $n)); |
|
| 134 | 134 | } // End If Statement |
| 135 | 135 | |
| 136 | 136 | // Add to functions list get args |
| 137 | - if ( '' == $functions_list ) { |
|
| 137 | + if ('' == $functions_list) { |
|
| 138 | 138 | $functions_list .= $value; |
| 139 | 139 | } else { |
| 140 | - $functions_list .= '+' . $value; |
|
| 140 | + $functions_list .= '+'.$value; |
|
| 141 | 141 | } // End If Statement |
| 142 | 142 | |
| 143 | 143 | // Mark update has having been run |
| 144 | - $this->set_update_run( $value ); |
|
| 144 | + $this->set_update_run($value); |
|
| 145 | 145 | |
| 146 | 146 | } // End For Loop |
| 147 | 147 | |
| 148 | 148 | } // End If Statement |
| 149 | 149 | |
| 150 | 150 | // Check for updates to run |
| 151 | - if ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) { |
|
| 151 | + if (isset($_GET['functions']) && '' != $_GET['functions']) { |
|
| 152 | 152 | |
| 153 | 153 | // Existing functions from GET variables instead of POST |
| 154 | 154 | $functions_array = $_GET['functions']; |
| 155 | 155 | |
| 156 | - foreach ( $functions_array as $key => $value ) { |
|
| 156 | + foreach ($functions_array as $key => $value) { |
|
| 157 | 157 | |
| 158 | 158 | // Dynamic function call |
| 159 | - if ( method_exists( $this, $value) ) { |
|
| 160 | - $done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) ); |
|
| 159 | + if (method_exists($this, $value)) { |
|
| 160 | + $done_processing = call_user_func_array(array($this, $value), array(50, $n)); |
|
| 161 | 161 | } else { |
| 162 | - $done_processing = call_user_func_array( $value, array( 50, $n ) ); |
|
| 162 | + $done_processing = call_user_func_array($value, array(50, $n)); |
|
| 163 | 163 | } // End If Statement |
| 164 | 164 | |
| 165 | 165 | // Add to functions list get args |
| 166 | - if ( '' == $functions_list ) { |
|
| 166 | + if ('' == $functions_list) { |
|
| 167 | 167 | $functions_list .= $value; |
| 168 | 168 | } else { |
| 169 | - $functions_list .= '+' . $value; |
|
| 169 | + $functions_list .= '+'.$value; |
|
| 170 | 170 | } // End If Statement |
| 171 | 171 | |
| 172 | - $this->set_update_run( $value ); |
|
| 172 | + $this->set_update_run($value); |
|
| 173 | 173 | |
| 174 | 174 | } // End For Loop |
| 175 | 175 | |
| 176 | 176 | } // End If Statement |
| 177 | 177 | |
| 178 | - if ( ! $done_processing ) { ?> |
|
| 178 | + if ( ! $done_processing) { ?> |
|
| 179 | 179 | |
| 180 | - <h3><?php _e( 'Processing Updates...', 'woothemes-sensei' ); ?></h3> |
|
| 180 | + <h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3> |
|
| 181 | 181 | |
| 182 | - <p><?php _e( 'If your browser doesn’t start loading the next page automatically, click this button:', 'woothemes-sensei' ); ?> <a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e( 'Next', 'woothemes-sensei' ); ?></a></p> |
|
| 182 | + <p><?php _e('If your browser doesn’t start loading the next page automatically, click this button:', 'woothemes-sensei'); ?> <a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e('Next', 'woothemes-sensei'); ?></a></p> |
|
| 183 | 183 | <script type='text/javascript'> |
| 184 | 184 | <!-- |
| 185 | 185 | function sensei_nextpage() { |
@@ -191,48 +191,48 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | } else { ?> |
| 193 | 193 | |
| 194 | - <p><strong><?php _e( 'Update completed successfully!', 'woothemes-sensei' ); ?></strong></p> |
|
| 195 | - <p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e( 'Create a new lesson', 'woothemes-sensei' ); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e( 'run some more updates', 'woothemes-sensei' ); ?></a>.</p> |
|
| 194 | + <p><strong><?php _e('Update completed successfully!', 'woothemes-sensei'); ?></strong></p> |
|
| 195 | + <p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e('Create a new lesson', 'woothemes-sensei'); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e('run some more updates', 'woothemes-sensei'); ?></a>.</p> |
|
| 196 | 196 | |
| 197 | 197 | <?php } // End If Statement |
| 198 | 198 | |
| 199 | 199 | } else { ?> |
| 200 | 200 | |
| 201 | - <h3><?php _e( 'Updates', 'woothemes-sensei' ); ?></h3> |
|
| 202 | - <p><?php printf( __( 'These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei' ), '<code>', '</code>' ); ?></p> |
|
| 201 | + <h3><?php _e('Updates', 'woothemes-sensei'); ?></h3> |
|
| 202 | + <p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p> |
|
| 203 | 203 | |
| 204 | - <div class="updated"><p><strong><?php _e( 'Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei' ); ?></strong></p></div> |
|
| 204 | + <div class="updated"><p><strong><?php _e('Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei'); ?></strong></p></div> |
|
| 205 | 205 | |
| 206 | 206 | <table class="widefat" cellspacing="0" id="update-plugins-table"> |
| 207 | 207 | |
| 208 | 208 | <thead> |
| 209 | 209 | <tr> |
| 210 | - <th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th> |
|
| 211 | - <th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th> |
|
| 212 | - <th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th> |
|
| 210 | + <th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th> |
|
| 211 | + <th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th> |
|
| 212 | + <th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th> |
|
| 213 | 213 | </tr> |
| 214 | 214 | </thead> |
| 215 | 215 | |
| 216 | 216 | <tfoot> |
| 217 | 217 | <tr> |
| 218 | - <th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th> |
|
| 219 | - <th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th> |
|
| 220 | - <th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th> |
|
| 218 | + <th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th> |
|
| 219 | + <th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th> |
|
| 220 | + <th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th> |
|
| 221 | 221 | </tr> |
| 222 | 222 | </tfoot> |
| 223 | 223 | |
| 224 | 224 | <tbody class="updates"> |
| 225 | 225 | <?php |
| 226 | 226 | // Sort updates with the latest at the top |
| 227 | - uksort( $this->updates, array( $this, 'sort_updates' ) ); |
|
| 228 | - $this->updates = array_reverse( $this->updates, true ); |
|
| 227 | + uksort($this->updates, array($this, 'sort_updates')); |
|
| 228 | + $this->updates = array_reverse($this->updates, true); |
|
| 229 | 229 | $class = 'alternate'; |
| 230 | - foreach( $this->updates as $version => $version_updates ) { |
|
| 231 | - foreach( $version_updates as $type => $updates ) { |
|
| 232 | - foreach( $updates as $update => $data ) { |
|
| 233 | - $update_run = $this->has_update_run( $update ); |
|
| 230 | + foreach ($this->updates as $version => $version_updates) { |
|
| 231 | + foreach ($version_updates as $type => $updates) { |
|
| 232 | + foreach ($updates as $update => $data) { |
|
| 233 | + $update_run = $this->has_update_run($update); |
|
| 234 | 234 | $product = 'Sensei'; |
| 235 | - if ( isset( $data['product'] ) && '' != $data['product'] ) { |
|
| 235 | + if (isset($data['product']) && '' != $data['product']) { |
|
| 236 | 236 | $product = $data['product']; |
| 237 | 237 | } // End If Statement |
| 238 | 238 | ?> |
@@ -242,21 +242,21 @@ discard block |
||
| 242 | 242 | <p> |
| 243 | 243 | <input type="hidden" name="checked[]" value="<?php echo $update; ?>"> |
| 244 | 244 | <strong><?php echo $data['title']; ?></strong><br><?php echo $data['desc']; ?><br> |
| 245 | - <em><?php printf( __( 'Originally included in %s v%s', 'woothemes-sensei' ), $product, $version ); ?></em> |
|
| 245 | + <em><?php printf(__('Originally included in %s v%s', 'woothemes-sensei'), $product, $version); ?></em> |
|
| 246 | 246 | </p> |
| 247 | 247 | </td> |
| 248 | 248 | <?php |
| 249 | - $type_label = __( 'Auto', 'woothemes-sensei' ); |
|
| 250 | - if( $type != 'auto' ) { |
|
| 251 | - $type_label = __( 'Manual', 'woothemes-sensei' ); |
|
| 249 | + $type_label = __('Auto', 'woothemes-sensei'); |
|
| 250 | + if ($type != 'auto') { |
|
| 251 | + $type_label = __('Manual', 'woothemes-sensei'); |
|
| 252 | 252 | } |
| 253 | 253 | ?> |
| 254 | 254 | <td><p><?php echo $type_label; ?></p></td> |
| 255 | - <td><p><input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" id="update-sensei" class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" type="submit" value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" name="update"></p></td> |
|
| 255 | + <td><p><input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" id="update-sensei" class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" type="submit" value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" name="update"></p></td> |
|
| 256 | 256 | </tr> |
| 257 | 257 | </form> |
| 258 | 258 | <?php |
| 259 | - if( 'alternate' == $class ) { |
|
| 259 | + if ('alternate' == $class) { |
|
| 260 | 260 | $class = ''; |
| 261 | 261 | } else { |
| 262 | 262 | $class = 'alternate'; |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * @param string $b Second key |
| 284 | 284 | * @return integer |
| 285 | 285 | */ |
| 286 | - private function sort_updates( $a, $b ) { |
|
| 287 | - return strcmp( $a, $b ); |
|
| 286 | + private function sort_updates($a, $b) { |
|
| 287 | + return strcmp($a, $b); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,32 +295,32 @@ discard block |
||
| 295 | 295 | * @access public |
| 296 | 296 | * @return boolean |
| 297 | 297 | */ |
| 298 | - public function update ( $type = 'auto' ) { |
|
| 298 | + public function update($type = 'auto') { |
|
| 299 | 299 | |
| 300 | 300 | // Only allow admins to run update functions |
| 301 | - if( current_user_can( 'manage_options' ) ) { |
|
| 301 | + if (current_user_can('manage_options')) { |
|
| 302 | 302 | |
| 303 | 303 | $this->force_updates(); |
| 304 | 304 | |
| 305 | 305 | // Run through all functions |
| 306 | - foreach ( $this->updates as $version => $value ) { |
|
| 307 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
| 308 | - if ( $upgrade_type == $type ) { |
|
| 306 | + foreach ($this->updates as $version => $value) { |
|
| 307 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
| 308 | + if ($upgrade_type == $type) { |
|
| 309 | 309 | $updated = false; |
| 310 | 310 | // Run the update function |
| 311 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
| 312 | - if ( isset( $function_name ) && '' != $function_name ) { |
|
| 313 | - if ( ! in_array( $function_name, $this->updates_run ) ) { |
|
| 311 | + foreach ($function_to_run as $function_name => $update_data) { |
|
| 312 | + if (isset($function_name) && '' != $function_name) { |
|
| 313 | + if ( ! in_array($function_name, $this->updates_run)) { |
|
| 314 | 314 | $updated = false; |
| 315 | - if ( method_exists( $this, $function_name ) ) { |
|
| 316 | - $updated = call_user_func( array( $this, $function_name ) ); |
|
| 317 | - } elseif( function_exists( $function_name ) ) { |
|
| 318 | - $updated = call_user_func( $function_name ); |
|
| 315 | + if (method_exists($this, $function_name)) { |
|
| 316 | + $updated = call_user_func(array($this, $function_name)); |
|
| 317 | + } elseif (function_exists($function_name)) { |
|
| 318 | + $updated = call_user_func($function_name); |
|
| 319 | 319 | } else { |
| 320 | 320 | // Nothing to see here... |
| 321 | 321 | } // End If Statement |
| 322 | - if ( $updated ) { |
|
| 323 | - array_push( $this->updates_run, $function_name ); |
|
| 322 | + if ($updated) { |
|
| 323 | + array_push($this->updates_run, $function_name); |
|
| 324 | 324 | } // End If Statement |
| 325 | 325 | } |
| 326 | 326 | } // End If Statement |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | } // End For Loop |
| 330 | 330 | } // End For Loop |
| 331 | 331 | |
| 332 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 333 | - update_option( $this->token . '-upgrades', $this->updates_run ); |
|
| 332 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
| 333 | + update_option($this->token.'-upgrades', $this->updates_run); |
|
| 334 | 334 | return true; |
| 335 | 335 | |
| 336 | 336 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | private function force_updates() { |
| 341 | 341 | |
| 342 | - if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) { |
|
| 342 | + if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) { |
|
| 343 | 343 | |
| 344 | 344 | // $skip_forced_updates = false; |
| 345 | 345 | // if( ! get_option( 'woothemes-sensei-force-updates', false ) ) { |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | // Force critical updates if only if lessons already exist |
| 350 | 350 | $skip_forced_updates = false; |
| 351 | - $lesson_posts = wp_count_posts( 'lesson' ); |
|
| 352 | - if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) { |
|
| 351 | + $lesson_posts = wp_count_posts('lesson'); |
|
| 352 | + if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) { |
|
| 353 | 353 | $skip_forced_updates = true; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -357,69 +357,69 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | $updates_to_run = array(); |
| 359 | 359 | |
| 360 | - foreach ( $this->updates as $version => $value ) { |
|
| 361 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
| 362 | - if ( $upgrade_type == 'forced' ) { |
|
| 363 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
| 360 | + foreach ($this->updates as $version => $value) { |
|
| 361 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
| 362 | + if ($upgrade_type == 'forced') { |
|
| 363 | + foreach ($function_to_run as $function_name => $update_data) { |
|
| 364 | 364 | |
| 365 | - if( $skip_forced_updates ) { |
|
| 366 | - $this->set_update_run( $function_name ); |
|
| 365 | + if ($skip_forced_updates) { |
|
| 366 | + $this->set_update_run($function_name); |
|
| 367 | 367 | continue; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $update_run = $this->has_update_run( $function_name ); |
|
| 370 | + $update_run = $this->has_update_run($function_name); |
|
| 371 | 371 | |
| 372 | - if( ! $update_run ) { |
|
| 372 | + if ( ! $update_run) { |
|
| 373 | 373 | $use_the_force = true; |
| 374 | - $updates_to_run[ $function_name ] = $update_data; |
|
| 374 | + $updates_to_run[$function_name] = $update_data; |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if( $skip_forced_updates ) { |
|
| 381 | + if ($skip_forced_updates) { |
|
| 382 | 382 | return; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if( $use_the_force && 0 < count( $updates_to_run ) ) { |
|
| 385 | + if ($use_the_force && 0 < count($updates_to_run)) { |
|
| 386 | 386 | |
| 387 | - $update_title = __( 'Important Sensei updates required', 'woothemes-sensei' ); |
|
| 387 | + $update_title = __('Important Sensei updates required', 'woothemes-sensei'); |
|
| 388 | 388 | |
| 389 | - $update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n"; |
|
| 389 | + $update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n"; |
|
| 390 | 390 | |
| 391 | 391 | // $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n"; |
| 392 | 392 | |
| 393 | - $update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
| 393 | + $update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n"; |
|
| 394 | 394 | |
| 395 | - $update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
| 395 | + $update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n"; |
|
| 396 | 396 | |
| 397 | - $update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
| 397 | + $update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n"; |
|
| 398 | 398 | |
| 399 | - $update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
| 399 | + $update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n"; |
|
| 400 | 400 | |
| 401 | - $update_message .= '<ol>' . "\n"; |
|
| 401 | + $update_message .= '<ol>'."\n"; |
|
| 402 | 402 | |
| 403 | - foreach( $updates_to_run as $function => $data ) { |
|
| 403 | + foreach ($updates_to_run as $function => $data) { |
|
| 404 | 404 | |
| 405 | - if( ! isset( $data['title'] ) ) { |
|
| 405 | + if ( ! isset($data['title'])) { |
|
| 406 | 406 | break; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - $update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>'; |
|
| 409 | + $update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $update_message .= '</ol>' . "\n"; |
|
| 412 | + $update_message .= '</ol>'."\n"; |
|
| 413 | 413 | |
| 414 | - switch( $version ) { |
|
| 414 | + switch ($version) { |
|
| 415 | 415 | |
| 416 | 416 | case '1.7.0': |
| 417 | - $update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n"; |
|
| 417 | + $update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n"; |
|
| 418 | 418 | break; |
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - wp_die( $update_message, $update_title ); |
|
| 422 | + wp_die($update_message, $update_title); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | * @since 1.4.0 |
| 432 | 432 | * @return boolean |
| 433 | 433 | */ |
| 434 | - private function has_update_run( $update ) { |
|
| 435 | - if ( in_array( $update, $this->updates_run ) ) { |
|
| 434 | + private function has_update_run($update) { |
|
| 435 | + if (in_array($update, $this->updates_run)) { |
|
| 436 | 436 | return true; |
| 437 | 437 | } |
| 438 | 438 | return false; |
@@ -444,10 +444,10 @@ discard block |
||
| 444 | 444 | * @param string $update Update to process |
| 445 | 445 | * @since 1.4.0 |
| 446 | 446 | */ |
| 447 | - private function set_update_run( $update ) { |
|
| 448 | - array_push( $this->updates_run, $update ); |
|
| 449 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 450 | - update_option( $this->token . '-upgrades', $this->updates_run ); |
|
| 447 | + private function set_update_run($update) { |
|
| 448 | + array_push($this->updates_run, $update); |
|
| 449 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
| 450 | + update_option($this->token.'-upgrades', $this->updates_run); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -458,15 +458,15 @@ discard block |
||
| 458 | 458 | * @return void |
| 459 | 459 | */ |
| 460 | 460 | public function assign_role_caps() { |
| 461 | - foreach ( $this->parent->post_types->role_caps as $role_cap_set ) { |
|
| 462 | - foreach ( $role_cap_set as $role_key => $capabilities_array ) { |
|
| 461 | + foreach ($this->parent->post_types->role_caps as $role_cap_set) { |
|
| 462 | + foreach ($role_cap_set as $role_key => $capabilities_array) { |
|
| 463 | 463 | /* Get the role. */ |
| 464 | - $role = get_role( $role_key ); |
|
| 465 | - foreach ( $capabilities_array as $cap_name ) { |
|
| 464 | + $role = get_role($role_key); |
|
| 465 | + foreach ($capabilities_array as $cap_name) { |
|
| 466 | 466 | /* If the role exists, add required capabilities for the plugin. */ |
| 467 | - if ( !empty( $role ) ) { |
|
| 468 | - if ( !$role->has_cap( $cap_name ) ) { |
|
| 469 | - $role->add_cap( $cap_name ); |
|
| 467 | + if ( ! empty($role)) { |
|
| 468 | + if ( ! $role->has_cap($cap_name)) { |
|
| 469 | + $role->add_cap($cap_name); |
|
| 470 | 470 | } // End If Statement |
| 471 | 471 | } // End If Statement |
| 472 | 472 | } // End For Loop |
@@ -483,16 +483,16 @@ discard block |
||
| 483 | 483 | * @return void |
| 484 | 484 | */ |
| 485 | 485 | public function set_default_quiz_grade_type() { |
| 486 | - $args = array( 'post_type' => 'quiz', |
|
| 486 | + $args = array('post_type' => 'quiz', |
|
| 487 | 487 | 'posts_per_page' => -1, |
| 488 | 488 | 'post_status' => 'publish', |
| 489 | 489 | 'suppress_filters' => 0 |
| 490 | 490 | ); |
| 491 | - $quizzes = get_posts( $args ); |
|
| 491 | + $quizzes = get_posts($args); |
|
| 492 | 492 | |
| 493 | - foreach( $quizzes as $quiz ) { |
|
| 494 | - update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' ); |
|
| 495 | - update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' ); |
|
| 493 | + foreach ($quizzes as $quiz) { |
|
| 494 | + update_post_meta($quiz->ID, '_quiz_grade_type', 'auto'); |
|
| 495 | + update_post_meta($quiz->ID, '_quiz_grade_type_disabled', ''); |
|
| 496 | 496 | } |
| 497 | 497 | return true; |
| 498 | 498 | } // End set_default_quiz_grade_type |
@@ -505,23 +505,23 @@ discard block |
||
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | 507 | public function set_default_question_type() { |
| 508 | - $args = array( 'post_type' => 'question', |
|
| 508 | + $args = array('post_type' => 'question', |
|
| 509 | 509 | 'posts_per_page' => -1, |
| 510 | 510 | 'post_status' => 'publish', |
| 511 | 511 | 'suppress_filters' => 0 |
| 512 | 512 | ); |
| 513 | - $questions = get_posts( $args ); |
|
| 513 | + $questions = get_posts($args); |
|
| 514 | 514 | |
| 515 | 515 | $already_run = true; |
| 516 | - foreach( $questions as $question ) { |
|
| 517 | - if( $already_run ) { |
|
| 518 | - $terms = wp_get_post_terms( $question->ID, 'question-type' ); |
|
| 519 | - if( is_array( $terms ) && count( $terms ) > 0 ) { |
|
| 516 | + foreach ($questions as $question) { |
|
| 517 | + if ($already_run) { |
|
| 518 | + $terms = wp_get_post_terms($question->ID, 'question-type'); |
|
| 519 | + if (is_array($terms) && count($terms) > 0) { |
|
| 520 | 520 | break; |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | $already_run = false; |
| 524 | - wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' ); |
|
| 524 | + wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type'); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | return true; |
@@ -534,90 +534,90 @@ discard block |
||
| 534 | 534 | * @access public |
| 535 | 535 | * @return void |
| 536 | 536 | */ |
| 537 | - public function update_question_answer_data( $n = 50, $offset = 0 ) { |
|
| 537 | + public function update_question_answer_data($n = 50, $offset = 0) { |
|
| 538 | 538 | |
| 539 | 539 | // Get Total Number of Updates to run |
| 540 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
| 540 | + $quiz_count_object = wp_count_posts('quiz'); |
|
| 541 | 541 | $quiz_count_published = $quiz_count_object->publish; |
| 542 | 542 | |
| 543 | 543 | // Calculate if this is the last page |
| 544 | - if ( 0 == $offset ) { |
|
| 544 | + if (0 == $offset) { |
|
| 545 | 545 | $current_page = 1; |
| 546 | 546 | } else { |
| 547 | - $current_page = intval( $offset / $n ); |
|
| 547 | + $current_page = intval($offset / $n); |
|
| 548 | 548 | } // End If Statement |
| 549 | - $total_pages = intval( $quiz_count_published / $n ); |
|
| 549 | + $total_pages = intval($quiz_count_published / $n); |
|
| 550 | 550 | |
| 551 | 551 | |
| 552 | - $args = array( 'post_type' => 'quiz', |
|
| 552 | + $args = array('post_type' => 'quiz', |
|
| 553 | 553 | 'posts_per_page' => $n, |
| 554 | 554 | 'offset' => $offset, |
| 555 | 555 | 'post_status' => 'publish', |
| 556 | 556 | 'suppress_filters' => 0 |
| 557 | 557 | ); |
| 558 | - $quizzes = get_posts( $args ); |
|
| 558 | + $quizzes = get_posts($args); |
|
| 559 | 559 | |
| 560 | 560 | $old_answers = array(); |
| 561 | 561 | $right_answers = array(); |
| 562 | 562 | $old_user_answers = array(); |
| 563 | 563 | |
| 564 | - if( is_array( $quizzes ) ) { |
|
| 565 | - foreach( $quizzes as $quiz ) { |
|
| 564 | + if (is_array($quizzes)) { |
|
| 565 | + foreach ($quizzes as $quiz) { |
|
| 566 | 566 | $quiz_id = $quiz->ID; |
| 567 | 567 | |
| 568 | 568 | // Get current user answers |
| 569 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true ); |
|
| 569 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true); |
|
| 570 | 570 | // Need to always return an array, even with only 1 item |
| 571 | - if ( !is_array($comments) ) { |
|
| 572 | - $comments = array( $comments ); |
|
| 571 | + if ( ! is_array($comments)) { |
|
| 572 | + $comments = array($comments); |
|
| 573 | 573 | } |
| 574 | - foreach ( $comments as $comment ) { |
|
| 574 | + foreach ($comments as $comment) { |
|
| 575 | 575 | $user_id = $comment->user_id; |
| 576 | - $content = maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 577 | - $old_user_answers[ $quiz_id ][ $user_id ] = $content; |
|
| 576 | + $content = maybe_unserialize(base64_decode($comment->comment_content)); |
|
| 577 | + $old_user_answers[$quiz_id][$user_id] = $content; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | // Get correct answers |
| 581 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 582 | - if( is_array( $questions ) ) { |
|
| 583 | - foreach( $questions as $question ) { |
|
| 584 | - $right_answer = get_post_meta( $question->ID, '_question_right_answer', true ); |
|
| 585 | - $right_answers[ $quiz_id ][ $question->ID ] = $right_answer; |
|
| 581 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 582 | + if (is_array($questions)) { |
|
| 583 | + foreach ($questions as $question) { |
|
| 584 | + $right_answer = get_post_meta($question->ID, '_question_right_answer', true); |
|
| 585 | + $right_answers[$quiz_id][$question->ID] = $right_answer; |
|
| 586 | 586 | } |
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - if( is_array( $right_answers ) ) { |
|
| 592 | - foreach( $right_answers as $quiz_id => $question ) { |
|
| 591 | + if (is_array($right_answers)) { |
|
| 592 | + foreach ($right_answers as $quiz_id => $question) { |
|
| 593 | 593 | $count = 0; |
| 594 | - if( is_array( $question ) ) { |
|
| 595 | - foreach( $question as $question_id => $answer ) { |
|
| 594 | + if (is_array($question)) { |
|
| 595 | + foreach ($question as $question_id => $answer) { |
|
| 596 | 596 | ++$count; |
| 597 | - if( isset( $old_user_answers[ $quiz_id ] ) ) { |
|
| 598 | - $answers_linkup[ $quiz_id ][ $count ] = $question_id; |
|
| 597 | + if (isset($old_user_answers[$quiz_id])) { |
|
| 598 | + $answers_linkup[$quiz_id][$count] = $question_id; |
|
| 599 | 599 | } |
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - if( is_array( $old_user_answers ) ) { |
|
| 606 | - foreach( $old_user_answers as $quiz_id => $user_answers ) { |
|
| 607 | - foreach( $user_answers as $user_id => $answers ) { |
|
| 608 | - foreach( $answers as $answer_id => $user_answer ) { |
|
| 609 | - $question_id = $answers_linkup[ $quiz_id ][ $answer_id ]; |
|
| 610 | - $new_user_answers[ $question_id ] = $user_answer; |
|
| 611 | - Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id ); |
|
| 605 | + if (is_array($old_user_answers)) { |
|
| 606 | + foreach ($old_user_answers as $quiz_id => $user_answers) { |
|
| 607 | + foreach ($user_answers as $user_id => $answers) { |
|
| 608 | + foreach ($answers as $answer_id => $user_answer) { |
|
| 609 | + $question_id = $answers_linkup[$quiz_id][$answer_id]; |
|
| 610 | + $new_user_answers[$question_id] = $user_answer; |
|
| 611 | + Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id); |
|
| 612 | 612 | } |
| 613 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 614 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 615 | - Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id ); |
|
| 613 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 614 | + Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 615 | + Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - if ( $current_page == $total_pages ) { |
|
| 620 | + if ($current_page == $total_pages) { |
|
| 621 | 621 | return true; |
| 622 | 622 | } else { |
| 623 | 623 | return false; |
@@ -632,15 +632,15 @@ discard block |
||
| 632 | 632 | * @return boolean |
| 633 | 633 | */ |
| 634 | 634 | public function update_question_grade_points() { |
| 635 | - $args = array( 'post_type' => 'question', |
|
| 635 | + $args = array('post_type' => 'question', |
|
| 636 | 636 | 'posts_per_page' => -1, |
| 637 | 637 | 'post_status' => 'publish', |
| 638 | 638 | 'suppress_filters' => 0 |
| 639 | 639 | ); |
| 640 | - $questions = get_posts( $args ); |
|
| 640 | + $questions = get_posts($args); |
|
| 641 | 641 | |
| 642 | - foreach( $questions as $question ) { |
|
| 643 | - update_post_meta( $question->ID, '_question_grade', '1' ); |
|
| 642 | + foreach ($questions as $question) { |
|
| 643 | + update_post_meta($question->ID, '_question_grade', '1'); |
|
| 644 | 644 | } |
| 645 | 645 | return true; |
| 646 | 646 | } // End update_question_grade_points |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | * @return boolean |
| 653 | 653 | */ |
| 654 | 654 | public function convert_essay_paste_questions() { |
| 655 | - $args = array( 'post_type' => 'question', |
|
| 655 | + $args = array('post_type' => 'question', |
|
| 656 | 656 | 'posts_per_page' => -1, |
| 657 | 657 | 'post_status' => 'publish', |
| 658 | 658 | 'tax_query' => array( |
@@ -664,14 +664,14 @@ discard block |
||
| 664 | 664 | ), |
| 665 | 665 | 'suppress_filters' => 0 |
| 666 | 666 | ); |
| 667 | - $questions = get_posts( $args ); |
|
| 667 | + $questions = get_posts($args); |
|
| 668 | 668 | |
| 669 | - foreach( $questions as $question ) { |
|
| 670 | - wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false ); |
|
| 669 | + foreach ($questions as $question) { |
|
| 670 | + wp_set_object_terms($question->ID, 'multi-line', 'question-type', false); |
|
| 671 | 671 | |
| 672 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
| 673 | - if( 0 < intval( $quiz_id ) ) { |
|
| 674 | - add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true ); |
|
| 672 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
| 673 | + if (0 < intval($quiz_id)) { |
|
| 674 | + add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true); |
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | return true; |
@@ -683,33 +683,33 @@ discard block |
||
| 683 | 683 | * @since 1.5.0 |
| 684 | 684 | * @return boolean |
| 685 | 685 | */ |
| 686 | - public function set_random_question_order( $n = 50, $offset = 0 ) { |
|
| 686 | + public function set_random_question_order($n = 50, $offset = 0) { |
|
| 687 | 687 | |
| 688 | 688 | // Get Total Number of Updates to run |
| 689 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
| 689 | + $quiz_count_object = wp_count_posts('quiz'); |
|
| 690 | 690 | $quiz_count_published = $quiz_count_object->publish; |
| 691 | 691 | |
| 692 | 692 | // Calculate if this is the last page |
| 693 | - if ( 0 == $offset ) { |
|
| 693 | + if (0 == $offset) { |
|
| 694 | 694 | $current_page = 1; |
| 695 | 695 | } else { |
| 696 | - $current_page = intval( $offset / $n ); |
|
| 696 | + $current_page = intval($offset / $n); |
|
| 697 | 697 | } // End If Statement |
| 698 | - $total_pages = intval( $quiz_count_published / $n ); |
|
| 698 | + $total_pages = intval($quiz_count_published / $n); |
|
| 699 | 699 | |
| 700 | - $args = array( 'post_type' => 'quiz', |
|
| 700 | + $args = array('post_type' => 'quiz', |
|
| 701 | 701 | 'post_status' => 'any', |
| 702 | 702 | 'posts_per_page' => $n, |
| 703 | 703 | 'offset' => $offset, |
| 704 | 704 | 'suppress_filters' => 0 |
| 705 | 705 | ); |
| 706 | - $quizzes = get_posts( $args ); |
|
| 706 | + $quizzes = get_posts($args); |
|
| 707 | 707 | |
| 708 | - foreach( $quizzes as $quiz ) { |
|
| 709 | - update_post_meta( $quiz->ID, '_random_question_order', 'yes' ); |
|
| 708 | + foreach ($quizzes as $quiz) { |
|
| 709 | + update_post_meta($quiz->ID, '_random_question_order', 'yes'); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - if ( $current_page == $total_pages ) { |
|
| 712 | + if ($current_page == $total_pages) { |
|
| 713 | 713 | return true; |
| 714 | 714 | } else { |
| 715 | 715 | return false; |
@@ -723,37 +723,37 @@ discard block |
||
| 723 | 723 | * @since 1.5.0 |
| 724 | 724 | * @return boolean |
| 725 | 725 | */ |
| 726 | - public function set_default_show_question_count( $n = 50, $offset = 0 ) { |
|
| 726 | + public function set_default_show_question_count($n = 50, $offset = 0) { |
|
| 727 | 727 | |
| 728 | - $args = array( 'post_type' => 'quiz', |
|
| 728 | + $args = array('post_type' => 'quiz', |
|
| 729 | 729 | 'post_status' => 'any', |
| 730 | 730 | 'posts_per_page' => $n, |
| 731 | 731 | 'offset' => $offset, |
| 732 | 732 | 'meta_key' => '_show_questions', |
| 733 | 733 | 'suppress_filters' => 0 |
| 734 | 734 | ); |
| 735 | - $quizzes = get_posts( $args ); |
|
| 735 | + $quizzes = get_posts($args); |
|
| 736 | 736 | |
| 737 | - $total_quizzes = count( $quizzes ); |
|
| 737 | + $total_quizzes = count($quizzes); |
|
| 738 | 738 | |
| 739 | - if( 0 == intval( $total_quizzes ) ) { |
|
| 739 | + if (0 == intval($total_quizzes)) { |
|
| 740 | 740 | return true; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - foreach( $quizzes as $quiz ) { |
|
| 744 | - delete_post_meta( $quiz->ID, '_show_questions' ); |
|
| 743 | + foreach ($quizzes as $quiz) { |
|
| 744 | + delete_post_meta($quiz->ID, '_show_questions'); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - $total_pages = intval( $total_quizzes / $n ); |
|
| 747 | + $total_pages = intval($total_quizzes / $n); |
|
| 748 | 748 | |
| 749 | 749 | // Calculate if this is the last page |
| 750 | - if ( 0 == $offset ) { |
|
| 750 | + if (0 == $offset) { |
|
| 751 | 751 | $current_page = 1; |
| 752 | 752 | } else { |
| 753 | - $current_page = intval( $offset / $n ); |
|
| 753 | + $current_page = intval($offset / $n); |
|
| 754 | 754 | } // End If Statement |
| 755 | 755 | |
| 756 | - if ( $current_page == $total_pages ) { |
|
| 756 | + if ($current_page == $total_pages) { |
|
| 757 | 757 | return true; |
| 758 | 758 | } else { |
| 759 | 759 | return false; |
@@ -761,17 +761,17 @@ discard block |
||
| 761 | 761 | |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - public function remove_deleted_user_activity( $n = 50, $offset = 0 ) { |
|
| 764 | + public function remove_deleted_user_activity($n = 50, $offset = 0) { |
|
| 765 | 765 | |
| 766 | 766 | |
| 767 | 767 | // remove_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) ); |
| 768 | 768 | |
| 769 | - $all_activity = get_comments( array( 'status' => 'approve' ) ); |
|
| 769 | + $all_activity = get_comments(array('status' => 'approve')); |
|
| 770 | 770 | $activity_count = array(); |
| 771 | - foreach( $all_activity as $activity ) { |
|
| 772 | - if( '' == $activity->comment_type ) continue; |
|
| 773 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 774 | - if( 0 == $activity->user_id ) continue; |
|
| 771 | + foreach ($all_activity as $activity) { |
|
| 772 | + if ('' == $activity->comment_type) continue; |
|
| 773 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 774 | + if (0 == $activity->user_id) continue; |
|
| 775 | 775 | $activity_count[] = $activity->comment_ID; |
| 776 | 776 | } |
| 777 | 777 | |
@@ -781,35 +781,35 @@ discard block |
||
| 781 | 781 | 'status' => 'approve' |
| 782 | 782 | ); |
| 783 | 783 | |
| 784 | - $activities = get_comments( $args ); |
|
| 784 | + $activities = get_comments($args); |
|
| 785 | 785 | |
| 786 | - foreach( $activities as $activity ) { |
|
| 787 | - if( '' == $activity->comment_type ) continue; |
|
| 788 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 789 | - if( 0 == $activity->user_id ) continue; |
|
| 786 | + foreach ($activities as $activity) { |
|
| 787 | + if ('' == $activity->comment_type) continue; |
|
| 788 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 789 | + if (0 == $activity->user_id) continue; |
|
| 790 | 790 | |
| 791 | - $user_exists = get_userdata( $activity->user_id ); |
|
| 791 | + $user_exists = get_userdata($activity->user_id); |
|
| 792 | 792 | |
| 793 | - if( ! $user_exists ) { |
|
| 794 | - wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
| 793 | + if ( ! $user_exists) { |
|
| 794 | + wp_delete_comment(intval($activity->comment_ID), true); |
|
| 795 | 795 | wp_cache_flush(); |
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | - $total_activities = count( $activity_count ); |
|
| 799 | + $total_activities = count($activity_count); |
|
| 800 | 800 | |
| 801 | - $total_pages = intval( $total_activities / $n ); |
|
| 801 | + $total_pages = intval($total_activities / $n); |
|
| 802 | 802 | |
| 803 | 803 | // Calculate if this is the last page |
| 804 | - if ( 0 == $offset ) { |
|
| 804 | + if (0 == $offset) { |
|
| 805 | 805 | $current_page = 1; |
| 806 | 806 | } else { |
| 807 | - $current_page = intval( $offset / $n ); |
|
| 807 | + $current_page = intval($offset / $n); |
|
| 808 | 808 | } // End If Statement |
| 809 | 809 | |
| 810 | 810 | // add_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) ); |
| 811 | 811 | |
| 812 | - if ( $current_page >= $total_pages ) { |
|
| 812 | + if ($current_page >= $total_pages) { |
|
| 813 | 813 | return true; |
| 814 | 814 | } else { |
| 815 | 815 | return false; |
@@ -818,16 +818,16 @@ discard block |
||
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | public function add_teacher_role() { |
| 821 | - add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) ); |
|
| 821 | + add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true)); |
|
| 822 | 822 | return true; |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | public function add_sensei_caps() { |
| 826 | - $role = get_role( 'administrator' ); |
|
| 826 | + $role = get_role('administrator'); |
|
| 827 | 827 | |
| 828 | - if( ! is_null( $role ) ) { |
|
| 829 | - $role->add_cap( 'manage_sensei' ); |
|
| 830 | - $role->add_cap( 'manage_sensei_grades' ); |
|
| 828 | + if ( ! is_null($role)) { |
|
| 829 | + $role->add_cap('manage_sensei'); |
|
| 830 | + $role->add_cap('manage_sensei_grades'); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | return true; |
@@ -841,16 +841,16 @@ discard block |
||
| 841 | 841 | 'suppress_filters' => 0 |
| 842 | 842 | ); |
| 843 | 843 | |
| 844 | - $questions = get_posts( $args ); |
|
| 844 | + $questions = get_posts($args); |
|
| 845 | 845 | |
| 846 | - foreach( $questions as $question ) { |
|
| 846 | + foreach ($questions as $question) { |
|
| 847 | 847 | |
| 848 | - if( ! isset( $question->ID ) ) continue; |
|
| 848 | + if ( ! isset($question->ID)) continue; |
|
| 849 | 849 | |
| 850 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
| 850 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
| 851 | 851 | |
| 852 | - $question_order = get_post_meta( $question->ID, '_quiz_question_order', true ); |
|
| 853 | - update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order ); |
|
| 852 | + $question_order = get_post_meta($question->ID, '_quiz_question_order', true); |
|
| 853 | + update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order); |
|
| 854 | 854 | |
| 855 | 855 | } |
| 856 | 856 | |
@@ -859,15 +859,15 @@ discard block |
||
| 859 | 859 | |
| 860 | 860 | public function update_quiz_settings() { |
| 861 | 861 | |
| 862 | - $settings = get_option( 'woothemes-sensei-settings', array() ); |
|
| 862 | + $settings = get_option('woothemes-sensei-settings', array()); |
|
| 863 | 863 | |
| 864 | 864 | $lesson_completion = false; |
| 865 | - if( isset( $settings['lesson_completion'] ) ) { |
|
| 865 | + if (isset($settings['lesson_completion'])) { |
|
| 866 | 866 | $lesson_completion = $settings['lesson_completion']; |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | $reset_quiz_allowed = false; |
| 870 | - if( isset( $settings['quiz_reset_allowed'] ) ) { |
|
| 870 | + if (isset($settings['quiz_reset_allowed'])) { |
|
| 871 | 871 | $reset_quiz_allowed = $settings['quiz_reset_allowed']; |
| 872 | 872 | } |
| 873 | 873 | |
@@ -878,20 +878,20 @@ discard block |
||
| 878 | 878 | 'suppress_filters' => 0 |
| 879 | 879 | ); |
| 880 | 880 | |
| 881 | - $quizzes = get_posts( $args ); |
|
| 881 | + $quizzes = get_posts($args); |
|
| 882 | 882 | |
| 883 | - foreach( $quizzes as $quiz ) { |
|
| 883 | + foreach ($quizzes as $quiz) { |
|
| 884 | 884 | |
| 885 | - if( ! isset( $quiz->ID ) ) continue; |
|
| 885 | + if ( ! isset($quiz->ID)) continue; |
|
| 886 | 886 | |
| 887 | - if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) { |
|
| 888 | - update_post_meta( $quiz->ID, '_pass_required', 'on' ); |
|
| 887 | + if (isset($lesson_completion) && 'passed' == $lesson_completion) { |
|
| 888 | + update_post_meta($quiz->ID, '_pass_required', 'on'); |
|
| 889 | 889 | } else { |
| 890 | - update_post_meta( $quiz->ID, '_quiz_passmark', 0 ); |
|
| 890 | + update_post_meta($quiz->ID, '_quiz_passmark', 0); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { |
|
| 894 | - update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' ); |
|
| 893 | + if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { |
|
| 894 | + update_post_meta($quiz->ID, '_enable_quiz_reset', 'on'); |
|
| 895 | 895 | } |
| 896 | 896 | } |
| 897 | 897 | |
@@ -906,22 +906,22 @@ discard block |
||
| 906 | 906 | 'suppress_filters' => 0 |
| 907 | 907 | ); |
| 908 | 908 | |
| 909 | - $lessons = get_posts( $args ); |
|
| 909 | + $lessons = get_posts($args); |
|
| 910 | 910 | |
| 911 | - foreach( $lessons as $lesson ) { |
|
| 911 | + foreach ($lessons as $lesson) { |
|
| 912 | 912 | |
| 913 | - if( ! isset( $lesson->ID ) ) continue; |
|
| 913 | + if ( ! isset($lesson->ID)) continue; |
|
| 914 | 914 | |
| 915 | - $course_id = get_post_meta( $lesson->ID, '_lesson_course', true); |
|
| 915 | + $course_id = get_post_meta($lesson->ID, '_lesson_course', true); |
|
| 916 | 916 | |
| 917 | - if( $course_id ) { |
|
| 918 | - update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
|
| 917 | + if ($course_id) { |
|
| 918 | + update_post_meta($lesson->ID, '_order_'.$course_id, 0); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 921 | + $module = Sensei()->modules->get_lesson_module($lesson->ID); |
|
| 922 | 922 | |
| 923 | - if( $module ) { |
|
| 924 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 923 | + if ($module) { |
|
| 924 | + update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0); |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | } |
@@ -930,10 +930,10 @@ discard block |
||
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | public function add_editor_caps() { |
| 933 | - $role = get_role( 'editor' ); |
|
| 933 | + $role = get_role('editor'); |
|
| 934 | 934 | |
| 935 | - if( ! is_null( $role ) ) { |
|
| 936 | - $role->add_cap( 'manage_sensei_grades' ); |
|
| 935 | + if ( ! is_null($role)) { |
|
| 936 | + $role->add_cap('manage_sensei_grades'); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | return true; |
@@ -952,26 +952,26 @@ discard block |
||
| 952 | 952 | WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%' |
| 953 | 953 | AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id |
| 954 | 954 | AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'"; |
| 955 | - $wpdb->query( $sql ); |
|
| 955 | + $wpdb->query($sql); |
|
| 956 | 956 | |
| 957 | 957 | return true; |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) { |
|
| 961 | - $count_object = wp_count_posts( 'quiz' ); |
|
| 960 | + public function update_quiz_lesson_relationship($n = 50, $offset = 0) { |
|
| 961 | + $count_object = wp_count_posts('quiz'); |
|
| 962 | 962 | |
| 963 | 963 | $count_published = 0; |
| 964 | - foreach ( $count_object AS $status => $count ) { |
|
| 964 | + foreach ($count_object AS $status => $count) { |
|
| 965 | 965 | $count_published += $count; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | // Calculate if this is the last page |
| 969 | - if ( 0 == $offset ) { |
|
| 969 | + if (0 == $offset) { |
|
| 970 | 970 | $current_page = 1; |
| 971 | 971 | } else { |
| 972 | - $current_page = intval( $offset / $n ); |
|
| 972 | + $current_page = intval($offset / $n); |
|
| 973 | 973 | } |
| 974 | - $total_pages = ceil( $count_published / $n ); |
|
| 974 | + $total_pages = ceil($count_published / $n); |
|
| 975 | 975 | |
| 976 | 976 | $args = array( |
| 977 | 977 | 'post_type' => 'quiz', |
@@ -980,52 +980,52 @@ discard block |
||
| 980 | 980 | 'post_status' => 'any' |
| 981 | 981 | ); |
| 982 | 982 | |
| 983 | - $quizzes = get_posts( $args ); |
|
| 983 | + $quizzes = get_posts($args); |
|
| 984 | 984 | |
| 985 | - foreach( $quizzes as $quiz ) { |
|
| 985 | + foreach ($quizzes as $quiz) { |
|
| 986 | 986 | |
| 987 | - if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue; |
|
| 987 | + if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue; |
|
| 988 | 988 | |
| 989 | - $lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true ); |
|
| 989 | + $lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true); |
|
| 990 | 990 | |
| 991 | - if( empty( $lesson_id ) ) continue; |
|
| 991 | + if (empty($lesson_id)) continue; |
|
| 992 | 992 | |
| 993 | 993 | $data = array( |
| 994 | 994 | 'ID' => $quiz->ID, |
| 995 | 995 | 'post_parent' => $lesson_id, |
| 996 | 996 | ); |
| 997 | - wp_update_post( $data ); |
|
| 997 | + wp_update_post($data); |
|
| 998 | 998 | |
| 999 | - update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID ); |
|
| 999 | + update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - if ( $current_page == $total_pages || 0 == $total_pages ) { |
|
| 1002 | + if ($current_page == $total_pages || 0 == $total_pages) { |
|
| 1003 | 1003 | return true; |
| 1004 | 1004 | } else { |
| 1005 | 1005 | return false; |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - function status_changes_fix_lessons( $n = 50, $offset = 0 ) { |
|
| 1009 | + function status_changes_fix_lessons($n = 50, $offset = 0) { |
|
| 1010 | 1010 | global $wpdb; |
| 1011 | 1011 | |
| 1012 | - $count_object = wp_count_posts( 'lesson' ); |
|
| 1012 | + $count_object = wp_count_posts('lesson'); |
|
| 1013 | 1013 | $count_published = 0; |
| 1014 | - foreach ( $count_object AS $status => $count ) { |
|
| 1014 | + foreach ($count_object AS $status => $count) { |
|
| 1015 | 1015 | $count_published += $count; |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - if ( 0 == $count_published ) { |
|
| 1018 | + if (0 == $count_published) { |
|
| 1019 | 1019 | return true; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | // Calculate if this is the last page |
| 1023 | - if ( 0 == $offset ) { |
|
| 1023 | + if (0 == $offset) { |
|
| 1024 | 1024 | $current_page = 1; |
| 1025 | 1025 | } else { |
| 1026 | - $current_page = intval( $offset / $n ); |
|
| 1026 | + $current_page = intval($offset / $n); |
|
| 1027 | 1027 | } |
| 1028 | - $total_pages = ceil( $count_published / $n ); |
|
| 1028 | + $total_pages = ceil($count_published / $n); |
|
| 1029 | 1029 | |
| 1030 | 1030 | // Get all Lessons with (and without) Quizzes... |
| 1031 | 1031 | $args = array( |
@@ -1035,26 +1035,26 @@ discard block |
||
| 1035 | 1035 | 'offset' => $offset, |
| 1036 | 1036 | 'fields' => 'ids' |
| 1037 | 1037 | ); |
| 1038 | - $lesson_ids = get_posts( $args ); |
|
| 1038 | + $lesson_ids = get_posts($args); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // ...get all Quiz IDs for the above Lessons |
| 1041 | - $id_list = join( ',', $lesson_ids ); |
|
| 1042 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1041 | + $id_list = join(',', $lesson_ids); |
|
| 1042 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1043 | 1043 | $lesson_quiz_ids = array(); |
| 1044 | - if ( !empty($meta_list) ) { |
|
| 1045 | - foreach ( $meta_list as $metarow ) { |
|
| 1044 | + if ( ! empty($meta_list)) { |
|
| 1045 | + foreach ($meta_list as $metarow) { |
|
| 1046 | 1046 | $lesson_id = $metarow['meta_value']; |
| 1047 | 1047 | $quiz_id = $metarow['post_id']; |
| 1048 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
| 1048 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | // ...check all Quiz IDs for questions |
| 1053 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
| 1054 | - $meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1053 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
| 1054 | + $meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1055 | 1055 | $lesson_quiz_ids_with_questions = array(); |
| 1056 | - if ( !empty($meta_list) ) { |
|
| 1057 | - foreach ( $meta_list as $metarow ) { |
|
| 1056 | + if ( ! empty($meta_list)) { |
|
| 1057 | + foreach ($meta_list as $metarow) { |
|
| 1058 | 1058 | $quiz_id = $metarow['meta_value']; |
| 1059 | 1059 | $lesson_quiz_ids_with_questions[] = $quiz_id; |
| 1060 | 1060 | } |
@@ -1062,49 +1062,49 @@ discard block |
||
| 1062 | 1062 | |
| 1063 | 1063 | // For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons |
| 1064 | 1064 | // if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons |
| 1065 | - $d_count = $a_count =0; |
|
| 1066 | - foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) { |
|
| 1067 | - if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1065 | + $d_count = $a_count = 0; |
|
| 1066 | + foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) { |
|
| 1067 | + if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | // Quiz has no questions, drop the corresponding data |
| 1070 | - delete_post_meta( $quiz_id, '_pass_required' ); |
|
| 1071 | - delete_post_meta( $quiz_id, '_quiz_passmark' ); |
|
| 1072 | - delete_post_meta( $lesson_id, '_quiz_has_questions' ); |
|
| 1070 | + delete_post_meta($quiz_id, '_pass_required'); |
|
| 1071 | + delete_post_meta($quiz_id, '_quiz_passmark'); |
|
| 1072 | + delete_post_meta($lesson_id, '_quiz_has_questions'); |
|
| 1073 | 1073 | $d_count++; |
| 1074 | 1074 | } |
| 1075 | - else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1075 | + else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
| 1076 | 1076 | |
| 1077 | 1077 | // Quiz has no questions, drop the corresponding data |
| 1078 | - update_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1078 | + update_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1079 | 1079 | $a_count++; |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | - if ( $current_page == $total_pages ) { |
|
| 1083 | + if ($current_page == $total_pages) { |
|
| 1084 | 1084 | return true; |
| 1085 | 1085 | } else { |
| 1086 | 1086 | return false; |
| 1087 | 1087 | } |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | - function status_changes_convert_lessons( $n = 50, $offset = 0 ) { |
|
| 1090 | + function status_changes_convert_lessons($n = 50, $offset = 0) { |
|
| 1091 | 1091 | global $wpdb; |
| 1092 | 1092 | |
| 1093 | - wp_defer_comment_counting( true ); |
|
| 1093 | + wp_defer_comment_counting(true); |
|
| 1094 | 1094 | |
| 1095 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1095 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1096 | 1096 | |
| 1097 | - if ( 0 == $user_count_result ) { |
|
| 1097 | + if (0 == $user_count_result) { |
|
| 1098 | 1098 | return true; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | - if ( 0 == $offset ) { |
|
| 1101 | + if (0 == $offset) { |
|
| 1102 | 1102 | $current_page = 1; |
| 1103 | 1103 | } else { |
| 1104 | - $current_page = intval( $offset / $n ); |
|
| 1104 | + $current_page = intval($offset / $n); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1107 | + $total_pages = ceil($user_count_result / $n); |
|
| 1108 | 1108 | |
| 1109 | 1109 | // Get all Lessons with Quizzes... |
| 1110 | 1110 | $args = array( |
@@ -1119,34 +1119,34 @@ discard block |
||
| 1119 | 1119 | ), |
| 1120 | 1120 | 'fields' => 'ids' |
| 1121 | 1121 | ); |
| 1122 | - $lesson_ids_with_quizzes = get_posts( $args ); |
|
| 1122 | + $lesson_ids_with_quizzes = get_posts($args); |
|
| 1123 | 1123 | // ...get all Quiz IDs for the above Lessons |
| 1124 | - $id_list = join( ',', $lesson_ids_with_quizzes ); |
|
| 1125 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1124 | + $id_list = join(',', $lesson_ids_with_quizzes); |
|
| 1125 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1126 | 1126 | $lesson_quiz_ids = array(); |
| 1127 | - if ( !empty($meta_list) ) { |
|
| 1128 | - foreach ( $meta_list as $metarow ) { |
|
| 1127 | + if ( ! empty($meta_list)) { |
|
| 1128 | + foreach ($meta_list as $metarow) { |
|
| 1129 | 1129 | $lesson_id = $metarow['meta_value']; |
| 1130 | 1130 | $quiz_id = $metarow['post_id']; |
| 1131 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
| 1131 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
| 1132 | 1132 | } |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | // ...get all Pass Required & Passmarks for the above Lesson/Quizzes |
| 1136 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
| 1137 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A ); |
|
| 1136 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
| 1137 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A); |
|
| 1138 | 1138 | $quizzes_pass_required = $quizzes_passmarks = array(); |
| 1139 | - if ( !empty($meta_list) ) { |
|
| 1140 | - foreach ( $meta_list as $metarow ) { |
|
| 1141 | - if ( !empty($metarow['meta_value']) ) { |
|
| 1139 | + if ( ! empty($meta_list)) { |
|
| 1140 | + foreach ($meta_list as $metarow) { |
|
| 1141 | + if ( ! empty($metarow['meta_value'])) { |
|
| 1142 | 1142 | $quiz_id = $metarow['post_id']; |
| 1143 | 1143 | $key = $metarow['meta_key']; |
| 1144 | 1144 | $value = $metarow['meta_value']; |
| 1145 | - if ( '_pass_required' == $key ) { |
|
| 1146 | - $quizzes_pass_required[ $quiz_id ] = $value; |
|
| 1145 | + if ('_pass_required' == $key) { |
|
| 1146 | + $quizzes_pass_required[$quiz_id] = $value; |
|
| 1147 | 1147 | } |
| 1148 | - if ( '_quiz_passmark' == $key ) { |
|
| 1149 | - $quizzes_passmarks[ $quiz_id ] = $value; |
|
| 1148 | + if ('_quiz_passmark' == $key) { |
|
| 1149 | + $quizzes_passmarks[$quiz_id] = $value; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } |
| 1152 | 1152 | } |
@@ -1160,41 +1160,41 @@ discard block |
||
| 1160 | 1160 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' "; |
| 1161 | 1161 | |
| 1162 | 1162 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
| 1163 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1163 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1164 | 1164 | |
| 1165 | - foreach ( $user_ids AS $user_id ) { |
|
| 1165 | + foreach ($user_ids AS $user_id) { |
|
| 1166 | 1166 | |
| 1167 | 1167 | $lesson_ends = $lesson_grades = $lesson_answers = array(); |
| 1168 | 1168 | |
| 1169 | 1169 | // Pre-process the lesson ends |
| 1170 | - $_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A ); |
|
| 1171 | - foreach ( $_lesson_ends as $lesson_end ) { |
|
| 1170 | + $_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A); |
|
| 1171 | + foreach ($_lesson_ends as $lesson_end) { |
|
| 1172 | 1172 | // This will overwrite existing entries with the newer ones |
| 1173 | - $lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date']; |
|
| 1173 | + $lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date']; |
|
| 1174 | 1174 | } |
| 1175 | - unset( $_lesson_ends ); |
|
| 1175 | + unset($_lesson_ends); |
|
| 1176 | 1176 | |
| 1177 | 1177 | // Pre-process the lesson grades |
| 1178 | - $_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A ); |
|
| 1179 | - foreach ( $_lesson_grades as $lesson_grade ) { |
|
| 1178 | + $_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A); |
|
| 1179 | + foreach ($_lesson_grades as $lesson_grade) { |
|
| 1180 | 1180 | // This will overwrite existing entries with the newer ones (assuming the grade is higher) |
| 1181 | - if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) { |
|
| 1182 | - $lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content']; |
|
| 1181 | + if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) { |
|
| 1182 | + $lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content']; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | } |
| 1185 | - unset( $_lesson_grades ); |
|
| 1185 | + unset($_lesson_grades); |
|
| 1186 | 1186 | |
| 1187 | 1187 | // Pre-process the lesson answers |
| 1188 | - $_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A ); |
|
| 1189 | - foreach ( $_lesson_answers as $lesson_answer ) { |
|
| 1188 | + $_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A); |
|
| 1189 | + foreach ($_lesson_answers as $lesson_answer) { |
|
| 1190 | 1190 | // This will overwrite existing entries with the newer ones |
| 1191 | - $lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content']; |
|
| 1191 | + $lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content']; |
|
| 1192 | 1192 | } |
| 1193 | - unset( $_lesson_answers ); |
|
| 1193 | + unset($_lesson_answers); |
|
| 1194 | 1194 | |
| 1195 | 1195 | // Grab all the lesson starts for the user |
| 1196 | - $lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
| 1197 | - foreach ( $lesson_starts as $lesson_log ) { |
|
| 1196 | + $lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
| 1197 | + foreach ($lesson_starts as $lesson_log) { |
|
| 1198 | 1198 | |
| 1199 | 1199 | $lesson_id = $lesson_log['comment_post_ID']; |
| 1200 | 1200 | |
@@ -1207,23 +1207,23 @@ discard block |
||
| 1207 | 1207 | 'start' => $status_date, |
| 1208 | 1208 | ); |
| 1209 | 1209 | // Check if there is a lesson end |
| 1210 | - if ( !empty($lesson_ends[$lesson_id]) ) { |
|
| 1210 | + if ( ! empty($lesson_ends[$lesson_id])) { |
|
| 1211 | 1211 | $status_date = $lesson_ends[$lesson_id]; |
| 1212 | 1212 | // Check lesson has quiz |
| 1213 | - if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) { |
|
| 1213 | + if ( ! empty($lesson_quiz_ids[$lesson_id])) { |
|
| 1214 | 1214 | // Check for the quiz answers |
| 1215 | - if ( !empty($lesson_answers[$quiz_id]) ) { |
|
| 1215 | + if ( ! empty($lesson_answers[$quiz_id])) { |
|
| 1216 | 1216 | $meta_data['questions_asked'] = $lesson_answers[$quiz_id]; |
| 1217 | 1217 | } |
| 1218 | 1218 | // Check if there is a quiz grade |
| 1219 | 1219 | $quiz_id = $lesson_quiz_ids[$lesson_id]; |
| 1220 | - if ( !empty($lesson_grades[$quiz_id]) ) { |
|
| 1220 | + if ( ! empty($lesson_grades[$quiz_id])) { |
|
| 1221 | 1221 | $meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id]; |
| 1222 | 1222 | // Check if the user has to get the passmark and has or not |
| 1223 | - if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) { |
|
| 1223 | + if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) { |
|
| 1224 | 1224 | $status = 'passed'; |
| 1225 | 1225 | } |
| 1226 | - elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1226 | + elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) { |
|
| 1227 | 1227 | $status = 'failed'; |
| 1228 | 1228 | } |
| 1229 | 1229 | else { |
@@ -1251,26 +1251,26 @@ discard block |
||
| 1251 | 1251 | 'comment_author' => '', |
| 1252 | 1252 | ); |
| 1253 | 1253 | // Check it doesn't already exist |
| 1254 | - $sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id ); |
|
| 1255 | - $comment_ID = $wpdb->get_var( $sql ); |
|
| 1256 | - if ( !$comment_ID ) { |
|
| 1254 | + $sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id); |
|
| 1255 | + $comment_ID = $wpdb->get_var($sql); |
|
| 1256 | + if ( ! $comment_ID) { |
|
| 1257 | 1257 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1258 | 1258 | $wpdb->insert($wpdb->comments, $data); |
| 1259 | 1259 | $comment_ID = (int) $wpdb->insert_id; |
| 1260 | 1260 | |
| 1261 | - if ( $comment_ID && !empty($meta_data) ) { |
|
| 1262 | - foreach ( $meta_data as $key => $value ) { |
|
| 1261 | + if ($comment_ID && ! empty($meta_data)) { |
|
| 1262 | + foreach ($meta_data as $key => $value) { |
|
| 1263 | 1263 | // Bypassing WP add_comment_meta(() so no actions/filters are run |
| 1264 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1264 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1265 | 1265 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1266 | - $comment_ID, $key ) ) ) { |
|
| 1266 | + $comment_ID, $key ))) { |
|
| 1267 | 1267 | continue; // Found the meta data already |
| 1268 | 1268 | } |
| 1269 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1269 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1270 | 1270 | 'comment_id' => $comment_ID, |
| 1271 | 1271 | 'meta_key' => $key, |
| 1272 | 1272 | 'meta_value' => $value |
| 1273 | - ) ); |
|
| 1273 | + )); |
|
| 1274 | 1274 | } |
| 1275 | 1275 | } |
| 1276 | 1276 | } |
@@ -1278,40 +1278,40 @@ discard block |
||
| 1278 | 1278 | } |
| 1279 | 1279 | $wpdb->flush(); |
| 1280 | 1280 | |
| 1281 | - if ( $current_page == $total_pages ) { |
|
| 1281 | + if ($current_page == $total_pages) { |
|
| 1282 | 1282 | return true; |
| 1283 | 1283 | } else { |
| 1284 | 1284 | return false; |
| 1285 | 1285 | } |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | - function status_changes_convert_courses( $n = 50, $offset = 0 ) { |
|
| 1288 | + function status_changes_convert_courses($n = 50, $offset = 0) { |
|
| 1289 | 1289 | global $wpdb; |
| 1290 | 1290 | |
| 1291 | - wp_defer_comment_counting( true ); |
|
| 1291 | + wp_defer_comment_counting(true); |
|
| 1292 | 1292 | |
| 1293 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1293 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1294 | 1294 | |
| 1295 | - if ( 0 == $user_count_result ) { |
|
| 1295 | + if (0 == $user_count_result) { |
|
| 1296 | 1296 | return true; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - if ( 0 == $offset ) { |
|
| 1299 | + if (0 == $offset) { |
|
| 1300 | 1300 | $current_page = 1; |
| 1301 | 1301 | } else { |
| 1302 | - $current_page = intval( $offset / $n ); |
|
| 1302 | + $current_page = intval($offset / $n); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1305 | + $total_pages = ceil($user_count_result / $n); |
|
| 1306 | 1306 | |
| 1307 | 1307 | // Get all Lesson => Course relationships |
| 1308 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A ); |
|
| 1308 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A); |
|
| 1309 | 1309 | $course_lesson_ids = array(); |
| 1310 | - if ( !empty($meta_list) ) { |
|
| 1311 | - foreach ( $meta_list as $metarow ) { |
|
| 1310 | + if ( ! empty($meta_list)) { |
|
| 1311 | + foreach ($meta_list as $metarow) { |
|
| 1312 | 1312 | $lesson_id = $metarow['post_id']; |
| 1313 | 1313 | $course_id = $metarow['meta_value']; |
| 1314 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
| 1314 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
| 1315 | 1315 | } |
| 1316 | 1316 | } |
| 1317 | 1317 | |
@@ -1321,13 +1321,13 @@ discard block |
||
| 1321 | 1321 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' "; |
| 1322 | 1322 | |
| 1323 | 1323 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
| 1324 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1324 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1325 | 1325 | |
| 1326 | - foreach ( $user_ids AS $user_id ) { |
|
| 1326 | + foreach ($user_ids AS $user_id) { |
|
| 1327 | 1327 | |
| 1328 | 1328 | // Grab all the course starts for the user |
| 1329 | - $course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
| 1330 | - foreach ( $course_starts as $course_log ) { |
|
| 1329 | + $course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
| 1330 | + foreach ($course_starts as $course_log) { |
|
| 1331 | 1331 | |
| 1332 | 1332 | $course_id = $course_log['comment_post_ID']; |
| 1333 | 1333 | |
@@ -1342,23 +1342,23 @@ discard block |
||
| 1342 | 1342 | 'percent' => 0, |
| 1343 | 1343 | ); |
| 1344 | 1344 | // Check if the course has lessons |
| 1345 | - if ( !empty( $course_lesson_ids[$course_id] ) ) { |
|
| 1345 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
| 1346 | 1346 | |
| 1347 | 1347 | $lessons_completed = 0; |
| 1348 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
| 1348 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
| 1349 | 1349 | |
| 1350 | 1350 | // Don't use prepare as we need to provide the id join |
| 1351 | - $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) ); |
|
| 1351 | + $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id])); |
|
| 1352 | 1352 | // Get all lesson statuses for this Courses' lessons |
| 1353 | - $lesson_statuses = $wpdb->get_results( $sql, ARRAY_A ); |
|
| 1353 | + $lesson_statuses = $wpdb->get_results($sql, ARRAY_A); |
|
| 1354 | 1354 | // Not enough lesson statuses, thus cannot be complete |
| 1355 | - if ( $total_lessons > count($lesson_statuses) ) { |
|
| 1355 | + if ($total_lessons > count($lesson_statuses)) { |
|
| 1356 | 1356 | $status = 'in-progress'; |
| 1357 | 1357 | } |
| 1358 | 1358 | // Count each lesson to work out the overall percentage |
| 1359 | - foreach ( $lesson_statuses as $lesson_status ) { |
|
| 1359 | + foreach ($lesson_statuses as $lesson_status) { |
|
| 1360 | 1360 | $status_date = $lesson_status['comment_date']; |
| 1361 | - switch ( $lesson_status['status'] ) { |
|
| 1361 | + switch ($lesson_status['status']) { |
|
| 1362 | 1362 | case 'complete': // Lesson has no quiz/questions |
| 1363 | 1363 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1364 | 1364 | case 'passed': |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | } |
| 1374 | 1374 | } |
| 1375 | 1375 | $meta_data['complete'] = $lessons_completed; |
| 1376 | - $meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
| 1376 | + $meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
| 1377 | 1377 | } |
| 1378 | 1378 | else { |
| 1379 | 1379 | // Course has no lessons, therefore cannot be 'complete' |
@@ -1390,26 +1390,26 @@ discard block |
||
| 1390 | 1390 | 'comment_author' => '', |
| 1391 | 1391 | ); |
| 1392 | 1392 | // Check it doesn't already exist |
| 1393 | - $sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id ); |
|
| 1394 | - $comment_ID = $wpdb->get_var( $sql ); |
|
| 1395 | - if ( !$comment_ID ) { |
|
| 1393 | + $sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id); |
|
| 1394 | + $comment_ID = $wpdb->get_var($sql); |
|
| 1395 | + if ( ! $comment_ID) { |
|
| 1396 | 1396 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1397 | 1397 | $wpdb->insert($wpdb->comments, $data); |
| 1398 | 1398 | $comment_ID = (int) $wpdb->insert_id; |
| 1399 | 1399 | |
| 1400 | - if ( $comment_ID && !empty($meta_data) ) { |
|
| 1401 | - foreach ( $meta_data as $key => $value ) { |
|
| 1400 | + if ($comment_ID && ! empty($meta_data)) { |
|
| 1401 | + foreach ($meta_data as $key => $value) { |
|
| 1402 | 1402 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1403 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1403 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1404 | 1404 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1405 | - $comment_ID, $key ) ) ) { |
|
| 1405 | + $comment_ID, $key ))) { |
|
| 1406 | 1406 | continue; // Found the meta data already |
| 1407 | 1407 | } |
| 1408 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1408 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1409 | 1409 | 'comment_id' => $comment_ID, |
| 1410 | 1410 | 'meta_key' => $key, |
| 1411 | 1411 | 'meta_value' => $value |
| 1412 | - ) ); |
|
| 1412 | + )); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | } |
| 1415 | 1415 | } |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | } |
| 1418 | 1418 | $wpdb->flush(); |
| 1419 | 1419 | |
| 1420 | - if ( $current_page == $total_pages ) { |
|
| 1420 | + if ($current_page == $total_pages) { |
|
| 1421 | 1421 | return true; |
| 1422 | 1422 | } else { |
| 1423 | 1423 | return false; |
@@ -1433,70 +1433,70 @@ discard block |
||
| 1433 | 1433 | * @param type $offset |
| 1434 | 1434 | * @return boolean |
| 1435 | 1435 | */ |
| 1436 | - function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) { |
|
| 1436 | + function status_changes_repair_course_statuses($n = 50, $offset = 0) { |
|
| 1437 | 1437 | global $wpdb; |
| 1438 | 1438 | |
| 1439 | - $count_object = wp_count_posts( 'lesson' ); |
|
| 1439 | + $count_object = wp_count_posts('lesson'); |
|
| 1440 | 1440 | $count_published = $count_object->publish; |
| 1441 | 1441 | |
| 1442 | - if ( 0 == $count_published ) { |
|
| 1442 | + if (0 == $count_published) { |
|
| 1443 | 1443 | return true; |
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | // Calculate if this is the last page |
| 1447 | - if ( 0 == $offset ) { |
|
| 1447 | + if (0 == $offset) { |
|
| 1448 | 1448 | $current_page = 1; |
| 1449 | 1449 | } else { |
| 1450 | - $current_page = intval( $offset / $n ); |
|
| 1450 | + $current_page = intval($offset / $n); |
|
| 1451 | 1451 | } |
| 1452 | - $total_pages = ceil( $count_published / $n ); |
|
| 1452 | + $total_pages = ceil($count_published / $n); |
|
| 1453 | 1453 | |
| 1454 | 1454 | $course_lesson_ids = $lesson_user_statuses = array(); |
| 1455 | 1455 | |
| 1456 | 1456 | // Get all Lesson => Course relationships |
| 1457 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A ); |
|
| 1458 | - if ( !empty($meta_list) ) { |
|
| 1459 | - foreach ( $meta_list as $metarow ) { |
|
| 1457 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A); |
|
| 1458 | + if ( ! empty($meta_list)) { |
|
| 1459 | + foreach ($meta_list as $metarow) { |
|
| 1460 | 1460 | $lesson_id = $metarow['post_id']; |
| 1461 | 1461 | $course_id = $metarow['meta_value']; |
| 1462 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
| 1462 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
| 1463 | 1463 | } |
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | // Get all Lesson => Course relationships |
| 1467 | - $status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A ); |
|
| 1468 | - if ( !empty($status_list) ) { |
|
| 1469 | - foreach ( $status_list as $status ) { |
|
| 1470 | - $lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved']; |
|
| 1467 | + $status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A); |
|
| 1468 | + if ( ! empty($status_list)) { |
|
| 1469 | + foreach ($status_list as $status) { |
|
| 1470 | + $lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved']; |
|
| 1471 | 1471 | } |
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
| 1474 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
| 1475 | 1475 | |
| 1476 | 1476 | $per_page = 40; |
| 1477 | 1477 | $comment_id_offset = $count = 0; |
| 1478 | 1478 | |
| 1479 | 1479 | $course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page"; |
| 1480 | 1480 | // $per_page users at a time |
| 1481 | - while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) { |
|
| 1481 | + while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) { |
|
| 1482 | 1482 | |
| 1483 | - foreach ( $course_statuses AS $course_status ) { |
|
| 1483 | + foreach ($course_statuses AS $course_status) { |
|
| 1484 | 1484 | $user_id = $course_status->user_id; |
| 1485 | 1485 | $course_id = $course_status->comment_post_ID; |
| 1486 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
| 1487 | - if ( $total_lessons <= 0 ) { |
|
| 1486 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
| 1487 | + if ($total_lessons <= 0) { |
|
| 1488 | 1488 | $total_lessons = 1; // Fix division of zero error, some courses have no lessons |
| 1489 | 1489 | } |
| 1490 | 1490 | $lessons_completed = 0; |
| 1491 | 1491 | $status = 'in-progress'; |
| 1492 | 1492 | |
| 1493 | 1493 | // Some Courses have no lessons... (can they ever be complete?) |
| 1494 | - if ( !empty($course_lesson_ids[ $course_id ]) ) { |
|
| 1495 | - foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) { |
|
| 1496 | - $lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ]; |
|
| 1494 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
| 1495 | + foreach ($course_lesson_ids[$course_id] AS $lesson_id) { |
|
| 1496 | + $lesson_status = $lesson_user_statuses[$lesson_id][$user_id]; |
|
| 1497 | 1497 | // If lessons are complete without needing quizzes to be passed |
| 1498 | - if ( 'passed' != $course_completion ) { |
|
| 1499 | - switch ( $lesson_status ) { |
|
| 1498 | + if ('passed' != $course_completion) { |
|
| 1499 | + switch ($lesson_status) { |
|
| 1500 | 1500 | // A user cannot 'complete' a course if a lesson... |
| 1501 | 1501 | case 'in-progress': // ...is still in progress |
| 1502 | 1502 | case 'ungraded': // ...hasn't yet been graded |
@@ -1508,7 +1508,7 @@ discard block |
||
| 1508 | 1508 | } |
| 1509 | 1509 | } |
| 1510 | 1510 | else { |
| 1511 | - switch ( $lesson_status ) { |
|
| 1511 | + switch ($lesson_status) { |
|
| 1512 | 1512 | case 'complete': // Lesson has no quiz/questions |
| 1513 | 1513 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1514 | 1514 | case 'passed': // Lesson has quiz and the user passed |
@@ -1523,79 +1523,79 @@ discard block |
||
| 1523 | 1523 | } |
| 1524 | 1524 | } // Each lesson |
| 1525 | 1525 | } // Check for lessons |
| 1526 | - if ( $lessons_completed == $total_lessons ) { |
|
| 1526 | + if ($lessons_completed == $total_lessons) { |
|
| 1527 | 1527 | $status = 'complete'; |
| 1528 | 1528 | } |
| 1529 | 1529 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
| 1530 | 1530 | $metadata = array( |
| 1531 | 1531 | 'complete' => $lessons_completed, |
| 1532 | - 'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ), |
|
| 1532 | + 'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)), |
|
| 1533 | 1533 | ); |
| 1534 | - Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata ); |
|
| 1534 | + Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata); |
|
| 1535 | 1535 | $count++; |
| 1536 | 1536 | |
| 1537 | 1537 | } // per course status |
| 1538 | 1538 | $comment_id_offset = $course_status->comment_ID; |
| 1539 | 1539 | } // all course statuses |
| 1540 | 1540 | |
| 1541 | - if ( $current_page == $total_pages ) { |
|
| 1541 | + if ($current_page == $total_pages) { |
|
| 1542 | 1542 | return true; |
| 1543 | 1543 | } else { |
| 1544 | 1544 | return false; |
| 1545 | 1545 | } |
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | - function status_changes_convert_questions( $n = 50, $offset = 0 ) { |
|
| 1548 | + function status_changes_convert_questions($n = 50, $offset = 0) { |
|
| 1549 | 1549 | global $wpdb; |
| 1550 | 1550 | |
| 1551 | - wp_defer_comment_counting( true ); |
|
| 1551 | + wp_defer_comment_counting(true); |
|
| 1552 | 1552 | |
| 1553 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1553 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1554 | 1554 | |
| 1555 | - if ( 0 == $user_count_result ) { |
|
| 1555 | + if (0 == $user_count_result) { |
|
| 1556 | 1556 | return true; |
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | // Calculate if this is the last page |
| 1560 | - if ( 0 == $offset ) { |
|
| 1560 | + if (0 == $offset) { |
|
| 1561 | 1561 | $current_page = 1; |
| 1562 | 1562 | } else { |
| 1563 | - $current_page = intval( $offset / $n ); |
|
| 1563 | + $current_page = intval($offset / $n); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1566 | + $total_pages = ceil($user_count_result / $n); |
|
| 1567 | 1567 | |
| 1568 | 1568 | $users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d"; |
| 1569 | 1569 | $answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID "; |
| 1570 | 1570 | $grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID "; |
| 1571 | 1571 | $notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID "; |
| 1572 | 1572 | |
| 1573 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1573 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1574 | 1574 | |
| 1575 | - foreach ( $user_ids AS $user_id ) { |
|
| 1575 | + foreach ($user_ids AS $user_id) { |
|
| 1576 | 1576 | |
| 1577 | 1577 | $answer_grades = $answer_notes = array(); |
| 1578 | 1578 | |
| 1579 | 1579 | // Pre-process the answer grades |
| 1580 | - $_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A ); |
|
| 1581 | - foreach ( $_answer_grades as $answer_grade ) { |
|
| 1580 | + $_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A); |
|
| 1581 | + foreach ($_answer_grades as $answer_grade) { |
|
| 1582 | 1582 | // This will overwrite existing entries with the newer ones |
| 1583 | - $answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content']; |
|
| 1583 | + $answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content']; |
|
| 1584 | 1584 | } |
| 1585 | - unset( $_answer_grades ); |
|
| 1585 | + unset($_answer_grades); |
|
| 1586 | 1586 | |
| 1587 | 1587 | // Pre-process the answer notes |
| 1588 | - $_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A ); |
|
| 1589 | - foreach ( $_answer_notes as $answer_note ) { |
|
| 1588 | + $_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A); |
|
| 1589 | + foreach ($_answer_notes as $answer_note) { |
|
| 1590 | 1590 | // This will overwrite existing entries with the newer ones |
| 1591 | - $answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content']; |
|
| 1591 | + $answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content']; |
|
| 1592 | 1592 | } |
| 1593 | - unset( $_answer_notes ); |
|
| 1593 | + unset($_answer_notes); |
|
| 1594 | 1594 | |
| 1595 | 1595 | // Grab all the questions for the user |
| 1596 | 1596 | $sql = $wpdb->prepare($answers_sql, $user_id); |
| 1597 | - $answers = $wpdb->get_results( $sql, ARRAY_A ); |
|
| 1598 | - foreach ( $answers as $answer ) { |
|
| 1597 | + $answers = $wpdb->get_results($sql, ARRAY_A); |
|
| 1598 | + foreach ($answers as $answer) { |
|
| 1599 | 1599 | |
| 1600 | 1600 | // Excape data |
| 1601 | 1601 | $answer = wp_slash($answer); |
@@ -1605,12 +1605,12 @@ discard block |
||
| 1605 | 1605 | $meta_data = array(); |
| 1606 | 1606 | |
| 1607 | 1607 | // Check if the question has been graded, add as meta |
| 1608 | - if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) { |
|
| 1609 | - $meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ]; |
|
| 1608 | + if ( ! empty($answer_grades[$answer['comment_post_ID']])) { |
|
| 1609 | + $meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']]; |
|
| 1610 | 1610 | } |
| 1611 | 1611 | // Check if there is an answer note, add as meta |
| 1612 | - if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) { |
|
| 1613 | - $meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ]; |
|
| 1612 | + if ( ! empty($answer_notes[$answer['comment_post_ID']])) { |
|
| 1613 | + $meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']]; |
|
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | 1616 | // Wipe the unnessary data from the main comment |
@@ -1623,21 +1623,21 @@ discard block |
||
| 1623 | 1623 | ); |
| 1624 | 1624 | $data = array_merge($answer, $data); |
| 1625 | 1625 | |
| 1626 | - $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); |
|
| 1627 | - if ( $rval ) { |
|
| 1628 | - if ( !empty($meta_data) ) { |
|
| 1629 | - foreach ( $meta_data as $key => $value ) { |
|
| 1626 | + $rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID')); |
|
| 1627 | + if ($rval) { |
|
| 1628 | + if ( ! empty($meta_data)) { |
|
| 1629 | + foreach ($meta_data as $key => $value) { |
|
| 1630 | 1630 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1631 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1631 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1632 | 1632 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1633 | - $comment_ID, $key ) ) ) { |
|
| 1633 | + $comment_ID, $key ))) { |
|
| 1634 | 1634 | continue; // Found the meta data already |
| 1635 | 1635 | } |
| 1636 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1636 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1637 | 1637 | 'comment_id' => $comment_ID, |
| 1638 | 1638 | 'meta_key' => $key, |
| 1639 | 1639 | 'meta_value' => $value |
| 1640 | - ) ); |
|
| 1640 | + )); |
|
| 1641 | 1641 | } |
| 1642 | 1642 | } |
| 1643 | 1643 | } |
@@ -1645,7 +1645,7 @@ discard block |
||
| 1645 | 1645 | } |
| 1646 | 1646 | $wpdb->flush(); |
| 1647 | 1647 | |
| 1648 | - if ( $current_page == $total_pages ) { |
|
| 1648 | + if ($current_page == $total_pages) { |
|
| 1649 | 1649 | return true; |
| 1650 | 1650 | } else { |
| 1651 | 1651 | return false; |
@@ -1662,10 +1662,10 @@ discard block |
||
| 1662 | 1662 | global $wpdb; |
| 1663 | 1663 | |
| 1664 | 1664 | // Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts |
| 1665 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " ); |
|
| 1665 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' "); |
|
| 1666 | 1666 | |
| 1667 | 1667 | // Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required |
| 1668 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " ); |
|
| 1668 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') "); |
|
| 1669 | 1669 | |
| 1670 | 1670 | return true; |
| 1671 | 1671 | } |
@@ -1678,50 +1678,50 @@ discard block |
||
| 1678 | 1678 | * @param type $offset |
| 1679 | 1679 | * @return boolean |
| 1680 | 1680 | */ |
| 1681 | - public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) { |
|
| 1681 | + public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) { |
|
| 1682 | 1682 | global $wpdb; |
| 1683 | 1683 | |
| 1684 | - $item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " ); |
|
| 1684 | + $item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') "); |
|
| 1685 | 1685 | |
| 1686 | - if ( 0 == $item_count_result ) { |
|
| 1686 | + if (0 == $item_count_result) { |
|
| 1687 | 1687 | return true; |
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | 1690 | // Calculate if this is the last page |
| 1691 | - if ( 0 == $offset ) { |
|
| 1691 | + if (0 == $offset) { |
|
| 1692 | 1692 | $current_page = 1; |
| 1693 | 1693 | } else { |
| 1694 | - $current_page = intval( $offset / $n ); |
|
| 1694 | + $current_page = intval($offset / $n); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - $total_pages = ceil( $item_count_result / $n ); |
|
| 1697 | + $total_pages = ceil($item_count_result / $n); |
|
| 1698 | 1698 | |
| 1699 | 1699 | // Recalculate all counts |
| 1700 | - $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) ); |
|
| 1701 | - foreach ( (array) $items as $post ) { |
|
| 1700 | + $items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset)); |
|
| 1701 | + foreach ((array) $items as $post) { |
|
| 1702 | 1702 | // Code copied from wp_update_comment_count_now() |
| 1703 | - $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) ); |
|
| 1704 | - $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) ); |
|
| 1703 | + $new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID)); |
|
| 1704 | + $wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID)); |
|
| 1705 | 1705 | |
| 1706 | - clean_post_cache( $post->ID ); |
|
| 1706 | + clean_post_cache($post->ID); |
|
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | - if ( $current_page == $total_pages ) { |
|
| 1709 | + if ($current_page == $total_pages) { |
|
| 1710 | 1710 | return true; |
| 1711 | 1711 | } else { |
| 1712 | 1712 | return false; |
| 1713 | 1713 | } |
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | - public function remove_legacy_comments () { |
|
| 1716 | + public function remove_legacy_comments() { |
|
| 1717 | 1717 | global $wpdb; |
| 1718 | 1718 | |
| 1719 | - $result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) ); |
|
| 1719 | + $result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy')); |
|
| 1720 | 1720 | |
| 1721 | 1721 | return true; |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | - public function index_comment_status_field () { |
|
| 1724 | + public function index_comment_status_field() { |
|
| 1725 | 1725 | global $wpdb; |
| 1726 | 1726 | |
| 1727 | 1727 | $wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )"); |
@@ -1740,7 +1740,7 @@ discard block |
||
| 1740 | 1740 | * @since 1.8.0 |
| 1741 | 1741 | * @return bool; |
| 1742 | 1742 | */ |
| 1743 | - public function enhance_teacher_role ( ) { |
|
| 1743 | + public function enhance_teacher_role( ) { |
|
| 1744 | 1744 | |
| 1745 | 1745 | require_once('class-sensei-teacher.php'); |
| 1746 | 1746 | $teacher = new Sensei_Teacher(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Grading User Quiz Class |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * @since 1.3.0 |
| 23 | 23 | * @return void |
| 24 | 24 | */ |
| 25 | - public function __construct ( $user_id = 0, $quiz_id = 0 ) { |
|
| 26 | - $this->user_id = intval( $user_id ); |
|
| 27 | - $this->quiz_id = intval( $quiz_id ); |
|
| 28 | - $this->lesson_id = get_post_meta( $this->quiz_id, '_quiz_lesson', true ); |
|
| 25 | + public function __construct($user_id = 0, $quiz_id = 0) { |
|
| 26 | + $this->user_id = intval($user_id); |
|
| 27 | + $this->quiz_id = intval($quiz_id); |
|
| 28 | + $this->lesson_id = get_post_meta($this->quiz_id, '_quiz_lesson', true); |
|
| 29 | 29 | } // End __construct() |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @return array |
| 36 | 36 | */ |
| 37 | 37 | public function build_data_array() { |
| 38 | - $data_array = Sensei_Utils::sensei_get_quiz_questions( $this->quiz_id ); |
|
| 38 | + $data_array = Sensei_Utils::sensei_get_quiz_questions($this->quiz_id); |
|
| 39 | 39 | return $data_array; |
| 40 | 40 | } // End build_data_array() |
| 41 | 41 | |
@@ -60,94 +60,94 @@ discard block |
||
| 60 | 60 | $lesson_id = $this->lesson_id; |
| 61 | 61 | $user_id = $this->user_id; |
| 62 | 62 | |
| 63 | - ?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post"> |
|
| 64 | - <?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?> |
|
| 65 | - <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e( $this->quiz_id ); ?>" /> |
|
| 66 | - <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e( $this->user_id ); ?>" /> |
|
| 63 | + ?><form name="<?php esc_attr_e('quiz_'.$this->quiz_id); ?>" action="" method="post"> |
|
| 64 | + <?php wp_nonce_field('sensei_manual_grading', '_wp_sensei_manual_grading_nonce'); ?> |
|
| 65 | + <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e($this->quiz_id); ?>" /> |
|
| 66 | + <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e($this->user_id); ?>" /> |
|
| 67 | 67 | <div class="total_grade_display"> |
| 68 | - <span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span> |
|
| 68 | + <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span> |
|
| 69 | 69 | <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%) |
| 70 | 70 | </div> |
| 71 | 71 | <div class="buttons"> |
| 72 | - <input type="submit" value="<?php esc_attr_e( __( 'Save', 'woothemes-sensei' ) ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 73 | - <input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 74 | - <input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 72 | + <input type="submit" value="<?php esc_attr_e(__('Save', 'woothemes-sensei')); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 73 | + <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 74 | + <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 75 | 75 | </div> |
| 76 | 76 | <div class="clear"></div><br/><?php |
| 77 | 77 | |
| 78 | - $lesson_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID' ) ); |
|
| 79 | - $user_quiz_grade = get_comment_meta( $lesson_status_id, 'grade', true ); |
|
| 78 | + $lesson_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID')); |
|
| 79 | + $user_quiz_grade = get_comment_meta($lesson_status_id, 'grade', true); |
|
| 80 | 80 | $correct_answers = 0; |
| 81 | 81 | |
| 82 | - foreach( $questions as $question ) { |
|
| 82 | + foreach ($questions as $question) { |
|
| 83 | 83 | $question_id = $question->ID; |
| 84 | 84 | ++$count; |
| 85 | 85 | |
| 86 | 86 | $type = false; |
| 87 | 87 | $type_name = ''; |
| 88 | 88 | |
| 89 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 89 | + $type = Sensei()->question->get_question_type($question_id); |
|
| 90 | 90 | |
| 91 | - $question_answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $user_id ); |
|
| 91 | + $question_answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $user_id); |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - $question_grade_total = Sensei()->question->get_question_grade( $question_id ); |
|
| 94 | + $question_grade_total = Sensei()->question->get_question_grade($question_id); |
|
| 95 | 95 | $quiz_grade_total += $question_grade_total; |
| 96 | 96 | |
| 97 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 98 | - $user_answer_content = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id, $user_id ); |
|
| 99 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 97 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 98 | + $user_answer_content = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, $user_id); |
|
| 99 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 100 | 100 | $grade_type = 'manual-grade'; |
| 101 | 101 | |
| 102 | - switch( $type ) { |
|
| 102 | + switch ($type) { |
|
| 103 | 103 | case 'boolean': |
| 104 | - $type_name = __( 'True/False', 'woothemes-sensei' ); |
|
| 105 | - $right_answer = ucfirst( $right_answer ); |
|
| 106 | - $user_answer_content = ucfirst( $user_answer_content ); |
|
| 104 | + $type_name = __('True/False', 'woothemes-sensei'); |
|
| 105 | + $right_answer = ucfirst($right_answer); |
|
| 106 | + $user_answer_content = ucfirst($user_answer_content); |
|
| 107 | 107 | $grade_type = 'auto-grade'; |
| 108 | 108 | break; |
| 109 | 109 | case 'multiple-choice': |
| 110 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 110 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 111 | 111 | $grade_type = 'auto-grade'; |
| 112 | 112 | break; |
| 113 | 113 | case 'gap-fill': |
| 114 | - $type_name = __( 'Gap Fill', 'woothemes-sensei' ); |
|
| 114 | + $type_name = __('Gap Fill', 'woothemes-sensei'); |
|
| 115 | 115 | |
| 116 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 117 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 118 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 119 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 116 | + $right_answer_array = explode('||', $right_answer); |
|
| 117 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 118 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 119 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 120 | 120 | |
| 121 | - if( ! $user_answer_content ) { |
|
| 121 | + if ( ! $user_answer_content) { |
|
| 122 | 122 | $user_answer_content = '______'; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 126 | - $user_answer_content = $gapfill_pre . ' <span class="highlight">' . $user_answer_content . '</span> ' . $gapfill_post; |
|
| 125 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
| 126 | + $user_answer_content = $gapfill_pre.' <span class="highlight">'.$user_answer_content.'</span> '.$gapfill_post; |
|
| 127 | 127 | $grade_type = 'auto-grade'; |
| 128 | 128 | |
| 129 | 129 | break; |
| 130 | 130 | case 'multi-line': |
| 131 | - $type_name = __( 'Multi Line', 'woothemes-sensei' ); |
|
| 131 | + $type_name = __('Multi Line', 'woothemes-sensei'); |
|
| 132 | 132 | $grade_type = 'manual-grade'; |
| 133 | 133 | break; |
| 134 | 134 | case 'single-line': |
| 135 | - $type_name = __( 'Single Line', 'woothemes-sensei' ); |
|
| 135 | + $type_name = __('Single Line', 'woothemes-sensei'); |
|
| 136 | 136 | $grade_type = 'manual-grade'; |
| 137 | 137 | break; |
| 138 | 138 | case 'file-upload': |
| 139 | - $type_name = __( 'File Upload', 'woothemes-sensei' ); |
|
| 139 | + $type_name = __('File Upload', 'woothemes-sensei'); |
|
| 140 | 140 | $grade_type = 'manual-grade'; |
| 141 | 141 | |
| 142 | 142 | // Get uploaded file |
| 143 | - if( $user_answer_content ) { |
|
| 143 | + if ($user_answer_content) { |
|
| 144 | 144 | $attachment_id = $user_answer_content; |
| 145 | 145 | $answer_media_url = $answer_media_filename = ''; |
| 146 | - if( 0 < intval( $attachment_id ) ) { |
|
| 147 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 148 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 149 | - if( $answer_media_url && $answer_media_filename ) { |
|
| 150 | - $user_answer_content = sprintf( __( 'Submitted file: %1$s', 'woothemes-sensei' ), '<a href="' . esc_url( $answer_media_url ) . '" target="_blank">' . esc_html( $answer_media_filename ) . '</a>' ); |
|
| 146 | + if (0 < intval($attachment_id)) { |
|
| 147 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
| 148 | + $answer_media_filename = basename($answer_media_url); |
|
| 149 | + if ($answer_media_url && $answer_media_filename) { |
|
| 150 | + $user_answer_content = sprintf(__('Submitted file: %1$s', 'woothemes-sensei'), '<a href="'.esc_url($answer_media_url).'" target="_blank">'.esc_html($answer_media_filename).'</a>'); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | } else { |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | $user_answer_content = (array) $user_answer_content; |
| 162 | 162 | $right_answer = (array) $right_answer; |
| 163 | - $question_title = sprintf( __( 'Question %d: ', 'woothemes-sensei' ), $count ) . $type_name; |
|
| 163 | + $question_title = sprintf(__('Question %d: ', 'woothemes-sensei'), $count).$type_name; |
|
| 164 | 164 | |
| 165 | 165 | $graded_class = ''; |
| 166 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, $user_id ); |
|
| 166 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, $user_id); |
|
| 167 | 167 | $graded_class = 'ungraded'; |
| 168 | - if ( 0 == $question_grade_total && 0 == intval( $user_question_grade ) ) { |
|
| 168 | + if (0 == $question_grade_total && 0 == intval($user_question_grade)) { |
|
| 169 | 169 | // Question skips grading |
| 170 | 170 | $grade_type = 'zero-graded'; |
| 171 | 171 | $graded_class = ''; |
@@ -173,86 +173,86 @@ discard block |
||
| 173 | 173 | ++$graded_count; |
| 174 | 174 | $user_question_grade = 0; |
| 175 | 175 | } |
| 176 | - elseif( intval( $user_question_grade ) > 0 ) { |
|
| 176 | + elseif (intval($user_question_grade) > 0) { |
|
| 177 | 177 | $graded_class = 'user_right'; |
| 178 | 178 | ++$correct_answers; |
| 179 | 179 | $user_quiz_grade_total += $user_question_grade; |
| 180 | 180 | ++$graded_count; |
| 181 | 181 | } else { |
| 182 | - if( ! is_string( $user_question_grade ) && intval( $user_question_grade ) == 0 ) { |
|
| 182 | + if ( ! is_string($user_question_grade) && intval($user_question_grade) == 0) { |
|
| 183 | 183 | $graded_class = 'user_wrong'; |
| 184 | 184 | ++$graded_count; |
| 185 | 185 | } |
| 186 | 186 | $user_question_grade = 0; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - ?><div class="postbox question_box <?php esc_attr_e( $type ); ?> <?php esc_attr_e( $grade_type ); ?> <?php esc_attr_e( $graded_class ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_box' ); ?>"> |
|
| 189 | + ?><div class="postbox question_box <?php esc_attr_e($type); ?> <?php esc_attr_e($grade_type); ?> <?php esc_attr_e($graded_class); ?>" id="<?php esc_attr_e('question_'.$question_id.'_box'); ?>"> |
|
| 190 | 190 | <div class="handlediv" title="Click to toggle"><br></div> |
| 191 | 191 | <h3 class="hndle"><span><?php echo $question_title; ?></span></h3> |
| 192 | 192 | <div class="inside"> |
| 193 | 193 | <div class="sensei-grading-actions"> |
| 194 | 194 | <div class="actions"> |
| 195 | - <input type="hidden" class="question_id" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
| 196 | - <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr( $question_grade_total ); ?>" /> |
|
| 197 | - <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_right_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="right" <?php checked( $graded_class, 'user_right', true ); ?> /></span> |
|
| 198 | - <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_wrong_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="wrong" <?php checked( $graded_class, 'user_wrong', true ); ?> /></span> |
|
| 199 | - <input type="number" class="question-grade" name="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" value="<?php echo esc_attr( $user_question_grade ); ?>" min="0" max="<?php echo esc_attr( $question_grade_total ); ?>" /> |
|
| 195 | + <input type="hidden" class="question_id" value="<?php esc_attr_e($question_id); ?>" /> |
|
| 196 | + <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr($question_grade_total); ?>" /> |
|
| 197 | + <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_right_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="right" <?php checked($graded_class, 'user_right', true); ?> /></span> |
|
| 198 | + <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_wrong_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="wrong" <?php checked($graded_class, 'user_wrong', true); ?> /></span> |
|
| 199 | + <input type="number" class="question-grade" name="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" id="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" value="<?php echo esc_attr($user_question_grade); ?>" min="0" max="<?php echo esc_attr($question_grade_total); ?>" /> |
|
| 200 | 200 | <span class="question-grade-total"><?php echo $question_grade_total; ?></span> |
| 201 | 201 | </div> |
| 202 | 202 | </div> |
| 203 | 203 | <div class="sensei-grading-answer"> |
| 204 | - <h4><?php echo apply_filters( 'sensei_question_title', $question->post_title ); ?></h4> |
|
| 205 | - <?php echo apply_filters( 'the_content', $question->post_content );?> |
|
| 204 | + <h4><?php echo apply_filters('sensei_question_title', $question->post_title); ?></h4> |
|
| 205 | + <?php echo apply_filters('the_content', $question->post_content); ?> |
|
| 206 | 206 | <p class="user-answer"><?php |
| 207 | - foreach ( $user_answer_content as $_user_answer ) { |
|
| 207 | + foreach ($user_answer_content as $_user_answer) { |
|
| 208 | 208 | |
| 209 | - if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
| 209 | + if ('multi-line' == Sensei()->question->get_question_type($question->ID)) { |
|
| 210 | 210 | |
| 211 | - $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
| 211 | + $_user_answer = htmlspecialchars_decode(nl2br(esc_html($_user_answer))); |
|
| 212 | 212 | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>"; |
|
| 215 | + echo apply_filters('sensei_answer_text', $_user_answer)."<br>"; |
|
| 216 | 216 | } |
| 217 | 217 | ?></p> |
| 218 | 218 | <div class="right-answer"> |
| 219 | - <h5><?php _e( 'Correct answer', 'woothemes-sensei' ) ?></h5> |
|
| 219 | + <h5><?php _e('Correct answer', 'woothemes-sensei') ?></h5> |
|
| 220 | 220 | <span class="correct-answer"><?php |
| 221 | - foreach ( $right_answer as $_right_answer ) { |
|
| 221 | + foreach ($right_answer as $_right_answer) { |
|
| 222 | 222 | |
| 223 | - echo apply_filters( 'sensei_answer_text', $_right_answer ) . "<br>"; |
|
| 223 | + echo apply_filters('sensei_answer_text', $_right_answer)."<br>"; |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | ?></span> |
| 227 | 227 | </div> |
| 228 | 228 | <div class="answer-notes"> |
| 229 | - <h5><?php _e( 'Grading Notes', 'woothemes-sensei' ) ?></h5> |
|
| 230 | - <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e( $question_id ); ?>]" placeholder="<?php _e( 'Add notes here...', 'woothemes-sensei' ) ?>"><?php echo $question_answer_notes; ?></textarea> |
|
| 229 | + <h5><?php _e('Grading Notes', 'woothemes-sensei') ?></h5> |
|
| 230 | + <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e($question_id); ?>]" placeholder="<?php _e('Add notes here...', 'woothemes-sensei') ?>"><?php echo $question_answer_notes; ?></textarea> |
|
| 231 | 231 | </div> |
| 232 | 232 | </div> |
| 233 | 233 | </div> |
| 234 | 234 | </div><?php |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $quiz_grade = intval( $user_quiz_grade ); |
|
| 237 | + $quiz_grade = intval($user_quiz_grade); |
|
| 238 | 238 | $all_graded = 'no'; |
| 239 | - if( intval( $count ) == intval( $graded_count ) ) { |
|
| 239 | + if (intval($count) == intval($graded_count)) { |
|
| 240 | 240 | $all_graded = 'yes'; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e( $user_quiz_grade_total ); ?>" /> |
|
| 244 | - <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e( $count ); ?>" /> |
|
| 245 | - <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e( $quiz_grade_total ); ?>" /> |
|
| 246 | - <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e( $graded_count ); ?>" /> |
|
| 247 | - <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e( $all_graded ); ?>" /> |
|
| 243 | + ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e($user_quiz_grade_total); ?>" /> |
|
| 244 | + <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e($count); ?>" /> |
|
| 245 | + <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e($quiz_grade_total); ?>" /> |
|
| 246 | + <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e($graded_count); ?>" /> |
|
| 247 | + <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e($all_graded); ?>" /> |
|
| 248 | 248 | <div class="total_grade_display"> |
| 249 | - <span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span> |
|
| 249 | + <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span> |
|
| 250 | 250 | <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%) |
| 251 | 251 | </div> |
| 252 | 252 | <div class="buttons"> |
| 253 | - <input type="submit" value="<?php esc_attr_e( 'Save' ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 254 | - <input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 255 | - <input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 253 | + <input type="submit" value="<?php esc_attr_e('Save'); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 254 | + <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 255 | + <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 256 | 256 | </div> |
| 257 | 257 | <div class="clear"></div> |
| 258 | 258 | <script type="text/javascript"> |
@@ -271,4 +271,4 @@ discard block |
||
| 271 | 271 | * for backward compatibility |
| 272 | 272 | * @since 1.9.0 |
| 273 | 273 | */ |
| 274 | -class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz{} |
|
| 274 | +class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz {} |
|
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Analysis Course List Table Class |
@@ -25,27 +25,27 @@ discard block |
||
| 25 | 25 | * @since 1.2.0 |
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | - public function __construct ( $course_id = 0, $user_id = 0 ) { |
|
| 29 | - $this->course_id = intval( $course_id ); |
|
| 30 | - $this->user_id = intval( $user_id ); |
|
| 28 | + public function __construct($course_id = 0, $user_id = 0) { |
|
| 29 | + $this->course_id = intval($course_id); |
|
| 30 | + $this->user_id = intval($user_id); |
|
| 31 | 31 | |
| 32 | - if( isset( $_GET['view'] ) && in_array( $_GET['view'], array( 'user', 'lesson' ) ) ) { |
|
| 32 | + if (isset($_GET['view']) && in_array($_GET['view'], array('user', 'lesson'))) { |
|
| 33 | 33 | $this->view = $_GET['view']; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // Viewing a single Learner always sets the view to Lessons |
| 37 | - if( $this->user_id ) { |
|
| 37 | + if ($this->user_id) { |
|
| 38 | 38 | $this->view = 'lesson'; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // Load Parent token into constructor |
| 42 | - parent::__construct( 'analysis_course' ); |
|
| 42 | + parent::__construct('analysis_course'); |
|
| 43 | 43 | |
| 44 | 44 | // Actions |
| 45 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
| 46 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
| 45 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
| 46 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
| 47 | 47 | |
| 48 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
| 48 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
| 49 | 49 | |
| 50 | 50 | } // End __construct() |
| 51 | 51 | |
@@ -56,45 +56,45 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function get_columns() { |
| 58 | 58 | |
| 59 | - switch( $this->view ) { |
|
| 59 | + switch ($this->view) { |
|
| 60 | 60 | case 'user' : |
| 61 | 61 | $columns = array( |
| 62 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
| 63 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
| 64 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
| 65 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
| 66 | - 'percent' => __( 'Percent Complete', 'woothemes-sensei' ), |
|
| 62 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
| 63 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
| 64 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
| 65 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
| 66 | + 'percent' => __('Percent Complete', 'woothemes-sensei'), |
|
| 67 | 67 | ); |
| 68 | 68 | break; |
| 69 | 69 | |
| 70 | 70 | case 'lesson' : |
| 71 | 71 | default: |
| 72 | - if ( $this->user_id ) { |
|
| 72 | + if ($this->user_id) { |
|
| 73 | 73 | |
| 74 | 74 | $columns = array( |
| 75 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
| 76 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
| 77 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
| 78 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
| 79 | - 'grade' => __( 'Grade', 'woothemes-sensei' ), |
|
| 75 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
| 76 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
| 77 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
| 78 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
| 79 | + 'grade' => __('Grade', 'woothemes-sensei'), |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | } else { |
| 83 | 83 | |
| 84 | 84 | $columns = array( |
| 85 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
| 86 | - 'num_learners' => __( 'Learners', 'woothemes-sensei' ), |
|
| 87 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
| 88 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
| 85 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
| 86 | + 'num_learners' => __('Learners', 'woothemes-sensei'), |
|
| 87 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
| 88 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | break; |
| 93 | 93 | } |
| 94 | 94 | // Backwards compatible |
| 95 | - $columns = apply_filters( 'sensei_analysis_course_' . $this->view . '_columns', $columns, $this ); |
|
| 95 | + $columns = apply_filters('sensei_analysis_course_'.$this->view.'_columns', $columns, $this); |
|
| 96 | 96 | // Moving forward, single filter with args |
| 97 | - $columns = apply_filters( 'sensei_analysis_course_columns', $columns, $this ); |
|
| 97 | + $columns = apply_filters('sensei_analysis_course_columns', $columns, $this); |
|
| 98 | 98 | return $columns; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -105,46 +105,46 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | function get_sortable_columns() { |
| 107 | 107 | |
| 108 | - switch( $this->view ) { |
|
| 108 | + switch ($this->view) { |
|
| 109 | 109 | case 'user' : |
| 110 | 110 | $columns = array( |
| 111 | - 'title' => array( 'title', false ), |
|
| 112 | - 'started' => array( 'started', false ), |
|
| 113 | - 'completed' => array( 'completed', false ), |
|
| 114 | - 'user_status' => array( 'user_status', false ), |
|
| 111 | + 'title' => array('title', false), |
|
| 112 | + 'started' => array('started', false), |
|
| 113 | + 'completed' => array('completed', false), |
|
| 114 | + 'user_status' => array('user_status', false), |
|
| 115 | 115 | // 'grade' => array( 'grade', false ), |
| 116 | - 'percent' => array( 'percent', false ) |
|
| 116 | + 'percent' => array('percent', false) |
|
| 117 | 117 | ); |
| 118 | 118 | break; |
| 119 | 119 | |
| 120 | 120 | case 'lesson' : |
| 121 | 121 | default: |
| 122 | - if ( $this->user_id ) { |
|
| 122 | + if ($this->user_id) { |
|
| 123 | 123 | |
| 124 | 124 | $columns = array( |
| 125 | - 'title' => array( 'title', false ), |
|
| 126 | - 'started' => array( 'started', false ), |
|
| 127 | - 'completed' => array( 'completed', false ), |
|
| 128 | - 'user_status' => array( 'user_status', false ), |
|
| 129 | - 'grade' => array( 'grade', false ), |
|
| 125 | + 'title' => array('title', false), |
|
| 126 | + 'started' => array('started', false), |
|
| 127 | + 'completed' => array('completed', false), |
|
| 128 | + 'user_status' => array('user_status', false), |
|
| 129 | + 'grade' => array('grade', false), |
|
| 130 | 130 | ); |
| 131 | 131 | |
| 132 | 132 | } else { |
| 133 | 133 | |
| 134 | 134 | $columns = array( |
| 135 | - 'title' => array( 'title', false ), |
|
| 136 | - 'num_learners' => array( 'num_learners', false ), |
|
| 137 | - 'completions' => array( 'completions', false ), |
|
| 138 | - 'average_grade' => array( 'average_grade', false ) |
|
| 135 | + 'title' => array('title', false), |
|
| 136 | + 'num_learners' => array('num_learners', false), |
|
| 137 | + 'completions' => array('completions', false), |
|
| 138 | + 'average_grade' => array('average_grade', false) |
|
| 139 | 139 | ); |
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | break; |
| 143 | 143 | } |
| 144 | 144 | // Backwards compatible |
| 145 | - $columns = apply_filters( 'sensei_analysis_course_' . $this->view . '_columns_sortable', $columns, $this ); |
|
| 145 | + $columns = apply_filters('sensei_analysis_course_'.$this->view.'_columns_sortable', $columns, $this); |
|
| 146 | 146 | // Moving forward, single filter with args |
| 147 | - $columns = apply_filters( 'sensei_analysis_course_columns_sortable', $columns, $this ); |
|
| 147 | + $columns = apply_filters('sensei_analysis_course_columns_sortable', $columns, $this); |
|
| 148 | 148 | return $columns; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -158,32 +158,32 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | // Handle orderby (needs work) |
| 160 | 160 | $orderby = ''; |
| 161 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 162 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 163 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 161 | + if ( ! empty($_GET['orderby'])) { |
|
| 162 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 163 | + $orderby = esc_html($_GET['orderby']); |
|
| 164 | 164 | } // End If Statement |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Handle order |
| 168 | 168 | $order = 'ASC'; |
| 169 | - if ( !empty( $_GET['order'] ) ) { |
|
| 170 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 169 | + if ( ! empty($_GET['order'])) { |
|
| 170 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Handle search, need 4.1 version of WP to be able to restrict statuses to known post_ids |
| 174 | 174 | $search = false; |
| 175 | - if ( !empty( $_GET['s'] ) ) { |
|
| 176 | - $search = esc_html( $_GET['s'] ); |
|
| 175 | + if ( ! empty($_GET['s'])) { |
|
| 176 | + $search = esc_html($_GET['s']); |
|
| 177 | 177 | } // End If Statement |
| 178 | 178 | $this->search = $search; |
| 179 | 179 | |
| 180 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
| 181 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
| 180 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
| 181 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
| 182 | 182 | |
| 183 | 183 | $paged = $this->get_pagenum(); |
| 184 | 184 | $offset = 0; |
| 185 | - if ( !empty($paged) ) { |
|
| 186 | - $offset = $per_page * ( $paged - 1 ); |
|
| 185 | + if ( ! empty($paged)) { |
|
| 186 | + $offset = $per_page * ($paged - 1); |
|
| 187 | 187 | } // End If Statement |
| 188 | 188 | |
| 189 | 189 | $args = array( |
@@ -192,28 +192,28 @@ discard block |
||
| 192 | 192 | 'orderby' => $orderby, |
| 193 | 193 | 'order' => $order, |
| 194 | 194 | ); |
| 195 | - if ( $this->search ) { |
|
| 195 | + if ($this->search) { |
|
| 196 | 196 | $args['search'] = $this->search; |
| 197 | 197 | } // End If Statement |
| 198 | 198 | |
| 199 | - switch( $this->view ) { |
|
| 199 | + switch ($this->view) { |
|
| 200 | 200 | case 'user' : |
| 201 | - $this->items = $this->get_course_statuses( $args ); |
|
| 201 | + $this->items = $this->get_course_statuses($args); |
|
| 202 | 202 | break; |
| 203 | 203 | |
| 204 | 204 | case 'lesson': |
| 205 | 205 | default: |
| 206 | - $this->items = $this->get_lessons( $args ); |
|
| 206 | + $this->items = $this->get_lessons($args); |
|
| 207 | 207 | break; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | $total_items = $this->total_items; |
| 211 | - $total_pages = ceil( $total_items / $per_page ); |
|
| 212 | - $this->set_pagination_args( array( |
|
| 211 | + $total_pages = ceil($total_items / $per_page); |
|
| 212 | + $this->set_pagination_args(array( |
|
| 213 | 213 | 'total_items' => $total_items, |
| 214 | 214 | 'total_pages' => $total_pages, |
| 215 | 215 | 'per_page' => $per_page |
| 216 | - ) ); |
|
| 216 | + )); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @since 1.7.0 |
| 222 | 222 | * @return data |
| 223 | 223 | */ |
| 224 | - public function generate_report( $report ) { |
|
| 224 | + public function generate_report($report) { |
|
| 225 | 225 | |
| 226 | 226 | $data = array(); |
| 227 | 227 | |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | // Handle orderby |
| 231 | 231 | $orderby = ''; |
| 232 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 233 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 234 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 232 | + if ( ! empty($_GET['orderby'])) { |
|
| 233 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 234 | + $orderby = esc_html($_GET['orderby']); |
|
| 235 | 235 | } // End If Statement |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // Handle order |
| 239 | 239 | $order = 'ASC'; |
| 240 | - if ( !empty( $_GET['order'] ) ) { |
|
| 241 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 240 | + if ( ! empty($_GET['order'])) { |
|
| 241 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Handle search |
| 245 | 245 | $search = false; |
| 246 | - if ( !empty( $_GET['s'] ) ) { |
|
| 247 | - $search = esc_html( $_GET['s'] ); |
|
| 246 | + if ( ! empty($_GET['s'])) { |
|
| 247 | + $search = esc_html($_GET['s']); |
|
| 248 | 248 | } // End If Statement |
| 249 | 249 | $this->search = $search; |
| 250 | 250 | |
@@ -252,32 +252,32 @@ discard block |
||
| 252 | 252 | 'orderby' => $orderby, |
| 253 | 253 | 'order' => $order, |
| 254 | 254 | ); |
| 255 | - if ( $this->search ) { |
|
| 255 | + if ($this->search) { |
|
| 256 | 256 | $args['search'] = $this->search; |
| 257 | 257 | } // End If Statement |
| 258 | 258 | |
| 259 | 259 | // Start the csv with the column headings |
| 260 | 260 | $column_headers = array(); |
| 261 | 261 | $columns = $this->get_columns(); |
| 262 | - foreach( $columns AS $key => $title ) { |
|
| 262 | + foreach ($columns AS $key => $title) { |
|
| 263 | 263 | $column_headers[] = $title; |
| 264 | 264 | } |
| 265 | 265 | $data[] = $column_headers; |
| 266 | 266 | |
| 267 | - switch( $this->view ) { |
|
| 267 | + switch ($this->view) { |
|
| 268 | 268 | case 'user' : |
| 269 | - $this->items = $this->get_course_statuses( $args ); |
|
| 269 | + $this->items = $this->get_course_statuses($args); |
|
| 270 | 270 | break; |
| 271 | 271 | |
| 272 | 272 | case 'lesson': |
| 273 | 273 | default: |
| 274 | - $this->items = $this->get_lessons( $args ); |
|
| 274 | + $this->items = $this->get_lessons($args); |
|
| 275 | 275 | break; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Process each row |
| 279 | - foreach( $this->items AS $item) { |
|
| 280 | - $data[] = $this->get_row_data( $item ); |
|
| 279 | + foreach ($this->items AS $item) { |
|
| 280 | + $data[] = $this->get_row_data($item); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | return $data; |
@@ -289,37 +289,37 @@ discard block |
||
| 289 | 289 | * @since 1.7.0 |
| 290 | 290 | * @param object $item The current item |
| 291 | 291 | */ |
| 292 | - protected function get_row_data( $item ) { |
|
| 292 | + protected function get_row_data($item) { |
|
| 293 | 293 | |
| 294 | - switch( $this->view ) { |
|
| 294 | + switch ($this->view) { |
|
| 295 | 295 | case 'user' : |
| 296 | - $user_start_date = get_comment_meta( $item->comment_ID, 'start', true ); |
|
| 296 | + $user_start_date = get_comment_meta($item->comment_ID, 'start', true); |
|
| 297 | 297 | $user_end_date = $item->comment_date; |
| 298 | 298 | |
| 299 | - if( 'complete' == $item->comment_approved ) { |
|
| 299 | + if ('complete' == $item->comment_approved) { |
|
| 300 | 300 | |
| 301 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
| 301 | + $status = __('Completed', 'woothemes-sensei'); |
|
| 302 | 302 | $status_class = 'graded'; |
| 303 | 303 | |
| 304 | 304 | } else { |
| 305 | 305 | |
| 306 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
| 306 | + $status = __('In Progress', 'woothemes-sensei'); |
|
| 307 | 307 | $status_class = 'in-progress'; |
| 308 | 308 | $user_end_date = ''; |
| 309 | 309 | |
| 310 | 310 | } |
| 311 | - $course_percent = get_comment_meta( $item->comment_ID, 'percent', true ); |
|
| 311 | + $course_percent = get_comment_meta($item->comment_ID, 'percent', true); |
|
| 312 | 312 | |
| 313 | 313 | // Output users data |
| 314 | - $user_name = Sensei()->learners->get_learner_full_name( $item->user_id ); |
|
| 314 | + $user_name = Sensei()->learners->get_learner_full_name($item->user_id); |
|
| 315 | 315 | |
| 316 | - if ( !$this->csv_output ) { |
|
| 316 | + if ( ! $this->csv_output) { |
|
| 317 | 317 | |
| 318 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) ); |
|
| 318 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id), admin_url('admin.php')); |
|
| 319 | 319 | |
| 320 | - $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $user_name . '</a></strong>'; |
|
| 321 | - $status = sprintf( '<span class="%s">%s</span>', $status_class, $status ); |
|
| 322 | - if ( is_numeric($course_percent) ) { |
|
| 320 | + $user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$user_name.'</a></strong>'; |
|
| 321 | + $status = sprintf('<span class="%s">%s</span>', $status_class, $status); |
|
| 322 | + if (is_numeric($course_percent)) { |
|
| 323 | 323 | |
| 324 | 324 | $course_percent .= '%'; |
| 325 | 325 | |
@@ -327,19 +327,19 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | } // End If Statement |
| 329 | 329 | |
| 330 | - $column_data = apply_filters( 'sensei_analysis_course_column_data', array( 'title' => $user_name, |
|
| 330 | + $column_data = apply_filters('sensei_analysis_course_column_data', array('title' => $user_name, |
|
| 331 | 331 | 'started' => $user_start_date, |
| 332 | 332 | 'completed' => $user_end_date, |
| 333 | 333 | 'user_status' => $status, |
| 334 | 334 | 'percent' => $course_percent, |
| 335 | - ), $item, $this ); |
|
| 335 | + ), $item, $this); |
|
| 336 | 336 | break; |
| 337 | 337 | |
| 338 | 338 | case 'lesson': |
| 339 | 339 | default: |
| 340 | 340 | // Displaying lessons for this Course for a specific User |
| 341 | - if ( $this->user_id ) { |
|
| 342 | - $status = __( 'Not started', 'woothemes-sensei' ); |
|
| 341 | + if ($this->user_id) { |
|
| 342 | + $status = __('Not started', 'woothemes-sensei'); |
|
| 343 | 343 | $user_start_date = $user_end_date = $status_class = $grade = ''; |
| 344 | 344 | |
| 345 | 345 | $lesson_args = array( |
@@ -348,66 +348,66 @@ discard block |
||
| 348 | 348 | 'type' => 'sensei_lesson_status', |
| 349 | 349 | 'status' => 'any', |
| 350 | 350 | ); |
| 351 | - $lesson_status = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_user_lesson', $lesson_args, $item, $this->user_id ), true ); |
|
| 351 | + $lesson_status = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_user_lesson', $lesson_args, $item, $this->user_id), true); |
|
| 352 | 352 | |
| 353 | - if ( !empty($lesson_status) ) { |
|
| 354 | - $user_start_date = get_comment_meta( $lesson_status->comment_ID, 'start', true ); |
|
| 353 | + if ( ! empty($lesson_status)) { |
|
| 354 | + $user_start_date = get_comment_meta($lesson_status->comment_ID, 'start', true); |
|
| 355 | 355 | $user_end_date = $lesson_status->comment_date; |
| 356 | 356 | |
| 357 | - if( 'complete' == $lesson_status->comment_approved ) { |
|
| 358 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
| 357 | + if ('complete' == $lesson_status->comment_approved) { |
|
| 358 | + $status = __('Completed', 'woothemes-sensei'); |
|
| 359 | 359 | $status_class = 'graded'; |
| 360 | 360 | |
| 361 | - $grade = __( 'No Grade', 'woothemes-sensei' ); |
|
| 361 | + $grade = __('No Grade', 'woothemes-sensei'); |
|
| 362 | 362 | } |
| 363 | - elseif( 'graded' == $lesson_status->comment_approved ) { |
|
| 364 | - $status = __( 'Graded', 'woothemes-sensei' ); |
|
| 363 | + elseif ('graded' == $lesson_status->comment_approved) { |
|
| 364 | + $status = __('Graded', 'woothemes-sensei'); |
|
| 365 | 365 | $status_class = 'graded'; |
| 366 | 366 | |
| 367 | - $grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true); |
|
| 367 | + $grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
| 368 | 368 | } |
| 369 | - elseif( 'passed' == $lesson_status->comment_approved ) { |
|
| 370 | - $status = __( 'Passed', 'woothemes-sensei' ); |
|
| 369 | + elseif ('passed' == $lesson_status->comment_approved) { |
|
| 370 | + $status = __('Passed', 'woothemes-sensei'); |
|
| 371 | 371 | $status_class = 'graded'; |
| 372 | 372 | |
| 373 | - $grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true); |
|
| 373 | + $grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
| 374 | 374 | } |
| 375 | - elseif( 'failed' == $lesson_status->comment_approved ) { |
|
| 376 | - $status = __( 'Failed', 'woothemes-sensei' ); |
|
| 375 | + elseif ('failed' == $lesson_status->comment_approved) { |
|
| 376 | + $status = __('Failed', 'woothemes-sensei'); |
|
| 377 | 377 | $status_class = 'failed'; |
| 378 | 378 | |
| 379 | - $grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true); |
|
| 379 | + $grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
| 380 | 380 | } |
| 381 | - elseif( 'ungraded' == $lesson_status->comment_approved ) { |
|
| 382 | - $status = __( 'Ungraded', 'woothemes-sensei' ); |
|
| 381 | + elseif ('ungraded' == $lesson_status->comment_approved) { |
|
| 382 | + $status = __('Ungraded', 'woothemes-sensei'); |
|
| 383 | 383 | $status_class = 'ungraded'; |
| 384 | 384 | |
| 385 | 385 | } |
| 386 | - elseif( 'in-progress' == $lesson_status->comment_approved ) { |
|
| 387 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
| 386 | + elseif ('in-progress' == $lesson_status->comment_approved) { |
|
| 387 | + $status = __('In Progress', 'woothemes-sensei'); |
|
| 388 | 388 | $user_end_date = ''; |
| 389 | 389 | } |
| 390 | 390 | } // END lesson_status |
| 391 | 391 | |
| 392 | 392 | // Output users data |
| 393 | - if ( $this->csv_output ) { |
|
| 394 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
| 393 | + if ($this->csv_output) { |
|
| 394 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
| 395 | 395 | } |
| 396 | 396 | else { |
| 397 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
| 398 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
| 397 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
| 398 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
| 399 | 399 | |
| 400 | - $status = sprintf( '<span class="%s">%s</span>', $status_class, $status ); |
|
| 401 | - if ( is_numeric($grade) ) { |
|
| 400 | + $status = sprintf('<span class="%s">%s</span>', $status_class, $status); |
|
| 401 | + if (is_numeric($grade)) { |
|
| 402 | 402 | $grade .= '%'; |
| 403 | 403 | } |
| 404 | 404 | } // End If Statement |
| 405 | - $column_data = apply_filters( 'sensei_analysis_course_column_data', array( 'title' => $lesson_title, |
|
| 405 | + $column_data = apply_filters('sensei_analysis_course_column_data', array('title' => $lesson_title, |
|
| 406 | 406 | 'started' => $user_start_date, |
| 407 | 407 | 'completed' => $user_end_date, |
| 408 | 408 | 'user_status' => $status, |
| 409 | 409 | 'grade' => $grade, |
| 410 | - ), $item, $this ); |
|
| 410 | + ), $item, $this); |
|
| 411 | 411 | } |
| 412 | 412 | // Display lessons for this Course regardless of users |
| 413 | 413 | else { |
@@ -417,51 +417,51 @@ discard block |
||
| 417 | 417 | 'type' => 'sensei_lesson_status', |
| 418 | 418 | 'status' => 'any', |
| 419 | 419 | ); |
| 420 | - $lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) ); |
|
| 420 | + $lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item)); |
|
| 421 | 421 | |
| 422 | 422 | // Get Course Completions |
| 423 | 423 | $lesson_args = array( |
| 424 | 424 | 'post_id' => $item->ID, |
| 425 | 425 | 'type' => 'sensei_lesson_status', |
| 426 | - 'status' => array( 'complete', 'graded', 'passed', 'failed' ), |
|
| 426 | + 'status' => array('complete', 'graded', 'passed', 'failed'), |
|
| 427 | 427 | 'count' => true, |
| 428 | 428 | ); |
| 429 | - $lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) ); |
|
| 429 | + $lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item)); |
|
| 430 | 430 | |
| 431 | 431 | $lesson_average_grade = __('n/a', 'woothemes-sensei'); |
| 432 | - if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) { |
|
| 432 | + if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
| 433 | 433 | // Get Percent Complete |
| 434 | 434 | $grade_args = array( |
| 435 | 435 | 'post_id' => $item->ID, |
| 436 | 436 | 'type' => 'sensei_lesson_status', |
| 437 | - 'status' => array( 'graded', 'passed', 'failed' ), |
|
| 437 | + 'status' => array('graded', 'passed', 'failed'), |
|
| 438 | 438 | 'meta_key' => 'grade', |
| 439 | 439 | ); |
| 440 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 441 | - $lesson_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ); |
|
| 442 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 440 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 441 | + $lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true); |
|
| 442 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 443 | 443 | |
| 444 | - $grade_count = !empty( $lesson_grades->total ) ? $lesson_grades->total : 1; |
|
| 445 | - $grade_total = !empty( $lesson_grades->meta_sum ) ? doubleval( $lesson_grades->meta_sum ) : 0; |
|
| 446 | - $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 444 | + $grade_count = ! empty($lesson_grades->total) ? $lesson_grades->total : 1; |
|
| 445 | + $grade_total = ! empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0; |
|
| 446 | + $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
| 447 | 447 | } |
| 448 | 448 | // Output lesson data |
| 449 | - if ( $this->csv_output ) { |
|
| 450 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
| 449 | + if ($this->csv_output) { |
|
| 450 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
| 451 | 451 | } |
| 452 | 452 | else { |
| 453 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
| 454 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
| 453 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
| 454 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
| 455 | 455 | |
| 456 | - if ( is_numeric( $lesson_average_grade ) ) { |
|
| 456 | + if (is_numeric($lesson_average_grade)) { |
|
| 457 | 457 | $lesson_average_grade .= '%'; |
| 458 | 458 | } |
| 459 | 459 | } // End If Statement |
| 460 | - $column_data = apply_filters( 'sensei_analysis_course_column_data', array( 'title' => $lesson_title, |
|
| 460 | + $column_data = apply_filters('sensei_analysis_course_column_data', array('title' => $lesson_title, |
|
| 461 | 461 | 'num_learners' => $lesson_students, |
| 462 | 462 | 'completions' => $lesson_completions, |
| 463 | 463 | 'average_grade' => $lesson_average_grade, |
| 464 | - ), $item, $this ); |
|
| 464 | + ), $item, $this); |
|
| 465 | 465 | } // END if |
| 466 | 466 | break; |
| 467 | 467 | } // END switch |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | * @since 1.7.0 |
| 475 | 475 | * @return array statuses |
| 476 | 476 | */ |
| 477 | - private function get_course_statuses( $args ) { |
|
| 477 | + private function get_course_statuses($args) { |
|
| 478 | 478 | |
| 479 | 479 | $activity_args = array( |
| 480 | 480 | 'post_id' => $this->course_id, |
@@ -487,34 +487,34 @@ discard block |
||
| 487 | 487 | ); |
| 488 | 488 | |
| 489 | 489 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
| 490 | - if ( $this->search ) { |
|
| 490 | + if ($this->search) { |
|
| 491 | 491 | $user_args = array( |
| 492 | - 'search' => '*' . $this->search . '*', |
|
| 492 | + 'search' => '*'.$this->search.'*', |
|
| 493 | 493 | 'fields' => 'ID', |
| 494 | 494 | ); |
| 495 | 495 | // Filter for extending |
| 496 | - $user_args = apply_filters( 'sensei_analysis_course_search_users', $user_args ); |
|
| 497 | - if ( !empty( $user_args ) ) { |
|
| 498 | - $learners_search = new WP_User_Query( $user_args ); |
|
| 496 | + $user_args = apply_filters('sensei_analysis_course_search_users', $user_args); |
|
| 497 | + if ( ! empty($user_args)) { |
|
| 498 | + $learners_search = new WP_User_Query($user_args); |
|
| 499 | 499 | // Store for reuse on counts |
| 500 | 500 | $activity_args['user_id'] = (array) $learners_search->get_results(); |
| 501 | 501 | } |
| 502 | 502 | } // End If Statement |
| 503 | 503 | |
| 504 | - $activity_args = apply_filters( 'sensei_analysis_course_filter_statuses', $activity_args ); |
|
| 504 | + $activity_args = apply_filters('sensei_analysis_course_filter_statuses', $activity_args); |
|
| 505 | 505 | |
| 506 | 506 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
| 507 | - $this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
| 507 | + $this->total_items = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
| 508 | 508 | |
| 509 | 509 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
| 510 | - if ( $this->total_items < $activity_args['offset'] ) { |
|
| 511 | - $new_paged = floor( $this->total_items / $activity_args['number'] ); |
|
| 510 | + if ($this->total_items < $activity_args['offset']) { |
|
| 511 | + $new_paged = floor($this->total_items / $activity_args['number']); |
|
| 512 | 512 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
| 513 | 513 | } |
| 514 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
| 514 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
| 515 | 515 | // Need to always return an array, even with only 1 item |
| 516 | - if ( !is_array($statuses) ) { |
|
| 517 | - $statuses = array( $statuses ); |
|
| 516 | + if ( ! is_array($statuses)) { |
|
| 517 | + $statuses = array($statuses); |
|
| 518 | 518 | } |
| 519 | 519 | return $statuses; |
| 520 | 520 | } // End get_course_statuses() |
@@ -524,32 +524,32 @@ discard block |
||
| 524 | 524 | * @since 1.7.0 |
| 525 | 525 | * @return array statuses |
| 526 | 526 | */ |
| 527 | - private function get_lessons( $args ) { |
|
| 527 | + private function get_lessons($args) { |
|
| 528 | 528 | |
| 529 | - $lessons_args = array( 'post_type' => 'lesson', |
|
| 529 | + $lessons_args = array('post_type' => 'lesson', |
|
| 530 | 530 | 'posts_per_page' => $args['number'], |
| 531 | 531 | 'offset' => $args['offset'], |
| 532 | - 'meta_key' => '_order_' . $this->course_id, |
|
| 532 | + 'meta_key' => '_order_'.$this->course_id, |
|
| 533 | 533 | // 'orderby' => $args['orderby'], |
| 534 | 534 | 'order' => $args['order'], |
| 535 | 535 | 'meta_query' => array( |
| 536 | 536 | array( |
| 537 | 537 | 'key' => '_lesson_course', |
| 538 | - 'value' => intval( $this->course_id ), |
|
| 538 | + 'value' => intval($this->course_id), |
|
| 539 | 539 | ), |
| 540 | 540 | ), |
| 541 | 541 | 'post_status' => array('publish', 'private'), |
| 542 | 542 | 'suppress_filters' => 0 |
| 543 | 543 | ); |
| 544 | - if ( $this->search ) { |
|
| 544 | + if ($this->search) { |
|
| 545 | 545 | $lessons_args['s'] = $this->search; |
| 546 | 546 | } |
| 547 | - if ( $this->csv_output ) { |
|
| 547 | + if ($this->csv_output) { |
|
| 548 | 548 | $lessons_args['posts_per_page'] = '-1'; |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
| 552 | - $lessons_query = new WP_Query( apply_filters( 'sensei_analysis_course_filter_lessons', $lessons_args ) ); |
|
| 552 | + $lessons_query = new WP_Query(apply_filters('sensei_analysis_course_filter_lessons', $lessons_args)); |
|
| 553 | 553 | $this->total_items = $lessons_query->found_posts; |
| 554 | 554 | return $lessons_query->posts; |
| 555 | 555 | } // End get_lessons() |
@@ -561,17 +561,17 @@ discard block |
||
| 561 | 561 | * @return void |
| 562 | 562 | */ |
| 563 | 563 | public function no_items() { |
| 564 | - switch( $this->view ) { |
|
| 564 | + switch ($this->view) { |
|
| 565 | 565 | case 'user' : |
| 566 | - $text = __( 'No learners found.', 'woothemes-sensei' ); |
|
| 566 | + $text = __('No learners found.', 'woothemes-sensei'); |
|
| 567 | 567 | break; |
| 568 | 568 | |
| 569 | 569 | case 'lesson': |
| 570 | 570 | default: |
| 571 | - $text = __( 'No lessons found.', 'woothemes-sensei' ); |
|
| 571 | + $text = __('No lessons found.', 'woothemes-sensei'); |
|
| 572 | 572 | break; |
| 573 | 573 | } |
| 574 | - echo apply_filters( 'sensei_analysis_course_no_items_text', $text ); |
|
| 574 | + echo apply_filters('sensei_analysis_course_no_items_text', $text); |
|
| 575 | 575 | } // End no_items() |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,25 +580,25 @@ discard block |
||
| 580 | 580 | * @return void |
| 581 | 581 | */ |
| 582 | 582 | public function data_table_header() { |
| 583 | - if ( $this->user_id ) { |
|
| 584 | - $learners_text = __( 'Other Learners taking this Course', 'woothemes-sensei' ); |
|
| 583 | + if ($this->user_id) { |
|
| 584 | + $learners_text = __('Other Learners taking this Course', 'woothemes-sensei'); |
|
| 585 | 585 | } |
| 586 | 586 | else { |
| 587 | - $learners_text = __( 'Learners taking this Course', 'woothemes-sensei' ); |
|
| 587 | + $learners_text = __('Learners taking this Course', 'woothemes-sensei'); |
|
| 588 | 588 | } |
| 589 | - $lessons_text = __( 'Lessons in this Course', 'woothemes-sensei' ); |
|
| 589 | + $lessons_text = __('Lessons in this Course', 'woothemes-sensei'); |
|
| 590 | 590 | |
| 591 | 591 | $url_args = array( |
| 592 | 592 | 'page' => $this->page_slug, |
| 593 | 593 | 'course_id' => $this->course_id, |
| 594 | 594 | ); |
| 595 | - $learners_url = esc_url( add_query_arg( array_merge( $url_args, array( 'view' => 'user' ) ), admin_url( 'admin.php' ) ) ); |
|
| 596 | - $lessons_url = esc_url( add_query_arg( array_merge( $url_args, array( 'view' => 'lesson' ) ), admin_url( 'admin.php' ) ) ); |
|
| 595 | + $learners_url = esc_url(add_query_arg(array_merge($url_args, array('view' => 'user')), admin_url('admin.php'))); |
|
| 596 | + $lessons_url = esc_url(add_query_arg(array_merge($url_args, array('view' => 'lesson')), admin_url('admin.php'))); |
|
| 597 | 597 | |
| 598 | 598 | $learners_class = $lessons_class = ''; |
| 599 | 599 | |
| 600 | 600 | $menu = array(); |
| 601 | - switch( $this->view ) { |
|
| 601 | + switch ($this->view) { |
|
| 602 | 602 | case 'user' : |
| 603 | 603 | $learners_class = 'current'; |
| 604 | 604 | break; |
@@ -608,17 +608,17 @@ discard block |
||
| 608 | 608 | $lessons_class = 'current'; |
| 609 | 609 | break; |
| 610 | 610 | } |
| 611 | - $menu['lesson'] = sprintf( '<a href="%s" class="%s">%s</a>', $lessons_url, $lessons_class, $lessons_text ); |
|
| 612 | - $menu['user'] = sprintf( '<a href="%s" class="%s">%s</a>', $learners_url, $learners_class, $learners_text ); |
|
| 613 | - |
|
| 614 | - $menu = apply_filters( 'sensei_analysis_course_sub_menu', $menu ); |
|
| 615 | - if ( !empty($menu) ) { |
|
| 616 | - echo '<ul class="subsubsub">' . "\n"; |
|
| 617 | - foreach ( $menu as $class => $item ) { |
|
| 618 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
| 611 | + $menu['lesson'] = sprintf('<a href="%s" class="%s">%s</a>', $lessons_url, $lessons_class, $lessons_text); |
|
| 612 | + $menu['user'] = sprintf('<a href="%s" class="%s">%s</a>', $learners_url, $learners_class, $learners_text); |
|
| 613 | + |
|
| 614 | + $menu = apply_filters('sensei_analysis_course_sub_menu', $menu); |
|
| 615 | + if ( ! empty($menu)) { |
|
| 616 | + echo '<ul class="subsubsub">'."\n"; |
|
| 617 | + foreach ($menu as $class => $item) { |
|
| 618 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
| 619 | 619 | } |
| 620 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
| 621 | - echo '</ul>' . "\n"; |
|
| 620 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
| 621 | + echo '</ul>'."\n"; |
|
| 622 | 622 | } |
| 623 | 623 | } // End data_table_header() |
| 624 | 624 | |
@@ -629,19 +629,19 @@ discard block |
||
| 629 | 629 | */ |
| 630 | 630 | public function data_table_footer() { |
| 631 | 631 | |
| 632 | - $course = get_post( $this->course_id ); |
|
| 633 | - $report = sanitize_title( $course->post_title ) . '-' . $this->view . 's-overview'; |
|
| 634 | - if ( $this->user_id ) { |
|
| 635 | - $user_name = Sensei()->learners->get_learner_full_name( $this->user_id ); |
|
| 636 | - $report = sanitize_title( $user_name ) . '-' . $report; |
|
| 632 | + $course = get_post($this->course_id); |
|
| 633 | + $report = sanitize_title($course->post_title).'-'.$this->view.'s-overview'; |
|
| 634 | + if ($this->user_id) { |
|
| 635 | + $user_name = Sensei()->learners->get_learner_full_name($this->user_id); |
|
| 636 | + $report = sanitize_title($user_name).'-'.$report; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - $url_args = array( 'page' => $this->page_slug, 'course_id' => $this->course_id, 'view' => $this->view, 'sensei_report_download' => $report ); |
|
| 640 | - if ( $this->user_id ) { |
|
| 639 | + $url_args = array('page' => $this->page_slug, 'course_id' => $this->course_id, 'view' => $this->view, 'sensei_report_download' => $report); |
|
| 640 | + if ($this->user_id) { |
|
| 641 | 641 | $url_args['user_id'] = $this->user_id; |
| 642 | 642 | } |
| 643 | - $url = add_query_arg( $url_args, admin_url( 'admin.php' ) ); |
|
| 644 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
| 643 | + $url = add_query_arg($url_args, admin_url('admin.php')); |
|
| 644 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
| 645 | 645 | } // End data_table_footer() |
| 646 | 646 | |
| 647 | 647 | /** |
@@ -649,15 +649,15 @@ discard block |
||
| 649 | 649 | * @since 1.7.0 |
| 650 | 650 | * @return void |
| 651 | 651 | */ |
| 652 | - public function search_button( $text = '' ) { |
|
| 653 | - switch( $this->view ) { |
|
| 652 | + public function search_button($text = '') { |
|
| 653 | + switch ($this->view) { |
|
| 654 | 654 | case 'user': |
| 655 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
| 655 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
| 656 | 656 | break; |
| 657 | 657 | |
| 658 | 658 | case 'lesson': |
| 659 | 659 | default: |
| 660 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
| 660 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
| 661 | 661 | break; |
| 662 | 662 | } // End Switch Statement |
| 663 | 663 | |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Constructor |
| 23 | 23 | * @since 1.3.0 |
| 24 | - * |
|
| 25 | - * @param $file |
|
| 24 | + * |
|
| 25 | + * @param $file |
|
| 26 | 26 | */ |
| 27 | 27 | public function __construct ( $file ) { |
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
| 286 | 286 | |
| 287 | - $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] ); |
|
| 287 | + $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] ); |
|
| 288 | 288 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 289 | 289 | |
| 290 | 290 | } // End If Statement |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | } |
| 319 | 319 | if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
| 320 | 320 | |
| 321 | - $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] ); |
|
| 321 | + $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] ); |
|
| 322 | 322 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 323 | 323 | |
| 324 | 324 | } // End If Statement |
@@ -367,15 +367,15 @@ discard block |
||
| 367 | 367 | public function count_statuses( $args = array() ) { |
| 368 | 368 | global $wpdb; |
| 369 | 369 | |
| 370 | - /** |
|
| 371 | - * Filter fires inside Sensei_Grading::count_statuses |
|
| 372 | - * |
|
| 373 | - * Alter the the post_in array to determine which posts the |
|
| 374 | - * comment query should be limited to. |
|
| 375 | - * @since 1.8.0 |
|
| 376 | - * @param array $args |
|
| 377 | - */ |
|
| 378 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 370 | + /** |
|
| 371 | + * Filter fires inside Sensei_Grading::count_statuses |
|
| 372 | + * |
|
| 373 | + * Alter the the post_in array to determine which posts the |
|
| 374 | + * comment query should be limited to. |
|
| 375 | + * @since 1.8.0 |
|
| 376 | + * @param array $args |
|
| 377 | + */ |
|
| 378 | + $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 379 | 379 | |
| 380 | 380 | if ( 'course' == $args['type'] ) { |
| 381 | 381 | $type = 'sensei_course_status'; |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
| 389 | 389 | |
| 390 | - // Restrict to specific posts |
|
| 390 | + // Restrict to specific posts |
|
| 391 | 391 | if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
| 392 | 392 | $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
| 393 | 393 | } |
@@ -522,148 +522,148 @@ discard block |
||
| 522 | 522 | return $html; |
| 523 | 523 | } // End lessons_drop_down_html() |
| 524 | 524 | |
| 525 | - /** |
|
| 526 | - * The process grading function handles admin grading submissions. |
|
| 527 | - * |
|
| 528 | - * This function is hooked on to admin_init. It simply accepts |
|
| 529 | - * the grades as the Grader selected theme and saves the total grade and |
|
| 530 | - * individual question grades. |
|
| 531 | - * |
|
| 532 | - * @return bool |
|
| 533 | - */ |
|
| 534 | - public function admin_process_grading_submission() { |
|
| 525 | + /** |
|
| 526 | + * The process grading function handles admin grading submissions. |
|
| 527 | + * |
|
| 528 | + * This function is hooked on to admin_init. It simply accepts |
|
| 529 | + * the grades as the Grader selected theme and saves the total grade and |
|
| 530 | + * individual question grades. |
|
| 531 | + * |
|
| 532 | + * @return bool |
|
| 533 | + */ |
|
| 534 | + public function admin_process_grading_submission() { |
|
| 535 | 535 | |
| 536 | - // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 537 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | - || ! isset( $_GET['quiz_id'] ) |
|
| 540 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 536 | + // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 537 | + if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | + || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | + || ! isset( $_GET['quiz_id'] ) |
|
| 540 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 541 | 541 | |
| 542 | - return false; //exit and do not grade |
|
| 542 | + return false; //exit and do not grade |
|
| 543 | 543 | |
| 544 | - } |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - $quiz_id = $_GET['quiz_id']; |
|
| 547 | - $user_id = $_GET['user']; |
|
| 546 | + $quiz_id = $_GET['quiz_id']; |
|
| 547 | + $user_id = $_GET['user']; |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 552 | - $quiz_grade = 0; |
|
| 553 | - $count = 0; |
|
| 554 | - $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 555 | - $all_question_grades = array(); |
|
| 556 | - $all_answers_feedback = array(); |
|
| 550 | + $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 552 | + $quiz_grade = 0; |
|
| 553 | + $count = 0; |
|
| 554 | + $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 555 | + $all_question_grades = array(); |
|
| 556 | + $all_answers_feedback = array(); |
|
| 557 | 557 | |
| 558 | - foreach( $questions as $question ) { |
|
| 558 | + foreach( $questions as $question ) { |
|
| 559 | 559 | |
| 560 | - ++$count; |
|
| 561 | - $question_id = $question->ID; |
|
| 560 | + ++$count; |
|
| 561 | + $question_id = $question->ID; |
|
| 562 | 562 | |
| 563 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 563 | + if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 564 | 564 | |
| 565 | - $question_grade = 0; |
|
| 566 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 565 | + $question_grade = 0; |
|
| 566 | + if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 567 | 567 | |
| 568 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 568 | + $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 569 | 569 | |
| 570 | - } |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - // add data to the array that will, after the loop, be stored on the lesson status |
|
| 573 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 572 | + // add data to the array that will, after the loop, be stored on the lesson status |
|
| 573 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 574 | 574 | |
| 575 | - // tally up the total quiz grade |
|
| 576 | - $quiz_grade += $question_grade; |
|
| 575 | + // tally up the total quiz grade |
|
| 576 | + $quiz_grade += $question_grade; |
|
| 577 | 577 | |
| 578 | - } // endif |
|
| 578 | + } // endif |
|
| 579 | 579 | |
| 580 | - // Question answer feedback / notes |
|
| 581 | - $question_feedback = ''; |
|
| 582 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 580 | + // Question answer feedback / notes |
|
| 581 | + $question_feedback = ''; |
|
| 582 | + if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 583 | 583 | |
| 584 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 584 | + $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 585 | 585 | |
| 586 | - } |
|
| 587 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 586 | + } |
|
| 587 | + $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 588 | 588 | |
| 589 | - } // end for each $questions |
|
| 589 | + } // end for each $questions |
|
| 590 | 590 | |
| 591 | - //store all question grades on the lesson status |
|
| 592 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 591 | + //store all question grades on the lesson status |
|
| 592 | + Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 593 | 593 | |
| 594 | - //store the feedback from grading |
|
| 595 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 594 | + //store the feedback from grading |
|
| 595 | + Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 596 | 596 | |
| 597 | - // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 598 | - // in the class sensei grading user quiz -> display() |
|
| 599 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 597 | + // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 598 | + // in the class sensei grading user quiz -> display() |
|
| 599 | + if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 600 | 600 | |
| 601 | - // set the users total quiz grade |
|
| 601 | + // set the users total quiz grade |
|
| 602 | 602 | if ( 0 < intval( $quiz_grade_total ) ) { |
| 603 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 603 | + $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 604 | 604 | } |
| 605 | 605 | else { |
| 606 | 606 | $grade = 0; |
| 607 | 607 | } |
| 608 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 609 | - |
|
| 610 | - // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 611 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 613 | - $lesson_metadata = array(); |
|
| 614 | - if ( $pass_required ) { |
|
| 615 | - // Student has reached the pass mark and lesson is complete |
|
| 616 | - if ( $quiz_passmark <= $grade ) { |
|
| 617 | - $lesson_status = 'passed'; |
|
| 618 | - } |
|
| 619 | - else { |
|
| 620 | - $lesson_status = 'failed'; |
|
| 621 | - } // End If Statement |
|
| 622 | - } |
|
| 623 | - // Student only has to partake the quiz |
|
| 624 | - else { |
|
| 625 | - $lesson_status = 'graded'; |
|
| 626 | - } |
|
| 627 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 608 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 609 | + |
|
| 610 | + // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 611 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 613 | + $lesson_metadata = array(); |
|
| 614 | + if ( $pass_required ) { |
|
| 615 | + // Student has reached the pass mark and lesson is complete |
|
| 616 | + if ( $quiz_passmark <= $grade ) { |
|
| 617 | + $lesson_status = 'passed'; |
|
| 618 | + } |
|
| 619 | + else { |
|
| 620 | + $lesson_status = 'failed'; |
|
| 621 | + } // End If Statement |
|
| 622 | + } |
|
| 623 | + // Student only has to partake the quiz |
|
| 624 | + else { |
|
| 625 | + $lesson_status = 'graded'; |
|
| 626 | + } |
|
| 627 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 628 | 628 | |
| 629 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 629 | + Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 630 | 630 | |
| 631 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 631 | + if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Summary. |
|
| 635 | - * |
|
| 636 | - * Description. |
|
| 637 | - * |
|
| 638 | - * @since 1.7.0 |
|
| 639 | - * |
|
| 640 | - * @param int $user_id |
|
| 641 | - * @param int $quiz_lesson_id |
|
| 642 | - */ |
|
| 643 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 633 | + /** |
|
| 634 | + * Summary. |
|
| 635 | + * |
|
| 636 | + * Description. |
|
| 637 | + * |
|
| 638 | + * @since 1.7.0 |
|
| 639 | + * |
|
| 640 | + * @param int $user_id |
|
| 641 | + * @param int $quiz_lesson_id |
|
| 642 | + */ |
|
| 643 | + do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 644 | 644 | |
| 645 | - } // end if in_array |
|
| 645 | + } // end if in_array |
|
| 646 | 646 | |
| 647 | - }// end if $_POST['all_que... |
|
| 647 | + }// end if $_POST['all_que... |
|
| 648 | 648 | |
| 649 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 649 | + if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 650 | 650 | |
| 651 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 651 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 652 | 652 | |
| 653 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 653 | + } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 654 | 654 | |
| 655 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 655 | + $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 656 | 656 | |
| 657 | - } else { |
|
| 657 | + } else { |
|
| 658 | 658 | |
| 659 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 659 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 660 | 660 | |
| 661 | - } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 664 | - exit; |
|
| 663 | + wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 664 | + exit; |
|
| 665 | 665 | |
| 666 | - } // end admin_process_grading_submission |
|
| 666 | + } // end admin_process_grading_submission |
|
| 667 | 667 | |
| 668 | 668 | public function get_redirect_url() { |
| 669 | 669 | // Parse POST data |
@@ -708,283 +708,283 @@ discard block |
||
| 708 | 708 | } // End If Statement |
| 709 | 709 | } // End sensei_grading_notices() |
| 710 | 710 | |
| 711 | - /** |
|
| 712 | - * Grade quiz automatically |
|
| 713 | - * |
|
| 714 | - * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 715 | - * the quiz will not be auto gradable. |
|
| 716 | - * |
|
| 717 | - * @since 1.7.4 |
|
| 718 | - * |
|
| 719 | - * @param integer $quiz_id ID of quiz |
|
| 720 | - * @param array $submitted questions id ans answers { |
|
| 721 | - * @type int $question_id |
|
| 722 | - * @type mixed $answer |
|
| 723 | - * } |
|
| 724 | - * @param integer $total_questions Total questions in quiz (not used) |
|
| 725 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 726 | - * |
|
| 727 | - * @return int $quiz_grade total sum of all question grades |
|
| 728 | - */ |
|
| 729 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 730 | - |
|
| 731 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | - || $quiz_grade_type != 'auto' ) { |
|
| 733 | - return false; // exit early |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - $user_id = get_current_user_id(); |
|
| 738 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 739 | - $quiz_autogradable = true; |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * Filter the types of question types that can be automatically graded. |
|
| 743 | - * |
|
| 744 | - * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 745 | - * |
|
| 746 | - * @param array { |
|
| 747 | - * 'multiple-choice', |
|
| 748 | - * 'boolean', |
|
| 749 | - * 'gap-fill'. |
|
| 750 | - * } |
|
| 751 | - */ |
|
| 752 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 753 | - |
|
| 754 | - $grade_total = 0; |
|
| 755 | - $all_question_grades = array(); |
|
| 756 | - foreach( $submitted as $question_id => $answer ) { |
|
| 757 | - |
|
| 758 | - // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 759 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 711 | + /** |
|
| 712 | + * Grade quiz automatically |
|
| 713 | + * |
|
| 714 | + * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 715 | + * the quiz will not be auto gradable. |
|
| 716 | + * |
|
| 717 | + * @since 1.7.4 |
|
| 718 | + * |
|
| 719 | + * @param integer $quiz_id ID of quiz |
|
| 720 | + * @param array $submitted questions id ans answers { |
|
| 721 | + * @type int $question_id |
|
| 722 | + * @type mixed $answer |
|
| 723 | + * } |
|
| 724 | + * @param integer $total_questions Total questions in quiz (not used) |
|
| 725 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 726 | + * |
|
| 727 | + * @return int $quiz_grade total sum of all question grades |
|
| 728 | + */ |
|
| 729 | + public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 730 | + |
|
| 731 | + if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | + || $quiz_grade_type != 'auto' ) { |
|
| 733 | + return false; // exit early |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + $user_id = get_current_user_id(); |
|
| 738 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 739 | + $quiz_autogradable = true; |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * Filter the types of question types that can be automatically graded. |
|
| 743 | + * |
|
| 744 | + * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 745 | + * |
|
| 746 | + * @param array { |
|
| 747 | + * 'multiple-choice', |
|
| 748 | + * 'boolean', |
|
| 749 | + * 'gap-fill'. |
|
| 750 | + * } |
|
| 751 | + */ |
|
| 752 | + $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 753 | + |
|
| 754 | + $grade_total = 0; |
|
| 755 | + $all_question_grades = array(); |
|
| 756 | + foreach( $submitted as $question_id => $answer ) { |
|
| 757 | + |
|
| 758 | + // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 759 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 760 | 760 | $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
| 761 | 761 | // Question has a zero grade, so skip grading |
| 762 | 762 | if ( 0 == $achievable_grade ) { |
| 763 | 763 | $all_question_grades[ $question_id ] = $achievable_grade; |
| 764 | 764 | } |
| 765 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | - // Get user question grade |
|
| 767 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 769 | - $grade_total += $question_grade; |
|
| 765 | + elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | + // Get user question grade |
|
| 767 | + $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 769 | + $grade_total += $question_grade; |
|
| 770 | 770 | |
| 771 | - } else { |
|
| 771 | + } else { |
|
| 772 | 772 | |
| 773 | - // There is a question that cannot be autograded |
|
| 774 | - $quiz_autogradable = false; |
|
| 773 | + // There is a question that cannot be autograded |
|
| 774 | + $quiz_autogradable = false; |
|
| 775 | 775 | |
| 776 | - } // end if in_array( $question_type... |
|
| 776 | + } // end if in_array( $question_type... |
|
| 777 | 777 | |
| 778 | - }// end for each question |
|
| 778 | + }// end for each question |
|
| 779 | 779 | |
| 780 | - // Only if the whole quiz was autogradable do we set a grade |
|
| 781 | - if ( $quiz_autogradable ) { |
|
| 780 | + // Only if the whole quiz was autogradable do we set a grade |
|
| 781 | + if ( $quiz_autogradable ) { |
|
| 782 | 782 | |
| 783 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 783 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 784 | 784 | // Check for zero total from grades |
| 785 | 785 | if ( 0 < $quiz_total ) { |
| 786 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 786 | + $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 787 | 787 | } |
| 788 | 788 | else { |
| 789 | 789 | $grade = 0; |
| 790 | 790 | } |
| 791 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 791 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 792 | 792 | |
| 793 | - } else { |
|
| 793 | + } else { |
|
| 794 | 794 | |
| 795 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 795 | + $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 796 | 796 | |
| 797 | - } |
|
| 798 | - |
|
| 799 | - // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 800 | - // when doing manual grading. |
|
| 801 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 797 | + } |
|
| 802 | 798 | |
| 803 | - return $grade; |
|
| 799 | + // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 800 | + // when doing manual grading. |
|
| 801 | + Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 804 | 802 | |
| 805 | - } // End grade_quiz_auto() |
|
| 803 | + return $grade; |
|
| 806 | 804 | |
| 807 | - /** |
|
| 808 | - * Grade question automatically |
|
| 809 | - * |
|
| 810 | - * This function checks the question typ and then grades it accordingly. |
|
| 811 | - * |
|
| 812 | - * @since 1.7.4 |
|
| 813 | - * |
|
| 814 | - * @param integer $question_id |
|
| 815 | - * @param string $question_type of the standard Sensei question types |
|
| 816 | - * @param string $answer |
|
| 817 | - * @param int $user_id |
|
| 818 | - * |
|
| 819 | - * @return int $question_grade |
|
| 820 | - */ |
|
| 821 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 822 | - |
|
| 823 | - if( intval( $user_id ) == 0 ) { |
|
| 824 | - |
|
| 825 | - $user_id = get_current_user_id(); |
|
| 826 | - |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 830 | - |
|
| 831 | - return false; |
|
| 832 | - |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - Sensei()->question->get_question_type( $question_id ); |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Applying a grade before the auto grading takes place. |
|
| 840 | - * |
|
| 841 | - * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 842 | - * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 843 | - * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 844 | - * |
|
| 845 | - * @param int $question_grade default false |
|
| 846 | - * @param int $question_id |
|
| 847 | - * @param string $question_type one of the Sensei question type. |
|
| 848 | - * @param string $answer user supplied question answer |
|
| 849 | - */ |
|
| 850 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 805 | + } // End grade_quiz_auto() |
|
| 851 | 806 | |
| 852 | - if ( false !== $question_grade ) { |
|
| 807 | + /** |
|
| 808 | + * Grade question automatically |
|
| 809 | + * |
|
| 810 | + * This function checks the question typ and then grades it accordingly. |
|
| 811 | + * |
|
| 812 | + * @since 1.7.4 |
|
| 813 | + * |
|
| 814 | + * @param integer $question_id |
|
| 815 | + * @param string $question_type of the standard Sensei question types |
|
| 816 | + * @param string $answer |
|
| 817 | + * @param int $user_id |
|
| 818 | + * |
|
| 819 | + * @return int $question_grade |
|
| 820 | + */ |
|
| 821 | + public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 822 | + |
|
| 823 | + if( intval( $user_id ) == 0 ) { |
|
| 824 | + |
|
| 825 | + $user_id = get_current_user_id(); |
|
| 826 | + |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 830 | + |
|
| 831 | + return false; |
|
| 832 | + |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + Sensei()->question->get_question_type( $question_id ); |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Applying a grade before the auto grading takes place. |
|
| 840 | + * |
|
| 841 | + * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 842 | + * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 843 | + * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 844 | + * |
|
| 845 | + * @param int $question_grade default false |
|
| 846 | + * @param int $question_id |
|
| 847 | + * @param string $question_type one of the Sensei question type. |
|
| 848 | + * @param string $answer user supplied question answer |
|
| 849 | + */ |
|
| 850 | + $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 853 | 851 | |
| 854 | - return $question_grade; |
|
| 852 | + if ( false !== $question_grade ) { |
|
| 855 | 853 | |
| 856 | - } |
|
| 854 | + return $question_grade; |
|
| 857 | 855 | |
| 858 | - // auto grading core |
|
| 859 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 856 | + } |
|
| 860 | 857 | |
| 861 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 858 | + // auto grading core |
|
| 859 | + if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 862 | 860 | |
| 863 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | - $answer = wp_unslash( $answer ); |
|
| 865 | - } |
|
| 866 | - $answer = (array) $answer; |
|
| 867 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 868 | - // Loop through all answers ensure none are 'missing' |
|
| 869 | - $all_correct = true; |
|
| 870 | - foreach ( $answer as $check_answer ) { |
|
| 871 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 872 | - $all_correct = false; |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - // If all correct then grade |
|
| 876 | - if ( $all_correct ) { |
|
| 877 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 861 | + $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 880 | 862 | |
| 881 | - } elseif( 'gap-fill' == $question_type ){ |
|
| 863 | + if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | + $answer = wp_unslash( $answer ); |
|
| 865 | + } |
|
| 866 | + $answer = (array) $answer; |
|
| 867 | + if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 868 | + // Loop through all answers ensure none are 'missing' |
|
| 869 | + $all_correct = true; |
|
| 870 | + foreach ( $answer as $check_answer ) { |
|
| 871 | + if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 872 | + $all_correct = false; |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + // If all correct then grade |
|
| 876 | + if ( $all_correct ) { |
|
| 877 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 882 | 880 | |
| 883 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 881 | + } elseif( 'gap-fill' == $question_type ){ |
|
| 884 | 882 | |
| 885 | - } else{ |
|
| 883 | + $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 886 | 884 | |
| 887 | - /** |
|
| 888 | - * Grading questions that are not auto gradable. |
|
| 889 | - * |
|
| 890 | - * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 891 | - * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 892 | - * |
|
| 893 | - * @param int $question_grade default zero |
|
| 894 | - * @param int $question_id |
|
| 895 | - * @param string $question_type one of the Sensei question type. |
|
| 896 | - * @param string $answer user supplied question answer |
|
| 897 | - */ |
|
| 898 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 885 | + } else{ |
|
| 899 | 886 | |
| 900 | - } // end if $question_type |
|
| 887 | + /** |
|
| 888 | + * Grading questions that are not auto gradable. |
|
| 889 | + * |
|
| 890 | + * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 891 | + * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 892 | + * |
|
| 893 | + * @param int $question_grade default zero |
|
| 894 | + * @param int $question_id |
|
| 895 | + * @param string $question_type one of the Sensei question type. |
|
| 896 | + * @param string $answer user supplied question answer |
|
| 897 | + */ |
|
| 898 | + $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 901 | 899 | |
| 902 | - return $question_grade; |
|
| 903 | - } // end grade_question_auto |
|
| 900 | + } // end if $question_type |
|
| 904 | 901 | |
| 905 | - /** |
|
| 906 | - * Grading logic specifically for the gap fill questions |
|
| 907 | - * |
|
| 908 | - * @since 1.9.0 |
|
| 909 | - * @param $question_id |
|
| 910 | - * @param $user_answer |
|
| 911 | - * |
|
| 912 | - * @return bool | int false or the grade given to the user answer |
|
| 913 | - */ |
|
| 914 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 902 | + return $question_grade; |
|
| 903 | + } // end grade_question_auto |
|
| 915 | 904 | |
| 916 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | - $gapfill_array = explode( '||', $right_answer ); |
|
| 905 | + /** |
|
| 906 | + * Grading logic specifically for the gap fill questions |
|
| 907 | + * |
|
| 908 | + * @since 1.9.0 |
|
| 909 | + * @param $question_id |
|
| 910 | + * @param $user_answer |
|
| 911 | + * |
|
| 912 | + * @return bool | int false or the grade given to the user answer |
|
| 913 | + */ |
|
| 914 | + public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 918 | 915 | |
| 919 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | - $user_answer = wp_unslash( $user_answer ); |
|
| 921 | - } |
|
| 916 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | + $gapfill_array = explode( '||', $right_answer ); |
|
| 922 | 918 | |
| 923 | - /** |
|
| 924 | - * case sensitive grading filter |
|
| 925 | - * |
|
| 926 | - * alter the value simply use this code in your plugin or the themes functions.php |
|
| 927 | - * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 928 | - * |
|
| 929 | - * @param bool $do_case_sensitive_comparison default false. |
|
| 930 | - * |
|
| 931 | - * @since 1.9.0 |
|
| 932 | - */ |
|
| 933 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 919 | + if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | + $user_answer = wp_unslash( $user_answer ); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * case sensitive grading filter |
|
| 925 | + * |
|
| 926 | + * alter the value simply use this code in your plugin or the themes functions.php |
|
| 927 | + * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 928 | + * |
|
| 929 | + * @param bool $do_case_sensitive_comparison default false. |
|
| 930 | + * |
|
| 931 | + * @since 1.9.0 |
|
| 932 | + */ |
|
| 933 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 934 | 934 | |
| 935 | - if( $do_case_sensitive_comparison ){ |
|
| 935 | + if( $do_case_sensitive_comparison ){ |
|
| 936 | 936 | |
| 937 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 938 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 937 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 938 | + if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 939 | 939 | |
| 940 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 940 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 941 | 941 | |
| 942 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 942 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 943 | 943 | |
| 944 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 944 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 945 | 945 | |
| 946 | - return Sensei()->question->get_question_grade($question_id); |
|
| 946 | + return Sensei()->question->get_question_grade($question_id); |
|
| 947 | 947 | |
| 948 | - }else{ |
|
| 948 | + }else{ |
|
| 949 | 949 | |
| 950 | - return false; |
|
| 950 | + return false; |
|
| 951 | 951 | |
| 952 | - } |
|
| 952 | + } |
|
| 953 | 953 | |
| 954 | - }else{ |
|
| 954 | + }else{ |
|
| 955 | 955 | |
| 956 | - return false; |
|
| 956 | + return false; |
|
| 957 | 957 | |
| 958 | - } |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - }else{ |
|
| 960 | + }else{ |
|
| 961 | 961 | |
| 962 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 963 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 962 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 963 | + if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 964 | 964 | |
| 965 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 965 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 966 | 966 | |
| 967 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 967 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 968 | 968 | |
| 969 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 969 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 970 | 970 | |
| 971 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 971 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 972 | 972 | |
| 973 | - }else{ |
|
| 973 | + }else{ |
|
| 974 | 974 | |
| 975 | - return false; |
|
| 975 | + return false; |
|
| 976 | 976 | |
| 977 | - } |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - }else{ |
|
| 979 | + }else{ |
|
| 980 | 980 | |
| 981 | - return false; |
|
| 981 | + return false; |
|
| 982 | 982 | |
| 983 | - } |
|
| 983 | + } |
|
| 984 | 984 | |
| 985 | - } |
|
| 985 | + } |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | 989 | } // End Class |
| 990 | 990 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Grading Class |
@@ -24,30 +24,30 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param $file |
| 26 | 26 | */ |
| 27 | - public function __construct ( $file ) { |
|
| 28 | - $this->name = __( 'Grading', 'woothemes-sensei' ); |
|
| 27 | + public function __construct($file) { |
|
| 28 | + $this->name = __('Grading', 'woothemes-sensei'); |
|
| 29 | 29 | $this->file = $file; |
| 30 | 30 | $this->page_slug = 'sensei_grading'; |
| 31 | 31 | |
| 32 | 32 | // Admin functions |
| 33 | - if ( is_admin() ) { |
|
| 34 | - add_action( 'admin_menu', array( $this, 'grading_admin_menu' ), 20); |
|
| 35 | - add_action( 'grading_wrapper_container', array( $this, 'wrapper_container' ) ); |
|
| 36 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
| 37 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 38 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
| 33 | + if (is_admin()) { |
|
| 34 | + add_action('admin_menu', array($this, 'grading_admin_menu'), 20); |
|
| 35 | + add_action('grading_wrapper_container', array($this, 'wrapper_container')); |
|
| 36 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
| 37 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
| 38 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - add_action( 'admin_init', array( $this, 'admin_process_grading_submission' ) ); |
|
| 41 | + add_action('admin_init', array($this, 'admin_process_grading_submission')); |
|
| 42 | 42 | |
| 43 | - add_action( 'admin_notices', array( $this, 'add_grading_notices' ) ); |
|
| 43 | + add_action('admin_notices', array($this, 'add_grading_notices')); |
|
| 44 | 44 | // add_action( 'sensei_grading_notices', array( $this, 'sensei_grading_notices' ) ); |
| 45 | 45 | } // End If Statement |
| 46 | 46 | |
| 47 | 47 | // Ajax functions |
| 48 | - if ( is_admin() ) { |
|
| 49 | - add_action( 'wp_ajax_get_lessons_dropdown', array( $this, 'get_lessons_dropdown' ) ); |
|
| 50 | - add_action( 'wp_ajax_get_redirect_url', array( $this, 'get_redirect_url' ) ); |
|
| 48 | + if (is_admin()) { |
|
| 49 | + add_action('wp_ajax_get_lessons_dropdown', array($this, 'get_lessons_dropdown')); |
|
| 50 | + add_action('wp_ajax_get_redirect_url', array($this, 'get_redirect_url')); |
|
| 51 | 51 | } // End If Statement |
| 52 | 52 | } // End __construct() |
| 53 | 53 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | public function grading_admin_menu() { |
| 61 | 61 | global $menu; |
| 62 | 62 | |
| 63 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
| 64 | - $grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei') , 'manage_sensei_grades', $this->page_slug, array( $this, 'grading_page' ) ); |
|
| 63 | + if (current_user_can('manage_sensei_grades')) { |
|
| 64 | + $grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei'), 'manage_sensei_grades', $this->page_slug, array($this, 'grading_page')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | } // End grading_admin_menu() |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * @since 1.3.0 |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function enqueue_scripts () { |
|
| 77 | + public function enqueue_scripts() { |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 80 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 81 | 81 | |
| 82 | 82 | // Load Grading JS |
| 83 | - wp_enqueue_script( 'sensei-grading-general', Sensei()->plugin_url . 'assets/js/grading-general' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
| 83 | + wp_enqueue_script('sensei-grading-general', Sensei()->plugin_url.'assets/js/grading-general'.$suffix.'.js', array('jquery'), Sensei()->version); |
|
| 84 | 84 | |
| 85 | 85 | } // End enqueue_scripts() |
| 86 | 86 | |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | * @since 1.0.0 |
| 93 | 93 | * @return void |
| 94 | 94 | */ |
| 95 | - public function enqueue_styles () { |
|
| 95 | + public function enqueue_styles() { |
|
| 96 | 96 | |
| 97 | - wp_enqueue_style( Sensei()->token . '-admin' ); |
|
| 97 | + wp_enqueue_style(Sensei()->token.'-admin'); |
|
| 98 | 98 | |
| 99 | - wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version ); |
|
| 99 | + wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version); |
|
| 100 | 100 | |
| 101 | 101 | } // End enqueue_styles() |
| 102 | 102 | |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | public function load_data_table_files() { |
| 109 | 109 | |
| 110 | 110 | // Load Grading Classes |
| 111 | - $classes_to_load = array( 'list-table', |
|
| 111 | + $classes_to_load = array('list-table', |
|
| 112 | 112 | 'grading-main', |
| 113 | 113 | 'grading-user-quiz' |
| 114 | 114 | ); |
| 115 | - foreach ( $classes_to_load as $class_file ) { |
|
| 116 | - Sensei()->load_class( $class_file ); |
|
| 115 | + foreach ($classes_to_load as $class_file) { |
|
| 116 | + Sensei()->load_class($class_file); |
|
| 117 | 117 | } // End For Loop |
| 118 | 118 | } // End load_data_table_files() |
| 119 | 119 | |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | * @param undefined $optional_data optional constructor arguments |
| 126 | 126 | * @return object class instance object |
| 127 | 127 | */ |
| 128 | - public function load_data_object( $name = '', $data = 0, $optional_data = null ) { |
|
| 128 | + public function load_data_object($name = '', $data = 0, $optional_data = null) { |
|
| 129 | 129 | // Load Analysis data |
| 130 | - $object_name = 'WooThemes_Sensei_Grading_' . $name; |
|
| 131 | - if ( is_null($optional_data) ) { |
|
| 132 | - $sensei_grading_object = new $object_name( $data ); |
|
| 130 | + $object_name = 'WooThemes_Sensei_Grading_'.$name; |
|
| 131 | + if (is_null($optional_data)) { |
|
| 132 | + $sensei_grading_object = new $object_name($data); |
|
| 133 | 133 | } |
| 134 | 134 | else { |
| 135 | - $sensei_grading_object = new $object_name( $data, $optional_data ); |
|
| 135 | + $sensei_grading_object = new $object_name($data, $optional_data); |
|
| 136 | 136 | } // End If Statement |
| 137 | - if ( 'Main' == $name ) { |
|
| 137 | + if ('Main' == $name) { |
|
| 138 | 138 | $sensei_grading_object->prepare_items(); |
| 139 | 139 | } // End If Statement |
| 140 | 140 | return $sensei_grading_object; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function grading_page() { |
| 150 | 150 | |
| 151 | - if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
|
| 151 | + if (isset($_GET['quiz_id']) && 0 < intval($_GET['quiz_id']) && isset($_GET['user']) && 0 < intval($_GET['user'])) { |
|
| 152 | 152 | $this->grading_user_quiz_view(); |
| 153 | 153 | } |
| 154 | 154 | else { |
@@ -164,23 +164,23 @@ discard block |
||
| 164 | 164 | public function grading_default_view() { |
| 165 | 165 | |
| 166 | 166 | // Load Grading data |
| 167 | - if( !empty( $_GET['course_id'] ) ) { |
|
| 168 | - $course_id = intval( $_GET['course_id'] ); |
|
| 167 | + if ( ! empty($_GET['course_id'])) { |
|
| 168 | + $course_id = intval($_GET['course_id']); |
|
| 169 | 169 | } |
| 170 | - if( !empty( $_GET['lesson_id'] ) ) { |
|
| 171 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
| 170 | + if ( ! empty($_GET['lesson_id'])) { |
|
| 171 | + $lesson_id = intval($_GET['lesson_id']); |
|
| 172 | 172 | } |
| 173 | - if( !empty( $_GET['user_id'] ) ) { |
|
| 174 | - $user_id = intval( $_GET['user_id'] ); |
|
| 173 | + if ( ! empty($_GET['user_id'])) { |
|
| 174 | + $user_id = intval($_GET['user_id']); |
|
| 175 | 175 | } |
| 176 | - if( !empty( $_GET['view'] ) ) { |
|
| 177 | - $view = esc_html( $_GET['view'] ); |
|
| 176 | + if ( ! empty($_GET['view'])) { |
|
| 177 | + $view = esc_html($_GET['view']); |
|
| 178 | 178 | } |
| 179 | - $sensei_grading_overview = $this->load_data_object( 'Main', compact( 'course_id', 'lesson_id', 'user_id', 'view' ) ); |
|
| 179 | + $sensei_grading_overview = $this->load_data_object('Main', compact('course_id', 'lesson_id', 'user_id', 'view')); |
|
| 180 | 180 | |
| 181 | 181 | // Wrappers |
| 182 | - do_action( 'grading_before_container' ); |
|
| 183 | - do_action( 'grading_wrapper_container', 'top' ); |
|
| 182 | + do_action('grading_before_container'); |
|
| 183 | + do_action('grading_wrapper_container', 'top'); |
|
| 184 | 184 | $this->grading_headers(); |
| 185 | 185 | ?> |
| 186 | 186 | <div id="poststuff" class="sensei-grading-wrap"> |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | <?php $sensei_grading_overview->display(); ?> |
| 189 | 189 | </div> |
| 190 | 190 | <div class="sensei-grading-extra"> |
| 191 | - <?php do_action( 'sensei_grading_extra' ); ?> |
|
| 191 | + <?php do_action('sensei_grading_extra'); ?> |
|
| 192 | 192 | </div> |
| 193 | 193 | </div> |
| 194 | 194 | <?php |
| 195 | - do_action( 'grading_wrapper_container', 'bottom' ); |
|
| 196 | - do_action( 'grading_after_container' ); |
|
| 195 | + do_action('grading_wrapper_container', 'bottom'); |
|
| 196 | + do_action('grading_after_container'); |
|
| 197 | 197 | } // End grading_default_view() |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | // Load Grading data |
| 207 | 207 | $user_id = 0; |
| 208 | 208 | $quiz_id = 0; |
| 209 | - if( isset( $_GET['user'] ) ) { |
|
| 210 | - $user_id = intval( $_GET['user'] ); |
|
| 209 | + if (isset($_GET['user'])) { |
|
| 210 | + $user_id = intval($_GET['user']); |
|
| 211 | 211 | } |
| 212 | - if( isset( $_GET['quiz_id'] ) ) { |
|
| 213 | - $quiz_id = intval( $_GET['quiz_id'] ); |
|
| 212 | + if (isset($_GET['quiz_id'])) { |
|
| 213 | + $quiz_id = intval($_GET['quiz_id']); |
|
| 214 | 214 | } |
| 215 | - $sensei_grading_user_profile = $this->load_data_object( 'User_Quiz', $user_id, $quiz_id ); |
|
| 215 | + $sensei_grading_user_profile = $this->load_data_object('User_Quiz', $user_id, $quiz_id); |
|
| 216 | 216 | // Wrappers |
| 217 | - do_action( 'grading_before_container' ); |
|
| 218 | - do_action( 'grading_wrapper_container', 'top' ); |
|
| 219 | - $this->grading_headers( array( 'nav' => 'user_quiz' ) ); |
|
| 217 | + do_action('grading_before_container'); |
|
| 218 | + do_action('grading_wrapper_container', 'top'); |
|
| 219 | + $this->grading_headers(array('nav' => 'user_quiz')); |
|
| 220 | 220 | ?> |
| 221 | 221 | <div id="poststuff" class="sensei-grading-wrap user-profile"> |
| 222 | 222 | <div class="sensei-grading-main"> |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | </div> |
| 226 | 226 | </div> |
| 227 | 227 | <?php |
| 228 | - do_action( 'grading_wrapper_container', 'bottom' ); |
|
| 229 | - do_action( 'grading_after_container' ); |
|
| 228 | + do_action('grading_wrapper_container', 'bottom'); |
|
| 229 | + do_action('grading_after_container'); |
|
| 230 | 230 | } // End grading_user_quiz_view() |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -234,15 +234,15 @@ discard block |
||
| 234 | 234 | * @since 1.3.0 |
| 235 | 235 | * @return void |
| 236 | 236 | */ |
| 237 | - public function grading_headers( $args = array( 'nav' => 'default' ) ) { |
|
| 237 | + public function grading_headers($args = array('nav' => 'default')) { |
|
| 238 | 238 | |
| 239 | 239 | |
| 240 | - $function = 'grading_' . $args['nav'] . '_nav'; |
|
| 240 | + $function = 'grading_'.$args['nav'].'_nav'; |
|
| 241 | 241 | $this->$function(); |
| 242 | 242 | ?> |
| 243 | - <p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
| 243 | + <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
| 244 | 244 | <?php |
| 245 | - do_action( 'sensei_grading_after_headers' ); |
|
| 245 | + do_action('sensei_grading_after_headers'); |
|
| 246 | 246 | } // End grading_headers() |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | * @param $which string |
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | - public function wrapper_container( $which ) { |
|
| 255 | - if ( 'top' == $which ) { |
|
| 256 | - ?><div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>"><?php |
|
| 257 | - } elseif ( 'bottom' == $which ) { |
|
| 254 | + public function wrapper_container($which) { |
|
| 255 | + if ('top' == $which) { |
|
| 256 | + ?><div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"><?php |
|
| 257 | + } elseif ('bottom' == $which) { |
|
| 258 | 258 | ?></div><!--/#woothemes-sensei--><?php |
| 259 | 259 | } // End If Statement |
| 260 | 260 | } // End wrapper_container() |
@@ -267,29 +267,29 @@ discard block |
||
| 267 | 267 | public function grading_default_nav() { |
| 268 | 268 | global $wp_version; |
| 269 | 269 | |
| 270 | - $title = sprintf( '<a href="%s">%s</a>', esc_url(add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) ); |
|
| 271 | - if ( isset( $_GET['course_id'] ) ) { |
|
| 272 | - $course_id = intval( $_GET['course_id'] ); |
|
| 273 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 274 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
| 275 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
| 270 | + $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name)); |
|
| 271 | + if (isset($_GET['course_id'])) { |
|
| 272 | + $course_id = intval($_GET['course_id']); |
|
| 273 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 274 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
| 275 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
| 276 | 276 | } |
| 277 | 277 | else { |
| 278 | - $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
|
| 278 | + $title .= sprintf(' <span class="course-title">> %s</span>', get_the_title($course_id)); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | - if ( isset( $_GET['lesson_id'] ) ) { |
|
| 282 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
| 283 | - $title .= ' <span class="lesson-title">> ' . get_the_title( intval( $lesson_id ) ) . '</span>'; |
|
| 281 | + if (isset($_GET['lesson_id'])) { |
|
| 282 | + $lesson_id = intval($_GET['lesson_id']); |
|
| 283 | + $title .= ' <span class="lesson-title">> '.get_the_title(intval($lesson_id)).'</span>'; |
|
| 284 | 284 | } |
| 285 | - if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
|
| 285 | + if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) { |
|
| 286 | 286 | |
| 287 | - $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] ); |
|
| 288 | - $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
|
| 287 | + $user_name = Sensei()->learners->get_learner_full_name($_GET['user_id']); |
|
| 288 | + $title .= ' <span class="user-title">> '.$user_name.'</span>'; |
|
| 289 | 289 | |
| 290 | 290 | } // End If Statement |
| 291 | 291 | ?> |
| 292 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> |
|
| 292 | + <h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> |
|
| 293 | 293 | <?php |
| 294 | 294 | } // End grading_default_nav() |
| 295 | 295 | |
@@ -301,29 +301,29 @@ discard block |
||
| 301 | 301 | public function grading_user_quiz_nav() { |
| 302 | 302 | global $wp_version; |
| 303 | 303 | |
| 304 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); |
|
| 305 | - if ( isset( $_GET['quiz_id'] ) ) { |
|
| 306 | - $quiz_id = intval( $_GET['quiz_id'] ); |
|
| 307 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 308 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 309 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 310 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
| 311 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
| 304 | + $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); |
|
| 305 | + if (isset($_GET['quiz_id'])) { |
|
| 306 | + $quiz_id = intval($_GET['quiz_id']); |
|
| 307 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 308 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 309 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 310 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
| 311 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
| 312 | 312 | } |
| 313 | 313 | else { |
| 314 | - $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
|
| 314 | + $title .= sprintf(' <span class="course-title">> %s</span>', get_the_title($course_id)); |
|
| 315 | 315 | } |
| 316 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); |
|
| 317 | - $title .= sprintf( ' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) ); |
|
| 316 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php')); |
|
| 317 | + $title .= sprintf(' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id)); |
|
| 318 | 318 | } |
| 319 | - if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
|
| 319 | + if (isset($_GET['user']) && 0 < intval($_GET['user'])) { |
|
| 320 | 320 | |
| 321 | - $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] ); |
|
| 322 | - $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
|
| 321 | + $user_name = Sensei()->learners->get_learner_full_name($_GET['user']); |
|
| 322 | + $title .= ' <span class="user-title">> '.$user_name.'</span>'; |
|
| 323 | 323 | |
| 324 | 324 | } // End If Statement |
| 325 | 325 | ?> |
| 326 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> |
|
| 326 | + <h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> |
|
| 327 | 327 | <?php |
| 328 | 328 | } // End grading_user_quiz_nav() |
| 329 | 329 | |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | * @since 1.7.0 |
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | - public function get_stati( $type ) { |
|
| 335 | + public function get_stati($type) { |
|
| 336 | 336 | $statuses = array(); |
| 337 | - switch( $type ) { |
|
| 337 | + switch ($type) { |
|
| 338 | 338 | case 'course' : |
| 339 | 339 | $statuses = array( |
| 340 | 340 | 'in-progress', |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @param array $args (default: array()) |
| 365 | 365 | * @return object |
| 366 | 366 | */ |
| 367 | - public function count_statuses( $args = array() ) { |
|
| 367 | + public function count_statuses($args = array()) { |
|
| 368 | 368 | global $wpdb; |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -375,71 +375,71 @@ discard block |
||
| 375 | 375 | * @since 1.8.0 |
| 376 | 376 | * @param array $args |
| 377 | 377 | */ |
| 378 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 378 | + $args = apply_filters('sensei_count_statuses_args', $args); |
|
| 379 | 379 | |
| 380 | - if ( 'course' == $args['type'] ) { |
|
| 380 | + if ('course' == $args['type']) { |
|
| 381 | 381 | $type = 'sensei_course_status'; |
| 382 | 382 | } |
| 383 | 383 | else { |
| 384 | 384 | $type = 'sensei_lesson_status'; |
| 385 | 385 | } |
| 386 | - $cache_key = 'sensei-' . $args['type'] . '-statuses'; |
|
| 386 | + $cache_key = 'sensei-'.$args['type'].'-statuses'; |
|
| 387 | 387 | |
| 388 | 388 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
| 389 | 389 | |
| 390 | 390 | // Restrict to specific posts |
| 391 | - if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
|
| 392 | - $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
|
| 391 | + if (isset($args['post__in']) && ! empty($args['post__in']) && is_array($args['post__in'])) { |
|
| 392 | + $query .= ' AND comment_post_ID IN ('.implode(',', array_map('absint', $args['post__in'])).')'; |
|
| 393 | 393 | } |
| 394 | - elseif ( !empty( $args['post_id'] ) ) { |
|
| 395 | - $query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] ); |
|
| 394 | + elseif ( ! empty($args['post_id'])) { |
|
| 395 | + $query .= $wpdb->prepare(' AND comment_post_ID = %d', $args['post_id']); |
|
| 396 | 396 | } |
| 397 | 397 | // Restrict to specific users |
| 398 | - if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) { |
|
| 399 | - $query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')'; |
|
| 398 | + if (isset($args['user_id']) && is_array($args['user_id'])) { |
|
| 399 | + $query .= ' AND user_id IN ('.implode(',', array_map('absint', $args['user_id'])).')'; |
|
| 400 | 400 | } |
| 401 | - elseif ( !empty( $args['user_id'] ) ) { |
|
| 402 | - $query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] ); |
|
| 401 | + elseif ( ! empty($args['user_id'])) { |
|
| 402 | + $query .= $wpdb->prepare(' AND user_id = %d', $args['user_id']); |
|
| 403 | 403 | } |
| 404 | 404 | $query .= ' GROUP BY comment_approved'; |
| 405 | 405 | |
| 406 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
| 407 | - if ( false === $counts ) { |
|
| 408 | - $sql = $wpdb->prepare( $query, $type ); |
|
| 409 | - $results = (array) $wpdb->get_results( $sql, ARRAY_A ); |
|
| 410 | - $counts = array_fill_keys( $this->get_stati( $type ), 0 ); |
|
| 406 | + $counts = wp_cache_get($cache_key, 'counts'); |
|
| 407 | + if (false === $counts) { |
|
| 408 | + $sql = $wpdb->prepare($query, $type); |
|
| 409 | + $results = (array) $wpdb->get_results($sql, ARRAY_A); |
|
| 410 | + $counts = array_fill_keys($this->get_stati($type), 0); |
|
| 411 | 411 | |
| 412 | - foreach ( $results as $row ) { |
|
| 413 | - $counts[ $row['comment_approved'] ] = $row['total']; |
|
| 412 | + foreach ($results as $row) { |
|
| 413 | + $counts[$row['comment_approved']] = $row['total']; |
|
| 414 | 414 | } |
| 415 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
| 415 | + wp_cache_set($cache_key, $counts, 'counts'); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if( ! isset( $counts['graded'] ) ) { |
|
| 418 | + if ( ! isset($counts['graded'])) { |
|
| 419 | 419 | $counts['graded'] = 0; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - if( ! isset( $counts['ungraded'] ) ) { |
|
| 422 | + if ( ! isset($counts['ungraded'])) { |
|
| 423 | 423 | $counts['ungraded'] = 0; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if( ! isset( $counts['passed'] ) ) { |
|
| 426 | + if ( ! isset($counts['passed'])) { |
|
| 427 | 427 | $counts['passed'] = 0; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if( ! isset( $counts['failed'] ) ) { |
|
| 430 | + if ( ! isset($counts['failed'])) { |
|
| 431 | 431 | $counts['failed'] = 0; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if( ! isset( $counts['in-progress'] ) ) { |
|
| 434 | + if ( ! isset($counts['in-progress'])) { |
|
| 435 | 435 | $counts['in-progress'] = 0; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if( ! isset( $counts['complete'] ) ) { |
|
| 438 | + if ( ! isset($counts['complete'])) { |
|
| 439 | 439 | $counts['complete'] = 0; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - return apply_filters( 'sensei_count_statuses', $counts, $type ); |
|
| 442 | + return apply_filters('sensei_count_statuses', $counts, $type); |
|
| 443 | 443 | } // End sensei_count_statuses() |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -447,11 +447,11 @@ discard block |
||
| 447 | 447 | * @since 1.7.0 |
| 448 | 448 | * @return string |
| 449 | 449 | */ |
| 450 | - public function courses_drop_down_html( $selected_course_id = 0 ) { |
|
| 450 | + public function courses_drop_down_html($selected_course_id = 0) { |
|
| 451 | 451 | |
| 452 | 452 | $html = ''; |
| 453 | 453 | |
| 454 | - $course_args = array( 'post_type' => 'course', |
|
| 454 | + $course_args = array('post_type' => 'course', |
|
| 455 | 455 | 'posts_per_page' => -1, |
| 456 | 456 | 'orderby' => 'title', |
| 457 | 457 | 'order' => 'ASC', |
@@ -459,12 +459,12 @@ discard block |
||
| 459 | 459 | 'suppress_filters' => 0, |
| 460 | 460 | 'fields' => 'ids', |
| 461 | 461 | ); |
| 462 | - $courses = get_posts( apply_filters( 'sensei_grading_filter_courses', $course_args ) ); |
|
| 462 | + $courses = get_posts(apply_filters('sensei_grading_filter_courses', $course_args)); |
|
| 463 | 463 | |
| 464 | - $html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>'; |
|
| 465 | - if ( count( $courses ) > 0 ) { |
|
| 466 | - foreach ($courses as $course_id){ |
|
| 467 | - $html .= '<option value="' . esc_attr( absint( $course_id ) ) . '" ' . selected( $course_id, $selected_course_id, false ) . '>' . esc_html( get_the_title( $course_id ) ) . '</option>' . "\n"; |
|
| 464 | + $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'; |
|
| 465 | + if (count($courses) > 0) { |
|
| 466 | + foreach ($courses as $course_id) { |
|
| 467 | + $html .= '<option value="'.esc_attr(absint($course_id)).'" '.selected($course_id, $selected_course_id, false).'>'.esc_html(get_the_title($course_id)).'</option>'."\n"; |
|
| 468 | 468 | } // End For Loop |
| 469 | 469 | } // End If Statement |
| 470 | 470 | |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | $course_data = array(); |
| 486 | 486 | parse_str($data, $course_data); |
| 487 | 487 | |
| 488 | - $course_id = intval( $course_data['course_id'] ); |
|
| 488 | + $course_id = intval($course_data['course_id']); |
|
| 489 | 489 | |
| 490 | - $html = $this->lessons_drop_down_html( $course_id ); |
|
| 490 | + $html = $this->lessons_drop_down_html($course_id); |
|
| 491 | 491 | |
| 492 | 492 | echo $html; |
| 493 | 493 | die(); // WordPress may print out a spurious zero without this can be particularly bad if using JSON |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - public function lessons_drop_down_html( $course_id = 0, $selected_lesson_id = 0 ) { |
|
| 496 | + public function lessons_drop_down_html($course_id = 0, $selected_lesson_id = 0) { |
|
| 497 | 497 | |
| 498 | 498 | $html = ''; |
| 499 | - if ( 0 < intval( $course_id ) ) { |
|
| 499 | + if (0 < intval($course_id)) { |
|
| 500 | 500 | |
| 501 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 501 | + $lesson_args = array('post_type' => 'lesson', |
|
| 502 | 502 | 'posts_per_page' => -1, |
| 503 | 503 | 'orderby' => 'title', |
| 504 | 504 | 'order' => 'ASC', |
@@ -508,12 +508,12 @@ discard block |
||
| 508 | 508 | 'suppress_filters' => 0, |
| 509 | 509 | 'fields' => 'ids', |
| 510 | 510 | ); |
| 511 | - $lessons = get_posts( apply_filters( 'sensei_grading_filter_lessons', $lesson_args ) ); |
|
| 511 | + $lessons = get_posts(apply_filters('sensei_grading_filter_lessons', $lesson_args)); |
|
| 512 | 512 | |
| 513 | - $html .= '<option value="">' . __( 'Select a lesson', 'woothemes-sensei' ) . '</option>'; |
|
| 514 | - if ( count( $lessons ) > 0 ) { |
|
| 515 | - foreach ( $lessons as $lesson_id ){ |
|
| 516 | - $html .= '<option value="' . esc_attr( absint( $lesson_id ) ) . '" ' . selected( $lesson_id, $selected_lesson_id, false ) . '>' . esc_html( get_the_title( $lesson_id ) ) . '</option>' . "\n"; |
|
| 513 | + $html .= '<option value="">'.__('Select a lesson', 'woothemes-sensei').'</option>'; |
|
| 514 | + if (count($lessons) > 0) { |
|
| 515 | + foreach ($lessons as $lesson_id) { |
|
| 516 | + $html .= '<option value="'.esc_attr(absint($lesson_id)).'" '.selected($lesson_id, $selected_lesson_id, false).'>'.esc_html(get_the_title($lesson_id)).'</option>'."\n"; |
|
| 517 | 517 | } // End For Loop |
| 518 | 518 | } // End If Statement |
| 519 | 519 | |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | public function admin_process_grading_submission() { |
| 535 | 535 | |
| 536 | 536 | // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
| 537 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | - || ! isset( $_GET['quiz_id'] ) |
|
| 540 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 537 | + if ( ! isset($_POST['sensei_manual_grade']) |
|
| 538 | + || ! wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading') |
|
| 539 | + || ! isset($_GET['quiz_id']) |
|
| 540 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade']) { |
|
| 541 | 541 | |
| 542 | 542 | return false; //exit and do not grade |
| 543 | 543 | |
@@ -547,30 +547,30 @@ discard block |
||
| 547 | 547 | $user_id = $_GET['user']; |
| 548 | 548 | |
| 549 | 549 | |
| 550 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 550 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 551 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 552 | 552 | $quiz_grade = 0; |
| 553 | 553 | $count = 0; |
| 554 | 554 | $quiz_grade_total = $_POST['quiz_grade_total']; |
| 555 | 555 | $all_question_grades = array(); |
| 556 | 556 | $all_answers_feedback = array(); |
| 557 | 557 | |
| 558 | - foreach( $questions as $question ) { |
|
| 558 | + foreach ($questions as $question) { |
|
| 559 | 559 | |
| 560 | 560 | ++$count; |
| 561 | 561 | $question_id = $question->ID; |
| 562 | 562 | |
| 563 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 563 | + if (isset($_POST['question_'.$question_id])) { |
|
| 564 | 564 | |
| 565 | 565 | $question_grade = 0; |
| 566 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 566 | + if ($_POST['question_'.$question_id] == 'right') { |
|
| 567 | 567 | |
| 568 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 568 | + $question_grade = $_POST['question_'.$question_id.'_grade']; |
|
| 569 | 569 | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | // add data to the array that will, after the loop, be stored on the lesson status |
| 573 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 573 | + $all_question_grades[$question_id] = $question_grade; |
|
| 574 | 574 | |
| 575 | 575 | // tally up the total quiz grade |
| 576 | 576 | $quiz_grade += $question_grade; |
@@ -579,41 +579,41 @@ discard block |
||
| 579 | 579 | |
| 580 | 580 | // Question answer feedback / notes |
| 581 | 581 | $question_feedback = ''; |
| 582 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 582 | + if (isset($_POST['questions_feedback'][$question_id])) { |
|
| 583 | 583 | |
| 584 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 584 | + $question_feedback = wp_unslash($_POST['questions_feedback'][$question_id]); |
|
| 585 | 585 | |
| 586 | 586 | } |
| 587 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 587 | + $all_answers_feedback[$question_id] = $question_feedback; |
|
| 588 | 588 | |
| 589 | 589 | } // end for each $questions |
| 590 | 590 | |
| 591 | 591 | //store all question grades on the lesson status |
| 592 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 592 | + Sensei()->quiz->set_user_grades($all_question_grades, $quiz_lesson_id, $user_id); |
|
| 593 | 593 | |
| 594 | 594 | //store the feedback from grading |
| 595 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 595 | + Sensei()->quiz->save_user_answers_feedback($all_answers_feedback, $quiz_lesson_id, $user_id); |
|
| 596 | 596 | |
| 597 | 597 | // $_POST['all_questions_graded'] is set when all questions have been graded |
| 598 | 598 | // in the class sensei grading user quiz -> display() |
| 599 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 599 | + if ($_POST['all_questions_graded'] == 'yes') { |
|
| 600 | 600 | |
| 601 | 601 | // set the users total quiz grade |
| 602 | - if ( 0 < intval( $quiz_grade_total ) ) { |
|
| 603 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 602 | + if (0 < intval($quiz_grade_total)) { |
|
| 603 | + $grade = abs(round((doubleval($quiz_grade) * 100) / ($quiz_grade_total), 2)); |
|
| 604 | 604 | } |
| 605 | 605 | else { |
| 606 | 606 | $grade = 0; |
| 607 | 607 | } |
| 608 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 608 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id); |
|
| 609 | 609 | |
| 610 | 610 | // Duplicating what Frontend->sensei_complete_quiz() does |
| 611 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 611 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 612 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 613 | 613 | $lesson_metadata = array(); |
| 614 | - if ( $pass_required ) { |
|
| 614 | + if ($pass_required) { |
|
| 615 | 615 | // Student has reached the pass mark and lesson is complete |
| 616 | - if ( $quiz_passmark <= $grade ) { |
|
| 616 | + if ($quiz_passmark <= $grade) { |
|
| 617 | 617 | $lesson_status = 'passed'; |
| 618 | 618 | } |
| 619 | 619 | else { |
@@ -626,9 +626,9 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
| 628 | 628 | |
| 629 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 629 | + Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata); |
|
| 630 | 630 | |
| 631 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 631 | + if (in_array($lesson_status, array('passed', 'graded'))) { |
|
| 632 | 632 | |
| 633 | 633 | /** |
| 634 | 634 | * Summary. |
@@ -640,27 +640,27 @@ discard block |
||
| 640 | 640 | * @param int $user_id |
| 641 | 641 | * @param int $quiz_lesson_id |
| 642 | 642 | */ |
| 643 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 643 | + do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id); |
|
| 644 | 644 | |
| 645 | 645 | } // end if in_array |
| 646 | 646 | |
| 647 | 647 | }// end if $_POST['all_que... |
| 648 | 648 | |
| 649 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 649 | + if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) { |
|
| 650 | 650 | |
| 651 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 651 | + $load_url = add_query_arg(array('message' => 'graded')); |
|
| 652 | 652 | |
| 653 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 653 | + } elseif (isset($_POST['_wp_http_referer'])) { |
|
| 654 | 654 | |
| 655 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 655 | + $load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']); |
|
| 656 | 656 | |
| 657 | 657 | } else { |
| 658 | 658 | |
| 659 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 659 | + $load_url = add_query_arg(array('message' => 'graded')); |
|
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 663 | + wp_safe_redirect(esc_url_raw($load_url)); |
|
| 664 | 664 | exit; |
| 665 | 665 | |
| 666 | 666 | } // end admin_process_grading_submission |
@@ -671,13 +671,13 @@ discard block |
||
| 671 | 671 | $lesson_data = array(); |
| 672 | 672 | parse_str($data, $lesson_data); |
| 673 | 673 | |
| 674 | - $lesson_id = intval( $lesson_data['lesson_id'] ); |
|
| 675 | - $course_id = intval( $lesson_data['course_id'] ); |
|
| 676 | - $grading_view = sanitize_text_field( $lesson_data['view'] ); |
|
| 674 | + $lesson_id = intval($lesson_data['lesson_id']); |
|
| 675 | + $course_id = intval($lesson_data['course_id']); |
|
| 676 | + $grading_view = sanitize_text_field($lesson_data['view']); |
|
| 677 | 677 | |
| 678 | 678 | $redirect_url = ''; |
| 679 | - if ( 0 < $lesson_id && 0 < $course_id ) { |
|
| 680 | - $redirect_url = esc_url_raw( apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view ), admin_url( 'admin.php' ) ) ) ); |
|
| 679 | + if (0 < $lesson_id && 0 < $course_id) { |
|
| 680 | + $redirect_url = esc_url_raw(apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view), admin_url('admin.php')))); |
|
| 681 | 681 | } // End If Statement |
| 682 | 682 | |
| 683 | 683 | echo $redirect_url; |
@@ -685,11 +685,11 @@ discard block |
||
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | public function add_grading_notices() { |
| 688 | - if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) { |
|
| 689 | - if( 'graded' == $_GET['message'] ) { |
|
| 688 | + if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) { |
|
| 689 | + if ('graded' == $_GET['message']) { |
|
| 690 | 690 | $msg = array( |
| 691 | 691 | 'updated', |
| 692 | - __( 'Quiz Graded Successfully!', 'woothemes-sensei' ), |
|
| 692 | + __('Quiz Graded Successfully!', 'woothemes-sensei'), |
|
| 693 | 693 | ); |
| 694 | 694 | } |
| 695 | 695 | ?> |
@@ -701,9 +701,9 @@ discard block |
||
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | public function sensei_grading_notices() { |
| 704 | - if ( isset( $_GET['action'] ) && 'graded' == $_GET['action'] ) { |
|
| 704 | + if (isset($_GET['action']) && 'graded' == $_GET['action']) { |
|
| 705 | 705 | echo '<div class="grading-notice updated">'; |
| 706 | - echo '<p>' . __( 'Quiz Graded Successfully!', 'woothemes-sensei' ) . '</p>'; |
|
| 706 | + echo '<p>'.__('Quiz Graded Successfully!', 'woothemes-sensei').'</p>'; |
|
| 707 | 707 | echo '</div>'; |
| 708 | 708 | } // End If Statement |
| 709 | 709 | } // End sensei_grading_notices() |
@@ -726,16 +726,16 @@ discard block |
||
| 726 | 726 | * |
| 727 | 727 | * @return int $quiz_grade total sum of all question grades |
| 728 | 728 | */ |
| 729 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 729 | + public static function grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
| 730 | 730 | |
| 731 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | - || $quiz_grade_type != 'auto' ) { |
|
| 731 | + if ( ! (intval($quiz_id) > 0) || ! $submitted |
|
| 732 | + || $quiz_grade_type != 'auto') { |
|
| 733 | 733 | return false; // exit early |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | |
| 737 | 737 | $user_id = get_current_user_id(); |
| 738 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 738 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 739 | 739 | $quiz_autogradable = true; |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -749,23 +749,23 @@ discard block |
||
| 749 | 749 | * 'gap-fill'. |
| 750 | 750 | * } |
| 751 | 751 | */ |
| 752 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 752 | + $autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill')); |
|
| 753 | 753 | |
| 754 | 754 | $grade_total = 0; |
| 755 | 755 | $all_question_grades = array(); |
| 756 | - foreach( $submitted as $question_id => $answer ) { |
|
| 756 | + foreach ($submitted as $question_id => $answer) { |
|
| 757 | 757 | |
| 758 | 758 | // check if the question is autogradable, either by type, or because the grade is 0 |
| 759 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 760 | - $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
| 760 | + $achievable_grade = Sensei()->question->get_question_grade($question_id); |
|
| 761 | 761 | // Question has a zero grade, so skip grading |
| 762 | - if ( 0 == $achievable_grade ) { |
|
| 763 | - $all_question_grades[ $question_id ] = $achievable_grade; |
|
| 762 | + if (0 == $achievable_grade) { |
|
| 763 | + $all_question_grades[$question_id] = $achievable_grade; |
|
| 764 | 764 | } |
| 765 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 765 | + elseif (in_array($question_type, $autogradable_question_types)) { |
|
| 766 | 766 | // Get user question grade |
| 767 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 767 | + $question_grade = Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
| 768 | + $all_question_grades[$question_id] = $question_grade; |
|
| 769 | 769 | $grade_total += $question_grade; |
| 770 | 770 | |
| 771 | 771 | } else { |
@@ -778,27 +778,27 @@ discard block |
||
| 778 | 778 | }// end for each question |
| 779 | 779 | |
| 780 | 780 | // Only if the whole quiz was autogradable do we set a grade |
| 781 | - if ( $quiz_autogradable ) { |
|
| 781 | + if ($quiz_autogradable) { |
|
| 782 | 782 | |
| 783 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 783 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total($quiz_id); |
|
| 784 | 784 | // Check for zero total from grades |
| 785 | - if ( 0 < $quiz_total ) { |
|
| 786 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 785 | + if (0 < $quiz_total) { |
|
| 786 | + $grade = abs(round((doubleval($grade_total) * 100) / ($quiz_total), 2)); |
|
| 787 | 787 | } |
| 788 | 788 | else { |
| 789 | 789 | $grade = 0; |
| 790 | 790 | } |
| 791 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 791 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type); |
|
| 792 | 792 | |
| 793 | 793 | } else { |
| 794 | 794 | |
| 795 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 795 | + $grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei')); |
|
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
| 800 | 800 | // when doing manual grading. |
| 801 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 801 | + Sensei()->quiz-> set_user_grades($all_question_grades, $lesson_id, $user_id); |
|
| 802 | 802 | |
| 803 | 803 | return $grade; |
| 804 | 804 | |
@@ -818,22 +818,22 @@ discard block |
||
| 818 | 818 | * |
| 819 | 819 | * @return int $question_grade |
| 820 | 820 | */ |
| 821 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 821 | + public static function grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
| 822 | 822 | |
| 823 | - if( intval( $user_id ) == 0 ) { |
|
| 823 | + if (intval($user_id) == 0) { |
|
| 824 | 824 | |
| 825 | 825 | $user_id = get_current_user_id(); |
| 826 | 826 | |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 829 | + if ( ! (intval($question_id) > 0)) { |
|
| 830 | 830 | |
| 831 | 831 | return false; |
| 832 | 832 | |
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | |
| 836 | - Sensei()->question->get_question_type( $question_id ); |
|
| 836 | + Sensei()->question->get_question_type($question_id); |
|
| 837 | 837 | |
| 838 | 838 | /** |
| 839 | 839 | * Applying a grade before the auto grading takes place. |
@@ -847,42 +847,42 @@ discard block |
||
| 847 | 847 | * @param string $question_type one of the Sensei question type. |
| 848 | 848 | * @param string $answer user supplied question answer |
| 849 | 849 | */ |
| 850 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 850 | + $question_grade = apply_filters('sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer); |
|
| 851 | 851 | |
| 852 | - if ( false !== $question_grade ) { |
|
| 852 | + if (false !== $question_grade) { |
|
| 853 | 853 | |
| 854 | 854 | return $question_grade; |
| 855 | 855 | |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | // auto grading core |
| 859 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 859 | + if (in_array($question_type, array('multiple-choice', 'boolean'))) { |
|
| 860 | 860 | |
| 861 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 861 | + $right_answer = (array) get_post_meta($question_id, '_question_right_answer', true); |
|
| 862 | 862 | |
| 863 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | - $answer = wp_unslash( $answer ); |
|
| 863 | + if (0 == get_magic_quotes_gpc()) { |
|
| 864 | + $answer = wp_unslash($answer); |
|
| 865 | 865 | } |
| 866 | 866 | $answer = (array) $answer; |
| 867 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 867 | + if (is_array($right_answer) && count($right_answer) == count($answer)) { |
|
| 868 | 868 | // Loop through all answers ensure none are 'missing' |
| 869 | 869 | $all_correct = true; |
| 870 | - foreach ( $answer as $check_answer ) { |
|
| 871 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 870 | + foreach ($answer as $check_answer) { |
|
| 871 | + if ( ! in_array($check_answer, $right_answer)) { |
|
| 872 | 872 | $all_correct = false; |
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | 875 | // If all correct then grade |
| 876 | - if ( $all_correct ) { |
|
| 877 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 876 | + if ($all_correct) { |
|
| 877 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
| 878 | 878 | } |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - } elseif( 'gap-fill' == $question_type ){ |
|
| 881 | + } elseif ('gap-fill' == $question_type) { |
|
| 882 | 882 | |
| 883 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 883 | + $question_grade = self::grade_gap_fill_question($question_id, $answer); |
|
| 884 | 884 | |
| 885 | - } else{ |
|
| 885 | + } else { |
|
| 886 | 886 | |
| 887 | 887 | /** |
| 888 | 888 | * Grading questions that are not auto gradable. |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | * @param string $question_type one of the Sensei question type. |
| 896 | 896 | * @param string $answer user supplied question answer |
| 897 | 897 | */ |
| 898 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 898 | + $question_grade = (int) apply_filters('sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer); |
|
| 899 | 899 | |
| 900 | 900 | } // end if $question_type |
| 901 | 901 | |
@@ -911,13 +911,13 @@ discard block |
||
| 911 | 911 | * |
| 912 | 912 | * @return bool | int false or the grade given to the user answer |
| 913 | 913 | */ |
| 914 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 914 | + public static function grade_gap_fill_question($question_id, $user_answer) { |
|
| 915 | 915 | |
| 916 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | - $gapfill_array = explode( '||', $right_answer ); |
|
| 916 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 917 | + $gapfill_array = explode('||', $right_answer); |
|
| 918 | 918 | |
| 919 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | - $user_answer = wp_unslash( $user_answer ); |
|
| 919 | + if (0 == get_magic_quotes_gpc()) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | + $user_answer = wp_unslash($user_answer); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /** |
@@ -930,53 +930,53 @@ discard block |
||
| 930 | 930 | * |
| 931 | 931 | * @since 1.9.0 |
| 932 | 932 | */ |
| 933 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 933 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false); |
|
| 934 | 934 | |
| 935 | - if( $do_case_sensitive_comparison ){ |
|
| 935 | + if ($do_case_sensitive_comparison) { |
|
| 936 | 936 | |
| 937 | 937 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
| 938 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 938 | + if (trim(($gapfill_array[1])) == trim($user_answer)) { |
|
| 939 | 939 | |
| 940 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 940 | + return Sensei()->question->get_question_grade($question_id); |
|
| 941 | 941 | |
| 942 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 942 | + } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { |
|
| 943 | 943 | |
| 944 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 944 | + if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { |
|
| 945 | 945 | |
| 946 | 946 | return Sensei()->question->get_question_grade($question_id); |
| 947 | 947 | |
| 948 | - }else{ |
|
| 948 | + } else { |
|
| 949 | 949 | |
| 950 | 950 | return false; |
| 951 | 951 | |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | - }else{ |
|
| 954 | + } else { |
|
| 955 | 955 | |
| 956 | 956 | return false; |
| 957 | 957 | |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - }else{ |
|
| 960 | + } else { |
|
| 961 | 961 | |
| 962 | 962 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
| 963 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 963 | + if (trim(strtolower($gapfill_array[1])) == trim(strtolower($user_answer))) { |
|
| 964 | 964 | |
| 965 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 965 | + return Sensei()->question->get_question_grade($question_id); |
|
| 966 | 966 | |
| 967 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 967 | + } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { |
|
| 968 | 968 | |
| 969 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 969 | + if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { |
|
| 970 | 970 | |
| 971 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 971 | + return Sensei()->question->get_question_grade($question_id); |
|
| 972 | 972 | |
| 973 | - }else{ |
|
| 973 | + } else { |
|
| 974 | 974 | |
| 975 | 975 | return false; |
| 976 | 976 | |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - }else{ |
|
| 979 | + } else { |
|
| 980 | 980 | |
| 981 | 981 | return false; |
| 982 | 982 | |
@@ -993,4 +993,4 @@ discard block |
||
| 993 | 993 | * for backward compatibility |
| 994 | 994 | * @since 1.9.0 |
| 995 | 995 | */ |
| 996 | -class WooThemes_Sensei_Grading extends Sensei_Grading{} |
|
| 996 | +class WooThemes_Sensei_Grading extends Sensei_Grading {} |
|
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Analysis Lesson List Table Class |
@@ -22,18 +22,18 @@ discard block |
||
| 22 | 22 | * @since 1.2.0 |
| 23 | 23 | * @return void |
| 24 | 24 | */ |
| 25 | - public function __construct ( $lesson_id = 0 ) { |
|
| 26 | - $this->lesson_id = intval( $lesson_id ); |
|
| 27 | - $this->course_id = intval( get_post_meta( $this->lesson_id, '_lesson_course', true ) ); |
|
| 25 | + public function __construct($lesson_id = 0) { |
|
| 26 | + $this->lesson_id = intval($lesson_id); |
|
| 27 | + $this->course_id = intval(get_post_meta($this->lesson_id, '_lesson_course', true)); |
|
| 28 | 28 | |
| 29 | 29 | // Load Parent token into constructor |
| 30 | - parent::__construct( 'analysis_lesson' ); |
|
| 30 | + parent::__construct('analysis_lesson'); |
|
| 31 | 31 | |
| 32 | 32 | // Actions |
| 33 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
| 34 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
| 33 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
| 34 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
| 35 | 35 | |
| 36 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
| 36 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
| 37 | 37 | } // End __construct() |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function get_columns() { |
| 45 | 45 | $columns = array( |
| 46 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
| 47 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
| 48 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
| 49 | - 'status' => __( 'Status', 'woothemes-sensei' ), |
|
| 50 | - 'grade' => __( 'Grade', 'woothemes-sensei' ), |
|
| 46 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
| 47 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
| 48 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
| 49 | + 'status' => __('Status', 'woothemes-sensei'), |
|
| 50 | + 'grade' => __('Grade', 'woothemes-sensei'), |
|
| 51 | 51 | ); |
| 52 | - $columns = apply_filters( 'sensei_analysis_lesson_columns', $columns, $this ); |
|
| 52 | + $columns = apply_filters('sensei_analysis_lesson_columns', $columns, $this); |
|
| 53 | 53 | return $columns; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function get_sortable_columns() { |
| 62 | 62 | $columns = array( |
| 63 | - 'title' => array( 'title', false ), |
|
| 64 | - 'started' => array( 'started', false ), |
|
| 65 | - 'completed' => array( 'completed', false ), |
|
| 66 | - 'status' => array( 'status', false ), |
|
| 67 | - 'grade' => array( 'grade', false ), |
|
| 63 | + 'title' => array('title', false), |
|
| 64 | + 'started' => array('started', false), |
|
| 65 | + 'completed' => array('completed', false), |
|
| 66 | + 'status' => array('status', false), |
|
| 67 | + 'grade' => array('grade', false), |
|
| 68 | 68 | ); |
| 69 | - $columns = apply_filters( 'sensei_analysis_lesson_columns_sortable', $columns, $this ); |
|
| 69 | + $columns = apply_filters('sensei_analysis_lesson_columns_sortable', $columns, $this); |
|
| 70 | 70 | return $columns; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -80,32 +80,32 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | // Handle orderby (needs work) |
| 82 | 82 | $orderby = ''; |
| 83 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 84 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 85 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 83 | + if ( ! empty($_GET['orderby'])) { |
|
| 84 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 85 | + $orderby = esc_html($_GET['orderby']); |
|
| 86 | 86 | } // End If Statement |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Handle order |
| 90 | 90 | $order = 'ASC'; |
| 91 | - if ( !empty( $_GET['order'] ) ) { |
|
| 92 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 91 | + if ( ! empty($_GET['order'])) { |
|
| 92 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Handle search, need 4.1 version of WP to be able to restrict statuses to known post_ids |
| 96 | 96 | $search = false; |
| 97 | - if ( !empty( $_GET['s'] ) ) { |
|
| 98 | - $search = esc_html( $_GET['s'] ); |
|
| 97 | + if ( ! empty($_GET['s'])) { |
|
| 98 | + $search = esc_html($_GET['s']); |
|
| 99 | 99 | } // End If Statement |
| 100 | 100 | $this->search = $search; |
| 101 | 101 | |
| 102 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
| 103 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
| 102 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
| 103 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
| 104 | 104 | |
| 105 | 105 | $paged = $this->get_pagenum(); |
| 106 | 106 | $offset = 0; |
| 107 | - if ( !empty($paged) ) { |
|
| 108 | - $offset = $per_page * ( $paged - 1 ); |
|
| 107 | + if ( ! empty($paged)) { |
|
| 108 | + $offset = $per_page * ($paged - 1); |
|
| 109 | 109 | } // End If Statement |
| 110 | 110 | |
| 111 | 111 | $args = array( |
@@ -114,19 +114,19 @@ discard block |
||
| 114 | 114 | 'orderby' => $orderby, |
| 115 | 115 | 'order' => $order, |
| 116 | 116 | ); |
| 117 | - if ( $this->search ) { |
|
| 117 | + if ($this->search) { |
|
| 118 | 118 | $args['search'] = $this->search; |
| 119 | 119 | } // End If Statement |
| 120 | 120 | |
| 121 | - $this->items = $this->get_lesson_statuses( $args ); |
|
| 121 | + $this->items = $this->get_lesson_statuses($args); |
|
| 122 | 122 | |
| 123 | 123 | $total_items = $this->total_items; |
| 124 | - $total_pages = ceil( $total_items / $per_page ); |
|
| 125 | - $this->set_pagination_args( array( |
|
| 124 | + $total_pages = ceil($total_items / $per_page); |
|
| 125 | + $this->set_pagination_args(array( |
|
| 126 | 126 | 'total_items' => $total_items, |
| 127 | 127 | 'total_pages' => $total_pages, |
| 128 | 128 | 'per_page' => $per_page |
| 129 | - ) ); |
|
| 129 | + )); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @since 1.7.0 |
| 135 | 135 | * @return data |
| 136 | 136 | */ |
| 137 | - public function generate_report( $report ) { |
|
| 137 | + public function generate_report($report) { |
|
| 138 | 138 | |
| 139 | 139 | $data = array(); |
| 140 | 140 | |
@@ -142,22 +142,22 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | // Handle orderby |
| 144 | 144 | $orderby = ''; |
| 145 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 146 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 147 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 145 | + if ( ! empty($_GET['orderby'])) { |
|
| 146 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 147 | + $orderby = esc_html($_GET['orderby']); |
|
| 148 | 148 | } // End If Statement |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Handle order |
| 152 | 152 | $order = 'ASC'; |
| 153 | - if ( !empty( $_GET['order'] ) ) { |
|
| 154 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 153 | + if ( ! empty($_GET['order'])) { |
|
| 154 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Handle search |
| 158 | 158 | $search = false; |
| 159 | - if ( !empty( $_GET['s'] ) ) { |
|
| 160 | - $search = esc_html( $_GET['s'] ); |
|
| 159 | + if ( ! empty($_GET['s'])) { |
|
| 160 | + $search = esc_html($_GET['s']); |
|
| 161 | 161 | } // End If Statement |
| 162 | 162 | $this->search = $search; |
| 163 | 163 | |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | 'orderby' => $orderby, |
| 166 | 166 | 'order' => $order, |
| 167 | 167 | ); |
| 168 | - if ( $this->search ) { |
|
| 168 | + if ($this->search) { |
|
| 169 | 169 | $args['search'] = $this->search; |
| 170 | 170 | } // End If Statement |
| 171 | 171 | |
| 172 | 172 | // Start the csv with the column headings |
| 173 | 173 | $column_headers = array(); |
| 174 | 174 | $columns = $this->get_columns(); |
| 175 | - foreach( $columns AS $key => $title ) { |
|
| 175 | + foreach ($columns AS $key => $title) { |
|
| 176 | 176 | $column_headers[] = $title; |
| 177 | 177 | } |
| 178 | 178 | $data[] = $column_headers; |
| 179 | 179 | |
| 180 | - $this->items = $this->get_lesson_statuses( $args ); |
|
| 180 | + $this->items = $this->get_lesson_statuses($args); |
|
| 181 | 181 | |
| 182 | 182 | // Process each row |
| 183 | - foreach( $this->items AS $item) { |
|
| 184 | - $data[] = $this->get_row_data( $item ); |
|
| 183 | + foreach ($this->items AS $item) { |
|
| 184 | + $data[] = $this->get_row_data($item); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | return $data; |
@@ -193,64 +193,64 @@ discard block |
||
| 193 | 193 | * @since 1.7.0 |
| 194 | 194 | * @param object $item The current item |
| 195 | 195 | */ |
| 196 | - protected function get_row_data( $item ) { |
|
| 196 | + protected function get_row_data($item) { |
|
| 197 | 197 | |
| 198 | - $user_start_date = get_comment_meta( $item->comment_ID, 'start', true ); |
|
| 198 | + $user_start_date = get_comment_meta($item->comment_ID, 'start', true); |
|
| 199 | 199 | $user_end_date = $item->comment_date; |
| 200 | 200 | $status_class = $grade = ''; |
| 201 | 201 | |
| 202 | - if( 'complete' == $item->comment_approved ) { |
|
| 203 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
| 202 | + if ('complete' == $item->comment_approved) { |
|
| 203 | + $status = __('Completed', 'woothemes-sensei'); |
|
| 204 | 204 | $status_class = 'graded'; |
| 205 | 205 | |
| 206 | - $grade = __( 'No Grade', 'woothemes-sensei' ); |
|
| 206 | + $grade = __('No Grade', 'woothemes-sensei'); |
|
| 207 | 207 | } |
| 208 | - elseif( 'graded' == $item->comment_approved ) { |
|
| 209 | - $status = __( 'Graded', 'woothemes-sensei' ) ; |
|
| 208 | + elseif ('graded' == $item->comment_approved) { |
|
| 209 | + $status = __('Graded', 'woothemes-sensei'); |
|
| 210 | 210 | $status_class = 'graded'; |
| 211 | 211 | |
| 212 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true); |
|
| 212 | + $grade = get_comment_meta($item->comment_ID, 'grade', true); |
|
| 213 | 213 | } |
| 214 | - elseif( 'passed' == $item->comment_approved ) { |
|
| 215 | - $status = __( 'Passed', 'woothemes-sensei' ); |
|
| 214 | + elseif ('passed' == $item->comment_approved) { |
|
| 215 | + $status = __('Passed', 'woothemes-sensei'); |
|
| 216 | 216 | $status_class = 'graded'; |
| 217 | 217 | |
| 218 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true); |
|
| 218 | + $grade = get_comment_meta($item->comment_ID, 'grade', true); |
|
| 219 | 219 | } |
| 220 | - elseif( 'failed' == $item->comment_approved ) { |
|
| 221 | - $status = __( 'Failed', 'woothemes-sensei' ); |
|
| 220 | + elseif ('failed' == $item->comment_approved) { |
|
| 221 | + $status = __('Failed', 'woothemes-sensei'); |
|
| 222 | 222 | $status_class = 'failed'; |
| 223 | 223 | |
| 224 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true); |
|
| 224 | + $grade = get_comment_meta($item->comment_ID, 'grade', true); |
|
| 225 | 225 | } |
| 226 | - elseif( 'ungraded' == $item->comment_approved ) { |
|
| 227 | - $status = __( 'Ungraded', 'woothemes-sensei' ); |
|
| 226 | + elseif ('ungraded' == $item->comment_approved) { |
|
| 227 | + $status = __('Ungraded', 'woothemes-sensei'); |
|
| 228 | 228 | $status_class = 'ungraded'; |
| 229 | 229 | |
| 230 | 230 | } |
| 231 | 231 | else { |
| 232 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
| 232 | + $status = __('In Progress', 'woothemes-sensei'); |
|
| 233 | 233 | $user_end_date = ''; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Output users data |
| 237 | - $user_name = Sensei()->learners->get_learner_full_name( $item->user_id ); |
|
| 237 | + $user_name = Sensei()->learners->get_learner_full_name($item->user_id); |
|
| 238 | 238 | |
| 239 | - if ( !$this->csv_output ) { |
|
| 240 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) ); |
|
| 239 | + if ( ! $this->csv_output) { |
|
| 240 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id), admin_url('admin.php')); |
|
| 241 | 241 | |
| 242 | - $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $user_name . '</a></strong>'; |
|
| 243 | - $status = sprintf( '<span class="%s">%s</span>', $item->comment_approved, $status ); |
|
| 244 | - if ( is_numeric($grade) ) { |
|
| 242 | + $user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$user_name.'</a></strong>'; |
|
| 243 | + $status = sprintf('<span class="%s">%s</span>', $item->comment_approved, $status); |
|
| 244 | + if (is_numeric($grade)) { |
|
| 245 | 245 | $grade .= '%'; |
| 246 | 246 | } |
| 247 | 247 | } // End If Statement |
| 248 | - $column_data = apply_filters( 'sensei_analysis_lesson_column_data', array( 'title' => $user_name, |
|
| 248 | + $column_data = apply_filters('sensei_analysis_lesson_column_data', array('title' => $user_name, |
|
| 249 | 249 | 'started' => $user_start_date, |
| 250 | 250 | 'completed' => $user_end_date, |
| 251 | 251 | 'status' => $status, |
| 252 | 252 | 'grade' => $grade, |
| 253 | - ), $item, $this ); |
|
| 253 | + ), $item, $this); |
|
| 254 | 254 | |
| 255 | 255 | return $column_data; |
| 256 | 256 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @since 1.7.0 |
| 261 | 261 | * @return array statuses |
| 262 | 262 | */ |
| 263 | - private function get_lesson_statuses( $args ) { |
|
| 263 | + private function get_lesson_statuses($args) { |
|
| 264 | 264 | |
| 265 | 265 | $activity_args = array( |
| 266 | 266 | 'post_id' => $this->lesson_id, |
@@ -273,34 +273,34 @@ discard block |
||
| 273 | 273 | ); |
| 274 | 274 | |
| 275 | 275 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
| 276 | - if ( $this->search ) { |
|
| 276 | + if ($this->search) { |
|
| 277 | 277 | $user_args = array( |
| 278 | - 'search' => '*' . $this->search . '*', |
|
| 278 | + 'search' => '*'.$this->search.'*', |
|
| 279 | 279 | 'fields' => 'ID', |
| 280 | 280 | ); |
| 281 | 281 | // Filter for extending |
| 282 | - $user_args = apply_filters( 'sensei_analysis_lesson_search_users', $user_args ); |
|
| 283 | - if ( !empty( $user_args ) ) { |
|
| 284 | - $learners_search = new WP_User_Query( $user_args ); |
|
| 282 | + $user_args = apply_filters('sensei_analysis_lesson_search_users', $user_args); |
|
| 283 | + if ( ! empty($user_args)) { |
|
| 284 | + $learners_search = new WP_User_Query($user_args); |
|
| 285 | 285 | // Store for reuse on counts |
| 286 | 286 | $activity_args['user_id'] = (array) $learners_search->get_results(); |
| 287 | 287 | } |
| 288 | 288 | } // End If Statement |
| 289 | 289 | |
| 290 | - $activity_args = apply_filters( 'sensei_analysis_lesson_filter_statuses', $activity_args ); |
|
| 290 | + $activity_args = apply_filters('sensei_analysis_lesson_filter_statuses', $activity_args); |
|
| 291 | 291 | |
| 292 | 292 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
| 293 | - $this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
| 293 | + $this->total_items = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
| 294 | 294 | |
| 295 | 295 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
| 296 | - if ( $this->total_items < $activity_args['offset'] ) { |
|
| 297 | - $new_paged = floor( $total_statuses / $activity_args['number'] ); |
|
| 296 | + if ($this->total_items < $activity_args['offset']) { |
|
| 297 | + $new_paged = floor($total_statuses / $activity_args['number']); |
|
| 298 | 298 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
| 299 | 299 | } |
| 300 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
| 300 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
| 301 | 301 | // Need to always return an array, even with only 1 item |
| 302 | - if ( !is_array($statuses) ) { |
|
| 303 | - $statuses = array( $statuses ); |
|
| 302 | + if ( ! is_array($statuses)) { |
|
| 303 | + $statuses = array($statuses); |
|
| 304 | 304 | } |
| 305 | 305 | return $statuses; |
| 306 | 306 | } // End get_lesson_statuses() |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | * @return void |
| 313 | 313 | */ |
| 314 | 314 | public function no_items() { |
| 315 | - _e( 'No learners found.', 'woothemes-sensei' ); |
|
| 315 | + _e('No learners found.', 'woothemes-sensei'); |
|
| 316 | 316 | } // End no_items() |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return void |
| 322 | 322 | */ |
| 323 | 323 | public function data_table_header() { |
| 324 | - echo '<strong>' . __( 'Learners taking this Lesson', 'woothemes-sensei' ) . '</strong>'; |
|
| 324 | + echo '<strong>'.__('Learners taking this Lesson', 'woothemes-sensei').'</strong>'; |
|
| 325 | 325 | } // End data_table_header() |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -330,10 +330,10 @@ discard block |
||
| 330 | 330 | * @return void |
| 331 | 331 | */ |
| 332 | 332 | public function data_table_footer() { |
| 333 | - $lesson = get_post( $this->lesson_id ); |
|
| 334 | - $report = sanitize_title( $lesson->post_title ) . '-learners-overview'; |
|
| 335 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $this->lesson_id, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) ); |
|
| 336 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
| 333 | + $lesson = get_post($this->lesson_id); |
|
| 334 | + $report = sanitize_title($lesson->post_title).'-learners-overview'; |
|
| 335 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $this->lesson_id, 'sensei_report_download' => $report), admin_url('admin.php')); |
|
| 336 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
| 337 | 337 | } // End data_table_footer() |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @since 1.7.0 |
| 342 | 342 | * @return void |
| 343 | 343 | */ |
| 344 | - public function search_button( $text = '' ) { |
|
| 345 | - return __( 'Search Learners', 'woothemes-sensei' );; |
|
| 344 | + public function search_button($text = '') { |
|
| 345 | + return __('Search Learners', 'woothemes-sensei'); ; |
|
| 346 | 346 | } |
| 347 | 347 | } // End Class |
| 348 | 348 | |
@@ -11,676 +11,676 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Sensei_Templates { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 16 | - * |
|
| 17 | - * @since 1.9.0 |
|
| 18 | - * @param string $slug |
|
| 19 | - * @param string $name default: '' |
|
| 20 | - * |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public static function get_part( $slug, $name = '' ){ |
|
| 14 | + /** |
|
| 15 | + * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 16 | + * |
|
| 17 | + * @since 1.9.0 |
|
| 18 | + * @param string $slug |
|
| 19 | + * @param string $name default: '' |
|
| 20 | + * |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public static function get_part( $slug, $name = '' ){ |
|
| 24 | 24 | |
| 25 | - $template = ''; |
|
| 26 | - $plugin_template_url = Sensei()->template_url; |
|
| 27 | - $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 25 | + $template = ''; |
|
| 26 | + $plugin_template_url = Sensei()->template_url; |
|
| 27 | + $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 28 | 28 | |
| 29 | - // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 30 | - if ( $name ){ |
|
| 29 | + // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 30 | + if ( $name ){ |
|
| 31 | 31 | |
| 32 | - $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 32 | + $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - // Get default slug-name.php |
|
| 37 | - if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 36 | + // Get default slug-name.php |
|
| 37 | + if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 38 | 38 | |
| 39 | - $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 39 | + $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 45 | - if ( !$template ){ |
|
| 44 | + // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 45 | + if ( !$template ){ |
|
| 46 | 46 | |
| 47 | - $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 47 | + $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - if ( $template ){ |
|
| 52 | + if ( $template ){ |
|
| 53 | 53 | |
| 54 | - load_template( $template, false ); |
|
| 54 | + load_template( $template, false ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - } // end get part |
|
| 58 | + } // end get part |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get the template. |
|
| 62 | - * |
|
| 63 | - * @since 1.9.0 |
|
| 64 | - * |
|
| 65 | - * @param $template_name |
|
| 66 | - * @param array $args |
|
| 67 | - * @param string $template_path |
|
| 68 | - * @param string $default_path |
|
| 69 | - */ |
|
| 70 | - public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 60 | + /** |
|
| 61 | + * Get the template. |
|
| 62 | + * |
|
| 63 | + * @since 1.9.0 |
|
| 64 | + * |
|
| 65 | + * @param $template_name |
|
| 66 | + * @param array $args |
|
| 67 | + * @param string $template_path |
|
| 68 | + * @param string $default_path |
|
| 69 | + */ |
|
| 70 | + public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 71 | 71 | |
| 72 | - if ( $args && is_array($args) ) |
|
| 73 | - extract( $args ); |
|
| 72 | + if ( $args && is_array($args) ) |
|
| 73 | + extract( $args ); |
|
| 74 | 74 | |
| 75 | - $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 75 | + $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 76 | 76 | |
| 77 | - if( ! empty( $located ) ){ |
|
| 77 | + if( ! empty( $located ) ){ |
|
| 78 | 78 | |
| 79 | - do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 79 | + do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 80 | 80 | |
| 81 | - include( $located ); |
|
| 81 | + include( $located ); |
|
| 82 | 82 | |
| 83 | - do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 83 | + do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 84 | 84 | |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - } // end get template |
|
| 87 | + } // end get template |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Check if the template file exists. A wrapper for WP locate_template. |
|
| 91 | - * |
|
| 92 | - * @since 1.9.0 |
|
| 93 | - * |
|
| 94 | - * @param $template_name |
|
| 95 | - * @param string $template_path |
|
| 96 | - * @param string $default_path |
|
| 97 | - * |
|
| 98 | - * @return mixed|void |
|
| 99 | - */ |
|
| 100 | - public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 89 | + /** |
|
| 90 | + * Check if the template file exists. A wrapper for WP locate_template. |
|
| 91 | + * |
|
| 92 | + * @since 1.9.0 |
|
| 93 | + * |
|
| 94 | + * @param $template_name |
|
| 95 | + * @param string $template_path |
|
| 96 | + * @param string $default_path |
|
| 97 | + * |
|
| 98 | + * @return mixed|void |
|
| 99 | + */ |
|
| 100 | + public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 101 | 101 | |
| 102 | - if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | - if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 102 | + if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | + if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 104 | 104 | |
| 105 | - // Look within passed path within the theme - this is priority |
|
| 106 | - $template = locate_template( |
|
| 107 | - array( |
|
| 108 | - $template_path . $template_name, |
|
| 109 | - $template_name |
|
| 110 | - ) |
|
| 111 | - ); |
|
| 105 | + // Look within passed path within the theme - this is priority |
|
| 106 | + $template = locate_template( |
|
| 107 | + array( |
|
| 108 | + $template_path . $template_name, |
|
| 109 | + $template_name |
|
| 110 | + ) |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - // Get default template |
|
| 114 | - if ( ! $template ){ |
|
| 113 | + // Get default template |
|
| 114 | + if ( ! $template ){ |
|
| 115 | 115 | |
| 116 | - $template = $default_path . $template_name; |
|
| 116 | + $template = $default_path . $template_name; |
|
| 117 | 117 | |
| 118 | - } |
|
| 119 | - // return nothing for file that do not exist |
|
| 120 | - if( !file_exists( $template ) ){ |
|
| 121 | - $template = ''; |
|
| 122 | - } |
|
| 118 | + } |
|
| 119 | + // return nothing for file that do not exist |
|
| 120 | + if( !file_exists( $template ) ){ |
|
| 121 | + $template = ''; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // Return what we found |
|
| 125 | - return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 124 | + // Return what we found |
|
| 125 | + return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 126 | 126 | |
| 127 | - } // end locate |
|
| 127 | + } // end locate |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Determine which Sensei template to load based on the |
|
| 131 | - * current page context. |
|
| 132 | - * |
|
| 133 | - * @since 1.0 |
|
| 134 | - * |
|
| 135 | - * @param string $template |
|
| 136 | - * @return string $template |
|
| 137 | - */ |
|
| 138 | - public static function template_loader ( $template = '' ) { |
|
| 129 | + /** |
|
| 130 | + * Determine which Sensei template to load based on the |
|
| 131 | + * current page context. |
|
| 132 | + * |
|
| 133 | + * @since 1.0 |
|
| 134 | + * |
|
| 135 | + * @param string $template |
|
| 136 | + * @return string $template |
|
| 137 | + */ |
|
| 138 | + public static function template_loader ( $template = '' ) { |
|
| 139 | 139 | |
| 140 | - global $wp_query, $email_template; |
|
| 140 | + global $wp_query, $email_template; |
|
| 141 | 141 | |
| 142 | - $find = array( 'woothemes-sensei.php' ); |
|
| 143 | - $file = ''; |
|
| 142 | + $find = array( 'woothemes-sensei.php' ); |
|
| 143 | + $file = ''; |
|
| 144 | 144 | |
| 145 | - if ( isset( $email_template ) && $email_template ) { |
|
| 145 | + if ( isset( $email_template ) && $email_template ) { |
|
| 146 | 146 | |
| 147 | - $file = 'emails/' . $email_template; |
|
| 148 | - $find[] = $file; |
|
| 149 | - $find[] = Sensei()->template_url . $file; |
|
| 147 | + $file = 'emails/' . $email_template; |
|
| 148 | + $find[] = $file; |
|
| 149 | + $find[] = Sensei()->template_url . $file; |
|
| 150 | 150 | |
| 151 | - } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 151 | + } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 152 | 152 | |
| 153 | - if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 153 | + if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 154 | 154 | |
| 155 | - // possible backward compatible template include if theme overrides content-single-course.php |
|
| 156 | - // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 157 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 155 | + // possible backward compatible template include if theme overrides content-single-course.php |
|
| 156 | + // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 157 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 158 | 158 | |
| 159 | - $file = 'single-course.php'; |
|
| 160 | - $find[] = $file; |
|
| 161 | - $find[] = Sensei()->template_url . $file; |
|
| 159 | + $file = 'single-course.php'; |
|
| 160 | + $find[] = $file; |
|
| 161 | + $find[] = Sensei()->template_url . $file; |
|
| 162 | 162 | |
| 163 | - } else { |
|
| 163 | + } else { |
|
| 164 | 164 | |
| 165 | - // No Permissions Page |
|
| 166 | - return self::get_no_permission_template(); |
|
| 165 | + // No Permissions Page |
|
| 166 | + return self::get_no_permission_template(); |
|
| 167 | 167 | |
| 168 | - } // End If Statement |
|
| 168 | + } // End If Statement |
|
| 169 | 169 | |
| 170 | - } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 170 | + } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 171 | 171 | |
| 172 | - if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 172 | + if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 173 | 173 | |
| 174 | - // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 175 | - // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 176 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 174 | + // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 175 | + // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 176 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 177 | 177 | |
| 178 | - $file = 'single-lesson.php'; |
|
| 179 | - $find[] = $file; |
|
| 180 | - $find[] = Sensei()->template_url . $file; |
|
| 178 | + $file = 'single-lesson.php'; |
|
| 179 | + $find[] = $file; |
|
| 180 | + $find[] = Sensei()->template_url . $file; |
|
| 181 | 181 | |
| 182 | - } else { |
|
| 182 | + } else { |
|
| 183 | 183 | |
| 184 | - // No Permissions Page |
|
| 185 | - return self::get_no_permission_template(); |
|
| 184 | + // No Permissions Page |
|
| 185 | + return self::get_no_permission_template(); |
|
| 186 | 186 | |
| 187 | - } // End If Statement |
|
| 187 | + } // End If Statement |
|
| 188 | 188 | |
| 189 | - } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 189 | + } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 190 | 190 | |
| 191 | - if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 191 | + if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 192 | 192 | |
| 193 | - // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 194 | - // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 195 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 193 | + // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 194 | + // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 195 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 196 | 196 | |
| 197 | - $file = 'single-quiz.php'; |
|
| 198 | - $find[] = $file; |
|
| 199 | - $find[] = Sensei()->template_url . $file; |
|
| 197 | + $file = 'single-quiz.php'; |
|
| 198 | + $find[] = $file; |
|
| 199 | + $find[] = Sensei()->template_url . $file; |
|
| 200 | 200 | |
| 201 | - } else { |
|
| 201 | + } else { |
|
| 202 | 202 | |
| 203 | - // No Permissions Page |
|
| 204 | - return self::get_no_permission_template(); |
|
| 203 | + // No Permissions Page |
|
| 204 | + return self::get_no_permission_template(); |
|
| 205 | 205 | |
| 206 | - } // End If Statement |
|
| 206 | + } // End If Statement |
|
| 207 | 207 | |
| 208 | - } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 208 | + } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 209 | 209 | |
| 210 | - // possible backward compatible template include if theme overrides content-single-message.php |
|
| 211 | - // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 212 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 210 | + // possible backward compatible template include if theme overrides content-single-message.php |
|
| 211 | + // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 212 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 213 | 213 | |
| 214 | - $file = 'single-message.php'; |
|
| 215 | - $find[] = $file; |
|
| 216 | - $find[] = Sensei()->template_url . $file; |
|
| 214 | + $file = 'single-message.php'; |
|
| 215 | + $find[] = $file; |
|
| 216 | + $find[] = Sensei()->template_url . $file; |
|
| 217 | 217 | |
| 218 | - } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | - || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | - || is_tax( 'course-category' )) { |
|
| 218 | + } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | + || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | + || is_tax( 'course-category' )) { |
|
| 221 | 221 | |
| 222 | - // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 223 | - // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 224 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 222 | + // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 223 | + // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 224 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 225 | 225 | |
| 226 | - $file = 'archive-course.php'; |
|
| 227 | - $find[] = $file; |
|
| 228 | - $find[] = Sensei()->template_url . $file; |
|
| 226 | + $file = 'archive-course.php'; |
|
| 227 | + $find[] = $file; |
|
| 228 | + $find[] = Sensei()->template_url . $file; |
|
| 229 | 229 | |
| 230 | - } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 230 | + } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 231 | 231 | |
| 232 | - $file = 'archive-message.php'; |
|
| 233 | - $find[] = $file; |
|
| 234 | - $find[] = Sensei()->template_url . $file; |
|
| 232 | + $file = 'archive-message.php'; |
|
| 233 | + $find[] = $file; |
|
| 234 | + $find[] = Sensei()->template_url . $file; |
|
| 235 | 235 | |
| 236 | - } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 236 | + } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 237 | 237 | |
| 238 | - // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 239 | - // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 240 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 238 | + // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 239 | + // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 240 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 241 | 241 | |
| 242 | - $file = 'archive-lesson.php'; |
|
| 243 | - $find[] = $file; |
|
| 244 | - $find[] = Sensei()->template_url . $file; |
|
| 242 | + $file = 'archive-lesson.php'; |
|
| 243 | + $find[] = $file; |
|
| 244 | + $find[] = Sensei()->template_url . $file; |
|
| 245 | 245 | |
| 246 | - } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 246 | + } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 247 | 247 | |
| 248 | - // Override for sites with static home page |
|
| 249 | - $wp_query->is_home = false; |
|
| 248 | + // Override for sites with static home page |
|
| 249 | + $wp_query->is_home = false; |
|
| 250 | 250 | |
| 251 | - $file = 'learner-profile.php'; |
|
| 252 | - $find[] = $file; |
|
| 253 | - $find[] = Sensei()->template_url . $file; |
|
| 251 | + $file = 'learner-profile.php'; |
|
| 252 | + $find[] = $file; |
|
| 253 | + $find[] = Sensei()->template_url . $file; |
|
| 254 | 254 | |
| 255 | - } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 255 | + } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 256 | 256 | |
| 257 | - // Override for sites with static home page |
|
| 258 | - $wp_query->is_home = false; |
|
| 257 | + // Override for sites with static home page |
|
| 258 | + $wp_query->is_home = false; |
|
| 259 | 259 | |
| 260 | - $file = 'course-results.php'; |
|
| 261 | - $find[] = $file; |
|
| 262 | - $find[] = Sensei()->template_url . $file; |
|
| 260 | + $file = 'course-results.php'; |
|
| 261 | + $find[] = $file; |
|
| 262 | + $find[] = Sensei()->template_url . $file; |
|
| 263 | 263 | |
| 264 | - }elseif( is_author() |
|
| 265 | - && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | - && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 264 | + }elseif( is_author() |
|
| 265 | + && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | + && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 267 | 267 | |
| 268 | - $file = 'teacher-archive.php'; |
|
| 269 | - $find[] = $file; |
|
| 270 | - $find[] = Sensei()->template_url . $file; |
|
| 268 | + $file = 'teacher-archive.php'; |
|
| 269 | + $find[] = $file; |
|
| 270 | + $find[] = Sensei()->template_url . $file; |
|
| 271 | 271 | |
| 272 | - } // Load the template file |
|
| 272 | + } // Load the template file |
|
| 273 | 273 | |
| 274 | - if ( $file ) { |
|
| 274 | + if ( $file ) { |
|
| 275 | 275 | |
| 276 | - $template = locate_template( $find ); |
|
| 277 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 276 | + $template = locate_template( $find ); |
|
| 277 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 278 | 278 | |
| 279 | - } // End If Statement |
|
| 279 | + } // End If Statement |
|
| 280 | 280 | |
| 281 | - return $template; |
|
| 281 | + return $template; |
|
| 282 | 282 | |
| 283 | - } // End template_loader() |
|
| 283 | + } // End template_loader() |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * This function loads the no-permissions template for users with no access |
|
| 287 | - * if a Sensei template was loaded. |
|
| 288 | - * |
|
| 289 | - * This function doesn't determine the permissions. Permissions must be determined |
|
| 290 | - * before loading this function as it only gets the template. |
|
| 291 | - * |
|
| 292 | - * This function also checks the user theme for overrides to ensure the right template |
|
| 293 | - * file is returned. |
|
| 294 | - * |
|
| 295 | - * @since 1.9.0 |
|
| 296 | - */ |
|
| 297 | - public static function get_no_permission_template( ){ |
|
| 285 | + /** |
|
| 286 | + * This function loads the no-permissions template for users with no access |
|
| 287 | + * if a Sensei template was loaded. |
|
| 288 | + * |
|
| 289 | + * This function doesn't determine the permissions. Permissions must be determined |
|
| 290 | + * before loading this function as it only gets the template. |
|
| 291 | + * |
|
| 292 | + * This function also checks the user theme for overrides to ensure the right template |
|
| 293 | + * file is returned. |
|
| 294 | + * |
|
| 295 | + * @since 1.9.0 |
|
| 296 | + */ |
|
| 297 | + public static function get_no_permission_template( ){ |
|
| 298 | 298 | |
| 299 | - // possible backward compatible template loading |
|
| 300 | - // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 301 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 299 | + // possible backward compatible template loading |
|
| 300 | + // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 301 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 302 | 302 | |
| 303 | - $file = 'no-permissions.php'; |
|
| 304 | - $find[] = $file; |
|
| 305 | - $find[] = Sensei()->template_url . $file; |
|
| 303 | + $file = 'no-permissions.php'; |
|
| 304 | + $find[] = $file; |
|
| 305 | + $find[] = Sensei()->template_url . $file; |
|
| 306 | 306 | |
| 307 | - $template = locate_template( $find ); |
|
| 308 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 307 | + $template = locate_template( $find ); |
|
| 308 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 309 | 309 | |
| 310 | - return $template; |
|
| 310 | + return $template; |
|
| 311 | 311 | |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * This function is specifically created for loading template files from the theme. |
|
| 316 | - * |
|
| 317 | - * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 318 | - * around the singular content file from their theme and exit. |
|
| 319 | - * |
|
| 320 | - * If none is found this function will do nothing. If a template is found this funciton |
|
| 321 | - * will exit execution of the script an not continue. |
|
| 322 | - * |
|
| 323 | - * @since 1.9.0 |
|
| 324 | - * @param string $template |
|
| 325 | - * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 326 | - */ |
|
| 327 | - public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 314 | + /** |
|
| 315 | + * This function is specifically created for loading template files from the theme. |
|
| 316 | + * |
|
| 317 | + * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 318 | + * around the singular content file from their theme and exit. |
|
| 319 | + * |
|
| 320 | + * If none is found this function will do nothing. If a template is found this funciton |
|
| 321 | + * will exit execution of the script an not continue. |
|
| 322 | + * |
|
| 323 | + * @since 1.9.0 |
|
| 324 | + * @param string $template |
|
| 325 | + * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 326 | + */ |
|
| 327 | + public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 328 | 328 | |
| 329 | - $found_template = locate_template( array( $template ) ); |
|
| 330 | - if( $found_template ){ |
|
| 329 | + $found_template = locate_template( array( $template ) ); |
|
| 330 | + if( $found_template ){ |
|
| 331 | 331 | |
| 332 | - if( $load_header_footer ){ |
|
| 333 | - |
|
| 334 | - get_sensei_header(); |
|
| 335 | - include( $found_template ); |
|
| 336 | - get_sensei_footer(); |
|
| 332 | + if( $load_header_footer ){ |
|
| 333 | + |
|
| 334 | + get_sensei_header(); |
|
| 335 | + include( $found_template ); |
|
| 336 | + get_sensei_footer(); |
|
| 337 | 337 | |
| 338 | - }else{ |
|
| 338 | + }else{ |
|
| 339 | 339 | |
| 340 | - include( $found_template ); |
|
| 340 | + include( $found_template ); |
|
| 341 | 341 | |
| 342 | - } |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - exit; |
|
| 344 | + exit; |
|
| 345 | 345 | |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | |
| 351 | - /** |
|
| 352 | - * Hooks the deprecated archive content hook into the hook again just in |
|
| 353 | - * case other developers have used it. |
|
| 354 | - * |
|
| 355 | - * @deprecated since 1.9.0 |
|
| 356 | - */ |
|
| 357 | - public static function deprecated_archive_course_content_hook(){ |
|
| 351 | + /** |
|
| 352 | + * Hooks the deprecated archive content hook into the hook again just in |
|
| 353 | + * case other developers have used it. |
|
| 354 | + * |
|
| 355 | + * @deprecated since 1.9.0 |
|
| 356 | + */ |
|
| 357 | + public static function deprecated_archive_course_content_hook(){ |
|
| 358 | 358 | |
| 359 | - sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 360 | - |
|
| 361 | - }// end deprecated_archive_hook |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * A generic function for echoing the post title |
|
| 365 | - * |
|
| 366 | - * @since 1.9.0 |
|
| 367 | - * @param WP_Post $post |
|
| 368 | - */ |
|
| 369 | - public static function the_title( $post ){ |
|
| 359 | + sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 360 | + |
|
| 361 | + }// end deprecated_archive_hook |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * A generic function for echoing the post title |
|
| 365 | + * |
|
| 366 | + * @since 1.9.0 |
|
| 367 | + * @param WP_Post $post |
|
| 368 | + */ |
|
| 369 | + public static function the_title( $post ){ |
|
| 370 | 370 | |
| 371 | - /** |
|
| 372 | - * Filter the template html tag for the title |
|
| 373 | - * |
|
| 374 | - * @since 1.9.0 |
|
| 375 | - * |
|
| 376 | - * @param $title_html_tag default is 'h3' |
|
| 377 | - */ |
|
| 378 | - $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Filter the title classes |
|
| 382 | - * |
|
| 383 | - * @since 1.9.0 |
|
| 384 | - * @param string $title_classes defaults to $post_type-title |
|
| 385 | - */ |
|
| 386 | - $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 387 | - |
|
| 388 | - $html= ''; |
|
| 389 | - $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 390 | - $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 391 | - $html .= $post->post_title ; |
|
| 392 | - $html .= '</a>'; |
|
| 393 | - $html .= '</'. $title_html_tag. '>'; |
|
| 394 | - echo $html; |
|
| 395 | - |
|
| 396 | - }// end the title |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * This function adds the hooks inside and above the single course content for |
|
| 400 | - * backwards compatibility sake. |
|
| 401 | - * |
|
| 402 | - * @since 1.9.0 |
|
| 403 | - * @deprecated 1.9.0 |
|
| 404 | - */ |
|
| 405 | - public static function deprecated_single_course_inside_before_hooks(){ |
|
| 406 | - |
|
| 407 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 408 | - sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 409 | - sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 410 | - |
|
| 411 | - }// end deprecated_single_course_inside_before_hooks |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * This function adds the hooks to sensei_course_single_lessons for |
|
| 415 | - * backwards compatibility sake. and provides developers with an alternative. |
|
| 416 | - * |
|
| 417 | - * @since 1.9.0 |
|
| 418 | - * @deprecated 1.9.0 |
|
| 419 | - */ |
|
| 420 | - public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 371 | + /** |
|
| 372 | + * Filter the template html tag for the title |
|
| 373 | + * |
|
| 374 | + * @since 1.9.0 |
|
| 375 | + * |
|
| 376 | + * @param $title_html_tag default is 'h3' |
|
| 377 | + */ |
|
| 378 | + $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Filter the title classes |
|
| 382 | + * |
|
| 383 | + * @since 1.9.0 |
|
| 384 | + * @param string $title_classes defaults to $post_type-title |
|
| 385 | + */ |
|
| 386 | + $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 387 | + |
|
| 388 | + $html= ''; |
|
| 389 | + $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 390 | + $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 391 | + $html .= $post->post_title ; |
|
| 392 | + $html .= '</a>'; |
|
| 393 | + $html .= '</'. $title_html_tag. '>'; |
|
| 394 | + echo $html; |
|
| 395 | + |
|
| 396 | + }// end the title |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * This function adds the hooks inside and above the single course content for |
|
| 400 | + * backwards compatibility sake. |
|
| 401 | + * |
|
| 402 | + * @since 1.9.0 |
|
| 403 | + * @deprecated 1.9.0 |
|
| 404 | + */ |
|
| 405 | + public static function deprecated_single_course_inside_before_hooks(){ |
|
| 406 | + |
|
| 407 | + sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 408 | + sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 409 | + sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 410 | + |
|
| 411 | + }// end deprecated_single_course_inside_before_hooks |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * This function adds the hooks to sensei_course_single_lessons for |
|
| 415 | + * backwards compatibility sake. and provides developers with an alternative. |
|
| 416 | + * |
|
| 417 | + * @since 1.9.0 |
|
| 418 | + * @deprecated 1.9.0 |
|
| 419 | + */ |
|
| 420 | + public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 421 | 421 | |
| 422 | - sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 422 | + sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 423 | 423 | |
| 424 | - }// deprecate_sensei_course_single_lessons_hook |
|
| 424 | + }// deprecate_sensei_course_single_lessons_hook |
|
| 425 | 425 | |
| 426 | - /** |
|
| 427 | - * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 428 | - * |
|
| 429 | - * The content must be dealt with inside the respective templates. |
|
| 430 | - * |
|
| 431 | - * @since 1.9.0 |
|
| 432 | - * @deprecated 1.9.0 |
|
| 433 | - */ |
|
| 434 | - public static function deprecated_single_main_content_hook(){ |
|
| 426 | + /** |
|
| 427 | + * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 428 | + * |
|
| 429 | + * The content must be dealt with inside the respective templates. |
|
| 430 | + * |
|
| 431 | + * @since 1.9.0 |
|
| 432 | + * @deprecated 1.9.0 |
|
| 433 | + */ |
|
| 434 | + public static function deprecated_single_main_content_hook(){ |
|
| 435 | 435 | |
| 436 | - if( is_singular( 'course' ) ) { |
|
| 436 | + if( is_singular( 'course' ) ) { |
|
| 437 | 437 | |
| 438 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 438 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 439 | 439 | |
| 440 | - } elseif( is_singular( 'message' ) ){ |
|
| 440 | + } elseif( is_singular( 'message' ) ){ |
|
| 441 | 441 | |
| 442 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - }// end deprecated_single_course_single_main_content_hook |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Deprecate the old sensei modules |
|
| 449 | - * @since 1.9.0 |
|
| 450 | - * @deprecated since 1.9.0 |
|
| 451 | - */ |
|
| 452 | - public static function deprecate_module_before_hook(){ |
|
| 442 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + }// end deprecated_single_course_single_main_content_hook |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Deprecate the old sensei modules |
|
| 449 | + * @since 1.9.0 |
|
| 450 | + * @deprecated since 1.9.0 |
|
| 451 | + */ |
|
| 452 | + public static function deprecate_module_before_hook(){ |
|
| 453 | 453 | |
| 454 | - sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 454 | + sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 455 | 455 | |
| 456 | - } |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - /** |
|
| 459 | - * Deprecate the old sensei modules after hooks |
|
| 460 | - * @since 1.9.0 |
|
| 461 | - * @deprecated since 1.9.0 |
|
| 462 | - */ |
|
| 463 | - public static function deprecate_module_after_hook(){ |
|
| 458 | + /** |
|
| 459 | + * Deprecate the old sensei modules after hooks |
|
| 460 | + * @since 1.9.0 |
|
| 461 | + * @deprecated since 1.9.0 |
|
| 462 | + */ |
|
| 463 | + public static function deprecate_module_after_hook(){ |
|
| 464 | 464 | |
| 465 | - sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 465 | + sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 466 | 466 | |
| 467 | - } |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | - /** |
|
| 470 | - * Deprecate the single message hooks for post types. |
|
| 471 | - * |
|
| 472 | - * @since 1.9.0 |
|
| 473 | - * @deprecated since 1.9.0 |
|
| 474 | - */ |
|
| 475 | - public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 469 | + /** |
|
| 470 | + * Deprecate the single message hooks for post types. |
|
| 471 | + * |
|
| 472 | + * @since 1.9.0 |
|
| 473 | + * @deprecated since 1.9.0 |
|
| 474 | + */ |
|
| 475 | + public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 476 | 476 | |
| 477 | - if( is_singular( 'sensei_message' ) ){ |
|
| 477 | + if( is_singular( 'sensei_message' ) ){ |
|
| 478 | 478 | |
| 479 | - sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 479 | + sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 480 | 480 | |
| 481 | - } |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - /** |
|
| 486 | - * course_single_meta function. |
|
| 487 | - * |
|
| 488 | - * @access public |
|
| 489 | - * @return void |
|
| 490 | - * @deprecated since 1.9.0 |
|
| 491 | - */ |
|
| 492 | - public static function deprecate_course_single_meta_hooks() { |
|
| 485 | + /** |
|
| 486 | + * course_single_meta function. |
|
| 487 | + * |
|
| 488 | + * @access public |
|
| 489 | + * @return void |
|
| 490 | + * @deprecated since 1.9.0 |
|
| 491 | + */ |
|
| 492 | + public static function deprecate_course_single_meta_hooks() { |
|
| 493 | 493 | |
| 494 | - // deprecate all these hooks |
|
| 495 | - sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 496 | - sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 497 | - sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 498 | - sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 494 | + // deprecate all these hooks |
|
| 495 | + sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 496 | + sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 497 | + sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 498 | + sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 499 | 499 | |
| 500 | - } // End deprecate_course_single_meta_hooks |
|
| 500 | + } // End deprecate_course_single_meta_hooks |
|
| 501 | 501 | |
| 502 | - /** |
|
| 503 | - * Run the deprecated hooks on the single lesson page |
|
| 504 | - * @deprecated since 1.9.0 |
|
| 505 | - */ |
|
| 506 | - public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 502 | + /** |
|
| 503 | + * Run the deprecated hooks on the single lesson page |
|
| 504 | + * @deprecated since 1.9.0 |
|
| 505 | + */ |
|
| 506 | + public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 507 | 507 | |
| 508 | - if( is_singular( 'lesson' ) ){ |
|
| 508 | + if( is_singular( 'lesson' ) ){ |
|
| 509 | 509 | |
| 510 | - sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 511 | - sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 510 | + sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 511 | + sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 512 | 512 | |
| 513 | - } |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 515 | + }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Deprecate the hook sensei_lesson_course_signup. |
|
| 519 | - * |
|
| 520 | - * The hook content will be linked directly on the recommended |
|
| 521 | - * sensei_single_lesson_content_inside_after |
|
| 522 | - * |
|
| 523 | - * @deprecated since 1.9.0 |
|
| 524 | - */ |
|
| 525 | - public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 517 | + /** |
|
| 518 | + * Deprecate the hook sensei_lesson_course_signup. |
|
| 519 | + * |
|
| 520 | + * The hook content will be linked directly on the recommended |
|
| 521 | + * sensei_single_lesson_content_inside_after |
|
| 522 | + * |
|
| 523 | + * @deprecated since 1.9.0 |
|
| 524 | + */ |
|
| 525 | + public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 526 | 526 | |
| 527 | - $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 528 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 527 | + $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 528 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 529 | 529 | |
| 530 | - if( !$user_taking_course ) { |
|
| 530 | + if( !$user_taking_course ) { |
|
| 531 | 531 | |
| 532 | - sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 532 | + sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 533 | 533 | |
| 534 | - } |
|
| 535 | - }// end deprecate_sensei_lesson_course_signup_hook |
|
| 534 | + } |
|
| 535 | + }// end deprecate_sensei_lesson_course_signup_hook |
|
| 536 | 536 | |
| 537 | - /** |
|
| 538 | - * Running the deprecated hook: sensei_lesson_single_meta |
|
| 539 | - * |
|
| 540 | - * @since 1.9.0 |
|
| 541 | - * @deprecated since 1.9.0 |
|
| 542 | - */ |
|
| 543 | - public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 537 | + /** |
|
| 538 | + * Running the deprecated hook: sensei_lesson_single_meta |
|
| 539 | + * |
|
| 540 | + * @since 1.9.0 |
|
| 541 | + * @deprecated since 1.9.0 |
|
| 542 | + */ |
|
| 543 | + public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 544 | 544 | |
| 545 | - if ( sensei_can_user_view_lesson() ) { |
|
| 545 | + if ( sensei_can_user_view_lesson() ) { |
|
| 546 | 546 | |
| 547 | - sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 547 | + sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | - } |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - }// end deprecate_sensei_lesson_single_meta_hook |
|
| 552 | + }// end deprecate_sensei_lesson_single_meta_hook |
|
| 553 | 553 | |
| 554 | - /** |
|
| 555 | - * Deprecate the sensei lesson single title hook |
|
| 556 | - * @deprecated since 1.9.0 |
|
| 557 | - */ |
|
| 558 | - public static function deprecate_sensei_lesson_single_title(){ |
|
| 554 | + /** |
|
| 555 | + * Deprecate the sensei lesson single title hook |
|
| 556 | + * @deprecated since 1.9.0 |
|
| 557 | + */ |
|
| 558 | + public static function deprecate_sensei_lesson_single_title(){ |
|
| 559 | 559 | |
| 560 | - sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 560 | + sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 561 | 561 | |
| 562 | - }// end deprecate_sensei_lesson_single_title |
|
| 562 | + }// end deprecate_sensei_lesson_single_title |
|
| 563 | 563 | |
| 564 | - /** |
|
| 565 | - * hook in the deperecated single main content to the lesson |
|
| 566 | - * @deprecated since 1.9.0 |
|
| 567 | - */ |
|
| 568 | - public static function deprecate_lesson_single_main_content_hook(){ |
|
| 564 | + /** |
|
| 565 | + * hook in the deperecated single main content to the lesson |
|
| 566 | + * @deprecated since 1.9.0 |
|
| 567 | + */ |
|
| 568 | + public static function deprecate_lesson_single_main_content_hook(){ |
|
| 569 | 569 | |
| 570 | - sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 570 | + sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 571 | 571 | |
| 572 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 572 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 573 | 573 | |
| 574 | - /** |
|
| 575 | - * hook in the deperecated single main content to the lesson |
|
| 576 | - * @deprecated since 1.9.0 |
|
| 577 | - */ |
|
| 578 | - public static function deprecate_lesson_image_hook(){ |
|
| 574 | + /** |
|
| 575 | + * hook in the deperecated single main content to the lesson |
|
| 576 | + * @deprecated since 1.9.0 |
|
| 577 | + */ |
|
| 578 | + public static function deprecate_lesson_image_hook(){ |
|
| 579 | 579 | |
| 580 | - sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 580 | + sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 581 | 581 | |
| 582 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 582 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 583 | 583 | |
| 584 | - /** |
|
| 585 | - * hook in the deprecated sensei_login_form hook for backwards |
|
| 586 | - * compatibility |
|
| 587 | - * |
|
| 588 | - * @since 1.9.0 |
|
| 589 | - * @deprecated since 1.9.0 |
|
| 590 | - */ |
|
| 591 | - public static function deprecate_sensei_login_form_hook(){ |
|
| 584 | + /** |
|
| 585 | + * hook in the deprecated sensei_login_form hook for backwards |
|
| 586 | + * compatibility |
|
| 587 | + * |
|
| 588 | + * @since 1.9.0 |
|
| 589 | + * @deprecated since 1.9.0 |
|
| 590 | + */ |
|
| 591 | + public static function deprecate_sensei_login_form_hook(){ |
|
| 592 | 592 | |
| 593 | - sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 593 | + sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 594 | 594 | |
| 595 | - } // end deprecate_sensei_login_form_hook |
|
| 595 | + } // end deprecate_sensei_login_form_hook |
|
| 596 | 596 | |
| 597 | - /** |
|
| 598 | - * Fire the sensei_complete_course action. |
|
| 599 | - * |
|
| 600 | - * This is just a backwards compatible function to add the action |
|
| 601 | - * to a template. This should not be used as the function from this |
|
| 602 | - * hook will be added directly to my-courses page via one of the hooks there. |
|
| 603 | - * |
|
| 604 | - * @since 1.9.0 |
|
| 605 | - */ |
|
| 606 | - public static function fire_sensei_complete_course_hook(){ |
|
| 597 | + /** |
|
| 598 | + * Fire the sensei_complete_course action. |
|
| 599 | + * |
|
| 600 | + * This is just a backwards compatible function to add the action |
|
| 601 | + * to a template. This should not be used as the function from this |
|
| 602 | + * hook will be added directly to my-courses page via one of the hooks there. |
|
| 603 | + * |
|
| 604 | + * @since 1.9.0 |
|
| 605 | + */ |
|
| 606 | + public static function fire_sensei_complete_course_hook(){ |
|
| 607 | 607 | |
| 608 | - do_action( 'sensei_complete_course' ); |
|
| 608 | + do_action( 'sensei_complete_course' ); |
|
| 609 | 609 | |
| 610 | - } //fire_sensei_complete_course_hook |
|
| 610 | + } //fire_sensei_complete_course_hook |
|
| 611 | 611 | |
| 612 | - /** |
|
| 613 | - * Fire the frontend message hook |
|
| 614 | - * |
|
| 615 | - * @since 1.9.0 |
|
| 616 | - */ |
|
| 617 | - public static function fire_frontend_messages_hook(){ |
|
| 612 | + /** |
|
| 613 | + * Fire the frontend message hook |
|
| 614 | + * |
|
| 615 | + * @since 1.9.0 |
|
| 616 | + */ |
|
| 617 | + public static function fire_frontend_messages_hook(){ |
|
| 618 | 618 | |
| 619 | - do_action( 'sensei_frontend_messages' ); |
|
| 619 | + do_action( 'sensei_frontend_messages' ); |
|
| 620 | 620 | |
| 621 | - }// end sensei_complete_course_action |
|
| 621 | + }// end sensei_complete_course_action |
|
| 622 | 622 | |
| 623 | - /** |
|
| 624 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 625 | - * of sensei_my_courses_content_inside_before. |
|
| 626 | - * |
|
| 627 | - * @deprected since 1.9.0 |
|
| 628 | - */ |
|
| 629 | - public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 623 | + /** |
|
| 624 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 625 | + * of sensei_my_courses_content_inside_before. |
|
| 626 | + * |
|
| 627 | + * @deprected since 1.9.0 |
|
| 628 | + */ |
|
| 629 | + public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 630 | 630 | |
| 631 | - sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 631 | + sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 632 | 632 | |
| 633 | - }// deprecate_sensei_before_user_course_content_hook |
|
| 633 | + }// deprecate_sensei_before_user_course_content_hook |
|
| 634 | 634 | |
| 635 | - /** |
|
| 636 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 637 | - * of sensei_my_courses_content_inside_after hook. |
|
| 638 | - * |
|
| 639 | - * @deprected since 1.9.0 |
|
| 640 | - */ |
|
| 641 | - public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 635 | + /** |
|
| 636 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 637 | + * of sensei_my_courses_content_inside_after hook. |
|
| 638 | + * |
|
| 639 | + * @deprected since 1.9.0 |
|
| 640 | + */ |
|
| 641 | + public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 642 | 642 | |
| 643 | - sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 643 | + sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 644 | 644 | |
| 645 | - }// deprecate_sensei_after_user_course_content_hook |
|
| 645 | + }// deprecate_sensei_after_user_course_content_hook |
|
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Deprecate the 2 main hooks on the archive message template |
|
| 649 | - * |
|
| 650 | - * @deprecated since 1.9.0 |
|
| 651 | - * @since 1.9.0 |
|
| 652 | - */ |
|
| 653 | - public static function deprecated_archive_message_hooks (){ |
|
| 654 | - |
|
| 655 | - sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 656 | - sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 647 | + /** |
|
| 648 | + * Deprecate the 2 main hooks on the archive message template |
|
| 649 | + * |
|
| 650 | + * @deprecated since 1.9.0 |
|
| 651 | + * @since 1.9.0 |
|
| 652 | + */ |
|
| 653 | + public static function deprecated_archive_message_hooks (){ |
|
| 654 | + |
|
| 655 | + sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 656 | + sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 657 | 657 | |
| 658 | - } |
|
| 658 | + } |
|
| 659 | 659 | |
| 660 | - /** |
|
| 661 | - * Run the sensei_complete_quiz for those still hooking |
|
| 662 | - * into but deprecated it. |
|
| 663 | - * |
|
| 664 | - * @deprecated since 1.9.0 |
|
| 665 | - */ |
|
| 666 | - public static function deprecate_sensei_complete_quiz_action(){ |
|
| 660 | + /** |
|
| 661 | + * Run the sensei_complete_quiz for those still hooking |
|
| 662 | + * into but deprecated it. |
|
| 663 | + * |
|
| 664 | + * @deprecated since 1.9.0 |
|
| 665 | + */ |
|
| 666 | + public static function deprecate_sensei_complete_quiz_action(){ |
|
| 667 | 667 | |
| 668 | - sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 668 | + sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 669 | 669 | |
| 670 | - } |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - /** |
|
| 673 | - * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 674 | - * it to provide user with a better alternative. |
|
| 675 | - * |
|
| 676 | - * @deprecated since 1.9.0 |
|
| 677 | - */ |
|
| 678 | - public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 672 | + /** |
|
| 673 | + * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 674 | + * it to provide user with a better alternative. |
|
| 675 | + * |
|
| 676 | + * @deprecated since 1.9.0 |
|
| 677 | + */ |
|
| 678 | + public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 679 | 679 | |
| 680 | - // Question Type |
|
| 681 | - global $sensei_question_loop; |
|
| 682 | - $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 683 | - sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 684 | - |
|
| 685 | - } |
|
| 680 | + // Question Type |
|
| 681 | + global $sensei_question_loop; |
|
| 682 | + $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 683 | + sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 684 | + |
|
| 685 | + } |
|
| 686 | 686 | }//end class |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP |
|
| 3 | 3 | /** |
| 4 | 4 | * Sensei Template Class |
| 5 | 5 | * |
@@ -20,38 +20,38 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return void |
| 22 | 22 | */ |
| 23 | - public static function get_part( $slug, $name = '' ){ |
|
| 23 | + public static function get_part($slug, $name = '') { |
|
| 24 | 24 | |
| 25 | 25 | $template = ''; |
| 26 | 26 | $plugin_template_url = Sensei()->template_url; |
| 27 | - $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 27 | + $plugin_template_path = Sensei()->plugin_path()."/templates/"; |
|
| 28 | 28 | |
| 29 | 29 | // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
| 30 | - if ( $name ){ |
|
| 30 | + if ($name) { |
|
| 31 | 31 | |
| 32 | - $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 32 | + $template = locate_template(array("{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php")); |
|
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // Get default slug-name.php |
| 37 | - if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 37 | + if ( ! $template && $name && file_exists($plugin_template_path."{$slug}-{$name}.php")) { |
|
| 38 | 38 | |
| 39 | - $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 39 | + $template = $plugin_template_path."{$slug}-{$name}.php"; |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
| 45 | - if ( !$template ){ |
|
| 45 | + if ( ! $template) { |
|
| 46 | 46 | |
| 47 | - $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 47 | + $template = locate_template(array("{$slug}.php", "{$plugin_template_url}{$slug}.php")); |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - if ( $template ){ |
|
| 52 | + if ($template) { |
|
| 53 | 53 | |
| 54 | - load_template( $template, false ); |
|
| 54 | + load_template($template, false); |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | |
@@ -67,20 +67,20 @@ discard block |
||
| 67 | 67 | * @param string $template_path |
| 68 | 68 | * @param string $default_path |
| 69 | 69 | */ |
| 70 | - public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 70 | + public static function get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 71 | 71 | |
| 72 | - if ( $args && is_array($args) ) |
|
| 73 | - extract( $args ); |
|
| 72 | + if ($args && is_array($args)) |
|
| 73 | + extract($args); |
|
| 74 | 74 | |
| 75 | - $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 75 | + $located = self::locate_template($template_name, $template_path, $default_path); |
|
| 76 | 76 | |
| 77 | - if( ! empty( $located ) ){ |
|
| 77 | + if ( ! empty($located)) { |
|
| 78 | 78 | |
| 79 | - do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 79 | + do_action('sensei_before_template_part', $template_name, $template_path, $located); |
|
| 80 | 80 | |
| 81 | - include( $located ); |
|
| 81 | + include($located); |
|
| 82 | 82 | |
| 83 | - do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 83 | + do_action('sensei_after_template_part', $template_name, $template_path, $located); |
|
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | |
@@ -97,32 +97,32 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return mixed|void |
| 99 | 99 | */ |
| 100 | - public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 100 | + public static function locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 101 | 101 | |
| 102 | - if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | - if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 102 | + if ( ! $template_path) $template_path = Sensei()->template_url; |
|
| 103 | + if ( ! $default_path) $default_path = Sensei()->plugin_path().'/templates/'; |
|
| 104 | 104 | |
| 105 | 105 | // Look within passed path within the theme - this is priority |
| 106 | 106 | $template = locate_template( |
| 107 | 107 | array( |
| 108 | - $template_path . $template_name, |
|
| 108 | + $template_path.$template_name, |
|
| 109 | 109 | $template_name |
| 110 | 110 | ) |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | 113 | // Get default template |
| 114 | - if ( ! $template ){ |
|
| 114 | + if ( ! $template) { |
|
| 115 | 115 | |
| 116 | - $template = $default_path . $template_name; |
|
| 116 | + $template = $default_path.$template_name; |
|
| 117 | 117 | |
| 118 | 118 | } |
| 119 | 119 | // return nothing for file that do not exist |
| 120 | - if( !file_exists( $template ) ){ |
|
| 120 | + if ( ! file_exists($template)) { |
|
| 121 | 121 | $template = ''; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // Return what we found |
| 125 | - return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 125 | + return apply_filters('sensei_locate_template', $template, $template_name, $template_path); |
|
| 126 | 126 | |
| 127 | 127 | } // end locate |
| 128 | 128 | |
@@ -135,30 +135,30 @@ discard block |
||
| 135 | 135 | * @param string $template |
| 136 | 136 | * @return string $template |
| 137 | 137 | */ |
| 138 | - public static function template_loader ( $template = '' ) { |
|
| 138 | + public static function template_loader($template = '') { |
|
| 139 | 139 | |
| 140 | 140 | global $wp_query, $email_template; |
| 141 | 141 | |
| 142 | - $find = array( 'woothemes-sensei.php' ); |
|
| 142 | + $find = array('woothemes-sensei.php'); |
|
| 143 | 143 | $file = ''; |
| 144 | 144 | |
| 145 | - if ( isset( $email_template ) && $email_template ) { |
|
| 145 | + if (isset($email_template) && $email_template) { |
|
| 146 | 146 | |
| 147 | - $file = 'emails/' . $email_template; |
|
| 147 | + $file = 'emails/'.$email_template; |
|
| 148 | 148 | $find[] = $file; |
| 149 | - $find[] = Sensei()->template_url . $file; |
|
| 149 | + $find[] = Sensei()->template_url.$file; |
|
| 150 | 150 | |
| 151 | - } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 151 | + } elseif (is_single() && get_post_type() == 'course') { |
|
| 152 | 152 | |
| 153 | - if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 153 | + if (Sensei()->check_user_permissions('course-single')) { |
|
| 154 | 154 | |
| 155 | 155 | // possible backward compatible template include if theme overrides content-single-course.php |
| 156 | 156 | // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
| 157 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 157 | + self::locate_and_load_template_overrides(Sensei()->template_url.'content-single-course.php', true); |
|
| 158 | 158 | |
| 159 | - $file = 'single-course.php'; |
|
| 159 | + $file = 'single-course.php'; |
|
| 160 | 160 | $find[] = $file; |
| 161 | - $find[] = Sensei()->template_url . $file; |
|
| 161 | + $find[] = Sensei()->template_url.$file; |
|
| 162 | 162 | |
| 163 | 163 | } else { |
| 164 | 164 | |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | } // End If Statement |
| 169 | 169 | |
| 170 | - } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 170 | + } elseif (is_single() && get_post_type() == 'lesson') { |
|
| 171 | 171 | |
| 172 | - if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 172 | + if (Sensei()->check_user_permissions('lesson-single')) { |
|
| 173 | 173 | |
| 174 | 174 | // possible backward compatible template include if theme overrides content-single-lesson.php |
| 175 | 175 | // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
| 176 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 176 | + self::locate_and_load_template_overrides(Sensei()->template_url.'content-single-lesson.php', true); |
|
| 177 | 177 | |
| 178 | - $file = 'single-lesson.php'; |
|
| 178 | + $file = 'single-lesson.php'; |
|
| 179 | 179 | $find[] = $file; |
| 180 | - $find[] = Sensei()->template_url . $file; |
|
| 180 | + $find[] = Sensei()->template_url.$file; |
|
| 181 | 181 | |
| 182 | 182 | } else { |
| 183 | 183 | |
@@ -186,17 +186,17 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | } // End If Statement |
| 188 | 188 | |
| 189 | - } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 189 | + } elseif (is_single() && get_post_type() == 'quiz') { |
|
| 190 | 190 | |
| 191 | - if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 191 | + if (Sensei()->check_user_permissions('quiz-single')) { |
|
| 192 | 192 | |
| 193 | 193 | // possible backward compatible template include if theme overrides content-single-quiz.php |
| 194 | 194 | // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
| 195 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 195 | + self::locate_and_load_template_overrides(Sensei()->template_url.'content-single-quiz.php', true); |
|
| 196 | 196 | |
| 197 | - $file = 'single-quiz.php'; |
|
| 197 | + $file = 'single-quiz.php'; |
|
| 198 | 198 | $find[] = $file; |
| 199 | - $find[] = Sensei()->template_url . $file; |
|
| 199 | + $find[] = Sensei()->template_url.$file; |
|
| 200 | 200 | |
| 201 | 201 | } else { |
| 202 | 202 | |
@@ -205,76 +205,76 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | } // End If Statement |
| 207 | 207 | |
| 208 | - } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 208 | + } elseif (is_single() && get_post_type() == 'sensei_message') { |
|
| 209 | 209 | |
| 210 | 210 | // possible backward compatible template include if theme overrides content-single-message.php |
| 211 | 211 | // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
| 212 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 212 | + self::locate_and_load_template_overrides(Sensei()->template_url.'content-single-message.php', true); |
|
| 213 | 213 | |
| 214 | - $file = 'single-message.php'; |
|
| 214 | + $file = 'single-message.php'; |
|
| 215 | 215 | $find[] = $file; |
| 216 | - $find[] = Sensei()->template_url . $file; |
|
| 216 | + $find[] = Sensei()->template_url.$file; |
|
| 217 | 217 | |
| 218 | - } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | - || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | - || is_tax( 'course-category' )) { |
|
| 218 | + } elseif (is_post_type_archive('course') |
|
| 219 | + || is_page(Sensei()->get_page_id('courses')) |
|
| 220 | + || is_tax('course-category')) { |
|
| 221 | 221 | |
| 222 | 222 | // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
| 223 | 223 | // this template was removed in 1.9.0 and replaced by archive-course.php |
| 224 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 224 | + self::locate_and_load_template_overrides(Sensei()->template_url.'taxonomy-course-category.php'); |
|
| 225 | 225 | |
| 226 | - $file = 'archive-course.php'; |
|
| 226 | + $file = 'archive-course.php'; |
|
| 227 | 227 | $find[] = $file; |
| 228 | - $find[] = Sensei()->template_url . $file; |
|
| 228 | + $find[] = Sensei()->template_url.$file; |
|
| 229 | 229 | |
| 230 | - } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 230 | + } elseif (is_post_type_archive('sensei_message')) { |
|
| 231 | 231 | |
| 232 | - $file = 'archive-message.php'; |
|
| 232 | + $file = 'archive-message.php'; |
|
| 233 | 233 | $find[] = $file; |
| 234 | - $find[] = Sensei()->template_url . $file; |
|
| 234 | + $find[] = Sensei()->template_url.$file; |
|
| 235 | 235 | |
| 236 | - } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 236 | + } elseif (is_tax('lesson-tag')) { |
|
| 237 | 237 | |
| 238 | 238 | // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
| 239 | 239 | // this template was removed in 1.9.0 and replaced by archive-lesson.php |
| 240 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 240 | + self::locate_and_load_template_overrides(Sensei()->template_url.'taxonomy-lesson-tag.php'); |
|
| 241 | 241 | |
| 242 | - $file = 'archive-lesson.php'; |
|
| 242 | + $file = 'archive-lesson.php'; |
|
| 243 | 243 | $find[] = $file; |
| 244 | - $find[] = Sensei()->template_url . $file; |
|
| 244 | + $find[] = Sensei()->template_url.$file; |
|
| 245 | 245 | |
| 246 | - } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 246 | + } elseif (isset($wp_query->query_vars['learner_profile'])) { |
|
| 247 | 247 | |
| 248 | 248 | // Override for sites with static home page |
| 249 | 249 | $wp_query->is_home = false; |
| 250 | 250 | |
| 251 | - $file = 'learner-profile.php'; |
|
| 251 | + $file = 'learner-profile.php'; |
|
| 252 | 252 | $find[] = $file; |
| 253 | - $find[] = Sensei()->template_url . $file; |
|
| 253 | + $find[] = Sensei()->template_url.$file; |
|
| 254 | 254 | |
| 255 | - } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 255 | + } elseif (isset($wp_query->query_vars['course_results'])) { |
|
| 256 | 256 | |
| 257 | 257 | // Override for sites with static home page |
| 258 | 258 | $wp_query->is_home = false; |
| 259 | 259 | |
| 260 | 260 | $file = 'course-results.php'; |
| 261 | 261 | $find[] = $file; |
| 262 | - $find[] = Sensei()->template_url . $file; |
|
| 262 | + $find[] = Sensei()->template_url.$file; |
|
| 263 | 263 | |
| 264 | - }elseif( is_author() |
|
| 265 | - && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | - && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 264 | + }elseif (is_author() |
|
| 265 | + && Sensei_Teacher::is_a_teacher(get_query_var('author')) |
|
| 266 | + && ! user_can(get_query_var('author'), 'manage_options')) { |
|
| 267 | 267 | |
| 268 | 268 | $file = 'teacher-archive.php'; |
| 269 | 269 | $find[] = $file; |
| 270 | - $find[] = Sensei()->template_url . $file; |
|
| 270 | + $find[] = Sensei()->template_url.$file; |
|
| 271 | 271 | |
| 272 | 272 | } // Load the template file |
| 273 | 273 | |
| 274 | - if ( $file ) { |
|
| 274 | + if ($file) { |
|
| 275 | 275 | |
| 276 | - $template = locate_template( $find ); |
|
| 277 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 276 | + $template = locate_template($find); |
|
| 277 | + if ( ! $template) $template = Sensei()->plugin_path().'/templates/'.$file; |
|
| 278 | 278 | |
| 279 | 279 | } // End If Statement |
| 280 | 280 | |
@@ -294,18 +294,18 @@ discard block |
||
| 294 | 294 | * |
| 295 | 295 | * @since 1.9.0 |
| 296 | 296 | */ |
| 297 | - public static function get_no_permission_template( ){ |
|
| 297 | + public static function get_no_permission_template( ) { |
|
| 298 | 298 | |
| 299 | 299 | // possible backward compatible template loading |
| 300 | 300 | // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
| 301 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 301 | + self::locate_and_load_template_overrides(Sensei()->template_url.'content-no-permissions.php', true); |
|
| 302 | 302 | |
| 303 | - $file = 'no-permissions.php'; |
|
| 303 | + $file = 'no-permissions.php'; |
|
| 304 | 304 | $find[] = $file; |
| 305 | - $find[] = Sensei()->template_url . $file; |
|
| 305 | + $find[] = Sensei()->template_url.$file; |
|
| 306 | 306 | |
| 307 | - $template = locate_template( $find ); |
|
| 308 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 307 | + $template = locate_template($find); |
|
| 308 | + if ( ! $template) $template = Sensei()->plugin_path().'/templates/'.$file; |
|
| 309 | 309 | |
| 310 | 310 | return $template; |
| 311 | 311 | |
@@ -324,20 +324,20 @@ discard block |
||
| 324 | 324 | * @param string $template |
| 325 | 325 | * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
| 326 | 326 | */ |
| 327 | - public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 327 | + public static function locate_and_load_template_overrides($template = '', $load_header_footer = false) { |
|
| 328 | 328 | |
| 329 | - $found_template = locate_template( array( $template ) ); |
|
| 330 | - if( $found_template ){ |
|
| 329 | + $found_template = locate_template(array($template)); |
|
| 330 | + if ($found_template) { |
|
| 331 | 331 | |
| 332 | - if( $load_header_footer ){ |
|
| 332 | + if ($load_header_footer) { |
|
| 333 | 333 | |
| 334 | 334 | get_sensei_header(); |
| 335 | - include( $found_template ); |
|
| 335 | + include($found_template); |
|
| 336 | 336 | get_sensei_footer(); |
| 337 | 337 | |
| 338 | - }else{ |
|
| 338 | + } else { |
|
| 339 | 339 | |
| 340 | - include( $found_template ); |
|
| 340 | + include($found_template); |
|
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | * |
| 355 | 355 | * @deprecated since 1.9.0 |
| 356 | 356 | */ |
| 357 | - public static function deprecated_archive_course_content_hook(){ |
|
| 357 | + public static function deprecated_archive_course_content_hook() { |
|
| 358 | 358 | |
| 359 | - sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 359 | + sensei_do_deprecated_action('sensei_course_archive_main_content', '1.9.0', 'sensei_loop_course_before'); |
|
| 360 | 360 | |
| 361 | 361 | }// end deprecated_archive_hook |
| 362 | 362 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * @since 1.9.0 |
| 367 | 367 | * @param WP_Post $post |
| 368 | 368 | */ |
| 369 | - public static function the_title( $post ){ |
|
| 369 | + public static function the_title($post) { |
|
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * Filter the template html tag for the title |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | * |
| 376 | 376 | * @param $title_html_tag default is 'h3' |
| 377 | 377 | */ |
| 378 | - $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 378 | + $title_html_tag = apply_filters('sensei_the_title_html_tag', 'h3'); |
|
| 379 | 379 | |
| 380 | 380 | /** |
| 381 | 381 | * Filter the title classes |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | * @since 1.9.0 |
| 384 | 384 | * @param string $title_classes defaults to $post_type-title |
| 385 | 385 | */ |
| 386 | - $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 386 | + $title_classes = apply_filters('sensei_the_title_classes', $post->post_type.'-title'); |
|
| 387 | 387 | |
| 388 | - $html= ''; |
|
| 389 | - $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 390 | - $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 391 | - $html .= $post->post_title ; |
|
| 388 | + $html = ''; |
|
| 389 | + $html .= '<'.$title_html_tag.' class="'.$title_classes.'" >'; |
|
| 390 | + $html .= '<a href="'.get_permalink($post->ID).'" >'; |
|
| 391 | + $html .= $post->post_title; |
|
| 392 | 392 | $html .= '</a>'; |
| 393 | - $html .= '</'. $title_html_tag. '>'; |
|
| 393 | + $html .= '</'.$title_html_tag.'>'; |
|
| 394 | 394 | echo $html; |
| 395 | 395 | |
| 396 | 396 | }// end the title |
@@ -402,11 +402,11 @@ discard block |
||
| 402 | 402 | * @since 1.9.0 |
| 403 | 403 | * @deprecated 1.9.0 |
| 404 | 404 | */ |
| 405 | - public static function deprecated_single_course_inside_before_hooks(){ |
|
| 405 | + public static function deprecated_single_course_inside_before_hooks() { |
|
| 406 | 406 | |
| 407 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 408 | - sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 409 | - sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 407 | + sensei_do_deprecated_action('sensei_course_image', '1.9.0', 'sensei_single_course_content_inside_before', array(get_the_ID())); |
|
| 408 | + sensei_do_deprecated_action('sensei_course_single_title', '1.9.0', 'sensei_single_course_content_inside_before'); |
|
| 409 | + sensei_do_deprecated_action('sensei_course_single_meta', '1.9.0', 'sensei_single_course_content_inside_before'); |
|
| 410 | 410 | |
| 411 | 411 | }// end deprecated_single_course_inside_before_hooks |
| 412 | 412 | |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * @since 1.9.0 |
| 418 | 418 | * @deprecated 1.9.0 |
| 419 | 419 | */ |
| 420 | - public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 420 | + public static function deprecate_sensei_course_single_lessons_hook() { |
|
| 421 | 421 | |
| 422 | - sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 422 | + sensei_do_deprecated_action('sensei_course_single_lessons', '1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 423 | 423 | |
| 424 | 424 | }// deprecate_sensei_course_single_lessons_hook |
| 425 | 425 | |
@@ -431,13 +431,13 @@ discard block |
||
| 431 | 431 | * @since 1.9.0 |
| 432 | 432 | * @deprecated 1.9.0 |
| 433 | 433 | */ |
| 434 | - public static function deprecated_single_main_content_hook(){ |
|
| 434 | + public static function deprecated_single_main_content_hook() { |
|
| 435 | 435 | |
| 436 | - if( is_singular( 'course' ) ) { |
|
| 436 | + if (is_singular('course')) { |
|
| 437 | 437 | |
| 438 | 438 | sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
| 439 | 439 | |
| 440 | - } elseif( is_singular( 'message' ) ){ |
|
| 440 | + } elseif (is_singular('message')) { |
|
| 441 | 441 | |
| 442 | 442 | sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
| 443 | 443 | } |
@@ -449,9 +449,9 @@ discard block |
||
| 449 | 449 | * @since 1.9.0 |
| 450 | 450 | * @deprecated since 1.9.0 |
| 451 | 451 | */ |
| 452 | - public static function deprecate_module_before_hook(){ |
|
| 452 | + public static function deprecate_module_before_hook() { |
|
| 453 | 453 | |
| 454 | - sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 454 | + sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0', 'sensei_single_course_modules_after'); |
|
| 455 | 455 | |
| 456 | 456 | } |
| 457 | 457 | |
@@ -460,9 +460,9 @@ discard block |
||
| 460 | 460 | * @since 1.9.0 |
| 461 | 461 | * @deprecated since 1.9.0 |
| 462 | 462 | */ |
| 463 | - public static function deprecate_module_after_hook(){ |
|
| 463 | + public static function deprecate_module_after_hook() { |
|
| 464 | 464 | |
| 465 | - sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 465 | + sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0', 'sensei_single_course_modules_after'); |
|
| 466 | 466 | |
| 467 | 467 | } |
| 468 | 468 | |
@@ -472,11 +472,11 @@ discard block |
||
| 472 | 472 | * @since 1.9.0 |
| 473 | 473 | * @deprecated since 1.9.0 |
| 474 | 474 | */ |
| 475 | - public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 475 | + public static function deprecate_all_post_type_single_title_hooks() { |
|
| 476 | 476 | |
| 477 | - if( is_singular( 'sensei_message' ) ){ |
|
| 477 | + if (is_singular('sensei_message')) { |
|
| 478 | 478 | |
| 479 | - sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 479 | + sensei_do_deprecated_action('sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before'); |
|
| 480 | 480 | |
| 481 | 481 | } |
| 482 | 482 | |
@@ -492,10 +492,10 @@ discard block |
||
| 492 | 492 | public static function deprecate_course_single_meta_hooks() { |
| 493 | 493 | |
| 494 | 494 | // deprecate all these hooks |
| 495 | - sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 496 | - sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 497 | - sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 498 | - sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 495 | + sensei_do_deprecated_action('sensei_course_start', '1.9.0', 'sensei_single_course_content_inside_before'); |
|
| 496 | + sensei_do_deprecated_action('sensei_woocommerce_in_cart_message', '1.9.0', 'sensei_single_course_content_inside_before'); |
|
| 497 | + sensei_do_deprecated_action('sensei_course_meta', '1.9.0', 'sensei_single_course_content_inside_before'); |
|
| 498 | + sensei_do_deprecated_action('sensei_course_meta_video', '1.9.0', 'sensei_single_course_content_inside_before'); |
|
| 499 | 499 | |
| 500 | 500 | } // End deprecate_course_single_meta_hooks |
| 501 | 501 | |
@@ -505,10 +505,10 @@ discard block |
||
| 505 | 505 | */ |
| 506 | 506 | public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
| 507 | 507 | |
| 508 | - if( is_singular( 'lesson' ) ){ |
|
| 508 | + if (is_singular('lesson')) { |
|
| 509 | 509 | |
| 510 | - sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 511 | - sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 510 | + sensei_do_deprecated_action('sensei_breadcrumb', '1.9.0', 'sensei_after_main_content', get_the_ID()); |
|
| 511 | + sensei_do_deprecated_action('sensei_comments', '1.9.0', 'sensei_after_main_content', get_the_ID()); |
|
| 512 | 512 | |
| 513 | 513 | } |
| 514 | 514 | |
@@ -522,14 +522,14 @@ discard block |
||
| 522 | 522 | * |
| 523 | 523 | * @deprecated since 1.9.0 |
| 524 | 524 | */ |
| 525 | - public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 525 | + public static function deprecate_sensei_lesson_course_signup_hook() { |
|
| 526 | 526 | |
| 527 | - $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 528 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 527 | + $lesson_course_id = get_post_meta(get_the_ID(), '_lesson_course', true); |
|
| 528 | + $user_taking_course = Sensei_Utils::user_started_course($lesson_course_id, get_current_user_id()); |
|
| 529 | 529 | |
| 530 | - if( !$user_taking_course ) { |
|
| 530 | + if ( ! $user_taking_course) { |
|
| 531 | 531 | |
| 532 | - sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 532 | + sensei_do_deprecated_action('sensei_lesson_course_signup', '1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id); |
|
| 533 | 533 | |
| 534 | 534 | } |
| 535 | 535 | }// end deprecate_sensei_lesson_course_signup_hook |
@@ -540,11 +540,11 @@ discard block |
||
| 540 | 540 | * @since 1.9.0 |
| 541 | 541 | * @deprecated since 1.9.0 |
| 542 | 542 | */ |
| 543 | - public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 543 | + public static function deprecate_sensei_lesson_single_meta_hook() { |
|
| 544 | 544 | |
| 545 | - if ( sensei_can_user_view_lesson() ) { |
|
| 545 | + if (sensei_can_user_view_lesson()) { |
|
| 546 | 546 | |
| 547 | - sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 547 | + sensei_do_deprecated_action('sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after'); |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | 550 | } |
@@ -555,9 +555,9 @@ discard block |
||
| 555 | 555 | * Deprecate the sensei lesson single title hook |
| 556 | 556 | * @deprecated since 1.9.0 |
| 557 | 557 | */ |
| 558 | - public static function deprecate_sensei_lesson_single_title(){ |
|
| 558 | + public static function deprecate_sensei_lesson_single_title() { |
|
| 559 | 559 | |
| 560 | - sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 560 | + sensei_do_deprecated_action('sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID()); |
|
| 561 | 561 | |
| 562 | 562 | }// end deprecate_sensei_lesson_single_title |
| 563 | 563 | |
@@ -565,9 +565,9 @@ discard block |
||
| 565 | 565 | * hook in the deperecated single main content to the lesson |
| 566 | 566 | * @deprecated since 1.9.0 |
| 567 | 567 | */ |
| 568 | - public static function deprecate_lesson_single_main_content_hook(){ |
|
| 568 | + public static function deprecate_lesson_single_main_content_hook() { |
|
| 569 | 569 | |
| 570 | - sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 570 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before'); |
|
| 571 | 571 | |
| 572 | 572 | }// end sensei_deprecate_lesson_single_main_content_hook |
| 573 | 573 | |
@@ -575,9 +575,9 @@ discard block |
||
| 575 | 575 | * hook in the deperecated single main content to the lesson |
| 576 | 576 | * @deprecated since 1.9.0 |
| 577 | 577 | */ |
| 578 | - public static function deprecate_lesson_image_hook(){ |
|
| 578 | + public static function deprecate_lesson_image_hook() { |
|
| 579 | 579 | |
| 580 | - sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 580 | + sensei_do_deprecated_action('sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID()); |
|
| 581 | 581 | |
| 582 | 582 | }// end sensei_deprecate_lesson_single_main_content_hook |
| 583 | 583 | |
@@ -588,9 +588,9 @@ discard block |
||
| 588 | 588 | * @since 1.9.0 |
| 589 | 589 | * @deprecated since 1.9.0 |
| 590 | 590 | */ |
| 591 | - public static function deprecate_sensei_login_form_hook(){ |
|
| 591 | + public static function deprecate_sensei_login_form_hook() { |
|
| 592 | 592 | |
| 593 | - sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 593 | + sensei_do_deprecated_action('sensei_login_form', '1.9.0', 'sensei_login_form_before'); |
|
| 594 | 594 | |
| 595 | 595 | } // end deprecate_sensei_login_form_hook |
| 596 | 596 | |
@@ -603,9 +603,9 @@ discard block |
||
| 603 | 603 | * |
| 604 | 604 | * @since 1.9.0 |
| 605 | 605 | */ |
| 606 | - public static function fire_sensei_complete_course_hook(){ |
|
| 606 | + public static function fire_sensei_complete_course_hook() { |
|
| 607 | 607 | |
| 608 | - do_action( 'sensei_complete_course' ); |
|
| 608 | + do_action('sensei_complete_course'); |
|
| 609 | 609 | |
| 610 | 610 | } //fire_sensei_complete_course_hook |
| 611 | 611 | |
@@ -614,9 +614,9 @@ discard block |
||
| 614 | 614 | * |
| 615 | 615 | * @since 1.9.0 |
| 616 | 616 | */ |
| 617 | - public static function fire_frontend_messages_hook(){ |
|
| 617 | + public static function fire_frontend_messages_hook() { |
|
| 618 | 618 | |
| 619 | - do_action( 'sensei_frontend_messages' ); |
|
| 619 | + do_action('sensei_frontend_messages'); |
|
| 620 | 620 | |
| 621 | 621 | }// end sensei_complete_course_action |
| 622 | 622 | |
@@ -626,9 +626,9 @@ discard block |
||
| 626 | 626 | * |
| 627 | 627 | * @deprected since 1.9.0 |
| 628 | 628 | */ |
| 629 | - public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 629 | + public static function deprecate_sensei_before_user_course_content_hook() { |
|
| 630 | 630 | |
| 631 | - sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 631 | + sensei_do_deprecated_action('sensei_before_user_course_content', '1.9.0', 'sensei_my_courses_content_inside_before', wp_get_current_user()); |
|
| 632 | 632 | |
| 633 | 633 | }// deprecate_sensei_before_user_course_content_hook |
| 634 | 634 | |
@@ -638,9 +638,9 @@ discard block |
||
| 638 | 638 | * |
| 639 | 639 | * @deprected since 1.9.0 |
| 640 | 640 | */ |
| 641 | - public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 641 | + public static function deprecate_sensei_after_user_course_content_hook() { |
|
| 642 | 642 | |
| 643 | - sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 643 | + sensei_do_deprecated_action('sensei_after_user_course_content', '1.9.0', 'sensei_my_courses_content_inside_after', wp_get_current_user()); |
|
| 644 | 644 | |
| 645 | 645 | }// deprecate_sensei_after_user_course_content_hook |
| 646 | 646 | |
@@ -650,10 +650,10 @@ discard block |
||
| 650 | 650 | * @deprecated since 1.9.0 |
| 651 | 651 | * @since 1.9.0 |
| 652 | 652 | */ |
| 653 | - public static function deprecated_archive_message_hooks (){ |
|
| 653 | + public static function deprecated_archive_message_hooks() { |
|
| 654 | 654 | |
| 655 | - sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 656 | - sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 655 | + sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop'); |
|
| 656 | + sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop'); |
|
| 657 | 657 | |
| 658 | 658 | } |
| 659 | 659 | |
@@ -663,9 +663,9 @@ discard block |
||
| 663 | 663 | * |
| 664 | 664 | * @deprecated since 1.9.0 |
| 665 | 665 | */ |
| 666 | - public static function deprecate_sensei_complete_quiz_action(){ |
|
| 666 | + public static function deprecate_sensei_complete_quiz_action() { |
|
| 667 | 667 | |
| 668 | - sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 668 | + sensei_do_deprecated_action('sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before'); |
|
| 669 | 669 | |
| 670 | 670 | } |
| 671 | 671 | |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | * |
| 676 | 676 | * @deprecated since 1.9.0 |
| 677 | 677 | */ |
| 678 | - public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 678 | + public static function deprecate_sensei_quiz_question_type_action() { |
|
| 679 | 679 | |
| 680 | 680 | // Question Type |
| 681 | 681 | global $sensei_question_loop; |
@@ -14,265 +14,265 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Core_Modules |
| 16 | 16 | { |
| 17 | - private $dir; |
|
| 18 | - private $file; |
|
| 19 | - private $assets_dir; |
|
| 20 | - private $assets_url; |
|
| 21 | - private $order_page_slug; |
|
| 22 | - public $taxonomy; |
|
| 23 | - |
|
| 24 | - public function __construct( $file ) |
|
| 25 | - { |
|
| 26 | - $this->file = $file; |
|
| 27 | - $this->dir = dirname($this->file); |
|
| 28 | - $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 29 | - $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
| 30 | - $this->taxonomy = 'module'; |
|
| 31 | - $this->order_page_slug = 'module-order'; |
|
| 32 | - |
|
| 33 | - // setup taxonomy |
|
| 34 | - add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 35 | - |
|
| 36 | - // Manage lesson meta boxes for taxonomy |
|
| 37 | - add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 38 | - |
|
| 39 | - // Save lesson meta box |
|
| 40 | - add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
| 41 | - |
|
| 42 | - //Reset the none modules lessons transient |
|
| 43 | - add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 44 | - |
|
| 45 | - // Frontend styling |
|
| 46 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 47 | - |
|
| 48 | - // Admin styling |
|
| 49 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
| 50 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 51 | - |
|
| 52 | - // Handle module completion record |
|
| 53 | - add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
| 54 | - add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
| 55 | - add_action('wp', array($this, 'save_module_progress'), 10); |
|
| 56 | - |
|
| 57 | - // Handle module ordering |
|
| 58 | - add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 59 | - add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
| 60 | - add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
| 61 | - |
|
| 62 | - // Ensure modules always show under courses |
|
| 63 | - add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | - add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | - add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 66 | - |
|
| 67 | - // Add course field to taxonomy |
|
| 68 | - add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | - add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | - add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | - add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | - add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
| 73 | - |
|
| 74 | - // Manage module taxonomy archive page |
|
| 75 | - add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
| 76 | - add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
| 77 | - add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
| 78 | - add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
| 79 | - add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
| 80 | - add_filter('body_class', array($this, 'module_archive_body_class')); |
|
| 81 | - |
|
| 82 | - // add modules to the single course template |
|
| 83 | - add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 84 | - |
|
| 85 | - //Single Course modules actions. Add to single-course/course-modules.php |
|
| 86 | - add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 87 | - |
|
| 88 | - // Set up display on single lesson page |
|
| 89 | - add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
| 90 | - |
|
| 91 | - // Add 'Modules' columns to Analysis tables |
|
| 92 | - add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
| 93 | - add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
| 94 | - add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
| 95 | - add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
| 96 | - |
|
| 97 | - // Manage module taxonomy columns |
|
| 98 | - add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | - add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | - add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
| 101 | - |
|
| 102 | - //store new modules created on the course edit screen |
|
| 103 | - add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 104 | - |
|
| 105 | - // for non admin users, only show taxonomies that belong to them |
|
| 106 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | - add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 108 | - |
|
| 109 | - // add the teacher name next to the module term in for admin users |
|
| 110 | - add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 111 | - |
|
| 112 | - // remove the default modules metabox |
|
| 113 | - add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 114 | - |
|
| 115 | - } // end constructor |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Alter a module term slug when a new taxonomy term is created |
|
| 119 | - * This will add the creators user name to the slug for uniqueness. |
|
| 120 | - * |
|
| 121 | - * @since 1.8.0 |
|
| 122 | - * |
|
| 123 | - * @param $term_id |
|
| 124 | - * @param $tt_id |
|
| 125 | - * @param $taxonomy |
|
| 126 | - * |
|
| 127 | - * @return void |
|
| 128 | - * @deprecated since 1.9.0 |
|
| 129 | - */ |
|
| 130 | - public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 131 | - |
|
| 132 | - _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 133 | - |
|
| 134 | - }// end add_module_term_group |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Hook in all meta boxes related tot he modules taxonomy |
|
| 138 | - * |
|
| 139 | - * @since 1.8.0 |
|
| 140 | - * |
|
| 141 | - * @param string $post_type |
|
| 142 | - * @param WP_Post $post |
|
| 143 | - * |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function modules_metaboxes( $post_type, $post ) |
|
| 147 | - { |
|
| 148 | - if ('lesson' == $post_type ) { |
|
| 149 | - |
|
| 150 | - // Remove default taxonomy meta box from Lesson edit screen |
|
| 151 | - remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 152 | - |
|
| 153 | - // Add custom meta box to limit module selection to one per lesson |
|
| 154 | - add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if( 'course' == $post_type ){ |
|
| 158 | - // Course modules selection metabox |
|
| 159 | - add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Build content for custom module meta box |
|
| 165 | - * |
|
| 166 | - * @since 1.8.0 |
|
| 167 | - * @param object $post Current post object |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public function lesson_module_metabox($post) |
|
| 171 | - { |
|
| 172 | - |
|
| 173 | - // Get lesson course |
|
| 174 | - $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
| 175 | - |
|
| 176 | - $html = ''; |
|
| 177 | - |
|
| 178 | - // Only show module selection if this lesson is part of a course |
|
| 179 | - if ($lesson_course && $lesson_course > 0) { |
|
| 180 | - |
|
| 181 | - // Get existing lesson module |
|
| 182 | - $lesson_module = 0; |
|
| 183 | - $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
| 184 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 185 | - foreach ($lesson_module_list as $single_module) { |
|
| 186 | - $lesson_module = $single_module->term_id; |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Get the available modules for this lesson's course |
|
| 192 | - $modules = $this->get_course_modules($lesson_course); |
|
| 193 | - |
|
| 194 | - // Build the HTML to output |
|
| 195 | - $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 196 | - if (is_array($modules) && count($modules) > 0) { |
|
| 197 | - $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | - $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 199 | - foreach ($modules as $module) { |
|
| 200 | - $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 201 | - } |
|
| 202 | - $html .= '</select>' . "\n"; |
|
| 203 | - } else { |
|
| 204 | - $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 206 | - } // End If Statement |
|
| 207 | - |
|
| 208 | - } else { |
|
| 209 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 210 | - } // End If Statement |
|
| 211 | - |
|
| 212 | - // Output the HTML |
|
| 213 | - echo $html; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Save module to lesson |
|
| 218 | - * |
|
| 219 | - * @since 1.8.0 |
|
| 220 | - * @param integer $post_id ID of post |
|
| 221 | - * @return mixed Post ID on permissions failure, boolean true on success |
|
| 222 | - */ |
|
| 223 | - public function save_lesson_module($post_id) |
|
| 224 | - { |
|
| 225 | - global $post; |
|
| 226 | - |
|
| 227 | - // Verify post type and nonce |
|
| 228 | - if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | - ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 230 | - return $post_id; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // Check if user has permissions to edit lessons |
|
| 234 | - $post_type = get_post_type_object($post->post_type); |
|
| 235 | - if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | - return $post_id; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Check if user has permissions to edit this specific post |
|
| 240 | - if (!current_user_can('edit_post', $post_id)) { |
|
| 241 | - return $post_id; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Cast module ID as an integer if selected, otherwise leave as empty string |
|
| 245 | - if ( isset( $_POST['lesson_module'] ) ) { |
|
| 246 | - |
|
| 247 | - if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | - wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 249 | - return true; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $module_id = intval( $_POST['lesson_module'] ); |
|
| 253 | - |
|
| 254 | - // Assign lesson to selected module |
|
| 255 | - wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
| 256 | - |
|
| 257 | - // Set default order for lesson inside module |
|
| 258 | - if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | - update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Display course field on new module screen |
|
| 268 | - * |
|
| 269 | - * @since 1.8.0 |
|
| 270 | - * @param object $taxonomy Taxonomy object |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - public function add_module_fields($taxonomy) |
|
| 274 | - { |
|
| 275 | - ?> |
|
| 17 | + private $dir; |
|
| 18 | + private $file; |
|
| 19 | + private $assets_dir; |
|
| 20 | + private $assets_url; |
|
| 21 | + private $order_page_slug; |
|
| 22 | + public $taxonomy; |
|
| 23 | + |
|
| 24 | + public function __construct( $file ) |
|
| 25 | + { |
|
| 26 | + $this->file = $file; |
|
| 27 | + $this->dir = dirname($this->file); |
|
| 28 | + $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 29 | + $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
| 30 | + $this->taxonomy = 'module'; |
|
| 31 | + $this->order_page_slug = 'module-order'; |
|
| 32 | + |
|
| 33 | + // setup taxonomy |
|
| 34 | + add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 35 | + |
|
| 36 | + // Manage lesson meta boxes for taxonomy |
|
| 37 | + add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 38 | + |
|
| 39 | + // Save lesson meta box |
|
| 40 | + add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
| 41 | + |
|
| 42 | + //Reset the none modules lessons transient |
|
| 43 | + add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 44 | + |
|
| 45 | + // Frontend styling |
|
| 46 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 47 | + |
|
| 48 | + // Admin styling |
|
| 49 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
| 50 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 51 | + |
|
| 52 | + // Handle module completion record |
|
| 53 | + add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
| 54 | + add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
| 55 | + add_action('wp', array($this, 'save_module_progress'), 10); |
|
| 56 | + |
|
| 57 | + // Handle module ordering |
|
| 58 | + add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 59 | + add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
| 60 | + add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
| 61 | + |
|
| 62 | + // Ensure modules always show under courses |
|
| 63 | + add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | + add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | + add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 66 | + |
|
| 67 | + // Add course field to taxonomy |
|
| 68 | + add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | + add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | + add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | + add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | + add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
| 73 | + |
|
| 74 | + // Manage module taxonomy archive page |
|
| 75 | + add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
| 76 | + add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
| 77 | + add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
| 78 | + add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
| 79 | + add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
| 80 | + add_filter('body_class', array($this, 'module_archive_body_class')); |
|
| 81 | + |
|
| 82 | + // add modules to the single course template |
|
| 83 | + add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 84 | + |
|
| 85 | + //Single Course modules actions. Add to single-course/course-modules.php |
|
| 86 | + add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 87 | + |
|
| 88 | + // Set up display on single lesson page |
|
| 89 | + add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
| 90 | + |
|
| 91 | + // Add 'Modules' columns to Analysis tables |
|
| 92 | + add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
| 93 | + add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
| 94 | + add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
| 95 | + add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
| 96 | + |
|
| 97 | + // Manage module taxonomy columns |
|
| 98 | + add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | + add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | + add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
| 101 | + |
|
| 102 | + //store new modules created on the course edit screen |
|
| 103 | + add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 104 | + |
|
| 105 | + // for non admin users, only show taxonomies that belong to them |
|
| 106 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | + add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 108 | + |
|
| 109 | + // add the teacher name next to the module term in for admin users |
|
| 110 | + add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 111 | + |
|
| 112 | + // remove the default modules metabox |
|
| 113 | + add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 114 | + |
|
| 115 | + } // end constructor |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Alter a module term slug when a new taxonomy term is created |
|
| 119 | + * This will add the creators user name to the slug for uniqueness. |
|
| 120 | + * |
|
| 121 | + * @since 1.8.0 |
|
| 122 | + * |
|
| 123 | + * @param $term_id |
|
| 124 | + * @param $tt_id |
|
| 125 | + * @param $taxonomy |
|
| 126 | + * |
|
| 127 | + * @return void |
|
| 128 | + * @deprecated since 1.9.0 |
|
| 129 | + */ |
|
| 130 | + public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 131 | + |
|
| 132 | + _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 133 | + |
|
| 134 | + }// end add_module_term_group |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Hook in all meta boxes related tot he modules taxonomy |
|
| 138 | + * |
|
| 139 | + * @since 1.8.0 |
|
| 140 | + * |
|
| 141 | + * @param string $post_type |
|
| 142 | + * @param WP_Post $post |
|
| 143 | + * |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function modules_metaboxes( $post_type, $post ) |
|
| 147 | + { |
|
| 148 | + if ('lesson' == $post_type ) { |
|
| 149 | + |
|
| 150 | + // Remove default taxonomy meta box from Lesson edit screen |
|
| 151 | + remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 152 | + |
|
| 153 | + // Add custom meta box to limit module selection to one per lesson |
|
| 154 | + add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if( 'course' == $post_type ){ |
|
| 158 | + // Course modules selection metabox |
|
| 159 | + add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Build content for custom module meta box |
|
| 165 | + * |
|
| 166 | + * @since 1.8.0 |
|
| 167 | + * @param object $post Current post object |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public function lesson_module_metabox($post) |
|
| 171 | + { |
|
| 172 | + |
|
| 173 | + // Get lesson course |
|
| 174 | + $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
| 175 | + |
|
| 176 | + $html = ''; |
|
| 177 | + |
|
| 178 | + // Only show module selection if this lesson is part of a course |
|
| 179 | + if ($lesson_course && $lesson_course > 0) { |
|
| 180 | + |
|
| 181 | + // Get existing lesson module |
|
| 182 | + $lesson_module = 0; |
|
| 183 | + $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
| 184 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 185 | + foreach ($lesson_module_list as $single_module) { |
|
| 186 | + $lesson_module = $single_module->term_id; |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Get the available modules for this lesson's course |
|
| 192 | + $modules = $this->get_course_modules($lesson_course); |
|
| 193 | + |
|
| 194 | + // Build the HTML to output |
|
| 195 | + $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 196 | + if (is_array($modules) && count($modules) > 0) { |
|
| 197 | + $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | + $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 199 | + foreach ($modules as $module) { |
|
| 200 | + $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 201 | + } |
|
| 202 | + $html .= '</select>' . "\n"; |
|
| 203 | + } else { |
|
| 204 | + $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 206 | + } // End If Statement |
|
| 207 | + |
|
| 208 | + } else { |
|
| 209 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 210 | + } // End If Statement |
|
| 211 | + |
|
| 212 | + // Output the HTML |
|
| 213 | + echo $html; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Save module to lesson |
|
| 218 | + * |
|
| 219 | + * @since 1.8.0 |
|
| 220 | + * @param integer $post_id ID of post |
|
| 221 | + * @return mixed Post ID on permissions failure, boolean true on success |
|
| 222 | + */ |
|
| 223 | + public function save_lesson_module($post_id) |
|
| 224 | + { |
|
| 225 | + global $post; |
|
| 226 | + |
|
| 227 | + // Verify post type and nonce |
|
| 228 | + if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | + ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 230 | + return $post_id; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // Check if user has permissions to edit lessons |
|
| 234 | + $post_type = get_post_type_object($post->post_type); |
|
| 235 | + if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | + return $post_id; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Check if user has permissions to edit this specific post |
|
| 240 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 241 | + return $post_id; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Cast module ID as an integer if selected, otherwise leave as empty string |
|
| 245 | + if ( isset( $_POST['lesson_module'] ) ) { |
|
| 246 | + |
|
| 247 | + if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | + wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 249 | + return true; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $module_id = intval( $_POST['lesson_module'] ); |
|
| 253 | + |
|
| 254 | + // Assign lesson to selected module |
|
| 255 | + wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
| 256 | + |
|
| 257 | + // Set default order for lesson inside module |
|
| 258 | + if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | + update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Display course field on new module screen |
|
| 268 | + * |
|
| 269 | + * @since 1.8.0 |
|
| 270 | + * @param object $taxonomy Taxonomy object |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + public function add_module_fields($taxonomy) |
|
| 274 | + { |
|
| 275 | + ?> |
|
| 276 | 276 | <div class="form-field"> |
| 277 | 277 | <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label> |
| 278 | 278 | <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses" |
@@ -281,44 +281,44 @@ discard block |
||
| 281 | 281 | class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span> |
| 282 | 282 | </div> |
| 283 | 283 | <?php |
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Display course field on module edit screen |
|
| 288 | - * |
|
| 289 | - * @since 1.8.0 |
|
| 290 | - * @param object $module Module term object |
|
| 291 | - * @return void |
|
| 292 | - */ |
|
| 293 | - public function edit_module_fields($module) |
|
| 294 | - { |
|
| 295 | - |
|
| 296 | - $module_id = $module->term_id; |
|
| 297 | - |
|
| 298 | - // Get module's existing courses |
|
| 299 | - $args = array( |
|
| 300 | - 'post_type' => 'course', |
|
| 301 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 302 | - 'posts_per_page' => -1, |
|
| 303 | - 'tax_query' => array( |
|
| 304 | - array( |
|
| 305 | - 'taxonomy' => $this->taxonomy, |
|
| 306 | - 'field' => 'id', |
|
| 307 | - 'terms' => $module_id |
|
| 308 | - ) |
|
| 309 | - ) |
|
| 310 | - ); |
|
| 311 | - $courses = get_posts($args); |
|
| 312 | - |
|
| 313 | - //build the defaults array |
|
| 314 | - $module_courses = array(); |
|
| 315 | - if (isset($courses) && is_array($courses)) { |
|
| 316 | - foreach ($courses as $course) { |
|
| 317 | - $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - ?> |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Display course field on module edit screen |
|
| 288 | + * |
|
| 289 | + * @since 1.8.0 |
|
| 290 | + * @param object $module Module term object |
|
| 291 | + * @return void |
|
| 292 | + */ |
|
| 293 | + public function edit_module_fields($module) |
|
| 294 | + { |
|
| 295 | + |
|
| 296 | + $module_id = $module->term_id; |
|
| 297 | + |
|
| 298 | + // Get module's existing courses |
|
| 299 | + $args = array( |
|
| 300 | + 'post_type' => 'course', |
|
| 301 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 302 | + 'posts_per_page' => -1, |
|
| 303 | + 'tax_query' => array( |
|
| 304 | + array( |
|
| 305 | + 'taxonomy' => $this->taxonomy, |
|
| 306 | + 'field' => 'id', |
|
| 307 | + 'terms' => $module_id |
|
| 308 | + ) |
|
| 309 | + ) |
|
| 310 | + ); |
|
| 311 | + $courses = get_posts($args); |
|
| 312 | + |
|
| 313 | + //build the defaults array |
|
| 314 | + $module_courses = array(); |
|
| 315 | + if (isset($courses) && is_array($courses)) { |
|
| 316 | + foreach ($courses as $course) { |
|
| 317 | + $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + ?> |
|
| 322 | 322 | <tr class="form-field"> |
| 323 | 323 | <th scope="row" valign="top"><label |
| 324 | 324 | for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th> |
@@ -335,1399 +335,1399 @@ discard block |
||
| 335 | 335 | </td> |
| 336 | 336 | </tr> |
| 337 | 337 | <?php |
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Save module course on add/edit |
|
| 342 | - * |
|
| 343 | - * @since 1.8.0 |
|
| 344 | - * @param integer $module_id ID of module |
|
| 345 | - * @return void |
|
| 346 | - */ |
|
| 347 | - public function save_module_course($module_id) |
|
| 348 | - { |
|
| 349 | - |
|
| 350 | - // Get module's existing courses |
|
| 351 | - $args = array( |
|
| 352 | - 'post_type' => 'course', |
|
| 353 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 354 | - 'posts_per_page' => -1, |
|
| 355 | - 'tax_query' => array( |
|
| 356 | - array( |
|
| 357 | - 'taxonomy' => $this->taxonomy, |
|
| 358 | - 'field' => 'id', |
|
| 359 | - 'terms' => $module_id |
|
| 360 | - ) |
|
| 361 | - ) |
|
| 362 | - ); |
|
| 363 | - $courses = get_posts($args); |
|
| 364 | - |
|
| 365 | - // Remove module from existing courses |
|
| 366 | - if (isset($courses) && is_array($courses)) { |
|
| 367 | - foreach ($courses as $course) { |
|
| 368 | - wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Add module to selected courses |
|
| 373 | - if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 374 | - |
|
| 375 | - $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 376 | - |
|
| 377 | - foreach ( $course_ids as $course_id ) { |
|
| 378 | - |
|
| 379 | - wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
| 380 | - |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Ajax function to search for courses matching term |
|
| 387 | - * |
|
| 388 | - * @since 1.8.0 |
|
| 389 | - * @return void |
|
| 390 | - */ |
|
| 391 | - public function search_courses_json() |
|
| 392 | - { |
|
| 393 | - |
|
| 394 | - // Security check |
|
| 395 | - check_ajax_referer('search-courses', 'security'); |
|
| 396 | - |
|
| 397 | - // Set content type |
|
| 398 | - header('Content-Type: application/json; charset=utf-8'); |
|
| 399 | - |
|
| 400 | - // Get user input |
|
| 401 | - $term = urldecode(stripslashes($_GET['term'])); |
|
| 402 | - |
|
| 403 | - // Return nothing if term is empty |
|
| 404 | - if (empty($term)) |
|
| 405 | - die(); |
|
| 406 | - |
|
| 407 | - // Set a default if none is given |
|
| 408 | - $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
| 409 | - |
|
| 410 | - // Set up array of results |
|
| 411 | - $found_courses = array('' => $default); |
|
| 412 | - |
|
| 413 | - // Fetch results |
|
| 414 | - $args = array( |
|
| 415 | - 'post_type' => 'course', |
|
| 416 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 417 | - 'posts_per_page' => -1, |
|
| 418 | - 'orderby' => 'title', |
|
| 419 | - 's' => $term |
|
| 420 | - ); |
|
| 421 | - $courses = get_posts($args); |
|
| 422 | - |
|
| 423 | - // Add results to array |
|
| 424 | - if ($courses) { |
|
| 425 | - foreach ($courses as $course) { |
|
| 426 | - $found_courses[$course->ID] = $course->post_title; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // Encode and return results for processing & selection |
|
| 431 | - echo json_encode($found_courses); |
|
| 432 | - die(); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * display modules on single course pages |
|
| 437 | - * |
|
| 438 | - * @since 1.8.0 |
|
| 439 | - * @return void |
|
| 440 | - */ |
|
| 441 | - public function single_course_modules(){ |
|
| 442 | - |
|
| 443 | - _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | - // only show modules on the course that has modules |
|
| 445 | - if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 446 | - |
|
| 447 | - $this->load_course_module_content_template(); |
|
| 448 | - |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - } // end single_course_modules |
|
| 452 | - |
|
| 453 | - public function sensei_course_preview_titles($title, $lesson_id) |
|
| 454 | - { |
|
| 455 | - global $post, $current_user; |
|
| 456 | - |
|
| 457 | - $course_id = $post->ID; |
|
| 458 | - $title_text = ''; |
|
| 459 | - |
|
| 460 | - if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
| 461 | - $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
| 462 | - if (!$is_user_taking_course) { |
|
| 463 | - if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
| 464 | - $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
| 465 | - // Remove brackets for display here |
|
| 466 | - $title_text = str_replace('(', '', $title_text); |
|
| 467 | - $title_text = str_replace(')', '', $title_text); |
|
| 468 | - $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 469 | - } |
|
| 470 | - $title .= ' ' . $title_text; |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - return $title; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - public function module_breadcrumb_link($html, $separator) |
|
| 478 | - { |
|
| 479 | - global $post; |
|
| 480 | - // Lesson |
|
| 481 | - if (is_singular('lesson')) { |
|
| 482 | - if (has_term('', $this->taxonomy, $post->ID)) { |
|
| 483 | - $module = $this->get_lesson_module($post->ID); |
|
| 484 | - if( $module ) { |
|
| 485 | - $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - // Module |
|
| 490 | - if (is_tax($this->taxonomy)) { |
|
| 491 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 492 | - $course_id = intval($_GET['course_id']); |
|
| 493 | - $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $html; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Set lesson archive template to display on module taxonomy archive page |
|
| 501 | - * |
|
| 502 | - * @since 1.8.0 |
|
| 503 | - * @param string $template Default template |
|
| 504 | - * @return string Modified template |
|
| 505 | - */ |
|
| 506 | - public function module_archive_template($template) { |
|
| 507 | - |
|
| 508 | - if ( ! is_tax($this->taxonomy) ) { |
|
| 509 | - return $template; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - $file = 'archive-lesson.php'; |
|
| 513 | - $find = array( $file, Sensei()->template_url . $file ); |
|
| 514 | - |
|
| 515 | - // locate the template file |
|
| 516 | - $template = locate_template($find); |
|
| 517 | - if (!$template) { |
|
| 518 | - |
|
| 519 | - $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 520 | - |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - return $template; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Modify module taxonomy archive query |
|
| 529 | - * |
|
| 530 | - * @since 1.8.0 |
|
| 531 | - * @param object $query The query object passed by reference |
|
| 532 | - * @return void |
|
| 533 | - */ |
|
| 534 | - public function module_archive_filter($query) |
|
| 535 | - { |
|
| 536 | - if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - // Limit to lessons only |
|
| 540 | - $query->set('post_type', 'lesson'); |
|
| 541 | - |
|
| 542 | - // Set order of lessons |
|
| 543 | - if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 544 | - $module_id = $query->queried_object_id; |
|
| 545 | - $query->set('meta_key', '_order_module_' . $module_id); |
|
| 546 | - $query->set('orderby', 'meta_value_num date'); |
|
| 547 | - } else { |
|
| 548 | - $query->set('orderby', 'menu_order'); |
|
| 549 | - } |
|
| 550 | - $query->set('order', 'ASC'); |
|
| 551 | - |
|
| 552 | - // Limit to specific course if specified |
|
| 553 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 554 | - $course_id = intval($_GET['course_id']); |
|
| 555 | - $meta_query[] = array( |
|
| 556 | - 'key' => '_lesson_course', |
|
| 557 | - 'value' => intval($course_id) |
|
| 558 | - ); |
|
| 559 | - $query->set('meta_query', $meta_query); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Modify archive page title |
|
| 567 | - * |
|
| 568 | - * @since 1.8.0 |
|
| 569 | - * @param string $title Default title |
|
| 570 | - * @return string Modified title |
|
| 571 | - */ |
|
| 572 | - public function module_archive_title($title) |
|
| 573 | - { |
|
| 574 | - if (is_tax($this->taxonomy)) { |
|
| 575 | - $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
| 576 | - } |
|
| 577 | - return $title; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Display module description on taxonomy archive page |
|
| 582 | - * |
|
| 583 | - * @since 1.8.0 |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - public function module_archive_description() |
|
| 587 | - { |
|
| 588 | - if (is_tax($this->taxonomy)) { |
|
| 589 | - |
|
| 590 | - $module = get_queried_object(); |
|
| 591 | - |
|
| 592 | - $module_progress = false; |
|
| 593 | - if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
| 594 | - global $current_user; |
|
| 595 | - wp_get_current_user(); |
|
| 596 | - $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if ($module_progress && $module_progress > 0) { |
|
| 600 | - $status = __('Completed', 'woothemes-sensei'); |
|
| 601 | - $class = 'completed'; |
|
| 602 | - if ($module_progress < 100) { |
|
| 603 | - $status = __('In progress', 'woothemes-sensei'); |
|
| 604 | - $class = 'in-progress'; |
|
| 605 | - } |
|
| 606 | - echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - public function module_archive_body_class($classes) |
|
| 614 | - { |
|
| 615 | - if (is_tax($this->taxonomy)) { |
|
| 616 | - $classes[] = 'module-archive'; |
|
| 617 | - } |
|
| 618 | - return $classes; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Display module navigation links on module taxonomy archive page |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * @return void |
|
| 626 | - */ |
|
| 627 | - public function module_navigation_links() |
|
| 628 | - { |
|
| 629 | - if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
| 630 | - |
|
| 631 | - $queried_module = get_queried_object(); |
|
| 632 | - $course_modules = $this->get_course_modules($_GET['course_id']); |
|
| 633 | - |
|
| 634 | - $prev_module = false; |
|
| 635 | - $next_module = false; |
|
| 636 | - $on_current = false; |
|
| 637 | - foreach ($course_modules as $module) { |
|
| 638 | - $this_module = $module; |
|
| 639 | - if ($on_current) { |
|
| 640 | - $next_module = $this_module; |
|
| 641 | - break; |
|
| 642 | - } |
|
| 643 | - if ($this_module == $queried_module) { |
|
| 644 | - $on_current = true; |
|
| 645 | - } else { |
|
| 646 | - $prev_module = $module; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - ?> |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Save module course on add/edit |
|
| 342 | + * |
|
| 343 | + * @since 1.8.0 |
|
| 344 | + * @param integer $module_id ID of module |
|
| 345 | + * @return void |
|
| 346 | + */ |
|
| 347 | + public function save_module_course($module_id) |
|
| 348 | + { |
|
| 349 | + |
|
| 350 | + // Get module's existing courses |
|
| 351 | + $args = array( |
|
| 352 | + 'post_type' => 'course', |
|
| 353 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 354 | + 'posts_per_page' => -1, |
|
| 355 | + 'tax_query' => array( |
|
| 356 | + array( |
|
| 357 | + 'taxonomy' => $this->taxonomy, |
|
| 358 | + 'field' => 'id', |
|
| 359 | + 'terms' => $module_id |
|
| 360 | + ) |
|
| 361 | + ) |
|
| 362 | + ); |
|
| 363 | + $courses = get_posts($args); |
|
| 364 | + |
|
| 365 | + // Remove module from existing courses |
|
| 366 | + if (isset($courses) && is_array($courses)) { |
|
| 367 | + foreach ($courses as $course) { |
|
| 368 | + wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Add module to selected courses |
|
| 373 | + if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 374 | + |
|
| 375 | + $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 376 | + |
|
| 377 | + foreach ( $course_ids as $course_id ) { |
|
| 378 | + |
|
| 379 | + wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
| 380 | + |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Ajax function to search for courses matching term |
|
| 387 | + * |
|
| 388 | + * @since 1.8.0 |
|
| 389 | + * @return void |
|
| 390 | + */ |
|
| 391 | + public function search_courses_json() |
|
| 392 | + { |
|
| 393 | + |
|
| 394 | + // Security check |
|
| 395 | + check_ajax_referer('search-courses', 'security'); |
|
| 396 | + |
|
| 397 | + // Set content type |
|
| 398 | + header('Content-Type: application/json; charset=utf-8'); |
|
| 399 | + |
|
| 400 | + // Get user input |
|
| 401 | + $term = urldecode(stripslashes($_GET['term'])); |
|
| 402 | + |
|
| 403 | + // Return nothing if term is empty |
|
| 404 | + if (empty($term)) |
|
| 405 | + die(); |
|
| 406 | + |
|
| 407 | + // Set a default if none is given |
|
| 408 | + $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
| 409 | + |
|
| 410 | + // Set up array of results |
|
| 411 | + $found_courses = array('' => $default); |
|
| 412 | + |
|
| 413 | + // Fetch results |
|
| 414 | + $args = array( |
|
| 415 | + 'post_type' => 'course', |
|
| 416 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 417 | + 'posts_per_page' => -1, |
|
| 418 | + 'orderby' => 'title', |
|
| 419 | + 's' => $term |
|
| 420 | + ); |
|
| 421 | + $courses = get_posts($args); |
|
| 422 | + |
|
| 423 | + // Add results to array |
|
| 424 | + if ($courses) { |
|
| 425 | + foreach ($courses as $course) { |
|
| 426 | + $found_courses[$course->ID] = $course->post_title; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // Encode and return results for processing & selection |
|
| 431 | + echo json_encode($found_courses); |
|
| 432 | + die(); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * display modules on single course pages |
|
| 437 | + * |
|
| 438 | + * @since 1.8.0 |
|
| 439 | + * @return void |
|
| 440 | + */ |
|
| 441 | + public function single_course_modules(){ |
|
| 442 | + |
|
| 443 | + _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | + // only show modules on the course that has modules |
|
| 445 | + if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 446 | + |
|
| 447 | + $this->load_course_module_content_template(); |
|
| 448 | + |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + } // end single_course_modules |
|
| 452 | + |
|
| 453 | + public function sensei_course_preview_titles($title, $lesson_id) |
|
| 454 | + { |
|
| 455 | + global $post, $current_user; |
|
| 456 | + |
|
| 457 | + $course_id = $post->ID; |
|
| 458 | + $title_text = ''; |
|
| 459 | + |
|
| 460 | + if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
| 461 | + $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
| 462 | + if (!$is_user_taking_course) { |
|
| 463 | + if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
| 464 | + $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
| 465 | + // Remove brackets for display here |
|
| 466 | + $title_text = str_replace('(', '', $title_text); |
|
| 467 | + $title_text = str_replace(')', '', $title_text); |
|
| 468 | + $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 469 | + } |
|
| 470 | + $title .= ' ' . $title_text; |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + return $title; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + public function module_breadcrumb_link($html, $separator) |
|
| 478 | + { |
|
| 479 | + global $post; |
|
| 480 | + // Lesson |
|
| 481 | + if (is_singular('lesson')) { |
|
| 482 | + if (has_term('', $this->taxonomy, $post->ID)) { |
|
| 483 | + $module = $this->get_lesson_module($post->ID); |
|
| 484 | + if( $module ) { |
|
| 485 | + $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + // Module |
|
| 490 | + if (is_tax($this->taxonomy)) { |
|
| 491 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 492 | + $course_id = intval($_GET['course_id']); |
|
| 493 | + $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $html; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Set lesson archive template to display on module taxonomy archive page |
|
| 501 | + * |
|
| 502 | + * @since 1.8.0 |
|
| 503 | + * @param string $template Default template |
|
| 504 | + * @return string Modified template |
|
| 505 | + */ |
|
| 506 | + public function module_archive_template($template) { |
|
| 507 | + |
|
| 508 | + if ( ! is_tax($this->taxonomy) ) { |
|
| 509 | + return $template; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $file = 'archive-lesson.php'; |
|
| 513 | + $find = array( $file, Sensei()->template_url . $file ); |
|
| 514 | + |
|
| 515 | + // locate the template file |
|
| 516 | + $template = locate_template($find); |
|
| 517 | + if (!$template) { |
|
| 518 | + |
|
| 519 | + $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 520 | + |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + return $template; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * Modify module taxonomy archive query |
|
| 529 | + * |
|
| 530 | + * @since 1.8.0 |
|
| 531 | + * @param object $query The query object passed by reference |
|
| 532 | + * @return void |
|
| 533 | + */ |
|
| 534 | + public function module_archive_filter($query) |
|
| 535 | + { |
|
| 536 | + if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + // Limit to lessons only |
|
| 540 | + $query->set('post_type', 'lesson'); |
|
| 541 | + |
|
| 542 | + // Set order of lessons |
|
| 543 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 544 | + $module_id = $query->queried_object_id; |
|
| 545 | + $query->set('meta_key', '_order_module_' . $module_id); |
|
| 546 | + $query->set('orderby', 'meta_value_num date'); |
|
| 547 | + } else { |
|
| 548 | + $query->set('orderby', 'menu_order'); |
|
| 549 | + } |
|
| 550 | + $query->set('order', 'ASC'); |
|
| 551 | + |
|
| 552 | + // Limit to specific course if specified |
|
| 553 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 554 | + $course_id = intval($_GET['course_id']); |
|
| 555 | + $meta_query[] = array( |
|
| 556 | + 'key' => '_lesson_course', |
|
| 557 | + 'value' => intval($course_id) |
|
| 558 | + ); |
|
| 559 | + $query->set('meta_query', $meta_query); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Modify archive page title |
|
| 567 | + * |
|
| 568 | + * @since 1.8.0 |
|
| 569 | + * @param string $title Default title |
|
| 570 | + * @return string Modified title |
|
| 571 | + */ |
|
| 572 | + public function module_archive_title($title) |
|
| 573 | + { |
|
| 574 | + if (is_tax($this->taxonomy)) { |
|
| 575 | + $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
| 576 | + } |
|
| 577 | + return $title; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Display module description on taxonomy archive page |
|
| 582 | + * |
|
| 583 | + * @since 1.8.0 |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + public function module_archive_description() |
|
| 587 | + { |
|
| 588 | + if (is_tax($this->taxonomy)) { |
|
| 589 | + |
|
| 590 | + $module = get_queried_object(); |
|
| 591 | + |
|
| 592 | + $module_progress = false; |
|
| 593 | + if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
| 594 | + global $current_user; |
|
| 595 | + wp_get_current_user(); |
|
| 596 | + $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + if ($module_progress && $module_progress > 0) { |
|
| 600 | + $status = __('Completed', 'woothemes-sensei'); |
|
| 601 | + $class = 'completed'; |
|
| 602 | + if ($module_progress < 100) { |
|
| 603 | + $status = __('In progress', 'woothemes-sensei'); |
|
| 604 | + $class = 'in-progress'; |
|
| 605 | + } |
|
| 606 | + echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + public function module_archive_body_class($classes) |
|
| 614 | + { |
|
| 615 | + if (is_tax($this->taxonomy)) { |
|
| 616 | + $classes[] = 'module-archive'; |
|
| 617 | + } |
|
| 618 | + return $classes; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Display module navigation links on module taxonomy archive page |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * @return void |
|
| 626 | + */ |
|
| 627 | + public function module_navigation_links() |
|
| 628 | + { |
|
| 629 | + if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
| 630 | + |
|
| 631 | + $queried_module = get_queried_object(); |
|
| 632 | + $course_modules = $this->get_course_modules($_GET['course_id']); |
|
| 633 | + |
|
| 634 | + $prev_module = false; |
|
| 635 | + $next_module = false; |
|
| 636 | + $on_current = false; |
|
| 637 | + foreach ($course_modules as $module) { |
|
| 638 | + $this_module = $module; |
|
| 639 | + if ($on_current) { |
|
| 640 | + $next_module = $this_module; |
|
| 641 | + break; |
|
| 642 | + } |
|
| 643 | + if ($this_module == $queried_module) { |
|
| 644 | + $on_current = true; |
|
| 645 | + } else { |
|
| 646 | + $prev_module = $module; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + ?> |
|
| 651 | 651 | <div id="post-entries" class="post-entries module-navigation fix"> |
| 652 | 652 | <?php if ($next_module) { |
| 653 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
| 654 | - ?> |
|
| 653 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
| 654 | + ?> |
|
| 655 | 655 | <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>" |
| 656 | 656 | title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?> |
| 657 | 657 | <span class="meta-nav"></span></a></div> |
| 658 | 658 | <?php } ?> |
| 659 | 659 | <?php if ($prev_module) { |
| 660 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
| 661 | - ?> |
|
| 660 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
| 661 | + ?> |
|
| 662 | 662 | <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>" |
| 663 | 663 | title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span |
| 664 | 664 | class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div> |
| 665 | 665 | <?php } ?> |
| 666 | 666 | </div> |
| 667 | 667 | <?php |
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
| 673 | - * |
|
| 674 | - * @since 1.8.0 |
|
| 675 | - * @param string $status Status of the lesson for the user |
|
| 676 | - * @param integer $user_id ID of user |
|
| 677 | - * @param integer $lesson_id ID of lesson |
|
| 678 | - * @return void |
|
| 679 | - */ |
|
| 680 | - public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
| 681 | - { |
|
| 682 | - $this->save_lesson_module_progress($user_id, $lesson_id); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Save lesson's module progress for a specific user |
|
| 687 | - * |
|
| 688 | - * @since 1.8.0 |
|
| 689 | - * @param integer $user_id ID of user |
|
| 690 | - * @param integer $lesson_id ID of lesson |
|
| 691 | - * @return void |
|
| 692 | - */ |
|
| 693 | - public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
| 694 | - { |
|
| 695 | - $module = $this->get_lesson_module($lesson_id); |
|
| 696 | - $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 697 | - if ($module && $course_id) { |
|
| 698 | - $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Save progress of module for user |
|
| 704 | - * |
|
| 705 | - * @since 1.8.0 |
|
| 706 | - * @return void |
|
| 707 | - */ |
|
| 708 | - public function save_module_progress() |
|
| 709 | - { |
|
| 710 | - if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 711 | - global $current_user; |
|
| 712 | - wp_get_current_user(); |
|
| 713 | - $user_id = $current_user->ID; |
|
| 714 | - |
|
| 715 | - $module = get_queried_object(); |
|
| 716 | - |
|
| 717 | - $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Save module progess for user |
|
| 723 | - * |
|
| 724 | - * @since 1.8.0 |
|
| 725 | - * |
|
| 726 | - * @param integer $module_id ID of module |
|
| 727 | - * @param integer $course_id ID of course |
|
| 728 | - * @param integer $user_id ID of user |
|
| 729 | - * @return void |
|
| 730 | - */ |
|
| 731 | - public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 732 | - { |
|
| 733 | - $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
| 734 | - update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 735 | - |
|
| 736 | - do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * Get module progress for a user |
|
| 741 | - * |
|
| 742 | - * @since 1.8.0 |
|
| 743 | - * |
|
| 744 | - * @param integer $module_id ID of module |
|
| 745 | - * @param integer $course_id ID of course |
|
| 746 | - * @param integer $user_id ID of user |
|
| 747 | - * @return mixed Module progress percentage on success, false on failure |
|
| 748 | - */ |
|
| 749 | - public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 750 | - { |
|
| 751 | - $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 752 | - if ($module_progress) { |
|
| 753 | - return (float)$module_progress; |
|
| 754 | - } |
|
| 755 | - return false; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Calculate module progess for user |
|
| 760 | - * |
|
| 761 | - * @since 1.8.0 |
|
| 762 | - * |
|
| 763 | - * @param integer $user_id ID of user |
|
| 764 | - * @param integer $module_id ID of module |
|
| 765 | - * @param integer $course_id ID of course |
|
| 766 | - * @return integer Module progress percentage |
|
| 767 | - */ |
|
| 768 | - public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
| 769 | - { |
|
| 770 | - |
|
| 771 | - $args = array( |
|
| 772 | - 'post_type' => 'lesson', |
|
| 773 | - 'post_status' => 'publish', |
|
| 774 | - 'posts_per_page' => -1, |
|
| 775 | - 'tax_query' => array( |
|
| 776 | - array( |
|
| 777 | - 'taxonomy' => $this->taxonomy, |
|
| 778 | - 'field' => 'id', |
|
| 779 | - 'terms' => $module_id |
|
| 780 | - ) |
|
| 781 | - ), |
|
| 782 | - 'meta_query' => array( |
|
| 783 | - array( |
|
| 784 | - 'key' => '_lesson_course', |
|
| 785 | - 'value' => $course_id |
|
| 786 | - ) |
|
| 787 | - ), |
|
| 788 | - 'fields' => 'ids' |
|
| 789 | - ); |
|
| 790 | - $lessons = get_posts($args); |
|
| 791 | - |
|
| 792 | - if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 793 | - |
|
| 794 | - $completed = false; |
|
| 795 | - $lesson_count = 0; |
|
| 796 | - $completed_count = 0; |
|
| 797 | - foreach ($lessons as $lesson_id) { |
|
| 798 | - $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
| 799 | - ++$lesson_count; |
|
| 800 | - if ($completed) { |
|
| 801 | - ++$completed_count; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $module_progress = ($completed_count / $lesson_count) * 100; |
|
| 805 | - |
|
| 806 | - return (float)$module_progress; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Register admin screen for ordering modules |
|
| 811 | - * |
|
| 812 | - * @since 1.8.0 |
|
| 813 | - * |
|
| 814 | - * @return void |
|
| 815 | - */ |
|
| 816 | - public function register_modules_admin_menu_items() |
|
| 817 | - { |
|
| 818 | - //add the modules link under the Course main menu |
|
| 819 | - add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 820 | - |
|
| 821 | - // Regsiter new admin page for module ordering |
|
| 822 | - $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
| 823 | - |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * Display Module Order screen |
|
| 828 | - * |
|
| 829 | - * @since 1.8.0 |
|
| 830 | - * |
|
| 831 | - * @return void |
|
| 832 | - */ |
|
| 833 | - public function module_order_screen() |
|
| 834 | - { |
|
| 835 | - ?> |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
| 673 | + * |
|
| 674 | + * @since 1.8.0 |
|
| 675 | + * @param string $status Status of the lesson for the user |
|
| 676 | + * @param integer $user_id ID of user |
|
| 677 | + * @param integer $lesson_id ID of lesson |
|
| 678 | + * @return void |
|
| 679 | + */ |
|
| 680 | + public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
| 681 | + { |
|
| 682 | + $this->save_lesson_module_progress($user_id, $lesson_id); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Save lesson's module progress for a specific user |
|
| 687 | + * |
|
| 688 | + * @since 1.8.0 |
|
| 689 | + * @param integer $user_id ID of user |
|
| 690 | + * @param integer $lesson_id ID of lesson |
|
| 691 | + * @return void |
|
| 692 | + */ |
|
| 693 | + public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
| 694 | + { |
|
| 695 | + $module = $this->get_lesson_module($lesson_id); |
|
| 696 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 697 | + if ($module && $course_id) { |
|
| 698 | + $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Save progress of module for user |
|
| 704 | + * |
|
| 705 | + * @since 1.8.0 |
|
| 706 | + * @return void |
|
| 707 | + */ |
|
| 708 | + public function save_module_progress() |
|
| 709 | + { |
|
| 710 | + if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 711 | + global $current_user; |
|
| 712 | + wp_get_current_user(); |
|
| 713 | + $user_id = $current_user->ID; |
|
| 714 | + |
|
| 715 | + $module = get_queried_object(); |
|
| 716 | + |
|
| 717 | + $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Save module progess for user |
|
| 723 | + * |
|
| 724 | + * @since 1.8.0 |
|
| 725 | + * |
|
| 726 | + * @param integer $module_id ID of module |
|
| 727 | + * @param integer $course_id ID of course |
|
| 728 | + * @param integer $user_id ID of user |
|
| 729 | + * @return void |
|
| 730 | + */ |
|
| 731 | + public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 732 | + { |
|
| 733 | + $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
| 734 | + update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 735 | + |
|
| 736 | + do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * Get module progress for a user |
|
| 741 | + * |
|
| 742 | + * @since 1.8.0 |
|
| 743 | + * |
|
| 744 | + * @param integer $module_id ID of module |
|
| 745 | + * @param integer $course_id ID of course |
|
| 746 | + * @param integer $user_id ID of user |
|
| 747 | + * @return mixed Module progress percentage on success, false on failure |
|
| 748 | + */ |
|
| 749 | + public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 750 | + { |
|
| 751 | + $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 752 | + if ($module_progress) { |
|
| 753 | + return (float)$module_progress; |
|
| 754 | + } |
|
| 755 | + return false; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Calculate module progess for user |
|
| 760 | + * |
|
| 761 | + * @since 1.8.0 |
|
| 762 | + * |
|
| 763 | + * @param integer $user_id ID of user |
|
| 764 | + * @param integer $module_id ID of module |
|
| 765 | + * @param integer $course_id ID of course |
|
| 766 | + * @return integer Module progress percentage |
|
| 767 | + */ |
|
| 768 | + public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
| 769 | + { |
|
| 770 | + |
|
| 771 | + $args = array( |
|
| 772 | + 'post_type' => 'lesson', |
|
| 773 | + 'post_status' => 'publish', |
|
| 774 | + 'posts_per_page' => -1, |
|
| 775 | + 'tax_query' => array( |
|
| 776 | + array( |
|
| 777 | + 'taxonomy' => $this->taxonomy, |
|
| 778 | + 'field' => 'id', |
|
| 779 | + 'terms' => $module_id |
|
| 780 | + ) |
|
| 781 | + ), |
|
| 782 | + 'meta_query' => array( |
|
| 783 | + array( |
|
| 784 | + 'key' => '_lesson_course', |
|
| 785 | + 'value' => $course_id |
|
| 786 | + ) |
|
| 787 | + ), |
|
| 788 | + 'fields' => 'ids' |
|
| 789 | + ); |
|
| 790 | + $lessons = get_posts($args); |
|
| 791 | + |
|
| 792 | + if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 793 | + |
|
| 794 | + $completed = false; |
|
| 795 | + $lesson_count = 0; |
|
| 796 | + $completed_count = 0; |
|
| 797 | + foreach ($lessons as $lesson_id) { |
|
| 798 | + $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
| 799 | + ++$lesson_count; |
|
| 800 | + if ($completed) { |
|
| 801 | + ++$completed_count; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $module_progress = ($completed_count / $lesson_count) * 100; |
|
| 805 | + |
|
| 806 | + return (float)$module_progress; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Register admin screen for ordering modules |
|
| 811 | + * |
|
| 812 | + * @since 1.8.0 |
|
| 813 | + * |
|
| 814 | + * @return void |
|
| 815 | + */ |
|
| 816 | + public function register_modules_admin_menu_items() |
|
| 817 | + { |
|
| 818 | + //add the modules link under the Course main menu |
|
| 819 | + add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 820 | + |
|
| 821 | + // Regsiter new admin page for module ordering |
|
| 822 | + $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
| 823 | + |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * Display Module Order screen |
|
| 828 | + * |
|
| 829 | + * @since 1.8.0 |
|
| 830 | + * |
|
| 831 | + * @return void |
|
| 832 | + */ |
|
| 833 | + public function module_order_screen() |
|
| 834 | + { |
|
| 835 | + ?> |
|
| 836 | 836 | <div id="<?php echo esc_attr($this->order_page_slug); ?>" |
| 837 | 837 | class="wrap <?php echo esc_attr($this->order_page_slug); ?>"> |
| 838 | 838 | <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php |
| 839 | 839 | |
| 840 | - $html = ''; |
|
| 841 | - |
|
| 842 | - if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
| 843 | - $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
| 844 | - |
|
| 845 | - if ($ordered) { |
|
| 846 | - $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | - $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | - $html .= '</div>' . "\n"; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - $courses = Sensei()->course->get_all_courses(); |
|
| 853 | - |
|
| 854 | - $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | - $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | - $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | - $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | - $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 859 | - |
|
| 860 | - foreach ($courses as $course) { |
|
| 861 | - if (has_term('', $this->taxonomy, $course->ID)) { |
|
| 862 | - $course_id = ''; |
|
| 863 | - if (isset($_GET['course_id'])) { |
|
| 864 | - $course_id = intval($_GET['course_id']); |
|
| 865 | - } |
|
| 866 | - $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - $html .= '</select>' . "\n"; |
|
| 871 | - $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | - $html .= '</form>' . "\n"; |
|
| 873 | - |
|
| 874 | - if (isset($_GET['course_id'])) { |
|
| 875 | - $course_id = intval($_GET['course_id']); |
|
| 876 | - if ($course_id > 0) { |
|
| 877 | - $modules = $this->get_course_modules($course_id); |
|
| 878 | - $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 879 | - if ($modules) { |
|
| 880 | - |
|
| 881 | - $order = $this->get_course_module_order($course_id); |
|
| 882 | - |
|
| 883 | - $order_string=''; |
|
| 884 | - if ($order) { |
|
| 885 | - $order_string = implode(',', $order); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | - $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 890 | - $count = 0; |
|
| 891 | - foreach ($modules as $module) { |
|
| 892 | - $count++; |
|
| 893 | - $class = $this->taxonomy; |
|
| 894 | - if ($count == 1) { |
|
| 895 | - $class .= ' first'; |
|
| 896 | - } |
|
| 897 | - if ($count == count($module)) { |
|
| 898 | - $class .= ' last'; |
|
| 899 | - } |
|
| 900 | - if ($count % 2 != 0) { |
|
| 901 | - $class .= ' alternate'; |
|
| 902 | - } |
|
| 903 | - $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 904 | - } |
|
| 905 | - $html .= '</ul>' . "\n"; |
|
| 906 | - |
|
| 907 | - $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | - $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | - $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - echo $html; |
|
| 916 | - |
|
| 917 | - ?></div><?php |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Add 'Module order' column to courses list table |
|
| 922 | - * |
|
| 923 | - * @since 1.8.0 |
|
| 924 | - * |
|
| 925 | - * @param array $columns Existing columns |
|
| 926 | - * @return array Modifed columns |
|
| 927 | - */ |
|
| 928 | - public function course_columns($columns = array()) |
|
| 929 | - { |
|
| 930 | - $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
| 931 | - return $columns; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * Load content in 'Module order' column |
|
| 936 | - * |
|
| 937 | - * @since 1.8.0 |
|
| 938 | - * |
|
| 939 | - * @param string $column Current column name |
|
| 940 | - * @param integer $course_id ID of course |
|
| 941 | - * @return void |
|
| 942 | - */ |
|
| 943 | - public function course_column_content($column = '', $course_id = 0) |
|
| 944 | - { |
|
| 945 | - if ($column == 'module_order') { |
|
| 946 | - if (has_term('', $this->taxonomy, $course_id)) { |
|
| 947 | - echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * Save module order for course |
|
| 954 | - * |
|
| 955 | - * @since 1.8.0 |
|
| 956 | - * |
|
| 957 | - * @param string $order_string Comma-separated string of module IDs |
|
| 958 | - * @param integer $course_id ID of course |
|
| 959 | - * @return boolean True on success, false on failure |
|
| 960 | - */ |
|
| 961 | - private function save_course_module_order($order_string = '', $course_id = 0) |
|
| 962 | - { |
|
| 963 | - if ($order_string && $course_id) { |
|
| 964 | - $order = explode(',', $order_string); |
|
| 965 | - update_post_meta(intval($course_id), '_module_order', $order); |
|
| 966 | - return true; |
|
| 967 | - } |
|
| 968 | - return false; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Get module order for course |
|
| 973 | - * |
|
| 974 | - * @since 1.8.0 |
|
| 975 | - * |
|
| 976 | - * @param integer $course_id ID of course |
|
| 977 | - * @return mixed Module order on success, false if no module order has been saved |
|
| 978 | - */ |
|
| 979 | - public function get_course_module_order($course_id = 0) |
|
| 980 | - { |
|
| 981 | - if ($course_id) { |
|
| 982 | - $order = get_post_meta(intval($course_id), '_module_order', true); |
|
| 983 | - return $order; |
|
| 984 | - } |
|
| 985 | - return false; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Modify module taxonomy columns |
|
| 990 | - * |
|
| 991 | - * @since 1.8.0 |
|
| 992 | - * |
|
| 993 | - * @param array $columns Default columns |
|
| 994 | - * @return array Modified columns |
|
| 995 | - */ |
|
| 996 | - public function taxonomy_column_headings($columns) |
|
| 997 | - { |
|
| 998 | - |
|
| 999 | - unset($columns['posts']); |
|
| 1000 | - |
|
| 1001 | - $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
| 1002 | - |
|
| 1003 | - return $columns; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Manage content in custom module taxonomy columns |
|
| 1008 | - * |
|
| 1009 | - * @since 1.8.0 |
|
| 1010 | - * |
|
| 1011 | - * @param string $column_data Default data for column |
|
| 1012 | - * @param string $column_name Name of current column |
|
| 1013 | - * @param integer $term_id ID of current term |
|
| 1014 | - * @return string Modified column data |
|
| 1015 | - */ |
|
| 1016 | - public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
| 1017 | - { |
|
| 1018 | - |
|
| 1019 | - $args = array( |
|
| 1020 | - 'post_status' => 'publish', |
|
| 1021 | - 'posts_per_page' => -1, |
|
| 1022 | - 'tax_query' => array( |
|
| 1023 | - array( |
|
| 1024 | - 'taxonomy' => $this->taxonomy, |
|
| 1025 | - 'field' => 'id', |
|
| 1026 | - 'terms' => intval($term_id) |
|
| 1027 | - ) |
|
| 1028 | - ) |
|
| 1029 | - ); |
|
| 1030 | - |
|
| 1031 | - $module = get_term($term_id, $this->taxonomy); |
|
| 1032 | - |
|
| 1033 | - switch ($column_name) { |
|
| 1034 | - |
|
| 1035 | - case 'lessons': |
|
| 1036 | - $args['post_type'] = 'lesson'; |
|
| 1037 | - $lessons = get_posts($args); |
|
| 1038 | - $total_lessons = count($lessons); |
|
| 1039 | - $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1040 | - break; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - return $column_data; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * Add 'Module' columns to Analysis Lesson Overview table |
|
| 1048 | - * |
|
| 1049 | - * @since 1.8.0 |
|
| 1050 | - * |
|
| 1051 | - * @param array $columns Default columns |
|
| 1052 | - * @return array Modified columns |
|
| 1053 | - */ |
|
| 1054 | - public function analysis_overview_column_title($columns) |
|
| 1055 | - { |
|
| 1056 | - |
|
| 1057 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1058 | - $new_columns = array(); |
|
| 1059 | - if (is_array($columns) && 0 < count($columns)) { |
|
| 1060 | - foreach ($columns as $column => $title) { |
|
| 1061 | - $new_columns[$column] = $title; |
|
| 1062 | - if ($column == 'title') { |
|
| 1063 | - $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - if (0 < count($new_columns)) { |
|
| 1069 | - return $new_columns; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $columns; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Data for 'Module' column Analysis Lesson Overview table |
|
| 1078 | - * |
|
| 1079 | - * @since 1.8.0 |
|
| 1080 | - * |
|
| 1081 | - * @param array $columns Table column data |
|
| 1082 | - * @param WP_Post $lesson |
|
| 1083 | - * @return array Updated column data |
|
| 1084 | - */ |
|
| 1085 | - public function analysis_overview_column_data($columns, $lesson ) |
|
| 1086 | - { |
|
| 1087 | - |
|
| 1088 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1089 | - $lesson_module = ''; |
|
| 1090 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1091 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1092 | - foreach ($lesson_module_list as $single_module) { |
|
| 1093 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1094 | - break; |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - $columns['lesson_module'] = $lesson_module; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - return $columns; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Add 'Module' columns to Analysis Course table |
|
| 1106 | - * |
|
| 1107 | - * @since 1.8.0 |
|
| 1108 | - * |
|
| 1109 | - * @param array $columns Default columns |
|
| 1110 | - * @return array Modified columns |
|
| 1111 | - */ |
|
| 1112 | - public function analysis_course_column_title($columns) |
|
| 1113 | - { |
|
| 1114 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1115 | - $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1116 | - } |
|
| 1117 | - return $columns; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * Data for 'Module' column in Analysis Course table |
|
| 1122 | - * |
|
| 1123 | - * @since 1.8.0 |
|
| 1124 | - * |
|
| 1125 | - * @param array $columns Table column data |
|
| 1126 | - * @param WP_Post $lesson |
|
| 1127 | - * @return array Updated columns data |
|
| 1128 | - */ |
|
| 1129 | - public function analysis_course_column_data($columns, $lesson ) |
|
| 1130 | - { |
|
| 1131 | - |
|
| 1132 | - if ( isset( $_GET['course_id'] ) ) { |
|
| 1133 | - $lesson_module = ''; |
|
| 1134 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1135 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1136 | - foreach ($lesson_module_list as $single_module) { |
|
| 1137 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1138 | - break; |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $columns['lesson_module'] = $lesson_module; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - return $columns; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * Get module for lesson |
|
| 1150 | - * |
|
| 1151 | - * This function also checks if the module still |
|
| 1152 | - * exists on the course before returning it. Although |
|
| 1153 | - * the lesson has a module the same module must exist on the |
|
| 1154 | - * course for it to be valid. |
|
| 1155 | - * |
|
| 1156 | - * @since 1.8.0 |
|
| 1157 | - * |
|
| 1158 | - * @param integer $lesson_id ID of lesson |
|
| 1159 | - * @return object Module taxonomy term object |
|
| 1160 | - */ |
|
| 1161 | - public function get_lesson_module($lesson_id = 0) |
|
| 1162 | - { |
|
| 1163 | - $lesson_id = intval($lesson_id); |
|
| 1164 | - if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1165 | - return false; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - // get taxonomy terms on this lesson |
|
| 1169 | - $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
| 1170 | - |
|
| 1171 | - //check if error returned |
|
| 1172 | - if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1173 | - return false; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - // get the last item in the array there should be only be 1 really. |
|
| 1177 | - // this method works for all php versions. |
|
| 1178 | - foreach( $modules as $module ){ |
|
| 1179 | - break; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
| 1183 | - return false; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - $module->url = get_term_link($module, $this->taxonomy); |
|
| 1187 | - $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
| 1188 | - if (isset($course_id) && 0 < $course_id) { |
|
| 1189 | - |
|
| 1190 | - // the course should contain the same module taxonomy term for this to be valid |
|
| 1191 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1192 | - return false; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
| 1196 | - } |
|
| 1197 | - return $module; |
|
| 1198 | - |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * Get ordered array of all modules in course |
|
| 1203 | - * |
|
| 1204 | - * @since 1.8.0 |
|
| 1205 | - * |
|
| 1206 | - * @param integer $course_id ID of course |
|
| 1207 | - * @return array Ordered array of module taxonomy term objects |
|
| 1208 | - */ |
|
| 1209 | - public function get_course_modules($course_id = 0) |
|
| 1210 | - { |
|
| 1211 | - $course_id = intval($course_id); |
|
| 1212 | - if (0 < $course_id) { |
|
| 1213 | - |
|
| 1214 | - // Get modules for course |
|
| 1215 | - $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1216 | - |
|
| 1217 | - // Get custom module order for course |
|
| 1218 | - $order = $this->get_course_module_order($course_id); |
|
| 1219 | - |
|
| 1220 | - // Sort by custom order if custom order exists |
|
| 1221 | - if ($order) { |
|
| 1222 | - $ordered_modules = array(); |
|
| 1223 | - $unordered_modules = array(); |
|
| 1224 | - foreach ($modules as $module) { |
|
| 1225 | - $order_key = array_search($module->term_id, $order); |
|
| 1226 | - if ($order_key !== false) { |
|
| 1227 | - $ordered_modules[$order_key] = $module; |
|
| 1228 | - } else { |
|
| 1229 | - $unordered_modules[] = $module; |
|
| 1230 | - } |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - // Order modules correctly |
|
| 1234 | - ksort($ordered_modules); |
|
| 1235 | - |
|
| 1236 | - // Append modules that have not yet been ordered |
|
| 1237 | - if (count($unordered_modules) > 0) { |
|
| 1238 | - $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - } else { |
|
| 1242 | - |
|
| 1243 | - $ordered_modules = $modules; |
|
| 1244 | - |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - return $ordered_modules; |
|
| 1248 | - |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - return false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Load frontend CSS |
|
| 1256 | - * |
|
| 1257 | - * @since 1.8.0 |
|
| 1258 | - * |
|
| 1259 | - * @return void |
|
| 1260 | - */ |
|
| 1261 | - public function enqueue_styles() |
|
| 1262 | - { |
|
| 1263 | - |
|
| 1264 | - |
|
| 1265 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Load admin Javascript |
|
| 1271 | - * |
|
| 1272 | - * @since 1.8.0 |
|
| 1273 | - * |
|
| 1274 | - * @return void |
|
| 1275 | - */ |
|
| 1276 | - public function admin_enqueue_scripts( $hook ) { |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Filter the page hooks where modules admin script can be loaded on. |
|
| 1280 | - * |
|
| 1281 | - * @param array $white_listed_pages |
|
| 1282 | - */ |
|
| 1283 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | - 'edit-tags.php', |
|
| 1285 | - 'course_page_module-order', |
|
| 1286 | - 'post-new.php', |
|
| 1287 | - 'post.php' |
|
| 1288 | - ) ); |
|
| 1289 | - |
|
| 1290 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1291 | - return; |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | - |
|
| 1296 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | - wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1299 | - |
|
| 1300 | - // localized module data |
|
| 1301 | - $localize_modulesAdmin = array( |
|
| 1302 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1304 | - ); |
|
| 1305 | - |
|
| 1306 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Load admin CSS |
|
| 1311 | - * |
|
| 1312 | - * @since 1.8.0 |
|
| 1313 | - * |
|
| 1314 | - * @return void |
|
| 1315 | - */ |
|
| 1316 | - public function admin_enqueue_styles() { |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1321 | - |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * Show the title modules on the single course template. |
|
| 1326 | - * |
|
| 1327 | - * Function is hooked into sensei_single_course_modules_before. |
|
| 1328 | - * |
|
| 1329 | - * @since 1.8.0 |
|
| 1330 | - * @return void |
|
| 1331 | - */ |
|
| 1332 | - public function course_modules_title( ) { |
|
| 1333 | - |
|
| 1334 | - if( sensei_module_has_lessons() ){ |
|
| 1335 | - |
|
| 1336 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1337 | - |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - /** |
|
| 1343 | - * Display the single course modules content this will only show |
|
| 1344 | - * if the course has modules. |
|
| 1345 | - * |
|
| 1346 | - * @since 1.8.0 |
|
| 1347 | - * @return void |
|
| 1348 | - */ |
|
| 1349 | - public function load_course_module_content_template(){ |
|
| 1350 | - |
|
| 1351 | - // load backwards compatible template name if it exists in the users theme |
|
| 1352 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | - if( $located_template ){ |
|
| 1354 | - |
|
| 1355 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1356 | - return; |
|
| 1357 | - |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1361 | - |
|
| 1362 | - } // end course_module_content |
|
| 1363 | - |
|
| 1364 | - /** |
|
| 1365 | - * Returns all lessons for the given module ID |
|
| 1366 | - * |
|
| 1367 | - * @since 1.8.0 |
|
| 1368 | - * |
|
| 1369 | - * @param $course_id |
|
| 1370 | - * @param $term_id |
|
| 1371 | - * @return array $lessons |
|
| 1372 | - */ |
|
| 1373 | - public function get_lessons( $course_id , $term_id ){ |
|
| 1374 | - |
|
| 1375 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 840 | + $html = ''; |
|
| 841 | + |
|
| 842 | + if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
| 843 | + $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
| 844 | + |
|
| 845 | + if ($ordered) { |
|
| 846 | + $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | + $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | + $html .= '</div>' . "\n"; |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + $courses = Sensei()->course->get_all_courses(); |
|
| 853 | + |
|
| 854 | + $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | + $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | + $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | + $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | + $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 859 | + |
|
| 860 | + foreach ($courses as $course) { |
|
| 861 | + if (has_term('', $this->taxonomy, $course->ID)) { |
|
| 862 | + $course_id = ''; |
|
| 863 | + if (isset($_GET['course_id'])) { |
|
| 864 | + $course_id = intval($_GET['course_id']); |
|
| 865 | + } |
|
| 866 | + $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + $html .= '</select>' . "\n"; |
|
| 871 | + $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | + $html .= '</form>' . "\n"; |
|
| 873 | + |
|
| 874 | + if (isset($_GET['course_id'])) { |
|
| 875 | + $course_id = intval($_GET['course_id']); |
|
| 876 | + if ($course_id > 0) { |
|
| 877 | + $modules = $this->get_course_modules($course_id); |
|
| 878 | + $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 879 | + if ($modules) { |
|
| 880 | + |
|
| 881 | + $order = $this->get_course_module_order($course_id); |
|
| 882 | + |
|
| 883 | + $order_string=''; |
|
| 884 | + if ($order) { |
|
| 885 | + $order_string = implode(',', $order); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | + $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 890 | + $count = 0; |
|
| 891 | + foreach ($modules as $module) { |
|
| 892 | + $count++; |
|
| 893 | + $class = $this->taxonomy; |
|
| 894 | + if ($count == 1) { |
|
| 895 | + $class .= ' first'; |
|
| 896 | + } |
|
| 897 | + if ($count == count($module)) { |
|
| 898 | + $class .= ' last'; |
|
| 899 | + } |
|
| 900 | + if ($count % 2 != 0) { |
|
| 901 | + $class .= ' alternate'; |
|
| 902 | + } |
|
| 903 | + $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 904 | + } |
|
| 905 | + $html .= '</ul>' . "\n"; |
|
| 906 | + |
|
| 907 | + $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | + $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | + $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | + $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + echo $html; |
|
| 916 | + |
|
| 917 | + ?></div><?php |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Add 'Module order' column to courses list table |
|
| 922 | + * |
|
| 923 | + * @since 1.8.0 |
|
| 924 | + * |
|
| 925 | + * @param array $columns Existing columns |
|
| 926 | + * @return array Modifed columns |
|
| 927 | + */ |
|
| 928 | + public function course_columns($columns = array()) |
|
| 929 | + { |
|
| 930 | + $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
| 931 | + return $columns; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * Load content in 'Module order' column |
|
| 936 | + * |
|
| 937 | + * @since 1.8.0 |
|
| 938 | + * |
|
| 939 | + * @param string $column Current column name |
|
| 940 | + * @param integer $course_id ID of course |
|
| 941 | + * @return void |
|
| 942 | + */ |
|
| 943 | + public function course_column_content($column = '', $course_id = 0) |
|
| 944 | + { |
|
| 945 | + if ($column == 'module_order') { |
|
| 946 | + if (has_term('', $this->taxonomy, $course_id)) { |
|
| 947 | + echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * Save module order for course |
|
| 954 | + * |
|
| 955 | + * @since 1.8.0 |
|
| 956 | + * |
|
| 957 | + * @param string $order_string Comma-separated string of module IDs |
|
| 958 | + * @param integer $course_id ID of course |
|
| 959 | + * @return boolean True on success, false on failure |
|
| 960 | + */ |
|
| 961 | + private function save_course_module_order($order_string = '', $course_id = 0) |
|
| 962 | + { |
|
| 963 | + if ($order_string && $course_id) { |
|
| 964 | + $order = explode(',', $order_string); |
|
| 965 | + update_post_meta(intval($course_id), '_module_order', $order); |
|
| 966 | + return true; |
|
| 967 | + } |
|
| 968 | + return false; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Get module order for course |
|
| 973 | + * |
|
| 974 | + * @since 1.8.0 |
|
| 975 | + * |
|
| 976 | + * @param integer $course_id ID of course |
|
| 977 | + * @return mixed Module order on success, false if no module order has been saved |
|
| 978 | + */ |
|
| 979 | + public function get_course_module_order($course_id = 0) |
|
| 980 | + { |
|
| 981 | + if ($course_id) { |
|
| 982 | + $order = get_post_meta(intval($course_id), '_module_order', true); |
|
| 983 | + return $order; |
|
| 984 | + } |
|
| 985 | + return false; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Modify module taxonomy columns |
|
| 990 | + * |
|
| 991 | + * @since 1.8.0 |
|
| 992 | + * |
|
| 993 | + * @param array $columns Default columns |
|
| 994 | + * @return array Modified columns |
|
| 995 | + */ |
|
| 996 | + public function taxonomy_column_headings($columns) |
|
| 997 | + { |
|
| 998 | + |
|
| 999 | + unset($columns['posts']); |
|
| 1000 | + |
|
| 1001 | + $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
| 1002 | + |
|
| 1003 | + return $columns; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Manage content in custom module taxonomy columns |
|
| 1008 | + * |
|
| 1009 | + * @since 1.8.0 |
|
| 1010 | + * |
|
| 1011 | + * @param string $column_data Default data for column |
|
| 1012 | + * @param string $column_name Name of current column |
|
| 1013 | + * @param integer $term_id ID of current term |
|
| 1014 | + * @return string Modified column data |
|
| 1015 | + */ |
|
| 1016 | + public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
| 1017 | + { |
|
| 1018 | + |
|
| 1019 | + $args = array( |
|
| 1020 | + 'post_status' => 'publish', |
|
| 1021 | + 'posts_per_page' => -1, |
|
| 1022 | + 'tax_query' => array( |
|
| 1023 | + array( |
|
| 1024 | + 'taxonomy' => $this->taxonomy, |
|
| 1025 | + 'field' => 'id', |
|
| 1026 | + 'terms' => intval($term_id) |
|
| 1027 | + ) |
|
| 1028 | + ) |
|
| 1029 | + ); |
|
| 1030 | + |
|
| 1031 | + $module = get_term($term_id, $this->taxonomy); |
|
| 1032 | + |
|
| 1033 | + switch ($column_name) { |
|
| 1034 | + |
|
| 1035 | + case 'lessons': |
|
| 1036 | + $args['post_type'] = 'lesson'; |
|
| 1037 | + $lessons = get_posts($args); |
|
| 1038 | + $total_lessons = count($lessons); |
|
| 1039 | + $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1040 | + break; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + return $column_data; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * Add 'Module' columns to Analysis Lesson Overview table |
|
| 1048 | + * |
|
| 1049 | + * @since 1.8.0 |
|
| 1050 | + * |
|
| 1051 | + * @param array $columns Default columns |
|
| 1052 | + * @return array Modified columns |
|
| 1053 | + */ |
|
| 1054 | + public function analysis_overview_column_title($columns) |
|
| 1055 | + { |
|
| 1056 | + |
|
| 1057 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1058 | + $new_columns = array(); |
|
| 1059 | + if (is_array($columns) && 0 < count($columns)) { |
|
| 1060 | + foreach ($columns as $column => $title) { |
|
| 1061 | + $new_columns[$column] = $title; |
|
| 1062 | + if ($column == 'title') { |
|
| 1063 | + $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + if (0 < count($new_columns)) { |
|
| 1069 | + return $new_columns; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $columns; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Data for 'Module' column Analysis Lesson Overview table |
|
| 1078 | + * |
|
| 1079 | + * @since 1.8.0 |
|
| 1080 | + * |
|
| 1081 | + * @param array $columns Table column data |
|
| 1082 | + * @param WP_Post $lesson |
|
| 1083 | + * @return array Updated column data |
|
| 1084 | + */ |
|
| 1085 | + public function analysis_overview_column_data($columns, $lesson ) |
|
| 1086 | + { |
|
| 1087 | + |
|
| 1088 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1089 | + $lesson_module = ''; |
|
| 1090 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1091 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1092 | + foreach ($lesson_module_list as $single_module) { |
|
| 1093 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1094 | + break; |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + $columns['lesson_module'] = $lesson_module; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + return $columns; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Add 'Module' columns to Analysis Course table |
|
| 1106 | + * |
|
| 1107 | + * @since 1.8.0 |
|
| 1108 | + * |
|
| 1109 | + * @param array $columns Default columns |
|
| 1110 | + * @return array Modified columns |
|
| 1111 | + */ |
|
| 1112 | + public function analysis_course_column_title($columns) |
|
| 1113 | + { |
|
| 1114 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1115 | + $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1116 | + } |
|
| 1117 | + return $columns; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * Data for 'Module' column in Analysis Course table |
|
| 1122 | + * |
|
| 1123 | + * @since 1.8.0 |
|
| 1124 | + * |
|
| 1125 | + * @param array $columns Table column data |
|
| 1126 | + * @param WP_Post $lesson |
|
| 1127 | + * @return array Updated columns data |
|
| 1128 | + */ |
|
| 1129 | + public function analysis_course_column_data($columns, $lesson ) |
|
| 1130 | + { |
|
| 1131 | + |
|
| 1132 | + if ( isset( $_GET['course_id'] ) ) { |
|
| 1133 | + $lesson_module = ''; |
|
| 1134 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1135 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1136 | + foreach ($lesson_module_list as $single_module) { |
|
| 1137 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1138 | + break; |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $columns['lesson_module'] = $lesson_module; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + return $columns; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * Get module for lesson |
|
| 1150 | + * |
|
| 1151 | + * This function also checks if the module still |
|
| 1152 | + * exists on the course before returning it. Although |
|
| 1153 | + * the lesson has a module the same module must exist on the |
|
| 1154 | + * course for it to be valid. |
|
| 1155 | + * |
|
| 1156 | + * @since 1.8.0 |
|
| 1157 | + * |
|
| 1158 | + * @param integer $lesson_id ID of lesson |
|
| 1159 | + * @return object Module taxonomy term object |
|
| 1160 | + */ |
|
| 1161 | + public function get_lesson_module($lesson_id = 0) |
|
| 1162 | + { |
|
| 1163 | + $lesson_id = intval($lesson_id); |
|
| 1164 | + if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1165 | + return false; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + // get taxonomy terms on this lesson |
|
| 1169 | + $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
| 1170 | + |
|
| 1171 | + //check if error returned |
|
| 1172 | + if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1173 | + return false; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + // get the last item in the array there should be only be 1 really. |
|
| 1177 | + // this method works for all php versions. |
|
| 1178 | + foreach( $modules as $module ){ |
|
| 1179 | + break; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
| 1183 | + return false; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + $module->url = get_term_link($module, $this->taxonomy); |
|
| 1187 | + $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
| 1188 | + if (isset($course_id) && 0 < $course_id) { |
|
| 1189 | + |
|
| 1190 | + // the course should contain the same module taxonomy term for this to be valid |
|
| 1191 | + if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1192 | + return false; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
| 1196 | + } |
|
| 1197 | + return $module; |
|
| 1198 | + |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * Get ordered array of all modules in course |
|
| 1203 | + * |
|
| 1204 | + * @since 1.8.0 |
|
| 1205 | + * |
|
| 1206 | + * @param integer $course_id ID of course |
|
| 1207 | + * @return array Ordered array of module taxonomy term objects |
|
| 1208 | + */ |
|
| 1209 | + public function get_course_modules($course_id = 0) |
|
| 1210 | + { |
|
| 1211 | + $course_id = intval($course_id); |
|
| 1212 | + if (0 < $course_id) { |
|
| 1213 | + |
|
| 1214 | + // Get modules for course |
|
| 1215 | + $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1216 | + |
|
| 1217 | + // Get custom module order for course |
|
| 1218 | + $order = $this->get_course_module_order($course_id); |
|
| 1219 | + |
|
| 1220 | + // Sort by custom order if custom order exists |
|
| 1221 | + if ($order) { |
|
| 1222 | + $ordered_modules = array(); |
|
| 1223 | + $unordered_modules = array(); |
|
| 1224 | + foreach ($modules as $module) { |
|
| 1225 | + $order_key = array_search($module->term_id, $order); |
|
| 1226 | + if ($order_key !== false) { |
|
| 1227 | + $ordered_modules[$order_key] = $module; |
|
| 1228 | + } else { |
|
| 1229 | + $unordered_modules[] = $module; |
|
| 1230 | + } |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + // Order modules correctly |
|
| 1234 | + ksort($ordered_modules); |
|
| 1235 | + |
|
| 1236 | + // Append modules that have not yet been ordered |
|
| 1237 | + if (count($unordered_modules) > 0) { |
|
| 1238 | + $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + } else { |
|
| 1242 | + |
|
| 1243 | + $ordered_modules = $modules; |
|
| 1244 | + |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + return $ordered_modules; |
|
| 1248 | + |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + return false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Load frontend CSS |
|
| 1256 | + * |
|
| 1257 | + * @since 1.8.0 |
|
| 1258 | + * |
|
| 1259 | + * @return void |
|
| 1260 | + */ |
|
| 1261 | + public function enqueue_styles() |
|
| 1262 | + { |
|
| 1263 | + |
|
| 1264 | + |
|
| 1265 | + wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | + wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Load admin Javascript |
|
| 1271 | + * |
|
| 1272 | + * @since 1.8.0 |
|
| 1273 | + * |
|
| 1274 | + * @return void |
|
| 1275 | + */ |
|
| 1276 | + public function admin_enqueue_scripts( $hook ) { |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Filter the page hooks where modules admin script can be loaded on. |
|
| 1280 | + * |
|
| 1281 | + * @param array $white_listed_pages |
|
| 1282 | + */ |
|
| 1283 | + $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | + 'edit-tags.php', |
|
| 1285 | + 'course_page_module-order', |
|
| 1286 | + 'post-new.php', |
|
| 1287 | + 'post.php' |
|
| 1288 | + ) ); |
|
| 1289 | + |
|
| 1290 | + if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1291 | + return; |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | + |
|
| 1296 | + wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | + wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1299 | + |
|
| 1300 | + // localized module data |
|
| 1301 | + $localize_modulesAdmin = array( |
|
| 1302 | + 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | + 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1304 | + ); |
|
| 1305 | + |
|
| 1306 | + wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Load admin CSS |
|
| 1311 | + * |
|
| 1312 | + * @since 1.8.0 |
|
| 1313 | + * |
|
| 1314 | + * @return void |
|
| 1315 | + */ |
|
| 1316 | + public function admin_enqueue_styles() { |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | + wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1321 | + |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * Show the title modules on the single course template. |
|
| 1326 | + * |
|
| 1327 | + * Function is hooked into sensei_single_course_modules_before. |
|
| 1328 | + * |
|
| 1329 | + * @since 1.8.0 |
|
| 1330 | + * @return void |
|
| 1331 | + */ |
|
| 1332 | + public function course_modules_title( ) { |
|
| 1333 | + |
|
| 1334 | + if( sensei_module_has_lessons() ){ |
|
| 1335 | + |
|
| 1336 | + echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1337 | + |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + /** |
|
| 1343 | + * Display the single course modules content this will only show |
|
| 1344 | + * if the course has modules. |
|
| 1345 | + * |
|
| 1346 | + * @since 1.8.0 |
|
| 1347 | + * @return void |
|
| 1348 | + */ |
|
| 1349 | + public function load_course_module_content_template(){ |
|
| 1350 | + |
|
| 1351 | + // load backwards compatible template name if it exists in the users theme |
|
| 1352 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | + if( $located_template ){ |
|
| 1354 | + |
|
| 1355 | + Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1356 | + return; |
|
| 1357 | + |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1361 | + |
|
| 1362 | + } // end course_module_content |
|
| 1363 | + |
|
| 1364 | + /** |
|
| 1365 | + * Returns all lessons for the given module ID |
|
| 1366 | + * |
|
| 1367 | + * @since 1.8.0 |
|
| 1368 | + * |
|
| 1369 | + * @param $course_id |
|
| 1370 | + * @param $term_id |
|
| 1371 | + * @return array $lessons |
|
| 1372 | + */ |
|
| 1373 | + public function get_lessons( $course_id , $term_id ){ |
|
| 1374 | + |
|
| 1375 | + $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1376 | 1376 | |
| 1377 | - if( isset( $lesson_query->posts ) ){ |
|
| 1377 | + if( isset( $lesson_query->posts ) ){ |
|
| 1378 | 1378 | |
| 1379 | - return $lesson_query->posts; |
|
| 1379 | + return $lesson_query->posts; |
|
| 1380 | 1380 | |
| 1381 | - }else{ |
|
| 1381 | + }else{ |
|
| 1382 | 1382 | |
| 1383 | - return array(); |
|
| 1383 | + return array(); |
|
| 1384 | 1384 | |
| 1385 | - } |
|
| 1385 | + } |
|
| 1386 | 1386 | |
| 1387 | - } // end get lessons |
|
| 1387 | + } // end get lessons |
|
| 1388 | 1388 | |
| 1389 | - /** |
|
| 1390 | - * Returns all lessons for the given module ID |
|
| 1391 | - * |
|
| 1392 | - * @since 1.8.0 |
|
| 1393 | - * |
|
| 1394 | - * @param $course_id |
|
| 1395 | - * @param $term_id |
|
| 1396 | - * @return WP_Query $lessons_query |
|
| 1397 | - */ |
|
| 1398 | - public function get_lessons_query( $course_id , $term_id ){ |
|
| 1399 | - |
|
| 1400 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1401 | - |
|
| 1402 | - return array(); |
|
| 1403 | - |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - $args = array( |
|
| 1407 | - 'post_type' => 'lesson', |
|
| 1408 | - 'post_status' => 'publish', |
|
| 1409 | - 'posts_per_page' => -1, |
|
| 1410 | - 'meta_query' => array( |
|
| 1411 | - array( |
|
| 1412 | - 'key' => '_lesson_course', |
|
| 1413 | - 'value' => intval($course_id), |
|
| 1414 | - 'compare' => '=' |
|
| 1415 | - ) |
|
| 1416 | - ), |
|
| 1417 | - 'tax_query' => array( |
|
| 1418 | - array( |
|
| 1419 | - 'taxonomy' => 'module', |
|
| 1420 | - 'field' => 'id', |
|
| 1421 | - 'terms' => intval( $term_id ) |
|
| 1422 | - ) |
|
| 1423 | - ), |
|
| 1424 | - 'orderby' => 'menu_order', |
|
| 1425 | - 'order' => 'ASC', |
|
| 1426 | - 'suppress_filters' => 0 |
|
| 1427 | - ); |
|
| 1428 | - |
|
| 1429 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1431 | - $args['orderby'] = 'meta_value_num date'; |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - $lessons_query = new WP_Query( $args ); |
|
| 1435 | - |
|
| 1436 | - return $lessons_query; |
|
| 1437 | - |
|
| 1438 | - } // end get lessons |
|
| 1439 | - |
|
| 1440 | - /** |
|
| 1441 | - * Find the lesson in the given course that doesn't belong |
|
| 1442 | - * to any of the courses modules |
|
| 1443 | - * |
|
| 1444 | - * |
|
| 1445 | - * @param $course_id |
|
| 1446 | - * |
|
| 1447 | - * @return array $non_module_lessons |
|
| 1448 | - */ |
|
| 1449 | - public function get_none_module_lessons( $course_id ){ |
|
| 1450 | - |
|
| 1451 | - $non_module_lessons = array(); |
|
| 1452 | - |
|
| 1453 | - //exit if there is no course id passed in |
|
| 1454 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1455 | - |
|
| 1456 | - return $non_module_lessons; |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - //save some time and check if we already have the saved |
|
| 1460 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1461 | - |
|
| 1462 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1463 | - |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - // create terms array which must be excluded from other arrays |
|
| 1467 | - $course_modules = $this->get_course_modules( $course_id ); |
|
| 1468 | - |
|
| 1469 | - //exit if there are no module on this course |
|
| 1470 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1471 | - |
|
| 1472 | - return Sensei()->course->course_lessons( $course_id ); |
|
| 1473 | - |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - $terms = array(); |
|
| 1477 | - foreach( $course_modules as $module ){ |
|
| 1478 | - |
|
| 1479 | - array_push( $terms , $module->term_id ); |
|
| 1480 | - |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $args = array( |
|
| 1484 | - 'post_type' => 'lesson', |
|
| 1485 | - 'post_status' => 'publish', |
|
| 1486 | - 'posts_per_page' => -1, |
|
| 1487 | - 'meta_query' => array( |
|
| 1488 | - array( |
|
| 1489 | - 'key' => '_lesson_course', |
|
| 1490 | - 'value' => intval( $course_id ), |
|
| 1491 | - 'compare' => '=' |
|
| 1492 | - ) |
|
| 1493 | - ), |
|
| 1494 | - 'tax_query' => array( |
|
| 1495 | - array( |
|
| 1496 | - 'taxonomy' => 'module', |
|
| 1497 | - 'field' => 'id', |
|
| 1498 | - 'terms' => $terms, |
|
| 1499 | - 'operator' => 'NOT IN' |
|
| 1500 | - ) |
|
| 1501 | - ), |
|
| 1502 | - 'orderby' => 'menu_order', |
|
| 1503 | - 'order' => 'ASC', |
|
| 1504 | - 'suppress_filters' => 0 |
|
| 1505 | - ); |
|
| 1506 | - |
|
| 1507 | - $wp_lessons_query = new WP_Query( $args ); |
|
| 1508 | - |
|
| 1509 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1510 | - $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1511 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - return $non_module_lessons; |
|
| 1515 | - } // end get_none_module_lessons |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Register the modules taxonomy |
|
| 1519 | - * |
|
| 1520 | - * @since 1.8.0 |
|
| 1521 | - */ |
|
| 1522 | - public function setup_modules_taxonomy(){ |
|
| 1523 | - |
|
| 1524 | - $labels = array( |
|
| 1525 | - 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1526 | - 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1527 | - 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1528 | - 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1529 | - 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1530 | - 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1531 | - 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1532 | - 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1533 | - 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1534 | - 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1535 | - 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | - ); |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * Filter to alter the Sensei Modules rewrite slug |
|
| 1540 | - * |
|
| 1541 | - * @since 1.8.0 |
|
| 1542 | - * @param string default 'modules' |
|
| 1543 | - */ |
|
| 1544 | - $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1545 | - |
|
| 1546 | - $args = array( |
|
| 1547 | - 'public' => true, |
|
| 1548 | - 'hierarchical' => true, |
|
| 1549 | - 'show_admin_column' => true, |
|
| 1550 | - 'capabilities' => array( |
|
| 1551 | - 'manage_terms' => 'manage_categories', |
|
| 1552 | - 'edit_terms' => 'edit_courses', |
|
| 1553 | - 'delete_terms' => 'manage_categories', |
|
| 1554 | - 'assign_terms' => 'edit_courses' |
|
| 1555 | - ), |
|
| 1556 | - 'show_in_nav_menus' => false, |
|
| 1557 | - 'show_in_quick_edit' => false, |
|
| 1558 | - 'show_ui' => true, |
|
| 1559 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1560 | - 'labels' => $labels |
|
| 1561 | - ); |
|
| 1562 | - |
|
| 1563 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1564 | - |
|
| 1565 | - }// end setup_modules_taxonomy |
|
| 1566 | - |
|
| 1567 | - /** |
|
| 1568 | - * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1569 | - * |
|
| 1570 | - * This function is hooked into the admin_menu |
|
| 1571 | - * |
|
| 1572 | - * @since 1.8.0 |
|
| 1573 | - * @return void |
|
| 1574 | - */ |
|
| 1575 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1576 | - |
|
| 1577 | - global $typenow , $taxnow; |
|
| 1578 | - |
|
| 1579 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - }// end redirect to course taxonomy |
|
| 1584 | - |
|
| 1585 | - /** |
|
| 1586 | - * Completely remove the module menu item under lessons. |
|
| 1587 | - * |
|
| 1588 | - * This function is hooked into the admin_menu |
|
| 1589 | - * |
|
| 1590 | - * @since 1.8.0 |
|
| 1591 | - * @return void |
|
| 1592 | - */ |
|
| 1593 | - public function remove_lessons_menu_model_taxonomy(){ |
|
| 1594 | - global $submenu; |
|
| 1595 | - |
|
| 1596 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1597 | - return; // exit |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1601 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1602 | - |
|
| 1603 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1605 | - } |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - }// end remove lesson module tax |
|
| 1609 | - |
|
| 1610 | - /** |
|
| 1611 | - * Completely remove the second modules under courses |
|
| 1612 | - * |
|
| 1613 | - * This function is hooked into the admin_menu |
|
| 1614 | - * |
|
| 1615 | - * @since 1.8.0 |
|
| 1616 | - * @return void |
|
| 1617 | - */ |
|
| 1618 | - public function remove_courses_menu_model_taxonomy(){ |
|
| 1619 | - global $submenu; |
|
| 1620 | - |
|
| 1621 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1622 | - return; // exit |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1626 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1627 | - |
|
| 1628 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1630 | - } |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - }// end remove courses module tax |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * Determine the author of a module term term by looking at |
|
| 1637 | - * the prefixed author id. This function will query the full term object. |
|
| 1638 | - * Will return the admin user author could not be determined. |
|
| 1639 | - * |
|
| 1640 | - * @since 1.8.0 |
|
| 1641 | - * |
|
| 1642 | - * @param string $term_name |
|
| 1643 | - * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1644 | - */ |
|
| 1645 | - public static function get_term_authors( $term_name ){ |
|
| 1646 | - |
|
| 1647 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1648 | - |
|
| 1649 | - $owners = array(); |
|
| 1650 | - if( empty( $terms ) ){ |
|
| 1651 | - |
|
| 1652 | - return $owners; |
|
| 1389 | + /** |
|
| 1390 | + * Returns all lessons for the given module ID |
|
| 1391 | + * |
|
| 1392 | + * @since 1.8.0 |
|
| 1393 | + * |
|
| 1394 | + * @param $course_id |
|
| 1395 | + * @param $term_id |
|
| 1396 | + * @return WP_Query $lessons_query |
|
| 1397 | + */ |
|
| 1398 | + public function get_lessons_query( $course_id , $term_id ){ |
|
| 1399 | + |
|
| 1400 | + if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1401 | + |
|
| 1402 | + return array(); |
|
| 1403 | + |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + $args = array( |
|
| 1407 | + 'post_type' => 'lesson', |
|
| 1408 | + 'post_status' => 'publish', |
|
| 1409 | + 'posts_per_page' => -1, |
|
| 1410 | + 'meta_query' => array( |
|
| 1411 | + array( |
|
| 1412 | + 'key' => '_lesson_course', |
|
| 1413 | + 'value' => intval($course_id), |
|
| 1414 | + 'compare' => '=' |
|
| 1415 | + ) |
|
| 1416 | + ), |
|
| 1417 | + 'tax_query' => array( |
|
| 1418 | + array( |
|
| 1419 | + 'taxonomy' => 'module', |
|
| 1420 | + 'field' => 'id', |
|
| 1421 | + 'terms' => intval( $term_id ) |
|
| 1422 | + ) |
|
| 1423 | + ), |
|
| 1424 | + 'orderby' => 'menu_order', |
|
| 1425 | + 'order' => 'ASC', |
|
| 1426 | + 'suppress_filters' => 0 |
|
| 1427 | + ); |
|
| 1428 | + |
|
| 1429 | + if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | + $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1431 | + $args['orderby'] = 'meta_value_num date'; |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + $lessons_query = new WP_Query( $args ); |
|
| 1435 | + |
|
| 1436 | + return $lessons_query; |
|
| 1437 | + |
|
| 1438 | + } // end get lessons |
|
| 1439 | + |
|
| 1440 | + /** |
|
| 1441 | + * Find the lesson in the given course that doesn't belong |
|
| 1442 | + * to any of the courses modules |
|
| 1443 | + * |
|
| 1444 | + * |
|
| 1445 | + * @param $course_id |
|
| 1446 | + * |
|
| 1447 | + * @return array $non_module_lessons |
|
| 1448 | + */ |
|
| 1449 | + public function get_none_module_lessons( $course_id ){ |
|
| 1450 | + |
|
| 1451 | + $non_module_lessons = array(); |
|
| 1452 | + |
|
| 1453 | + //exit if there is no course id passed in |
|
| 1454 | + if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1455 | + |
|
| 1456 | + return $non_module_lessons; |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + //save some time and check if we already have the saved |
|
| 1460 | + if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1461 | + |
|
| 1462 | + return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1463 | + |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + // create terms array which must be excluded from other arrays |
|
| 1467 | + $course_modules = $this->get_course_modules( $course_id ); |
|
| 1468 | + |
|
| 1469 | + //exit if there are no module on this course |
|
| 1470 | + if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1471 | + |
|
| 1472 | + return Sensei()->course->course_lessons( $course_id ); |
|
| 1473 | + |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + $terms = array(); |
|
| 1477 | + foreach( $course_modules as $module ){ |
|
| 1478 | + |
|
| 1479 | + array_push( $terms , $module->term_id ); |
|
| 1480 | + |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + $args = array( |
|
| 1484 | + 'post_type' => 'lesson', |
|
| 1485 | + 'post_status' => 'publish', |
|
| 1486 | + 'posts_per_page' => -1, |
|
| 1487 | + 'meta_query' => array( |
|
| 1488 | + array( |
|
| 1489 | + 'key' => '_lesson_course', |
|
| 1490 | + 'value' => intval( $course_id ), |
|
| 1491 | + 'compare' => '=' |
|
| 1492 | + ) |
|
| 1493 | + ), |
|
| 1494 | + 'tax_query' => array( |
|
| 1495 | + array( |
|
| 1496 | + 'taxonomy' => 'module', |
|
| 1497 | + 'field' => 'id', |
|
| 1498 | + 'terms' => $terms, |
|
| 1499 | + 'operator' => 'NOT IN' |
|
| 1500 | + ) |
|
| 1501 | + ), |
|
| 1502 | + 'orderby' => 'menu_order', |
|
| 1503 | + 'order' => 'ASC', |
|
| 1504 | + 'suppress_filters' => 0 |
|
| 1505 | + ); |
|
| 1506 | + |
|
| 1507 | + $wp_lessons_query = new WP_Query( $args ); |
|
| 1508 | + |
|
| 1509 | + if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1510 | + $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1511 | + set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + return $non_module_lessons; |
|
| 1515 | + } // end get_none_module_lessons |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Register the modules taxonomy |
|
| 1519 | + * |
|
| 1520 | + * @since 1.8.0 |
|
| 1521 | + */ |
|
| 1522 | + public function setup_modules_taxonomy(){ |
|
| 1523 | + |
|
| 1524 | + $labels = array( |
|
| 1525 | + 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1526 | + 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1527 | + 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1528 | + 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1529 | + 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1530 | + 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1531 | + 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1532 | + 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1533 | + 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1534 | + 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1535 | + 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | + ); |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * Filter to alter the Sensei Modules rewrite slug |
|
| 1540 | + * |
|
| 1541 | + * @since 1.8.0 |
|
| 1542 | + * @param string default 'modules' |
|
| 1543 | + */ |
|
| 1544 | + $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1545 | + |
|
| 1546 | + $args = array( |
|
| 1547 | + 'public' => true, |
|
| 1548 | + 'hierarchical' => true, |
|
| 1549 | + 'show_admin_column' => true, |
|
| 1550 | + 'capabilities' => array( |
|
| 1551 | + 'manage_terms' => 'manage_categories', |
|
| 1552 | + 'edit_terms' => 'edit_courses', |
|
| 1553 | + 'delete_terms' => 'manage_categories', |
|
| 1554 | + 'assign_terms' => 'edit_courses' |
|
| 1555 | + ), |
|
| 1556 | + 'show_in_nav_menus' => false, |
|
| 1557 | + 'show_in_quick_edit' => false, |
|
| 1558 | + 'show_ui' => true, |
|
| 1559 | + 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1560 | + 'labels' => $labels |
|
| 1561 | + ); |
|
| 1562 | + |
|
| 1563 | + register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1564 | + |
|
| 1565 | + }// end setup_modules_taxonomy |
|
| 1566 | + |
|
| 1567 | + /** |
|
| 1568 | + * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1569 | + * |
|
| 1570 | + * This function is hooked into the admin_menu |
|
| 1571 | + * |
|
| 1572 | + * @since 1.8.0 |
|
| 1573 | + * @return void |
|
| 1574 | + */ |
|
| 1575 | + function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1576 | + |
|
| 1577 | + global $typenow , $taxnow; |
|
| 1578 | + |
|
| 1579 | + if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | + wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + }// end redirect to course taxonomy |
|
| 1584 | + |
|
| 1585 | + /** |
|
| 1586 | + * Completely remove the module menu item under lessons. |
|
| 1587 | + * |
|
| 1588 | + * This function is hooked into the admin_menu |
|
| 1589 | + * |
|
| 1590 | + * @since 1.8.0 |
|
| 1591 | + * @return void |
|
| 1592 | + */ |
|
| 1593 | + public function remove_lessons_menu_model_taxonomy(){ |
|
| 1594 | + global $submenu; |
|
| 1595 | + |
|
| 1596 | + if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1597 | + return; // exit |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1601 | + foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1602 | + |
|
| 1603 | + if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | + unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1605 | + } |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + }// end remove lesson module tax |
|
| 1609 | + |
|
| 1610 | + /** |
|
| 1611 | + * Completely remove the second modules under courses |
|
| 1612 | + * |
|
| 1613 | + * This function is hooked into the admin_menu |
|
| 1614 | + * |
|
| 1615 | + * @since 1.8.0 |
|
| 1616 | + * @return void |
|
| 1617 | + */ |
|
| 1618 | + public function remove_courses_menu_model_taxonomy(){ |
|
| 1619 | + global $submenu; |
|
| 1620 | + |
|
| 1621 | + if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1622 | + return; // exit |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1626 | + foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1627 | + |
|
| 1628 | + if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | + unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1630 | + } |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + }// end remove courses module tax |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * Determine the author of a module term term by looking at |
|
| 1637 | + * the prefixed author id. This function will query the full term object. |
|
| 1638 | + * Will return the admin user author could not be determined. |
|
| 1639 | + * |
|
| 1640 | + * @since 1.8.0 |
|
| 1641 | + * |
|
| 1642 | + * @param string $term_name |
|
| 1643 | + * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1644 | + */ |
|
| 1645 | + public static function get_term_authors( $term_name ){ |
|
| 1646 | + |
|
| 1647 | + $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1648 | + |
|
| 1649 | + $owners = array(); |
|
| 1650 | + if( empty( $terms ) ){ |
|
| 1651 | + |
|
| 1652 | + return $owners; |
|
| 1653 | 1653 | |
| 1654 | - } |
|
| 1654 | + } |
|
| 1655 | 1655 | |
| 1656 | - // setup the admin user |
|
| 1656 | + // setup the admin user |
|
| 1657 | 1657 | |
| 1658 | 1658 | |
| 1659 | - //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1660 | - foreach( $terms as $term){ |
|
| 1661 | - if( $term->name == $term_name ){ |
|
| 1659 | + //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1660 | + foreach( $terms as $term){ |
|
| 1661 | + if( $term->name == $term_name ){ |
|
| 1662 | 1662 | |
| 1663 | - // look for the author in the slug |
|
| 1664 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1663 | + // look for the author in the slug |
|
| 1664 | + $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1665 | 1665 | |
| 1666 | - }// end if term name |
|
| 1666 | + }// end if term name |
|
| 1667 | 1667 | |
| 1668 | - } // end for each |
|
| 1668 | + } // end for each |
|
| 1669 | 1669 | |
| 1670 | - return $owners; |
|
| 1670 | + return $owners; |
|
| 1671 | 1671 | |
| 1672 | - }// end get_term_author |
|
| 1672 | + }// end get_term_author |
|
| 1673 | 1673 | |
| 1674 | - /** |
|
| 1675 | - * Looks at a term slug and figures out |
|
| 1676 | - * which author created the slug. The author was |
|
| 1677 | - * appended when the user saved the module term in the course edit |
|
| 1678 | - * screen. |
|
| 1679 | - * |
|
| 1680 | - * @since 1.8.0 |
|
| 1681 | - * |
|
| 1682 | - * @param $slug |
|
| 1683 | - * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1684 | - */ |
|
| 1685 | - public static function get_term_author( $slug='' ){ |
|
| 1674 | + /** |
|
| 1675 | + * Looks at a term slug and figures out |
|
| 1676 | + * which author created the slug. The author was |
|
| 1677 | + * appended when the user saved the module term in the course edit |
|
| 1678 | + * screen. |
|
| 1679 | + * |
|
| 1680 | + * @since 1.8.0 |
|
| 1681 | + * |
|
| 1682 | + * @param $slug |
|
| 1683 | + * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1684 | + */ |
|
| 1685 | + public static function get_term_author( $slug='' ){ |
|
| 1686 | 1686 | |
| 1687 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1687 | + $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1688 | 1688 | |
| 1689 | - if( empty( $slug ) ){ |
|
| 1689 | + if( empty( $slug ) ){ |
|
| 1690 | 1690 | |
| 1691 | - return $term_owner; |
|
| 1691 | + return $term_owner; |
|
| 1692 | 1692 | |
| 1693 | - } |
|
| 1693 | + } |
|
| 1694 | 1694 | |
| 1695 | - // look for the author in the slug |
|
| 1696 | - $slug_parts = explode( '-', $slug ); |
|
| 1695 | + // look for the author in the slug |
|
| 1696 | + $slug_parts = explode( '-', $slug ); |
|
| 1697 | 1697 | |
| 1698 | - if( count( $slug_parts ) > 1 ){ |
|
| 1698 | + if( count( $slug_parts ) > 1 ){ |
|
| 1699 | 1699 | |
| 1700 | - // get the user data |
|
| 1701 | - $possible_user_id = $slug_parts[0]; |
|
| 1702 | - $author = get_userdata( $possible_user_id ); |
|
| 1700 | + // get the user data |
|
| 1701 | + $possible_user_id = $slug_parts[0]; |
|
| 1702 | + $author = get_userdata( $possible_user_id ); |
|
| 1703 | 1703 | |
| 1704 | - // if the user doesnt exist for the first part of the slug |
|
| 1705 | - // then this slug was also created by admin |
|
| 1706 | - if( is_a( $author, 'WP_User' ) ){ |
|
| 1704 | + // if the user doesnt exist for the first part of the slug |
|
| 1705 | + // then this slug was also created by admin |
|
| 1706 | + if( is_a( $author, 'WP_User' ) ){ |
|
| 1707 | 1707 | |
| 1708 | - $term_owner = $author; |
|
| 1708 | + $term_owner = $author; |
|
| 1709 | 1709 | |
| 1710 | - } |
|
| 1711 | - } |
|
| 1710 | + } |
|
| 1711 | + } |
|
| 1712 | 1712 | |
| 1713 | - return $term_owner; |
|
| 1714 | - } |
|
| 1713 | + return $term_owner; |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - /** |
|
| 1717 | - * Display the Sensei modules taxonomy terms metabox |
|
| 1718 | - * |
|
| 1719 | - * @since 1.8.0 |
|
| 1720 | - * |
|
| 1721 | - * @hooked into add_meta_box |
|
| 1722 | - * |
|
| 1723 | - * @param WP_Post $post Post object. |
|
| 1724 | - */ |
|
| 1725 | - public function course_module_metabox( $post ) { |
|
| 1716 | + /** |
|
| 1717 | + * Display the Sensei modules taxonomy terms metabox |
|
| 1718 | + * |
|
| 1719 | + * @since 1.8.0 |
|
| 1720 | + * |
|
| 1721 | + * @hooked into add_meta_box |
|
| 1722 | + * |
|
| 1723 | + * @param WP_Post $post Post object. |
|
| 1724 | + */ |
|
| 1725 | + public function course_module_metabox( $post ) { |
|
| 1726 | 1726 | |
| 1727 | - $tax_name = 'module'; |
|
| 1728 | - $taxonomy = get_taxonomy( 'module' ); |
|
| 1727 | + $tax_name = 'module'; |
|
| 1728 | + $taxonomy = get_taxonomy( 'module' ); |
|
| 1729 | 1729 | |
| 1730 | - ?> |
|
| 1730 | + ?> |
|
| 1731 | 1731 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 1732 | 1732 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 1733 | 1733 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
@@ -1742,9 +1742,9 @@ discard block |
||
| 1742 | 1742 | |
| 1743 | 1743 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
| 1744 | 1744 | <?php |
| 1745 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1746 | - echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 1747 | - ?> |
|
| 1745 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1746 | + echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 1747 | + ?> |
|
| 1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
| 1749 | 1749 | <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
| 1750 | 1750 | </ul> |
@@ -1754,9 +1754,9 @@ discard block |
||
| 1754 | 1754 | <h4> |
| 1755 | 1755 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
| 1756 | 1756 | <?php |
| 1757 | - /* translators: %s: add new taxonomy label */ |
|
| 1758 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1759 | - ?> |
|
| 1757 | + /* translators: %s: add new taxonomy label */ |
|
| 1758 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1759 | + ?> |
|
| 1760 | 1760 | </a> |
| 1761 | 1761 | </h4> |
| 1762 | 1762 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -1771,331 +1771,331 @@ discard block |
||
| 1771 | 1771 | </div> |
| 1772 | 1772 | <?php |
| 1773 | 1773 | |
| 1774 | - } // end course_module_metabox |
|
| 1774 | + } // end course_module_metabox |
|
| 1775 | 1775 | |
| 1776 | 1776 | |
| 1777 | - /** |
|
| 1778 | - * Submits a new module term prefixed with the |
|
| 1779 | - * the current author id. |
|
| 1780 | - * |
|
| 1781 | - * @since 1.8.0 |
|
| 1782 | - */ |
|
| 1783 | - public static function add_new_module_term( ) { |
|
| 1777 | + /** |
|
| 1778 | + * Submits a new module term prefixed with the |
|
| 1779 | + * the current author id. |
|
| 1780 | + * |
|
| 1781 | + * @since 1.8.0 |
|
| 1782 | + */ |
|
| 1783 | + public static function add_new_module_term( ) { |
|
| 1784 | 1784 | |
| 1785 | 1785 | |
| 1786 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1788 | - } |
|
| 1786 | + if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | + wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1788 | + } |
|
| 1789 | 1789 | |
| 1790 | - // get the term an create the new term storing infomration |
|
| 1791 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1790 | + // get the term an create the new term storing infomration |
|
| 1791 | + $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1792 | 1792 | |
| 1793 | - if( current_user_can('manage_options' ) ) { |
|
| 1793 | + if( current_user_can('manage_options' ) ) { |
|
| 1794 | 1794 | |
| 1795 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1795 | + $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1796 | 1796 | |
| 1797 | - } else { |
|
| 1797 | + } else { |
|
| 1798 | 1798 | |
| 1799 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1799 | + $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1800 | 1800 | |
| 1801 | - } |
|
| 1801 | + } |
|
| 1802 | 1802 | |
| 1803 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1803 | + $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1804 | 1804 | |
| 1805 | - // save the term |
|
| 1806 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1805 | + // save the term |
|
| 1806 | + $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1807 | 1807 | |
| 1808 | - // send error for all errors except term exits |
|
| 1809 | - if( is_wp_error( $slug ) ){ |
|
| 1808 | + // send error for all errors except term exits |
|
| 1809 | + if( is_wp_error( $slug ) ){ |
|
| 1810 | 1810 | |
| 1811 | - // prepare for possible term name and id to be passed down if term exists |
|
| 1812 | - $term_data = array(); |
|
| 1811 | + // prepare for possible term name and id to be passed down if term exists |
|
| 1812 | + $term_data = array(); |
|
| 1813 | 1813 | |
| 1814 | - // if term exists also send back the term name and id |
|
| 1815 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1814 | + // if term exists also send back the term name and id |
|
| 1815 | + if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1816 | 1816 | |
| 1817 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1818 | - $term_data['name'] = $term_name; |
|
| 1819 | - $term_data['id'] = $term->term_id; |
|
| 1817 | + $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1818 | + $term_data['name'] = $term_name; |
|
| 1819 | + $term_data['id'] = $term->term_id; |
|
| 1820 | 1820 | |
| 1821 | - // set the object terms |
|
| 1822 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1823 | - } |
|
| 1821 | + // set the object terms |
|
| 1822 | + wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1823 | + } |
|
| 1824 | 1824 | |
| 1825 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1825 | + wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1826 | 1826 | |
| 1827 | - } |
|
| 1827 | + } |
|
| 1828 | 1828 | |
| 1829 | - //make sure the new term is checked for this course |
|
| 1829 | + //make sure the new term is checked for this course |
|
| 1830 | 1830 | |
| 1831 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1831 | + wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1832 | 1832 | |
| 1833 | - // Handle request then generate response using WP_Ajax_Response |
|
| 1834 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1833 | + // Handle request then generate response using WP_Ajax_Response |
|
| 1834 | + wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1835 | 1835 | |
| 1836 | - } |
|
| 1836 | + } |
|
| 1837 | 1837 | |
| 1838 | - /** |
|
| 1839 | - * Limit the course module metabox |
|
| 1840 | - * term list to only those on courses belonging to current teacher. |
|
| 1841 | - * |
|
| 1842 | - * Hooked into 'get_terms' |
|
| 1843 | - * |
|
| 1844 | - * @since 1.8.0 |
|
| 1845 | - */ |
|
| 1846 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1838 | + /** |
|
| 1839 | + * Limit the course module metabox |
|
| 1840 | + * term list to only those on courses belonging to current teacher. |
|
| 1841 | + * |
|
| 1842 | + * Hooked into 'get_terms' |
|
| 1843 | + * |
|
| 1844 | + * @since 1.8.0 |
|
| 1845 | + */ |
|
| 1846 | + public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1847 | 1847 | |
| 1848 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1849 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1850 | - return $terms; |
|
| 1851 | - } |
|
| 1848 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1849 | + if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1850 | + return $terms; |
|
| 1851 | + } |
|
| 1852 | 1852 | |
| 1853 | - // avoid infinite call loop |
|
| 1854 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1853 | + // avoid infinite call loop |
|
| 1854 | + remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1855 | 1855 | |
| 1856 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1857 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1858 | - // change only scrub the terms ids form the array keys |
|
| 1859 | - $terms = array_keys( $terms ); |
|
| 1860 | - } |
|
| 1856 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1857 | + if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1858 | + // change only scrub the terms ids form the array keys |
|
| 1859 | + $terms = array_keys( $terms ); |
|
| 1860 | + } |
|
| 1861 | 1861 | |
| 1862 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1862 | + $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1863 | 1863 | |
| 1864 | - // add filter again as removed above |
|
| 1865 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1864 | + // add filter again as removed above |
|
| 1865 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1866 | 1866 | |
| 1867 | - return $teachers_terms; |
|
| 1868 | - }// end filter_module_terms |
|
| 1867 | + return $teachers_terms; |
|
| 1868 | + }// end filter_module_terms |
|
| 1869 | 1869 | |
| 1870 | - /** |
|
| 1871 | - * For the selected items on a course module only return those |
|
| 1872 | - * for the current user. This does not apply to admin and super admin users. |
|
| 1873 | - * |
|
| 1874 | - * hooked into get_object_terms |
|
| 1875 | - * |
|
| 1876 | - * @since 1.8.0 |
|
| 1877 | - */ |
|
| 1878 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1870 | + /** |
|
| 1871 | + * For the selected items on a course module only return those |
|
| 1872 | + * for the current user. This does not apply to admin and super admin users. |
|
| 1873 | + * |
|
| 1874 | + * hooked into get_object_terms |
|
| 1875 | + * |
|
| 1876 | + * @since 1.8.0 |
|
| 1877 | + */ |
|
| 1878 | + public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1879 | 1879 | |
| 1880 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1881 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1882 | - // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1883 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1884 | - return $terms; |
|
| 1885 | - } |
|
| 1880 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1881 | + if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1882 | + // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1883 | + || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1884 | + return $terms; |
|
| 1885 | + } |
|
| 1886 | 1886 | |
| 1887 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1887 | + $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1888 | 1888 | |
| 1889 | - // if term objects were passed in send back objects |
|
| 1890 | - // if term id were passed in send that back |
|
| 1891 | - if( is_object( $terms[0] ) ){ |
|
| 1892 | - return $term_objects; |
|
| 1893 | - } |
|
| 1889 | + // if term objects were passed in send back objects |
|
| 1890 | + // if term id were passed in send that back |
|
| 1891 | + if( is_object( $terms[0] ) ){ |
|
| 1892 | + return $term_objects; |
|
| 1893 | + } |
|
| 1894 | 1894 | |
| 1895 | - $terms = array(); |
|
| 1896 | - foreach( $term_objects as $term_object ){ |
|
| 1897 | - $terms[] = $term_object->term_id; |
|
| 1898 | - } |
|
| 1895 | + $terms = array(); |
|
| 1896 | + foreach( $term_objects as $term_object ){ |
|
| 1897 | + $terms[] = $term_object->term_id; |
|
| 1898 | + } |
|
| 1899 | 1899 | |
| 1900 | - return $terms; |
|
| 1900 | + return $terms; |
|
| 1901 | 1901 | |
| 1902 | 1902 | |
| 1903 | - }// end filter_course_selected_terms |
|
| 1903 | + }// end filter_course_selected_terms |
|
| 1904 | 1904 | |
| 1905 | - /** |
|
| 1906 | - * Filter the given terms and only return the |
|
| 1907 | - * terms that belong to the given user id. |
|
| 1908 | - * |
|
| 1909 | - * @since 1.8.0 |
|
| 1910 | - * @param $terms |
|
| 1911 | - * @param $user_id |
|
| 1912 | - * @return array |
|
| 1913 | - */ |
|
| 1914 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1905 | + /** |
|
| 1906 | + * Filter the given terms and only return the |
|
| 1907 | + * terms that belong to the given user id. |
|
| 1908 | + * |
|
| 1909 | + * @since 1.8.0 |
|
| 1910 | + * @param $terms |
|
| 1911 | + * @param $user_id |
|
| 1912 | + * @return array |
|
| 1913 | + */ |
|
| 1914 | + public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1915 | 1915 | |
| 1916 | - $users_terms = array(); |
|
| 1916 | + $users_terms = array(); |
|
| 1917 | 1917 | |
| 1918 | - foreach( $terms as $index => $term ){ |
|
| 1918 | + foreach( $terms as $index => $term ){ |
|
| 1919 | 1919 | |
| 1920 | - if( is_numeric( $term ) ){ |
|
| 1921 | - // the term id was given, get the term object |
|
| 1922 | - $term = get_term( $term, 'module' ); |
|
| 1923 | - } |
|
| 1920 | + if( is_numeric( $term ) ){ |
|
| 1921 | + // the term id was given, get the term object |
|
| 1922 | + $term = get_term( $term, 'module' ); |
|
| 1923 | + } |
|
| 1924 | 1924 | |
| 1925 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1925 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1926 | 1926 | |
| 1927 | - if ( $user_id == $author->ID ) { |
|
| 1928 | - // add the term to the teachers terms |
|
| 1929 | - $users_terms[] = $term; |
|
| 1930 | - } |
|
| 1927 | + if ( $user_id == $author->ID ) { |
|
| 1928 | + // add the term to the teachers terms |
|
| 1929 | + $users_terms[] = $term; |
|
| 1930 | + } |
|
| 1931 | 1931 | |
| 1932 | - } |
|
| 1932 | + } |
|
| 1933 | 1933 | |
| 1934 | - return $users_terms; |
|
| 1934 | + return $users_terms; |
|
| 1935 | 1935 | |
| 1936 | - } // end filter terms by owner |
|
| 1936 | + } // end filter terms by owner |
|
| 1937 | 1937 | |
| 1938 | - /** |
|
| 1939 | - * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1940 | - * This will not add name to terms belonging to admin user. |
|
| 1941 | - * |
|
| 1942 | - * Hooked into 'get_terms' |
|
| 1943 | - * |
|
| 1944 | - * @since 1.8.0 |
|
| 1945 | - */ |
|
| 1946 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1947 | - { |
|
| 1938 | + /** |
|
| 1939 | + * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1940 | + * This will not add name to terms belonging to admin user. |
|
| 1941 | + * |
|
| 1942 | + * Hooked into 'get_terms' |
|
| 1943 | + * |
|
| 1944 | + * @since 1.8.0 |
|
| 1945 | + */ |
|
| 1946 | + public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1947 | + { |
|
| 1948 | 1948 | |
| 1949 | - // only for admin users ont he module taxonomy |
|
| 1950 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1951 | - return $terms; |
|
| 1952 | - } |
|
| 1949 | + // only for admin users ont he module taxonomy |
|
| 1950 | + if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1951 | + return $terms; |
|
| 1952 | + } |
|
| 1953 | 1953 | |
| 1954 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1955 | - // simply return this as wp doesn't need an array of stdObject Term |
|
| 1956 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1954 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1955 | + // simply return this as wp doesn't need an array of stdObject Term |
|
| 1956 | + if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1957 | 1957 | |
| 1958 | - return $terms; |
|
| 1958 | + return $terms; |
|
| 1959 | 1959 | |
| 1960 | - } |
|
| 1960 | + } |
|
| 1961 | 1961 | |
| 1962 | - // loop through and update all terms adding the author name |
|
| 1963 | - foreach( $terms as $index => $term ){ |
|
| 1962 | + // loop through and update all terms adding the author name |
|
| 1963 | + foreach( $terms as $index => $term ){ |
|
| 1964 | 1964 | |
| 1965 | - if( is_numeric( $term ) ){ |
|
| 1966 | - // the term id was given, get the term object |
|
| 1967 | - $term = get_term( $term, 'module' ); |
|
| 1968 | - } |
|
| 1965 | + if( is_numeric( $term ) ){ |
|
| 1966 | + // the term id was given, get the term object |
|
| 1967 | + $term = get_term( $term, 'module' ); |
|
| 1968 | + } |
|
| 1969 | 1969 | |
| 1970 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1970 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1971 | 1971 | |
| 1972 | - if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1974 | - } |
|
| 1972 | + if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | + $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1974 | + } |
|
| 1975 | 1975 | |
| 1976 | - // add the term to the teachers terms |
|
| 1977 | - $users_terms[] = $term; |
|
| 1976 | + // add the term to the teachers terms |
|
| 1977 | + $users_terms[] = $term; |
|
| 1978 | 1978 | |
| 1979 | - } |
|
| 1979 | + } |
|
| 1980 | 1980 | |
| 1981 | - return $users_terms; |
|
| 1982 | - } |
|
| 1981 | + return $users_terms; |
|
| 1982 | + } |
|
| 1983 | 1983 | |
| 1984 | - /** |
|
| 1985 | - * Remove modules metabox that come by default |
|
| 1986 | - * with the modules taxonomy. We are removing this as |
|
| 1987 | - * we have created our own custom meta box. |
|
| 1988 | - */ |
|
| 1989 | - public static function remove_default_modules_box() { |
|
| 1984 | + /** |
|
| 1985 | + * Remove modules metabox that come by default |
|
| 1986 | + * with the modules taxonomy. We are removing this as |
|
| 1987 | + * we have created our own custom meta box. |
|
| 1988 | + */ |
|
| 1989 | + public static function remove_default_modules_box() { |
|
| 1990 | 1990 | |
| 1991 | - remove_meta_box('modulediv', 'course', 'side'); |
|
| 1991 | + remove_meta_box('modulediv', 'course', 'side'); |
|
| 1992 | 1992 | |
| 1993 | - } |
|
| 1993 | + } |
|
| 1994 | 1994 | |
| 1995 | - /** |
|
| 1996 | - * When a course is save make sure to reset the transient set |
|
| 1997 | - * for it when determining the none module lessons. |
|
| 1998 | - * |
|
| 1999 | - * @sine 1.9.0 |
|
| 2000 | - * @param $post_id |
|
| 2001 | - */ |
|
| 2002 | - public static function reset_none_modules_transient ( $post_id ){ |
|
| 1995 | + /** |
|
| 1996 | + * When a course is save make sure to reset the transient set |
|
| 1997 | + * for it when determining the none module lessons. |
|
| 1998 | + * |
|
| 1999 | + * @sine 1.9.0 |
|
| 2000 | + * @param $post_id |
|
| 2001 | + */ |
|
| 2002 | + public static function reset_none_modules_transient ( $post_id ){ |
|
| 2003 | 2003 | |
| 2004 | - // this should only apply to course and lesson post types |
|
| 2005 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2004 | + // this should only apply to course and lesson post types |
|
| 2005 | + if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2006 | 2006 | |
| 2007 | - $course_id = ''; |
|
| 2007 | + $course_id = ''; |
|
| 2008 | 2008 | |
| 2009 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2009 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2010 | 2010 | |
| 2011 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2011 | + $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2012 | 2012 | |
| 2013 | - } |
|
| 2013 | + } |
|
| 2014 | 2014 | |
| 2015 | 2015 | |
| 2016 | - if( !empty( $course_id ) ){ |
|
| 2016 | + if( !empty( $course_id ) ){ |
|
| 2017 | 2017 | |
| 2018 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2018 | + delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2019 | 2019 | |
| 2020 | - } |
|
| 2020 | + } |
|
| 2021 | 2021 | |
| 2022 | - } // end if is a course or a lesson |
|
| 2022 | + } // end if is a course or a lesson |
|
| 2023 | 2023 | |
| 2024 | - } // end reset_none_modules_transient |
|
| 2024 | + } // end reset_none_modules_transient |
|
| 2025 | 2025 | |
| 2026 | - /** |
|
| 2027 | - * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2028 | - * |
|
| 2029 | - * @since 1.9.0 |
|
| 2030 | - * @deprecated since 1.9.0 |
|
| 2031 | - * |
|
| 2032 | - */ |
|
| 2033 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2026 | + /** |
|
| 2027 | + * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2028 | + * |
|
| 2029 | + * @since 1.9.0 |
|
| 2030 | + * @deprecated since 1.9.0 |
|
| 2031 | + * |
|
| 2032 | + */ |
|
| 2033 | + public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2034 | 2034 | |
| 2035 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2035 | + sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2036 | 2036 | |
| 2037 | - } |
|
| 2037 | + } |
|
| 2038 | 2038 | |
| 2039 | - /** |
|
| 2040 | - * Setup the single course module loop. |
|
| 2041 | - * |
|
| 2042 | - * Setup the global $sensei_modules_loop |
|
| 2043 | - * |
|
| 2044 | - * @since 1.9.0 |
|
| 2045 | - */ |
|
| 2046 | - public static function setup_single_course_module_loop(){ |
|
| 2039 | + /** |
|
| 2040 | + * Setup the single course module loop. |
|
| 2041 | + * |
|
| 2042 | + * Setup the global $sensei_modules_loop |
|
| 2043 | + * |
|
| 2044 | + * @since 1.9.0 |
|
| 2045 | + */ |
|
| 2046 | + public static function setup_single_course_module_loop(){ |
|
| 2047 | 2047 | |
| 2048 | - global $sensei_modules_loop, $post; |
|
| 2049 | - $course_id = $post->ID; |
|
| 2048 | + global $sensei_modules_loop, $post; |
|
| 2049 | + $course_id = $post->ID; |
|
| 2050 | 2050 | |
| 2051 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2051 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2052 | 2052 | |
| 2053 | - //initial setup |
|
| 2054 | - $sensei_modules_loop['total'] = 0; |
|
| 2055 | - $sensei_modules_loop['modules'] = array(); |
|
| 2056 | - $sensei_modules_loop['current'] = -1; |
|
| 2053 | + //initial setup |
|
| 2054 | + $sensei_modules_loop['total'] = 0; |
|
| 2055 | + $sensei_modules_loop['modules'] = array(); |
|
| 2056 | + $sensei_modules_loop['current'] = -1; |
|
| 2057 | 2057 | |
| 2058 | - // exit if this course doesn't have modules |
|
| 2059 | - if( !$modules || empty( $modules ) ){ |
|
| 2060 | - return; |
|
| 2061 | - } |
|
| 2058 | + // exit if this course doesn't have modules |
|
| 2059 | + if( !$modules || empty( $modules ) ){ |
|
| 2060 | + return; |
|
| 2061 | + } |
|
| 2062 | 2062 | |
| 2063 | 2063 | |
| 2064 | - $lessons_in_all_modules = array(); |
|
| 2065 | - foreach( $modules as $term ){ |
|
| 2064 | + $lessons_in_all_modules = array(); |
|
| 2065 | + foreach( $modules as $term ){ |
|
| 2066 | 2066 | |
| 2067 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2067 | + $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | + $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2069 | 2069 | |
| 2070 | - } |
|
| 2070 | + } |
|
| 2071 | 2071 | |
| 2072 | 2072 | |
| 2073 | - //setup all of the modules loop variables |
|
| 2074 | - $sensei_modules_loop['total'] = count( $modules ); |
|
| 2075 | - $sensei_modules_loop['modules'] = $modules; |
|
| 2076 | - $sensei_modules_loop['current'] = -1; |
|
| 2077 | - $sensei_modules_loop['course_id'] = $course_id; |
|
| 2073 | + //setup all of the modules loop variables |
|
| 2074 | + $sensei_modules_loop['total'] = count( $modules ); |
|
| 2075 | + $sensei_modules_loop['modules'] = $modules; |
|
| 2076 | + $sensei_modules_loop['current'] = -1; |
|
| 2077 | + $sensei_modules_loop['course_id'] = $course_id; |
|
| 2078 | 2078 | |
| 2079 | - }// end setup_single_course_module_loop |
|
| 2079 | + }// end setup_single_course_module_loop |
|
| 2080 | 2080 | |
| 2081 | - /** |
|
| 2082 | - * Tear down the course module loop. |
|
| 2083 | - * |
|
| 2084 | - * @since 1.9.0 |
|
| 2085 | - * |
|
| 2086 | - */ |
|
| 2087 | - public static function teardown_single_course_module_loop(){ |
|
| 2081 | + /** |
|
| 2082 | + * Tear down the course module loop. |
|
| 2083 | + * |
|
| 2084 | + * @since 1.9.0 |
|
| 2085 | + * |
|
| 2086 | + */ |
|
| 2087 | + public static function teardown_single_course_module_loop(){ |
|
| 2088 | 2088 | |
| 2089 | - global $sensei_modules_loop, $wp_query, $post; |
|
| 2089 | + global $sensei_modules_loop, $wp_query, $post; |
|
| 2090 | 2090 | |
| 2091 | - //reset all of the modules loop variables |
|
| 2092 | - $sensei_modules_loop['total'] = 0; |
|
| 2093 | - $sensei_modules_loop['modules'] = array(); |
|
| 2094 | - $sensei_modules_loop['current'] = -1; |
|
| 2091 | + //reset all of the modules loop variables |
|
| 2092 | + $sensei_modules_loop['total'] = 0; |
|
| 2093 | + $sensei_modules_loop['modules'] = array(); |
|
| 2094 | + $sensei_modules_loop['current'] = -1; |
|
| 2095 | 2095 | |
| 2096 | - // set the current course to be the global post again |
|
| 2097 | - wp_reset_query(); |
|
| 2098 | - $post = $wp_query->post; |
|
| 2099 | - }// end teardown_single_course_module_loop |
|
| 2096 | + // set the current course to be the global post again |
|
| 2097 | + wp_reset_query(); |
|
| 2098 | + $post = $wp_query->post; |
|
| 2099 | + }// end teardown_single_course_module_loop |
|
| 2100 | 2100 | |
| 2101 | 2101 | } // end modules class |