@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | if ( current_user_can( 'manage_sensei_grades' ) ) { |
| 57 | 57 | |
| 58 | - add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'), __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) ); |
|
| 58 | + add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'), __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) ); |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | 'analysis-lesson' |
| 106 | 106 | ); |
| 107 | 107 | foreach ( $classes_to_load as $class_file ) { |
| 108 | - Sensei()->load_class( $class_file ); |
|
| 108 | + Sensei()->load_class( $class_file ); |
|
| 109 | 109 | } // End For Loop |
| 110 | 110 | } // End load_data_table_files() |
| 111 | 111 | |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | |
| 444 | 444 | $user_id = intval( $_GET['user_id'] ); |
| 445 | 445 | $url = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $user_id ), admin_url( 'admin.php' ) ) ); |
| 446 | - $user_name = Sensei_Student::get_full_name( $user_id ); |
|
| 446 | + $user_name = Sensei_Student::get_full_name( $user_id ); |
|
| 447 | 447 | $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name ); |
| 448 | 448 | |
| 449 | 449 | } // End If Statement |
@@ -464,8 +464,8 @@ discard block |
||
| 464 | 464 | $user_id = intval( $_GET['user_id'] ); |
| 465 | 465 | $user_data = get_userdata( $user_id ); |
| 466 | 466 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $user_id ), admin_url( 'admin.php' ) ); |
| 467 | - $user_name = Sensei_Student::get_full_name( $user_id ); |
|
| 468 | - $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name ); |
|
| 467 | + $user_name = Sensei_Student::get_full_name( $user_id ); |
|
| 468 | + $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name ); |
|
| 469 | 469 | $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', esc_url( $url ), $user_data->display_name ); |
| 470 | 470 | } // End If Statement |
| 471 | 471 | if ( isset( $_GET['course_id'] ) ) { |
@@ -79,17 +79,17 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | // Load Learners JS |
| 81 | 81 | wp_enqueue_script( 'sensei-learners-general', |
| 82 | - Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
| 83 | - array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
| 82 | + Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
| 83 | + array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
| 84 | 84 | |
| 85 | 85 | $data = array( |
| 86 | 86 | 'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ), |
| 87 | 87 | 'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ), |
| 88 | 88 | 'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ), |
| 89 | - 'remove_from_purchased_course_confirm' => __( 'Are you sure you want to remove the user from this course? This order associate with this will also be set to canceled.', 'woothemes-sensei' ), |
|
| 89 | + 'remove_from_purchased_course_confirm' => __( 'Are you sure you want to remove the user from this course? This order associate with this will also be set to canceled.', 'woothemes-sensei' ), |
|
| 90 | 90 | 'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ), |
| 91 | - 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
| 92 | - 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
| 91 | + 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
| 92 | + 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data ); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $user_id = intval( $action_data['user_id'] ); |
| 275 | 275 | $post_id = intval( $action_data['post_id'] ); |
| 276 | 276 | $post_type = sanitize_text_field( $action_data['post_type'] ); |
| 277 | - $order_id = sanitize_text_field( $action_data['order_id'] ); |
|
| 277 | + $order_id = sanitize_text_field( $action_data['order_id'] ); |
|
| 278 | 278 | |
| 279 | 279 | $user = get_userdata( $user_id ); |
| 280 | 280 | |
@@ -283,15 +283,15 @@ discard block |
||
| 283 | 283 | case 'course': |
| 284 | 284 | $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
| 285 | 285 | |
| 286 | - if( ! empty( $order_id ) && Sensei_WC::is_woocommerce_active() ){ |
|
| 286 | + if( ! empty( $order_id ) && Sensei_WC::is_woocommerce_active() ){ |
|
| 287 | 287 | |
| 288 | - $order = new WC_Order($order_id); |
|
| 288 | + $order = new WC_Order($order_id); |
|
| 289 | 289 | |
| 290 | - if (!empty($order)) { |
|
| 291 | - $order->update_status( 'cancelled' ); |
|
| 292 | - } |
|
| 290 | + if (!empty($order)) { |
|
| 291 | + $order->update_status( 'cancelled' ); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - } |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | 296 | break; |
| 297 | 297 | |
@@ -336,19 +336,19 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | if ( $users ) { |
| 338 | 338 | foreach ( $users as $user ) { |
| 339 | - $full_name = Sensei_Student::get_full_name( $user->ID ); |
|
| 339 | + $full_name = Sensei_Student::get_full_name( $user->ID ); |
|
| 340 | 340 | |
| 341 | - if( trim($user->display_name ) == trim( $full_name ) ){ |
|
| 341 | + if( trim($user->display_name ) == trim( $full_name ) ){ |
|
| 342 | 342 | |
| 343 | - $name = $full_name; |
|
| 343 | + $name = $full_name; |
|
| 344 | 344 | |
| 345 | - }else{ |
|
| 345 | + }else{ |
|
| 346 | 346 | |
| 347 | - $name = $full_name . ' ['. $user->display_name .']'; |
|
| 347 | + $name = $full_name . ' ['. $user->display_name .']'; |
|
| 348 | 348 | |
| 349 | - } |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
| 351 | + $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | break; |
| 393 | 393 | |
| 394 | 394 | case 'lesson': |
| 395 | - $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
| 395 | + $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
| 396 | 396 | $complete = false; |
| 397 | 397 | if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) { |
| 398 | 398 | $complete = true; |
@@ -452,23 +452,23 @@ discard block |
||
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - /** |
|
| 456 | - * Return the full name and surname or the display name of the user. |
|
| 457 | - * |
|
| 458 | - * The user must have both name and surname otherwise display name will be returned. |
|
| 459 | - * |
|
| 460 | - * @deprecated since 1.9.0 use Se |
|
| 461 | - * @since 1.8.0 |
|
| 462 | - * |
|
| 463 | - * @param int $user_id | bool false for an invalid $user_id |
|
| 464 | - * |
|
| 465 | - * @return string $full_name |
|
| 466 | - */ |
|
| 467 | - public function get_learner_full_name( $user_id ){ |
|
| 468 | - |
|
| 469 | - return Sensei_Student::get_full_name( $user_id ); |
|
| 470 | - |
|
| 471 | - } // end get_learner_full_name |
|
| 455 | + /** |
|
| 456 | + * Return the full name and surname or the display name of the user. |
|
| 457 | + * |
|
| 458 | + * The user must have both name and surname otherwise display name will be returned. |
|
| 459 | + * |
|
| 460 | + * @deprecated since 1.9.0 use Se |
|
| 461 | + * @since 1.8.0 |
|
| 462 | + * |
|
| 463 | + * @param int $user_id | bool false for an invalid $user_id |
|
| 464 | + * |
|
| 465 | + * @return string $full_name |
|
| 466 | + */ |
|
| 467 | + public function get_learner_full_name( $user_id ){ |
|
| 468 | + |
|
| 469 | + return Sensei_Student::get_full_name( $user_id ); |
|
| 470 | + |
|
| 471 | + } // end get_learner_full_name |
|
| 472 | 472 | |
| 473 | 473 | } // End Class |
| 474 | 474 | |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | * @since 1.4.0 |
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Learner_Profiles { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - private $profile_url_base; |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + private $profile_url_base; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Constructor. |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | if( isset( $wp_query->query_vars['learner_profile'] ) ) { |
| 64 | 64 | $learner_user = get_user_by( 'login', $wp_query->query_vars['learner_profile'] ); |
| 65 | 65 | |
| 66 | - $name = Sensei_Student::get_full_name( $learner_user->ID ); |
|
| 66 | + $name = Sensei_Student::get_full_name( $learner_user->ID ); |
|
| 67 | 67 | |
| 68 | 68 | $title = apply_filters( 'sensei_learner_profile_courses_heading', sprintf( __( 'Courses %s is taking', 'woothemes-sensei' ), $name ) ) . ' ' . $sep . ' '; |
| 69 | 69 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | if( isset( $wp_query->query_vars['learner_profile'] ) ) { |
| 113 | 113 | |
| 114 | - Sensei_Templates::get_template( 'learner-profile/learner-info.php' ); |
|
| 114 | + Sensei_Templates::get_template( 'learner-profile/learner-info.php' ); |
|
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -141,43 +141,43 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public static function user_info( $user ) { |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * This hooke fires inside the Sensei_Learner_Profiles::user_info function. |
|
| 146 | - * just before the htmls is generated. |
|
| 147 | - * @since 1.0.0 |
|
| 148 | - */ |
|
| 149 | - do_action( 'sensei_learner_profile_info', $user ); |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * This filter runs inside the Sensei_Learner_Profiles::user_info function. |
|
| 153 | - * Here you can change the user avatar. |
|
| 154 | - * |
|
| 155 | - * @since 1.0.0 |
|
| 156 | - * |
|
| 157 | - * @param false|string `<img>` $user_avatar |
|
| 158 | - */ |
|
| 144 | + /** |
|
| 145 | + * This hooke fires inside the Sensei_Learner_Profiles::user_info function. |
|
| 146 | + * just before the htmls is generated. |
|
| 147 | + * @since 1.0.0 |
|
| 148 | + */ |
|
| 149 | + do_action( 'sensei_learner_profile_info', $user ); |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * This filter runs inside the Sensei_Learner_Profiles::user_info function. |
|
| 153 | + * Here you can change the user avatar. |
|
| 154 | + * |
|
| 155 | + * @since 1.0.0 |
|
| 156 | + * |
|
| 157 | + * @param false|string `<img>` $user_avatar |
|
| 158 | + */ |
|
| 159 | 159 | $learner_avatar = apply_filters( 'sensei_learner_profile_info_avatar', get_avatar( $user->ID, 120 ), $user->ID ); |
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * This filter runs inside the Sensei_Learner_Profiles::user_info function. |
|
| 163 | - * Here you can change the learner profile user display name. |
|
| 164 | - * @since 1.0.0 |
|
| 165 | - * |
|
| 166 | - * @param string $user_display_name |
|
| 167 | - * @param string $user_id |
|
| 168 | - */ |
|
| 161 | + /** |
|
| 162 | + * This filter runs inside the Sensei_Learner_Profiles::user_info function. |
|
| 163 | + * Here you can change the learner profile user display name. |
|
| 164 | + * @since 1.0.0 |
|
| 165 | + * |
|
| 166 | + * @param string $user_display_name |
|
| 167 | + * @param string $user_id |
|
| 168 | + */ |
|
| 169 | 169 | $learner_name = apply_filters( 'sensei_learner_profile_info_name', $user->display_name, $user->ID ); |
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * This filter runs inside the Sensei_Learner_Profiles::user_info function. |
|
| 173 | - * With this filter can change the users description on the learner user info |
|
| 174 | - * output. |
|
| 175 | - * |
|
| 176 | - * @since 1.0.0 |
|
| 177 | - * |
|
| 178 | - * @param string $user_description |
|
| 179 | - * @param string $user_id |
|
| 180 | - */ |
|
| 171 | + /** |
|
| 172 | + * This filter runs inside the Sensei_Learner_Profiles::user_info function. |
|
| 173 | + * With this filter can change the users description on the learner user info |
|
| 174 | + * output. |
|
| 175 | + * |
|
| 176 | + * @since 1.0.0 |
|
| 177 | + * |
|
| 178 | + * @param string $user_description |
|
| 179 | + * @param string $user_id |
|
| 180 | + */ |
|
| 181 | 181 | $learner_bio = apply_filters( 'sensei_learner_profile_info_bio', $user->description, $user->ID ); |
| 182 | 182 | ?> |
| 183 | 183 | |
@@ -211,16 +211,16 @@ discard block |
||
| 211 | 211 | return $classes; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Deprecate the deprecate_sensei_learner_profile_content hook |
|
| 216 | - * |
|
| 217 | - * @since 1.9.0 |
|
| 218 | - */ |
|
| 219 | - public static function deprecate_sensei_learner_profile_content_hook(){ |
|
| 214 | + /** |
|
| 215 | + * Deprecate the deprecate_sensei_learner_profile_content hook |
|
| 216 | + * |
|
| 217 | + * @since 1.9.0 |
|
| 218 | + */ |
|
| 219 | + public static function deprecate_sensei_learner_profile_content_hook(){ |
|
| 220 | 220 | |
| 221 | - sensei_do_deprecated_action( 'sensei_learner_profile_content', '1.9.0', 'sensei_learner_profile_content_before' ); |
|
| 221 | + sensei_do_deprecated_action( 'sensei_learner_profile_content', '1.9.0', 'sensei_learner_profile_content_before' ); |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | 226 | } // End Class |
@@ -234,9 +234,9 @@ |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Output users data |
| 237 | - $user_name = Sensei_Student::get_full_name( $item->user_id ); |
|
| 237 | + $user_name = Sensei_Student::get_full_name( $item->user_id ); |
|
| 238 | 238 | |
| 239 | - if ( !$this->csv_output ) { |
|
| 239 | + if ( !$this->csv_output ) { |
|
| 240 | 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 | 242 | $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $user_name . '</a></strong>'; |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @since 1.0.0 |
| 22 | 22 | */ |
| 23 | 23 | public function __construct () { |
| 24 | - $this->token = 'question'; |
|
| 24 | + $this->token = 'question'; |
|
| 25 | 25 | $this->question_types = $this->question_types(); |
| 26 | 26 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
| 27 | 27 | if ( is_admin() ) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | if( isset( $post->ID ) ) { |
| 120 | 120 | |
| 121 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 121 | + $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 122 | 122 | |
| 123 | 123 | if( $question_type ) { |
| 124 | 124 | $type = $this->question_types[ $question_type ]; |
@@ -238,15 +238,15 @@ discard block |
||
| 238 | 238 | public function save_question( $post_id = 0 ) { |
| 239 | 239 | |
| 240 | 240 | if( ! isset( $_POST['post_type'] |
| 241 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 242 | - return; |
|
| 243 | - } |
|
| 241 | + ) || 'question' != $_POST['post_type'] ) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | |
| 247 | - //setup the data for saving |
|
| 247 | + //setup the data for saving |
|
| 248 | 248 | $data = $_POST ; |
| 249 | - $data['quiz_id'] = 0; |
|
| 249 | + $data['quiz_id'] = 0; |
|
| 250 | 250 | $data['question_id'] = $post_id; |
| 251 | 251 | |
| 252 | 252 | if ( ! wp_is_post_revision( $post_id ) ){ |
@@ -340,34 +340,34 @@ discard block |
||
| 340 | 340 | return $request; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * Get the type of question by id |
|
| 345 | - * |
|
| 346 | - * This function uses the post terms to determine which question type |
|
| 347 | - * the passed question id belongs to. |
|
| 348 | - * |
|
| 349 | - * @since 1.7.4 |
|
| 350 | - * |
|
| 351 | - * @param int $question_id |
|
| 352 | - * |
|
| 353 | - * @return string $question_type | bool |
|
| 354 | - */ |
|
| 355 | - public function get_question_type( $question_id ){ |
|
| 356 | - |
|
| 357 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 358 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 359 | - return false; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - $question_type = 'multiple-choice'; |
|
| 363 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 364 | - foreach( $question_types as $type ) { |
|
| 365 | - $question_type = $type->slug; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $question_type; |
|
| 369 | - |
|
| 370 | - }// end get_question_type |
|
| 343 | + /** |
|
| 344 | + * Get the type of question by id |
|
| 345 | + * |
|
| 346 | + * This function uses the post terms to determine which question type |
|
| 347 | + * the passed question id belongs to. |
|
| 348 | + * |
|
| 349 | + * @since 1.7.4 |
|
| 350 | + * |
|
| 351 | + * @param int $question_id |
|
| 352 | + * |
|
| 353 | + * @return string $question_type | bool |
|
| 354 | + */ |
|
| 355 | + public function get_question_type( $question_id ){ |
|
| 356 | + |
|
| 357 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 358 | + || 'question' != get_post_type( $question_id ) ){ |
|
| 359 | + return false; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + $question_type = 'multiple-choice'; |
|
| 363 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 364 | + foreach( $question_types as $type ) { |
|
| 365 | + $question_type = $type->slug; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $question_type; |
|
| 369 | + |
|
| 370 | + }// end get_question_type |
|
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | 373 | * Given a question ID, return the grade that can be achieved. |
@@ -399,317 +399,317 @@ discard block |
||
| 399 | 399 | } // end get_question_grade |
| 400 | 400 | |
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * This function simply loads the question type template |
|
| 404 | - * |
|
| 405 | - * @since 1.9.0 |
|
| 406 | - * @param $question_type |
|
| 407 | - */ |
|
| 408 | - public static function load_question_template( $question_type ){ |
|
| 409 | - |
|
| 410 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Echo the sensei question title. |
|
| 415 | - * |
|
| 416 | - * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 417 | - * |
|
| 418 | - * @since 1.9.0 |
|
| 419 | - * @param $question_id |
|
| 420 | - */ |
|
| 421 | - public static function the_question_title( $question_id ){ |
|
| 422 | - |
|
| 423 | - echo self::get_the_question_title( $question_id ); |
|
| 424 | - |
|
| 425 | - }// end the_question_title |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Generate the question title with it's grade. |
|
| 429 | - * |
|
| 430 | - * @since 1.9.0 |
|
| 431 | - * |
|
| 432 | - * @param $question_id |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - public static function get_the_question_title( $question_id ){ |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Filter the sensei question title |
|
| 439 | - * |
|
| 440 | - * @since 1.3.0 |
|
| 441 | - * @param $question_title |
|
| 442 | - */ |
|
| 443 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * hook document in class-woothemes-sensei-message.php the_title() |
|
| 447 | - */ |
|
| 448 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 449 | - |
|
| 450 | - $title_html = '<span class="question question-title">'; |
|
| 451 | - $title_html .= $title; |
|
| 452 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 453 | - $title_html .='</span>'; |
|
| 454 | - |
|
| 455 | - return $title_html; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Tech the question description |
|
| 460 | - * |
|
| 461 | - * @param $question_id |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 464 | - public static function get_the_question_description( $question_id ){ |
|
| 465 | - |
|
| 466 | - $question = get_post( $question_id ); |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Already documented within WordPress Core |
|
| 470 | - */ |
|
| 471 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 472 | - |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Output the question description |
|
| 477 | - * |
|
| 478 | - * @since 1.9.0 |
|
| 479 | - * @param $question_id |
|
| 480 | - */ |
|
| 481 | - public static function the_question_description( $question_id ){ |
|
| 482 | - |
|
| 483 | - echo self::get_the_question_description( $question_id ); |
|
| 484 | - |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Get the questions media markup |
|
| 489 | - * |
|
| 490 | - * @since 1.9.0 |
|
| 491 | - * @param $question_id |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public static function get_the_question_media( $question_id ){ |
|
| 495 | - |
|
| 496 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 497 | - $question_media_link = ''; |
|
| 498 | - if( 0 < intval( $question_media ) ) { |
|
| 499 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 500 | - if( $mimetype ) { |
|
| 501 | - $mimetype_array = explode( '/', $mimetype); |
|
| 502 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 503 | - $question_media_type = $mimetype_array[0]; |
|
| 504 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 505 | - $attachment = get_post( $question_media ); |
|
| 506 | - $question_media_title = $attachment->post_title; |
|
| 507 | - $question_media_description = $attachment->post_content; |
|
| 508 | - switch( $question_media_type ) { |
|
| 509 | - case 'image': |
|
| 510 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 511 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 512 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 513 | - break; |
|
| 514 | - |
|
| 515 | - case 'audio': |
|
| 516 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 517 | - break; |
|
| 518 | - |
|
| 519 | - case 'video': |
|
| 520 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 521 | - break; |
|
| 522 | - |
|
| 523 | - default: |
|
| 524 | - $question_media_filename = basename( $question_media_url ); |
|
| 525 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 526 | - break; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $output = ''; |
|
| 533 | - if( $question_media_link ) { |
|
| 534 | - |
|
| 535 | - $output .= '<div class="question_media_display">'; |
|
| 536 | - $output .= $question_media_link; |
|
| 537 | - $output .= '<dl>'; |
|
| 538 | - |
|
| 539 | - if( $question_media_title ) { |
|
| 540 | - |
|
| 541 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 542 | - |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if( $question_media_description ) { |
|
| 546 | - |
|
| 547 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 548 | - |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $output .= '</dl>'; |
|
| 552 | - $output .= '</div>'; |
|
| 402 | + /** |
|
| 403 | + * This function simply loads the question type template |
|
| 404 | + * |
|
| 405 | + * @since 1.9.0 |
|
| 406 | + * @param $question_type |
|
| 407 | + */ |
|
| 408 | + public static function load_question_template( $question_type ){ |
|
| 409 | + |
|
| 410 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Echo the sensei question title. |
|
| 415 | + * |
|
| 416 | + * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 417 | + * |
|
| 418 | + * @since 1.9.0 |
|
| 419 | + * @param $question_id |
|
| 420 | + */ |
|
| 421 | + public static function the_question_title( $question_id ){ |
|
| 422 | + |
|
| 423 | + echo self::get_the_question_title( $question_id ); |
|
| 424 | + |
|
| 425 | + }// end the_question_title |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Generate the question title with it's grade. |
|
| 429 | + * |
|
| 430 | + * @since 1.9.0 |
|
| 431 | + * |
|
| 432 | + * @param $question_id |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + public static function get_the_question_title( $question_id ){ |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Filter the sensei question title |
|
| 439 | + * |
|
| 440 | + * @since 1.3.0 |
|
| 441 | + * @param $question_title |
|
| 442 | + */ |
|
| 443 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * hook document in class-woothemes-sensei-message.php the_title() |
|
| 447 | + */ |
|
| 448 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 449 | + |
|
| 450 | + $title_html = '<span class="question question-title">'; |
|
| 451 | + $title_html .= $title; |
|
| 452 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 453 | + $title_html .='</span>'; |
|
| 454 | + |
|
| 455 | + return $title_html; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Tech the question description |
|
| 460 | + * |
|
| 461 | + * @param $question_id |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | + public static function get_the_question_description( $question_id ){ |
|
| 465 | + |
|
| 466 | + $question = get_post( $question_id ); |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Already documented within WordPress Core |
|
| 470 | + */ |
|
| 471 | + return apply_filters( 'the_content', $question->post_content ); |
|
| 472 | + |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Output the question description |
|
| 477 | + * |
|
| 478 | + * @since 1.9.0 |
|
| 479 | + * @param $question_id |
|
| 480 | + */ |
|
| 481 | + public static function the_question_description( $question_id ){ |
|
| 482 | + |
|
| 483 | + echo self::get_the_question_description( $question_id ); |
|
| 484 | + |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Get the questions media markup |
|
| 489 | + * |
|
| 490 | + * @since 1.9.0 |
|
| 491 | + * @param $question_id |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public static function get_the_question_media( $question_id ){ |
|
| 495 | + |
|
| 496 | + $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 497 | + $question_media_link = ''; |
|
| 498 | + if( 0 < intval( $question_media ) ) { |
|
| 499 | + $mimetype = get_post_mime_type( $question_media ); |
|
| 500 | + if( $mimetype ) { |
|
| 501 | + $mimetype_array = explode( '/', $mimetype); |
|
| 502 | + if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 503 | + $question_media_type = $mimetype_array[0]; |
|
| 504 | + $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 505 | + $attachment = get_post( $question_media ); |
|
| 506 | + $question_media_title = $attachment->post_title; |
|
| 507 | + $question_media_description = $attachment->post_content; |
|
| 508 | + switch( $question_media_type ) { |
|
| 509 | + case 'image': |
|
| 510 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 511 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 512 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 513 | + break; |
|
| 514 | + |
|
| 515 | + case 'audio': |
|
| 516 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 517 | + break; |
|
| 518 | + |
|
| 519 | + case 'video': |
|
| 520 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 521 | + break; |
|
| 522 | + |
|
| 523 | + default: |
|
| 524 | + $question_media_filename = basename( $question_media_url ); |
|
| 525 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 526 | + break; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $output = ''; |
|
| 533 | + if( $question_media_link ) { |
|
| 553 | 534 | |
| 535 | + $output .= '<div class="question_media_display">'; |
|
| 536 | + $output .= $question_media_link; |
|
| 537 | + $output .= '<dl>'; |
|
| 554 | 538 | |
| 555 | - } |
|
| 556 | - |
|
| 557 | - return $output; |
|
| 558 | - |
|
| 559 | - } // end get_the_question_media |
|
| 560 | - |
|
| 539 | + if( $question_media_title ) { |
|
| 561 | 540 | |
| 562 | - /** |
|
| 563 | - * Output the question media |
|
| 564 | - * |
|
| 565 | - * @since 1.9.0 |
|
| 566 | - * @param string $question_id |
|
| 567 | - */ |
|
| 568 | - public static function the_question_media( $question_id ){ |
|
| 541 | + $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 569 | 542 | |
| 570 | - echo self::get_the_question_media( $question_id ); |
|
| 543 | + } |
|
| 571 | 544 | |
| 572 | - } |
|
| 545 | + if( $question_media_description ) { |
|
| 573 | 546 | |
| 574 | - /** |
|
| 575 | - * Output a special field for the question needed for question submission. |
|
| 576 | - * |
|
| 577 | - * @since 1.9.0 |
|
| 578 | - * |
|
| 579 | - * @param $question_id |
|
| 580 | - */ |
|
| 581 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 582 | - ?> |
|
| 547 | + $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 548 | + |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $output .= '</dl>'; |
|
| 552 | + $output .= '</div>'; |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return $output; |
|
| 558 | + |
|
| 559 | + } // end get_the_question_media |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Output the question media |
|
| 564 | + * |
|
| 565 | + * @since 1.9.0 |
|
| 566 | + * @param string $question_id |
|
| 567 | + */ |
|
| 568 | + public static function the_question_media( $question_id ){ |
|
| 569 | + |
|
| 570 | + echo self::get_the_question_media( $question_id ); |
|
| 571 | + |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Output a special field for the question needed for question submission. |
|
| 576 | + * |
|
| 577 | + * @since 1.9.0 |
|
| 578 | + * |
|
| 579 | + * @param $question_id |
|
| 580 | + */ |
|
| 581 | + public static function the_question_hidden_fields( $question_id ){ |
|
| 582 | + ?> |
|
| 583 | 583 | |
| 584 | 584 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
| 585 | 585 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
| 586 | 586 | |
| 587 | 587 | <?php |
| 588 | - } |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - /** |
|
| 591 | - * This function can only be run withing the single quiz question loop |
|
| 592 | - * |
|
| 593 | - * @since 1.9.0 |
|
| 594 | - * @param $question_id |
|
| 595 | - */ |
|
| 596 | - public static function answer_feedback_notes( $question_id ){ |
|
| 590 | + /** |
|
| 591 | + * This function can only be run withing the single quiz question loop |
|
| 592 | + * |
|
| 593 | + * @since 1.9.0 |
|
| 594 | + * @param $question_id |
|
| 595 | + */ |
|
| 596 | + public static function answer_feedback_notes( $question_id ){ |
|
| 597 | 597 | |
| 598 | - //IDS |
|
| 599 | - $quiz_id = get_the_ID(); |
|
| 600 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 598 | + //IDS |
|
| 599 | + $quiz_id = get_the_ID(); |
|
| 600 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 601 | 601 | |
| 602 | - // Data to check before showing feedback |
|
| 603 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 604 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 605 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 606 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 607 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 608 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 602 | + // Data to check before showing feedback |
|
| 603 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 604 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 605 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 606 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 607 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 608 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 609 | 609 | |
| 610 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 611 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 612 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 610 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 611 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 612 | + || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 613 | 613 | |
| 614 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 614 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 615 | 615 | |
| 616 | - if( $answer_notes ) { ?> |
|
| 616 | + if( $answer_notes ) { ?> |
|
| 617 | 617 | |
| 618 | 618 | <div class="sensei-message info info-special answer-feedback"> |
| 619 | 619 | |
| 620 | 620 | <?php |
| 621 | 621 | |
| 622 | - /** |
|
| 623 | - * Filter the answer feedback |
|
| 624 | - * Since 1.9.0 |
|
| 625 | - * |
|
| 626 | - * @param string $answer_notes |
|
| 627 | - * @param string $question_id |
|
| 628 | - * @param string $lesson_id |
|
| 629 | - */ |
|
| 630 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 622 | + /** |
|
| 623 | + * Filter the answer feedback |
|
| 624 | + * Since 1.9.0 |
|
| 625 | + * |
|
| 626 | + * @param string $answer_notes |
|
| 627 | + * @param string $question_id |
|
| 628 | + * @param string $lesson_id |
|
| 629 | + */ |
|
| 630 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 631 | 631 | |
| 632 | - ?> |
|
| 632 | + ?> |
|
| 633 | 633 | |
| 634 | 634 | </div> |
| 635 | 635 | |
| 636 | 636 | <?php } |
| 637 | 637 | |
| 638 | - }// end if we can show answer feedback |
|
| 638 | + }// end if we can show answer feedback |
|
| 639 | 639 | |
| 640 | - }// end answer_feedback_notes |
|
| 640 | + }// end answer_feedback_notes |
|
| 641 | 641 | |
| 642 | - /** |
|
| 643 | - * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 644 | - * |
|
| 645 | - * |
|
| 646 | - * @since 1.9.0 |
|
| 647 | - * @param string $question_id |
|
| 648 | - */ |
|
| 649 | - public static function the_answer_result_indication( $question_id ){ |
|
| 642 | + /** |
|
| 643 | + * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 644 | + * |
|
| 645 | + * |
|
| 646 | + * @since 1.9.0 |
|
| 647 | + * @param string $question_id |
|
| 648 | + */ |
|
| 649 | + public static function the_answer_result_indication( $question_id ){ |
|
| 650 | 650 | |
| 651 | - global $post, $current_user, $sensei_question_loop; |
|
| 651 | + global $post, $current_user, $sensei_question_loop; |
|
| 652 | 652 | |
| 653 | - // Post Data |
|
| 654 | - $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 655 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 656 | - $question_item = $sensei_question_loop['current_question']; |
|
| 653 | + // Post Data |
|
| 654 | + $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 655 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 656 | + $question_item = $sensei_question_loop['current_question']; |
|
| 657 | 657 | |
| 658 | - // Setup variable needed to determine if the message should show and what it should show |
|
| 659 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 660 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 661 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 662 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 658 | + // Setup variable needed to determine if the message should show and what it should show |
|
| 659 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 660 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 661 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 662 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 663 | 663 | |
| 664 | - // retrieve the question total grade |
|
| 665 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 664 | + // retrieve the question total grade |
|
| 665 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 666 | 666 | |
| 667 | - // retrieve grade the user achieved |
|
| 668 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 667 | + // retrieve grade the user achieved |
|
| 668 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 669 | 669 | |
| 670 | - // Question ID |
|
| 671 | - $question_id = $question_item->ID; |
|
| 670 | + // Question ID |
|
| 671 | + $question_id = $question_item->ID; |
|
| 672 | 672 | |
| 673 | - // conditions to check |
|
| 674 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 675 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 676 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 673 | + // conditions to check |
|
| 674 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 675 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 676 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 677 | 677 | |
| 678 | - if ( $completed_with_valid_grade |
|
| 679 | - || $completed_with_valid_grade_and_reset_not_allowed |
|
| 680 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 678 | + if ( $completed_with_valid_grade |
|
| 679 | + || $completed_with_valid_grade_and_reset_not_allowed |
|
| 680 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 681 | 681 | |
| 682 | - $user_correct = false; |
|
| 683 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 684 | - $answer_message_class = 'user_wrong'; |
|
| 685 | - // For zero grade mark as 'correct' but add no classes |
|
| 686 | - if ( 0 == $question_grade ) { |
|
| 682 | + $user_correct = false; |
|
| 683 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 684 | + $answer_message_class = 'user_wrong'; |
|
| 685 | + // For zero grade mark as 'correct' but add no classes |
|
| 686 | + if ( 0 == $question_grade ) { |
|
| 687 | 687 | |
| 688 | - $user_correct = true; |
|
| 689 | - $answer_message = ''; |
|
| 690 | - $answer_message_class = ''; |
|
| 688 | + $user_correct = true; |
|
| 689 | + $answer_message = ''; |
|
| 690 | + $answer_message_class = ''; |
|
| 691 | 691 | |
| 692 | - } else if( $user_question_grade > 0 ) { |
|
| 692 | + } else if( $user_question_grade > 0 ) { |
|
| 693 | 693 | |
| 694 | - $user_correct = true; |
|
| 695 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 696 | - $answer_message_class = 'user_right'; |
|
| 694 | + $user_correct = true; |
|
| 695 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 696 | + $answer_message_class = 'user_right'; |
|
| 697 | 697 | |
| 698 | - } |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 701 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 700 | + // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 701 | + if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 702 | 702 | |
| 703 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 703 | + $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - // answer feedback |
|
| 708 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 709 | - if( $answer_notes ) { |
|
| 710 | - $answer_message_class .= ' has_notes'; |
|
| 711 | - } |
|
| 712 | - ?> |
|
| 707 | + // answer feedback |
|
| 708 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 709 | + if( $answer_notes ) { |
|
| 710 | + $answer_message_class .= ' has_notes'; |
|
| 711 | + } |
|
| 712 | + ?> |
|
| 713 | 713 | |
| 714 | 714 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
| 715 | 715 | |
@@ -719,387 +719,387 @@ discard block |
||
| 719 | 719 | |
| 720 | 720 | <?php |
| 721 | 721 | |
| 722 | - } // end if user can see all the goodies |
|
| 723 | - |
|
| 724 | - }// end the_answer_result_indication |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * Generate the question template data and return it as an array. |
|
| 728 | - * |
|
| 729 | - * @since 1.9.0 |
|
| 730 | - * |
|
| 731 | - * @param string $question_id |
|
| 732 | - * @param $quiz_id |
|
| 733 | - * @return array $question_data |
|
| 734 | - */ |
|
| 735 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 736 | - |
|
| 737 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 738 | - |
|
| 739 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 740 | - //backwards compatibility |
|
| 741 | - if( 'on' == $reset_allowed ) { |
|
| 742 | - $reset_allowed = 1; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - // Check again that the lesson is complete |
|
| 746 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 747 | - $user_lesson_complete = false; |
|
| 748 | - if ( $user_lesson_end ) { |
|
| 749 | - $user_lesson_complete = true; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - //setup the question data |
|
| 753 | - $data[ 'ID' ] = $question_id; |
|
| 754 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 755 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 756 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 757 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 758 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 759 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 760 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 761 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 762 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 763 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 764 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 765 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 766 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 767 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Filter the question template data. This filter fires in |
|
| 771 | - * the get_template_data function |
|
| 772 | - * |
|
| 773 | - * @hooked self::boolean_load_question_data |
|
| 774 | - * |
|
| 775 | - * @since 1.9.0 |
|
| 776 | - * |
|
| 777 | - * @param array $data |
|
| 778 | - * @param string $question_id |
|
| 779 | - * @param string $quiz_id |
|
| 780 | - */ |
|
| 781 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 722 | + } // end if user can see all the goodies |
|
| 782 | 723 | |
| 783 | - } |
|
| 724 | + }// end the_answer_result_indication |
|
| 784 | 725 | |
| 785 | - /** |
|
| 786 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 787 | - * filter. |
|
| 788 | - * |
|
| 789 | - * @since 1.9.0 |
|
| 790 | - * |
|
| 791 | - * @param $question_data |
|
| 792 | - * @param $question_id |
|
| 793 | - * @param $quiz_id |
|
| 794 | - * |
|
| 795 | - * @return array() |
|
| 796 | - */ |
|
| 797 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 726 | + /** |
|
| 727 | + * Generate the question template data and return it as an array. |
|
| 728 | + * |
|
| 729 | + * @since 1.9.0 |
|
| 730 | + * |
|
| 731 | + * @param string $question_id |
|
| 732 | + * @param $quiz_id |
|
| 733 | + * @return array $question_data |
|
| 734 | + */ |
|
| 735 | + public static function get_template_data( $question_id, $quiz_id ){ |
|
| 798 | 736 | |
| 737 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 799 | 738 | |
| 800 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 739 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 740 | + //backwards compatibility |
|
| 741 | + if( 'on' == $reset_allowed ) { |
|
| 742 | + $reset_allowed = 1; |
|
| 743 | + } |
|
| 801 | 744 | |
| 802 | - // Get uploaded file |
|
| 803 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 804 | - $answer_media_url = $answer_media_filename = ''; |
|
| 745 | + // Check again that the lesson is complete |
|
| 746 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 747 | + $user_lesson_complete = false; |
|
| 748 | + if ( $user_lesson_end ) { |
|
| 749 | + $user_lesson_complete = true; |
|
| 750 | + } |
|
| 805 | 751 | |
| 752 | + //setup the question data |
|
| 753 | + $data[ 'ID' ] = $question_id; |
|
| 754 | + $data[ 'title' ] = get_the_title( $question_id ); |
|
| 755 | + $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 756 | + $data[ 'quiz_id' ] = $quiz_id; |
|
| 757 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 758 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 759 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 760 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 761 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 762 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 763 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 764 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 765 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 766 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 767 | + $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Filter the question template data. This filter fires in |
|
| 771 | + * the get_template_data function |
|
| 772 | + * |
|
| 773 | + * @hooked self::boolean_load_question_data |
|
| 774 | + * |
|
| 775 | + * @since 1.9.0 |
|
| 776 | + * |
|
| 777 | + * @param array $data |
|
| 778 | + * @param string $question_id |
|
| 779 | + * @param string $quiz_id |
|
| 780 | + */ |
|
| 781 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 806 | 782 | |
| 807 | - $question_helptext = ''; |
|
| 808 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 783 | + } |
|
| 809 | 784 | |
| 810 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 785 | + /** |
|
| 786 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 787 | + * filter. |
|
| 788 | + * |
|
| 789 | + * @since 1.9.0 |
|
| 790 | + * |
|
| 791 | + * @param $question_data |
|
| 792 | + * @param $question_id |
|
| 793 | + * @param $quiz_id |
|
| 794 | + * |
|
| 795 | + * @return array() |
|
| 796 | + */ |
|
| 797 | + public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 811 | 798 | |
| 812 | - } |
|
| 813 | 799 | |
| 800 | + if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 814 | 801 | |
| 815 | - if( 0 < intval( $attachment_id ) ) { |
|
| 802 | + // Get uploaded file |
|
| 803 | + $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 804 | + $answer_media_url = $answer_media_filename = ''; |
|
| 816 | 805 | |
| 817 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 818 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 819 | 806 | |
| 820 | - } |
|
| 807 | + $question_helptext = ''; |
|
| 808 | + if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 821 | 809 | |
| 810 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 822 | 811 | |
| 823 | - // Get max upload file size, formatted for display |
|
| 824 | - // Code copied from wp-admin/includes/media.php:1515 |
|
| 825 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 826 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 827 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 828 | - $upload_size_unit /= 1024; |
|
| 829 | - } |
|
| 830 | - if ( $u < 0 ) { |
|
| 812 | + } |
|
| 831 | 813 | |
| 832 | - $upload_size_unit = 0; |
|
| 833 | - $u = 0; |
|
| 834 | 814 | |
| 835 | - } else { |
|
| 815 | + if( 0 < intval( $attachment_id ) ) { |
|
| 836 | 816 | |
| 837 | - $upload_size_unit = (int) $upload_size_unit; |
|
| 817 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 818 | + $answer_media_filename = basename( $answer_media_url ); |
|
| 838 | 819 | |
| 839 | - } |
|
| 840 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 820 | + } |
|
| 841 | 821 | |
| 842 | - // Assemble all the data needed by the file upload template |
|
| 843 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 844 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 845 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 846 | 822 | |
| 847 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 823 | + // Get max upload file size, formatted for display |
|
| 824 | + // Code copied from wp-admin/includes/media.php:1515 |
|
| 825 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 826 | + $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 827 | + for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 828 | + $upload_size_unit /= 1024; |
|
| 829 | + } |
|
| 830 | + if ( $u < 0 ) { |
|
| 848 | 831 | |
| 849 | - }// end if is file upload type |
|
| 832 | + $upload_size_unit = 0; |
|
| 833 | + $u = 0; |
|
| 850 | 834 | |
| 851 | - return $question_data; |
|
| 835 | + } else { |
|
| 852 | 836 | |
| 853 | - }// end file_upload_load_question_data |
|
| 837 | + $upload_size_unit = (int) $upload_size_unit; |
|
| 854 | 838 | |
| 855 | - /** |
|
| 856 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 857 | - * filter. |
|
| 858 | - * |
|
| 859 | - * @since 1.9.0 |
|
| 860 | - * |
|
| 861 | - * @param $question_data |
|
| 862 | - * @param $question_id |
|
| 863 | - * @param $quiz_id |
|
| 864 | - * |
|
| 865 | - * @return array() |
|
| 866 | - */ |
|
| 867 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 839 | + } |
|
| 840 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 868 | 841 | |
| 869 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 842 | + // Assemble all the data needed by the file upload template |
|
| 843 | + $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 844 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 845 | + $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 870 | 846 | |
| 847 | + $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 871 | 848 | |
| 872 | - $answer_type = 'radio'; |
|
| 873 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 849 | + }// end if is file upload type |
|
| 874 | 850 | |
| 875 | - $answer_type = 'checkbox'; |
|
| 851 | + return $question_data; |
|
| 876 | 852 | |
| 877 | - } |
|
| 853 | + }// end file_upload_load_question_data |
|
| 878 | 854 | |
| 879 | - // Merge right and wrong answers |
|
| 880 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 855 | + /** |
|
| 856 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 857 | + * filter. |
|
| 858 | + * |
|
| 859 | + * @since 1.9.0 |
|
| 860 | + * |
|
| 861 | + * @param $question_data |
|
| 862 | + * @param $question_id |
|
| 863 | + * @param $quiz_id |
|
| 864 | + * |
|
| 865 | + * @return array() |
|
| 866 | + */ |
|
| 867 | + public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 881 | 868 | |
| 882 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 869 | + if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 883 | 870 | |
| 884 | - } else { |
|
| 885 | 871 | |
| 886 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 887 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 872 | + $answer_type = 'radio'; |
|
| 873 | + if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 888 | 874 | |
| 889 | - } |
|
| 875 | + $answer_type = 'checkbox'; |
|
| 890 | 876 | |
| 891 | - // Setup answer options array. |
|
| 892 | - $question_answers_options = array(); |
|
| 893 | - $count = 0; |
|
| 877 | + } |
|
| 894 | 878 | |
| 895 | - foreach( $merged_options as $answer ) { |
|
| 879 | + // Merge right and wrong answers |
|
| 880 | + if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 896 | 881 | |
| 897 | - $count++; |
|
| 898 | - $question_option = array(); |
|
| 882 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 899 | 883 | |
| 900 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 902 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 884 | + } else { |
|
| 903 | 885 | |
| 904 | - $user_correct = false; |
|
| 886 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 887 | + $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 905 | 888 | |
| 889 | + } |
|
| 906 | 890 | |
| 907 | - // For zero grade mark as 'correct' but add no classes |
|
| 908 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 891 | + // Setup answer options array. |
|
| 892 | + $question_answers_options = array(); |
|
| 893 | + $count = 0; |
|
| 909 | 894 | |
| 910 | - $user_correct = true; |
|
| 895 | + foreach( $merged_options as $answer ) { |
|
| 911 | 896 | |
| 912 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 897 | + $count++; |
|
| 898 | + $question_option = array(); |
|
| 913 | 899 | |
| 914 | - $user_correct = true; |
|
| 900 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 902 | + || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 915 | 903 | |
| 916 | - } |
|
| 904 | + $user_correct = false; |
|
| 917 | 905 | |
| 918 | - } |
|
| 919 | 906 | |
| 920 | - // setup the option specific classes |
|
| 921 | - $answer_class = ''; |
|
| 922 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 923 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 907 | + // For zero grade mark as 'correct' but add no classes |
|
| 908 | + if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 924 | 909 | |
| 925 | - $answer_class .= ' right_answer'; |
|
| 910 | + $user_correct = true; |
|
| 926 | 911 | |
| 927 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 912 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 928 | 913 | |
| 929 | - $answer_class .= ' right_answer'; |
|
| 914 | + $user_correct = true; |
|
| 930 | 915 | |
| 931 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 932 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 916 | + } |
|
| 933 | 917 | |
| 934 | - $answer_class = 'user_wrong'; |
|
| 935 | - if( $user_correct ) { |
|
| 918 | + } |
|
| 936 | 919 | |
| 937 | - $answer_class = 'user_right'; |
|
| 920 | + // setup the option specific classes |
|
| 921 | + $answer_class = ''; |
|
| 922 | + if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 923 | + if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 938 | 924 | |
| 939 | - } |
|
| 925 | + $answer_class .= ' right_answer'; |
|
| 940 | 926 | |
| 941 | - } |
|
| 927 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 942 | 928 | |
| 943 | - } |
|
| 929 | + $answer_class .= ' right_answer'; |
|
| 944 | 930 | |
| 945 | - // determine if the current option must be checked |
|
| 946 | - $checked = ''; |
|
| 947 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 948 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 931 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 932 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 949 | 933 | |
| 950 | - $checked = 'checked="checked"'; |
|
| 934 | + $answer_class = 'user_wrong'; |
|
| 935 | + if( $user_correct ) { |
|
| 951 | 936 | |
| 952 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 937 | + $answer_class = 'user_right'; |
|
| 953 | 938 | |
| 954 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 939 | + } |
|
| 955 | 940 | |
| 956 | - } |
|
| 941 | + } |
|
| 957 | 942 | |
| 958 | - } // End If Statement |
|
| 943 | + } |
|
| 959 | 944 | |
| 960 | - //Load the answer option data |
|
| 961 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 962 | - $question_option[ 'answer' ] = $answer; |
|
| 963 | - $question_option[ 'option_class'] = $answer_class; |
|
| 964 | - $question_option[ 'checked'] = $checked; |
|
| 965 | - $question_option[ 'count' ] = $count; |
|
| 966 | - $question_option[ 'type' ] = $answer_type; |
|
| 945 | + // determine if the current option must be checked |
|
| 946 | + $checked = ''; |
|
| 947 | + if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 948 | + if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 967 | 949 | |
| 968 | - // add the speci fic option to the list of options for this question |
|
| 969 | - $question_answers_options[] = $question_option; |
|
| 950 | + $checked = 'checked="checked"'; |
|
| 970 | 951 | |
| 971 | - } // end for each option |
|
| 952 | + } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 972 | 953 | |
| 954 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 973 | 955 | |
| 974 | - // Shuffle the array depending on the settings |
|
| 975 | - $answer_options_sorted = array(); |
|
| 976 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 977 | - if( $random_order && $random_order == 'yes' ) { |
|
| 956 | + } |
|
| 978 | 957 | |
| 979 | - $answer_options_sorted = $question_answers_options; |
|
| 980 | - shuffle( $answer_options_sorted ); |
|
| 958 | + } // End If Statement |
|
| 981 | 959 | |
| 982 | - } else { |
|
| 960 | + //Load the answer option data |
|
| 961 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 962 | + $question_option[ 'answer' ] = $answer; |
|
| 963 | + $question_option[ 'option_class'] = $answer_class; |
|
| 964 | + $question_option[ 'checked'] = $checked; |
|
| 965 | + $question_option[ 'count' ] = $count; |
|
| 966 | + $question_option[ 'type' ] = $answer_type; |
|
| 983 | 967 | |
| 984 | - $answer_order = array(); |
|
| 985 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 986 | - if( $answer_order_string ) { |
|
| 968 | + // add the speci fic option to the list of options for this question |
|
| 969 | + $question_answers_options[] = $question_option; |
|
| 987 | 970 | |
| 988 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 989 | - if( count( $answer_order ) > 0 ) { |
|
| 971 | + } // end for each option |
|
| 990 | 972 | |
| 991 | - foreach( $answer_order as $answer_id ) { |
|
| 992 | 973 | |
| 993 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 974 | + // Shuffle the array depending on the settings |
|
| 975 | + $answer_options_sorted = array(); |
|
| 976 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 977 | + if( $random_order && $random_order == 'yes' ) { |
|
| 994 | 978 | |
| 995 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 996 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 979 | + $answer_options_sorted = $question_answers_options; |
|
| 980 | + shuffle( $answer_options_sorted ); |
|
| 997 | 981 | |
| 998 | - } |
|
| 982 | + } else { |
|
| 999 | 983 | |
| 1000 | - } |
|
| 984 | + $answer_order = array(); |
|
| 985 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 986 | + if( $answer_order_string ) { |
|
| 1001 | 987 | |
| 1002 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1003 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 988 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 989 | + if( count( $answer_order ) > 0 ) { |
|
| 1004 | 990 | |
| 1005 | - $answer_options_sorted[ $id ] = $answer; |
|
| 991 | + foreach( $answer_order as $answer_id ) { |
|
| 1006 | 992 | |
| 1007 | - } |
|
| 1008 | - } |
|
| 993 | + if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 1009 | 994 | |
| 1010 | - }else{ |
|
| 995 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 996 | + unset( $question_answers_options[ $answer_id ] ); |
|
| 1011 | 997 | |
| 1012 | - $answer_options_sorted = $question_answers_options; |
|
| 998 | + } |
|
| 1013 | 999 | |
| 1014 | - } |
|
| 1000 | + } |
|
| 1015 | 1001 | |
| 1016 | - }else{ |
|
| 1002 | + if( count( $question_answers_options ) > 0 ) { |
|
| 1003 | + foreach( $question_answers_options as $id => $answer ) { |
|
| 1017 | 1004 | |
| 1018 | - $answer_options_sorted = $question_answers_options; |
|
| 1005 | + $answer_options_sorted[ $id ] = $answer; |
|
| 1019 | 1006 | |
| 1020 | - } // end if $answer_order_string |
|
| 1007 | + } |
|
| 1008 | + } |
|
| 1021 | 1009 | |
| 1022 | - } // end if random order |
|
| 1010 | + }else{ |
|
| 1023 | 1011 | |
| 1012 | + $answer_options_sorted = $question_answers_options; |
|
| 1024 | 1013 | |
| 1025 | - // assemble and setup the data for the templates data array |
|
| 1026 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1014 | + } |
|
| 1027 | 1015 | |
| 1028 | - } |
|
| 1016 | + }else{ |
|
| 1029 | 1017 | |
| 1030 | - return $question_data; |
|
| 1018 | + $answer_options_sorted = $question_answers_options; |
|
| 1031 | 1019 | |
| 1032 | - }// end multiple_choice_load_question_data |
|
| 1020 | + } // end if $answer_order_string |
|
| 1033 | 1021 | |
| 1034 | - /** |
|
| 1035 | - * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1036 | - * filter. |
|
| 1037 | - * |
|
| 1038 | - * @since 1.9.0 |
|
| 1039 | - * |
|
| 1040 | - * @param $question_data |
|
| 1041 | - * @param $question_id |
|
| 1042 | - * @param $quiz_id |
|
| 1043 | - * |
|
| 1044 | - * @return array() |
|
| 1045 | - */ |
|
| 1046 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1022 | + } // end if random order |
|
| 1047 | 1023 | |
| 1048 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1049 | 1024 | |
| 1050 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1051 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1052 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1053 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1025 | + // assemble and setup the data for the templates data array |
|
| 1026 | + $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1054 | 1027 | |
| 1055 | - } |
|
| 1028 | + } |
|
| 1056 | 1029 | |
| 1057 | - return $question_data; |
|
| 1030 | + return $question_data; |
|
| 1058 | 1031 | |
| 1059 | - }// end gap_fill_load_question_data |
|
| 1032 | + }// end multiple_choice_load_question_data |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1036 | + * filter. |
|
| 1037 | + * |
|
| 1038 | + * @since 1.9.0 |
|
| 1039 | + * |
|
| 1040 | + * @param $question_data |
|
| 1041 | + * @param $question_id |
|
| 1042 | + * @param $quiz_id |
|
| 1043 | + * |
|
| 1044 | + * @return array() |
|
| 1045 | + */ |
|
| 1046 | + public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1047 | + |
|
| 1048 | + if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1049 | + |
|
| 1050 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1051 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1052 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1053 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1054 | + |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + return $question_data; |
|
| 1058 | + |
|
| 1059 | + }// end gap_fill_load_question_data |
|
| 1060 | 1060 | |
| 1061 | 1061 | |
| 1062 | - /** |
|
| 1063 | - * Get the correct answer for a question |
|
| 1064 | - * |
|
| 1065 | - * @param $question_id |
|
| 1066 | - * @return string $correct_answer or empty |
|
| 1067 | - */ |
|
| 1068 | - public static function get_correct_answer( $question_id ){ |
|
| 1062 | + /** |
|
| 1063 | + * Get the correct answer for a question |
|
| 1064 | + * |
|
| 1065 | + * @param $question_id |
|
| 1066 | + * @return string $correct_answer or empty |
|
| 1067 | + */ |
|
| 1068 | + public static function get_correct_answer( $question_id ){ |
|
| 1069 | 1069 | |
| 1070 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1071 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1072 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1073 | - $grade_type = 'manual-grade'; |
|
| 1070 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1071 | + $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1072 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1073 | + $grade_type = 'manual-grade'; |
|
| 1074 | 1074 | |
| 1075 | - if ('boolean'== $type ) { |
|
| 1075 | + if ('boolean'== $type ) { |
|
| 1076 | 1076 | |
| 1077 | - $right_answer = ucfirst($right_answer); |
|
| 1077 | + $right_answer = ucfirst($right_answer); |
|
| 1078 | 1078 | |
| 1079 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1079 | + }elseif( 'multiple-choice' == $type ) { |
|
| 1080 | 1080 | |
| 1081 | - $right_answer = (array) $right_answer; |
|
| 1082 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1081 | + $right_answer = (array) $right_answer; |
|
| 1082 | + $right_answer = implode( ', ', $right_answer ); |
|
| 1083 | 1083 | |
| 1084 | - }elseif( 'gap-fill' == $type ) { |
|
| 1084 | + }elseif( 'gap-fill' == $type ) { |
|
| 1085 | 1085 | |
| 1086 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1087 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1089 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1086 | + $right_answer_array = explode( '||', $right_answer ); |
|
| 1087 | + if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1088 | + if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1089 | + if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1090 | 1090 | |
| 1091 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1091 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1092 | 1092 | |
| 1093 | - }else{ |
|
| 1093 | + }else{ |
|
| 1094 | 1094 | |
| 1095 | - // for non auto gradable question types no answer should be returned. |
|
| 1096 | - $right_answer = ''; |
|
| 1095 | + // for non auto gradable question types no answer should be returned. |
|
| 1096 | + $right_answer = ''; |
|
| 1097 | 1097 | |
| 1098 | - } |
|
| 1098 | + } |
|
| 1099 | 1099 | |
| 1100 | - return $right_answer; |
|
| 1100 | + return $right_answer; |
|
| 1101 | 1101 | |
| 1102 | - } // get_correct_answer |
|
| 1102 | + } // get_correct_answer |
|
| 1103 | 1103 | |
| 1104 | 1104 | } // End Class |
| 1105 | 1105 | |
@@ -13,21 +13,21 @@ discard block |
||
| 13 | 13 | * @since 1.0.0 |
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course { |
| 16 | - /** |
|
| 17 | - * @var $token |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var $token |
|
| 18 | + */ |
|
| 19 | 19 | public $token; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array $meta_fields |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var array $meta_fields |
|
| 23 | + */ |
|
| 24 | 24 | public $meta_fields; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string|bool $my_courses_page reference to the sites |
|
| 28 | - * my courses page, false if none was set |
|
| 29 | - */ |
|
| 30 | - public $my_courses_page; |
|
| 26 | + /** |
|
| 27 | + * @var string|bool $my_courses_page reference to the sites |
|
| 28 | + * my courses page, false if none was set |
|
| 29 | + */ |
|
| 30 | + public $my_courses_page; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Constructor. |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct () { |
| 37 | 37 | |
| 38 | - $this->token = 'course'; |
|
| 38 | + $this->token = 'course'; |
|
| 39 | 39 | |
| 40 | 40 | // Setup meta fields for this post type |
| 41 | 41 | $this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' ); |
| 42 | 42 | // Admin actions |
| 43 | 43 | if ( is_admin() ) { |
| 44 | 44 | // Metabox functions |
| 45 | - add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 45 | + add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 46 | 46 | add_action( 'save_post', array( $this, 'meta_box_save' ) ); |
| 47 | 47 | // Custom Write Panel Columns |
| 48 | 48 | add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
@@ -58,47 +58,47 @@ discard block |
||
| 58 | 58 | // Update course completion upon grading of a quiz |
| 59 | 59 | add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 ); |
| 60 | 60 | |
| 61 | - // show the progress bar ont he single course page |
|
| 62 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 61 | + // show the progress bar ont he single course page |
|
| 62 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 64 | 64 | |
| 65 | - // provide an option to block all emails related to a selected course |
|
| 66 | - add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | - add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 65 | + // provide an option to block all emails related to a selected course |
|
| 66 | + add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | + add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 68 | 68 | |
| 69 | - // preview lessons on the course content |
|
| 70 | - add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 69 | + // preview lessons on the course content |
|
| 70 | + add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 71 | 71 | |
| 72 | - // the course meta |
|
| 73 | - add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 72 | + // the course meta |
|
| 73 | + add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 74 | 74 | |
| 75 | - // backwards compatible template hooks |
|
| 76 | - add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | - add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 75 | + // backwards compatible template hooks |
|
| 76 | + add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | + add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 78 | 78 | |
| 79 | - // add the user status on the course to the markup as a class |
|
| 80 | - add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 79 | + // add the user status on the course to the markup as a class |
|
| 80 | + add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 81 | 81 | |
| 82 | - //filter the course query in Sensei specific instances |
|
| 83 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 82 | + //filter the course query in Sensei specific instances |
|
| 83 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 84 | 84 | |
| 85 | - //attache the sorting to the course archive |
|
| 86 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 85 | + //attache the sorting to the course archive |
|
| 86 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 87 | 87 | |
| 88 | - //attach the filter links to the course archive |
|
| 89 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 88 | + //attach the filter links to the course archive |
|
| 89 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 90 | 90 | |
| 91 | - //filter the course query when featured filter is applied |
|
| 92 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 91 | + //filter the course query when featured filter is applied |
|
| 92 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 93 | 93 | |
| 94 | - // handle the order by title post submission |
|
| 95 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 94 | + // handle the order by title post submission |
|
| 95 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 96 | 96 | |
| 97 | - // ensure the course category page respects the manual order set for courses |
|
| 98 | - add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 97 | + // ensure the course category page respects the manual order set for courses |
|
| 98 | + add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 99 | 99 | |
| 100 | - // flush rewrite rules when saving a course |
|
| 101 | - add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 100 | + // flush rewrite rules when saving a course |
|
| 101 | + add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 102 | 102 | |
| 103 | 103 | } // End __construct() |
| 104 | 104 | |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 152 | 152 | // Add Meta Box for Course Lessons |
| 153 | 153 | add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 154 | - // Add Meta Box to link to Manage Learners |
|
| 155 | - add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 156 | - // Remove "Custom Settings" meta box. |
|
| 154 | + // Add Meta Box to link to Manage Learners |
|
| 155 | + add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 156 | + // Remove "Custom Settings" meta box. |
|
| 157 | 157 | remove_meta_box( 'woothemes-settings', $this->token, 'normal' ); |
| 158 | 158 | |
| 159 | - // add Disable email notification box |
|
| 160 | - add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 159 | + // add Disable email notification box |
|
| 160 | + add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 161 | 161 | |
| 162 | 162 | } // End meta_box_setup() |
| 163 | 163 | |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | $post_args = array( 'post_type' => array( 'product', 'product_variation' ), |
| 176 | 176 | 'posts_per_page' => -1, |
| 177 | 177 | 'orderby' => 'title', |
| 178 | - 'order' => 'DESC', |
|
| 179 | - 'exclude' => $post->ID, |
|
| 180 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 181 | - 'tax_query' => array( |
|
| 178 | + 'order' => 'DESC', |
|
| 179 | + 'exclude' => $post->ID, |
|
| 180 | + 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 181 | + 'tax_query' => array( |
|
| 182 | 182 | array( |
| 183 | 183 | 'taxonomy' => 'product_type', |
| 184 | 184 | 'field' => 'slug', |
@@ -206,21 +206,21 @@ discard block |
||
| 206 | 206 | $product_object = get_product( $post_item->ID ); |
| 207 | 207 | $parent_id = wp_get_post_parent_id( $post_item->ID ); |
| 208 | 208 | |
| 209 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 209 | + if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 210 | 210 | $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
| 211 | 211 | |
| 212 | 212 | } else { |
| 213 | - // fall back to pre wc 2.1 |
|
| 213 | + // fall back to pre wc 2.1 |
|
| 214 | 214 | $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
| 215 | 215 | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $product_name = ucwords( $formatted_variation ); |
|
| 219 | - if( empty( $product_name ) ){ |
|
| 218 | + $product_name = ucwords( $formatted_variation ); |
|
| 219 | + if( empty( $product_name ) ){ |
|
| 220 | 220 | |
| 221 | - $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 221 | + $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | } else { |
| 226 | 226 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | } else { |
| 272 | 272 | |
| 273 | - $html .= '<p>' . "\n"; |
|
| 273 | + $html .= '<p>' . "\n"; |
|
| 274 | 274 | $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n"; |
| 275 | 275 | $html .= '</p>'."\n"; |
| 276 | 276 | |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | $post_args = array( 'post_type' => 'course', |
| 297 | 297 | 'posts_per_page' => -1, |
| 298 | 298 | 'orderby' => 'title', |
| 299 | - 'order' => 'DESC', |
|
| 300 | - 'exclude' => $post->ID, |
|
| 299 | + 'order' => 'DESC', |
|
| 300 | + 'exclude' => $post->ID, |
|
| 301 | 301 | 'suppress_filters' => 0 |
| 302 | 302 | ); |
| 303 | 303 | $posts_array = get_posts( $post_args ); |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | $checked = ''; |
| 340 | 340 | if ( isset( $course_featured ) && ( '' != $course_featured ) ) { |
| 341 | - $checked = checked( 'featured', $course_featured, false ); |
|
| 341 | + $checked = checked( 'featured', $course_featured, false ); |
|
| 342 | 342 | } // End If Statement |
| 343 | 343 | |
| 344 | 344 | $html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '> ' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>'; |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
| 434 | 434 | } // End If Statement |
| 435 | 435 | |
| 436 | - // update field with the new value |
|
| 437 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 436 | + // update field with the new value |
|
| 437 | + return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 438 | 438 | |
| 439 | 439 | } // End save_post_meta() |
| 440 | 440 | |
@@ -458,8 +458,8 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | $html = ''; |
| 460 | 460 | $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' |
| 461 | - . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | - . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 461 | + . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | + . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 463 | 463 | |
| 464 | 464 | if ( count( $posts_array ) > 0 ) { |
| 465 | 465 | |
@@ -480,8 +480,8 @@ discard block |
||
| 480 | 480 | $html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n"; |
| 481 | 481 | |
| 482 | 482 | $html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id ) |
| 483 | - . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | - . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 483 | + . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | + . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 485 | 485 | |
| 486 | 486 | $html .= '</p>'."\n"; |
| 487 | 487 | } // End If Statement |
@@ -490,29 +490,29 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | } // End course_lessons_meta_box_content() |
| 492 | 492 | |
| 493 | - /** |
|
| 494 | - * course_manage_meta_box_content function. |
|
| 495 | - * |
|
| 496 | - * @since 1.9.0 |
|
| 497 | - * @access public |
|
| 498 | - * @return void |
|
| 499 | - */ |
|
| 493 | + /** |
|
| 494 | + * course_manage_meta_box_content function. |
|
| 495 | + * |
|
| 496 | + * @since 1.9.0 |
|
| 497 | + * @access public |
|
| 498 | + * @return void |
|
| 499 | + */ |
|
| 500 | 500 | |
| 501 | - public function course_manage_meta_box_content () { |
|
| 502 | - global $post; |
|
| 501 | + public function course_manage_meta_box_content () { |
|
| 502 | + global $post; |
|
| 503 | 503 | |
| 504 | - $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 504 | + $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 505 | 505 | |
| 506 | - $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 506 | + $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 507 | 507 | |
| 508 | 508 | |
| 509 | - echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 509 | + echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 510 | 510 | |
| 511 | - echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 511 | + echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 512 | 512 | |
| 513 | 513 | |
| 514 | 514 | |
| 515 | - } // End course_manage_meta_box_content() |
|
| 515 | + } // End course_manage_meta_box_content() |
|
| 516 | 516 | |
| 517 | 517 | /** |
| 518 | 518 | * Add column headings to the "lesson" post list screen. |
@@ -653,92 +653,92 @@ discard block |
||
| 653 | 653 | } // End If Statement |
| 654 | 654 | } // End If Statement |
| 655 | 655 | |
| 656 | - $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 657 | - $order = 'ASC'; |
|
| 658 | - $orderby = 'menu_order'; |
|
| 659 | - if( empty( $stored_order ) ){ |
|
| 656 | + $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 657 | + $order = 'ASC'; |
|
| 658 | + $orderby = 'menu_order'; |
|
| 659 | + if( empty( $stored_order ) ){ |
|
| 660 | 660 | |
| 661 | - $order = 'DESC'; |
|
| 662 | - $orderby = 'date'; |
|
| 661 | + $order = 'DESC'; |
|
| 662 | + $orderby = 'date'; |
|
| 663 | 663 | |
| 664 | - } |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | switch ($type) { |
| 667 | 667 | |
| 668 | 668 | case 'usercourses': |
| 669 | 669 | $post_args = array( 'post_type' => 'course', |
| 670 | 670 | 'orderby' => $orderby, |
| 671 | - 'order' => $order, |
|
| 672 | - 'post_status' => 'publish', |
|
| 673 | - 'include' => $includes, |
|
| 674 | - 'exclude' => $excludes, |
|
| 675 | - 'suppress_filters' => 0 |
|
| 671 | + 'order' => $order, |
|
| 672 | + 'post_status' => 'publish', |
|
| 673 | + 'include' => $includes, |
|
| 674 | + 'exclude' => $excludes, |
|
| 675 | + 'suppress_filters' => 0 |
|
| 676 | 676 | ); |
| 677 | 677 | break; |
| 678 | 678 | case 'freecourses': |
| 679 | 679 | |
| 680 | - $post_args = array( |
|
| 681 | - 'post_type' => 'course', |
|
| 682 | - 'orderby' => $orderby, |
|
| 683 | - 'order' => $order, |
|
| 684 | - 'post_status' => 'publish', |
|
| 685 | - 'exclude' => $excludes, |
|
| 686 | - 'suppress_filters' => 0 |
|
| 687 | - ); |
|
| 688 | - // Sub Query to get all WooCommerce Products that have Zero price |
|
| 689 | - $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 680 | + $post_args = array( |
|
| 681 | + 'post_type' => 'course', |
|
| 682 | + 'orderby' => $orderby, |
|
| 683 | + 'order' => $order, |
|
| 684 | + 'post_status' => 'publish', |
|
| 685 | + 'exclude' => $excludes, |
|
| 686 | + 'suppress_filters' => 0 |
|
| 687 | + ); |
|
| 688 | + // Sub Query to get all WooCommerce Products that have Zero price |
|
| 689 | + $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 690 | 690 | |
| 691 | - break; |
|
| 691 | + break; |
|
| 692 | 692 | |
| 693 | 693 | case 'paidcourses': |
| 694 | 694 | |
| 695 | - $post_args = array( |
|
| 696 | - 'post_type' => 'course', |
|
| 697 | - 'orderby' => $orderby, |
|
| 698 | - 'order' => $order, |
|
| 699 | - 'post_status' => 'publish', |
|
| 700 | - 'exclude' => $excludes, |
|
| 701 | - 'suppress_filters' => 0 |
|
| 702 | - ); |
|
| 695 | + $post_args = array( |
|
| 696 | + 'post_type' => 'course', |
|
| 697 | + 'orderby' => $orderby, |
|
| 698 | + 'order' => $order, |
|
| 699 | + 'post_status' => 'publish', |
|
| 700 | + 'exclude' => $excludes, |
|
| 701 | + 'suppress_filters' => 0 |
|
| 702 | + ); |
|
| 703 | 703 | |
| 704 | - // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 705 | - $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 704 | + // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 705 | + $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 706 | 706 | |
| 707 | 707 | break; |
| 708 | 708 | |
| 709 | 709 | case 'featuredcourses': |
| 710 | - $post_args = array( 'post_type' => 'course', |
|
| 711 | - 'orderby' => $orderby, |
|
| 712 | - 'order' => $order, |
|
| 713 | - 'post_status' => 'publish', |
|
| 714 | - 'meta_value' => 'featured', |
|
| 715 | - 'meta_key' => '_course_featured', |
|
| 716 | - 'meta_compare' => '=', |
|
| 717 | - 'exclude' => $excludes, |
|
| 718 | - 'suppress_filters' => 0 |
|
| 710 | + $post_args = array( 'post_type' => 'course', |
|
| 711 | + 'orderby' => $orderby, |
|
| 712 | + 'order' => $order, |
|
| 713 | + 'post_status' => 'publish', |
|
| 714 | + 'meta_value' => 'featured', |
|
| 715 | + 'meta_key' => '_course_featured', |
|
| 716 | + 'meta_compare' => '=', |
|
| 717 | + 'exclude' => $excludes, |
|
| 718 | + 'suppress_filters' => 0 |
|
| 719 | 719 | ); |
| 720 | 720 | break; |
| 721 | 721 | default: |
| 722 | 722 | $post_args = array( 'post_type' => 'course', |
| 723 | - 'orderby' => $orderby, |
|
| 724 | - 'order' => $order, |
|
| 725 | - 'post_status' => 'publish', |
|
| 726 | - 'exclude' => $excludes, |
|
| 727 | - 'suppress_filters' => 0 |
|
| 723 | + 'orderby' => $orderby, |
|
| 724 | + 'order' => $order, |
|
| 725 | + 'post_status' => 'publish', |
|
| 726 | + 'exclude' => $excludes, |
|
| 727 | + 'suppress_filters' => 0 |
|
| 728 | 728 | ); |
| 729 | 729 | break; |
| 730 | 730 | |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | - $post_args['posts_per_page'] = $amount; |
|
| 734 | - $paged = $wp_query->get( 'paged' ); |
|
| 735 | - $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 733 | + $post_args['posts_per_page'] = $amount; |
|
| 734 | + $paged = $wp_query->get( 'paged' ); |
|
| 735 | + $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 736 | 736 | |
| 737 | - if( 'newcourses' == $type ){ |
|
| 737 | + if( 'newcourses' == $type ){ |
|
| 738 | 738 | |
| 739 | - $post_args[ 'orderby' ] = 'date'; |
|
| 740 | - $post_args[ 'order' ] = 'DESC'; |
|
| 741 | - } |
|
| 739 | + $post_args[ 'orderby' ] = 'date'; |
|
| 740 | + $post_args[ 'order' ] = 'DESC'; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | 743 | return $post_args; |
| 744 | 744 | } |
@@ -748,22 +748,22 @@ discard block |
||
| 748 | 748 | * course_image function. |
| 749 | 749 | * |
| 750 | 750 | * Outputs the courses image, or first image from a lesson within a course |
| 751 | - * |
|
| 752 | - * Will echo the image unless return true is specified. |
|
| 751 | + * |
|
| 752 | + * Will echo the image unless return true is specified. |
|
| 753 | 753 | * |
| 754 | 754 | * @access public |
| 755 | 755 | * @param int | WP_Post $course_id (default: 0) |
| 756 | 756 | * @param string $width (default: '100') |
| 757 | 757 | * @param string $height (default: '100') |
| 758 | - * @param bool $return default false |
|
| 759 | - * |
|
| 758 | + * @param bool $return default false |
|
| 759 | + * |
|
| 760 | 760 | * @return string | void |
| 761 | 761 | */ |
| 762 | 762 | public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) { |
| 763 | 763 | |
| 764 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 765 | - $course_id = $course_id->ID; |
|
| 766 | - } |
|
| 764 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 765 | + $course_id = $course_id->ID; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | $html = ''; |
| 769 | 769 | |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | // Display Image Placeholder if none |
| 821 | 821 | if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) { |
| 822 | 822 | |
| 823 | - $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 823 | + $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 824 | 824 | |
| 825 | 825 | } // End If Statement |
| 826 | 826 | |
@@ -834,15 +834,15 @@ discard block |
||
| 834 | 834 | |
| 835 | 835 | } // End If Statement |
| 836 | 836 | |
| 837 | - if( $return ){ |
|
| 837 | + if( $return ){ |
|
| 838 | 838 | |
| 839 | - return $html; |
|
| 839 | + return $html; |
|
| 840 | 840 | |
| 841 | - }else{ |
|
| 841 | + }else{ |
|
| 842 | 842 | |
| 843 | - echo $html; |
|
| 843 | + echo $html; |
|
| 844 | 844 | |
| 845 | - } |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | 847 | } // End course_image() |
| 848 | 848 | |
@@ -886,9 +886,9 @@ discard block |
||
| 886 | 886 | */ |
| 887 | 887 | public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) { |
| 888 | 888 | |
| 889 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 890 | - $course_id = $course_id->ID; |
|
| 891 | - } |
|
| 889 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 890 | + $course_id = $course_id->ID; |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | 893 | $post_args = array( 'post_type' => 'lesson', |
| 894 | 894 | 'posts_per_page' => -1, |
@@ -904,67 +904,67 @@ discard block |
||
| 904 | 904 | 'suppress_filters' => 0, |
| 905 | 905 | ); |
| 906 | 906 | $query_results = new WP_Query( $post_args ); |
| 907 | - $lessons = $query_results->posts; |
|
| 908 | - |
|
| 909 | - // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 910 | - // with the course order for a different course and this should not be included. It could also not |
|
| 911 | - // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 912 | - // that have been added to the course. |
|
| 913 | - if( count( $lessons) > 1 ){ |
|
| 914 | - |
|
| 915 | - foreach( $lessons as $lesson ){ |
|
| 916 | - |
|
| 917 | - $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 918 | - // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 919 | - $lesson->course_order = $order ? $order : 100000; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * Filter runs inside Sensei_Course::course_lessons function |
|
| 927 | - * |
|
| 928 | - * Returns all lessons for a given course |
|
| 929 | - * |
|
| 930 | - * @param array $lessons |
|
| 931 | - * @param int $course_id |
|
| 932 | - */ |
|
| 933 | - $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 934 | - |
|
| 935 | - //return the requested fields |
|
| 936 | - // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 937 | - // objects |
|
| 938 | - if( 'ids' == $fields ) { |
|
| 939 | - $lesson_objects = $lessons; |
|
| 940 | - $lessons = array(); |
|
| 941 | - |
|
| 942 | - foreach ($lesson_objects as $lesson) { |
|
| 943 | - $lessons[] = $lesson->ID; |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - return $lessons; |
|
| 907 | + $lessons = $query_results->posts; |
|
| 908 | + |
|
| 909 | + // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 910 | + // with the course order for a different course and this should not be included. It could also not |
|
| 911 | + // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 912 | + // that have been added to the course. |
|
| 913 | + if( count( $lessons) > 1 ){ |
|
| 914 | + |
|
| 915 | + foreach( $lessons as $lesson ){ |
|
| 916 | + |
|
| 917 | + $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 918 | + // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 919 | + $lesson->course_order = $order ? $order : 100000; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * Filter runs inside Sensei_Course::course_lessons function |
|
| 927 | + * |
|
| 928 | + * Returns all lessons for a given course |
|
| 929 | + * |
|
| 930 | + * @param array $lessons |
|
| 931 | + * @param int $course_id |
|
| 932 | + */ |
|
| 933 | + $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 934 | + |
|
| 935 | + //return the requested fields |
|
| 936 | + // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 937 | + // objects |
|
| 938 | + if( 'ids' == $fields ) { |
|
| 939 | + $lesson_objects = $lessons; |
|
| 940 | + $lessons = array(); |
|
| 941 | + |
|
| 942 | + foreach ($lesson_objects as $lesson) { |
|
| 943 | + $lessons[] = $lesson->ID; |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + return $lessons; |
|
| 948 | 948 | |
| 949 | 949 | } // End course_lessons() |
| 950 | 950 | |
| 951 | - /** |
|
| 952 | - * Used for the uasort in $this->course_lessons() |
|
| 953 | - * @since 1.8.0 |
|
| 954 | - * @access protected |
|
| 955 | - * |
|
| 956 | - * @param array $lesson_1 |
|
| 957 | - * @param array $lesson_2 |
|
| 958 | - * @return int |
|
| 959 | - */ |
|
| 960 | - protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 951 | + /** |
|
| 952 | + * Used for the uasort in $this->course_lessons() |
|
| 953 | + * @since 1.8.0 |
|
| 954 | + * @access protected |
|
| 955 | + * |
|
| 956 | + * @param array $lesson_1 |
|
| 957 | + * @param array $lesson_2 |
|
| 958 | + * @return int |
|
| 959 | + */ |
|
| 960 | + protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 961 | 961 | |
| 962 | - if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 963 | - return 0; |
|
| 964 | - } |
|
| 962 | + if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 963 | + return 0; |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | - return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 967 | - } |
|
| 966 | + return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | 969 | /** |
| 970 | 970 | * Fetch all quiz ids in a course |
@@ -1027,15 +1027,15 @@ discard block |
||
| 1027 | 1027 | */ |
| 1028 | 1028 | public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) { |
| 1029 | 1029 | |
| 1030 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1030 | + $lesson_args = array( 'post_type' => 'lesson', |
|
| 1031 | 1031 | 'posts_per_page' => -1, |
| 1032 | - 'author' => $author_id, |
|
| 1033 | - 'meta_key' => '_lesson_course', |
|
| 1034 | - 'meta_value' => $course_id, |
|
| 1035 | - 'post_status' => 'publish', |
|
| 1036 | - 'suppress_filters' => 0, |
|
| 1032 | + 'author' => $author_id, |
|
| 1033 | + 'meta_key' => '_lesson_course', |
|
| 1034 | + 'meta_value' => $course_id, |
|
| 1035 | + 'post_status' => 'publish', |
|
| 1036 | + 'suppress_filters' => 0, |
|
| 1037 | 1037 | 'fields' => 'ids', // less data to retrieve |
| 1038 | - ); |
|
| 1038 | + ); |
|
| 1039 | 1039 | $lessons_array = get_posts( $lesson_args ); |
| 1040 | 1040 | $count = count( $lessons_array ); |
| 1041 | 1041 | return $count; |
@@ -1053,17 +1053,17 @@ discard block |
||
| 1053 | 1053 | |
| 1054 | 1054 | $lesson_args = array( 'post_type' => 'lesson', |
| 1055 | 1055 | 'posts_per_page' => -1, |
| 1056 | - 'meta_key' => '_lesson_course', |
|
| 1057 | - 'meta_value' => $course_id, |
|
| 1058 | - 'post_status' => 'publish', |
|
| 1059 | - 'suppress_filters' => 0, |
|
| 1056 | + 'meta_key' => '_lesson_course', |
|
| 1057 | + 'meta_value' => $course_id, |
|
| 1058 | + 'post_status' => 'publish', |
|
| 1059 | + 'suppress_filters' => 0, |
|
| 1060 | 1060 | 'fields' => 'ids', // less data to retrieve |
| 1061 | - ); |
|
| 1061 | + ); |
|
| 1062 | 1062 | $lessons_array = get_posts( $lesson_args ); |
| 1063 | 1063 | |
| 1064 | - $count = count( $lessons_array ); |
|
| 1064 | + $count = count( $lessons_array ); |
|
| 1065 | 1065 | |
| 1066 | - return $count; |
|
| 1066 | + return $count; |
|
| 1067 | 1067 | |
| 1068 | 1068 | } // End course_lesson_count() |
| 1069 | 1069 | |
@@ -1078,9 +1078,9 @@ discard block |
||
| 1078 | 1078 | |
| 1079 | 1079 | $lesson_args = array( 'post_type' => 'lesson', |
| 1080 | 1080 | 'posts_per_page' => -1, |
| 1081 | - 'post_status' => 'publish', |
|
| 1082 | - 'suppress_filters' => 0, |
|
| 1083 | - 'meta_query' => array( |
|
| 1081 | + 'post_status' => 'publish', |
|
| 1082 | + 'suppress_filters' => 0, |
|
| 1083 | + 'meta_query' => array( |
|
| 1084 | 1084 | array( |
| 1085 | 1085 | 'key' => '_lesson_course', |
| 1086 | 1086 | 'value' => $course_id |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | ) |
| 1092 | 1092 | ), |
| 1093 | 1093 | 'fields' => 'ids', // less data to retrieve |
| 1094 | - ); |
|
| 1094 | + ); |
|
| 1095 | 1095 | $lessons_array = get_posts( $lesson_args ); |
| 1096 | 1096 | |
| 1097 | 1097 | $count = count( $lessons_array ); |
| 1098 | 1098 | |
| 1099 | - return $count; |
|
| 1099 | + return $count; |
|
| 1100 | 1100 | |
| 1101 | 1101 | } // End course_lesson_count() |
| 1102 | 1102 | |
@@ -1115,8 +1115,8 @@ discard block |
||
| 1115 | 1115 | $post_args = array( 'post_type' => 'course', |
| 1116 | 1116 | 'posts_per_page' => -1, |
| 1117 | 1117 | 'meta_key' => '_course_woocommerce_product', |
| 1118 | - 'meta_value' => $product_id, |
|
| 1119 | - 'post_status' => 'publish', |
|
| 1118 | + 'meta_value' => $product_id, |
|
| 1119 | + 'post_status' => 'publish', |
|
| 1120 | 1120 | 'suppress_filters' => 0, |
| 1121 | 1121 | 'orderby' => 'menu_order date', |
| 1122 | 1122 | 'order' => 'ASC', |
@@ -1157,9 +1157,9 @@ discard block |
||
| 1157 | 1157 | |
| 1158 | 1158 | /** |
| 1159 | 1159 | * load_user_courses_content generates HTML for user's active & completed courses |
| 1160 | - * |
|
| 1161 | - * This function also ouputs the html so no need to echo the content. |
|
| 1162 | - * |
|
| 1160 | + * |
|
| 1161 | + * This function also ouputs the html so no need to echo the content. |
|
| 1162 | + * |
|
| 1163 | 1163 | * @since 1.4.0 |
| 1164 | 1164 | * @param object $user Queried user object |
| 1165 | 1165 | * @param boolean $manage Whether the user has permission to manage the courses |
@@ -1168,17 +1168,17 @@ discard block |
||
| 1168 | 1168 | public function load_user_courses_content( $user = false ) { |
| 1169 | 1169 | global $course, $my_courses_page, $my_courses_section; |
| 1170 | 1170 | |
| 1171 | - if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | - || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1171 | + if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | + || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1173 | 1173 | |
| 1174 | - // do not show the content if the settings doesn't allow for it |
|
| 1175 | - return; |
|
| 1174 | + // do not show the content if the settings doesn't allow for it |
|
| 1175 | + return; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1179 | + $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1180 | 1180 | |
| 1181 | - do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1181 | + do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1182 | 1182 | |
| 1183 | 1183 | // Build Output HTML |
| 1184 | 1184 | $complete_html = $active_html = ''; |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | // Logic for Active and Completed Courses |
| 1194 | 1194 | $per_page = 20; |
| 1195 | 1195 | if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) |
| 1196 | - && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1196 | + && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1197 | 1197 | |
| 1198 | 1198 | $per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
| 1199 | 1199 | |
@@ -1239,111 +1239,111 @@ discard block |
||
| 1239 | 1239 | } |
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | - // Get Course Categories |
|
| 1243 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1242 | + // Get Course Categories |
|
| 1243 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1244 | 1244 | |
| 1245 | - $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1245 | + $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1246 | 1246 | |
| 1247 | - // Image |
|
| 1248 | - $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1247 | + // Image |
|
| 1248 | + $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1249 | 1249 | |
| 1250 | - // Title |
|
| 1251 | - $active_html .= '<header>'; |
|
| 1250 | + // Title |
|
| 1251 | + $active_html .= '<header>'; |
|
| 1252 | 1252 | |
| 1253 | - $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1253 | + $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1254 | 1254 | |
| 1255 | - $active_html .= '</header>'; |
|
| 1255 | + $active_html .= '</header>'; |
|
| 1256 | 1256 | |
| 1257 | - $active_html .= '<section class="entry">'; |
|
| 1257 | + $active_html .= '<section class="entry">'; |
|
| 1258 | 1258 | |
| 1259 | - $active_html .= '<p class="sensei-course-meta">'; |
|
| 1259 | + $active_html .= '<p class="sensei-course-meta">'; |
|
| 1260 | 1260 | |
| 1261 | - // Author |
|
| 1262 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | - && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1261 | + // Author |
|
| 1262 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | + && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1265 | 1265 | |
| 1266 | - $active_html .= '<span class="course-author">' |
|
| 1267 | - . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | - . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | - . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | - . esc_html( $user_info->display_name ) |
|
| 1271 | - . '</a></span>'; |
|
| 1266 | + $active_html .= '<span class="course-author">' |
|
| 1267 | + . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | + . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | + . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | + . esc_html( $user_info->display_name ) |
|
| 1271 | + . '</a></span>'; |
|
| 1272 | 1272 | |
| 1273 | - } // End If Statement |
|
| 1273 | + } // End If Statement |
|
| 1274 | 1274 | |
| 1275 | - // Lesson count for this author |
|
| 1276 | - $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1277 | - // Handle Division by Zero |
|
| 1278 | - if ( 0 == $lesson_count ) { |
|
| 1275 | + // Lesson count for this author |
|
| 1276 | + $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1277 | + // Handle Division by Zero |
|
| 1278 | + if ( 0 == $lesson_count ) { |
|
| 1279 | 1279 | |
| 1280 | - $lesson_count = 1; |
|
| 1280 | + $lesson_count = 1; |
|
| 1281 | 1281 | |
| 1282 | - } // End If Statement |
|
| 1283 | - $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1284 | - // Course Categories |
|
| 1285 | - if ( '' != $category_output ) { |
|
| 1282 | + } // End If Statement |
|
| 1283 | + $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1284 | + // Course Categories |
|
| 1285 | + if ( '' != $category_output ) { |
|
| 1286 | 1286 | |
| 1287 | - $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1287 | + $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1288 | 1288 | |
| 1289 | - } // End If Statement |
|
| 1290 | - $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1289 | + } // End If Statement |
|
| 1290 | + $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1291 | 1291 | |
| 1292 | - $active_html .= '</p>'; |
|
| 1292 | + $active_html .= '</p>'; |
|
| 1293 | 1293 | |
| 1294 | - $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1294 | + $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | 1297 | |
| 1298 | - $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1298 | + $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1299 | 1299 | |
| 1300 | - $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1300 | + $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1301 | 1301 | |
| 1302 | - $active_html .= '</section>'; |
|
| 1302 | + $active_html .= '</section>'; |
|
| 1303 | 1303 | |
| 1304 | - if( is_user_logged_in() ) { |
|
| 1304 | + if( is_user_logged_in() ) { |
|
| 1305 | 1305 | |
| 1306 | - $active_html .= '<section class="entry-actions">'; |
|
| 1306 | + $active_html .= '<section class="entry-actions">'; |
|
| 1307 | 1307 | |
| 1308 | - $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1308 | + $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1309 | 1309 | |
| 1310 | - $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1310 | + $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1311 | 1311 | |
| 1312 | - $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1312 | + $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1313 | 1313 | |
| 1314 | - if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1314 | + if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1315 | 1315 | |
| 1316 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1317 | - . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1316 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1317 | + . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1318 | 1318 | |
| 1319 | - } // End If Statement |
|
| 1319 | + } // End If Statement |
|
| 1320 | 1320 | |
| 1321 | - $course_purchased = false; |
|
| 1322 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1321 | + $course_purchased = false; |
|
| 1322 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1323 | 1323 | |
| 1324 | - // Get the product ID |
|
| 1325 | - $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | - if ( 0 < $wc_post_id ) { |
|
| 1324 | + // Get the product ID |
|
| 1325 | + $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | + if ( 0 < $wc_post_id ) { |
|
| 1327 | 1327 | |
| 1328 | - $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1328 | + $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1329 | 1329 | |
| 1330 | - } // End If Statement |
|
| 1330 | + } // End If Statement |
|
| 1331 | 1331 | |
| 1332 | - } // End If Statement |
|
| 1332 | + } // End If Statement |
|
| 1333 | 1333 | |
| 1334 | - if ( false == $course_purchased ) { |
|
| 1334 | + if ( false == $course_purchased ) { |
|
| 1335 | 1335 | |
| 1336 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1337 | - . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1336 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1337 | + . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1338 | 1338 | |
| 1339 | - } // End If Statement |
|
| 1339 | + } // End If Statement |
|
| 1340 | 1340 | |
| 1341 | - $active_html .= '</form>'; |
|
| 1341 | + $active_html .= '</form>'; |
|
| 1342 | 1342 | |
| 1343 | - $active_html .= '</section>'; |
|
| 1344 | - } |
|
| 1343 | + $active_html .= '</section>'; |
|
| 1344 | + } |
|
| 1345 | 1345 | |
| 1346 | - $active_html .= '</article>'; |
|
| 1346 | + $active_html .= '</article>'; |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | // Active pagination |
@@ -1383,49 +1383,49 @@ discard block |
||
| 1383 | 1383 | foreach ( $completed_courses as $course_item ) { |
| 1384 | 1384 | $course = $course_item; |
| 1385 | 1385 | |
| 1386 | - // Get Course Categories |
|
| 1387 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1386 | + // Get Course Categories |
|
| 1387 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1388 | 1388 | |
| 1389 | - $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1389 | + $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1390 | 1390 | |
| 1391 | - // Image |
|
| 1392 | - $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1391 | + // Image |
|
| 1392 | + $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1393 | 1393 | |
| 1394 | - // Title |
|
| 1395 | - $complete_html .= '<header>'; |
|
| 1394 | + // Title |
|
| 1395 | + $complete_html .= '<header>'; |
|
| 1396 | 1396 | |
| 1397 | - $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1397 | + $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1398 | 1398 | |
| 1399 | - $complete_html .= '</header>'; |
|
| 1399 | + $complete_html .= '</header>'; |
|
| 1400 | 1400 | |
| 1401 | - $complete_html .= '<section class="entry">'; |
|
| 1401 | + $complete_html .= '<section class="entry">'; |
|
| 1402 | 1402 | |
| 1403 | - $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1403 | + $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1404 | 1404 | |
| 1405 | - // Author |
|
| 1406 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | - $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1409 | - } // End If Statement |
|
| 1405 | + // Author |
|
| 1406 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | + $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1409 | + } // End If Statement |
|
| 1410 | 1410 | |
| 1411 | - // Lesson count for this author |
|
| 1412 | - $complete_html .= '<span class="course-lesson-count">' |
|
| 1413 | - . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | - . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1415 | - . '</span>'; |
|
| 1411 | + // Lesson count for this author |
|
| 1412 | + $complete_html .= '<span class="course-lesson-count">' |
|
| 1413 | + . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | + . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1415 | + . '</span>'; |
|
| 1416 | 1416 | |
| 1417 | - // Course Categories |
|
| 1418 | - if ( '' != $category_output ) { |
|
| 1417 | + // Course Categories |
|
| 1418 | + if ( '' != $category_output ) { |
|
| 1419 | 1419 | |
| 1420 | - $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1420 | + $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1421 | 1421 | |
| 1422 | - } // End If Statement |
|
| 1422 | + } // End If Statement |
|
| 1423 | 1423 | |
| 1424 | 1424 | $complete_html .= '</p>'; |
| 1425 | 1425 | |
| 1426 | 1426 | $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
| 1427 | 1427 | |
| 1428 | - $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1428 | + $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1429 | 1429 | |
| 1430 | 1430 | if( $manage ) { |
| 1431 | 1431 | $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true ); |
@@ -1438,9 +1438,9 @@ discard block |
||
| 1438 | 1438 | if( $has_quizzes ) { |
| 1439 | 1439 | |
| 1440 | 1440 | $results_link = '<a class="button view-results" href="' |
| 1441 | - . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | - . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1443 | - . '</a>'; |
|
| 1441 | + . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | + . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1443 | + . '</a>'; |
|
| 1444 | 1444 | } |
| 1445 | 1445 | $complete_html .= apply_filters( 'sensei_results_links', $results_link ); |
| 1446 | 1446 | $complete_html .= '</p>'; |
@@ -1448,9 +1448,9 @@ discard block |
||
| 1448 | 1448 | } |
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | - $complete_html .= '</section>'; |
|
| 1451 | + $complete_html .= '</section>'; |
|
| 1452 | 1452 | |
| 1453 | - $complete_html .= '</article>'; |
|
| 1453 | + $complete_html .= '</article>'; |
|
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | // Active pagination |
@@ -1525,16 +1525,16 @@ discard block |
||
| 1525 | 1525 | <?php do_action( 'sensei_before_active_user_courses' ); ?> |
| 1526 | 1526 | |
| 1527 | 1527 | <?php |
| 1528 | - $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1529 | - ?> |
|
| 1528 | + $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1529 | + ?> |
|
| 1530 | 1530 | |
| 1531 | 1531 | <div id="active-courses"> |
| 1532 | 1532 | |
| 1533 | 1533 | <?php if ( '' != $active_html ) { |
| 1534 | 1534 | |
| 1535 | - echo $active_html; |
|
| 1535 | + echo $active_html; |
|
| 1536 | 1536 | |
| 1537 | - } else { ?> |
|
| 1537 | + } else { ?> |
|
| 1538 | 1538 | |
| 1539 | 1539 | <div class="sensei-message info"> |
| 1540 | 1540 | |
@@ -1560,9 +1560,9 @@ discard block |
||
| 1560 | 1560 | |
| 1561 | 1561 | <?php if ( '' != $complete_html ) { |
| 1562 | 1562 | |
| 1563 | - echo $complete_html; |
|
| 1563 | + echo $complete_html; |
|
| 1564 | 1564 | |
| 1565 | - } else { ?> |
|
| 1565 | + } else { ?> |
|
| 1566 | 1566 | |
| 1567 | 1567 | <div class="sensei-message info"> |
| 1568 | 1568 | |
@@ -1581,355 +1581,355 @@ discard block |
||
| 1581 | 1581 | <?php do_action( 'sensei_after_user_courses' ); ?> |
| 1582 | 1582 | |
| 1583 | 1583 | <?php |
| 1584 | - echo ob_get_clean(); |
|
| 1584 | + echo ob_get_clean(); |
|
| 1585 | 1585 | |
| 1586 | - do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1586 | + do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1587 | 1587 | |
| 1588 | 1588 | } // end load_user_courses_content |
| 1589 | 1589 | |
| 1590 | - /** |
|
| 1591 | - * Returns a list of all courses |
|
| 1592 | - * |
|
| 1593 | - * @since 1.8.0 |
|
| 1594 | - * @return array $courses{ |
|
| 1595 | - * @type $course WP_Post |
|
| 1596 | - * } |
|
| 1597 | - */ |
|
| 1598 | - public static function get_all_courses(){ |
|
| 1599 | - |
|
| 1600 | - $args = array( |
|
| 1601 | - 'post_type' => 'course', |
|
| 1602 | - 'posts_per_page' => -1, |
|
| 1603 | - 'orderby' => 'title', |
|
| 1604 | - 'order' => 'ASC', |
|
| 1605 | - 'post_status' => 'any', |
|
| 1606 | - 'suppress_filters' => 0, |
|
| 1607 | - ); |
|
| 1608 | - |
|
| 1609 | - $wp_query_obj = new WP_Query( $args ); |
|
| 1610 | - |
|
| 1611 | - /** |
|
| 1612 | - * sensei_get_all_courses filter |
|
| 1613 | - * |
|
| 1614 | - * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1615 | - * |
|
| 1616 | - * @param array $courses{ |
|
| 1617 | - * @type WP_Post |
|
| 1618 | - * } |
|
| 1619 | - * @param array $attributes |
|
| 1620 | - */ |
|
| 1621 | - return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1622 | - |
|
| 1623 | - }// end get_all_courses |
|
| 1624 | - |
|
| 1625 | - /** |
|
| 1626 | - * Generate the course meter component |
|
| 1627 | - * |
|
| 1628 | - * @since 1.8.0 |
|
| 1629 | - * @param int $progress_percentage 0 - 100 |
|
| 1630 | - * @return string $progress_bar_html |
|
| 1631 | - */ |
|
| 1632 | - public function get_progress_meter( $progress_percentage ){ |
|
| 1633 | - |
|
| 1634 | - if ( 50 < $progress_percentage ) { |
|
| 1635 | - $class = ' green'; |
|
| 1636 | - } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1637 | - $class = ' orange'; |
|
| 1638 | - } else { |
|
| 1639 | - $class = ' red'; |
|
| 1640 | - } |
|
| 1641 | - $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1642 | - |
|
| 1643 | - return $progress_bar_html; |
|
| 1644 | - |
|
| 1645 | - }// end get_progress_meter |
|
| 1646 | - |
|
| 1647 | - /** |
|
| 1648 | - * Generate a statement that tells users |
|
| 1649 | - * how far they are in the course. |
|
| 1650 | - * |
|
| 1651 | - * @param int $course_id |
|
| 1652 | - * @param int $user_id |
|
| 1653 | - * |
|
| 1654 | - * @return string $statement_html |
|
| 1655 | - */ |
|
| 1656 | - public function get_progress_statement( $course_id, $user_id ){ |
|
| 1657 | - |
|
| 1658 | - if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | - || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1660 | - return ''; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1665 | - |
|
| 1666 | - $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1667 | - |
|
| 1668 | - /** |
|
| 1669 | - * Filter the course completion statement. |
|
| 1670 | - * Default Currently completed $var lesson($plural) of $var in total |
|
| 1671 | - * |
|
| 1672 | - * @param string $statement |
|
| 1673 | - */ |
|
| 1674 | - return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1675 | - |
|
| 1676 | - }// end generate_progress_statement |
|
| 1677 | - |
|
| 1678 | - /** |
|
| 1679 | - * Output the course progress statement |
|
| 1680 | - * |
|
| 1681 | - * @param $course_id |
|
| 1682 | - * @return void |
|
| 1683 | - */ |
|
| 1684 | - public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | - if( empty( $course_id ) ){ |
|
| 1686 | - global $post; |
|
| 1687 | - $course_id = $post->ID; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - if( empty( $user_id ) ){ |
|
| 1691 | - $user_id = get_current_user_id(); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Output the course progress bar |
|
| 1699 | - * |
|
| 1700 | - * @param $course_id |
|
| 1701 | - * @return void |
|
| 1702 | - */ |
|
| 1703 | - public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1704 | - |
|
| 1705 | - if( empty( $course_id ) ){ |
|
| 1706 | - global $post; |
|
| 1707 | - $course_id = $post->ID; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - if( empty( $user_id ) ){ |
|
| 1711 | - $user_id = get_current_user_id(); |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | - || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1716 | - return; |
|
| 1717 | - } |
|
| 1718 | - $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1719 | - |
|
| 1720 | - echo $this->get_progress_meter( $percentage_completed ); |
|
| 1721 | - |
|
| 1722 | - }// end the_progress_meter |
|
| 1723 | - |
|
| 1724 | - /** |
|
| 1725 | - * Checks how many lessons are completed |
|
| 1726 | - * |
|
| 1727 | - * @since 1.8.0 |
|
| 1728 | - * |
|
| 1729 | - * @param int $course_id |
|
| 1730 | - * @param int $user_id |
|
| 1731 | - * @return array $completed_lesson_ids |
|
| 1732 | - */ |
|
| 1733 | - public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1734 | - |
|
| 1735 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1736 | - $user_id = get_current_user_id(); |
|
| 1737 | - } |
|
| 1590 | + /** |
|
| 1591 | + * Returns a list of all courses |
|
| 1592 | + * |
|
| 1593 | + * @since 1.8.0 |
|
| 1594 | + * @return array $courses{ |
|
| 1595 | + * @type $course WP_Post |
|
| 1596 | + * } |
|
| 1597 | + */ |
|
| 1598 | + public static function get_all_courses(){ |
|
| 1599 | + |
|
| 1600 | + $args = array( |
|
| 1601 | + 'post_type' => 'course', |
|
| 1602 | + 'posts_per_page' => -1, |
|
| 1603 | + 'orderby' => 'title', |
|
| 1604 | + 'order' => 'ASC', |
|
| 1605 | + 'post_status' => 'any', |
|
| 1606 | + 'suppress_filters' => 0, |
|
| 1607 | + ); |
|
| 1608 | + |
|
| 1609 | + $wp_query_obj = new WP_Query( $args ); |
|
| 1610 | + |
|
| 1611 | + /** |
|
| 1612 | + * sensei_get_all_courses filter |
|
| 1613 | + * |
|
| 1614 | + * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1615 | + * |
|
| 1616 | + * @param array $courses{ |
|
| 1617 | + * @type WP_Post |
|
| 1618 | + * } |
|
| 1619 | + * @param array $attributes |
|
| 1620 | + */ |
|
| 1621 | + return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1622 | + |
|
| 1623 | + }// end get_all_courses |
|
| 1738 | 1624 | |
| 1739 | - $completed_lesson_ids = array(); |
|
| 1625 | + /** |
|
| 1626 | + * Generate the course meter component |
|
| 1627 | + * |
|
| 1628 | + * @since 1.8.0 |
|
| 1629 | + * @param int $progress_percentage 0 - 100 |
|
| 1630 | + * @return string $progress_bar_html |
|
| 1631 | + */ |
|
| 1632 | + public function get_progress_meter( $progress_percentage ){ |
|
| 1740 | 1633 | |
| 1741 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 1634 | + if ( 50 < $progress_percentage ) { |
|
| 1635 | + $class = ' green'; |
|
| 1636 | + } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1637 | + $class = ' orange'; |
|
| 1638 | + } else { |
|
| 1639 | + $class = ' red'; |
|
| 1640 | + } |
|
| 1641 | + $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1742 | 1642 | |
| 1743 | - foreach( $course_lessons as $lesson ){ |
|
| 1643 | + return $progress_bar_html; |
|
| 1744 | 1644 | |
| 1745 | - $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | - if( $is_lesson_completed ){ |
|
| 1747 | - $completed_lesson_ids[] = $lesson->ID; |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - } |
|
| 1751 | - |
|
| 1752 | - return $completed_lesson_ids; |
|
| 1645 | + }// end get_progress_meter |
|
| 1753 | 1646 | |
| 1754 | - }// end get_completed_lesson_ids |
|
| 1647 | + /** |
|
| 1648 | + * Generate a statement that tells users |
|
| 1649 | + * how far they are in the course. |
|
| 1650 | + * |
|
| 1651 | + * @param int $course_id |
|
| 1652 | + * @param int $user_id |
|
| 1653 | + * |
|
| 1654 | + * @return string $statement_html |
|
| 1655 | + */ |
|
| 1656 | + public function get_progress_statement( $course_id, $user_id ){ |
|
| 1755 | 1657 | |
| 1756 | - /** |
|
| 1757 | - * Calculate the perceantage completed in the course |
|
| 1758 | - * |
|
| 1759 | - * @since 1.8.0 |
|
| 1760 | - * |
|
| 1761 | - * @param int $course_id |
|
| 1762 | - * @param int $user_id |
|
| 1763 | - * @return int $percentage |
|
| 1764 | - */ |
|
| 1765 | - public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1766 | - |
|
| 1767 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1768 | - $user_id = get_current_user_id(); |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1772 | - |
|
| 1773 | - if( ! ( $completed > 0 ) ){ |
|
| 1774 | - return 0; |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1778 | - $percentage = $completed / $total_lessons * 100; |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * |
|
| 1782 | - * Filter the percentage returned for a users course. |
|
| 1783 | - * |
|
| 1784 | - * @param $percentage |
|
| 1785 | - * @param $course_id |
|
| 1786 | - * @param $user_id |
|
| 1787 | - * @since 1.8.0 |
|
| 1788 | - */ |
|
| 1789 | - return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1658 | + if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | + || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1660 | + return ''; |
|
| 1661 | + } |
|
| 1790 | 1662 | |
| 1791 | - }// end get_completed_lesson_ids |
|
| 1663 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1792 | 1665 | |
| 1793 | - /** |
|
| 1794 | - * Block email notifications for the specific courses |
|
| 1795 | - * that the user disabled the notifications. |
|
| 1796 | - * |
|
| 1797 | - * @since 1.8.0 |
|
| 1798 | - * @param $should_send |
|
| 1799 | - * @return bool |
|
| 1800 | - */ |
|
| 1801 | - public function block_notification_emails( $should_send ){ |
|
| 1802 | - global $sensei_email_data; |
|
| 1803 | - $email = $sensei_email_data; |
|
| 1666 | + $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1804 | 1667 | |
| 1805 | - $course_id = ''; |
|
| 1668 | + /** |
|
| 1669 | + * Filter the course completion statement. |
|
| 1670 | + * Default Currently completed $var lesson($plural) of $var in total |
|
| 1671 | + * |
|
| 1672 | + * @param string $statement |
|
| 1673 | + */ |
|
| 1674 | + return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1806 | 1675 | |
| 1807 | - if( isset( $email['course_id'] ) ){ |
|
| 1676 | + }// end generate_progress_statement |
|
| 1808 | 1677 | |
| 1809 | - $course_id = $email['course_id']; |
|
| 1810 | - |
|
| 1811 | - }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1678 | + /** |
|
| 1679 | + * Output the course progress statement |
|
| 1680 | + * |
|
| 1681 | + * @param $course_id |
|
| 1682 | + * @return void |
|
| 1683 | + */ |
|
| 1684 | + public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | + if( empty( $course_id ) ){ |
|
| 1686 | + global $post; |
|
| 1687 | + $course_id = $post->ID; |
|
| 1688 | + } |
|
| 1812 | 1689 | |
| 1813 | - $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1690 | + if( empty( $user_id ) ){ |
|
| 1691 | + $user_id = get_current_user_id(); |
|
| 1692 | + } |
|
| 1814 | 1693 | |
| 1815 | - }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1694 | + echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * Output the course progress bar |
|
| 1699 | + * |
|
| 1700 | + * @param $course_id |
|
| 1701 | + * @return void |
|
| 1702 | + */ |
|
| 1703 | + public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1704 | + |
|
| 1705 | + if( empty( $course_id ) ){ |
|
| 1706 | + global $post; |
|
| 1707 | + $course_id = $post->ID; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + if( empty( $user_id ) ){ |
|
| 1711 | + $user_id = get_current_user_id(); |
|
| 1712 | + } |
|
| 1816 | 1713 | |
| 1817 | - $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1714 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | + || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1716 | + return; |
|
| 1717 | + } |
|
| 1718 | + $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1819 | 1719 | |
| 1820 | - } |
|
| 1720 | + echo $this->get_progress_meter( $percentage_completed ); |
|
| 1721 | + |
|
| 1722 | + }// end the_progress_meter |
|
| 1723 | + |
|
| 1724 | + /** |
|
| 1725 | + * Checks how many lessons are completed |
|
| 1726 | + * |
|
| 1727 | + * @since 1.8.0 |
|
| 1728 | + * |
|
| 1729 | + * @param int $course_id |
|
| 1730 | + * @param int $user_id |
|
| 1731 | + * @return array $completed_lesson_ids |
|
| 1732 | + */ |
|
| 1733 | + public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1734 | + |
|
| 1735 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1736 | + $user_id = get_current_user_id(); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + $completed_lesson_ids = array(); |
|
| 1740 | + |
|
| 1741 | + $course_lessons = $this->course_lessons( $course_id ); |
|
| 1742 | + |
|
| 1743 | + foreach( $course_lessons as $lesson ){ |
|
| 1744 | + |
|
| 1745 | + $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | + if( $is_lesson_completed ){ |
|
| 1747 | + $completed_lesson_ids[] = $lesson->ID; |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + } |
|
| 1821 | 1751 | |
| 1822 | - if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | - |
|
| 1824 | - $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | - |
|
| 1826 | - if ($course_emails_disabled) { |
|
| 1827 | - |
|
| 1828 | - return false; |
|
| 1829 | - |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - }// end if |
|
| 1833 | - |
|
| 1834 | - return $should_send; |
|
| 1835 | - }// end block_notification_emails |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * Render the course notification setting meta box |
|
| 1839 | - * |
|
| 1840 | - * @since 1.8.0 |
|
| 1841 | - * @param $course |
|
| 1842 | - */ |
|
| 1843 | - public function course_notification_meta_box_content( $course ){ |
|
| 1844 | - |
|
| 1845 | - $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1846 | - |
|
| 1847 | - // generate checked html |
|
| 1848 | - $checked_html = ''; |
|
| 1849 | - if( $checked ){ |
|
| 1850 | - $checked_html = 'checked="checked"'; |
|
| 1851 | - } |
|
| 1852 | - wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1853 | - |
|
| 1854 | - echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | - echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1856 | - |
|
| 1857 | - }// end course_notification_meta_box_content |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * Store the setting for the course notification setting. |
|
| 1861 | - * |
|
| 1862 | - * @hooked int save_post |
|
| 1863 | - * @since 1.8.0 |
|
| 1864 | - * |
|
| 1865 | - * @param $course_id |
|
| 1866 | - */ |
|
| 1867 | - public function save_course_notification_meta_box( $course_id ){ |
|
| 1868 | - |
|
| 1869 | - if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | - || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1871 | - return; |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1875 | - $new_val = true; |
|
| 1876 | - }else{ |
|
| 1877 | - $new_val = false; |
|
| 1878 | - } |
|
| 1879 | - |
|
| 1880 | - update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1881 | - |
|
| 1882 | - }// end save notification meta box |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * Backwards compatibility hooks added to ensure that |
|
| 1886 | - * plugins and other parts of sensei still works. |
|
| 1887 | - * |
|
| 1888 | - * This function hooks into `sensei_course_content_inside_before` |
|
| 1889 | - * |
|
| 1890 | - * @since 1.9 |
|
| 1891 | - * |
|
| 1892 | - * @param WP_Post $post |
|
| 1893 | - */ |
|
| 1894 | - public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1895 | - |
|
| 1896 | - sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | - sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1752 | + return $completed_lesson_ids; |
|
| 1898 | 1753 | |
| 1899 | - } |
|
| 1754 | + }// end get_completed_lesson_ids |
|
| 1900 | 1755 | |
| 1901 | - /** |
|
| 1902 | - * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1903 | - * |
|
| 1904 | - * hooked into 'sensei_loop_course_before' |
|
| 1905 | - * |
|
| 1906 | - * @since 1.9 |
|
| 1907 | - * |
|
| 1908 | - * @global WP_Post $post |
|
| 1909 | - */ |
|
| 1910 | - public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1911 | - |
|
| 1912 | - global $post; |
|
| 1913 | - sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1914 | - |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - /** |
|
| 1918 | - * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1919 | - * |
|
| 1920 | - * hooked into 'sensei_course_content_inside_after' |
|
| 1921 | - * |
|
| 1922 | - * @since 1.9.0 |
|
| 1923 | - * |
|
| 1924 | - * @param WP_Post $course |
|
| 1925 | - */ |
|
| 1926 | - public function the_course_free_lesson_preview( $course ){ |
|
| 1927 | - // Meta data |
|
| 1928 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1929 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1930 | - |
|
| 1931 | - if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1932 | - ?> |
|
| 1756 | + /** |
|
| 1757 | + * Calculate the perceantage completed in the course |
|
| 1758 | + * |
|
| 1759 | + * @since 1.8.0 |
|
| 1760 | + * |
|
| 1761 | + * @param int $course_id |
|
| 1762 | + * @param int $user_id |
|
| 1763 | + * @return int $percentage |
|
| 1764 | + */ |
|
| 1765 | + public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1766 | + |
|
| 1767 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1768 | + $user_id = get_current_user_id(); |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1772 | + |
|
| 1773 | + if( ! ( $completed > 0 ) ){ |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1778 | + $percentage = $completed / $total_lessons * 100; |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * |
|
| 1782 | + * Filter the percentage returned for a users course. |
|
| 1783 | + * |
|
| 1784 | + * @param $percentage |
|
| 1785 | + * @param $course_id |
|
| 1786 | + * @param $user_id |
|
| 1787 | + * @since 1.8.0 |
|
| 1788 | + */ |
|
| 1789 | + return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1790 | + |
|
| 1791 | + }// end get_completed_lesson_ids |
|
| 1792 | + |
|
| 1793 | + /** |
|
| 1794 | + * Block email notifications for the specific courses |
|
| 1795 | + * that the user disabled the notifications. |
|
| 1796 | + * |
|
| 1797 | + * @since 1.8.0 |
|
| 1798 | + * @param $should_send |
|
| 1799 | + * @return bool |
|
| 1800 | + */ |
|
| 1801 | + public function block_notification_emails( $should_send ){ |
|
| 1802 | + global $sensei_email_data; |
|
| 1803 | + $email = $sensei_email_data; |
|
| 1804 | + |
|
| 1805 | + $course_id = ''; |
|
| 1806 | + |
|
| 1807 | + if( isset( $email['course_id'] ) ){ |
|
| 1808 | + |
|
| 1809 | + $course_id = $email['course_id']; |
|
| 1810 | + |
|
| 1811 | + }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1812 | + |
|
| 1813 | + $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1814 | + |
|
| 1815 | + }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1816 | + |
|
| 1817 | + $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1819 | + |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | + |
|
| 1824 | + $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | + |
|
| 1826 | + if ($course_emails_disabled) { |
|
| 1827 | + |
|
| 1828 | + return false; |
|
| 1829 | + |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + }// end if |
|
| 1833 | + |
|
| 1834 | + return $should_send; |
|
| 1835 | + }// end block_notification_emails |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * Render the course notification setting meta box |
|
| 1839 | + * |
|
| 1840 | + * @since 1.8.0 |
|
| 1841 | + * @param $course |
|
| 1842 | + */ |
|
| 1843 | + public function course_notification_meta_box_content( $course ){ |
|
| 1844 | + |
|
| 1845 | + $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1846 | + |
|
| 1847 | + // generate checked html |
|
| 1848 | + $checked_html = ''; |
|
| 1849 | + if( $checked ){ |
|
| 1850 | + $checked_html = 'checked="checked"'; |
|
| 1851 | + } |
|
| 1852 | + wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1853 | + |
|
| 1854 | + echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | + echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1856 | + |
|
| 1857 | + }// end course_notification_meta_box_content |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * Store the setting for the course notification setting. |
|
| 1861 | + * |
|
| 1862 | + * @hooked int save_post |
|
| 1863 | + * @since 1.8.0 |
|
| 1864 | + * |
|
| 1865 | + * @param $course_id |
|
| 1866 | + */ |
|
| 1867 | + public function save_course_notification_meta_box( $course_id ){ |
|
| 1868 | + |
|
| 1869 | + if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | + || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1871 | + return; |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1875 | + $new_val = true; |
|
| 1876 | + }else{ |
|
| 1877 | + $new_val = false; |
|
| 1878 | + } |
|
| 1879 | + |
|
| 1880 | + update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1881 | + |
|
| 1882 | + }// end save notification meta box |
|
| 1883 | + |
|
| 1884 | + /** |
|
| 1885 | + * Backwards compatibility hooks added to ensure that |
|
| 1886 | + * plugins and other parts of sensei still works. |
|
| 1887 | + * |
|
| 1888 | + * This function hooks into `sensei_course_content_inside_before` |
|
| 1889 | + * |
|
| 1890 | + * @since 1.9 |
|
| 1891 | + * |
|
| 1892 | + * @param WP_Post $post |
|
| 1893 | + */ |
|
| 1894 | + public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1895 | + |
|
| 1896 | + sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | + sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1898 | + |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + /** |
|
| 1902 | + * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1903 | + * |
|
| 1904 | + * hooked into 'sensei_loop_course_before' |
|
| 1905 | + * |
|
| 1906 | + * @since 1.9 |
|
| 1907 | + * |
|
| 1908 | + * @global WP_Post $post |
|
| 1909 | + */ |
|
| 1910 | + public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1911 | + |
|
| 1912 | + global $post; |
|
| 1913 | + sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1914 | + |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + /** |
|
| 1918 | + * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1919 | + * |
|
| 1920 | + * hooked into 'sensei_course_content_inside_after' |
|
| 1921 | + * |
|
| 1922 | + * @since 1.9.0 |
|
| 1923 | + * |
|
| 1924 | + * @param WP_Post $course |
|
| 1925 | + */ |
|
| 1926 | + public function the_course_free_lesson_preview( $course ){ |
|
| 1927 | + // Meta data |
|
| 1928 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1929 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1930 | + |
|
| 1931 | + if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1932 | + ?> |
|
| 1933 | 1933 | <p class="sensei-free-lessons"> |
| 1934 | 1934 | <a href="<?php echo get_permalink(); ?>"> |
| 1935 | 1935 | <?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
@@ -1938,22 +1938,22 @@ discard block |
||
| 1938 | 1938 | </p> |
| 1939 | 1939 | |
| 1940 | 1940 | <?php |
| 1941 | - } |
|
| 1942 | - } |
|
| 1941 | + } |
|
| 1942 | + } |
|
| 1943 | 1943 | |
| 1944 | - /** |
|
| 1945 | - * Add course mata to the course meta hook |
|
| 1946 | - * |
|
| 1947 | - * @since 1.9.0 |
|
| 1948 | - * @param WP_Post $course |
|
| 1949 | - */ |
|
| 1950 | - public function the_course_meta( $course ){ |
|
| 1951 | - echo '<p class="sensei-course-meta">'; |
|
| 1944 | + /** |
|
| 1945 | + * Add course mata to the course meta hook |
|
| 1946 | + * |
|
| 1947 | + * @since 1.9.0 |
|
| 1948 | + * @param WP_Post $course |
|
| 1949 | + */ |
|
| 1950 | + public function the_course_meta( $course ){ |
|
| 1951 | + echo '<p class="sensei-course-meta">'; |
|
| 1952 | 1952 | |
| 1953 | - $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1954 | - $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1953 | + $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1954 | + $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1955 | 1955 | |
| 1956 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1956 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1957 | 1957 | |
| 1958 | 1958 | <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?> |
| 1959 | 1959 | |
@@ -1971,59 +1971,59 @@ discard block |
||
| 1971 | 1971 | |
| 1972 | 1972 | <?php } // End If Statement |
| 1973 | 1973 | |
| 1974 | - // number of completed lessons |
|
| 1975 | - if( is_user_logged_in() ){ |
|
| 1976 | - $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1977 | - $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1978 | - echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1979 | - } |
|
| 1974 | + // number of completed lessons |
|
| 1975 | + if( is_user_logged_in() ){ |
|
| 1976 | + $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1977 | + $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1978 | + echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1979 | + } |
|
| 1980 | 1980 | |
| 1981 | - sensei_simple_course_price( $course->ID ); |
|
| 1981 | + sensei_simple_course_price( $course->ID ); |
|
| 1982 | 1982 | |
| 1983 | - echo '</p>'; |
|
| 1984 | - } // end the course meta |
|
| 1983 | + echo '</p>'; |
|
| 1984 | + } // end the course meta |
|
| 1985 | 1985 | |
| 1986 | - /** |
|
| 1987 | - * Filter the classes attached to a post types for courses |
|
| 1988 | - * and add a status class for when the user is logged in. |
|
| 1989 | - * |
|
| 1990 | - * @param $classes |
|
| 1991 | - * @param $class |
|
| 1992 | - * @param $post_id |
|
| 1993 | - * |
|
| 1994 | - * @return array $classes |
|
| 1995 | - */ |
|
| 1996 | - public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1986 | + /** |
|
| 1987 | + * Filter the classes attached to a post types for courses |
|
| 1988 | + * and add a status class for when the user is logged in. |
|
| 1989 | + * |
|
| 1990 | + * @param $classes |
|
| 1991 | + * @param $class |
|
| 1992 | + * @param $post_id |
|
| 1993 | + * |
|
| 1994 | + * @return array $classes |
|
| 1995 | + */ |
|
| 1996 | + public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1997 | 1997 | |
| 1998 | - if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 1998 | + if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 1999 | 1999 | |
| 2000 | - if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2000 | + if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2001 | 2001 | |
| 2002 | - $classes[] = 'user-status-completed'; |
|
| 2002 | + $classes[] = 'user-status-completed'; |
|
| 2003 | 2003 | |
| 2004 | - }else{ |
|
| 2004 | + }else{ |
|
| 2005 | 2005 | |
| 2006 | - $classes[] = 'user-status-active'; |
|
| 2006 | + $classes[] = 'user-status-active'; |
|
| 2007 | 2007 | |
| 2008 | - } |
|
| 2008 | + } |
|
| 2009 | 2009 | |
| 2010 | - } |
|
| 2010 | + } |
|
| 2011 | 2011 | |
| 2012 | - return $classes; |
|
| 2012 | + return $classes; |
|
| 2013 | 2013 | |
| 2014 | - }// end add_course_user_status_class |
|
| 2014 | + }// end add_course_user_status_class |
|
| 2015 | 2015 | |
| 2016 | - /** |
|
| 2017 | - * Prints out the course action buttons links |
|
| 2018 | - * |
|
| 2019 | - * - complete course |
|
| 2020 | - * - delete course |
|
| 2021 | - * |
|
| 2022 | - * @param WP_Post $course |
|
| 2023 | - */ |
|
| 2024 | - public static function the_course_action_buttons( $course ){ |
|
| 2016 | + /** |
|
| 2017 | + * Prints out the course action buttons links |
|
| 2018 | + * |
|
| 2019 | + * - complete course |
|
| 2020 | + * - delete course |
|
| 2021 | + * |
|
| 2022 | + * @param WP_Post $course |
|
| 2023 | + */ |
|
| 2024 | + public static function the_course_action_buttons( $course ){ |
|
| 2025 | 2025 | |
| 2026 | - if( is_user_logged_in() ) { ?> |
|
| 2026 | + if( is_user_logged_in() ) { ?> |
|
| 2027 | 2027 | |
| 2028 | 2028 | <section class="entry-actions"> |
| 2029 | 2029 | <form method="POST" action="<?php echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>"> |
@@ -2042,32 +2042,32 @@ discard block |
||
| 2042 | 2042 | |
| 2043 | 2043 | <?php } // End If Statement |
| 2044 | 2044 | |
| 2045 | - $course_purchased = false; |
|
| 2046 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2047 | - // Get the product ID |
|
| 2048 | - $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2049 | - if ( 0 < $wc_post_id ) { |
|
| 2045 | + $course_purchased = false; |
|
| 2046 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2047 | + // Get the product ID |
|
| 2048 | + $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2049 | + if ( 0 < $wc_post_id ) { |
|
| 2050 | 2050 | |
| 2051 | - $user = wp_get_current_user(); |
|
| 2052 | - $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2051 | + $user = wp_get_current_user(); |
|
| 2052 | + $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2053 | 2053 | |
| 2054 | - } // End If Statement |
|
| 2055 | - } // End If Statement |
|
| 2054 | + } // End If Statement |
|
| 2055 | + } // End If Statement |
|
| 2056 | 2056 | |
| 2057 | - if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2057 | + if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2058 | 2058 | |
| 2059 | 2059 | <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span> |
| 2060 | 2060 | |
| 2061 | 2061 | <?php } // End If Statement |
| 2062 | 2062 | |
| 2063 | - $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2064 | - $results_link = ''; |
|
| 2065 | - if( $has_quizzes ){ |
|
| 2066 | - $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2067 | - } |
|
| 2063 | + $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2064 | + $results_link = ''; |
|
| 2065 | + if( $has_quizzes ){ |
|
| 2066 | + $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2067 | + } |
|
| 2068 | 2068 | |
| 2069 | - // Output only if there is content to display |
|
| 2070 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2069 | + // Output only if there is content to display |
|
| 2070 | + if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2071 | 2071 | |
| 2072 | 2072 | <p class="sensei-results-links"> |
| 2073 | 2073 | <?php echo apply_filters( 'sensei_results_links', $results_link ); ?> |
@@ -2079,440 +2079,440 @@ discard block |
||
| 2079 | 2079 | |
| 2080 | 2080 | <?php }// end if is user logged in |
| 2081 | 2081 | |
| 2082 | - }// end the_course_action_buttons |
|
| 2083 | - |
|
| 2084 | - /** |
|
| 2085 | - * This function alter the main query on the course archive page. |
|
| 2086 | - * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2087 | - * |
|
| 2088 | - * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2089 | - * query parameters via the arguments. |
|
| 2090 | - * |
|
| 2091 | - * This function is hooked into pre_get_posts filter |
|
| 2092 | - * |
|
| 2093 | - * @since 1.9.0 |
|
| 2094 | - * |
|
| 2095 | - * @param WP_Query $query |
|
| 2096 | - * @return WP_Query $query |
|
| 2097 | - */ |
|
| 2098 | - public static function course_query_filter( $query ){ |
|
| 2099 | - |
|
| 2100 | - // exit early for no course queries and admin queries |
|
| 2101 | - if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2102 | - return $query; |
|
| 2103 | - } |
|
| 2104 | - |
|
| 2105 | - global $post; // used to get the current page id for my courses |
|
| 2106 | - |
|
| 2107 | - // for the course archive page |
|
| 2108 | - if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2109 | - { |
|
| 2110 | - |
|
| 2111 | - $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2112 | - |
|
| 2113 | - } |
|
| 2114 | - // for the my courses page |
|
| 2115 | - elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2116 | - { |
|
| 2117 | - |
|
| 2118 | - $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2119 | - |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - return $query; |
|
| 2123 | - |
|
| 2124 | - }// end course_query_filter |
|
| 2125 | - |
|
| 2126 | - /** |
|
| 2127 | - * Determine the class of the course loop |
|
| 2128 | - * |
|
| 2129 | - * This will output .first or .last and .course-item-number-x |
|
| 2130 | - * |
|
| 2131 | - * @return array $extra_classes |
|
| 2132 | - * @since 1.9.0 |
|
| 2133 | - */ |
|
| 2134 | - public static function get_course_loop_content_class () |
|
| 2135 | - { |
|
| 2136 | - |
|
| 2137 | - global $sensei_course_loop; |
|
| 2138 | - |
|
| 2139 | - |
|
| 2140 | - if( !isset( $sensei_course_loop ) ){ |
|
| 2141 | - $sensei_course_loop = array(); |
|
| 2142 | - } |
|
| 2143 | - |
|
| 2144 | - if (!isset($sensei_course_loop['counter'])) { |
|
| 2145 | - $sensei_course_loop['counter'] = 0; |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - if (!isset($sensei_course_loop['columns'])) { |
|
| 2149 | - $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - // increment the counter |
|
| 2153 | - $sensei_course_loop['counter']++; |
|
| 2154 | - |
|
| 2155 | - $extra_classes = array(); |
|
| 2156 | - if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2157 | - $extra_classes[] = 'first'; |
|
| 2158 | - } |
|
| 2159 | - |
|
| 2160 | - if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2161 | - $extra_classes[] = 'last'; |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - // add the item number to the classes as well. |
|
| 2165 | - $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2166 | - |
|
| 2167 | - /** |
|
| 2168 | - * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2169 | - * which is called from the course loop content-course.php |
|
| 2170 | - * |
|
| 2171 | - * @since 1.9.0 |
|
| 2172 | - * |
|
| 2173 | - * @param array $extra_classes |
|
| 2174 | - * @param WP_Post $loop_current_course |
|
| 2175 | - */ |
|
| 2176 | - return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2177 | - |
|
| 2178 | - }// end get_course_loop_class |
|
| 2179 | - |
|
| 2180 | - /** |
|
| 2181 | - * Get the number of columns set for Sensei courses |
|
| 2182 | - * |
|
| 2183 | - * @since 1.9.0 |
|
| 2184 | - * @return mixed|void |
|
| 2185 | - */ |
|
| 2186 | - public static function get_loop_number_of_columns(){ |
|
| 2187 | - |
|
| 2188 | - /** |
|
| 2189 | - * Filter the number of columns on the course archive page. |
|
| 2190 | - * |
|
| 2191 | - * @since 1.9.0 |
|
| 2192 | - * @param int $number_of_columns default 1 |
|
| 2193 | - */ |
|
| 2194 | - return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2195 | - |
|
| 2196 | - } |
|
| 2197 | - |
|
| 2198 | - /** |
|
| 2199 | - * Output the course archive filter markup |
|
| 2200 | - * |
|
| 2201 | - * hooked into sensei_loop_course_before |
|
| 2202 | - * |
|
| 2203 | - * @since 1.9.0 |
|
| 2204 | - * @param |
|
| 2205 | - */ |
|
| 2206 | - public static function course_archive_sorting( $query ){ |
|
| 2207 | - |
|
| 2208 | - // don't show on category pages and other pages |
|
| 2209 | - if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2210 | - return; |
|
| 2211 | - } |
|
| 2212 | - |
|
| 2213 | - /** |
|
| 2214 | - * Filter the sensei archive course order by values |
|
| 2215 | - * |
|
| 2216 | - * @since 1.9.0 |
|
| 2217 | - * @param array $options { |
|
| 2218 | - * @type string $option_value |
|
| 2219 | - * @type string $option_string |
|
| 2220 | - * } |
|
| 2221 | - */ |
|
| 2222 | - $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2223 | - "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2224 | - "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2225 | - )); |
|
| 2226 | - |
|
| 2227 | - // setup the currently selected item |
|
| 2228 | - $selected = 'newness'; |
|
| 2229 | - if( isset( $_GET['orderby'] ) ){ |
|
| 2230 | - |
|
| 2231 | - $selected = $_GET[ 'orderby' ]; |
|
| 2232 | - |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - ?> |
|
| 2082 | + }// end the_course_action_buttons |
|
| 2083 | + |
|
| 2084 | + /** |
|
| 2085 | + * This function alter the main query on the course archive page. |
|
| 2086 | + * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2087 | + * |
|
| 2088 | + * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2089 | + * query parameters via the arguments. |
|
| 2090 | + * |
|
| 2091 | + * This function is hooked into pre_get_posts filter |
|
| 2092 | + * |
|
| 2093 | + * @since 1.9.0 |
|
| 2094 | + * |
|
| 2095 | + * @param WP_Query $query |
|
| 2096 | + * @return WP_Query $query |
|
| 2097 | + */ |
|
| 2098 | + public static function course_query_filter( $query ){ |
|
| 2099 | + |
|
| 2100 | + // exit early for no course queries and admin queries |
|
| 2101 | + if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2102 | + return $query; |
|
| 2103 | + } |
|
| 2104 | + |
|
| 2105 | + global $post; // used to get the current page id for my courses |
|
| 2106 | + |
|
| 2107 | + // for the course archive page |
|
| 2108 | + if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2109 | + { |
|
| 2110 | + |
|
| 2111 | + $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2112 | + |
|
| 2113 | + } |
|
| 2114 | + // for the my courses page |
|
| 2115 | + elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2116 | + { |
|
| 2117 | + |
|
| 2118 | + $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2119 | + |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + return $query; |
|
| 2123 | + |
|
| 2124 | + }// end course_query_filter |
|
| 2125 | + |
|
| 2126 | + /** |
|
| 2127 | + * Determine the class of the course loop |
|
| 2128 | + * |
|
| 2129 | + * This will output .first or .last and .course-item-number-x |
|
| 2130 | + * |
|
| 2131 | + * @return array $extra_classes |
|
| 2132 | + * @since 1.9.0 |
|
| 2133 | + */ |
|
| 2134 | + public static function get_course_loop_content_class () |
|
| 2135 | + { |
|
| 2136 | + |
|
| 2137 | + global $sensei_course_loop; |
|
| 2138 | + |
|
| 2139 | + |
|
| 2140 | + if( !isset( $sensei_course_loop ) ){ |
|
| 2141 | + $sensei_course_loop = array(); |
|
| 2142 | + } |
|
| 2143 | + |
|
| 2144 | + if (!isset($sensei_course_loop['counter'])) { |
|
| 2145 | + $sensei_course_loop['counter'] = 0; |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + if (!isset($sensei_course_loop['columns'])) { |
|
| 2149 | + $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + // increment the counter |
|
| 2153 | + $sensei_course_loop['counter']++; |
|
| 2154 | + |
|
| 2155 | + $extra_classes = array(); |
|
| 2156 | + if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2157 | + $extra_classes[] = 'first'; |
|
| 2158 | + } |
|
| 2159 | + |
|
| 2160 | + if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2161 | + $extra_classes[] = 'last'; |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + // add the item number to the classes as well. |
|
| 2165 | + $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2166 | + |
|
| 2167 | + /** |
|
| 2168 | + * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2169 | + * which is called from the course loop content-course.php |
|
| 2170 | + * |
|
| 2171 | + * @since 1.9.0 |
|
| 2172 | + * |
|
| 2173 | + * @param array $extra_classes |
|
| 2174 | + * @param WP_Post $loop_current_course |
|
| 2175 | + */ |
|
| 2176 | + return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2177 | + |
|
| 2178 | + }// end get_course_loop_class |
|
| 2179 | + |
|
| 2180 | + /** |
|
| 2181 | + * Get the number of columns set for Sensei courses |
|
| 2182 | + * |
|
| 2183 | + * @since 1.9.0 |
|
| 2184 | + * @return mixed|void |
|
| 2185 | + */ |
|
| 2186 | + public static function get_loop_number_of_columns(){ |
|
| 2187 | + |
|
| 2188 | + /** |
|
| 2189 | + * Filter the number of columns on the course archive page. |
|
| 2190 | + * |
|
| 2191 | + * @since 1.9.0 |
|
| 2192 | + * @param int $number_of_columns default 1 |
|
| 2193 | + */ |
|
| 2194 | + return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2195 | + |
|
| 2196 | + } |
|
| 2197 | + |
|
| 2198 | + /** |
|
| 2199 | + * Output the course archive filter markup |
|
| 2200 | + * |
|
| 2201 | + * hooked into sensei_loop_course_before |
|
| 2202 | + * |
|
| 2203 | + * @since 1.9.0 |
|
| 2204 | + * @param |
|
| 2205 | + */ |
|
| 2206 | + public static function course_archive_sorting( $query ){ |
|
| 2207 | + |
|
| 2208 | + // don't show on category pages and other pages |
|
| 2209 | + if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2210 | + return; |
|
| 2211 | + } |
|
| 2212 | + |
|
| 2213 | + /** |
|
| 2214 | + * Filter the sensei archive course order by values |
|
| 2215 | + * |
|
| 2216 | + * @since 1.9.0 |
|
| 2217 | + * @param array $options { |
|
| 2218 | + * @type string $option_value |
|
| 2219 | + * @type string $option_string |
|
| 2220 | + * } |
|
| 2221 | + */ |
|
| 2222 | + $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2223 | + "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2224 | + "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2225 | + )); |
|
| 2226 | + |
|
| 2227 | + // setup the currently selected item |
|
| 2228 | + $selected = 'newness'; |
|
| 2229 | + if( isset( $_GET['orderby'] ) ){ |
|
| 2230 | + |
|
| 2231 | + $selected = $_GET[ 'orderby' ]; |
|
| 2232 | + |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + ?> |
|
| 2236 | 2236 | |
| 2237 | 2237 | <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST"> |
| 2238 | 2238 | <select name="course-orderby" class="orderby"> |
| 2239 | 2239 | <?php |
| 2240 | - foreach( $course_order_by_options as $value => $text ){ |
|
| 2240 | + foreach( $course_order_by_options as $value => $text ){ |
|
| 2241 | 2241 | |
| 2242 | - echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2242 | + echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2243 | 2243 | |
| 2244 | - } |
|
| 2245 | - ?> |
|
| 2244 | + } |
|
| 2245 | + ?> |
|
| 2246 | 2246 | </select> |
| 2247 | 2247 | </form> |
| 2248 | 2248 | |
| 2249 | 2249 | <?php |
| 2250 | - }// end course archive filters |
|
| 2251 | - |
|
| 2252 | - /** |
|
| 2253 | - * Output the course archive filter markup |
|
| 2254 | - * |
|
| 2255 | - * hooked into sensei_loop_course_before |
|
| 2256 | - * |
|
| 2257 | - * @since 1.9.0 |
|
| 2258 | - * @param |
|
| 2259 | - */ |
|
| 2260 | - public static function course_archive_filters( $query ){ |
|
| 2261 | - |
|
| 2262 | - // don't show on category pages |
|
| 2263 | - if( is_tax('course-category') ){ |
|
| 2264 | - return; |
|
| 2265 | - } |
|
| 2266 | - |
|
| 2267 | - /** |
|
| 2268 | - * filter the course archive filter buttons |
|
| 2269 | - * |
|
| 2270 | - * @since 1.9.0 |
|
| 2271 | - * @param array $filters{ |
|
| 2272 | - * @type array ( $id, $url , $title ) |
|
| 2273 | - * } |
|
| 2274 | - * |
|
| 2275 | - */ |
|
| 2276 | - $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2277 | - array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2278 | - array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2279 | - )); |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - ?> |
|
| 2250 | + }// end course archive filters |
|
| 2251 | + |
|
| 2252 | + /** |
|
| 2253 | + * Output the course archive filter markup |
|
| 2254 | + * |
|
| 2255 | + * hooked into sensei_loop_course_before |
|
| 2256 | + * |
|
| 2257 | + * @since 1.9.0 |
|
| 2258 | + * @param |
|
| 2259 | + */ |
|
| 2260 | + public static function course_archive_filters( $query ){ |
|
| 2261 | + |
|
| 2262 | + // don't show on category pages |
|
| 2263 | + if( is_tax('course-category') ){ |
|
| 2264 | + return; |
|
| 2265 | + } |
|
| 2266 | + |
|
| 2267 | + /** |
|
| 2268 | + * filter the course archive filter buttons |
|
| 2269 | + * |
|
| 2270 | + * @since 1.9.0 |
|
| 2271 | + * @param array $filters{ |
|
| 2272 | + * @type array ( $id, $url , $title ) |
|
| 2273 | + * } |
|
| 2274 | + * |
|
| 2275 | + */ |
|
| 2276 | + $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2277 | + array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2278 | + array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2279 | + )); |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + ?> |
|
| 2283 | 2283 | <ul class="sensei-course-filters clearfix" > |
| 2284 | 2284 | <?php |
| 2285 | 2285 | |
| 2286 | - //determine the current active url |
|
| 2287 | - $current_url = Sensei_Utils::get_current_url(); |
|
| 2286 | + //determine the current active url |
|
| 2287 | + $current_url = Sensei_Utils::get_current_url(); |
|
| 2288 | 2288 | |
| 2289 | - foreach( $filters as $filter ) { |
|
| 2289 | + foreach( $filters as $filter ) { |
|
| 2290 | 2290 | |
| 2291 | - $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2291 | + $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2292 | 2292 | |
| 2293 | - echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2293 | + echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2294 | 2294 | |
| 2295 | - } |
|
| 2296 | - ?> |
|
| 2295 | + } |
|
| 2296 | + ?> |
|
| 2297 | 2297 | |
| 2298 | 2298 | </ul> |
| 2299 | 2299 | |
| 2300 | 2300 | <?php |
| 2301 | 2301 | |
| 2302 | - } |
|
| 2302 | + } |
|
| 2303 | 2303 | |
| 2304 | - /** |
|
| 2305 | - * if the featured link is clicked on the course archive page |
|
| 2306 | - * filter the courses returned to only show those featured |
|
| 2307 | - * |
|
| 2308 | - * Hooked into pre_get_posts |
|
| 2309 | - * |
|
| 2310 | - * @since 1.9.0 |
|
| 2311 | - * @param WP_Query $query |
|
| 2312 | - * @return WP_Query $query |
|
| 2313 | - */ |
|
| 2314 | - public static function course_archive_featured_filter( $query ){ |
|
| 2315 | - |
|
| 2316 | - if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2317 | - //setup meta query for featured courses |
|
| 2318 | - $query->set( 'meta_value', 'featured' ); |
|
| 2319 | - $query->set( 'meta_key', '_course_featured' ); |
|
| 2320 | - $query->set( 'meta_compare', '=' ); |
|
| 2321 | - } |
|
| 2322 | - |
|
| 2323 | - return $query; |
|
| 2324 | - } |
|
| 2325 | - |
|
| 2326 | - /** |
|
| 2327 | - * if the course order drop down is changed |
|
| 2328 | - * |
|
| 2329 | - * Hooked into pre_get_posts |
|
| 2330 | - * |
|
| 2331 | - * @since 1.9.0 |
|
| 2332 | - * @param WP_Query $query |
|
| 2333 | - * @return WP_Query $query |
|
| 2334 | - */ |
|
| 2335 | - public static function course_archive_order_by_title( $query ){ |
|
| 2336 | - |
|
| 2337 | - if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2338 | - && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2339 | - // setup the order by title for this query |
|
| 2340 | - $query->set( 'orderby', 'title' ); |
|
| 2341 | - $query->set( 'order', 'ASC' ); |
|
| 2342 | - } |
|
| 2343 | - |
|
| 2344 | - return $query; |
|
| 2345 | - } |
|
| 2346 | - |
|
| 2347 | - |
|
| 2348 | - /** |
|
| 2349 | - * Get the link to the courses page. This will be the course post type archive |
|
| 2350 | - * page link or the page the user set in their settings |
|
| 2351 | - * |
|
| 2352 | - * @since 1.9.0 |
|
| 2353 | - * @return string $course_page_url |
|
| 2354 | - */ |
|
| 2355 | - public static function get_courses_page_url(){ |
|
| 2356 | - |
|
| 2357 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2358 | - $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2304 | + /** |
|
| 2305 | + * if the featured link is clicked on the course archive page |
|
| 2306 | + * filter the courses returned to only show those featured |
|
| 2307 | + * |
|
| 2308 | + * Hooked into pre_get_posts |
|
| 2309 | + * |
|
| 2310 | + * @since 1.9.0 |
|
| 2311 | + * @param WP_Query $query |
|
| 2312 | + * @return WP_Query $query |
|
| 2313 | + */ |
|
| 2314 | + public static function course_archive_featured_filter( $query ){ |
|
| 2359 | 2315 | |
| 2360 | - return $course_page_url; |
|
| 2361 | - |
|
| 2362 | - }// get_course_url |
|
| 2316 | + if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2317 | + //setup meta query for featured courses |
|
| 2318 | + $query->set( 'meta_value', 'featured' ); |
|
| 2319 | + $query->set( 'meta_key', '_course_featured' ); |
|
| 2320 | + $query->set( 'meta_compare', '=' ); |
|
| 2321 | + } |
|
| 2363 | 2322 | |
| 2364 | - /** |
|
| 2365 | - * Output the headers on the course archive page |
|
| 2366 | - * |
|
| 2367 | - * Hooked into the sensei_archive_title |
|
| 2368 | - * |
|
| 2369 | - * @since 1.9.0 |
|
| 2370 | - * @param string $query_type |
|
| 2371 | - * @param string $before_html |
|
| 2372 | - * @param string $after_html |
|
| 2373 | - * @return void |
|
| 2374 | - */ |
|
| 2375 | - public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2323 | + return $query; |
|
| 2324 | + } |
|
| 2376 | 2325 | |
| 2377 | - if( ! is_post_type_archive('course') ){ |
|
| 2378 | - return; |
|
| 2379 | - } |
|
| 2326 | + /** |
|
| 2327 | + * if the course order drop down is changed |
|
| 2328 | + * |
|
| 2329 | + * Hooked into pre_get_posts |
|
| 2330 | + * |
|
| 2331 | + * @since 1.9.0 |
|
| 2332 | + * @param WP_Query $query |
|
| 2333 | + * @return WP_Query $query |
|
| 2334 | + */ |
|
| 2335 | + public static function course_archive_order_by_title( $query ){ |
|
| 2380 | 2336 | |
| 2381 | - // deprecated since 1.9.0 |
|
| 2382 | - sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2337 | + if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2338 | + && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2339 | + // setup the order by title for this query |
|
| 2340 | + $query->set( 'orderby', 'title' ); |
|
| 2341 | + $query->set( 'order', 'ASC' ); |
|
| 2342 | + } |
|
| 2383 | 2343 | |
| 2384 | - $html = ''; |
|
| 2344 | + return $query; |
|
| 2345 | + } |
|
| 2385 | 2346 | |
| 2386 | - if( empty( $before_html ) ){ |
|
| 2387 | 2347 | |
| 2388 | - $before_html = '<header class="archive-header"><h1>'; |
|
| 2348 | + /** |
|
| 2349 | + * Get the link to the courses page. This will be the course post type archive |
|
| 2350 | + * page link or the page the user set in their settings |
|
| 2351 | + * |
|
| 2352 | + * @since 1.9.0 |
|
| 2353 | + * @return string $course_page_url |
|
| 2354 | + */ |
|
| 2355 | + public static function get_courses_page_url(){ |
|
| 2389 | 2356 | |
| 2390 | - } |
|
| 2357 | + $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2358 | + $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2391 | 2359 | |
| 2392 | - if( empty( $after_html ) ){ |
|
| 2360 | + return $course_page_url; |
|
| 2393 | 2361 | |
| 2394 | - $after_html = '</h1></header>'; |
|
| 2362 | + }// get_course_url |
|
| 2395 | 2363 | |
| 2396 | - } |
|
| 2364 | + /** |
|
| 2365 | + * Output the headers on the course archive page |
|
| 2366 | + * |
|
| 2367 | + * Hooked into the sensei_archive_title |
|
| 2368 | + * |
|
| 2369 | + * @since 1.9.0 |
|
| 2370 | + * @param string $query_type |
|
| 2371 | + * @param string $before_html |
|
| 2372 | + * @param string $after_html |
|
| 2373 | + * @return void |
|
| 2374 | + */ |
|
| 2375 | + public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2397 | 2376 | |
| 2398 | - if ( is_tax( 'course-category' ) ) { |
|
| 2377 | + if( ! is_post_type_archive('course') ){ |
|
| 2378 | + return; |
|
| 2379 | + } |
|
| 2399 | 2380 | |
| 2400 | - global $wp_query; |
|
| 2381 | + // deprecated since 1.9.0 |
|
| 2382 | + sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2401 | 2383 | |
| 2402 | - $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2403 | - $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2404 | - $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2405 | - $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2406 | - echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2407 | - return; |
|
| 2384 | + $html = ''; |
|
| 2408 | 2385 | |
| 2409 | - } // End If Statement |
|
| 2386 | + if( empty( $before_html ) ){ |
|
| 2410 | 2387 | |
| 2411 | - switch ( $query_type ) { |
|
| 2412 | - case 'newcourses': |
|
| 2413 | - $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2414 | - break; |
|
| 2415 | - case 'featuredcourses': |
|
| 2416 | - $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2417 | - break; |
|
| 2418 | - case 'freecourses': |
|
| 2419 | - $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2420 | - break; |
|
| 2421 | - case 'paidcourses': |
|
| 2422 | - $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2423 | - break; |
|
| 2424 | - default: |
|
| 2425 | - $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2426 | - break; |
|
| 2427 | - } // End Switch Statement |
|
| 2388 | + $before_html = '<header class="archive-header"><h1>'; |
|
| 2428 | 2389 | |
| 2429 | - echo apply_filters( 'course_archive_title', $html ); |
|
| 2390 | + } |
|
| 2430 | 2391 | |
| 2431 | - }//course_archive_header |
|
| 2392 | + if( empty( $after_html ) ){ |
|
| 2432 | 2393 | |
| 2394 | + $after_html = '</h1></header>'; |
|
| 2433 | 2395 | |
| 2434 | - /** |
|
| 2435 | - * Filter the single course content |
|
| 2436 | - * taking into account if the user has access. |
|
| 2437 | - * |
|
| 2438 | - * @1.9.0 |
|
| 2439 | - * |
|
| 2440 | - * @param string $content |
|
| 2441 | - * @return string $content or $excerpt |
|
| 2442 | - */ |
|
| 2443 | - public static function single_course_content( $content ){ |
|
| 2396 | + } |
|
| 2444 | 2397 | |
| 2445 | - if( ! is_singular('course') ){ |
|
| 2398 | + if ( is_tax( 'course-category' ) ) { |
|
| 2446 | 2399 | |
| 2447 | - return $content; |
|
| 2400 | + global $wp_query; |
|
| 2448 | 2401 | |
| 2449 | - } |
|
| 2402 | + $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2403 | + $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2404 | + $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2405 | + $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2406 | + echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2407 | + return; |
|
| 2450 | 2408 | |
| 2451 | - // Content Access Permissions |
|
| 2452 | - $access_permission = false; |
|
| 2409 | + } // End If Statement |
|
| 2453 | 2410 | |
| 2454 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2411 | + switch ( $query_type ) { |
|
| 2412 | + case 'newcourses': |
|
| 2413 | + $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2414 | + break; |
|
| 2415 | + case 'featuredcourses': |
|
| 2416 | + $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2417 | + break; |
|
| 2418 | + case 'freecourses': |
|
| 2419 | + $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2420 | + break; |
|
| 2421 | + case 'paidcourses': |
|
| 2422 | + $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2423 | + break; |
|
| 2424 | + default: |
|
| 2425 | + $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2426 | + break; |
|
| 2427 | + } // End Switch Statement |
|
| 2455 | 2428 | |
| 2456 | - $access_permission = true; |
|
| 2429 | + echo apply_filters( 'course_archive_title', $html ); |
|
| 2457 | 2430 | |
| 2458 | - } // End If Statement |
|
| 2431 | + }//course_archive_header |
|
| 2459 | 2432 | |
| 2460 | - // Check if the user is taking the course |
|
| 2461 | - $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2462 | 2433 | |
| 2463 | - if(Sensei_WC::is_woocommerce_active()) { |
|
| 2434 | + /** |
|
| 2435 | + * Filter the single course content |
|
| 2436 | + * taking into account if the user has access. |
|
| 2437 | + * |
|
| 2438 | + * @1.9.0 |
|
| 2439 | + * |
|
| 2440 | + * @param string $content |
|
| 2441 | + * @return string $content or $excerpt |
|
| 2442 | + */ |
|
| 2443 | + public static function single_course_content( $content ){ |
|
| 2464 | 2444 | |
| 2465 | - $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2466 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2445 | + if( ! is_singular('course') ){ |
|
| 2467 | 2446 | |
| 2468 | - $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2447 | + return $content; |
|
| 2469 | 2448 | |
| 2470 | - } else { |
|
| 2449 | + } |
|
| 2471 | 2450 | |
| 2472 | - $has_product_attached = false; |
|
| 2451 | + // Content Access Permissions |
|
| 2452 | + $access_permission = false; |
|
| 2473 | 2453 | |
| 2474 | - } |
|
| 2454 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2475 | 2455 | |
| 2476 | - if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2477 | - || ( $access_permission && !$has_product_attached) |
|
| 2478 | - || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2456 | + $access_permission = true; |
|
| 2479 | 2457 | |
| 2480 | - return $content; |
|
| 2458 | + } // End If Statement |
|
| 2481 | 2459 | |
| 2482 | - } else { |
|
| 2460 | + // Check if the user is taking the course |
|
| 2461 | + $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2483 | 2462 | |
| 2484 | - return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2463 | + if(Sensei_WC::is_woocommerce_active()) { |
|
| 2485 | 2464 | |
| 2486 | - } |
|
| 2465 | + $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2466 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2487 | 2467 | |
| 2488 | - }// end single_course_content |
|
| 2468 | + $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2489 | 2469 | |
| 2490 | - /** |
|
| 2491 | - * Output the the single course lessons title with markup. |
|
| 2492 | - * |
|
| 2493 | - * @since 1.9.0 |
|
| 2494 | - */ |
|
| 2495 | - public static function the_course_lessons_title(){ |
|
| 2496 | - global $post; |
|
| 2497 | - $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2498 | - $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2470 | + } else { |
|
| 2471 | + |
|
| 2472 | + $has_product_attached = false; |
|
| 2473 | + |
|
| 2474 | + } |
|
| 2499 | 2475 | |
| 2500 | - // title should be Other Lessons if there are lessons belonging to models. |
|
| 2501 | - $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2502 | - if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2476 | + if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2477 | + || ( $access_permission && !$has_product_attached) |
|
| 2478 | + || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2503 | 2479 | |
| 2504 | - $title = __('Lessons', 'woothemes-sensei'); |
|
| 2480 | + return $content; |
|
| 2505 | 2481 | |
| 2506 | - } |
|
| 2482 | + } else { |
|
| 2507 | 2483 | |
| 2508 | - /** |
|
| 2509 | - * hook document in class-woothemes-sensei-message.php |
|
| 2510 | - */ |
|
| 2511 | - $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2484 | + return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2512 | 2485 | |
| 2513 | - ob_start(); // start capturing the following output. |
|
| 2486 | + } |
|
| 2514 | 2487 | |
| 2515 | - ?> |
|
| 2488 | + }// end single_course_content |
|
| 2489 | + |
|
| 2490 | + /** |
|
| 2491 | + * Output the the single course lessons title with markup. |
|
| 2492 | + * |
|
| 2493 | + * @since 1.9.0 |
|
| 2494 | + */ |
|
| 2495 | + public static function the_course_lessons_title(){ |
|
| 2496 | + global $post; |
|
| 2497 | + $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2498 | + $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2499 | + |
|
| 2500 | + // title should be Other Lessons if there are lessons belonging to models. |
|
| 2501 | + $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2502 | + if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2503 | + |
|
| 2504 | + $title = __('Lessons', 'woothemes-sensei'); |
|
| 2505 | + |
|
| 2506 | + } |
|
| 2507 | + |
|
| 2508 | + /** |
|
| 2509 | + * hook document in class-woothemes-sensei-message.php |
|
| 2510 | + */ |
|
| 2511 | + $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2512 | + |
|
| 2513 | + ob_start(); // start capturing the following output. |
|
| 2514 | + |
|
| 2515 | + ?> |
|
| 2516 | 2516 | |
| 2517 | 2517 | <header> |
| 2518 | 2518 | <h2> <?php echo $title; ?> </h2> |
@@ -2520,277 +2520,277 @@ discard block |
||
| 2520 | 2520 | |
| 2521 | 2521 | <?php |
| 2522 | 2522 | |
| 2523 | - /** |
|
| 2524 | - * Filter the title and markup that appears above the lessons on a single course |
|
| 2525 | - * page. |
|
| 2526 | - * |
|
| 2527 | - * @since 1.9.0 |
|
| 2528 | - * @param string $lessons_title_html |
|
| 2529 | - */ |
|
| 2530 | - echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2531 | - |
|
| 2532 | - }// end the_course_lessons_title |
|
| 2533 | - |
|
| 2534 | - /** |
|
| 2535 | - * This function loads the global wp_query object with with lessons |
|
| 2536 | - * of the current course. It is designed to be used on the single-course template |
|
| 2537 | - * and expects the global post to be a singular course. |
|
| 2538 | - * |
|
| 2539 | - * This function excludes lessons belonging to modules as they are |
|
| 2540 | - * queried separately. |
|
| 2541 | - * |
|
| 2542 | - * @since 1.9.0 |
|
| 2543 | - * @global $wp_query |
|
| 2544 | - */ |
|
| 2545 | - public static function load_single_course_lessons_query(){ |
|
| 2546 | - |
|
| 2547 | - global $post, $wp_query; |
|
| 2523 | + /** |
|
| 2524 | + * Filter the title and markup that appears above the lessons on a single course |
|
| 2525 | + * page. |
|
| 2526 | + * |
|
| 2527 | + * @since 1.9.0 |
|
| 2528 | + * @param string $lessons_title_html |
|
| 2529 | + */ |
|
| 2530 | + echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2548 | 2531 | |
| 2549 | - $course_id = $post->ID; |
|
| 2532 | + }// end the_course_lessons_title |
|
| 2550 | 2533 | |
| 2551 | - if( 'course' != get_post_type( $course_id ) ){ |
|
| 2552 | - return; |
|
| 2553 | - } |
|
| 2534 | + /** |
|
| 2535 | + * This function loads the global wp_query object with with lessons |
|
| 2536 | + * of the current course. It is designed to be used on the single-course template |
|
| 2537 | + * and expects the global post to be a singular course. |
|
| 2538 | + * |
|
| 2539 | + * This function excludes lessons belonging to modules as they are |
|
| 2540 | + * queried separately. |
|
| 2541 | + * |
|
| 2542 | + * @since 1.9.0 |
|
| 2543 | + * @global $wp_query |
|
| 2544 | + */ |
|
| 2545 | + public static function load_single_course_lessons_query(){ |
|
| 2554 | 2546 | |
| 2555 | - $course_lesson_query_args = array( |
|
| 2556 | - 'post_type' => 'lesson', |
|
| 2557 | - 'posts_per_page' => 500, |
|
| 2558 | - 'orderby' => 'date', |
|
| 2559 | - 'order' => 'ASC', |
|
| 2560 | - 'meta_query' => array( |
|
| 2561 | - array( |
|
| 2562 | - 'key' => '_lesson_course', |
|
| 2563 | - 'value' => intval( $course_id ), |
|
| 2564 | - ), |
|
| 2565 | - ), |
|
| 2566 | - 'post_status' => 'public', |
|
| 2567 | - 'suppress_filters' => 0, |
|
| 2568 | - ); |
|
| 2547 | + global $post, $wp_query; |
|
| 2569 | 2548 | |
| 2570 | - // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2571 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2572 | - if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2549 | + $course_id = $post->ID; |
|
| 2573 | 2550 | |
| 2574 | - $terms_ids = array(); |
|
| 2575 | - foreach( $modules as $term ){ |
|
| 2551 | + if( 'course' != get_post_type( $course_id ) ){ |
|
| 2552 | + return; |
|
| 2553 | + } |
|
| 2576 | 2554 | |
| 2577 | - $terms_ids[] = $term->term_id; |
|
| 2555 | + $course_lesson_query_args = array( |
|
| 2556 | + 'post_type' => 'lesson', |
|
| 2557 | + 'posts_per_page' => 500, |
|
| 2558 | + 'orderby' => 'date', |
|
| 2559 | + 'order' => 'ASC', |
|
| 2560 | + 'meta_query' => array( |
|
| 2561 | + array( |
|
| 2562 | + 'key' => '_lesson_course', |
|
| 2563 | + 'value' => intval( $course_id ), |
|
| 2564 | + ), |
|
| 2565 | + ), |
|
| 2566 | + 'post_status' => 'public', |
|
| 2567 | + 'suppress_filters' => 0, |
|
| 2568 | + ); |
|
| 2569 | + |
|
| 2570 | + // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2571 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2572 | + if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2573 | + |
|
| 2574 | + $terms_ids = array(); |
|
| 2575 | + foreach( $modules as $term ){ |
|
| 2576 | + |
|
| 2577 | + $terms_ids[] = $term->term_id; |
|
| 2578 | 2578 | |
| 2579 | - } |
|
| 2579 | + } |
|
| 2580 | 2580 | |
| 2581 | - $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2582 | - array( |
|
| 2583 | - 'taxonomy' => 'module', |
|
| 2584 | - 'field' => 'id', |
|
| 2585 | - 'terms' => $terms_ids, |
|
| 2586 | - 'operator' => 'NOT IN', |
|
| 2587 | - ), |
|
| 2588 | - ); |
|
| 2589 | - } |
|
| 2581 | + $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2582 | + array( |
|
| 2583 | + 'taxonomy' => 'module', |
|
| 2584 | + 'field' => 'id', |
|
| 2585 | + 'terms' => $terms_ids, |
|
| 2586 | + 'operator' => 'NOT IN', |
|
| 2587 | + ), |
|
| 2588 | + ); |
|
| 2589 | + } |
|
| 2590 | 2590 | |
| 2591 | - $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2591 | + $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2592 | 2592 | |
| 2593 | - }// load_single_course_lessons |
|
| 2593 | + }// load_single_course_lessons |
|
| 2594 | 2594 | |
| 2595 | - /** |
|
| 2596 | - * Flush the rewrite rules for a course post type |
|
| 2597 | - * |
|
| 2598 | - * @since 1.9.0 |
|
| 2599 | - * |
|
| 2600 | - * @param $post_id |
|
| 2601 | - */ |
|
| 2602 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 2595 | + /** |
|
| 2596 | + * Flush the rewrite rules for a course post type |
|
| 2597 | + * |
|
| 2598 | + * @since 1.9.0 |
|
| 2599 | + * |
|
| 2600 | + * @param $post_id |
|
| 2601 | + */ |
|
| 2602 | + public static function flush_rewrite_rules( $post_id ){ |
|
| 2603 | 2603 | |
| 2604 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2604 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2605 | 2605 | |
| 2606 | - return; |
|
| 2606 | + return; |
|
| 2607 | 2607 | |
| 2608 | - } |
|
| 2608 | + } |
|
| 2609 | 2609 | |
| 2610 | 2610 | |
| 2611 | - if( 'course' == get_post_type( $post_id ) ){ |
|
| 2611 | + if( 'course' == get_post_type( $post_id ) ){ |
|
| 2612 | 2612 | |
| 2613 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 2613 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 2614 | 2614 | |
| 2615 | - } |
|
| 2615 | + } |
|
| 2616 | 2616 | |
| 2617 | - } |
|
| 2617 | + } |
|
| 2618 | 2618 | |
| 2619 | - /** |
|
| 2620 | - * Optionally return the full content on the single course pages |
|
| 2621 | - * depending on the users course_single_content_display setting |
|
| 2622 | - * |
|
| 2623 | - * @since 1.9.0 |
|
| 2624 | - * @param $excerpt |
|
| 2625 | - * @return string |
|
| 2626 | - */ |
|
| 2627 | - public static function full_content_excerpt_override( $excerpt ){ |
|
| 2619 | + /** |
|
| 2620 | + * Optionally return the full content on the single course pages |
|
| 2621 | + * depending on the users course_single_content_display setting |
|
| 2622 | + * |
|
| 2623 | + * @since 1.9.0 |
|
| 2624 | + * @param $excerpt |
|
| 2625 | + * @return string |
|
| 2626 | + */ |
|
| 2627 | + public static function full_content_excerpt_override( $excerpt ){ |
|
| 2628 | 2628 | |
| 2629 | - if ( is_singular('course') && |
|
| 2630 | - 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2629 | + if ( is_singular('course') && |
|
| 2630 | + 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2631 | 2631 | |
| 2632 | - return get_the_content(); |
|
| 2632 | + return get_the_content(); |
|
| 2633 | 2633 | |
| 2634 | - } else { |
|
| 2634 | + } else { |
|
| 2635 | 2635 | |
| 2636 | - return $excerpt; |
|
| 2636 | + return $excerpt; |
|
| 2637 | 2637 | |
| 2638 | - } |
|
| 2638 | + } |
|
| 2639 | 2639 | |
| 2640 | - } |
|
| 2640 | + } |
|
| 2641 | 2641 | |
| 2642 | - /** |
|
| 2643 | - * Output the course actions like start taking course, register, add to cart etc. |
|
| 2644 | - * |
|
| 2645 | - * @since 1.9.0 |
|
| 2646 | - */ |
|
| 2647 | - public static function the_course_enrolment_actions(){ |
|
| 2648 | - ?> |
|
| 2642 | + /** |
|
| 2643 | + * Output the course actions like start taking course, register, add to cart etc. |
|
| 2644 | + * |
|
| 2645 | + * @since 1.9.0 |
|
| 2646 | + */ |
|
| 2647 | + public static function the_course_enrolment_actions(){ |
|
| 2648 | + ?> |
|
| 2649 | 2649 | <section class="course-meta course-enrolment"> |
| 2650 | 2650 | <?php |
| 2651 | - global $post, $current_user; |
|
| 2652 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2653 | - if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2654 | - |
|
| 2655 | - // Get the product ID |
|
| 2656 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2657 | - |
|
| 2658 | - // Check for woocommerce |
|
| 2659 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2660 | - sensei_wc_add_to_cart($post->ID); |
|
| 2661 | - } else { |
|
| 2662 | - sensei_start_course_form($post->ID); |
|
| 2663 | - } // End If Statement |
|
| 2664 | - |
|
| 2665 | - } elseif ( is_user_logged_in() ) { |
|
| 2666 | - |
|
| 2667 | - // Check if course is completed |
|
| 2668 | - $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2669 | - $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2670 | - // Success message |
|
| 2671 | - if ( $completed_course ) { ?> |
|
| 2651 | + global $post, $current_user; |
|
| 2652 | + $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2653 | + if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2654 | + |
|
| 2655 | + // Get the product ID |
|
| 2656 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2657 | + |
|
| 2658 | + // Check for woocommerce |
|
| 2659 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2660 | + sensei_wc_add_to_cart($post->ID); |
|
| 2661 | + } else { |
|
| 2662 | + sensei_start_course_form($post->ID); |
|
| 2663 | + } // End If Statement |
|
| 2664 | + |
|
| 2665 | + } elseif ( is_user_logged_in() ) { |
|
| 2666 | + |
|
| 2667 | + // Check if course is completed |
|
| 2668 | + $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2669 | + $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2670 | + // Success message |
|
| 2671 | + if ( $completed_course ) { ?> |
|
| 2672 | 2672 | <div class="status completed"><?php _e( 'Completed', 'woothemes-sensei' ); ?></div> |
| 2673 | 2673 | <?php |
| 2674 | - $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2675 | - if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2674 | + $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2675 | + if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2676 | 2676 | <p class="sensei-results-links"> |
| 2677 | 2677 | <?php |
| 2678 | - $results_link = ''; |
|
| 2679 | - if( $has_quizzes ) { |
|
| 2680 | - $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2681 | - } |
|
| 2682 | - $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2683 | - echo $results_link; |
|
| 2684 | - ?></p> |
|
| 2678 | + $results_link = ''; |
|
| 2679 | + if( $has_quizzes ) { |
|
| 2680 | + $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2681 | + } |
|
| 2682 | + $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2683 | + echo $results_link; |
|
| 2684 | + ?></p> |
|
| 2685 | 2685 | <?php } ?> |
| 2686 | 2686 | <?php } else { ?> |
| 2687 | 2687 | <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div> |
| 2688 | 2688 | <?php } |
| 2689 | 2689 | |
| 2690 | - } else { |
|
| 2691 | - // Get the product ID |
|
| 2692 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2693 | - // Check for woocommerce |
|
| 2694 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2690 | + } else { |
|
| 2691 | + // Get the product ID |
|
| 2692 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2693 | + // Check for woocommerce |
|
| 2694 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2695 | 2695 | |
| 2696 | - sensei_wc_add_to_cart($post->ID); |
|
| 2696 | + sensei_wc_add_to_cart($post->ID); |
|
| 2697 | 2697 | |
| 2698 | - } else { |
|
| 2698 | + } else { |
|
| 2699 | 2699 | |
| 2700 | - if( get_option( 'users_can_register') ) { |
|
| 2700 | + if( get_option( 'users_can_register') ) { |
|
| 2701 | 2701 | |
| 2702 | 2702 | |
| 2703 | - $my_courses_page_id = ''; |
|
| 2703 | + $my_courses_page_id = ''; |
|
| 2704 | 2704 | |
| 2705 | - /** |
|
| 2706 | - * Filter to force Sensei to output the default WordPress user |
|
| 2707 | - * registration link. |
|
| 2708 | - * |
|
| 2709 | - * @since 1.9.0 |
|
| 2710 | - * @param bool $wp_register_link default false |
|
| 2711 | - */ |
|
| 2705 | + /** |
|
| 2706 | + * Filter to force Sensei to output the default WordPress user |
|
| 2707 | + * registration link. |
|
| 2708 | + * |
|
| 2709 | + * @since 1.9.0 |
|
| 2710 | + * @param bool $wp_register_link default false |
|
| 2711 | + */ |
|
| 2712 | 2712 | |
| 2713 | - $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2713 | + $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2714 | 2714 | |
| 2715 | - $settings = Sensei()->settings->get_settings(); |
|
| 2716 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 2717 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2715 | + $settings = Sensei()->settings->get_settings(); |
|
| 2716 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 2717 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2718 | 2718 | |
| 2719 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2719 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2720 | 2720 | |
| 2721 | - } |
|
| 2721 | + } |
|
| 2722 | 2722 | |
| 2723 | - // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2724 | - // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2725 | - if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2723 | + // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2724 | + // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2725 | + if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2726 | 2726 | |
| 2727 | - $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2728 | - $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2729 | - echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2727 | + $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2728 | + $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2729 | + echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2730 | 2730 | |
| 2731 | - } else{ |
|
| 2731 | + } else{ |
|
| 2732 | 2732 | |
| 2733 | - wp_register( '<div class="status register">', '</div>' ); |
|
| 2733 | + wp_register( '<div class="status register">', '</div>' ); |
|
| 2734 | 2734 | |
| 2735 | - } |
|
| 2735 | + } |
|
| 2736 | 2736 | |
| 2737 | - } // end if user can register |
|
| 2737 | + } // end if user can register |
|
| 2738 | 2738 | |
| 2739 | - } // End If Statement |
|
| 2739 | + } // End If Statement |
|
| 2740 | 2740 | |
| 2741 | - } // End If Statement ?> |
|
| 2741 | + } // End If Statement ?> |
|
| 2742 | 2742 | |
| 2743 | 2743 | </section><?php |
| 2744 | 2744 | |
| 2745 | - }// end the_course_enrolment_actions |
|
| 2745 | + }// end the_course_enrolment_actions |
|
| 2746 | 2746 | |
| 2747 | - /** |
|
| 2748 | - * Output the course video inside the loop. |
|
| 2749 | - * |
|
| 2750 | - * @since 1.9.0 |
|
| 2751 | - */ |
|
| 2752 | - public static function the_course_video(){ |
|
| 2747 | + /** |
|
| 2748 | + * Output the course video inside the loop. |
|
| 2749 | + * |
|
| 2750 | + * @since 1.9.0 |
|
| 2751 | + */ |
|
| 2752 | + public static function the_course_video(){ |
|
| 2753 | 2753 | |
| 2754 | - global $post; |
|
| 2755 | - // Get the meta info |
|
| 2756 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2754 | + global $post; |
|
| 2755 | + // Get the meta info |
|
| 2756 | + $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2757 | 2757 | |
| 2758 | - if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2758 | + if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2759 | 2759 | |
| 2760 | - $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2760 | + $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2761 | 2761 | |
| 2762 | - } // End If Statement |
|
| 2762 | + } // End If Statement |
|
| 2763 | 2763 | |
| 2764 | - if ( '' != $course_video_embed ) { ?> |
|
| 2764 | + if ( '' != $course_video_embed ) { ?> |
|
| 2765 | 2765 | |
| 2766 | 2766 | <div class="course-video"> |
| 2767 | 2767 | <?php echo html_entity_decode($course_video_embed); ?> |
| 2768 | 2768 | </div> |
| 2769 | 2769 | |
| 2770 | 2770 | <?php } // End If Statement |
| 2771 | - } |
|
| 2771 | + } |
|
| 2772 | 2772 | |
| 2773 | - /** |
|
| 2774 | - * Output the title for the single lesson page |
|
| 2775 | - * |
|
| 2776 | - * @global $post |
|
| 2777 | - * @since 1.9.0 |
|
| 2778 | - */ |
|
| 2779 | - public static function the_title(){ |
|
| 2773 | + /** |
|
| 2774 | + * Output the title for the single lesson page |
|
| 2775 | + * |
|
| 2776 | + * @global $post |
|
| 2777 | + * @since 1.9.0 |
|
| 2778 | + */ |
|
| 2779 | + public static function the_title(){ |
|
| 2780 | 2780 | |
| 2781 | - global $post; |
|
| 2781 | + global $post; |
|
| 2782 | 2782 | |
| 2783 | - ?> |
|
| 2783 | + ?> |
|
| 2784 | 2784 | <header> |
| 2785 | 2785 | |
| 2786 | 2786 | <h1> |
| 2787 | 2787 | |
| 2788 | 2788 | <?php |
| 2789 | - /** |
|
| 2790 | - * Filter documented in class-sensei-messages.php the_title |
|
| 2791 | - */ |
|
| 2792 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2793 | - ?> |
|
| 2789 | + /** |
|
| 2790 | + * Filter documented in class-sensei-messages.php the_title |
|
| 2791 | + */ |
|
| 2792 | + echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2793 | + ?> |
|
| 2794 | 2794 | |
| 2795 | 2795 | </h1> |
| 2796 | 2796 | |
@@ -2798,111 +2798,111 @@ discard block |
||
| 2798 | 2798 | |
| 2799 | 2799 | <?php |
| 2800 | 2800 | |
| 2801 | - }//the_title |
|
| 2802 | - |
|
| 2803 | - /** |
|
| 2804 | - * Show the title on the course category pages |
|
| 2805 | - * |
|
| 2806 | - * @since 1.9.0 |
|
| 2807 | - */ |
|
| 2808 | - public static function course_category_title(){ |
|
| 2809 | - |
|
| 2810 | - if( ! is_tax( 'course-category' ) ){ |
|
| 2811 | - return; |
|
| 2812 | - } |
|
| 2813 | - |
|
| 2814 | - $category_slug = get_query_var('course-category'); |
|
| 2815 | - $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2816 | - |
|
| 2817 | - if( ! empty($term) ){ |
|
| 2818 | - |
|
| 2819 | - $title = $term->name; |
|
| 2820 | - |
|
| 2821 | - }else{ |
|
| 2822 | - |
|
| 2823 | - $title = 'Course Category'; |
|
| 2824 | - |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - $html = '<h2 class="sensei-category-title">'; |
|
| 2828 | - $html .= __('Category') . ' ' . $title; |
|
| 2829 | - $html .= '</h2>'; |
|
| 2830 | - |
|
| 2831 | - echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2832 | - |
|
| 2833 | - }// course_category_title |
|
| 2834 | - |
|
| 2835 | - /** |
|
| 2836 | - * Alter the course query to respect the order set for courses and apply |
|
| 2837 | - * this on the course-category pages. |
|
| 2838 | - * |
|
| 2839 | - * @since 1.9.0 |
|
| 2840 | - * |
|
| 2841 | - * @param WP_Query $query |
|
| 2842 | - * @return WP_Query |
|
| 2843 | - */ |
|
| 2844 | - public static function alter_course_category_order( $query ){ |
|
| 2845 | - |
|
| 2846 | - if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2847 | - return $query; |
|
| 2848 | - } |
|
| 2849 | - |
|
| 2850 | - $order = get_option( 'sensei_course_order', '' ); |
|
| 2851 | - if( !empty( $order ) ){ |
|
| 2852 | - $query->set('orderby', 'menu_order' ); |
|
| 2853 | - $query->set('order', 'ASC' ); |
|
| 2854 | - } |
|
| 2855 | - |
|
| 2856 | - return $query; |
|
| 2857 | - |
|
| 2858 | - } |
|
| 2859 | - |
|
| 2860 | - /** |
|
| 2861 | - * The very basic course query arguments |
|
| 2862 | - * so we don't have to repeat this througout |
|
| 2863 | - * the code base. |
|
| 2864 | - * |
|
| 2865 | - * Usage: |
|
| 2866 | - * $args = Sensei_Course::get_default_query_args(); |
|
| 2867 | - * $args['custom_arg'] ='custom value'; |
|
| 2868 | - * $courses = get_posts( $args ) |
|
| 2869 | - * |
|
| 2870 | - * @since 1.9.0 |
|
| 2871 | - * |
|
| 2872 | - * @return array |
|
| 2873 | - */ |
|
| 2874 | - public static function get_default_query_args(){ |
|
| 2875 | - return array( |
|
| 2876 | - 'post_type' => 'course', |
|
| 2877 | - 'posts_per_page' => 1000, |
|
| 2878 | - 'orderby' => 'date', |
|
| 2879 | - 'order' => 'DESC', |
|
| 2880 | - 'suppress_filters' => 0 |
|
| 2881 | - ); |
|
| 2882 | - } |
|
| 2883 | - |
|
| 2884 | - /** |
|
| 2885 | - * Check if the prerequisite course is completed |
|
| 2886 | - * Courses with no pre-requisite should always return true |
|
| 2887 | - * |
|
| 2888 | - * @since 1.9.0 |
|
| 2889 | - * @param $course_id |
|
| 2890 | - * @return bool |
|
| 2891 | - */ |
|
| 2892 | - public static function is_prerequisite_complete( $course_id ){ |
|
| 2893 | - |
|
| 2894 | - $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2895 | - |
|
| 2896 | - // if it has a pre requisite course check it |
|
| 2897 | - if( ! empty( $course_prerequisite_id ) ){ |
|
| 2898 | - |
|
| 2899 | - return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2900 | - |
|
| 2901 | - } |
|
| 2902 | - |
|
| 2903 | - return true; |
|
| 2904 | - |
|
| 2905 | - }// end is_prerequisite_complete |
|
| 2801 | + }//the_title |
|
| 2802 | + |
|
| 2803 | + /** |
|
| 2804 | + * Show the title on the course category pages |
|
| 2805 | + * |
|
| 2806 | + * @since 1.9.0 |
|
| 2807 | + */ |
|
| 2808 | + public static function course_category_title(){ |
|
| 2809 | + |
|
| 2810 | + if( ! is_tax( 'course-category' ) ){ |
|
| 2811 | + return; |
|
| 2812 | + } |
|
| 2813 | + |
|
| 2814 | + $category_slug = get_query_var('course-category'); |
|
| 2815 | + $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2816 | + |
|
| 2817 | + if( ! empty($term) ){ |
|
| 2818 | + |
|
| 2819 | + $title = $term->name; |
|
| 2820 | + |
|
| 2821 | + }else{ |
|
| 2822 | + |
|
| 2823 | + $title = 'Course Category'; |
|
| 2824 | + |
|
| 2825 | + } |
|
| 2826 | + |
|
| 2827 | + $html = '<h2 class="sensei-category-title">'; |
|
| 2828 | + $html .= __('Category') . ' ' . $title; |
|
| 2829 | + $html .= '</h2>'; |
|
| 2830 | + |
|
| 2831 | + echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2832 | + |
|
| 2833 | + }// course_category_title |
|
| 2834 | + |
|
| 2835 | + /** |
|
| 2836 | + * Alter the course query to respect the order set for courses and apply |
|
| 2837 | + * this on the course-category pages. |
|
| 2838 | + * |
|
| 2839 | + * @since 1.9.0 |
|
| 2840 | + * |
|
| 2841 | + * @param WP_Query $query |
|
| 2842 | + * @return WP_Query |
|
| 2843 | + */ |
|
| 2844 | + public static function alter_course_category_order( $query ){ |
|
| 2845 | + |
|
| 2846 | + if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2847 | + return $query; |
|
| 2848 | + } |
|
| 2849 | + |
|
| 2850 | + $order = get_option( 'sensei_course_order', '' ); |
|
| 2851 | + if( !empty( $order ) ){ |
|
| 2852 | + $query->set('orderby', 'menu_order' ); |
|
| 2853 | + $query->set('order', 'ASC' ); |
|
| 2854 | + } |
|
| 2855 | + |
|
| 2856 | + return $query; |
|
| 2857 | + |
|
| 2858 | + } |
|
| 2859 | + |
|
| 2860 | + /** |
|
| 2861 | + * The very basic course query arguments |
|
| 2862 | + * so we don't have to repeat this througout |
|
| 2863 | + * the code base. |
|
| 2864 | + * |
|
| 2865 | + * Usage: |
|
| 2866 | + * $args = Sensei_Course::get_default_query_args(); |
|
| 2867 | + * $args['custom_arg'] ='custom value'; |
|
| 2868 | + * $courses = get_posts( $args ) |
|
| 2869 | + * |
|
| 2870 | + * @since 1.9.0 |
|
| 2871 | + * |
|
| 2872 | + * @return array |
|
| 2873 | + */ |
|
| 2874 | + public static function get_default_query_args(){ |
|
| 2875 | + return array( |
|
| 2876 | + 'post_type' => 'course', |
|
| 2877 | + 'posts_per_page' => 1000, |
|
| 2878 | + 'orderby' => 'date', |
|
| 2879 | + 'order' => 'DESC', |
|
| 2880 | + 'suppress_filters' => 0 |
|
| 2881 | + ); |
|
| 2882 | + } |
|
| 2883 | + |
|
| 2884 | + /** |
|
| 2885 | + * Check if the prerequisite course is completed |
|
| 2886 | + * Courses with no pre-requisite should always return true |
|
| 2887 | + * |
|
| 2888 | + * @since 1.9.0 |
|
| 2889 | + * @param $course_id |
|
| 2890 | + * @return bool |
|
| 2891 | + */ |
|
| 2892 | + public static function is_prerequisite_complete( $course_id ){ |
|
| 2893 | + |
|
| 2894 | + $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2895 | + |
|
| 2896 | + // if it has a pre requisite course check it |
|
| 2897 | + if( ! empty( $course_prerequisite_id ) ){ |
|
| 2898 | + |
|
| 2899 | + return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2900 | + |
|
| 2901 | + } |
|
| 2902 | + |
|
| 2903 | + return true; |
|
| 2904 | + |
|
| 2905 | + }// end is_prerequisite_complete |
|
| 2906 | 2906 | |
| 2907 | 2907 | |
| 2908 | 2908 | }// End Class |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @since 1.6.0 |
| 23 | 23 | */ |
| 24 | 24 | public function __construct () { |
| 25 | - $this->token = 'messages'; |
|
| 25 | + $this->token = 'messages'; |
|
| 26 | 26 | $this->post_type = 'sensei_message'; |
| 27 | 27 | $this->meta_fields = array( 'sender', 'receiver' ); |
| 28 | 28 | |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | // Monitor when new reply is posted |
| 38 | 38 | add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); |
| 39 | 39 | |
| 40 | - // Block WordPress from sending comment update emails for the messages post type |
|
| 41 | - add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 40 | + // Block WordPress from sending comment update emails for the messages post type |
|
| 41 | + add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 42 | 42 | |
| 43 | - // Block WordPress from sending comment moderator emails on the sensei messages post types |
|
| 44 | - add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 43 | + // Block WordPress from sending comment moderator emails on the sensei messages post types |
|
| 44 | + add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 45 | 45 | |
| 46 | 46 | // Process saving of message posts |
| 47 | 47 | add_action( 'save_post', array( $this, 'save_message' ) ); |
@@ -49,20 +49,20 @@ discard block |
||
| 49 | 49 | // Add message links to courses & lessons |
| 50 | 50 | add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); |
| 51 | 51 | |
| 52 | - // add message link to lesson |
|
| 53 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 52 | + // add message link to lesson |
|
| 53 | + add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 54 | 54 | |
| 55 | - // add message link to lesson |
|
| 56 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 55 | + // add message link to lesson |
|
| 56 | + add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 57 | 57 | |
| 58 | 58 | // Hide messages and replies from users who do not have access |
| 59 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 60 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 61 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 62 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 63 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 64 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 65 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 59 | + add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 60 | + add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 61 | + add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 62 | + add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 63 | + add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 64 | + add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 65 | + add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 66 | 66 | } // End __construct() |
| 67 | 67 | |
| 68 | 68 | public function add_menu_item() { |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | public function send_message_link( $post_id = 0, $user_id = 0 ) { |
| 164 | 164 | global $post; |
| 165 | 165 | |
| 166 | - // only show the link for the allowed post types: |
|
| 167 | - $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 166 | + // only show the link for the allowed post types: |
|
| 167 | + $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 168 | 168 | if ( ! in_array( get_post_type() , $allowed_post_types ) ) { |
| 169 | 169 | |
| 170 | 170 | return; |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | } elseif( 'course' == $post->post_type ) { |
| 188 | 188 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
| 189 | 189 | }else{ |
| 190 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 191 | - } |
|
| 190 | + $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; |
| 194 | 194 | } |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | if( ! isset( $post->ID ) ) return $html; |
| 215 | 215 | |
| 216 | - //confirm private message |
|
| 217 | - $confirmation = ''; |
|
| 218 | - if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 216 | + //confirm private message |
|
| 217 | + $confirmation = ''; |
|
| 218 | + if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 219 | 219 | |
| 220 | - $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 221 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 220 | + $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 221 | + $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; |
| 226 | - $html .= '<p>'; |
|
| 227 | - $html .= $confirmation; |
|
| 228 | - $html .= '</p>'; |
|
| 226 | + $html .= '<p>'; |
|
| 227 | + $html .= $confirmation; |
|
| 228 | + $html .= '</p>'; |
|
| 229 | 229 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; |
| 230 | 230 | $html .= '<p class="form-row form-row-wide">'; |
| 231 | 231 | $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | public function message_reply_received( $comment_id = 0 ) { |
| 257 | 257 | |
| 258 | 258 | // Get comment object |
| 259 | - $comment = get_comment( $comment_id ); |
|
| 259 | + $comment = get_comment( $comment_id ); |
|
| 260 | 260 | |
| 261 | 261 | if( is_null( $comment ) ) return; |
| 262 | 262 | |
@@ -271,87 +271,87 @@ discard block |
||
| 271 | 271 | do_action( 'sensei_private_message_reply', $comment, $message ); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * This function stops WordPress from sending the default comment update emails. |
|
| 276 | - * |
|
| 277 | - * This function is hooked into comment_notification_recipients. It will simply return |
|
| 278 | - * an empty array if the current passed in comment is on a message post type. |
|
| 279 | - * |
|
| 280 | - * @param array $emails |
|
| 281 | - * @param int $comment_id |
|
| 282 | - * @return array; |
|
| 283 | - */ |
|
| 284 | - public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 274 | + /** |
|
| 275 | + * This function stops WordPress from sending the default comment update emails. |
|
| 276 | + * |
|
| 277 | + * This function is hooked into comment_notification_recipients. It will simply return |
|
| 278 | + * an empty array if the current passed in comment is on a message post type. |
|
| 279 | + * |
|
| 280 | + * @param array $emails |
|
| 281 | + * @param int $comment_id |
|
| 282 | + * @return array; |
|
| 283 | + */ |
|
| 284 | + public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 285 | 285 | |
| 286 | - $comment = get_comment( $comment_id ); |
|
| 287 | - if( isset( $comment->comment_post_ID ) && |
|
| 288 | - 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 286 | + $comment = get_comment( $comment_id ); |
|
| 287 | + if( isset( $comment->comment_post_ID ) && |
|
| 288 | + 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 289 | 289 | |
| 290 | - // empty the emails array to ensure no emails are sent for this comment |
|
| 291 | - $emails = array(); |
|
| 290 | + // empty the emails array to ensure no emails are sent for this comment |
|
| 291 | + $emails = array(); |
|
| 292 | 292 | |
| 293 | - } |
|
| 294 | - return $emails; |
|
| 293 | + } |
|
| 294 | + return $emails; |
|
| 295 | 295 | |
| 296 | - }// end stop_wp_comment_emails |
|
| 296 | + }// end stop_wp_comment_emails |
|
| 297 | 297 | |
| 298 | 298 | /** |
| 299 | - * Save new message post |
|
| 300 | - * @param integer $sender_id ID of sender |
|
| 301 | - * @param integer $receiver_id ID of receiver |
|
| 302 | - * @param string $message Message content |
|
| 303 | - * @param string $post_id ID of post related to message |
|
| 304 | - * @return mixed Message ID on success, boolean false on failure |
|
| 305 | - */ |
|
| 306 | - private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 299 | + * Save new message post |
|
| 300 | + * @param integer $sender_id ID of sender |
|
| 301 | + * @param integer $receiver_id ID of receiver |
|
| 302 | + * @param string $message Message content |
|
| 303 | + * @param string $post_id ID of post related to message |
|
| 304 | + * @return mixed Message ID on success, boolean false on failure |
|
| 305 | + */ |
|
| 306 | + private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 307 | 307 | |
| 308 | - $message_id = false; |
|
| 308 | + $message_id = false; |
|
| 309 | 309 | |
| 310 | - if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 310 | + if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 311 | 311 | |
| 312 | - $title = wp_trim_words( $message, 8, '...' ); |
|
| 312 | + $title = wp_trim_words( $message, 8, '...' ); |
|
| 313 | 313 | |
| 314 | - // Set up post data for message |
|
| 315 | - $message_data = array( |
|
| 316 | - 'post_type' => $this->post_type, |
|
| 317 | - 'post_title' => esc_html( $title ), |
|
| 318 | - 'post_content' => esc_html( $message ), |
|
| 319 | - 'post_status' => 'publish', |
|
| 320 | - 'ping_status' => 'closed', |
|
| 321 | - 'comment_status' => 'open', |
|
| 322 | - 'post_excerpt' => '', |
|
| 323 | - 'post_author' => intval( $sender_id ) |
|
| 324 | - ); |
|
| 314 | + // Set up post data for message |
|
| 315 | + $message_data = array( |
|
| 316 | + 'post_type' => $this->post_type, |
|
| 317 | + 'post_title' => esc_html( $title ), |
|
| 318 | + 'post_content' => esc_html( $message ), |
|
| 319 | + 'post_status' => 'publish', |
|
| 320 | + 'ping_status' => 'closed', |
|
| 321 | + 'comment_status' => 'open', |
|
| 322 | + 'post_excerpt' => '', |
|
| 323 | + 'post_author' => intval( $sender_id ) |
|
| 324 | + ); |
|
| 325 | 325 | |
| 326 | - // Insert post |
|
| 327 | - $message_id = wp_insert_post( $message_data ); |
|
| 326 | + // Insert post |
|
| 327 | + $message_id = wp_insert_post( $message_data ); |
|
| 328 | 328 | |
| 329 | - if( ! is_wp_error( $message_id ) ) { |
|
| 329 | + if( ! is_wp_error( $message_id ) ) { |
|
| 330 | 330 | |
| 331 | - // Add sender to message meta |
|
| 332 | - $sender = get_userdata( $sender_id ); |
|
| 333 | - add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 331 | + // Add sender to message meta |
|
| 332 | + $sender = get_userdata( $sender_id ); |
|
| 333 | + add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 334 | 334 | |
| 335 | - // Add receiver to message meta |
|
| 336 | - $receiver = get_userdata( $receiver_id ); |
|
| 337 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 335 | + // Add receiver to message meta |
|
| 336 | + $receiver = get_userdata( $receiver_id ); |
|
| 337 | + add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 338 | 338 | |
| 339 | - // Add lesson/course ID to message meta |
|
| 340 | - $post = get_post( $post_id ); |
|
| 341 | - add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 342 | - add_post_meta( $message_id, '_post', $post->ID ); |
|
| 339 | + // Add lesson/course ID to message meta |
|
| 340 | + $post = get_post( $post_id ); |
|
| 341 | + add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 342 | + add_post_meta( $message_id, '_post', $post->ID ); |
|
| 343 | 343 | |
| 344 | - do_action( 'sensei_new_private_message', $message_id ); |
|
| 344 | + do_action( 'sensei_new_private_message', $message_id ); |
|
| 345 | 345 | |
| 346 | - } else { |
|
| 346 | + } else { |
|
| 347 | 347 | |
| 348 | - $message_id = false; |
|
| 348 | + $message_id = false; |
|
| 349 | 349 | |
| 350 | - } |
|
| 351 | - } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - return $message_id; |
|
| 354 | - } |
|
| 353 | + return $message_id; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Check if user has access to view this message |
@@ -390,56 +390,56 @@ discard block |
||
| 390 | 390 | remove_meta_box('commentstatusdiv', $this->post_type, 'normal'); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * Function message_login() |
|
| 395 | - * |
|
| 396 | - * Only show /messages/* to logged in users, and |
|
| 397 | - * redirect logged out users to wp-login.php |
|
| 398 | - * |
|
| 399 | - * @since 1.9.0 |
|
| 400 | - * @param none |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 393 | + /** |
|
| 394 | + * Function message_login() |
|
| 395 | + * |
|
| 396 | + * Only show /messages/* to logged in users, and |
|
| 397 | + * redirect logged out users to wp-login.php |
|
| 398 | + * |
|
| 399 | + * @since 1.9.0 |
|
| 400 | + * @param none |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | 403 | |
| 404 | - public function message_login () { |
|
| 404 | + public function message_login () { |
|
| 405 | 405 | |
| 406 | - if ( is_user_logged_in() ) { |
|
| 406 | + if ( is_user_logged_in() ) { |
|
| 407 | 407 | |
| 408 | - return; |
|
| 409 | - } |
|
| 408 | + return; |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - $settings = Sensei()->settings->get_settings(); |
|
| 412 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 413 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 411 | + $settings = Sensei()->settings->get_settings(); |
|
| 412 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 413 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 414 | 414 | |
| 415 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 415 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 416 | 416 | |
| 417 | - $my_courses_url = get_permalink($my_courses_page_id); |
|
| 417 | + $my_courses_url = get_permalink($my_courses_page_id); |
|
| 418 | 418 | |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - if ( is_single() && is_singular( $this->post_type ) |
|
| 422 | - || is_post_type_archive( $this->post_type ) ) { |
|
| 421 | + if ( is_single() && is_singular( $this->post_type ) |
|
| 422 | + || is_post_type_archive( $this->post_type ) ) { |
|
| 423 | 423 | |
| 424 | - if ( isset($my_courses_url) ) { |
|
| 424 | + if ( isset($my_courses_url) ) { |
|
| 425 | 425 | |
| 426 | - wp_redirect($my_courses_url, 303); |
|
| 427 | - exit; |
|
| 428 | - } |
|
| 426 | + wp_redirect($my_courses_url, 303); |
|
| 427 | + exit; |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | - else { |
|
| 430 | + else { |
|
| 431 | 431 | |
| 432 | - wp_redirect(home_url('/wp-login.php'), 303); |
|
| 433 | - exit; |
|
| 434 | - } |
|
| 432 | + wp_redirect(home_url('/wp-login.php'), 303); |
|
| 433 | + exit; |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - } |
|
| 437 | - } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | 438 | /** |
| 439 | - * Only show allowed messages in messages archive |
|
| 440 | - * @param array $query Original query |
|
| 441 | - * @return void |
|
| 442 | - */ |
|
| 439 | + * Only show allowed messages in messages archive |
|
| 440 | + * @param array $query Original query |
|
| 441 | + * @return void |
|
| 442 | + */ |
|
| 443 | 443 | public function message_list( $query ) { |
| 444 | 444 | global $current_user; |
| 445 | 445 | |
@@ -556,17 +556,17 @@ discard block |
||
| 556 | 556 | return $open; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - /** |
|
| 560 | - * Print outthe message was sent by $sender_username on the |
|
| 561 | - * |
|
| 562 | - * @since 1.9.0 |
|
| 563 | - */ |
|
| 564 | - public static function the_message_sent_by_title(){ |
|
| 559 | + /** |
|
| 560 | + * Print outthe message was sent by $sender_username on the |
|
| 561 | + * |
|
| 562 | + * @since 1.9.0 |
|
| 563 | + */ |
|
| 564 | + public static function the_message_sent_by_title(){ |
|
| 565 | 565 | |
| 566 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 567 | - if( $sender_username ) { |
|
| 566 | + $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 567 | + if( $sender_username ) { |
|
| 568 | 568 | |
| 569 | - $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 569 | + $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 570 | 570 | |
| 571 | 571 | <p class="message-meta"> |
| 572 | 572 | <small> |
@@ -578,41 +578,41 @@ discard block |
||
| 578 | 578 | |
| 579 | 579 | <?php } |
| 580 | 580 | |
| 581 | - } |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - /** |
|
| 584 | - * sensei_single_title output for single page title |
|
| 585 | - * @since 1.1.0 |
|
| 586 | - * @return void |
|
| 587 | - * @deprecate |
|
| 588 | - */ |
|
| 589 | - public static function the_title() { |
|
| 583 | + /** |
|
| 584 | + * sensei_single_title output for single page title |
|
| 585 | + * @since 1.1.0 |
|
| 586 | + * @return void |
|
| 587 | + * @deprecate |
|
| 588 | + */ |
|
| 589 | + public static function the_title() { |
|
| 590 | 590 | |
| 591 | - global $post; |
|
| 591 | + global $post; |
|
| 592 | 592 | |
| 593 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 594 | - if( $content_post_id ) { |
|
| 595 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 596 | - } else { |
|
| 597 | - $title = get_the_title( $post->ID ); |
|
| 598 | - } |
|
| 593 | + $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 594 | + if( $content_post_id ) { |
|
| 595 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 596 | + } else { |
|
| 597 | + $title = get_the_title( $post->ID ); |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - ?> |
|
| 600 | + ?> |
|
| 601 | 601 | <header> |
| 602 | 602 | |
| 603 | 603 | <h1> |
| 604 | 604 | |
| 605 | 605 | <?php |
| 606 | - /** |
|
| 607 | - * Filter Sensei single title |
|
| 608 | - * |
|
| 609 | - * @since 1.8.0 |
|
| 610 | - * @param string $title |
|
| 611 | - * @param string $template |
|
| 612 | - * @param string $post_type |
|
| 613 | - */ |
|
| 614 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 615 | - ?> |
|
| 606 | + /** |
|
| 607 | + * Filter Sensei single title |
|
| 608 | + * |
|
| 609 | + * @since 1.8.0 |
|
| 610 | + * @param string $title |
|
| 611 | + * @param string $template |
|
| 612 | + * @param string $post_type |
|
| 613 | + */ |
|
| 614 | + echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 615 | + ?> |
|
| 616 | 616 | |
| 617 | 617 | </h1> |
| 618 | 618 | |
@@ -620,52 +620,52 @@ discard block |
||
| 620 | 620 | |
| 621 | 621 | <?php |
| 622 | 622 | |
| 623 | - } // End sensei_single_title() |
|
| 623 | + } // End sensei_single_title() |
|
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Generates the my messages |
|
| 627 | - * archive header. |
|
| 628 | - * |
|
| 629 | - * @since 1.9.0 |
|
| 630 | - * |
|
| 631 | - * @return string |
|
| 632 | - */ |
|
| 633 | - public static function the_archive_header( ){ |
|
| 625 | + /** |
|
| 626 | + * Generates the my messages |
|
| 627 | + * archive header. |
|
| 628 | + * |
|
| 629 | + * @since 1.9.0 |
|
| 630 | + * |
|
| 631 | + * @return string |
|
| 632 | + */ |
|
| 633 | + public static function the_archive_header( ){ |
|
| 634 | 634 | |
| 635 | - $html = ''; |
|
| 636 | - $html .= '<header class="archive-header"><h1>'; |
|
| 637 | - $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 638 | - $html .= '</h1></header>'; |
|
| 635 | + $html = ''; |
|
| 636 | + $html .= '<header class="archive-header"><h1>'; |
|
| 637 | + $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 638 | + $html .= '</h1></header>'; |
|
| 639 | 639 | |
| 640 | - /** |
|
| 641 | - * Filter the sensei messages archive title. |
|
| 642 | - * @since 1.0.0 |
|
| 643 | - */ |
|
| 644 | - echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 640 | + /** |
|
| 641 | + * Filter the sensei messages archive title. |
|
| 642 | + * @since 1.0.0 |
|
| 643 | + */ |
|
| 644 | + echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 645 | 645 | |
| 646 | - } // get_archive_header() |
|
| 646 | + } // get_archive_header() |
|
| 647 | 647 | |
| 648 | - /** |
|
| 649 | - * Output the title for a message given the post_id. |
|
| 650 | - * |
|
| 651 | - * @since 1.9.0 |
|
| 652 | - * @param $post_id |
|
| 653 | - */ |
|
| 654 | - public static function the_message_title( $message_post_id ){ |
|
| 648 | + /** |
|
| 649 | + * Output the title for a message given the post_id. |
|
| 650 | + * |
|
| 651 | + * @since 1.9.0 |
|
| 652 | + * @param $post_id |
|
| 653 | + */ |
|
| 654 | + public static function the_message_title( $message_post_id ){ |
|
| 655 | 655 | |
| 656 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 656 | + $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 657 | 657 | |
| 658 | - if( $content_post_id ) { |
|
| 658 | + if( $content_post_id ) { |
|
| 659 | 659 | |
| 660 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 660 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 661 | 661 | |
| 662 | - } else { |
|
| 662 | + } else { |
|
| 663 | 663 | |
| 664 | - $title = get_the_title( $message_post_id ); |
|
| 664 | + $title = get_the_title( $message_post_id ); |
|
| 665 | 665 | |
| 666 | - } |
|
| 666 | + } |
|
| 667 | 667 | |
| 668 | - ?> |
|
| 668 | + ?> |
|
| 669 | 669 | <h2> |
| 670 | 670 | <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> |
| 671 | 671 | <?php echo $title; ?> |
@@ -674,21 +674,21 @@ discard block |
||
| 674 | 674 | </h2> |
| 675 | 675 | |
| 676 | 676 | <?php |
| 677 | - } //end the_message_header |
|
| 677 | + } //end the_message_header |
|
| 678 | 678 | |
| 679 | - /** |
|
| 680 | - * Output the message sender given the post id. |
|
| 681 | - * |
|
| 682 | - * @param $message_post_id |
|
| 683 | - */ |
|
| 684 | - public static function the_message_sender( $message_post_id ){ |
|
| 679 | + /** |
|
| 680 | + * Output the message sender given the post id. |
|
| 681 | + * |
|
| 682 | + * @param $message_post_id |
|
| 683 | + */ |
|
| 684 | + public static function the_message_sender( $message_post_id ){ |
|
| 685 | 685 | |
| 686 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 687 | - $sender = get_user_by( 'login', $sender_username ); |
|
| 686 | + $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 687 | + $sender = get_user_by( 'login', $sender_username ); |
|
| 688 | 688 | |
| 689 | - if( $sender_username && $sender instanceof WP_User ) { |
|
| 690 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 691 | - ?> |
|
| 689 | + if( $sender_username && $sender instanceof WP_User ) { |
|
| 690 | + $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 691 | + ?> |
|
| 692 | 692 | <p class="message-meta"> |
| 693 | 693 | <small> |
| 694 | 694 | <em> <?php echo $sender_display_name; ?> </em> |
@@ -696,18 +696,18 @@ discard block |
||
| 696 | 696 | </p> |
| 697 | 697 | |
| 698 | 698 | <?php |
| 699 | - } // end if |
|
| 700 | - |
|
| 701 | - } // end the_message_archive_sender |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Link to the users my messages page |
|
| 705 | - * |
|
| 706 | - * @since 1.9.0 |
|
| 707 | - */ |
|
| 708 | - public static function the_my_messages_link(){ |
|
| 709 | - if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 710 | - ?> |
|
| 699 | + } // end if |
|
| 700 | + |
|
| 701 | + } // end the_message_archive_sender |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Link to the users my messages page |
|
| 705 | + * |
|
| 706 | + * @since 1.9.0 |
|
| 707 | + */ |
|
| 708 | + public static function the_my_messages_link(){ |
|
| 709 | + if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 710 | + ?> |
|
| 711 | 711 | <p class="my-messages-link-container"> |
| 712 | 712 | <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
| 713 | 713 | title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | </a> |
| 716 | 716 | </p> |
| 717 | 717 | <?php |
| 718 | - } |
|
| 719 | - } |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | 721 | } // End Class |
| 722 | 722 | |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Generates content for a single row of the table in the user management |
| 209 | - * screen. |
|
| 210 | - * |
|
| 209 | + * screen. |
|
| 210 | + * |
|
| 211 | 211 | * @since 1.7.0 |
| 212 | - * |
|
| 212 | + * |
|
| 213 | 213 | * @param object $item The current item |
| 214 | - * |
|
| 215 | - * @return void |
|
| 214 | + * |
|
| 215 | + * @return void |
|
| 216 | 216 | */ |
| 217 | 217 | protected function get_row_data( $item ) { |
| 218 | 218 | global $wp_version; |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | switch ( $this->view ) { |
| 221 | 221 | case 'learners' : |
| 222 | 222 | |
| 223 | - // in this case the item passed in is actually the users activity on course of lesson |
|
| 224 | - $user_activity = $item; |
|
| 223 | + // in this case the item passed in is actually the users activity on course of lesson |
|
| 224 | + $user_activity = $item; |
|
| 225 | 225 | $post_id = false; |
| 226 | 226 | |
| 227 | 227 | if( $this->lesson_id ) { |
@@ -240,45 +240,45 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) { |
| 242 | 242 | |
| 243 | - $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 243 | + $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 244 | 244 | |
| 245 | 245 | } else { |
| 246 | 246 | |
| 247 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 247 | + $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - $title = Sensei_Student::get_full_name( $user_activity->user_id ); |
|
| 251 | + $title = Sensei_Student::get_full_name( $user_activity->user_id ); |
|
| 252 | 252 | $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
| 253 | 253 | |
| 254 | - // get the learners order for this course if the course was purchased |
|
| 254 | + // get the learners order for this course if the course was purchased |
|
| 255 | 255 | |
| 256 | - $course_order_id_attribute = ''; |
|
| 257 | - if( Sensei_WC::is_woocommerce_active() ){ |
|
| 256 | + $course_order_id_attribute = ''; |
|
| 257 | + if( Sensei_WC::is_woocommerce_active() ){ |
|
| 258 | 258 | |
| 259 | - $course_product_order_id = Sensei_WC::get_learner_course_active_order_id( $user_activity->user_id, $post_id ); |
|
| 259 | + $course_product_order_id = Sensei_WC::get_learner_course_active_order_id( $user_activity->user_id, $post_id ); |
|
| 260 | 260 | |
| 261 | - if( $course_product_order_id ){ |
|
| 261 | + if( $course_product_order_id ){ |
|
| 262 | 262 | |
| 263 | - $course_order_id_attribute = ' data-order_id="' . $course_product_order_id . '" '; |
|
| 263 | + $course_order_id_attribute = ' data-order_id="' . $course_product_order_id . '" '; |
|
| 264 | 264 | |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - } |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * sensei_learners_main_column_data filter |
|
| 271 | - * |
|
| 272 | - * This filter runs on the learner management screen for a specific course. |
|
| 273 | - * It provides the learner row column details. |
|
| 274 | - * |
|
| 275 | - * @param array $columns{ |
|
| 276 | - * type string $title |
|
| 277 | - * type string $date_started |
|
| 278 | - * type string $course_status (completed, started etc) |
|
| 279 | - * type html $action_buttons |
|
| 280 | - * } |
|
| 281 | - */ |
|
| 269 | + /** |
|
| 270 | + * sensei_learners_main_column_data filter |
|
| 271 | + * |
|
| 272 | + * This filter runs on the learner management screen for a specific course. |
|
| 273 | + * It provides the learner row column details. |
|
| 274 | + * |
|
| 275 | + * @param array $columns{ |
|
| 276 | + * type string $title |
|
| 277 | + * type string $date_started |
|
| 278 | + * type string $course_status (completed, started etc) |
|
| 279 | + * type html $action_buttons |
|
| 280 | + * } |
|
| 281 | + */ |
|
| 282 | 282 | $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
| 283 | 283 | 'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
| 284 | 284 | 'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true), |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | case 'courses' : |
| 310 | 310 | default: |
| 311 | - $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) ); |
|
| 311 | + $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) ); |
|
| 312 | 312 | $title = get_the_title( $item ); |
| 313 | 313 | $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
| 314 | 314 | |
@@ -632,7 +632,7 @@ |
||
| 632 | 632 | $course = get_post( $this->course_id ); |
| 633 | 633 | $report = sanitize_title( $course->post_title ) . '-' . $this->view . 's-overview'; |
| 634 | 634 | if ( $this->user_id ) { |
| 635 | - $user_name = Sensei_Student::get_full_name( $this->user_id ); |
|
| 635 | + $user_name = Sensei_Student::get_full_name( $this->user_id ); |
|
| 636 | 636 | $report = sanitize_title( $user_name ) . '-' . $report; |
| 637 | 637 | } |
| 638 | 638 | |