@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Check if WooCommerce is present. |
| 29 | - * |
|
| 30 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
| 29 | + * |
|
| 30 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
| 31 | 31 | * @access public |
| 32 | 32 | * @since 1.0.2 |
| 33 | 33 | * @static |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public static function sensei_is_woocommerce_present () { |
| 37 | 37 | |
| 38 | - return Sensei_WC::is_woocommerce_present(); |
|
| 38 | + return Sensei_WC::is_woocommerce_present(); |
|
| 39 | 39 | |
| 40 | 40 | } // End sensei_is_woocommerce_present() |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Check if WooCommerce is active. |
| 44 | - * |
|
| 45 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
| 44 | + * |
|
| 45 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
| 46 | 46 | * @access public |
| 47 | 47 | * @since 1.0.2 |
| 48 | 48 | * @static |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - //Get the comments |
|
| 191 | - /** |
|
| 192 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 193 | - * |
|
| 194 | - * It runs while getting the comments for the given request. |
|
| 195 | - * |
|
| 196 | - * @param int|array $comments |
|
| 197 | - */ |
|
| 198 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 190 | + //Get the comments |
|
| 191 | + /** |
|
| 192 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 193 | + * |
|
| 194 | + * It runs while getting the comments for the given request. |
|
| 195 | + * |
|
| 196 | + * @param int|array $comments |
|
| 197 | + */ |
|
| 198 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 199 | 199 | |
| 200 | 200 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
| 201 | 201 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -280,18 +280,18 @@ discard block |
||
| 280 | 280 | return $dataset_changes; |
| 281 | 281 | } // End sensei_delete_activities() |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * Delete all activity for specified user |
|
| 285 | - * @access public |
|
| 283 | + /** |
|
| 284 | + * Delete all activity for specified user |
|
| 285 | + * @access public |
|
| 286 | 286 | * @since 1.5.0 |
| 287 | - * @param integer $user_id User ID |
|
| 288 | - * @return boolean |
|
| 289 | - */ |
|
| 290 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 287 | + * @param integer $user_id User ID |
|
| 288 | + * @return boolean |
|
| 289 | + */ |
|
| 290 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 291 | 291 | |
| 292 | - $dataset_changes = false; |
|
| 292 | + $dataset_changes = false; |
|
| 293 | 293 | |
| 294 | - if( $user_id ) { |
|
| 294 | + if( $user_id ) { |
|
| 295 | 295 | |
| 296 | 296 | $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
| 297 | 297 | |
@@ -336,35 +336,35 @@ discard block |
||
| 336 | 336 | return $activity_value; |
| 337 | 337 | } // End sensei_get_activity_value() |
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * Checks if a user (by email) has bought an item. |
|
| 341 | - * |
|
| 342 | - * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 343 | - * @access public |
|
| 344 | - * @since 1.0.0 |
|
| 345 | - * @param string $customer_email |
|
| 346 | - * @param int $user_id |
|
| 347 | - * @param int $product_id |
|
| 348 | - * @return bool |
|
| 349 | - */ |
|
| 350 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 339 | + /** |
|
| 340 | + * Checks if a user (by email) has bought an item. |
|
| 341 | + * |
|
| 342 | + * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 343 | + * @access public |
|
| 344 | + * @since 1.0.0 |
|
| 345 | + * @param string $customer_email |
|
| 346 | + * @param int $user_id |
|
| 347 | + * @param int $product_id |
|
| 348 | + * @return bool |
|
| 349 | + */ |
|
| 350 | + public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 351 | 351 | |
| 352 | - $emails = array(); |
|
| 352 | + $emails = array(); |
|
| 353 | 353 | |
| 354 | - if ( $user_id ) { |
|
| 355 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 356 | - $emails[] = $user->user_email; |
|
| 357 | - } |
|
| 354 | + if ( $user_id ) { |
|
| 355 | + $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 356 | + $emails[] = $user->user_email; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - if ( is_email( $customer_email ) ) |
|
| 360 | - $emails[] = $customer_email; |
|
| 359 | + if ( is_email( $customer_email ) ) |
|
| 360 | + $emails[] = $customer_email; |
|
| 361 | 361 | |
| 362 | - if ( sizeof( $emails ) == 0 ) |
|
| 363 | - return false; |
|
| 362 | + if ( sizeof( $emails ) == 0 ) |
|
| 363 | + return false; |
|
| 364 | 364 | |
| 365 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 365 | + return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 366 | 366 | |
| 367 | - } // End sensei_customer_bought_product() |
|
| 367 | + } // End sensei_customer_bought_product() |
|
| 368 | 368 | |
| 369 | 369 | /** |
| 370 | 370 | * Load the WordPress rich text editor |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | /** |
| 401 | 401 | * Save quiz answers submitted by users |
| 402 | 402 | * @param array $submitted User's quiz answers |
| 403 | - * @param int $user_id |
|
| 403 | + * @param int $user_id |
|
| 404 | 404 | * @return boolean Whether the answers were saved or not |
| 405 | 405 | */ |
| 406 | 406 | public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
@@ -468,72 +468,72 @@ discard block |
||
| 468 | 468 | |
| 469 | 469 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
| 473 | - * |
|
| 474 | - * This filter was mainly added for Unit Testing purposes. |
|
| 475 | - * |
|
| 476 | - * @since 1.7.4 |
|
| 477 | - * |
|
| 478 | - * @param array $file_upload_args { |
|
| 479 | - * array of current values |
|
| 480 | - * |
|
| 481 | - * @type string test_form set to false by default |
|
| 482 | - * } |
|
| 483 | - */ |
|
| 484 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 485 | - |
|
| 486 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 487 | - |
|
| 488 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 489 | - return false; |
|
| 490 | - } else { |
|
| 471 | + /** |
|
| 472 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
| 473 | + * |
|
| 474 | + * This filter was mainly added for Unit Testing purposes. |
|
| 475 | + * |
|
| 476 | + * @since 1.7.4 |
|
| 477 | + * |
|
| 478 | + * @param array $file_upload_args { |
|
| 479 | + * array of current values |
|
| 480 | + * |
|
| 481 | + * @type string test_form set to false by default |
|
| 482 | + * } |
|
| 483 | + */ |
|
| 484 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 485 | + |
|
| 486 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 487 | + |
|
| 488 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 489 | + return false; |
|
| 490 | + } else { |
|
| 491 | 491 | |
| 492 | - $filename = $file_return['file']; |
|
| 492 | + $filename = $file_return['file']; |
|
| 493 | 493 | |
| 494 | - $attachment = array( |
|
| 495 | - 'post_mime_type' => $file_return['type'], |
|
| 496 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 497 | - 'post_content' => '', |
|
| 498 | - 'post_status' => 'inherit', |
|
| 499 | - 'guid' => $file_return['url'] |
|
| 500 | - ); |
|
| 494 | + $attachment = array( |
|
| 495 | + 'post_mime_type' => $file_return['type'], |
|
| 496 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 497 | + 'post_content' => '', |
|
| 498 | + 'post_status' => 'inherit', |
|
| 499 | + 'guid' => $file_return['url'] |
|
| 500 | + ); |
|
| 501 | 501 | |
| 502 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 502 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 503 | 503 | |
| 504 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 505 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 506 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 504 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 505 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 506 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 507 | 507 | |
| 508 | - if( 0 < intval( $attachment_id ) ) { |
|
| 509 | - return $attachment_id; |
|
| 510 | - } |
|
| 511 | - } |
|
| 508 | + if( 0 < intval( $attachment_id ) ) { |
|
| 509 | + return $attachment_id; |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - return false; |
|
| 513 | + return false; |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
| 517 | 517 | * Grade quiz automatically |
| 518 | - * |
|
| 519 | - * This function grades each question automatically if the are auto gradable. |
|
| 520 | - * It store all question grades. |
|
| 521 | - * |
|
| 522 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 523 | - * |
|
| 518 | + * |
|
| 519 | + * This function grades each question automatically if the are auto gradable. |
|
| 520 | + * It store all question grades. |
|
| 521 | + * |
|
| 522 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 523 | + * |
|
| 524 | 524 | * @param integer $quiz_id ID of quiz |
| 525 | 525 | * @param array $submitted questions id ans answers { |
| 526 | - * @type int $question_id |
|
| 527 | - * @type mixed $answer |
|
| 528 | - * } |
|
| 526 | + * @type int $question_id |
|
| 527 | + * @type mixed $answer |
|
| 528 | + * } |
|
| 529 | 529 | * @param integer $total_questions Total questions in quiz (not used) |
| 530 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 531 | - * |
|
| 530 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 531 | + * |
|
| 532 | 532 | * @return int $quiz_grade total sum of all question grades |
| 533 | 533 | */ |
| 534 | 534 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
| 535 | 535 | |
| 536 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 536 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 537 | 537 | |
| 538 | 538 | } // End sensei_grade_quiz_auto() |
| 539 | 539 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @param integer $quiz_id ID of quiz |
| 543 | 543 | * @param integer $grade Grade received |
| 544 | 544 | * @param integer $user_id ID of user being graded |
| 545 | - * @param string $quiz_grade_type default 'auto' |
|
| 545 | + * @param string $quiz_grade_type default 'auto' |
|
| 546 | 546 | * @return boolean |
| 547 | 547 | */ |
| 548 | 548 | public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
@@ -566,21 +566,21 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | /** |
| 568 | 568 | * Grade question automatically |
| 569 | - * |
|
| 570 | - * This function checks the question typ and then grades it accordingly. |
|
| 571 | - * |
|
| 572 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 573 | - * |
|
| 569 | + * |
|
| 570 | + * This function checks the question typ and then grades it accordingly. |
|
| 571 | + * |
|
| 572 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 573 | + * |
|
| 574 | 574 | * @param integer $question_id |
| 575 | - * @param string $question_type of the standard Sensei question types |
|
| 575 | + * @param string $question_type of the standard Sensei question types |
|
| 576 | 576 | * @param string $answer |
| 577 | - * @param int $user_id |
|
| 578 | - * |
|
| 577 | + * @param int $user_id |
|
| 578 | + * |
|
| 579 | 579 | * @return int $question_grade |
| 580 | 580 | */ |
| 581 | 581 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
| 582 | 582 | |
| 583 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 583 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 584 | 584 | |
| 585 | 585 | } // end sensei_grade_question_auto |
| 586 | 586 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * Grade question |
| 589 | 589 | * @param integer $question_id ID of question |
| 590 | 590 | * @param integer $grade Grade received |
| 591 | - * @param int $user_id |
|
| 591 | + * @param int $user_id |
|
| 592 | 592 | * @return boolean |
| 593 | 593 | */ |
| 594 | 594 | public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
@@ -627,35 +627,35 @@ discard block |
||
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | |
| 630 | - /** |
|
| 631 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 632 | - * |
|
| 633 | - * @since 1.7.4 |
|
| 634 | - * |
|
| 635 | - * @param integer $user_id |
|
| 636 | - * @param integer $lesson_id |
|
| 637 | - * @param bool $complete |
|
| 638 | - * |
|
| 639 | - * @return mixed boolean or comment_ID |
|
| 640 | - */ |
|
| 641 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 630 | + /** |
|
| 631 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 632 | + * |
|
| 633 | + * @since 1.7.4 |
|
| 634 | + * |
|
| 635 | + * @param integer $user_id |
|
| 636 | + * @param integer $lesson_id |
|
| 637 | + * @param bool $complete |
|
| 638 | + * |
|
| 639 | + * @return mixed boolean or comment_ID |
|
| 640 | + */ |
|
| 641 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 642 | 642 | |
| 643 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 643 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 644 | 644 | |
| 645 | - }// end user_start_lesson() |
|
| 645 | + }// end user_start_lesson() |
|
| 646 | 646 | |
| 647 | 647 | /** |
| 648 | 648 | * Mark a lesson as started for user |
| 649 | - * |
|
| 650 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 651 | - * |
|
| 652 | - * @since 1.6.0 |
|
| 653 | - * |
|
| 649 | + * |
|
| 650 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 651 | + * |
|
| 652 | + * @since 1.6.0 |
|
| 653 | + * |
|
| 654 | 654 | * @param integer $lesson_id ID of lesson |
| 655 | 655 | * @param int| string $user_id default 0 |
| 656 | - * @param bool $complete default false |
|
| 657 | - * |
|
| 658 | - * @return mixed boolean or comment_ID |
|
| 656 | + * @param bool $complete default false |
|
| 657 | + * |
|
| 658 | + * @return mixed boolean or comment_ID |
|
| 659 | 659 | */ |
| 660 | 660 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
| 661 | 661 | |
@@ -701,21 +701,21 @@ discard block |
||
| 701 | 701 | $metadata['start'] = current_time('mysql'); |
| 702 | 702 | $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
| 703 | 703 | |
| 704 | - } else { |
|
| 704 | + } else { |
|
| 705 | 705 | |
| 706 | - // if users is already taking the lesson and the status changes to complete update it |
|
| 707 | - $current_user_activity = get_comment($activity_logged); |
|
| 708 | - if( $status=='complete' && |
|
| 709 | - $status != $current_user_activity->comment_approved ){ |
|
| 706 | + // if users is already taking the lesson and the status changes to complete update it |
|
| 707 | + $current_user_activity = get_comment($activity_logged); |
|
| 708 | + if( $status=='complete' && |
|
| 709 | + $status != $current_user_activity->comment_approved ){ |
|
| 710 | 710 | |
| 711 | - $comment = array(); |
|
| 712 | - $comment['comment_ID'] = $activity_logged; |
|
| 713 | - $comment['comment_approved'] = $status; |
|
| 714 | - wp_update_comment( $comment ); |
|
| 711 | + $comment = array(); |
|
| 712 | + $comment['comment_ID'] = $activity_logged; |
|
| 713 | + $comment['comment_approved'] = $status; |
|
| 714 | + wp_update_comment( $comment ); |
|
| 715 | 715 | |
| 716 | - } |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | 720 | if ( $complete ) { |
| 721 | 721 | // Run this *after* the lesson status has been created/updated |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | /** |
| 862 | 862 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 863 | 863 | * |
| 864 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 864 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 865 | 865 | * @param mixed $question |
| 866 | 866 | * @param int $user_id |
| 867 | 867 | * @return string |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | * Add answer notes to question |
| 922 | 922 | * @param integer $question_id ID of question |
| 923 | 923 | * @param integer $user_id ID of user |
| 924 | - * @param string $notes |
|
| 924 | + * @param string $notes |
|
| 925 | 925 | * @return boolean |
| 926 | 926 | */ |
| 927 | 927 | public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
@@ -979,17 +979,17 @@ discard block |
||
| 979 | 979 | * @return void |
| 980 | 980 | */ |
| 981 | 981 | public static function sort_array_by_key( $array, $key ) { |
| 982 | - $sorter = array(); |
|
| 983 | - $ret = array(); |
|
| 984 | - reset( $array ); |
|
| 985 | - foreach ( $array as $ii => $va ) { |
|
| 986 | - $sorter[$ii] = $va[$key]; |
|
| 987 | - } // End For Loop |
|
| 988 | - asort( $sorter ); |
|
| 989 | - foreach ( $sorter as $ii => $va ) { |
|
| 990 | - $ret[$ii] = $array[$ii]; |
|
| 991 | - } // End For Loop |
|
| 992 | - $array = $ret; |
|
| 982 | + $sorter = array(); |
|
| 983 | + $ret = array(); |
|
| 984 | + reset( $array ); |
|
| 985 | + foreach ( $array as $ii => $va ) { |
|
| 986 | + $sorter[$ii] = $va[$key]; |
|
| 987 | + } // End For Loop |
|
| 988 | + asort( $sorter ); |
|
| 989 | + foreach ( $sorter as $ii => $va ) { |
|
| 990 | + $ret[$ii] = $array[$ii]; |
|
| 991 | + } // End For Loop |
|
| 992 | + $array = $ret; |
|
| 993 | 993 | } // End sort_array_by_key() |
| 994 | 994 | |
| 995 | 995 | /** |
@@ -1002,21 +1002,21 @@ discard block |
||
| 1002 | 1002 | $questions_array = array(); |
| 1003 | 1003 | if ( 0 < $quiz_id ) { |
| 1004 | 1004 | $question_args = array( 'post_type' => 'question', |
| 1005 | - 'posts_per_page' => -1, |
|
| 1006 | - 'orderby' => 'ID', |
|
| 1007 | - 'order' => 'ASC', |
|
| 1008 | - 'meta_query' => array( |
|
| 1005 | + 'posts_per_page' => -1, |
|
| 1006 | + 'orderby' => 'ID', |
|
| 1007 | + 'order' => 'ASC', |
|
| 1008 | + 'meta_query' => array( |
|
| 1009 | 1009 | array( |
| 1010 | 1010 | 'key' => '_quiz_id', |
| 1011 | 1011 | 'value' => $quiz_id, |
| 1012 | 1012 | ) |
| 1013 | 1013 | ), |
| 1014 | - 'post_status' => 'any', |
|
| 1015 | - 'suppress_filters' => 0 |
|
| 1016 | - ); |
|
| 1017 | - $questions_array = get_posts( $question_args ); |
|
| 1018 | - } // End If Statement |
|
| 1019 | - return $questions_array; |
|
| 1014 | + 'post_status' => 'any', |
|
| 1015 | + 'suppress_filters' => 0 |
|
| 1016 | + ); |
|
| 1017 | + $questions_array = get_posts( $question_args ); |
|
| 1018 | + } // End If Statement |
|
| 1019 | + return $questions_array; |
|
| 1020 | 1020 | } // End lesson_quiz_questions() |
| 1021 | 1021 | |
| 1022 | 1022 | /** |
@@ -1174,7 +1174,7 @@ discard block |
||
| 1174 | 1174 | * Set the status message displayed to the user for a quiz |
| 1175 | 1175 | * @param integer $lesson_id ID of quiz lesson |
| 1176 | 1176 | * @param integer $user_id ID of user |
| 1177 | - * @param bool $is_lesson |
|
| 1177 | + * @param bool $is_lesson |
|
| 1178 | 1178 | * @return array Status code and message |
| 1179 | 1179 | */ |
| 1180 | 1180 | public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
@@ -1257,20 +1257,20 @@ discard block |
||
| 1257 | 1257 | } |
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | - // add next lesson button |
|
| 1261 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1262 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1260 | + // add next lesson button |
|
| 1261 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1262 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1263 | 1263 | |
| 1264 | - // Output HTML |
|
| 1265 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1266 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1267 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1268 | - .'</a>'; |
|
| 1264 | + // Output HTML |
|
| 1265 | + if ( ( 0 < $next_lesson_id ) ) { |
|
| 1266 | + $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1267 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1268 | + .'</a>'; |
|
| 1269 | 1269 | |
| 1270 | - } |
|
| 1270 | + } |
|
| 1271 | 1271 | |
| 1272 | 1272 | } |
| 1273 | - // Lesson/Quiz not complete |
|
| 1273 | + // Lesson/Quiz not complete |
|
| 1274 | 1274 | else { |
| 1275 | 1275 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1276 | 1276 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
| 1311 | 1311 | |
| 1312 | 1312 | if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
| 1313 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1313 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1314 | 1314 | $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
| 1315 | 1315 | } |
| 1316 | 1316 | |
@@ -1368,9 +1368,9 @@ discard block |
||
| 1368 | 1368 | $user_id = get_current_user_id(); |
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | - if( ! $user_id > 0 ){ |
|
| 1372 | - return false; |
|
| 1373 | - } |
|
| 1371 | + if( ! $user_id > 0 ){ |
|
| 1372 | + return false; |
|
| 1373 | + } |
|
| 1374 | 1374 | |
| 1375 | 1375 | $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
| 1376 | 1376 | if( $user_course_status_id ) { |
@@ -1494,7 +1494,7 @@ discard block |
||
| 1494 | 1494 | * Check if a user has completed a course or not |
| 1495 | 1495 | * |
| 1496 | 1496 | * @param int | WP_Post | WP_Comment $course course_id or sensei_course_status entry |
| 1497 | - * |
|
| 1497 | + * |
|
| 1498 | 1498 | * @param int $user_id |
| 1499 | 1499 | * @return boolean |
| 1500 | 1500 | */ |
@@ -1512,14 +1512,14 @@ discard block |
||
| 1512 | 1512 | $user_id = get_current_user_id(); |
| 1513 | 1513 | } |
| 1514 | 1514 | |
| 1515 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1516 | - $course = $course->ID; |
|
| 1517 | - } |
|
| 1515 | + if( is_a( $course, 'WP_Post' ) ){ |
|
| 1516 | + $course = $course->ID; |
|
| 1517 | + } |
|
| 1518 | 1518 | |
| 1519 | 1519 | $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
| 1520 | 1520 | if( isset( $user_course_status->comment_approved ) ){ |
| 1521 | - $user_course_status = $user_course_status->comment_approved; |
|
| 1522 | - } |
|
| 1521 | + $user_course_status = $user_course_status->comment_approved; |
|
| 1522 | + } |
|
| 1523 | 1523 | |
| 1524 | 1524 | } |
| 1525 | 1525 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1544,11 +1544,11 @@ discard block |
||
| 1544 | 1544 | $user_id = get_current_user_id(); |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | - $activity_args = array( |
|
| 1548 | - 'post_id' => $lesson_id, |
|
| 1549 | - 'user_id' => $user_id, |
|
| 1550 | - 'type' => 'sensei_lesson_status', |
|
| 1551 | - 'field' => 'comment_ID' ); |
|
| 1547 | + $activity_args = array( |
|
| 1548 | + 'post_id' => $lesson_id, |
|
| 1549 | + 'user_id' => $user_id, |
|
| 1550 | + 'type' => 'sensei_lesson_status', |
|
| 1551 | + 'field' => 'comment_ID' ); |
|
| 1552 | 1552 | |
| 1553 | 1553 | $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
| 1554 | 1554 | if( $user_lesson_status_id ) { |
@@ -1561,7 +1561,7 @@ discard block |
||
| 1561 | 1561 | /** |
| 1562 | 1562 | * Check if a user has completed a lesson or not |
| 1563 | 1563 | * |
| 1564 | - * @uses Sensei() |
|
| 1564 | + * @uses Sensei() |
|
| 1565 | 1565 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
| 1566 | 1566 | * @param int $user_id |
| 1567 | 1567 | * @return boolean |
@@ -1582,10 +1582,10 @@ discard block |
||
| 1582 | 1582 | $user_id = get_current_user_id(); |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | - // the user is not logged in |
|
| 1586 | - if( ! $user_id > 0 ){ |
|
| 1587 | - return false; |
|
| 1588 | - } |
|
| 1585 | + // the user is not logged in |
|
| 1586 | + if( ! $user_id > 0 ){ |
|
| 1587 | + return false; |
|
| 1588 | + } |
|
| 1589 | 1589 | $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
| 1590 | 1590 | |
| 1591 | 1591 | if ( $_user_lesson_status ) { |
@@ -1664,9 +1664,9 @@ discard block |
||
| 1664 | 1664 | */ |
| 1665 | 1665 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1666 | 1666 | |
| 1667 | - if( ! $user_id ) { |
|
| 1668 | - $user_id = get_current_user_id(); |
|
| 1669 | - } |
|
| 1667 | + if( ! $user_id ) { |
|
| 1668 | + $user_id = get_current_user_id(); |
|
| 1669 | + } |
|
| 1670 | 1670 | |
| 1671 | 1671 | if( $lesson_id > 0 && $user_id > 0 ) { |
| 1672 | 1672 | |
@@ -1717,12 +1717,12 @@ discard block |
||
| 1717 | 1717 | * Sets the status for the lesson |
| 1718 | 1718 | * |
| 1719 | 1719 | * @since 1.7.0 |
| 1720 | - * |
|
| 1720 | + * |
|
| 1721 | 1721 | * @param int|string $user_id |
| 1722 | 1722 | * @param int|string $lesson_id |
| 1723 | 1723 | * @param string $status |
| 1724 | 1724 | * @param array $metadata |
| 1725 | - * |
|
| 1725 | + * |
|
| 1726 | 1726 | * @return mixed false or comment_ID |
| 1727 | 1727 | */ |
| 1728 | 1728 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
| 1838 | 1838 | /** |
| 1839 | 1839 | * Adjust the comment query to be faster on the database, used by Analysis admin |
| 1840 | 1840 | * @since 1.7.0 |
| 1841 | - * @param array $pieces |
|
| 1841 | + * @param array $pieces |
|
| 1842 | 1842 | * @return array $pieces |
| 1843 | 1843 | */ |
| 1844 | 1844 | public static function comment_total_sum_meta_value_filter( $pieces ) { |
@@ -1873,360 +1873,360 @@ discard block |
||
| 1873 | 1873 | return $pieces; |
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | - /** |
|
| 1877 | - * |
|
| 1878 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1879 | - * @since 1.7.4 |
|
| 1880 | - * |
|
| 1881 | - * @param string $data_key maximum 39 characters allowed |
|
| 1882 | - * @param int $post_id |
|
| 1883 | - * @param mixed $value |
|
| 1884 | - * @param int $user_id |
|
| 1885 | - * |
|
| 1886 | - * @return bool $success |
|
| 1887 | - */ |
|
| 1888 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1889 | - |
|
| 1890 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1891 | - |
|
| 1892 | - }// end add_user_data |
|
| 1893 | - |
|
| 1894 | - /** |
|
| 1895 | - * add user specific data to the passed in sensei post type id |
|
| 1896 | - * |
|
| 1897 | - * This function saves comment meta on the users current status. If no status is available |
|
| 1898 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1899 | - * |
|
| 1900 | - * @since 1.7.4 |
|
| 1901 | - * |
|
| 1902 | - * @param string $data_key maximum 39 characters allowed |
|
| 1903 | - * @param int $post_id |
|
| 1904 | - * @param mixed $value |
|
| 1905 | - * @param int $user_id |
|
| 1906 | - * |
|
| 1907 | - * @return bool $success |
|
| 1908 | - */ |
|
| 1909 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1910 | - |
|
| 1911 | - if( ! ( $user_id > 0 ) ){ |
|
| 1912 | - $user_id = get_current_user_id(); |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1916 | - $post_type = get_post_type( $post_id ); |
|
| 1917 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1918 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1919 | - || !get_userdata( $user_id ) |
|
| 1920 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1921 | - |
|
| 1922 | - return false; |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1926 | - // and get the activity ID |
|
| 1927 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1928 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1929 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1930 | - |
|
| 1931 | - $start_function = 'user_start_'.$post_type; |
|
| 1932 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1933 | - |
|
| 1934 | - }else{ |
|
| 1935 | - |
|
| 1936 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1937 | - |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - // store the data |
|
| 1941 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1942 | - |
|
| 1943 | - return $success; |
|
| 1944 | - |
|
| 1945 | - }//update_user_data |
|
| 1946 | - |
|
| 1947 | - /** |
|
| 1948 | - * Get the user data stored on the passed in post type |
|
| 1949 | - * |
|
| 1950 | - * This function gets the comment meta on the lesson or course status |
|
| 1951 | - * |
|
| 1952 | - * @since 1.7.4 |
|
| 1953 | - * |
|
| 1954 | - * @param $data_key |
|
| 1955 | - * @param $post_id |
|
| 1956 | - * @param int $user_id |
|
| 1957 | - * |
|
| 1958 | - * @return mixed $user_data_value |
|
| 1959 | - */ |
|
| 1960 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1961 | - |
|
| 1962 | - $user_data_value = true; |
|
| 1963 | - |
|
| 1964 | - if( ! ( $user_id > 0 ) ){ |
|
| 1965 | - $user_id = get_current_user_id(); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1969 | - $post_type = get_post_type( $post_id ); |
|
| 1970 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1971 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1972 | - || ! get_userdata( $user_id ) |
|
| 1973 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1974 | - |
|
| 1975 | - return false; |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1979 | - // and get the activity ID |
|
| 1980 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1981 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1982 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1983 | - return false; |
|
| 1984 | - } |
|
| 1985 | - |
|
| 1986 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1987 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 1988 | - |
|
| 1989 | - return $user_data_value; |
|
| 1990 | - |
|
| 1991 | - }// end get_user_data |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 1995 | - * |
|
| 1996 | - * @param int $data_key |
|
| 1997 | - * @param int $post_id |
|
| 1998 | - * @param int $user_id |
|
| 1999 | - * |
|
| 2000 | - * @return bool $deleted |
|
| 2001 | - */ |
|
| 2002 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2003 | - $deleted = true; |
|
| 1876 | + /** |
|
| 1877 | + * |
|
| 1878 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1879 | + * @since 1.7.4 |
|
| 1880 | + * |
|
| 1881 | + * @param string $data_key maximum 39 characters allowed |
|
| 1882 | + * @param int $post_id |
|
| 1883 | + * @param mixed $value |
|
| 1884 | + * @param int $user_id |
|
| 1885 | + * |
|
| 1886 | + * @return bool $success |
|
| 1887 | + */ |
|
| 1888 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1889 | + |
|
| 1890 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1891 | + |
|
| 1892 | + }// end add_user_data |
|
| 1893 | + |
|
| 1894 | + /** |
|
| 1895 | + * add user specific data to the passed in sensei post type id |
|
| 1896 | + * |
|
| 1897 | + * This function saves comment meta on the users current status. If no status is available |
|
| 1898 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1899 | + * |
|
| 1900 | + * @since 1.7.4 |
|
| 1901 | + * |
|
| 1902 | + * @param string $data_key maximum 39 characters allowed |
|
| 1903 | + * @param int $post_id |
|
| 1904 | + * @param mixed $value |
|
| 1905 | + * @param int $user_id |
|
| 1906 | + * |
|
| 1907 | + * @return bool $success |
|
| 1908 | + */ |
|
| 1909 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1910 | + |
|
| 1911 | + if( ! ( $user_id > 0 ) ){ |
|
| 1912 | + $user_id = get_current_user_id(); |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1916 | + $post_type = get_post_type( $post_id ); |
|
| 1917 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1918 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1919 | + || !get_userdata( $user_id ) |
|
| 1920 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1921 | + |
|
| 1922 | + return false; |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1926 | + // and get the activity ID |
|
| 1927 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1928 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1929 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1930 | + |
|
| 1931 | + $start_function = 'user_start_'.$post_type; |
|
| 1932 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1933 | + |
|
| 1934 | + }else{ |
|
| 1935 | + |
|
| 1936 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1937 | + |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + // store the data |
|
| 1941 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1942 | + |
|
| 1943 | + return $success; |
|
| 1944 | + |
|
| 1945 | + }//update_user_data |
|
| 1946 | + |
|
| 1947 | + /** |
|
| 1948 | + * Get the user data stored on the passed in post type |
|
| 1949 | + * |
|
| 1950 | + * This function gets the comment meta on the lesson or course status |
|
| 1951 | + * |
|
| 1952 | + * @since 1.7.4 |
|
| 1953 | + * |
|
| 1954 | + * @param $data_key |
|
| 1955 | + * @param $post_id |
|
| 1956 | + * @param int $user_id |
|
| 1957 | + * |
|
| 1958 | + * @return mixed $user_data_value |
|
| 1959 | + */ |
|
| 1960 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1961 | + |
|
| 1962 | + $user_data_value = true; |
|
| 1963 | + |
|
| 1964 | + if( ! ( $user_id > 0 ) ){ |
|
| 1965 | + $user_id = get_current_user_id(); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1969 | + $post_type = get_post_type( $post_id ); |
|
| 1970 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1971 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1972 | + || ! get_userdata( $user_id ) |
|
| 1973 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2004 | 1974 | |
| 2005 | - if( ! ( $user_id > 0 ) ){ |
|
| 2006 | - $user_id = get_current_user_id(); |
|
| 2007 | - } |
|
| 1975 | + return false; |
|
| 1976 | + } |
|
| 2008 | 1977 | |
| 2009 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2010 | - $post_type = get_post_type( $post_id ); |
|
| 2011 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2012 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2013 | - || ! get_userdata( $user_id ) |
|
| 2014 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1978 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1979 | + // and get the activity ID |
|
| 1980 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1981 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1982 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1983 | + return false; |
|
| 1984 | + } |
|
| 2015 | 1985 | |
| 2016 | - return false; |
|
| 2017 | - } |
|
| 1986 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1987 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 1988 | + |
|
| 1989 | + return $user_data_value; |
|
| 1990 | + |
|
| 1991 | + }// end get_user_data |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 1995 | + * |
|
| 1996 | + * @param int $data_key |
|
| 1997 | + * @param int $post_id |
|
| 1998 | + * @param int $user_id |
|
| 1999 | + * |
|
| 2000 | + * @return bool $deleted |
|
| 2001 | + */ |
|
| 2002 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2003 | + $deleted = true; |
|
| 2004 | + |
|
| 2005 | + if( ! ( $user_id > 0 ) ){ |
|
| 2006 | + $user_id = get_current_user_id(); |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 2010 | + $post_type = get_post_type( $post_id ); |
|
| 2011 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2012 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2013 | + || ! get_userdata( $user_id ) |
|
| 2014 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2015 | + |
|
| 2016 | + return false; |
|
| 2017 | + } |
|
| 2018 | 2018 | |
| 2019 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2020 | - // and get the activity ID |
|
| 2021 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2022 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2023 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2024 | - return false; |
|
| 2025 | - } |
|
| 2019 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2020 | + // and get the activity ID |
|
| 2021 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2022 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2023 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2024 | + return false; |
|
| 2025 | + } |
|
| 2026 | 2026 | |
| 2027 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2028 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2027 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2028 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2029 | 2029 | |
| 2030 | - return $deleted; |
|
| 2030 | + return $deleted; |
|
| 2031 | 2031 | |
| 2032 | - }// end delete_user_data |
|
| 2032 | + }// end delete_user_data |
|
| 2033 | 2033 | |
| 2034 | 2034 | |
| 2035 | - /** |
|
| 2036 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2037 | - * |
|
| 2038 | - * @since 1.8.0 |
|
| 2039 | - * |
|
| 2040 | - * @param string $selected_value |
|
| 2041 | - * @param $options{ |
|
| 2042 | - * @type string $value the value saved in the database |
|
| 2043 | - * @type string $option what the user will see in the list of items |
|
| 2044 | - * } |
|
| 2045 | - * @param array $attributes{ |
|
| 2046 | - * @type string $attribute type such name or id etc. |
|
| 2047 | - * @type string $value |
|
| 2048 | - * } |
|
| 2049 | - * @param bool $enable_none_option |
|
| 2050 | - * |
|
| 2051 | - * @return string $drop_down_element |
|
| 2052 | - */ |
|
| 2053 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2035 | + /** |
|
| 2036 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2037 | + * |
|
| 2038 | + * @since 1.8.0 |
|
| 2039 | + * |
|
| 2040 | + * @param string $selected_value |
|
| 2041 | + * @param $options{ |
|
| 2042 | + * @type string $value the value saved in the database |
|
| 2043 | + * @type string $option what the user will see in the list of items |
|
| 2044 | + * } |
|
| 2045 | + * @param array $attributes{ |
|
| 2046 | + * @type string $attribute type such name or id etc. |
|
| 2047 | + * @type string $value |
|
| 2048 | + * } |
|
| 2049 | + * @param bool $enable_none_option |
|
| 2050 | + * |
|
| 2051 | + * @return string $drop_down_element |
|
| 2052 | + */ |
|
| 2053 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2054 | 2054 | |
| 2055 | - $drop_down_element = ''; |
|
| 2055 | + $drop_down_element = ''; |
|
| 2056 | 2056 | |
| 2057 | - // setup the basic attributes |
|
| 2058 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2057 | + // setup the basic attributes |
|
| 2058 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2059 | 2059 | |
| 2060 | - $attributes['name'] = 'sensei-options'; |
|
| 2060 | + $attributes['name'] = 'sensei-options'; |
|
| 2061 | 2061 | |
| 2062 | - } |
|
| 2062 | + } |
|
| 2063 | 2063 | |
| 2064 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2064 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2065 | 2065 | |
| 2066 | - $attributes['id'] = 'sensei-options'; |
|
| 2066 | + $attributes['id'] = 'sensei-options'; |
|
| 2067 | 2067 | |
| 2068 | - } |
|
| 2068 | + } |
|
| 2069 | 2069 | |
| 2070 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2070 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2071 | 2071 | |
| 2072 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2072 | + $attributes['class'] ='chosen_select widefat'; |
|
| 2073 | 2073 | |
| 2074 | - } |
|
| 2074 | + } |
|
| 2075 | 2075 | |
| 2076 | - // create element attributes |
|
| 2077 | - $combined_attributes = ''; |
|
| 2078 | - foreach( $attributes as $attribute => $value ){ |
|
| 2076 | + // create element attributes |
|
| 2077 | + $combined_attributes = ''; |
|
| 2078 | + foreach( $attributes as $attribute => $value ){ |
|
| 2079 | 2079 | |
| 2080 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2080 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2081 | 2081 | |
| 2082 | - }// end for each |
|
| 2082 | + }// end for each |
|
| 2083 | 2083 | |
| 2084 | 2084 | |
| 2085 | - // create the select element |
|
| 2086 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2085 | + // create the select element |
|
| 2086 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2087 | 2087 | |
| 2088 | - // show the none option if the client requested |
|
| 2089 | - if( $enable_none_option ) { |
|
| 2090 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2091 | - } |
|
| 2088 | + // show the none option if the client requested |
|
| 2089 | + if( $enable_none_option ) { |
|
| 2090 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2091 | + } |
|
| 2092 | 2092 | |
| 2093 | - if ( count( $options ) > 0 ) { |
|
| 2093 | + if ( count( $options ) > 0 ) { |
|
| 2094 | 2094 | |
| 2095 | - foreach ($options as $value => $option ){ |
|
| 2095 | + foreach ($options as $value => $option ){ |
|
| 2096 | 2096 | |
| 2097 | - $element = ''; |
|
| 2098 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2099 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2100 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2097 | + $element = ''; |
|
| 2098 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2099 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2100 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2101 | 2101 | |
| 2102 | - // add the element to the select html |
|
| 2103 | - $drop_down_element.= $element; |
|
| 2104 | - } // End For Loop |
|
| 2102 | + // add the element to the select html |
|
| 2103 | + $drop_down_element.= $element; |
|
| 2104 | + } // End For Loop |
|
| 2105 | 2105 | |
| 2106 | - } // End If Statement |
|
| 2106 | + } // End If Statement |
|
| 2107 | 2107 | |
| 2108 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2108 | + $drop_down_element .= '</select>' . "\n"; |
|
| 2109 | 2109 | |
| 2110 | - return $drop_down_element; |
|
| 2110 | + return $drop_down_element; |
|
| 2111 | 2111 | |
| 2112 | - }// generate_drop_down |
|
| 2112 | + }// generate_drop_down |
|
| 2113 | 2113 | |
| 2114 | - /** |
|
| 2115 | - * Wrapper for the default php round() function. |
|
| 2116 | - * This allows us to give more control to a user on how they can round Sensei |
|
| 2117 | - * decimals passed through this function. |
|
| 2118 | - * |
|
| 2119 | - * @since 1.8.5 |
|
| 2120 | - * |
|
| 2121 | - * @param double $val |
|
| 2122 | - * @param int $precision |
|
| 2123 | - * @param $mode |
|
| 2124 | - * @param string $context |
|
| 2125 | - * |
|
| 2126 | - * @return double $val |
|
| 2127 | - */ |
|
| 2128 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2114 | + /** |
|
| 2115 | + * Wrapper for the default php round() function. |
|
| 2116 | + * This allows us to give more control to a user on how they can round Sensei |
|
| 2117 | + * decimals passed through this function. |
|
| 2118 | + * |
|
| 2119 | + * @since 1.8.5 |
|
| 2120 | + * |
|
| 2121 | + * @param double $val |
|
| 2122 | + * @param int $precision |
|
| 2123 | + * @param $mode |
|
| 2124 | + * @param string $context |
|
| 2125 | + * |
|
| 2126 | + * @return double $val |
|
| 2127 | + */ |
|
| 2128 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2129 | 2129 | |
| 2130 | - /**å |
|
| 2130 | + /**å |
|
| 2131 | 2131 | * Change the precision for the Sensei_Utils::round function. |
| 2132 | 2132 | * the precision given will be passed into the php round function |
| 2133 | 2133 | * @since 1.8.5 |
| 2134 | 2134 | */ |
| 2135 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * Change the mode for the Sensei_Utils::round function. |
|
| 2139 | - * the mode given will be passed into the php round function |
|
| 2140 | - * |
|
| 2141 | - * This applies only to PHP version 5.3.0 and greater |
|
| 2142 | - * |
|
| 2143 | - * @since 1.8.5 |
|
| 2144 | - */ |
|
| 2145 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2135 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * Change the mode for the Sensei_Utils::round function. |
|
| 2139 | + * the mode given will be passed into the php round function |
|
| 2140 | + * |
|
| 2141 | + * This applies only to PHP version 5.3.0 and greater |
|
| 2142 | + * |
|
| 2143 | + * @since 1.8.5 |
|
| 2144 | + */ |
|
| 2145 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2146 | 2146 | |
| 2147 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2147 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2148 | 2148 | |
| 2149 | - return round( $val, $precision, $mode ); |
|
| 2149 | + return round( $val, $precision, $mode ); |
|
| 2150 | 2150 | |
| 2151 | - }else{ |
|
| 2151 | + }else{ |
|
| 2152 | 2152 | |
| 2153 | - return round( $val, $precision ); |
|
| 2153 | + return round( $val, $precision ); |
|
| 2154 | 2154 | |
| 2155 | - } |
|
| 2155 | + } |
|
| 2156 | 2156 | |
| 2157 | - } |
|
| 2157 | + } |
|
| 2158 | 2158 | |
| 2159 | - /** |
|
| 2160 | - * Returns the current url with all the query vars |
|
| 2161 | - * |
|
| 2162 | - * @since 1.9.0 |
|
| 2163 | - * @return string $url |
|
| 2164 | - */ |
|
| 2165 | - public static function get_current_url(){ |
|
| 2159 | + /** |
|
| 2160 | + * Returns the current url with all the query vars |
|
| 2161 | + * |
|
| 2162 | + * @since 1.9.0 |
|
| 2163 | + * @return string $url |
|
| 2164 | + */ |
|
| 2165 | + public static function get_current_url(){ |
|
| 2166 | 2166 | |
| 2167 | - global $wp; |
|
| 2168 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2169 | - if ( isset( $_GET ) ) { |
|
| 2167 | + global $wp; |
|
| 2168 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2169 | + if ( isset( $_GET ) ) { |
|
| 2170 | 2170 | |
| 2171 | - foreach ($_GET as $param => $val ) { |
|
| 2171 | + foreach ($_GET as $param => $val ) { |
|
| 2172 | 2172 | |
| 2173 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2173 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2174 | 2174 | |
| 2175 | - } |
|
| 2176 | - } |
|
| 2175 | + } |
|
| 2176 | + } |
|
| 2177 | 2177 | |
| 2178 | - return $current_url; |
|
| 2179 | - } |
|
| 2178 | + return $current_url; |
|
| 2179 | + } |
|
| 2180 | 2180 | |
| 2181 | - /** |
|
| 2182 | - * Restore the global WP_Query |
|
| 2183 | - * |
|
| 2184 | - * @since 1.9.0 |
|
| 2185 | - */ |
|
| 2186 | - public static function restore_wp_query() { |
|
| 2181 | + /** |
|
| 2182 | + * Restore the global WP_Query |
|
| 2183 | + * |
|
| 2184 | + * @since 1.9.0 |
|
| 2185 | + */ |
|
| 2186 | + public static function restore_wp_query() { |
|
| 2187 | 2187 | |
| 2188 | - wp_reset_query(); |
|
| 2188 | + wp_reset_query(); |
|
| 2189 | 2189 | |
| 2190 | - } |
|
| 2190 | + } |
|
| 2191 | 2191 | |
| 2192 | - /** |
|
| 2193 | - * Merge two arrays in a zip like fashion. |
|
| 2194 | - * If one array is longer than the other the elements will be apended |
|
| 2195 | - * to the end of the resulting array. |
|
| 2196 | - * |
|
| 2197 | - * @since 1.9.0 |
|
| 2198 | - * |
|
| 2199 | - * @param array $array_a |
|
| 2200 | - * @param array $array_b |
|
| 2201 | - * @return array $merged_array |
|
| 2202 | - */ |
|
| 2203 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2192 | + /** |
|
| 2193 | + * Merge two arrays in a zip like fashion. |
|
| 2194 | + * If one array is longer than the other the elements will be apended |
|
| 2195 | + * to the end of the resulting array. |
|
| 2196 | + * |
|
| 2197 | + * @since 1.9.0 |
|
| 2198 | + * |
|
| 2199 | + * @param array $array_a |
|
| 2200 | + * @param array $array_b |
|
| 2201 | + * @return array $merged_array |
|
| 2202 | + */ |
|
| 2203 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2204 | 2204 | |
| 2205 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2206 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2207 | - } |
|
| 2205 | + if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2206 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2207 | + } |
|
| 2208 | 2208 | |
| 2209 | - $merged_array = array(); |
|
| 2210 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2209 | + $merged_array = array(); |
|
| 2210 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2211 | 2211 | |
| 2212 | - // Zip arrays |
|
| 2213 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2212 | + // Zip arrays |
|
| 2213 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2214 | 2214 | |
| 2215 | - // if has an element at current index push a on top |
|
| 2216 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2217 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2218 | - } |
|
| 2215 | + // if has an element at current index push a on top |
|
| 2216 | + if( isset( $array_a[ $i ] ) ){ |
|
| 2217 | + $merged_array[] = $array_a[ $i ] ; |
|
| 2218 | + } |
|
| 2219 | 2219 | |
| 2220 | - // next if $array_b has an element at current index push a on top of the element |
|
| 2221 | - // from a if there was one, if not the element before that. |
|
| 2222 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2223 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2224 | - } |
|
| 2220 | + // next if $array_b has an element at current index push a on top of the element |
|
| 2221 | + // from a if there was one, if not the element before that. |
|
| 2222 | + if( isset( $array_b[ $i ] ) ){ |
|
| 2223 | + $merged_array[] = $array_b[ $i ] ; |
|
| 2224 | + } |
|
| 2225 | 2225 | |
| 2226 | - } |
|
| 2226 | + } |
|
| 2227 | 2227 | |
| 2228 | - return $merged_array; |
|
| 2229 | - } |
|
| 2228 | + return $merged_array; |
|
| 2229 | + } |
|
| 2230 | 2230 | |
| 2231 | 2231 | } // End Class |
| 2232 | 2232 | |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Constructor |
| 23 | 23 | * @since 1.3.0 |
| 24 | - * |
|
| 25 | - * @param $file |
|
| 24 | + * |
|
| 25 | + * @param $file |
|
| 26 | 26 | */ |
| 27 | 27 | public function __construct ( $file ) { |
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
| 286 | 286 | |
| 287 | - $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] ); |
|
| 287 | + $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] ); |
|
| 288 | 288 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 289 | 289 | |
| 290 | 290 | } // End If Statement |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | } |
| 319 | 319 | if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
| 320 | 320 | |
| 321 | - $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] ); |
|
| 321 | + $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] ); |
|
| 322 | 322 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 323 | 323 | |
| 324 | 324 | } // End If Statement |
@@ -367,15 +367,15 @@ discard block |
||
| 367 | 367 | public function count_statuses( $args = array() ) { |
| 368 | 368 | global $wpdb; |
| 369 | 369 | |
| 370 | - /** |
|
| 371 | - * Filter fires inside Sensei_Grading::count_statuses |
|
| 372 | - * |
|
| 373 | - * Alter the the post_in array to determine which posts the |
|
| 374 | - * comment query should be limited to. |
|
| 375 | - * @since 1.8.0 |
|
| 376 | - * @param array $args |
|
| 377 | - */ |
|
| 378 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 370 | + /** |
|
| 371 | + * Filter fires inside Sensei_Grading::count_statuses |
|
| 372 | + * |
|
| 373 | + * Alter the the post_in array to determine which posts the |
|
| 374 | + * comment query should be limited to. |
|
| 375 | + * @since 1.8.0 |
|
| 376 | + * @param array $args |
|
| 377 | + */ |
|
| 378 | + $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 379 | 379 | |
| 380 | 380 | if ( 'course' == $args['type'] ) { |
| 381 | 381 | $type = 'sensei_course_status'; |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
| 389 | 389 | |
| 390 | - // Restrict to specific posts |
|
| 390 | + // Restrict to specific posts |
|
| 391 | 391 | if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
| 392 | 392 | $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
| 393 | 393 | } |
@@ -522,148 +522,148 @@ discard block |
||
| 522 | 522 | return $html; |
| 523 | 523 | } // End lessons_drop_down_html() |
| 524 | 524 | |
| 525 | - /** |
|
| 526 | - * The process grading function handles admin grading submissions. |
|
| 527 | - * |
|
| 528 | - * This function is hooked on to admin_init. It simply accepts |
|
| 529 | - * the grades as the Grader selected theme and saves the total grade and |
|
| 530 | - * individual question grades. |
|
| 531 | - * |
|
| 532 | - * @return bool |
|
| 533 | - */ |
|
| 534 | - public function admin_process_grading_submission() { |
|
| 525 | + /** |
|
| 526 | + * The process grading function handles admin grading submissions. |
|
| 527 | + * |
|
| 528 | + * This function is hooked on to admin_init. It simply accepts |
|
| 529 | + * the grades as the Grader selected theme and saves the total grade and |
|
| 530 | + * individual question grades. |
|
| 531 | + * |
|
| 532 | + * @return bool |
|
| 533 | + */ |
|
| 534 | + public function admin_process_grading_submission() { |
|
| 535 | 535 | |
| 536 | - // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 537 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | - || ! isset( $_GET['quiz_id'] ) |
|
| 540 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 536 | + // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 537 | + if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | + || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | + || ! isset( $_GET['quiz_id'] ) |
|
| 540 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 541 | 541 | |
| 542 | - return false; //exit and do not grade |
|
| 542 | + return false; //exit and do not grade |
|
| 543 | 543 | |
| 544 | - } |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - $quiz_id = $_GET['quiz_id']; |
|
| 547 | - $user_id = $_GET['user']; |
|
| 546 | + $quiz_id = $_GET['quiz_id']; |
|
| 547 | + $user_id = $_GET['user']; |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 552 | - $quiz_grade = 0; |
|
| 553 | - $count = 0; |
|
| 554 | - $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 555 | - $all_question_grades = array(); |
|
| 556 | - $all_answers_feedback = array(); |
|
| 550 | + $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 552 | + $quiz_grade = 0; |
|
| 553 | + $count = 0; |
|
| 554 | + $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 555 | + $all_question_grades = array(); |
|
| 556 | + $all_answers_feedback = array(); |
|
| 557 | 557 | |
| 558 | - foreach( $questions as $question ) { |
|
| 558 | + foreach( $questions as $question ) { |
|
| 559 | 559 | |
| 560 | - ++$count; |
|
| 561 | - $question_id = $question->ID; |
|
| 560 | + ++$count; |
|
| 561 | + $question_id = $question->ID; |
|
| 562 | 562 | |
| 563 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 563 | + if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 564 | 564 | |
| 565 | - $question_grade = 0; |
|
| 566 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 565 | + $question_grade = 0; |
|
| 566 | + if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 567 | 567 | |
| 568 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 568 | + $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 569 | 569 | |
| 570 | - } |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - // add data to the array that will, after the loop, be stored on the lesson status |
|
| 573 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 572 | + // add data to the array that will, after the loop, be stored on the lesson status |
|
| 573 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 574 | 574 | |
| 575 | - // tally up the total quiz grade |
|
| 576 | - $quiz_grade += $question_grade; |
|
| 575 | + // tally up the total quiz grade |
|
| 576 | + $quiz_grade += $question_grade; |
|
| 577 | 577 | |
| 578 | - } // endif |
|
| 578 | + } // endif |
|
| 579 | 579 | |
| 580 | - // Question answer feedback / notes |
|
| 581 | - $question_feedback = ''; |
|
| 582 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 580 | + // Question answer feedback / notes |
|
| 581 | + $question_feedback = ''; |
|
| 582 | + if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 583 | 583 | |
| 584 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 584 | + $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 585 | 585 | |
| 586 | - } |
|
| 587 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 586 | + } |
|
| 587 | + $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 588 | 588 | |
| 589 | - } // end for each $questions |
|
| 589 | + } // end for each $questions |
|
| 590 | 590 | |
| 591 | - //store all question grades on the lesson status |
|
| 592 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 591 | + //store all question grades on the lesson status |
|
| 592 | + Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 593 | 593 | |
| 594 | - //store the feedback from grading |
|
| 595 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 594 | + //store the feedback from grading |
|
| 595 | + Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 596 | 596 | |
| 597 | - // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 598 | - // in the class sensei grading user quiz -> display() |
|
| 599 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 597 | + // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 598 | + // in the class sensei grading user quiz -> display() |
|
| 599 | + if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 600 | 600 | |
| 601 | - // set the users total quiz grade |
|
| 601 | + // set the users total quiz grade |
|
| 602 | 602 | if ( 0 < intval( $quiz_grade_total ) ) { |
| 603 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 603 | + $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 604 | 604 | } |
| 605 | 605 | else { |
| 606 | 606 | $grade = 0; |
| 607 | 607 | } |
| 608 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 609 | - |
|
| 610 | - // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 611 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 613 | - $lesson_metadata = array(); |
|
| 614 | - if ( $pass_required ) { |
|
| 615 | - // Student has reached the pass mark and lesson is complete |
|
| 616 | - if ( $quiz_passmark <= $grade ) { |
|
| 617 | - $lesson_status = 'passed'; |
|
| 618 | - } |
|
| 619 | - else { |
|
| 620 | - $lesson_status = 'failed'; |
|
| 621 | - } // End If Statement |
|
| 622 | - } |
|
| 623 | - // Student only has to partake the quiz |
|
| 624 | - else { |
|
| 625 | - $lesson_status = 'graded'; |
|
| 626 | - } |
|
| 627 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 608 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 609 | + |
|
| 610 | + // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 611 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 613 | + $lesson_metadata = array(); |
|
| 614 | + if ( $pass_required ) { |
|
| 615 | + // Student has reached the pass mark and lesson is complete |
|
| 616 | + if ( $quiz_passmark <= $grade ) { |
|
| 617 | + $lesson_status = 'passed'; |
|
| 618 | + } |
|
| 619 | + else { |
|
| 620 | + $lesson_status = 'failed'; |
|
| 621 | + } // End If Statement |
|
| 622 | + } |
|
| 623 | + // Student only has to partake the quiz |
|
| 624 | + else { |
|
| 625 | + $lesson_status = 'graded'; |
|
| 626 | + } |
|
| 627 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 628 | 628 | |
| 629 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 629 | + Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 630 | 630 | |
| 631 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 631 | + if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Summary. |
|
| 635 | - * |
|
| 636 | - * Description. |
|
| 637 | - * |
|
| 638 | - * @since 1.7.0 |
|
| 639 | - * |
|
| 640 | - * @param int $user_id |
|
| 641 | - * @param int $quiz_lesson_id |
|
| 642 | - */ |
|
| 643 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 633 | + /** |
|
| 634 | + * Summary. |
|
| 635 | + * |
|
| 636 | + * Description. |
|
| 637 | + * |
|
| 638 | + * @since 1.7.0 |
|
| 639 | + * |
|
| 640 | + * @param int $user_id |
|
| 641 | + * @param int $quiz_lesson_id |
|
| 642 | + */ |
|
| 643 | + do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 644 | 644 | |
| 645 | - } // end if in_array |
|
| 645 | + } // end if in_array |
|
| 646 | 646 | |
| 647 | - }// end if $_POST['all_que... |
|
| 647 | + }// end if $_POST['all_que... |
|
| 648 | 648 | |
| 649 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 649 | + if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 650 | 650 | |
| 651 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 651 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 652 | 652 | |
| 653 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 653 | + } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 654 | 654 | |
| 655 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 655 | + $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 656 | 656 | |
| 657 | - } else { |
|
| 657 | + } else { |
|
| 658 | 658 | |
| 659 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 659 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 660 | 660 | |
| 661 | - } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 664 | - exit; |
|
| 663 | + wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 664 | + exit; |
|
| 665 | 665 | |
| 666 | - } // end admin_process_grading_submission |
|
| 666 | + } // end admin_process_grading_submission |
|
| 667 | 667 | |
| 668 | 668 | public function get_redirect_url() { |
| 669 | 669 | // Parse POST data |
@@ -708,283 +708,283 @@ discard block |
||
| 708 | 708 | } // End If Statement |
| 709 | 709 | } // End sensei_grading_notices() |
| 710 | 710 | |
| 711 | - /** |
|
| 712 | - * Grade quiz automatically |
|
| 713 | - * |
|
| 714 | - * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 715 | - * the quiz will not be auto gradable. |
|
| 716 | - * |
|
| 717 | - * @since 1.7.4 |
|
| 718 | - * |
|
| 719 | - * @param integer $quiz_id ID of quiz |
|
| 720 | - * @param array $submitted questions id ans answers { |
|
| 721 | - * @type int $question_id |
|
| 722 | - * @type mixed $answer |
|
| 723 | - * } |
|
| 724 | - * @param integer $total_questions Total questions in quiz (not used) |
|
| 725 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 726 | - * |
|
| 727 | - * @return int $quiz_grade total sum of all question grades |
|
| 728 | - */ |
|
| 729 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 730 | - |
|
| 731 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | - || $quiz_grade_type != 'auto' ) { |
|
| 733 | - return false; // exit early |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - $user_id = get_current_user_id(); |
|
| 738 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 739 | - $quiz_autogradable = true; |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * Filter the types of question types that can be automatically graded. |
|
| 743 | - * |
|
| 744 | - * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 745 | - * |
|
| 746 | - * @param array { |
|
| 747 | - * 'multiple-choice', |
|
| 748 | - * 'boolean', |
|
| 749 | - * 'gap-fill'. |
|
| 750 | - * } |
|
| 751 | - */ |
|
| 752 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 753 | - |
|
| 754 | - $grade_total = 0; |
|
| 755 | - $all_question_grades = array(); |
|
| 756 | - foreach( $submitted as $question_id => $answer ) { |
|
| 757 | - |
|
| 758 | - // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 759 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 711 | + /** |
|
| 712 | + * Grade quiz automatically |
|
| 713 | + * |
|
| 714 | + * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 715 | + * the quiz will not be auto gradable. |
|
| 716 | + * |
|
| 717 | + * @since 1.7.4 |
|
| 718 | + * |
|
| 719 | + * @param integer $quiz_id ID of quiz |
|
| 720 | + * @param array $submitted questions id ans answers { |
|
| 721 | + * @type int $question_id |
|
| 722 | + * @type mixed $answer |
|
| 723 | + * } |
|
| 724 | + * @param integer $total_questions Total questions in quiz (not used) |
|
| 725 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 726 | + * |
|
| 727 | + * @return int $quiz_grade total sum of all question grades |
|
| 728 | + */ |
|
| 729 | + public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 730 | + |
|
| 731 | + if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | + || $quiz_grade_type != 'auto' ) { |
|
| 733 | + return false; // exit early |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + $user_id = get_current_user_id(); |
|
| 738 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 739 | + $quiz_autogradable = true; |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * Filter the types of question types that can be automatically graded. |
|
| 743 | + * |
|
| 744 | + * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 745 | + * |
|
| 746 | + * @param array { |
|
| 747 | + * 'multiple-choice', |
|
| 748 | + * 'boolean', |
|
| 749 | + * 'gap-fill'. |
|
| 750 | + * } |
|
| 751 | + */ |
|
| 752 | + $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 753 | + |
|
| 754 | + $grade_total = 0; |
|
| 755 | + $all_question_grades = array(); |
|
| 756 | + foreach( $submitted as $question_id => $answer ) { |
|
| 757 | + |
|
| 758 | + // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 759 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 760 | 760 | $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
| 761 | 761 | // Question has a zero grade, so skip grading |
| 762 | 762 | if ( 0 == $achievable_grade ) { |
| 763 | 763 | $all_question_grades[ $question_id ] = $achievable_grade; |
| 764 | 764 | } |
| 765 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | - // Get user question grade |
|
| 767 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 769 | - $grade_total += $question_grade; |
|
| 765 | + elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | + // Get user question grade |
|
| 767 | + $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 769 | + $grade_total += $question_grade; |
|
| 770 | 770 | |
| 771 | - } else { |
|
| 771 | + } else { |
|
| 772 | 772 | |
| 773 | - // There is a question that cannot be autograded |
|
| 774 | - $quiz_autogradable = false; |
|
| 773 | + // There is a question that cannot be autograded |
|
| 774 | + $quiz_autogradable = false; |
|
| 775 | 775 | |
| 776 | - } // end if in_array( $question_type... |
|
| 776 | + } // end if in_array( $question_type... |
|
| 777 | 777 | |
| 778 | - }// end for each question |
|
| 778 | + }// end for each question |
|
| 779 | 779 | |
| 780 | - // Only if the whole quiz was autogradable do we set a grade |
|
| 781 | - if ( $quiz_autogradable ) { |
|
| 780 | + // Only if the whole quiz was autogradable do we set a grade |
|
| 781 | + if ( $quiz_autogradable ) { |
|
| 782 | 782 | |
| 783 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 783 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 784 | 784 | // Check for zero total from grades |
| 785 | 785 | if ( 0 < $quiz_total ) { |
| 786 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 786 | + $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 787 | 787 | } |
| 788 | 788 | else { |
| 789 | 789 | $grade = 0; |
| 790 | 790 | } |
| 791 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 791 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 792 | 792 | |
| 793 | - } else { |
|
| 793 | + } else { |
|
| 794 | 794 | |
| 795 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 795 | + $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 796 | 796 | |
| 797 | - } |
|
| 798 | - |
|
| 799 | - // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 800 | - // when doing manual grading. |
|
| 801 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 797 | + } |
|
| 802 | 798 | |
| 803 | - return $grade; |
|
| 799 | + // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 800 | + // when doing manual grading. |
|
| 801 | + Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 804 | 802 | |
| 805 | - } // End grade_quiz_auto() |
|
| 803 | + return $grade; |
|
| 806 | 804 | |
| 807 | - /** |
|
| 808 | - * Grade question automatically |
|
| 809 | - * |
|
| 810 | - * This function checks the question typ and then grades it accordingly. |
|
| 811 | - * |
|
| 812 | - * @since 1.7.4 |
|
| 813 | - * |
|
| 814 | - * @param integer $question_id |
|
| 815 | - * @param string $question_type of the standard Sensei question types |
|
| 816 | - * @param string $answer |
|
| 817 | - * @param int $user_id |
|
| 818 | - * |
|
| 819 | - * @return int $question_grade |
|
| 820 | - */ |
|
| 821 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 822 | - |
|
| 823 | - if( intval( $user_id ) == 0 ) { |
|
| 824 | - |
|
| 825 | - $user_id = get_current_user_id(); |
|
| 826 | - |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 830 | - |
|
| 831 | - return false; |
|
| 832 | - |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - Sensei()->question->get_question_type( $question_id ); |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Applying a grade before the auto grading takes place. |
|
| 840 | - * |
|
| 841 | - * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 842 | - * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 843 | - * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 844 | - * |
|
| 845 | - * @param int $question_grade default false |
|
| 846 | - * @param int $question_id |
|
| 847 | - * @param string $question_type one of the Sensei question type. |
|
| 848 | - * @param string $answer user supplied question answer |
|
| 849 | - */ |
|
| 850 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 805 | + } // End grade_quiz_auto() |
|
| 851 | 806 | |
| 852 | - if ( false !== $question_grade ) { |
|
| 807 | + /** |
|
| 808 | + * Grade question automatically |
|
| 809 | + * |
|
| 810 | + * This function checks the question typ and then grades it accordingly. |
|
| 811 | + * |
|
| 812 | + * @since 1.7.4 |
|
| 813 | + * |
|
| 814 | + * @param integer $question_id |
|
| 815 | + * @param string $question_type of the standard Sensei question types |
|
| 816 | + * @param string $answer |
|
| 817 | + * @param int $user_id |
|
| 818 | + * |
|
| 819 | + * @return int $question_grade |
|
| 820 | + */ |
|
| 821 | + public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 822 | + |
|
| 823 | + if( intval( $user_id ) == 0 ) { |
|
| 824 | + |
|
| 825 | + $user_id = get_current_user_id(); |
|
| 826 | + |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 830 | + |
|
| 831 | + return false; |
|
| 832 | + |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + Sensei()->question->get_question_type( $question_id ); |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Applying a grade before the auto grading takes place. |
|
| 840 | + * |
|
| 841 | + * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 842 | + * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 843 | + * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 844 | + * |
|
| 845 | + * @param int $question_grade default false |
|
| 846 | + * @param int $question_id |
|
| 847 | + * @param string $question_type one of the Sensei question type. |
|
| 848 | + * @param string $answer user supplied question answer |
|
| 849 | + */ |
|
| 850 | + $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 853 | 851 | |
| 854 | - return $question_grade; |
|
| 852 | + if ( false !== $question_grade ) { |
|
| 855 | 853 | |
| 856 | - } |
|
| 854 | + return $question_grade; |
|
| 857 | 855 | |
| 858 | - // auto grading core |
|
| 859 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 856 | + } |
|
| 860 | 857 | |
| 861 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 858 | + // auto grading core |
|
| 859 | + if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 862 | 860 | |
| 863 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | - $answer = wp_unslash( $answer ); |
|
| 865 | - } |
|
| 866 | - $answer = (array) $answer; |
|
| 867 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 868 | - // Loop through all answers ensure none are 'missing' |
|
| 869 | - $all_correct = true; |
|
| 870 | - foreach ( $answer as $check_answer ) { |
|
| 871 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 872 | - $all_correct = false; |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - // If all correct then grade |
|
| 876 | - if ( $all_correct ) { |
|
| 877 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 861 | + $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 880 | 862 | |
| 881 | - } elseif( 'gap-fill' == $question_type ){ |
|
| 863 | + if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | + $answer = wp_unslash( $answer ); |
|
| 865 | + } |
|
| 866 | + $answer = (array) $answer; |
|
| 867 | + if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 868 | + // Loop through all answers ensure none are 'missing' |
|
| 869 | + $all_correct = true; |
|
| 870 | + foreach ( $answer as $check_answer ) { |
|
| 871 | + if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 872 | + $all_correct = false; |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + // If all correct then grade |
|
| 876 | + if ( $all_correct ) { |
|
| 877 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 882 | 880 | |
| 883 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 881 | + } elseif( 'gap-fill' == $question_type ){ |
|
| 884 | 882 | |
| 885 | - } else{ |
|
| 883 | + $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 886 | 884 | |
| 887 | - /** |
|
| 888 | - * Grading questions that are not auto gradable. |
|
| 889 | - * |
|
| 890 | - * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 891 | - * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 892 | - * |
|
| 893 | - * @param int $question_grade default zero |
|
| 894 | - * @param int $question_id |
|
| 895 | - * @param string $question_type one of the Sensei question type. |
|
| 896 | - * @param string $answer user supplied question answer |
|
| 897 | - */ |
|
| 898 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 885 | + } else{ |
|
| 899 | 886 | |
| 900 | - } // end if $question_type |
|
| 887 | + /** |
|
| 888 | + * Grading questions that are not auto gradable. |
|
| 889 | + * |
|
| 890 | + * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 891 | + * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 892 | + * |
|
| 893 | + * @param int $question_grade default zero |
|
| 894 | + * @param int $question_id |
|
| 895 | + * @param string $question_type one of the Sensei question type. |
|
| 896 | + * @param string $answer user supplied question answer |
|
| 897 | + */ |
|
| 898 | + $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 901 | 899 | |
| 902 | - return $question_grade; |
|
| 903 | - } // end grade_question_auto |
|
| 900 | + } // end if $question_type |
|
| 904 | 901 | |
| 905 | - /** |
|
| 906 | - * Grading logic specifically for the gap fill questions |
|
| 907 | - * |
|
| 908 | - * @since 1.9.0 |
|
| 909 | - * @param $question_id |
|
| 910 | - * @param $user_answer |
|
| 911 | - * |
|
| 912 | - * @return bool | int false or the grade given to the user answer |
|
| 913 | - */ |
|
| 914 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 902 | + return $question_grade; |
|
| 903 | + } // end grade_question_auto |
|
| 915 | 904 | |
| 916 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | - $gapfill_array = explode( '||', $right_answer ); |
|
| 905 | + /** |
|
| 906 | + * Grading logic specifically for the gap fill questions |
|
| 907 | + * |
|
| 908 | + * @since 1.9.0 |
|
| 909 | + * @param $question_id |
|
| 910 | + * @param $user_answer |
|
| 911 | + * |
|
| 912 | + * @return bool | int false or the grade given to the user answer |
|
| 913 | + */ |
|
| 914 | + public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 918 | 915 | |
| 919 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | - $user_answer = wp_unslash( $user_answer ); |
|
| 921 | - } |
|
| 916 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | + $gapfill_array = explode( '||', $right_answer ); |
|
| 922 | 918 | |
| 923 | - /** |
|
| 924 | - * case sensitive grading filter |
|
| 925 | - * |
|
| 926 | - * alter the value simply use this code in your plugin or the themes functions.php |
|
| 927 | - * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 928 | - * |
|
| 929 | - * @param bool $do_case_sensitive_comparison default false. |
|
| 930 | - * |
|
| 931 | - * @since 1.9.0 |
|
| 932 | - */ |
|
| 933 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 919 | + if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | + $user_answer = wp_unslash( $user_answer ); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * case sensitive grading filter |
|
| 925 | + * |
|
| 926 | + * alter the value simply use this code in your plugin or the themes functions.php |
|
| 927 | + * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 928 | + * |
|
| 929 | + * @param bool $do_case_sensitive_comparison default false. |
|
| 930 | + * |
|
| 931 | + * @since 1.9.0 |
|
| 932 | + */ |
|
| 933 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 934 | 934 | |
| 935 | - if( $do_case_sensitive_comparison ){ |
|
| 935 | + if( $do_case_sensitive_comparison ){ |
|
| 936 | 936 | |
| 937 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 938 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 937 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 938 | + if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 939 | 939 | |
| 940 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 940 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 941 | 941 | |
| 942 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 942 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 943 | 943 | |
| 944 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 944 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 945 | 945 | |
| 946 | - return Sensei()->question->get_question_grade($question_id); |
|
| 946 | + return Sensei()->question->get_question_grade($question_id); |
|
| 947 | 947 | |
| 948 | - }else{ |
|
| 948 | + }else{ |
|
| 949 | 949 | |
| 950 | - return false; |
|
| 950 | + return false; |
|
| 951 | 951 | |
| 952 | - } |
|
| 952 | + } |
|
| 953 | 953 | |
| 954 | - }else{ |
|
| 954 | + }else{ |
|
| 955 | 955 | |
| 956 | - return false; |
|
| 956 | + return false; |
|
| 957 | 957 | |
| 958 | - } |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - }else{ |
|
| 960 | + }else{ |
|
| 961 | 961 | |
| 962 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 963 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 962 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 963 | + if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 964 | 964 | |
| 965 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 965 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 966 | 966 | |
| 967 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 967 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 968 | 968 | |
| 969 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 969 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 970 | 970 | |
| 971 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 971 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 972 | 972 | |
| 973 | - }else{ |
|
| 973 | + }else{ |
|
| 974 | 974 | |
| 975 | - return false; |
|
| 975 | + return false; |
|
| 976 | 976 | |
| 977 | - } |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - }else{ |
|
| 979 | + }else{ |
|
| 980 | 980 | |
| 981 | - return false; |
|
| 981 | + return false; |
|
| 982 | 982 | |
| 983 | - } |
|
| 983 | + } |
|
| 984 | 984 | |
| 985 | - } |
|
| 985 | + } |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | 989 | } // End Class |
| 990 | 990 | |
@@ -5,18 +5,18 @@ discard block |
||
| 5 | 5 | * Output tags. |
| 6 | 6 | ***************************************************************************************************/ |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * sensei_course_archive_next_link function. |
|
| 10 | - * |
|
| 11 | - * @access public |
|
| 12 | - * @param string $type (default: 'newcourses') |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
| 8 | + /** |
|
| 9 | + * sensei_course_archive_next_link function. |
|
| 10 | + * |
|
| 11 | + * @access public |
|
| 12 | + * @param string $type (default: 'newcourses') |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
| 16 | 16 | |
| 17 | - _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
| 17 | + _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
| 18 | 18 | |
| 19 | - } // End sensei_course_archive_next_link() |
|
| 19 | + } // End sensei_course_archive_next_link() |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * course_single_lessons function. |
@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function course_single_lessons() { |
| 28 | 28 | |
| 29 | - // load backwards compatible template name if it exists in the users theme |
|
| 30 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
| 31 | - if( $located_template ){ |
|
| 29 | + // load backwards compatible template name if it exists in the users theme |
|
| 30 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
| 31 | + if( $located_template ){ |
|
| 32 | 32 | |
| 33 | - Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
| 34 | - return; |
|
| 33 | + Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
| 34 | + return; |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | Sensei_Templates::get_template( 'single-course/lessons.php' ); |
| 39 | 39 | |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function lesson_single_meta() { |
| 50 | 50 | |
| 51 | - _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
| 52 | - sensei_the_single_lesson_meta(); |
|
| 51 | + _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
| 52 | + sensei_the_single_lesson_meta(); |
|
| 53 | 53 | |
| 54 | 54 | } // End lesson_single_meta() |
| 55 | 55 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @access public |
| 61 | 61 | * @param bool $return (default: false) |
| 62 | 62 | * @return void |
| 63 | - * @deprecated since 1.9.0 |
|
| 63 | + * @deprecated since 1.9.0 |
|
| 64 | 64 | */ |
| 65 | 65 | function quiz_questions( $return = false ) { |
| 66 | 66 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | * @access public |
| 75 | 75 | * @since 1.3.0 |
| 76 | 76 | * @return void |
| 77 | - * @deprecated |
|
| 77 | + * @deprecated |
|
| 78 | 78 | */ |
| 79 | 79 | function quiz_question_type( $question_type = 'multiple-choice' ) { |
| 80 | 80 | |
| 81 | - Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 81 | + Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 82 | 82 | |
| 83 | 83 | } // End lesson_single_meta() |
| 84 | 84 | |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | /** |
| 90 | 90 | * sensei_check_prerequisite_course function. |
| 91 | 91 | * |
| 92 | - * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 92 | + * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 93 | 93 | * @access public |
| 94 | 94 | * @param mixed $course_id |
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | 97 | function sensei_check_prerequisite_course( $course_id ) { |
| 98 | 98 | |
| 99 | - return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 99 | + return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 100 | 100 | |
| 101 | 101 | } // End sensei_check_prerequisite_course() |
| 102 | 102 | |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | <span><input name="course_start" type="submit" class="course-start" value="<?php _e( 'Start taking this Course', 'woothemes-sensei' ); ?>"/></span> |
| 121 | 121 | |
| 122 | 122 | </form><?php |
| 123 | - } // End If Statement |
|
| 123 | + } // End If Statement |
|
| 124 | 124 | } // End sensei_start_course_form() |
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * sensei_wc_add_to_cart function. |
| 129 | 129 | * |
| 130 | - * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
| 130 | + * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
| 131 | 131 | * @access public |
| 132 | 132 | * @param mixed $course_id |
| 133 | 133 | * @return void |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @return bool |
| 148 | 148 | */ |
| 149 | 149 | function sensei_check_if_product_is_in_cart( $wc_product_id = 0 ) { |
| 150 | - return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
| 150 | + return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
| 151 | 151 | } // End sensei_check_if_product_is_in_cart() |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | function sensei_simple_course_price( $post_id ) { |
| 161 | 161 | |
| 162 | 162 | //WooCommerce Pricing |
| 163 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 164 | - $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
| 165 | - if ( 0 < $wc_post_id ) { |
|
| 166 | - // Get the product |
|
| 167 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 163 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 164 | + $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
| 165 | + if ( 0 < $wc_post_id ) { |
|
| 166 | + // Get the product |
|
| 167 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 168 | 168 | |
| 169 | - if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
| 169 | + if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
| 170 | 170 | <span class="course-price"><?php echo $product->get_price_html(); ?></span> |
| 171 | 171 | <?php } // End If Statement |
| 172 | - } // End If Statement |
|
| 173 | - } // End If Statement |
|
| 172 | + } // End If Statement |
|
| 173 | + } // End If Statement |
|
| 174 | 174 | } // End sensei_simple_course_price() |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | |
| 199 | 199 | if ( ! $query->is_main_query() ) |
| 200 | - return; |
|
| 200 | + return; |
|
| 201 | 201 | |
| 202 | 202 | // Apply Filter only if on frontend and when course archive is running |
| 203 | 203 | $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | if ( ! is_admin() && 0 < $course_page_id && 0 < intval( $query->get( 'page_id' ) ) && $query->get( 'page_id' ) == $course_page_id ) { |
| 206 | 206 | // Check for pagination settings |
| 207 | 207 | if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
| 208 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 209 | - } else { |
|
| 210 | - $amount = $query->get( 'posts_per_page' ); |
|
| 211 | - } // End If Statement |
|
| 212 | - $query->set( 'posts_per_page', $amount ); |
|
| 208 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 209 | + } else { |
|
| 210 | + $amount = $query->get( 'posts_per_page' ); |
|
| 211 | + } // End If Statement |
|
| 212 | + $query->set( 'posts_per_page', $amount ); |
|
| 213 | 213 | } // End If Statement |
| 214 | 214 | } // End sensei_course_archive_filter() |
| 215 | 215 | add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 ); |
@@ -248,66 +248,66 @@ discard block |
||
| 248 | 248 | $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
| 249 | 249 | $all_lessons = array(); |
| 250 | 250 | |
| 251 | - $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
| 252 | - |
|
| 253 | - foreach( (array) $modules as $module ) { |
|
| 254 | - |
|
| 255 | - $args = array( |
|
| 256 | - 'post_type' => 'lesson', |
|
| 257 | - 'post_status' => 'publish', |
|
| 258 | - 'posts_per_page' => -1, |
|
| 259 | - 'meta_query' => array( |
|
| 260 | - array( |
|
| 261 | - 'key' => '_lesson_course', |
|
| 262 | - 'value' => intval( $lesson_course_id ), |
|
| 263 | - 'compare' => '=' |
|
| 264 | - ) |
|
| 265 | - ), |
|
| 266 | - 'tax_query' => array( |
|
| 267 | - array( |
|
| 268 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 269 | - 'field' => 'id', |
|
| 270 | - 'terms' => intval( $module->term_id ) |
|
| 271 | - ) |
|
| 272 | - ), |
|
| 273 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
| 274 | - 'orderby' => 'meta_value_num date', |
|
| 275 | - 'order' => 'ASC', |
|
| 276 | - 'suppress_filters' => 0 |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - $lessons = get_posts( $args ); |
|
| 280 | - if ( 0 < count( $lessons ) ) { |
|
| 281 | - foreach ($lessons as $lesson_item){ |
|
| 282 | - $all_lessons[] = $lesson_item->ID; |
|
| 283 | - } // End For Loop |
|
| 284 | - } // End If Statement |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $args = array( |
|
| 288 | - 'post_type' => 'lesson', |
|
| 289 | - 'posts_per_page' => -1, |
|
| 290 | - 'suppress_filters' => 0, |
|
| 291 | - 'meta_key' => '_order_' . $lesson_course_id, |
|
| 292 | - 'orderby' => 'meta_value_num date', |
|
| 293 | - 'order' => 'ASC', |
|
| 294 | - 'meta_query' => array( |
|
| 295 | - array( |
|
| 296 | - 'key' => '_lesson_course', |
|
| 297 | - 'value' => intval( $lesson_course_id ), |
|
| 298 | - ), |
|
| 299 | - ), |
|
| 300 | - 'post__not_in' => $all_lessons, |
|
| 301 | - ); |
|
| 302 | - |
|
| 303 | - $other_lessons = get_posts( $args ); |
|
| 304 | - if ( 0 < count( $other_lessons ) ) { |
|
| 251 | + $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
| 252 | + |
|
| 253 | + foreach( (array) $modules as $module ) { |
|
| 254 | + |
|
| 255 | + $args = array( |
|
| 256 | + 'post_type' => 'lesson', |
|
| 257 | + 'post_status' => 'publish', |
|
| 258 | + 'posts_per_page' => -1, |
|
| 259 | + 'meta_query' => array( |
|
| 260 | + array( |
|
| 261 | + 'key' => '_lesson_course', |
|
| 262 | + 'value' => intval( $lesson_course_id ), |
|
| 263 | + 'compare' => '=' |
|
| 264 | + ) |
|
| 265 | + ), |
|
| 266 | + 'tax_query' => array( |
|
| 267 | + array( |
|
| 268 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 269 | + 'field' => 'id', |
|
| 270 | + 'terms' => intval( $module->term_id ) |
|
| 271 | + ) |
|
| 272 | + ), |
|
| 273 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
| 274 | + 'orderby' => 'meta_value_num date', |
|
| 275 | + 'order' => 'ASC', |
|
| 276 | + 'suppress_filters' => 0 |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + $lessons = get_posts( $args ); |
|
| 280 | + if ( 0 < count( $lessons ) ) { |
|
| 281 | + foreach ($lessons as $lesson_item){ |
|
| 282 | + $all_lessons[] = $lesson_item->ID; |
|
| 283 | + } // End For Loop |
|
| 284 | + } // End If Statement |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $args = array( |
|
| 288 | + 'post_type' => 'lesson', |
|
| 289 | + 'posts_per_page' => -1, |
|
| 290 | + 'suppress_filters' => 0, |
|
| 291 | + 'meta_key' => '_order_' . $lesson_course_id, |
|
| 292 | + 'orderby' => 'meta_value_num date', |
|
| 293 | + 'order' => 'ASC', |
|
| 294 | + 'meta_query' => array( |
|
| 295 | + array( |
|
| 296 | + 'key' => '_lesson_course', |
|
| 297 | + 'value' => intval( $lesson_course_id ), |
|
| 298 | + ), |
|
| 299 | + ), |
|
| 300 | + 'post__not_in' => $all_lessons, |
|
| 301 | + ); |
|
| 302 | + |
|
| 303 | + $other_lessons = get_posts( $args ); |
|
| 304 | + if ( 0 < count( $other_lessons ) ) { |
|
| 305 | 305 | foreach ($other_lessons as $lesson_item){ |
| 306 | 306 | $all_lessons[] = $lesson_item->ID; |
| 307 | 307 | } // End For Loop |
| 308 | 308 | } // End If Statement |
| 309 | 309 | |
| 310 | - if ( 0 < count( $all_lessons ) ) { |
|
| 310 | + if ( 0 < count( $all_lessons ) ) { |
|
| 311 | 311 | $found_index = false; |
| 312 | 312 | foreach ( $all_lessons as $lesson ){ |
| 313 | 313 | if ( $found_index && $return_values['next_lesson'] == 0 ) { |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | function sensei_get_excerpt( $post_id = '' ) { |
| 340 | 340 | |
| 341 | - global $post; |
|
| 342 | - _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
| 343 | - return get_the_excerpt(); |
|
| 341 | + global $post; |
|
| 342 | + _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
| 343 | + return get_the_excerpt(); |
|
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | function sensei_has_user_completed_prerequisite_lesson( $current_lesson_id, $user_id ) { |
| 367 | 367 | |
| 368 | - return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
| 368 | + return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
| 369 | 369 | |
| 370 | 370 | } // End sensei_has_user_completed_prerequisite_lesson() |
| 371 | 371 | |
@@ -480,27 +480,27 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | }else{ |
| 482 | 482 | |
| 483 | - // if the loop has not been initiated check the first module has lessons |
|
| 484 | - if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
| 483 | + // if the loop has not been initiated check the first module has lessons |
|
| 484 | + if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
| 485 | 485 | |
| 486 | - $index = 0; |
|
| 486 | + $index = 0; |
|
| 487 | 487 | |
| 488 | - if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
| 489 | - // setup the query for the module lessons |
|
| 490 | - $course_id = $sensei_modules_loop['course_id']; |
|
| 488 | + if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
| 489 | + // setup the query for the module lessons |
|
| 490 | + $course_id = $sensei_modules_loop['course_id']; |
|
| 491 | 491 | |
| 492 | - $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
| 493 | - $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
| 492 | + $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
| 493 | + $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
| 494 | 494 | |
| 495 | - // setup the global wp-query only if the lessons |
|
| 496 | - if( $modules_query->have_posts() ){ |
|
| 495 | + // setup the global wp-query only if the lessons |
|
| 496 | + if( $modules_query->have_posts() ){ |
|
| 497 | 497 | |
| 498 | - return true; |
|
| 498 | + return true; |
|
| 499 | 499 | |
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - // default to false if the first module doesn't have posts |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + // default to false if the first module doesn't have posts |
|
| 504 | 504 | return false; |
| 505 | 505 | |
| 506 | 506 | } |
@@ -612,21 +612,21 @@ discard block |
||
| 612 | 612 | */ |
| 613 | 613 | function sensei_quiz_has_questions(){ |
| 614 | 614 | |
| 615 | - global $sensei_question_loop; |
|
| 615 | + global $sensei_question_loop; |
|
| 616 | 616 | |
| 617 | - if( !isset( $sensei_question_loop['total'] ) ){ |
|
| 618 | - return false; |
|
| 619 | - } |
|
| 617 | + if( !isset( $sensei_question_loop['total'] ) ){ |
|
| 618 | + return false; |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | - if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
| 621 | + if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
| 622 | 622 | |
| 623 | - return true; |
|
| 623 | + return true; |
|
| 624 | 624 | |
| 625 | - }else{ |
|
| 625 | + }else{ |
|
| 626 | 626 | |
| 627 | - return false; |
|
| 627 | + return false; |
|
| 628 | 628 | |
| 629 | - } |
|
| 629 | + } |
|
| 630 | 630 | |
| 631 | 631 | }// end sensei_quiz_has_questions |
| 632 | 632 | |
@@ -637,15 +637,14 @@ discard block |
||
| 637 | 637 | * execution. |
| 638 | 638 | * |
| 639 | 639 | * @since 1.9.0 |
| 640 | - |
|
| 641 | 640 | */ |
| 642 | 641 | function sensei_setup_the_question(){ |
| 643 | 642 | |
| 644 | - global $sensei_question_loop; |
|
| 643 | + global $sensei_question_loop; |
|
| 645 | 644 | |
| 646 | - $sensei_question_loop['current']++; |
|
| 647 | - $index = $sensei_question_loop['current']; |
|
| 648 | - $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
| 645 | + $sensei_question_loop['current']++; |
|
| 646 | + $index = $sensei_question_loop['current']; |
|
| 647 | + $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
| 649 | 648 | |
| 650 | 649 | |
| 651 | 650 | }// end sensei_setup_the_question |
@@ -658,12 +657,12 @@ discard block |
||
| 658 | 657 | */ |
| 659 | 658 | function sensei_the_question_content(){ |
| 660 | 659 | |
| 661 | - global $sensei_question_loop; |
|
| 660 | + global $sensei_question_loop; |
|
| 662 | 661 | |
| 663 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 662 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 664 | 663 | |
| 665 | - // load the template that displays the question information. |
|
| 666 | - WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
| 664 | + // load the template that displays the question information. |
|
| 665 | + WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
| 667 | 666 | |
| 668 | 667 | }// end sensei_the_question_content |
| 669 | 668 | |
@@ -674,26 +673,26 @@ discard block |
||
| 674 | 673 | */ |
| 675 | 674 | function sensei_the_question_class(){ |
| 676 | 675 | |
| 677 | - global $sensei_question_loop; |
|
| 676 | + global $sensei_question_loop; |
|
| 678 | 677 | |
| 679 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 678 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 680 | 679 | |
| 681 | - /** |
|
| 682 | - * filter the sensei question class within |
|
| 683 | - * the quiz question loop. |
|
| 684 | - * |
|
| 685 | - * @since 1.9.0 |
|
| 686 | - */ |
|
| 687 | - $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
| 680 | + /** |
|
| 681 | + * filter the sensei question class within |
|
| 682 | + * the quiz question loop. |
|
| 683 | + * |
|
| 684 | + * @since 1.9.0 |
|
| 685 | + */ |
|
| 686 | + $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
| 688 | 687 | |
| 689 | - $html_classes = ''; |
|
| 690 | - foreach( $classes as $class ){ |
|
| 688 | + $html_classes = ''; |
|
| 689 | + foreach( $classes as $class ){ |
|
| 691 | 690 | |
| 692 | - $html_classes .= $class . ' '; |
|
| 691 | + $html_classes .= $class . ' '; |
|
| 693 | 692 | |
| 694 | - }// end foreach |
|
| 693 | + }// end foreach |
|
| 695 | 694 | |
| 696 | - esc_attr_e( trim( $html_classes ) ); |
|
| 695 | + esc_attr_e( trim( $html_classes ) ); |
|
| 697 | 696 | |
| 698 | 697 | } |
| 699 | 698 | |
@@ -704,12 +703,12 @@ discard block |
||
| 704 | 703 | */ |
| 705 | 704 | function sensei_get_the_question_id( ){ |
| 706 | 705 | |
| 707 | - global $sensei_question_loop; |
|
| 708 | - if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
| 706 | + global $sensei_question_loop; |
|
| 707 | + if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
| 709 | 708 | |
| 710 | - return $sensei_question_loop['current_question']->ID; |
|
| 709 | + return $sensei_question_loop['current_question']->ID; |
|
| 711 | 710 | |
| 712 | - } |
|
| 711 | + } |
|
| 713 | 712 | |
| 714 | 713 | }// end sensei_the_question_id |
| 715 | 714 | |
@@ -736,63 +735,63 @@ discard block |
||
| 736 | 735 | */ |
| 737 | 736 | function sensei_can_user_view_lesson( $lesson_id = '', $user_id = '' ){ |
| 738 | 737 | |
| 739 | - if( empty( $lesson_id ) ){ |
|
| 738 | + if( empty( $lesson_id ) ){ |
|
| 740 | 739 | |
| 741 | - $lesson_id = get_the_ID(); |
|
| 740 | + $lesson_id = get_the_ID(); |
|
| 742 | 741 | |
| 743 | - } |
|
| 742 | + } |
|
| 744 | 743 | |
| 745 | - if( empty( $user_id ) ){ |
|
| 744 | + if( empty( $user_id ) ){ |
|
| 746 | 745 | |
| 747 | - $user_id = get_current_user_id(); |
|
| 746 | + $user_id = get_current_user_id(); |
|
| 748 | 747 | |
| 749 | - } |
|
| 748 | + } |
|
| 750 | 749 | |
| 751 | - // Check for prerequisite lesson completions |
|
| 752 | - $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
| 753 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 754 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
| 750 | + // Check for prerequisite lesson completions |
|
| 751 | + $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
| 752 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 753 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
| 755 | 754 | |
| 756 | - $is_preview = false; |
|
| 757 | - if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
| 755 | + $is_preview = false; |
|
| 756 | + if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
| 758 | 757 | |
| 759 | - $is_preview = true; |
|
| 760 | - $pre_requisite_complete = true; |
|
| 758 | + $is_preview = true; |
|
| 759 | + $pre_requisite_complete = true; |
|
| 761 | 760 | |
| 762 | - }; |
|
| 761 | + }; |
|
| 763 | 762 | |
| 764 | 763 | |
| 765 | - $user_can_access_lesson = false; |
|
| 764 | + $user_can_access_lesson = false; |
|
| 766 | 765 | |
| 767 | - if( is_user_logged_in() && $user_taking_course ){ |
|
| 766 | + if( is_user_logged_in() && $user_taking_course ){ |
|
| 768 | 767 | |
| 769 | - $user_can_access_lesson = true; |
|
| 768 | + $user_can_access_lesson = true; |
|
| 770 | 769 | |
| 771 | - } |
|
| 770 | + } |
|
| 772 | 771 | |
| 773 | 772 | |
| 774 | - $access_permission = false; |
|
| 773 | + $access_permission = false; |
|
| 775 | 774 | |
| 776 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 775 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 777 | 776 | |
| 778 | - $access_permission = true; |
|
| 777 | + $access_permission = true; |
|
| 779 | 778 | |
| 780 | - } |
|
| 779 | + } |
|
| 781 | 780 | |
| 782 | - $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
| 781 | + $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
| 783 | 782 | |
| 784 | - /** |
|
| 785 | - * Filter the can user view lesson function |
|
| 786 | - * |
|
| 787 | - * @since 1.9.0 |
|
| 788 | - * |
|
| 789 | - * @hooked Sensei_WC::alter_can_user_view_lesson |
|
| 790 | - * |
|
| 791 | - * @param bool $can_user_view_lesson |
|
| 792 | - * @param string $lesson_id |
|
| 793 | - * @param string $user_id |
|
| 794 | - */ |
|
| 795 | - return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
| 783 | + /** |
|
| 784 | + * Filter the can user view lesson function |
|
| 785 | + * |
|
| 786 | + * @since 1.9.0 |
|
| 787 | + * |
|
| 788 | + * @hooked Sensei_WC::alter_can_user_view_lesson |
|
| 789 | + * |
|
| 790 | + * @param bool $can_user_view_lesson |
|
| 791 | + * @param string $lesson_id |
|
| 792 | + * @param string $user_id |
|
| 793 | + */ |
|
| 794 | + return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
| 796 | 795 | |
| 797 | 796 | } // end sensei_can_current_user_view_lesson |
| 798 | 797 | |
@@ -804,52 +803,52 @@ discard block |
||
| 804 | 803 | */ |
| 805 | 804 | function sensei_the_single_lesson_meta(){ |
| 806 | 805 | |
| 807 | - // if the lesson meta is included within theme load that instead of the function content |
|
| 808 | - $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
| 809 | - if( ! empty( $template ) ){ |
|
| 806 | + // if the lesson meta is included within theme load that instead of the function content |
|
| 807 | + $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
| 808 | + if( ! empty( $template ) ){ |
|
| 810 | 809 | |
| 811 | - Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
| 812 | - return; |
|
| 810 | + Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
| 811 | + return; |
|
| 813 | 812 | |
| 814 | - } |
|
| 813 | + } |
|
| 815 | 814 | |
| 816 | - // Get the meta info |
|
| 817 | - $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
| 818 | - $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
| 815 | + // Get the meta info |
|
| 816 | + $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
| 817 | + $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
| 819 | 818 | |
| 820 | - // Get User Meta |
|
| 821 | - get_currentuserinfo(); |
|
| 819 | + // Get User Meta |
|
| 820 | + get_currentuserinfo(); |
|
| 822 | 821 | |
| 823 | - // Complete Lesson Logic |
|
| 824 | - do_action( 'sensei_complete_lesson' ); |
|
| 825 | - // Check that the course has been started |
|
| 826 | - if ( Sensei()->access_settings() |
|
| 827 | - || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
| 828 | - || $is_preview ) { |
|
| 829 | - ?> |
|
| 822 | + // Complete Lesson Logic |
|
| 823 | + do_action( 'sensei_complete_lesson' ); |
|
| 824 | + // Check that the course has been started |
|
| 825 | + if ( Sensei()->access_settings() |
|
| 826 | + || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
| 827 | + || $is_preview ) { |
|
| 828 | + ?> |
|
| 830 | 829 | <section class="lesson-meta"> |
| 831 | 830 | <?php |
| 832 | - if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
| 831 | + if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
| 833 | 832 | |
| 834 | - do_action( 'sensei_lesson_video', get_the_ID() ); |
|
| 833 | + do_action( 'sensei_lesson_video', get_the_ID() ); |
|
| 835 | 834 | |
| 836 | - } |
|
| 837 | - ?> |
|
| 835 | + } |
|
| 836 | + ?> |
|
| 838 | 837 | <?php do_action( 'sensei_frontend_messages' ); ?> |
| 839 | 838 | |
| 840 | 839 | <?php if ( ! $is_preview |
| 841 | - || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
| 840 | + || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
| 842 | 841 | |
| 843 | - sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
| 842 | + sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
| 844 | 843 | |
| 845 | - } ?> |
|
| 844 | + } ?> |
|
| 846 | 845 | </section> |
| 847 | 846 | |
| 848 | 847 | <?php do_action( 'sensei_lesson_back_link', $lesson_course_id ); ?> |
| 849 | 848 | |
| 850 | 849 | <?php } |
| 851 | 850 | |
| 852 | - do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
| 851 | + do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
| 853 | 852 | |
| 854 | 853 | } // end the_single_lesson_meta |
| 855 | 854 | |
@@ -865,16 +864,16 @@ discard block |
||
| 865 | 864 | */ |
| 866 | 865 | function get_sensei_header(){ |
| 867 | 866 | |
| 868 | - if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 867 | + if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 869 | 868 | |
| 870 | - get_header(); |
|
| 869 | + get_header(); |
|
| 871 | 870 | |
| 872 | - /** |
|
| 873 | - * sensei_before_main_content hook |
|
| 874 | - * |
|
| 875 | - * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
| 876 | - */ |
|
| 877 | - do_action( 'sensei_before_main_content' ); |
|
| 871 | + /** |
|
| 872 | + * sensei_before_main_content hook |
|
| 873 | + * |
|
| 874 | + * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
| 875 | + */ |
|
| 876 | + do_action( 'sensei_before_main_content' ); |
|
| 878 | 877 | |
| 879 | 878 | }// end get_sensei_header |
| 880 | 879 | |
@@ -890,28 +889,28 @@ discard block |
||
| 890 | 889 | */ |
| 891 | 890 | function get_sensei_footer(){ |
| 892 | 891 | |
| 893 | - /** |
|
| 894 | - * sensei_pagination hook |
|
| 895 | - * |
|
| 896 | - * @hooked sensei_pagination - 10 (outputs pagination) |
|
| 897 | - */ |
|
| 898 | - do_action( 'sensei_pagination' ); |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * sensei_after_main_content hook |
|
| 902 | - * |
|
| 903 | - * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
| 904 | - */ |
|
| 905 | - do_action( 'sensei_after_main_content' ); |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * sensei_sidebar hook |
|
| 909 | - * |
|
| 910 | - * @hooked sensei_get_sidebar - 10 |
|
| 911 | - */ |
|
| 912 | - do_action( 'sensei_sidebar' ); |
|
| 913 | - |
|
| 914 | - get_footer(); |
|
| 892 | + /** |
|
| 893 | + * sensei_pagination hook |
|
| 894 | + * |
|
| 895 | + * @hooked sensei_pagination - 10 (outputs pagination) |
|
| 896 | + */ |
|
| 897 | + do_action( 'sensei_pagination' ); |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * sensei_after_main_content hook |
|
| 901 | + * |
|
| 902 | + * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
| 903 | + */ |
|
| 904 | + do_action( 'sensei_after_main_content' ); |
|
| 905 | + |
|
| 906 | + /** |
|
| 907 | + * sensei_sidebar hook |
|
| 908 | + * |
|
| 909 | + * @hooked sensei_get_sidebar - 10 |
|
| 910 | + */ |
|
| 911 | + do_action( 'sensei_sidebar' ); |
|
| 912 | + |
|
| 913 | + get_footer(); |
|
| 915 | 914 | |
| 916 | 915 | }// end get_sensei_header |
| 917 | 916 | |
@@ -923,14 +922,14 @@ discard block |
||
| 923 | 922 | */ |
| 924 | 923 | function the_no_permissions_title(){ |
| 925 | 924 | |
| 926 | - /** |
|
| 927 | - * Filter the no permissions title just before it is echo'd on the |
|
| 928 | - * no-permissions.php file. |
|
| 929 | - * |
|
| 930 | - * @since 1.9.0 |
|
| 931 | - * @param $no_permissions_title |
|
| 932 | - */ |
|
| 933 | - echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
| 925 | + /** |
|
| 926 | + * Filter the no permissions title just before it is echo'd on the |
|
| 927 | + * no-permissions.php file. |
|
| 928 | + * |
|
| 929 | + * @since 1.9.0 |
|
| 930 | + * @param $no_permissions_title |
|
| 931 | + */ |
|
| 932 | + echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
| 934 | 933 | |
| 935 | 934 | } |
| 936 | 935 | |
@@ -941,14 +940,14 @@ discard block |
||
| 941 | 940 | */ |
| 942 | 941 | function the_no_permissions_message( $post_id ){ |
| 943 | 942 | |
| 944 | - /** |
|
| 945 | - * Filter the no permissions message just before it is echo'd on the |
|
| 946 | - * no-permissions.php file. |
|
| 947 | - * |
|
| 948 | - * @since 1.9.0 |
|
| 949 | - * @param $no_permissions_message |
|
| 950 | - */ |
|
| 951 | - echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
| 943 | + /** |
|
| 944 | + * Filter the no permissions message just before it is echo'd on the |
|
| 945 | + * no-permissions.php file. |
|
| 946 | + * |
|
| 947 | + * @since 1.9.0 |
|
| 948 | + * @param $no_permissions_message |
|
| 949 | + */ |
|
| 950 | + echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
| 952 | 951 | |
| 953 | 952 | } |
| 954 | 953 | |
@@ -959,8 +958,8 @@ discard block |
||
| 959 | 958 | */ |
| 960 | 959 | function sensei_the_excerpt( $post_id ){ |
| 961 | 960 | |
| 962 | - global $post; |
|
| 963 | - the_excerpt( $post ); |
|
| 961 | + global $post; |
|
| 962 | + the_excerpt( $post ); |
|
| 964 | 963 | |
| 965 | 964 | } |
| 966 | 965 | |
@@ -974,9 +973,9 @@ discard block |
||
| 974 | 973 | */ |
| 975 | 974 | function sensei_get_current_page_url(){ |
| 976 | 975 | |
| 977 | - global $wp; |
|
| 978 | - $current_page_url = home_url( $wp->request ); |
|
| 979 | - return $current_page_url; |
|
| 976 | + global $wp; |
|
| 977 | + $current_page_url = home_url( $wp->request ); |
|
| 978 | + return $current_page_url; |
|
| 980 | 979 | |
| 981 | 980 | } |
| 982 | 981 | |
@@ -988,7 +987,7 @@ discard block |
||
| 988 | 987 | */ |
| 989 | 988 | function sensei_the_my_courses_content(){ |
| 990 | 989 | |
| 991 | - echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
| 990 | + echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
| 992 | 991 | |
| 993 | 992 | } // sensei_the_my_courses_content |
| 994 | 993 | |
@@ -1003,7 +1002,7 @@ discard block |
||
| 1003 | 1002 | */ |
| 1004 | 1003 | function sensei_load_template( $template_name ){ |
| 1005 | 1004 | |
| 1006 | - Sensei_Templates::get_template( $template_name ); |
|
| 1005 | + Sensei_Templates::get_template( $template_name ); |
|
| 1007 | 1006 | |
| 1008 | 1007 | } |
| 1009 | 1008 | |
@@ -1017,7 +1016,7 @@ discard block |
||
| 1017 | 1016 | */ |
| 1018 | 1017 | function sensei_load_template_part( $slug, $name ){ |
| 1019 | 1018 | |
| 1020 | - Sensei_Templates::get_part( $slug, $name ); |
|
| 1019 | + Sensei_Templates::get_part( $slug, $name ); |
|
| 1021 | 1020 | |
| 1022 | 1021 | } |
| 1023 | 1022 | |
@@ -1036,17 +1035,17 @@ discard block |
||
| 1036 | 1035 | */ |
| 1037 | 1036 | function sensei_the_lesson_excerpt( $lesson_id = '' ) { |
| 1038 | 1037 | |
| 1039 | - if( empty( $lesson_id )){ |
|
| 1038 | + if( empty( $lesson_id )){ |
|
| 1040 | 1039 | |
| 1041 | - $lesson_id = get_the_ID(); |
|
| 1040 | + $lesson_id = get_the_ID(); |
|
| 1042 | 1041 | |
| 1043 | - } |
|
| 1042 | + } |
|
| 1044 | 1043 | |
| 1045 | - if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 1046 | - return; |
|
| 1047 | - } |
|
| 1044 | + if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 1045 | + return; |
|
| 1046 | + } |
|
| 1048 | 1047 | |
| 1049 | - echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
| 1048 | + echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
| 1050 | 1049 | |
| 1051 | 1050 | }// End lesson_excerpt() |
| 1052 | 1051 | |
@@ -1056,16 +1055,16 @@ discard block |
||
| 1056 | 1055 | * @since 1.9.0 |
| 1057 | 1056 | */ |
| 1058 | 1057 | function sensei_the_course_results_lessons(){ |
| 1059 | - // load backwards compatible template name if it exists in the users theme |
|
| 1060 | - $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
| 1061 | - if( $located_template ){ |
|
| 1058 | + // load backwards compatible template name if it exists in the users theme |
|
| 1059 | + $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
| 1060 | + if( $located_template ){ |
|
| 1062 | 1061 | |
| 1063 | - Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
| 1064 | - return; |
|
| 1062 | + Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
| 1063 | + return; |
|
| 1065 | 1064 | |
| 1066 | - } |
|
| 1065 | + } |
|
| 1067 | 1066 | |
| 1068 | - Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
| 1067 | + Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
| 1069 | 1068 | } |
| 1070 | 1069 | |
| 1071 | 1070 | /** |
@@ -1077,6 +1076,6 @@ discard block |
||
| 1077 | 1076 | */ |
| 1078 | 1077 | function sensei_courses_per_row(){ |
| 1079 | 1078 | |
| 1080 | - echo Sensei_Course::get_loop_number_of_columns(); |
|
| 1079 | + echo Sensei_Course::get_loop_number_of_columns(); |
|
| 1081 | 1080 | |
| 1082 | 1081 | } |
@@ -11,676 +11,676 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Sensei_Templates { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 16 | - * |
|
| 17 | - * @since 1.9.0 |
|
| 18 | - * @param string $slug |
|
| 19 | - * @param string $name default: '' |
|
| 20 | - * |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public static function get_part( $slug, $name = '' ){ |
|
| 14 | + /** |
|
| 15 | + * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 16 | + * |
|
| 17 | + * @since 1.9.0 |
|
| 18 | + * @param string $slug |
|
| 19 | + * @param string $name default: '' |
|
| 20 | + * |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public static function get_part( $slug, $name = '' ){ |
|
| 24 | 24 | |
| 25 | - $template = ''; |
|
| 26 | - $plugin_template_url = Sensei()->template_url; |
|
| 27 | - $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 25 | + $template = ''; |
|
| 26 | + $plugin_template_url = Sensei()->template_url; |
|
| 27 | + $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 28 | 28 | |
| 29 | - // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 30 | - if ( $name ){ |
|
| 29 | + // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 30 | + if ( $name ){ |
|
| 31 | 31 | |
| 32 | - $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 32 | + $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - // Get default slug-name.php |
|
| 37 | - if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 36 | + // Get default slug-name.php |
|
| 37 | + if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 38 | 38 | |
| 39 | - $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 39 | + $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 45 | - if ( !$template ){ |
|
| 44 | + // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 45 | + if ( !$template ){ |
|
| 46 | 46 | |
| 47 | - $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 47 | + $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - if ( $template ){ |
|
| 52 | + if ( $template ){ |
|
| 53 | 53 | |
| 54 | - load_template( $template, false ); |
|
| 54 | + load_template( $template, false ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - } // end get part |
|
| 58 | + } // end get part |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get the template. |
|
| 62 | - * |
|
| 63 | - * @since 1.9.0 |
|
| 64 | - * |
|
| 65 | - * @param $template_name |
|
| 66 | - * @param array $args |
|
| 67 | - * @param string $template_path |
|
| 68 | - * @param string $default_path |
|
| 69 | - */ |
|
| 70 | - public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 60 | + /** |
|
| 61 | + * Get the template. |
|
| 62 | + * |
|
| 63 | + * @since 1.9.0 |
|
| 64 | + * |
|
| 65 | + * @param $template_name |
|
| 66 | + * @param array $args |
|
| 67 | + * @param string $template_path |
|
| 68 | + * @param string $default_path |
|
| 69 | + */ |
|
| 70 | + public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 71 | 71 | |
| 72 | - if ( $args && is_array($args) ) |
|
| 73 | - extract( $args ); |
|
| 72 | + if ( $args && is_array($args) ) |
|
| 73 | + extract( $args ); |
|
| 74 | 74 | |
| 75 | - $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 75 | + $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 76 | 76 | |
| 77 | - if( ! empty( $located ) ){ |
|
| 77 | + if( ! empty( $located ) ){ |
|
| 78 | 78 | |
| 79 | - do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 79 | + do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 80 | 80 | |
| 81 | - include( $located ); |
|
| 81 | + include( $located ); |
|
| 82 | 82 | |
| 83 | - do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 83 | + do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 84 | 84 | |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - } // end get template |
|
| 87 | + } // end get template |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Check if the template file exists. A wrapper for WP locate_template. |
|
| 91 | - * |
|
| 92 | - * @since 1.9.0 |
|
| 93 | - * |
|
| 94 | - * @param $template_name |
|
| 95 | - * @param string $template_path |
|
| 96 | - * @param string $default_path |
|
| 97 | - * |
|
| 98 | - * @return mixed|void |
|
| 99 | - */ |
|
| 100 | - public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 89 | + /** |
|
| 90 | + * Check if the template file exists. A wrapper for WP locate_template. |
|
| 91 | + * |
|
| 92 | + * @since 1.9.0 |
|
| 93 | + * |
|
| 94 | + * @param $template_name |
|
| 95 | + * @param string $template_path |
|
| 96 | + * @param string $default_path |
|
| 97 | + * |
|
| 98 | + * @return mixed|void |
|
| 99 | + */ |
|
| 100 | + public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 101 | 101 | |
| 102 | - if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | - if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 102 | + if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | + if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 104 | 104 | |
| 105 | - // Look within passed path within the theme - this is priority |
|
| 106 | - $template = locate_template( |
|
| 107 | - array( |
|
| 108 | - $template_path . $template_name, |
|
| 109 | - $template_name |
|
| 110 | - ) |
|
| 111 | - ); |
|
| 105 | + // Look within passed path within the theme - this is priority |
|
| 106 | + $template = locate_template( |
|
| 107 | + array( |
|
| 108 | + $template_path . $template_name, |
|
| 109 | + $template_name |
|
| 110 | + ) |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - // Get default template |
|
| 114 | - if ( ! $template ){ |
|
| 113 | + // Get default template |
|
| 114 | + if ( ! $template ){ |
|
| 115 | 115 | |
| 116 | - $template = $default_path . $template_name; |
|
| 116 | + $template = $default_path . $template_name; |
|
| 117 | 117 | |
| 118 | - } |
|
| 119 | - // return nothing for file that do not exist |
|
| 120 | - if( !file_exists( $template ) ){ |
|
| 121 | - $template = ''; |
|
| 122 | - } |
|
| 118 | + } |
|
| 119 | + // return nothing for file that do not exist |
|
| 120 | + if( !file_exists( $template ) ){ |
|
| 121 | + $template = ''; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // Return what we found |
|
| 125 | - return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 124 | + // Return what we found |
|
| 125 | + return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 126 | 126 | |
| 127 | - } // end locate |
|
| 127 | + } // end locate |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Determine which Sensei template to load based on the |
|
| 131 | - * current page context. |
|
| 132 | - * |
|
| 133 | - * @since 1.0 |
|
| 134 | - * |
|
| 135 | - * @param string $template |
|
| 136 | - * @return string $template |
|
| 137 | - */ |
|
| 138 | - public static function template_loader ( $template = '' ) { |
|
| 129 | + /** |
|
| 130 | + * Determine which Sensei template to load based on the |
|
| 131 | + * current page context. |
|
| 132 | + * |
|
| 133 | + * @since 1.0 |
|
| 134 | + * |
|
| 135 | + * @param string $template |
|
| 136 | + * @return string $template |
|
| 137 | + */ |
|
| 138 | + public static function template_loader ( $template = '' ) { |
|
| 139 | 139 | |
| 140 | - global $wp_query, $email_template; |
|
| 140 | + global $wp_query, $email_template; |
|
| 141 | 141 | |
| 142 | - $find = array( 'woothemes-sensei.php' ); |
|
| 143 | - $file = ''; |
|
| 142 | + $find = array( 'woothemes-sensei.php' ); |
|
| 143 | + $file = ''; |
|
| 144 | 144 | |
| 145 | - if ( isset( $email_template ) && $email_template ) { |
|
| 145 | + if ( isset( $email_template ) && $email_template ) { |
|
| 146 | 146 | |
| 147 | - $file = 'emails/' . $email_template; |
|
| 148 | - $find[] = $file; |
|
| 149 | - $find[] = Sensei()->template_url . $file; |
|
| 147 | + $file = 'emails/' . $email_template; |
|
| 148 | + $find[] = $file; |
|
| 149 | + $find[] = Sensei()->template_url . $file; |
|
| 150 | 150 | |
| 151 | - } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 151 | + } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 152 | 152 | |
| 153 | - if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 153 | + if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 154 | 154 | |
| 155 | - // possible backward compatible template include if theme overrides content-single-course.php |
|
| 156 | - // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 157 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 155 | + // possible backward compatible template include if theme overrides content-single-course.php |
|
| 156 | + // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 157 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 158 | 158 | |
| 159 | - $file = 'single-course.php'; |
|
| 160 | - $find[] = $file; |
|
| 161 | - $find[] = Sensei()->template_url . $file; |
|
| 159 | + $file = 'single-course.php'; |
|
| 160 | + $find[] = $file; |
|
| 161 | + $find[] = Sensei()->template_url . $file; |
|
| 162 | 162 | |
| 163 | - } else { |
|
| 163 | + } else { |
|
| 164 | 164 | |
| 165 | - // No Permissions Page |
|
| 166 | - return self::get_no_permission_template(); |
|
| 165 | + // No Permissions Page |
|
| 166 | + return self::get_no_permission_template(); |
|
| 167 | 167 | |
| 168 | - } // End If Statement |
|
| 168 | + } // End If Statement |
|
| 169 | 169 | |
| 170 | - } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 170 | + } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 171 | 171 | |
| 172 | - if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 172 | + if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 173 | 173 | |
| 174 | - // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 175 | - // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 176 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 174 | + // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 175 | + // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 176 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 177 | 177 | |
| 178 | - $file = 'single-lesson.php'; |
|
| 179 | - $find[] = $file; |
|
| 180 | - $find[] = Sensei()->template_url . $file; |
|
| 178 | + $file = 'single-lesson.php'; |
|
| 179 | + $find[] = $file; |
|
| 180 | + $find[] = Sensei()->template_url . $file; |
|
| 181 | 181 | |
| 182 | - } else { |
|
| 182 | + } else { |
|
| 183 | 183 | |
| 184 | - // No Permissions Page |
|
| 185 | - return self::get_no_permission_template(); |
|
| 184 | + // No Permissions Page |
|
| 185 | + return self::get_no_permission_template(); |
|
| 186 | 186 | |
| 187 | - } // End If Statement |
|
| 187 | + } // End If Statement |
|
| 188 | 188 | |
| 189 | - } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 189 | + } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 190 | 190 | |
| 191 | - if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 191 | + if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 192 | 192 | |
| 193 | - // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 194 | - // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 195 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 193 | + // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 194 | + // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 195 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 196 | 196 | |
| 197 | - $file = 'single-quiz.php'; |
|
| 198 | - $find[] = $file; |
|
| 199 | - $find[] = Sensei()->template_url . $file; |
|
| 197 | + $file = 'single-quiz.php'; |
|
| 198 | + $find[] = $file; |
|
| 199 | + $find[] = Sensei()->template_url . $file; |
|
| 200 | 200 | |
| 201 | - } else { |
|
| 201 | + } else { |
|
| 202 | 202 | |
| 203 | - // No Permissions Page |
|
| 204 | - return self::get_no_permission_template(); |
|
| 203 | + // No Permissions Page |
|
| 204 | + return self::get_no_permission_template(); |
|
| 205 | 205 | |
| 206 | - } // End If Statement |
|
| 206 | + } // End If Statement |
|
| 207 | 207 | |
| 208 | - } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 208 | + } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 209 | 209 | |
| 210 | - // possible backward compatible template include if theme overrides content-single-message.php |
|
| 211 | - // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 212 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 210 | + // possible backward compatible template include if theme overrides content-single-message.php |
|
| 211 | + // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 212 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 213 | 213 | |
| 214 | - $file = 'single-message.php'; |
|
| 215 | - $find[] = $file; |
|
| 216 | - $find[] = Sensei()->template_url . $file; |
|
| 214 | + $file = 'single-message.php'; |
|
| 215 | + $find[] = $file; |
|
| 216 | + $find[] = Sensei()->template_url . $file; |
|
| 217 | 217 | |
| 218 | - } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | - || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | - || is_tax( 'course-category' )) { |
|
| 218 | + } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | + || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | + || is_tax( 'course-category' )) { |
|
| 221 | 221 | |
| 222 | - // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 223 | - // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 224 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 222 | + // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 223 | + // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 224 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 225 | 225 | |
| 226 | - $file = 'archive-course.php'; |
|
| 227 | - $find[] = $file; |
|
| 228 | - $find[] = Sensei()->template_url . $file; |
|
| 226 | + $file = 'archive-course.php'; |
|
| 227 | + $find[] = $file; |
|
| 228 | + $find[] = Sensei()->template_url . $file; |
|
| 229 | 229 | |
| 230 | - } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 230 | + } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 231 | 231 | |
| 232 | - $file = 'archive-message.php'; |
|
| 233 | - $find[] = $file; |
|
| 234 | - $find[] = Sensei()->template_url . $file; |
|
| 232 | + $file = 'archive-message.php'; |
|
| 233 | + $find[] = $file; |
|
| 234 | + $find[] = Sensei()->template_url . $file; |
|
| 235 | 235 | |
| 236 | - } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 236 | + } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 237 | 237 | |
| 238 | - // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 239 | - // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 240 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 238 | + // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 239 | + // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 240 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 241 | 241 | |
| 242 | - $file = 'archive-lesson.php'; |
|
| 243 | - $find[] = $file; |
|
| 244 | - $find[] = Sensei()->template_url . $file; |
|
| 242 | + $file = 'archive-lesson.php'; |
|
| 243 | + $find[] = $file; |
|
| 244 | + $find[] = Sensei()->template_url . $file; |
|
| 245 | 245 | |
| 246 | - } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 246 | + } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 247 | 247 | |
| 248 | - // Override for sites with static home page |
|
| 249 | - $wp_query->is_home = false; |
|
| 248 | + // Override for sites with static home page |
|
| 249 | + $wp_query->is_home = false; |
|
| 250 | 250 | |
| 251 | - $file = 'learner-profile.php'; |
|
| 252 | - $find[] = $file; |
|
| 253 | - $find[] = Sensei()->template_url . $file; |
|
| 251 | + $file = 'learner-profile.php'; |
|
| 252 | + $find[] = $file; |
|
| 253 | + $find[] = Sensei()->template_url . $file; |
|
| 254 | 254 | |
| 255 | - } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 255 | + } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 256 | 256 | |
| 257 | - // Override for sites with static home page |
|
| 258 | - $wp_query->is_home = false; |
|
| 257 | + // Override for sites with static home page |
|
| 258 | + $wp_query->is_home = false; |
|
| 259 | 259 | |
| 260 | - $file = 'course-results.php'; |
|
| 261 | - $find[] = $file; |
|
| 262 | - $find[] = Sensei()->template_url . $file; |
|
| 260 | + $file = 'course-results.php'; |
|
| 261 | + $find[] = $file; |
|
| 262 | + $find[] = Sensei()->template_url . $file; |
|
| 263 | 263 | |
| 264 | - }elseif( is_author() |
|
| 265 | - && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | - && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 264 | + }elseif( is_author() |
|
| 265 | + && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | + && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 267 | 267 | |
| 268 | - $file = 'teacher-archive.php'; |
|
| 269 | - $find[] = $file; |
|
| 270 | - $find[] = Sensei()->template_url . $file; |
|
| 268 | + $file = 'teacher-archive.php'; |
|
| 269 | + $find[] = $file; |
|
| 270 | + $find[] = Sensei()->template_url . $file; |
|
| 271 | 271 | |
| 272 | - } // Load the template file |
|
| 272 | + } // Load the template file |
|
| 273 | 273 | |
| 274 | - if ( $file ) { |
|
| 274 | + if ( $file ) { |
|
| 275 | 275 | |
| 276 | - $template = locate_template( $find ); |
|
| 277 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 276 | + $template = locate_template( $find ); |
|
| 277 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 278 | 278 | |
| 279 | - } // End If Statement |
|
| 279 | + } // End If Statement |
|
| 280 | 280 | |
| 281 | - return $template; |
|
| 281 | + return $template; |
|
| 282 | 282 | |
| 283 | - } // End template_loader() |
|
| 283 | + } // End template_loader() |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * This function loads the no-permissions template for users with no access |
|
| 287 | - * if a Sensei template was loaded. |
|
| 288 | - * |
|
| 289 | - * This function doesn't determine the permissions. Permissions must be determined |
|
| 290 | - * before loading this function as it only gets the template. |
|
| 291 | - * |
|
| 292 | - * This function also checks the user theme for overrides to ensure the right template |
|
| 293 | - * file is returned. |
|
| 294 | - * |
|
| 295 | - * @since 1.9.0 |
|
| 296 | - */ |
|
| 297 | - public static function get_no_permission_template( ){ |
|
| 285 | + /** |
|
| 286 | + * This function loads the no-permissions template for users with no access |
|
| 287 | + * if a Sensei template was loaded. |
|
| 288 | + * |
|
| 289 | + * This function doesn't determine the permissions. Permissions must be determined |
|
| 290 | + * before loading this function as it only gets the template. |
|
| 291 | + * |
|
| 292 | + * This function also checks the user theme for overrides to ensure the right template |
|
| 293 | + * file is returned. |
|
| 294 | + * |
|
| 295 | + * @since 1.9.0 |
|
| 296 | + */ |
|
| 297 | + public static function get_no_permission_template( ){ |
|
| 298 | 298 | |
| 299 | - // possible backward compatible template loading |
|
| 300 | - // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 301 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 299 | + // possible backward compatible template loading |
|
| 300 | + // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 301 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 302 | 302 | |
| 303 | - $file = 'no-permissions.php'; |
|
| 304 | - $find[] = $file; |
|
| 305 | - $find[] = Sensei()->template_url . $file; |
|
| 303 | + $file = 'no-permissions.php'; |
|
| 304 | + $find[] = $file; |
|
| 305 | + $find[] = Sensei()->template_url . $file; |
|
| 306 | 306 | |
| 307 | - $template = locate_template( $find ); |
|
| 308 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 307 | + $template = locate_template( $find ); |
|
| 308 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 309 | 309 | |
| 310 | - return $template; |
|
| 310 | + return $template; |
|
| 311 | 311 | |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * This function is specifically created for loading template files from the theme. |
|
| 316 | - * |
|
| 317 | - * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 318 | - * around the singular content file from their theme and exit. |
|
| 319 | - * |
|
| 320 | - * If none is found this function will do nothing. If a template is found this funciton |
|
| 321 | - * will exit execution of the script an not continue. |
|
| 322 | - * |
|
| 323 | - * @since 1.9.0 |
|
| 324 | - * @param string $template |
|
| 325 | - * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 326 | - */ |
|
| 327 | - public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 314 | + /** |
|
| 315 | + * This function is specifically created for loading template files from the theme. |
|
| 316 | + * |
|
| 317 | + * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 318 | + * around the singular content file from their theme and exit. |
|
| 319 | + * |
|
| 320 | + * If none is found this function will do nothing. If a template is found this funciton |
|
| 321 | + * will exit execution of the script an not continue. |
|
| 322 | + * |
|
| 323 | + * @since 1.9.0 |
|
| 324 | + * @param string $template |
|
| 325 | + * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 326 | + */ |
|
| 327 | + public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 328 | 328 | |
| 329 | - $found_template = locate_template( array( $template ) ); |
|
| 330 | - if( $found_template ){ |
|
| 329 | + $found_template = locate_template( array( $template ) ); |
|
| 330 | + if( $found_template ){ |
|
| 331 | 331 | |
| 332 | - if( $load_header_footer ){ |
|
| 333 | - |
|
| 334 | - get_sensei_header(); |
|
| 335 | - include( $found_template ); |
|
| 336 | - get_sensei_footer(); |
|
| 332 | + if( $load_header_footer ){ |
|
| 333 | + |
|
| 334 | + get_sensei_header(); |
|
| 335 | + include( $found_template ); |
|
| 336 | + get_sensei_footer(); |
|
| 337 | 337 | |
| 338 | - }else{ |
|
| 338 | + }else{ |
|
| 339 | 339 | |
| 340 | - include( $found_template ); |
|
| 340 | + include( $found_template ); |
|
| 341 | 341 | |
| 342 | - } |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - exit; |
|
| 344 | + exit; |
|
| 345 | 345 | |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | |
| 351 | - /** |
|
| 352 | - * Hooks the deprecated archive content hook into the hook again just in |
|
| 353 | - * case other developers have used it. |
|
| 354 | - * |
|
| 355 | - * @deprecated since 1.9.0 |
|
| 356 | - */ |
|
| 357 | - public static function deprecated_archive_course_content_hook(){ |
|
| 351 | + /** |
|
| 352 | + * Hooks the deprecated archive content hook into the hook again just in |
|
| 353 | + * case other developers have used it. |
|
| 354 | + * |
|
| 355 | + * @deprecated since 1.9.0 |
|
| 356 | + */ |
|
| 357 | + public static function deprecated_archive_course_content_hook(){ |
|
| 358 | 358 | |
| 359 | - sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 360 | - |
|
| 361 | - }// end deprecated_archive_hook |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * A generic function for echoing the post title |
|
| 365 | - * |
|
| 366 | - * @since 1.9.0 |
|
| 367 | - * @param WP_Post $post |
|
| 368 | - */ |
|
| 369 | - public static function the_title( $post ){ |
|
| 359 | + sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 360 | + |
|
| 361 | + }// end deprecated_archive_hook |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * A generic function for echoing the post title |
|
| 365 | + * |
|
| 366 | + * @since 1.9.0 |
|
| 367 | + * @param WP_Post $post |
|
| 368 | + */ |
|
| 369 | + public static function the_title( $post ){ |
|
| 370 | 370 | |
| 371 | - /** |
|
| 372 | - * Filter the template html tag for the title |
|
| 373 | - * |
|
| 374 | - * @since 1.9.0 |
|
| 375 | - * |
|
| 376 | - * @param $title_html_tag default is 'h3' |
|
| 377 | - */ |
|
| 378 | - $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Filter the title classes |
|
| 382 | - * |
|
| 383 | - * @since 1.9.0 |
|
| 384 | - * @param string $title_classes defaults to $post_type-title |
|
| 385 | - */ |
|
| 386 | - $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 387 | - |
|
| 388 | - $html= ''; |
|
| 389 | - $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 390 | - $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 391 | - $html .= $post->post_title ; |
|
| 392 | - $html .= '</a>'; |
|
| 393 | - $html .= '</'. $title_html_tag. '>'; |
|
| 394 | - echo $html; |
|
| 395 | - |
|
| 396 | - }// end the title |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * This function adds the hooks inside and above the single course content for |
|
| 400 | - * backwards compatibility sake. |
|
| 401 | - * |
|
| 402 | - * @since 1.9.0 |
|
| 403 | - * @deprecated 1.9.0 |
|
| 404 | - */ |
|
| 405 | - public static function deprecated_single_course_inside_before_hooks(){ |
|
| 406 | - |
|
| 407 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 408 | - sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 409 | - sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 410 | - |
|
| 411 | - }// end deprecated_single_course_inside_before_hooks |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * This function adds the hooks to sensei_course_single_lessons for |
|
| 415 | - * backwards compatibility sake. and provides developers with an alternative. |
|
| 416 | - * |
|
| 417 | - * @since 1.9.0 |
|
| 418 | - * @deprecated 1.9.0 |
|
| 419 | - */ |
|
| 420 | - public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 371 | + /** |
|
| 372 | + * Filter the template html tag for the title |
|
| 373 | + * |
|
| 374 | + * @since 1.9.0 |
|
| 375 | + * |
|
| 376 | + * @param $title_html_tag default is 'h3' |
|
| 377 | + */ |
|
| 378 | + $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Filter the title classes |
|
| 382 | + * |
|
| 383 | + * @since 1.9.0 |
|
| 384 | + * @param string $title_classes defaults to $post_type-title |
|
| 385 | + */ |
|
| 386 | + $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 387 | + |
|
| 388 | + $html= ''; |
|
| 389 | + $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 390 | + $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 391 | + $html .= $post->post_title ; |
|
| 392 | + $html .= '</a>'; |
|
| 393 | + $html .= '</'. $title_html_tag. '>'; |
|
| 394 | + echo $html; |
|
| 395 | + |
|
| 396 | + }// end the title |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * This function adds the hooks inside and above the single course content for |
|
| 400 | + * backwards compatibility sake. |
|
| 401 | + * |
|
| 402 | + * @since 1.9.0 |
|
| 403 | + * @deprecated 1.9.0 |
|
| 404 | + */ |
|
| 405 | + public static function deprecated_single_course_inside_before_hooks(){ |
|
| 406 | + |
|
| 407 | + sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 408 | + sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 409 | + sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 410 | + |
|
| 411 | + }// end deprecated_single_course_inside_before_hooks |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * This function adds the hooks to sensei_course_single_lessons for |
|
| 415 | + * backwards compatibility sake. and provides developers with an alternative. |
|
| 416 | + * |
|
| 417 | + * @since 1.9.0 |
|
| 418 | + * @deprecated 1.9.0 |
|
| 419 | + */ |
|
| 420 | + public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 421 | 421 | |
| 422 | - sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 422 | + sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 423 | 423 | |
| 424 | - }// deprecate_sensei_course_single_lessons_hook |
|
| 424 | + }// deprecate_sensei_course_single_lessons_hook |
|
| 425 | 425 | |
| 426 | - /** |
|
| 427 | - * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 428 | - * |
|
| 429 | - * The content must be dealt with inside the respective templates. |
|
| 430 | - * |
|
| 431 | - * @since 1.9.0 |
|
| 432 | - * @deprecated 1.9.0 |
|
| 433 | - */ |
|
| 434 | - public static function deprecated_single_main_content_hook(){ |
|
| 426 | + /** |
|
| 427 | + * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 428 | + * |
|
| 429 | + * The content must be dealt with inside the respective templates. |
|
| 430 | + * |
|
| 431 | + * @since 1.9.0 |
|
| 432 | + * @deprecated 1.9.0 |
|
| 433 | + */ |
|
| 434 | + public static function deprecated_single_main_content_hook(){ |
|
| 435 | 435 | |
| 436 | - if( is_singular( 'course' ) ) { |
|
| 436 | + if( is_singular( 'course' ) ) { |
|
| 437 | 437 | |
| 438 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 438 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 439 | 439 | |
| 440 | - } elseif( is_singular( 'message' ) ){ |
|
| 440 | + } elseif( is_singular( 'message' ) ){ |
|
| 441 | 441 | |
| 442 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - }// end deprecated_single_course_single_main_content_hook |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Deprecate the old sensei modules |
|
| 449 | - * @since 1.9.0 |
|
| 450 | - * @deprecated since 1.9.0 |
|
| 451 | - */ |
|
| 452 | - public static function deprecate_module_before_hook(){ |
|
| 442 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + }// end deprecated_single_course_single_main_content_hook |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Deprecate the old sensei modules |
|
| 449 | + * @since 1.9.0 |
|
| 450 | + * @deprecated since 1.9.0 |
|
| 451 | + */ |
|
| 452 | + public static function deprecate_module_before_hook(){ |
|
| 453 | 453 | |
| 454 | - sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 454 | + sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 455 | 455 | |
| 456 | - } |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - /** |
|
| 459 | - * Deprecate the old sensei modules after hooks |
|
| 460 | - * @since 1.9.0 |
|
| 461 | - * @deprecated since 1.9.0 |
|
| 462 | - */ |
|
| 463 | - public static function deprecate_module_after_hook(){ |
|
| 458 | + /** |
|
| 459 | + * Deprecate the old sensei modules after hooks |
|
| 460 | + * @since 1.9.0 |
|
| 461 | + * @deprecated since 1.9.0 |
|
| 462 | + */ |
|
| 463 | + public static function deprecate_module_after_hook(){ |
|
| 464 | 464 | |
| 465 | - sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 465 | + sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 466 | 466 | |
| 467 | - } |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | - /** |
|
| 470 | - * Deprecate the single message hooks for post types. |
|
| 471 | - * |
|
| 472 | - * @since 1.9.0 |
|
| 473 | - * @deprecated since 1.9.0 |
|
| 474 | - */ |
|
| 475 | - public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 469 | + /** |
|
| 470 | + * Deprecate the single message hooks for post types. |
|
| 471 | + * |
|
| 472 | + * @since 1.9.0 |
|
| 473 | + * @deprecated since 1.9.0 |
|
| 474 | + */ |
|
| 475 | + public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 476 | 476 | |
| 477 | - if( is_singular( 'sensei_message' ) ){ |
|
| 477 | + if( is_singular( 'sensei_message' ) ){ |
|
| 478 | 478 | |
| 479 | - sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 479 | + sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 480 | 480 | |
| 481 | - } |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - /** |
|
| 486 | - * course_single_meta function. |
|
| 487 | - * |
|
| 488 | - * @access public |
|
| 489 | - * @return void |
|
| 490 | - * @deprecated since 1.9.0 |
|
| 491 | - */ |
|
| 492 | - public static function deprecate_course_single_meta_hooks() { |
|
| 485 | + /** |
|
| 486 | + * course_single_meta function. |
|
| 487 | + * |
|
| 488 | + * @access public |
|
| 489 | + * @return void |
|
| 490 | + * @deprecated since 1.9.0 |
|
| 491 | + */ |
|
| 492 | + public static function deprecate_course_single_meta_hooks() { |
|
| 493 | 493 | |
| 494 | - // deprecate all these hooks |
|
| 495 | - sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 496 | - sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 497 | - sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 498 | - sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 494 | + // deprecate all these hooks |
|
| 495 | + sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 496 | + sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 497 | + sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 498 | + sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 499 | 499 | |
| 500 | - } // End deprecate_course_single_meta_hooks |
|
| 500 | + } // End deprecate_course_single_meta_hooks |
|
| 501 | 501 | |
| 502 | - /** |
|
| 503 | - * Run the deprecated hooks on the single lesson page |
|
| 504 | - * @deprecated since 1.9.0 |
|
| 505 | - */ |
|
| 506 | - public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 502 | + /** |
|
| 503 | + * Run the deprecated hooks on the single lesson page |
|
| 504 | + * @deprecated since 1.9.0 |
|
| 505 | + */ |
|
| 506 | + public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 507 | 507 | |
| 508 | - if( is_singular( 'lesson' ) ){ |
|
| 508 | + if( is_singular( 'lesson' ) ){ |
|
| 509 | 509 | |
| 510 | - sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 511 | - sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 510 | + sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 511 | + sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 512 | 512 | |
| 513 | - } |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 515 | + }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Deprecate the hook sensei_lesson_course_signup. |
|
| 519 | - * |
|
| 520 | - * The hook content will be linked directly on the recommended |
|
| 521 | - * sensei_single_lesson_content_inside_after |
|
| 522 | - * |
|
| 523 | - * @deprecated since 1.9.0 |
|
| 524 | - */ |
|
| 525 | - public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 517 | + /** |
|
| 518 | + * Deprecate the hook sensei_lesson_course_signup. |
|
| 519 | + * |
|
| 520 | + * The hook content will be linked directly on the recommended |
|
| 521 | + * sensei_single_lesson_content_inside_after |
|
| 522 | + * |
|
| 523 | + * @deprecated since 1.9.0 |
|
| 524 | + */ |
|
| 525 | + public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 526 | 526 | |
| 527 | - $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 528 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 527 | + $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 528 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 529 | 529 | |
| 530 | - if( !$user_taking_course ) { |
|
| 530 | + if( !$user_taking_course ) { |
|
| 531 | 531 | |
| 532 | - sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 532 | + sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 533 | 533 | |
| 534 | - } |
|
| 535 | - }// end deprecate_sensei_lesson_course_signup_hook |
|
| 534 | + } |
|
| 535 | + }// end deprecate_sensei_lesson_course_signup_hook |
|
| 536 | 536 | |
| 537 | - /** |
|
| 538 | - * Running the deprecated hook: sensei_lesson_single_meta |
|
| 539 | - * |
|
| 540 | - * @since 1.9.0 |
|
| 541 | - * @deprecated since 1.9.0 |
|
| 542 | - */ |
|
| 543 | - public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 537 | + /** |
|
| 538 | + * Running the deprecated hook: sensei_lesson_single_meta |
|
| 539 | + * |
|
| 540 | + * @since 1.9.0 |
|
| 541 | + * @deprecated since 1.9.0 |
|
| 542 | + */ |
|
| 543 | + public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 544 | 544 | |
| 545 | - if ( sensei_can_user_view_lesson() ) { |
|
| 545 | + if ( sensei_can_user_view_lesson() ) { |
|
| 546 | 546 | |
| 547 | - sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 547 | + sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | - } |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - }// end deprecate_sensei_lesson_single_meta_hook |
|
| 552 | + }// end deprecate_sensei_lesson_single_meta_hook |
|
| 553 | 553 | |
| 554 | - /** |
|
| 555 | - * Deprecate the sensei lesson single title hook |
|
| 556 | - * @deprecated since 1.9.0 |
|
| 557 | - */ |
|
| 558 | - public static function deprecate_sensei_lesson_single_title(){ |
|
| 554 | + /** |
|
| 555 | + * Deprecate the sensei lesson single title hook |
|
| 556 | + * @deprecated since 1.9.0 |
|
| 557 | + */ |
|
| 558 | + public static function deprecate_sensei_lesson_single_title(){ |
|
| 559 | 559 | |
| 560 | - sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 560 | + sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 561 | 561 | |
| 562 | - }// end deprecate_sensei_lesson_single_title |
|
| 562 | + }// end deprecate_sensei_lesson_single_title |
|
| 563 | 563 | |
| 564 | - /** |
|
| 565 | - * hook in the deperecated single main content to the lesson |
|
| 566 | - * @deprecated since 1.9.0 |
|
| 567 | - */ |
|
| 568 | - public static function deprecate_lesson_single_main_content_hook(){ |
|
| 564 | + /** |
|
| 565 | + * hook in the deperecated single main content to the lesson |
|
| 566 | + * @deprecated since 1.9.0 |
|
| 567 | + */ |
|
| 568 | + public static function deprecate_lesson_single_main_content_hook(){ |
|
| 569 | 569 | |
| 570 | - sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 570 | + sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 571 | 571 | |
| 572 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 572 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 573 | 573 | |
| 574 | - /** |
|
| 575 | - * hook in the deperecated single main content to the lesson |
|
| 576 | - * @deprecated since 1.9.0 |
|
| 577 | - */ |
|
| 578 | - public static function deprecate_lesson_image_hook(){ |
|
| 574 | + /** |
|
| 575 | + * hook in the deperecated single main content to the lesson |
|
| 576 | + * @deprecated since 1.9.0 |
|
| 577 | + */ |
|
| 578 | + public static function deprecate_lesson_image_hook(){ |
|
| 579 | 579 | |
| 580 | - sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 580 | + sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 581 | 581 | |
| 582 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 582 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 583 | 583 | |
| 584 | - /** |
|
| 585 | - * hook in the deprecated sensei_login_form hook for backwards |
|
| 586 | - * compatibility |
|
| 587 | - * |
|
| 588 | - * @since 1.9.0 |
|
| 589 | - * @deprecated since 1.9.0 |
|
| 590 | - */ |
|
| 591 | - public static function deprecate_sensei_login_form_hook(){ |
|
| 584 | + /** |
|
| 585 | + * hook in the deprecated sensei_login_form hook for backwards |
|
| 586 | + * compatibility |
|
| 587 | + * |
|
| 588 | + * @since 1.9.0 |
|
| 589 | + * @deprecated since 1.9.0 |
|
| 590 | + */ |
|
| 591 | + public static function deprecate_sensei_login_form_hook(){ |
|
| 592 | 592 | |
| 593 | - sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 593 | + sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 594 | 594 | |
| 595 | - } // end deprecate_sensei_login_form_hook |
|
| 595 | + } // end deprecate_sensei_login_form_hook |
|
| 596 | 596 | |
| 597 | - /** |
|
| 598 | - * Fire the sensei_complete_course action. |
|
| 599 | - * |
|
| 600 | - * This is just a backwards compatible function to add the action |
|
| 601 | - * to a template. This should not be used as the function from this |
|
| 602 | - * hook will be added directly to my-courses page via one of the hooks there. |
|
| 603 | - * |
|
| 604 | - * @since 1.9.0 |
|
| 605 | - */ |
|
| 606 | - public static function fire_sensei_complete_course_hook(){ |
|
| 597 | + /** |
|
| 598 | + * Fire the sensei_complete_course action. |
|
| 599 | + * |
|
| 600 | + * This is just a backwards compatible function to add the action |
|
| 601 | + * to a template. This should not be used as the function from this |
|
| 602 | + * hook will be added directly to my-courses page via one of the hooks there. |
|
| 603 | + * |
|
| 604 | + * @since 1.9.0 |
|
| 605 | + */ |
|
| 606 | + public static function fire_sensei_complete_course_hook(){ |
|
| 607 | 607 | |
| 608 | - do_action( 'sensei_complete_course' ); |
|
| 608 | + do_action( 'sensei_complete_course' ); |
|
| 609 | 609 | |
| 610 | - } //fire_sensei_complete_course_hook |
|
| 610 | + } //fire_sensei_complete_course_hook |
|
| 611 | 611 | |
| 612 | - /** |
|
| 613 | - * Fire the frontend message hook |
|
| 614 | - * |
|
| 615 | - * @since 1.9.0 |
|
| 616 | - */ |
|
| 617 | - public static function fire_frontend_messages_hook(){ |
|
| 612 | + /** |
|
| 613 | + * Fire the frontend message hook |
|
| 614 | + * |
|
| 615 | + * @since 1.9.0 |
|
| 616 | + */ |
|
| 617 | + public static function fire_frontend_messages_hook(){ |
|
| 618 | 618 | |
| 619 | - do_action( 'sensei_frontend_messages' ); |
|
| 619 | + do_action( 'sensei_frontend_messages' ); |
|
| 620 | 620 | |
| 621 | - }// end sensei_complete_course_action |
|
| 621 | + }// end sensei_complete_course_action |
|
| 622 | 622 | |
| 623 | - /** |
|
| 624 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 625 | - * of sensei_my_courses_content_inside_before. |
|
| 626 | - * |
|
| 627 | - * @deprected since 1.9.0 |
|
| 628 | - */ |
|
| 629 | - public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 623 | + /** |
|
| 624 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 625 | + * of sensei_my_courses_content_inside_before. |
|
| 626 | + * |
|
| 627 | + * @deprected since 1.9.0 |
|
| 628 | + */ |
|
| 629 | + public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 630 | 630 | |
| 631 | - sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 631 | + sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 632 | 632 | |
| 633 | - }// deprecate_sensei_before_user_course_content_hook |
|
| 633 | + }// deprecate_sensei_before_user_course_content_hook |
|
| 634 | 634 | |
| 635 | - /** |
|
| 636 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 637 | - * of sensei_my_courses_content_inside_after hook. |
|
| 638 | - * |
|
| 639 | - * @deprected since 1.9.0 |
|
| 640 | - */ |
|
| 641 | - public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 635 | + /** |
|
| 636 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 637 | + * of sensei_my_courses_content_inside_after hook. |
|
| 638 | + * |
|
| 639 | + * @deprected since 1.9.0 |
|
| 640 | + */ |
|
| 641 | + public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 642 | 642 | |
| 643 | - sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 643 | + sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 644 | 644 | |
| 645 | - }// deprecate_sensei_after_user_course_content_hook |
|
| 645 | + }// deprecate_sensei_after_user_course_content_hook |
|
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Deprecate the 2 main hooks on the archive message template |
|
| 649 | - * |
|
| 650 | - * @deprecated since 1.9.0 |
|
| 651 | - * @since 1.9.0 |
|
| 652 | - */ |
|
| 653 | - public static function deprecated_archive_message_hooks (){ |
|
| 654 | - |
|
| 655 | - sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 656 | - sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 647 | + /** |
|
| 648 | + * Deprecate the 2 main hooks on the archive message template |
|
| 649 | + * |
|
| 650 | + * @deprecated since 1.9.0 |
|
| 651 | + * @since 1.9.0 |
|
| 652 | + */ |
|
| 653 | + public static function deprecated_archive_message_hooks (){ |
|
| 654 | + |
|
| 655 | + sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 656 | + sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 657 | 657 | |
| 658 | - } |
|
| 658 | + } |
|
| 659 | 659 | |
| 660 | - /** |
|
| 661 | - * Run the sensei_complete_quiz for those still hooking |
|
| 662 | - * into but deprecated it. |
|
| 663 | - * |
|
| 664 | - * @deprecated since 1.9.0 |
|
| 665 | - */ |
|
| 666 | - public static function deprecate_sensei_complete_quiz_action(){ |
|
| 660 | + /** |
|
| 661 | + * Run the sensei_complete_quiz for those still hooking |
|
| 662 | + * into but deprecated it. |
|
| 663 | + * |
|
| 664 | + * @deprecated since 1.9.0 |
|
| 665 | + */ |
|
| 666 | + public static function deprecate_sensei_complete_quiz_action(){ |
|
| 667 | 667 | |
| 668 | - sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 668 | + sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 669 | 669 | |
| 670 | - } |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - /** |
|
| 673 | - * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 674 | - * it to provide user with a better alternative. |
|
| 675 | - * |
|
| 676 | - * @deprecated since 1.9.0 |
|
| 677 | - */ |
|
| 678 | - public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 672 | + /** |
|
| 673 | + * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 674 | + * it to provide user with a better alternative. |
|
| 675 | + * |
|
| 676 | + * @deprecated since 1.9.0 |
|
| 677 | + */ |
|
| 678 | + public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 679 | 679 | |
| 680 | - // Question Type |
|
| 681 | - global $sensei_question_loop; |
|
| 682 | - $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 683 | - sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 684 | - |
|
| 685 | - } |
|
| 680 | + // Question Type |
|
| 681 | + global $sensei_question_loop; |
|
| 682 | + $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 683 | + sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 684 | + |
|
| 685 | + } |
|
| 686 | 686 | }//end class |
@@ -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. |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | // Admin actions |
| 40 | 40 | if ( is_admin() ) { |
| 41 | 41 | // Metabox functions |
| 42 | - add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 42 | + add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 43 | 43 | add_action( 'save_post', array( $this, 'meta_box_save' ) ); |
| 44 | 44 | // Custom Write Panel Columns |
| 45 | 45 | add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
@@ -55,47 +55,47 @@ discard block |
||
| 55 | 55 | // Update course completion upon grading of a quiz |
| 56 | 56 | add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 ); |
| 57 | 57 | |
| 58 | - // show the progress bar ont he single course page |
|
| 59 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 60 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 58 | + // show the progress bar ont he single course page |
|
| 59 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 60 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 61 | 61 | |
| 62 | - // provide an option to block all emails related to a selected course |
|
| 63 | - add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 64 | - add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 62 | + // provide an option to block all emails related to a selected course |
|
| 63 | + add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 64 | + add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 65 | 65 | |
| 66 | - // preview lessons on the course content |
|
| 67 | - add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 66 | + // preview lessons on the course content |
|
| 67 | + add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 68 | 68 | |
| 69 | - // the course meta |
|
| 70 | - add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 69 | + // the course meta |
|
| 70 | + add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 71 | 71 | |
| 72 | - // backwards compatible template hooks |
|
| 73 | - add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 74 | - add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 72 | + // backwards compatible template hooks |
|
| 73 | + add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 74 | + add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 75 | 75 | |
| 76 | - // add the user status on the course to the markup as a class |
|
| 77 | - add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 76 | + // add the user status on the course to the markup as a class |
|
| 77 | + add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 78 | 78 | |
| 79 | - //filter the course query in Sensei specific instances |
|
| 80 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 79 | + //filter the course query in Sensei specific instances |
|
| 80 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 81 | 81 | |
| 82 | - //attache the sorting to the course archive |
|
| 83 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 82 | + //attache the sorting to the course archive |
|
| 83 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 84 | 84 | |
| 85 | - //attach the filter links to the course archive |
|
| 86 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 85 | + //attach the filter links to the course archive |
|
| 86 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 87 | 87 | |
| 88 | - //filter the course query when featured filter is applied |
|
| 89 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 88 | + //filter the course query when featured filter is applied |
|
| 89 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 90 | 90 | |
| 91 | - // handle the order by title post submission |
|
| 92 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 91 | + // handle the order by title post submission |
|
| 92 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 93 | 93 | |
| 94 | - // ensure the course category page respects the manual order set for courses |
|
| 95 | - add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 94 | + // ensure the course category page respects the manual order set for courses |
|
| 95 | + add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 96 | 96 | |
| 97 | - // flush rewrite rules when saving a course |
|
| 98 | - add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 97 | + // flush rewrite rules when saving a course |
|
| 98 | + add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 99 | 99 | |
| 100 | 100 | } // End __construct() |
| 101 | 101 | |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 149 | 149 | // Add Meta Box for Course Lessons |
| 150 | 150 | add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 151 | - // Add Meta Box to link to Manage Learners |
|
| 152 | - add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 153 | - // Remove "Custom Settings" meta box. |
|
| 151 | + // Add Meta Box to link to Manage Learners |
|
| 152 | + add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 153 | + // Remove "Custom Settings" meta box. |
|
| 154 | 154 | remove_meta_box( 'woothemes-settings', $this->token, 'normal' ); |
| 155 | 155 | |
| 156 | - // add Disable email notification box |
|
| 157 | - add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 156 | + // add Disable email notification box |
|
| 157 | + add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 158 | 158 | |
| 159 | 159 | } // End meta_box_setup() |
| 160 | 160 | |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | $post_args = array( 'post_type' => array( 'product', 'product_variation' ), |
| 173 | 173 | 'posts_per_page' => -1, |
| 174 | 174 | 'orderby' => 'title', |
| 175 | - 'order' => 'DESC', |
|
| 176 | - 'exclude' => $post->ID, |
|
| 177 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 178 | - 'tax_query' => array( |
|
| 175 | + 'order' => 'DESC', |
|
| 176 | + 'exclude' => $post->ID, |
|
| 177 | + 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 178 | + 'tax_query' => array( |
|
| 179 | 179 | array( |
| 180 | 180 | 'taxonomy' => 'product_type', |
| 181 | 181 | 'field' => 'slug', |
@@ -203,21 +203,21 @@ discard block |
||
| 203 | 203 | $product_object = get_product( $post_item->ID ); |
| 204 | 204 | $parent_id = wp_get_post_parent_id( $post_item->ID ); |
| 205 | 205 | |
| 206 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 206 | + if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 207 | 207 | $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
| 208 | 208 | |
| 209 | 209 | } else { |
| 210 | - // fall back to pre wc 2.1 |
|
| 210 | + // fall back to pre wc 2.1 |
|
| 211 | 211 | $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
| 212 | 212 | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - $product_name = ucwords( $formatted_variation ); |
|
| 216 | - if( empty( $product_name ) ){ |
|
| 215 | + $product_name = ucwords( $formatted_variation ); |
|
| 216 | + if( empty( $product_name ) ){ |
|
| 217 | 217 | |
| 218 | - $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 218 | + $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 219 | 219 | |
| 220 | - } |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | } else { |
| 223 | 223 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | } else { |
| 269 | 269 | |
| 270 | - $html .= '<p>' . "\n"; |
|
| 270 | + $html .= '<p>' . "\n"; |
|
| 271 | 271 | $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n"; |
| 272 | 272 | $html .= '</p>'."\n"; |
| 273 | 273 | |
@@ -293,8 +293,8 @@ discard block |
||
| 293 | 293 | $post_args = array( 'post_type' => 'course', |
| 294 | 294 | 'posts_per_page' => -1, |
| 295 | 295 | 'orderby' => 'title', |
| 296 | - 'order' => 'DESC', |
|
| 297 | - 'exclude' => $post->ID, |
|
| 296 | + 'order' => 'DESC', |
|
| 297 | + 'exclude' => $post->ID, |
|
| 298 | 298 | 'suppress_filters' => 0 |
| 299 | 299 | ); |
| 300 | 300 | $posts_array = get_posts( $post_args ); |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | $checked = ''; |
| 337 | 337 | if ( isset( $course_featured ) && ( '' != $course_featured ) ) { |
| 338 | - $checked = checked( 'featured', $course_featured, false ); |
|
| 338 | + $checked = checked( 'featured', $course_featured, false ); |
|
| 339 | 339 | } // End If Statement |
| 340 | 340 | |
| 341 | 341 | $html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '> ' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>'; |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
| 431 | 431 | } // End If Statement |
| 432 | 432 | |
| 433 | - // update field with the new value |
|
| 434 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 433 | + // update field with the new value |
|
| 434 | + return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 435 | 435 | |
| 436 | 436 | } // End save_post_meta() |
| 437 | 437 | |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | |
| 456 | 456 | $html = ''; |
| 457 | 457 | $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' |
| 458 | - . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 459 | - . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 458 | + . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 459 | + . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 460 | 460 | |
| 461 | 461 | if ( count( $posts_array ) > 0 ) { |
| 462 | 462 | |
@@ -477,8 +477,8 @@ discard block |
||
| 477 | 477 | $html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n"; |
| 478 | 478 | |
| 479 | 479 | $html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id ) |
| 480 | - . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 481 | - . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 480 | + . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 481 | + . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 482 | 482 | |
| 483 | 483 | $html .= '</p>'."\n"; |
| 484 | 484 | } // End If Statement |
@@ -487,29 +487,29 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | } // End course_lessons_meta_box_content() |
| 489 | 489 | |
| 490 | - /** |
|
| 491 | - * course_manage_meta_box_content function. |
|
| 492 | - * |
|
| 493 | - * @since 1.9.0 |
|
| 494 | - * @access public |
|
| 495 | - * @return void |
|
| 496 | - */ |
|
| 490 | + /** |
|
| 491 | + * course_manage_meta_box_content function. |
|
| 492 | + * |
|
| 493 | + * @since 1.9.0 |
|
| 494 | + * @access public |
|
| 495 | + * @return void |
|
| 496 | + */ |
|
| 497 | 497 | |
| 498 | - public function course_manage_meta_box_content () { |
|
| 499 | - global $post; |
|
| 498 | + public function course_manage_meta_box_content () { |
|
| 499 | + global $post; |
|
| 500 | 500 | |
| 501 | - $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 501 | + $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 502 | 502 | |
| 503 | - $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 503 | + $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 504 | 504 | |
| 505 | 505 | |
| 506 | - echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 506 | + echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 507 | 507 | |
| 508 | - echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 508 | + echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 509 | 509 | |
| 510 | 510 | |
| 511 | 511 | |
| 512 | - } // End course_manage_meta_box_content() |
|
| 512 | + } // End course_manage_meta_box_content() |
|
| 513 | 513 | |
| 514 | 514 | /** |
| 515 | 515 | * Add column headings to the "lesson" post list screen. |
@@ -650,92 +650,92 @@ discard block |
||
| 650 | 650 | } // End If Statement |
| 651 | 651 | } // End If Statement |
| 652 | 652 | |
| 653 | - $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 654 | - $order = 'ASC'; |
|
| 655 | - $orderby = 'menu_order'; |
|
| 656 | - if( empty( $stored_order ) ){ |
|
| 653 | + $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 654 | + $order = 'ASC'; |
|
| 655 | + $orderby = 'menu_order'; |
|
| 656 | + if( empty( $stored_order ) ){ |
|
| 657 | 657 | |
| 658 | - $order = 'DESC'; |
|
| 659 | - $orderby = 'date'; |
|
| 658 | + $order = 'DESC'; |
|
| 659 | + $orderby = 'date'; |
|
| 660 | 660 | |
| 661 | - } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | 663 | switch ($type) { |
| 664 | 664 | |
| 665 | 665 | case 'usercourses': |
| 666 | 666 | $post_args = array( 'post_type' => 'course', |
| 667 | 667 | 'orderby' => $orderby, |
| 668 | - 'order' => $order, |
|
| 669 | - 'post_status' => 'publish', |
|
| 670 | - 'include' => $includes, |
|
| 671 | - 'exclude' => $excludes, |
|
| 672 | - 'suppress_filters' => 0 |
|
| 668 | + 'order' => $order, |
|
| 669 | + 'post_status' => 'publish', |
|
| 670 | + 'include' => $includes, |
|
| 671 | + 'exclude' => $excludes, |
|
| 672 | + 'suppress_filters' => 0 |
|
| 673 | 673 | ); |
| 674 | 674 | break; |
| 675 | 675 | case 'freecourses': |
| 676 | 676 | |
| 677 | - $post_args = array( |
|
| 678 | - 'post_type' => 'course', |
|
| 679 | - 'orderby' => $orderby, |
|
| 680 | - 'order' => $order, |
|
| 681 | - 'post_status' => 'publish', |
|
| 682 | - 'exclude' => $excludes, |
|
| 683 | - 'suppress_filters' => 0 |
|
| 684 | - ); |
|
| 685 | - // Sub Query to get all WooCommerce Products that have Zero price |
|
| 686 | - $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 677 | + $post_args = array( |
|
| 678 | + 'post_type' => 'course', |
|
| 679 | + 'orderby' => $orderby, |
|
| 680 | + 'order' => $order, |
|
| 681 | + 'post_status' => 'publish', |
|
| 682 | + 'exclude' => $excludes, |
|
| 683 | + 'suppress_filters' => 0 |
|
| 684 | + ); |
|
| 685 | + // Sub Query to get all WooCommerce Products that have Zero price |
|
| 686 | + $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 687 | 687 | |
| 688 | - break; |
|
| 688 | + break; |
|
| 689 | 689 | |
| 690 | 690 | case 'paidcourses': |
| 691 | 691 | |
| 692 | - $post_args = array( |
|
| 693 | - 'post_type' => 'course', |
|
| 694 | - 'orderby' => $orderby, |
|
| 695 | - 'order' => $order, |
|
| 696 | - 'post_status' => 'publish', |
|
| 697 | - 'exclude' => $excludes, |
|
| 698 | - 'suppress_filters' => 0 |
|
| 699 | - ); |
|
| 692 | + $post_args = array( |
|
| 693 | + 'post_type' => 'course', |
|
| 694 | + 'orderby' => $orderby, |
|
| 695 | + 'order' => $order, |
|
| 696 | + 'post_status' => 'publish', |
|
| 697 | + 'exclude' => $excludes, |
|
| 698 | + 'suppress_filters' => 0 |
|
| 699 | + ); |
|
| 700 | 700 | |
| 701 | - // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 702 | - $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 701 | + // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 702 | + $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 703 | 703 | |
| 704 | 704 | break; |
| 705 | 705 | |
| 706 | 706 | case 'featuredcourses': |
| 707 | - $post_args = array( 'post_type' => 'course', |
|
| 708 | - 'orderby' => $orderby, |
|
| 709 | - 'order' => $order, |
|
| 710 | - 'post_status' => 'publish', |
|
| 711 | - 'meta_value' => 'featured', |
|
| 712 | - 'meta_key' => '_course_featured', |
|
| 713 | - 'meta_compare' => '=', |
|
| 714 | - 'exclude' => $excludes, |
|
| 715 | - 'suppress_filters' => 0 |
|
| 707 | + $post_args = array( 'post_type' => 'course', |
|
| 708 | + 'orderby' => $orderby, |
|
| 709 | + 'order' => $order, |
|
| 710 | + 'post_status' => 'publish', |
|
| 711 | + 'meta_value' => 'featured', |
|
| 712 | + 'meta_key' => '_course_featured', |
|
| 713 | + 'meta_compare' => '=', |
|
| 714 | + 'exclude' => $excludes, |
|
| 715 | + 'suppress_filters' => 0 |
|
| 716 | 716 | ); |
| 717 | 717 | break; |
| 718 | 718 | default: |
| 719 | 719 | $post_args = array( 'post_type' => 'course', |
| 720 | - 'orderby' => $orderby, |
|
| 721 | - 'order' => $order, |
|
| 722 | - 'post_status' => 'publish', |
|
| 723 | - 'exclude' => $excludes, |
|
| 724 | - 'suppress_filters' => 0 |
|
| 720 | + 'orderby' => $orderby, |
|
| 721 | + 'order' => $order, |
|
| 722 | + 'post_status' => 'publish', |
|
| 723 | + 'exclude' => $excludes, |
|
| 724 | + 'suppress_filters' => 0 |
|
| 725 | 725 | ); |
| 726 | 726 | break; |
| 727 | 727 | |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - $post_args['posts_per_page'] = $amount; |
|
| 731 | - $paged = $wp_query->get( 'paged' ); |
|
| 732 | - $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 730 | + $post_args['posts_per_page'] = $amount; |
|
| 731 | + $paged = $wp_query->get( 'paged' ); |
|
| 732 | + $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 733 | 733 | |
| 734 | - if( 'newcourses' == $type ){ |
|
| 734 | + if( 'newcourses' == $type ){ |
|
| 735 | 735 | |
| 736 | - $post_args[ 'orderby' ] = 'date'; |
|
| 737 | - $post_args[ 'order' ] = 'DESC'; |
|
| 738 | - } |
|
| 736 | + $post_args[ 'orderby' ] = 'date'; |
|
| 737 | + $post_args[ 'order' ] = 'DESC'; |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | return $post_args; |
| 741 | 741 | } |
@@ -745,22 +745,22 @@ discard block |
||
| 745 | 745 | * course_image function. |
| 746 | 746 | * |
| 747 | 747 | * Outputs the courses image, or first image from a lesson within a course |
| 748 | - * |
|
| 749 | - * Will echo the image unless return true is specified. |
|
| 748 | + * |
|
| 749 | + * Will echo the image unless return true is specified. |
|
| 750 | 750 | * |
| 751 | 751 | * @access public |
| 752 | 752 | * @param int | WP_Post $course_id (default: 0) |
| 753 | 753 | * @param string $width (default: '100') |
| 754 | 754 | * @param string $height (default: '100') |
| 755 | - * @param bool $return default false |
|
| 756 | - * |
|
| 755 | + * @param bool $return default false |
|
| 756 | + * |
|
| 757 | 757 | * @return string | void |
| 758 | 758 | */ |
| 759 | 759 | public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) { |
| 760 | 760 | |
| 761 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 762 | - $course_id = $course_id->ID; |
|
| 763 | - } |
|
| 761 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 762 | + $course_id = $course_id->ID; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | $html = ''; |
| 766 | 766 | |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | // Display Image Placeholder if none |
| 818 | 818 | if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) { |
| 819 | 819 | |
| 820 | - $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 820 | + $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 821 | 821 | |
| 822 | 822 | } // End If Statement |
| 823 | 823 | |
@@ -831,15 +831,15 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | } // End If Statement |
| 833 | 833 | |
| 834 | - if( $return ){ |
|
| 834 | + if( $return ){ |
|
| 835 | 835 | |
| 836 | - return $html; |
|
| 836 | + return $html; |
|
| 837 | 837 | |
| 838 | - }else{ |
|
| 838 | + }else{ |
|
| 839 | 839 | |
| 840 | - echo $html; |
|
| 840 | + echo $html; |
|
| 841 | 841 | |
| 842 | - } |
|
| 842 | + } |
|
| 843 | 843 | |
| 844 | 844 | } // End course_image() |
| 845 | 845 | |
@@ -883,9 +883,9 @@ discard block |
||
| 883 | 883 | */ |
| 884 | 884 | public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) { |
| 885 | 885 | |
| 886 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 887 | - $course_id = $course_id->ID; |
|
| 888 | - } |
|
| 886 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 887 | + $course_id = $course_id->ID; |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | 890 | $post_args = array( 'post_type' => 'lesson', |
| 891 | 891 | 'posts_per_page' => -1, |
@@ -901,67 +901,67 @@ discard block |
||
| 901 | 901 | 'suppress_filters' => 0, |
| 902 | 902 | ); |
| 903 | 903 | $query_results = new WP_Query( $post_args ); |
| 904 | - $lessons = $query_results->posts; |
|
| 905 | - |
|
| 906 | - // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 907 | - // with the course order for a different course and this should not be included. It could also not |
|
| 908 | - // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 909 | - // that have been added to the course. |
|
| 910 | - if( count( $lessons) > 1 ){ |
|
| 911 | - |
|
| 912 | - foreach( $lessons as $lesson ){ |
|
| 913 | - |
|
| 914 | - $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 915 | - // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 916 | - $lesson->course_order = $order ? $order : 100000; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - /** |
|
| 923 | - * Filter runs inside Sensei_Course::course_lessons function |
|
| 924 | - * |
|
| 925 | - * Returns all lessons for a given course |
|
| 926 | - * |
|
| 927 | - * @param array $lessons |
|
| 928 | - * @param int $course_id |
|
| 929 | - */ |
|
| 930 | - $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 931 | - |
|
| 932 | - //return the requested fields |
|
| 933 | - // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 934 | - // objects |
|
| 935 | - if( 'ids' == $fields ) { |
|
| 936 | - $lesson_objects = $lessons; |
|
| 937 | - $lessons = array(); |
|
| 938 | - |
|
| 939 | - foreach ($lesson_objects as $lesson) { |
|
| 940 | - $lessons[] = $lesson->ID; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - return $lessons; |
|
| 904 | + $lessons = $query_results->posts; |
|
| 905 | + |
|
| 906 | + // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 907 | + // with the course order for a different course and this should not be included. It could also not |
|
| 908 | + // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 909 | + // that have been added to the course. |
|
| 910 | + if( count( $lessons) > 1 ){ |
|
| 911 | + |
|
| 912 | + foreach( $lessons as $lesson ){ |
|
| 913 | + |
|
| 914 | + $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 915 | + // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 916 | + $lesson->course_order = $order ? $order : 100000; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + /** |
|
| 923 | + * Filter runs inside Sensei_Course::course_lessons function |
|
| 924 | + * |
|
| 925 | + * Returns all lessons for a given course |
|
| 926 | + * |
|
| 927 | + * @param array $lessons |
|
| 928 | + * @param int $course_id |
|
| 929 | + */ |
|
| 930 | + $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 931 | + |
|
| 932 | + //return the requested fields |
|
| 933 | + // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 934 | + // objects |
|
| 935 | + if( 'ids' == $fields ) { |
|
| 936 | + $lesson_objects = $lessons; |
|
| 937 | + $lessons = array(); |
|
| 938 | + |
|
| 939 | + foreach ($lesson_objects as $lesson) { |
|
| 940 | + $lessons[] = $lesson->ID; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + return $lessons; |
|
| 945 | 945 | |
| 946 | 946 | } // End course_lessons() |
| 947 | 947 | |
| 948 | - /** |
|
| 949 | - * Used for the uasort in $this->course_lessons() |
|
| 950 | - * @since 1.8.0 |
|
| 951 | - * @access protected |
|
| 952 | - * |
|
| 953 | - * @param array $lesson_1 |
|
| 954 | - * @param array $lesson_2 |
|
| 955 | - * @return int |
|
| 956 | - */ |
|
| 957 | - protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 948 | + /** |
|
| 949 | + * Used for the uasort in $this->course_lessons() |
|
| 950 | + * @since 1.8.0 |
|
| 951 | + * @access protected |
|
| 952 | + * |
|
| 953 | + * @param array $lesson_1 |
|
| 954 | + * @param array $lesson_2 |
|
| 955 | + * @return int |
|
| 956 | + */ |
|
| 957 | + protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 958 | 958 | |
| 959 | - if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 960 | - return 0; |
|
| 961 | - } |
|
| 959 | + if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 960 | + return 0; |
|
| 961 | + } |
|
| 962 | 962 | |
| 963 | - return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 964 | - } |
|
| 963 | + return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | 966 | /** |
| 967 | 967 | * Fetch all quiz ids in a course |
@@ -1024,15 +1024,15 @@ discard block |
||
| 1024 | 1024 | */ |
| 1025 | 1025 | public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) { |
| 1026 | 1026 | |
| 1027 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1027 | + $lesson_args = array( 'post_type' => 'lesson', |
|
| 1028 | 1028 | 'posts_per_page' => -1, |
| 1029 | - 'author' => $author_id, |
|
| 1030 | - 'meta_key' => '_lesson_course', |
|
| 1031 | - 'meta_value' => $course_id, |
|
| 1032 | - 'post_status' => 'publish', |
|
| 1033 | - 'suppress_filters' => 0, |
|
| 1029 | + 'author' => $author_id, |
|
| 1030 | + 'meta_key' => '_lesson_course', |
|
| 1031 | + 'meta_value' => $course_id, |
|
| 1032 | + 'post_status' => 'publish', |
|
| 1033 | + 'suppress_filters' => 0, |
|
| 1034 | 1034 | 'fields' => 'ids', // less data to retrieve |
| 1035 | - ); |
|
| 1035 | + ); |
|
| 1036 | 1036 | $lessons_array = get_posts( $lesson_args ); |
| 1037 | 1037 | $count = count( $lessons_array ); |
| 1038 | 1038 | return $count; |
@@ -1050,17 +1050,17 @@ discard block |
||
| 1050 | 1050 | |
| 1051 | 1051 | $lesson_args = array( 'post_type' => 'lesson', |
| 1052 | 1052 | 'posts_per_page' => -1, |
| 1053 | - 'meta_key' => '_lesson_course', |
|
| 1054 | - 'meta_value' => $course_id, |
|
| 1055 | - 'post_status' => 'publish', |
|
| 1056 | - 'suppress_filters' => 0, |
|
| 1053 | + 'meta_key' => '_lesson_course', |
|
| 1054 | + 'meta_value' => $course_id, |
|
| 1055 | + 'post_status' => 'publish', |
|
| 1056 | + 'suppress_filters' => 0, |
|
| 1057 | 1057 | 'fields' => 'ids', // less data to retrieve |
| 1058 | - ); |
|
| 1058 | + ); |
|
| 1059 | 1059 | $lessons_array = get_posts( $lesson_args ); |
| 1060 | 1060 | |
| 1061 | - $count = count( $lessons_array ); |
|
| 1061 | + $count = count( $lessons_array ); |
|
| 1062 | 1062 | |
| 1063 | - return $count; |
|
| 1063 | + return $count; |
|
| 1064 | 1064 | |
| 1065 | 1065 | } // End course_lesson_count() |
| 1066 | 1066 | |
@@ -1075,9 +1075,9 @@ discard block |
||
| 1075 | 1075 | |
| 1076 | 1076 | $lesson_args = array( 'post_type' => 'lesson', |
| 1077 | 1077 | 'posts_per_page' => -1, |
| 1078 | - 'post_status' => 'publish', |
|
| 1079 | - 'suppress_filters' => 0, |
|
| 1080 | - 'meta_query' => array( |
|
| 1078 | + 'post_status' => 'publish', |
|
| 1079 | + 'suppress_filters' => 0, |
|
| 1080 | + 'meta_query' => array( |
|
| 1081 | 1081 | array( |
| 1082 | 1082 | 'key' => '_lesson_course', |
| 1083 | 1083 | 'value' => $course_id |
@@ -1088,12 +1088,12 @@ discard block |
||
| 1088 | 1088 | ) |
| 1089 | 1089 | ), |
| 1090 | 1090 | 'fields' => 'ids', // less data to retrieve |
| 1091 | - ); |
|
| 1091 | + ); |
|
| 1092 | 1092 | $lessons_array = get_posts( $lesson_args ); |
| 1093 | 1093 | |
| 1094 | 1094 | $count = count( $lessons_array ); |
| 1095 | 1095 | |
| 1096 | - return $count; |
|
| 1096 | + return $count; |
|
| 1097 | 1097 | |
| 1098 | 1098 | } // End course_lesson_count() |
| 1099 | 1099 | |
@@ -1112,8 +1112,8 @@ discard block |
||
| 1112 | 1112 | $post_args = array( 'post_type' => 'course', |
| 1113 | 1113 | 'posts_per_page' => -1, |
| 1114 | 1114 | 'meta_key' => '_course_woocommerce_product', |
| 1115 | - 'meta_value' => $product_id, |
|
| 1116 | - 'post_status' => 'publish', |
|
| 1115 | + 'meta_value' => $product_id, |
|
| 1116 | + 'post_status' => 'publish', |
|
| 1117 | 1117 | 'suppress_filters' => 0, |
| 1118 | 1118 | 'orderby' => 'menu_order date', |
| 1119 | 1119 | 'order' => 'ASC', |
@@ -1154,9 +1154,9 @@ discard block |
||
| 1154 | 1154 | |
| 1155 | 1155 | /** |
| 1156 | 1156 | * load_user_courses_content generates HTML for user's active & completed courses |
| 1157 | - * |
|
| 1158 | - * This function also ouputs the html so no need to echo the content. |
|
| 1159 | - * |
|
| 1157 | + * |
|
| 1158 | + * This function also ouputs the html so no need to echo the content. |
|
| 1159 | + * |
|
| 1160 | 1160 | * @since 1.4.0 |
| 1161 | 1161 | * @param object $user Queried user object |
| 1162 | 1162 | * @param boolean $manage Whether the user has permission to manage the courses |
@@ -1165,17 +1165,17 @@ discard block |
||
| 1165 | 1165 | public function load_user_courses_content( $user = false ) { |
| 1166 | 1166 | global $course, $my_courses_page, $my_courses_section; |
| 1167 | 1167 | |
| 1168 | - if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1169 | - || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1168 | + if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1169 | + || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1170 | 1170 | |
| 1171 | - // do not show the content if the settings doesn't allow for it |
|
| 1172 | - return; |
|
| 1171 | + // do not show the content if the settings doesn't allow for it |
|
| 1172 | + return; |
|
| 1173 | 1173 | |
| 1174 | - } |
|
| 1174 | + } |
|
| 1175 | 1175 | |
| 1176 | - $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1176 | + $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1177 | 1177 | |
| 1178 | - do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1178 | + do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1179 | 1179 | |
| 1180 | 1180 | // Build Output HTML |
| 1181 | 1181 | $complete_html = $active_html = ''; |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | // Logic for Active and Completed Courses |
| 1191 | 1191 | $per_page = 20; |
| 1192 | 1192 | if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) |
| 1193 | - && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1193 | + && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1194 | 1194 | |
| 1195 | 1195 | $per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
| 1196 | 1196 | |
@@ -1236,111 +1236,111 @@ discard block |
||
| 1236 | 1236 | } |
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | - // Get Course Categories |
|
| 1240 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1239 | + // Get Course Categories |
|
| 1240 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1241 | 1241 | |
| 1242 | - $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1242 | + $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1243 | 1243 | |
| 1244 | - // Image |
|
| 1245 | - $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1244 | + // Image |
|
| 1245 | + $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1246 | 1246 | |
| 1247 | - // Title |
|
| 1248 | - $active_html .= '<header>'; |
|
| 1247 | + // Title |
|
| 1248 | + $active_html .= '<header>'; |
|
| 1249 | 1249 | |
| 1250 | - $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>'; |
|
| 1250 | + $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>'; |
|
| 1251 | 1251 | |
| 1252 | - $active_html .= '</header>'; |
|
| 1252 | + $active_html .= '</header>'; |
|
| 1253 | 1253 | |
| 1254 | - $active_html .= '<section class="entry">'; |
|
| 1254 | + $active_html .= '<section class="entry">'; |
|
| 1255 | 1255 | |
| 1256 | - $active_html .= '<p class="sensei-course-meta">'; |
|
| 1256 | + $active_html .= '<p class="sensei-course-meta">'; |
|
| 1257 | 1257 | |
| 1258 | - // Author |
|
| 1259 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1260 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1261 | - && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1258 | + // Author |
|
| 1259 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1260 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1261 | + && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1262 | 1262 | |
| 1263 | - $active_html .= '<span class="course-author">' |
|
| 1264 | - . __( 'by ', 'woothemes-sensei' ) |
|
| 1265 | - . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1266 | - . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1267 | - . esc_html( $user_info->display_name ) |
|
| 1268 | - . '</a></span>'; |
|
| 1263 | + $active_html .= '<span class="course-author">' |
|
| 1264 | + . __( 'by ', 'woothemes-sensei' ) |
|
| 1265 | + . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1266 | + . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1267 | + . esc_html( $user_info->display_name ) |
|
| 1268 | + . '</a></span>'; |
|
| 1269 | 1269 | |
| 1270 | - } // End If Statement |
|
| 1270 | + } // End If Statement |
|
| 1271 | 1271 | |
| 1272 | - // Lesson count for this author |
|
| 1273 | - $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1274 | - // Handle Division by Zero |
|
| 1275 | - if ( 0 == $lesson_count ) { |
|
| 1272 | + // Lesson count for this author |
|
| 1273 | + $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1274 | + // Handle Division by Zero |
|
| 1275 | + if ( 0 == $lesson_count ) { |
|
| 1276 | 1276 | |
| 1277 | - $lesson_count = 1; |
|
| 1277 | + $lesson_count = 1; |
|
| 1278 | 1278 | |
| 1279 | - } // End If Statement |
|
| 1280 | - $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1281 | - // Course Categories |
|
| 1282 | - if ( '' != $category_output ) { |
|
| 1279 | + } // End If Statement |
|
| 1280 | + $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1281 | + // Course Categories |
|
| 1282 | + if ( '' != $category_output ) { |
|
| 1283 | 1283 | |
| 1284 | - $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1284 | + $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1285 | 1285 | |
| 1286 | - } // End If Statement |
|
| 1287 | - $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1286 | + } // End If Statement |
|
| 1287 | + $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1288 | 1288 | |
| 1289 | - $active_html .= '</p>'; |
|
| 1289 | + $active_html .= '</p>'; |
|
| 1290 | 1290 | |
| 1291 | - $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1291 | + $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1292 | 1292 | |
| 1293 | 1293 | |
| 1294 | 1294 | |
| 1295 | - $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1295 | + $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1296 | 1296 | |
| 1297 | - $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1297 | + $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1298 | 1298 | |
| 1299 | - $active_html .= '</section>'; |
|
| 1299 | + $active_html .= '</section>'; |
|
| 1300 | 1300 | |
| 1301 | - if( is_user_logged_in() ) { |
|
| 1301 | + if( is_user_logged_in() ) { |
|
| 1302 | 1302 | |
| 1303 | - $active_html .= '<section class="entry-actions">'; |
|
| 1303 | + $active_html .= '<section class="entry-actions">'; |
|
| 1304 | 1304 | |
| 1305 | - $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1305 | + $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1306 | 1306 | |
| 1307 | - $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' ) ) . '" />'; |
|
| 1307 | + $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' ) ) . '" />'; |
|
| 1308 | 1308 | |
| 1309 | - $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1309 | + $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1310 | 1310 | |
| 1311 | - if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1311 | + if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1312 | 1312 | |
| 1313 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1314 | - . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1313 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1314 | + . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1315 | 1315 | |
| 1316 | - } // End If Statement |
|
| 1316 | + } // End If Statement |
|
| 1317 | 1317 | |
| 1318 | - $course_purchased = false; |
|
| 1319 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1318 | + $course_purchased = false; |
|
| 1319 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1320 | 1320 | |
| 1321 | - // Get the product ID |
|
| 1322 | - $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1323 | - if ( 0 < $wc_post_id ) { |
|
| 1321 | + // Get the product ID |
|
| 1322 | + $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1323 | + if ( 0 < $wc_post_id ) { |
|
| 1324 | 1324 | |
| 1325 | - $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1325 | + $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1326 | 1326 | |
| 1327 | - } // End If Statement |
|
| 1327 | + } // End If Statement |
|
| 1328 | 1328 | |
| 1329 | - } // End If Statement |
|
| 1329 | + } // End If Statement |
|
| 1330 | 1330 | |
| 1331 | - if ( false == $course_purchased ) { |
|
| 1331 | + if ( false == $course_purchased ) { |
|
| 1332 | 1332 | |
| 1333 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1334 | - . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1333 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1334 | + . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1335 | 1335 | |
| 1336 | - } // End If Statement |
|
| 1336 | + } // End If Statement |
|
| 1337 | 1337 | |
| 1338 | - $active_html .= '</form>'; |
|
| 1338 | + $active_html .= '</form>'; |
|
| 1339 | 1339 | |
| 1340 | - $active_html .= '</section>'; |
|
| 1341 | - } |
|
| 1340 | + $active_html .= '</section>'; |
|
| 1341 | + } |
|
| 1342 | 1342 | |
| 1343 | - $active_html .= '</article>'; |
|
| 1343 | + $active_html .= '</article>'; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | // Active pagination |
@@ -1380,49 +1380,49 @@ discard block |
||
| 1380 | 1380 | foreach ( $completed_courses as $course_item ) { |
| 1381 | 1381 | $course = $course_item; |
| 1382 | 1382 | |
| 1383 | - // Get Course Categories |
|
| 1384 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1383 | + // Get Course Categories |
|
| 1384 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1385 | 1385 | |
| 1386 | - $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1386 | + $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1387 | 1387 | |
| 1388 | - // Image |
|
| 1389 | - $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1388 | + // Image |
|
| 1389 | + $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1390 | 1390 | |
| 1391 | - // Title |
|
| 1392 | - $complete_html .= '<header>'; |
|
| 1391 | + // Title |
|
| 1392 | + $complete_html .= '<header>'; |
|
| 1393 | 1393 | |
| 1394 | - $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>'; |
|
| 1394 | + $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>'; |
|
| 1395 | 1395 | |
| 1396 | - $complete_html .= '</header>'; |
|
| 1396 | + $complete_html .= '</header>'; |
|
| 1397 | 1397 | |
| 1398 | - $complete_html .= '<section class="entry">'; |
|
| 1398 | + $complete_html .= '<section class="entry">'; |
|
| 1399 | 1399 | |
| 1400 | - $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1400 | + $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1401 | 1401 | |
| 1402 | - // Author |
|
| 1403 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1404 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1405 | - $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>'; |
|
| 1406 | - } // End If Statement |
|
| 1402 | + // Author |
|
| 1403 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1404 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1405 | + $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>'; |
|
| 1406 | + } // End If Statement |
|
| 1407 | 1407 | |
| 1408 | - // Lesson count for this author |
|
| 1409 | - $complete_html .= '<span class="course-lesson-count">' |
|
| 1410 | - . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1411 | - . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1412 | - . '</span>'; |
|
| 1408 | + // Lesson count for this author |
|
| 1409 | + $complete_html .= '<span class="course-lesson-count">' |
|
| 1410 | + . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1411 | + . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1412 | + . '</span>'; |
|
| 1413 | 1413 | |
| 1414 | - // Course Categories |
|
| 1415 | - if ( '' != $category_output ) { |
|
| 1414 | + // Course Categories |
|
| 1415 | + if ( '' != $category_output ) { |
|
| 1416 | 1416 | |
| 1417 | - $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1417 | + $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1418 | 1418 | |
| 1419 | - } // End If Statement |
|
| 1419 | + } // End If Statement |
|
| 1420 | 1420 | |
| 1421 | 1421 | $complete_html .= '</p>'; |
| 1422 | 1422 | |
| 1423 | 1423 | $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
| 1424 | 1424 | |
| 1425 | - $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1425 | + $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1426 | 1426 | |
| 1427 | 1427 | if( $manage ) { |
| 1428 | 1428 | $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true ); |
@@ -1435,9 +1435,9 @@ discard block |
||
| 1435 | 1435 | if( $has_quizzes ) { |
| 1436 | 1436 | |
| 1437 | 1437 | $results_link = '<a class="button view-results" href="' |
| 1438 | - . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1439 | - . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1440 | - . '</a>'; |
|
| 1438 | + . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1439 | + . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1440 | + . '</a>'; |
|
| 1441 | 1441 | } |
| 1442 | 1442 | $complete_html .= apply_filters( 'sensei_results_links', $results_link ); |
| 1443 | 1443 | $complete_html .= '</p>'; |
@@ -1445,9 +1445,9 @@ discard block |
||
| 1445 | 1445 | } |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | - $complete_html .= '</section>'; |
|
| 1448 | + $complete_html .= '</section>'; |
|
| 1449 | 1449 | |
| 1450 | - $complete_html .= '</article>'; |
|
| 1450 | + $complete_html .= '</article>'; |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | // Active pagination |
@@ -1522,16 +1522,16 @@ discard block |
||
| 1522 | 1522 | <?php do_action( 'sensei_before_active_user_courses' ); ?> |
| 1523 | 1523 | |
| 1524 | 1524 | <?php |
| 1525 | - $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1526 | - ?> |
|
| 1525 | + $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1526 | + ?> |
|
| 1527 | 1527 | |
| 1528 | 1528 | <div id="active-courses"> |
| 1529 | 1529 | |
| 1530 | 1530 | <?php if ( '' != $active_html ) { |
| 1531 | 1531 | |
| 1532 | - echo $active_html; |
|
| 1532 | + echo $active_html; |
|
| 1533 | 1533 | |
| 1534 | - } else { ?> |
|
| 1534 | + } else { ?> |
|
| 1535 | 1535 | |
| 1536 | 1536 | <div class="sensei-message info"> |
| 1537 | 1537 | |
@@ -1557,9 +1557,9 @@ discard block |
||
| 1557 | 1557 | |
| 1558 | 1558 | <?php if ( '' != $complete_html ) { |
| 1559 | 1559 | |
| 1560 | - echo $complete_html; |
|
| 1560 | + echo $complete_html; |
|
| 1561 | 1561 | |
| 1562 | - } else { ?> |
|
| 1562 | + } else { ?> |
|
| 1563 | 1563 | |
| 1564 | 1564 | <div class="sensei-message info"> |
| 1565 | 1565 | |
@@ -1578,366 +1578,366 @@ discard block |
||
| 1578 | 1578 | <?php do_action( 'sensei_after_user_courses' ); ?> |
| 1579 | 1579 | |
| 1580 | 1580 | <?php |
| 1581 | - echo ob_get_clean(); |
|
| 1581 | + echo ob_get_clean(); |
|
| 1582 | 1582 | |
| 1583 | - do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1583 | + do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1584 | 1584 | |
| 1585 | 1585 | } // end load_user_courses_content |
| 1586 | 1586 | |
| 1587 | - /** |
|
| 1588 | - * Returns a list of all courses |
|
| 1589 | - * |
|
| 1590 | - * @since 1.8.0 |
|
| 1591 | - * @return array $courses{ |
|
| 1592 | - * @type $course WP_Post |
|
| 1593 | - * } |
|
| 1594 | - */ |
|
| 1595 | - public static function get_all_courses(){ |
|
| 1596 | - |
|
| 1597 | - $args = array( |
|
| 1598 | - 'post_type' => 'course', |
|
| 1599 | - 'posts_per_page' => -1, |
|
| 1600 | - 'orderby' => 'title', |
|
| 1601 | - 'order' => 'ASC', |
|
| 1602 | - 'post_status' => 'any', |
|
| 1603 | - 'suppress_filters' => 0, |
|
| 1604 | - ); |
|
| 1605 | - |
|
| 1606 | - $wp_query_obj = new WP_Query( $args ); |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * sensei_get_all_courses filter |
|
| 1610 | - * |
|
| 1611 | - * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1612 | - * |
|
| 1613 | - * @param array $courses{ |
|
| 1614 | - * @type WP_Post |
|
| 1615 | - * } |
|
| 1616 | - * @param array $attributes |
|
| 1617 | - */ |
|
| 1618 | - return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1619 | - |
|
| 1620 | - }// end get_all_courses |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * Generate the course meter component |
|
| 1624 | - * |
|
| 1625 | - * @since 1.8.0 |
|
| 1626 | - * @param int $progress_percentage 0 - 100 |
|
| 1627 | - * @return string $progress_bar_html |
|
| 1628 | - */ |
|
| 1629 | - public function get_progress_meter( $progress_percentage ){ |
|
| 1630 | - |
|
| 1631 | - if ( 50 < $progress_percentage ) { |
|
| 1632 | - $class = ' green'; |
|
| 1633 | - } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1634 | - $class = ' orange'; |
|
| 1635 | - } else { |
|
| 1636 | - $class = ' red'; |
|
| 1637 | - } |
|
| 1638 | - $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1639 | - |
|
| 1640 | - return $progress_bar_html; |
|
| 1641 | - |
|
| 1642 | - }// end get_progress_meter |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * Generate a statement that tells users |
|
| 1646 | - * how far they are in the course. |
|
| 1647 | - * |
|
| 1648 | - * @param int $course_id |
|
| 1649 | - * @param int $user_id |
|
| 1650 | - * |
|
| 1651 | - * @return string $statement_html |
|
| 1652 | - */ |
|
| 1653 | - public function get_progress_statement( $course_id, $user_id ){ |
|
| 1654 | - |
|
| 1655 | - if( empty( $course_id ) || empty( $user_id ) |
|
| 1656 | - || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1657 | - return ''; |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1661 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1662 | - |
|
| 1663 | - $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 ); |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * Filter the course completion statement. |
|
| 1667 | - * Default Currently completed $var lesson($plural) of $var in total |
|
| 1668 | - * |
|
| 1669 | - * @param string $statement |
|
| 1670 | - */ |
|
| 1671 | - return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1672 | - |
|
| 1673 | - }// end generate_progress_statement |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * Output the course progress statement |
|
| 1677 | - * |
|
| 1678 | - * @param $course_id |
|
| 1679 | - * @return void |
|
| 1680 | - */ |
|
| 1681 | - public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1682 | - if( empty( $course_id ) ){ |
|
| 1683 | - global $post; |
|
| 1684 | - $course_id = $post->ID; |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - if( empty( $user_id ) ){ |
|
| 1688 | - $user_id = get_current_user_id(); |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - /** |
|
| 1695 | - * Output the course progress bar |
|
| 1696 | - * |
|
| 1697 | - * @param $course_id |
|
| 1698 | - * @return void |
|
| 1699 | - */ |
|
| 1700 | - public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1701 | - |
|
| 1702 | - if( empty( $course_id ) ){ |
|
| 1703 | - global $post; |
|
| 1704 | - $course_id = $post->ID; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - if( empty( $user_id ) ){ |
|
| 1708 | - $user_id = get_current_user_id(); |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1712 | - || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1713 | - return; |
|
| 1714 | - } |
|
| 1715 | - $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1716 | - |
|
| 1717 | - echo $this->get_progress_meter( $percentage_completed ); |
|
| 1718 | - |
|
| 1719 | - }// end the_progress_meter |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * Checks how many lessons are completed |
|
| 1723 | - * |
|
| 1724 | - * @since 1.8.0 |
|
| 1725 | - * |
|
| 1726 | - * @param int $course_id |
|
| 1727 | - * @param int $user_id |
|
| 1728 | - * @return array $completed_lesson_ids |
|
| 1729 | - */ |
|
| 1730 | - public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1731 | - |
|
| 1732 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1733 | - $user_id = get_current_user_id(); |
|
| 1734 | - } |
|
| 1587 | + /** |
|
| 1588 | + * Returns a list of all courses |
|
| 1589 | + * |
|
| 1590 | + * @since 1.8.0 |
|
| 1591 | + * @return array $courses{ |
|
| 1592 | + * @type $course WP_Post |
|
| 1593 | + * } |
|
| 1594 | + */ |
|
| 1595 | + public static function get_all_courses(){ |
|
| 1596 | + |
|
| 1597 | + $args = array( |
|
| 1598 | + 'post_type' => 'course', |
|
| 1599 | + 'posts_per_page' => -1, |
|
| 1600 | + 'orderby' => 'title', |
|
| 1601 | + 'order' => 'ASC', |
|
| 1602 | + 'post_status' => 'any', |
|
| 1603 | + 'suppress_filters' => 0, |
|
| 1604 | + ); |
|
| 1605 | + |
|
| 1606 | + $wp_query_obj = new WP_Query( $args ); |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * sensei_get_all_courses filter |
|
| 1610 | + * |
|
| 1611 | + * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1612 | + * |
|
| 1613 | + * @param array $courses{ |
|
| 1614 | + * @type WP_Post |
|
| 1615 | + * } |
|
| 1616 | + * @param array $attributes |
|
| 1617 | + */ |
|
| 1618 | + return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1619 | + |
|
| 1620 | + }// end get_all_courses |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * Generate the course meter component |
|
| 1624 | + * |
|
| 1625 | + * @since 1.8.0 |
|
| 1626 | + * @param int $progress_percentage 0 - 100 |
|
| 1627 | + * @return string $progress_bar_html |
|
| 1628 | + */ |
|
| 1629 | + public function get_progress_meter( $progress_percentage ){ |
|
| 1630 | + |
|
| 1631 | + if ( 50 < $progress_percentage ) { |
|
| 1632 | + $class = ' green'; |
|
| 1633 | + } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1634 | + $class = ' orange'; |
|
| 1635 | + } else { |
|
| 1636 | + $class = ' red'; |
|
| 1637 | + } |
|
| 1638 | + $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1639 | + |
|
| 1640 | + return $progress_bar_html; |
|
| 1641 | + |
|
| 1642 | + }// end get_progress_meter |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * Generate a statement that tells users |
|
| 1646 | + * how far they are in the course. |
|
| 1647 | + * |
|
| 1648 | + * @param int $course_id |
|
| 1649 | + * @param int $user_id |
|
| 1650 | + * |
|
| 1651 | + * @return string $statement_html |
|
| 1652 | + */ |
|
| 1653 | + public function get_progress_statement( $course_id, $user_id ){ |
|
| 1654 | + |
|
| 1655 | + if( empty( $course_id ) || empty( $user_id ) |
|
| 1656 | + || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1657 | + return ''; |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1661 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1662 | + |
|
| 1663 | + $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 ); |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * Filter the course completion statement. |
|
| 1667 | + * Default Currently completed $var lesson($plural) of $var in total |
|
| 1668 | + * |
|
| 1669 | + * @param string $statement |
|
| 1670 | + */ |
|
| 1671 | + return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1672 | + |
|
| 1673 | + }// end generate_progress_statement |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * Output the course progress statement |
|
| 1677 | + * |
|
| 1678 | + * @param $course_id |
|
| 1679 | + * @return void |
|
| 1680 | + */ |
|
| 1681 | + public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1682 | + if( empty( $course_id ) ){ |
|
| 1683 | + global $post; |
|
| 1684 | + $course_id = $post->ID; |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + if( empty( $user_id ) ){ |
|
| 1688 | + $user_id = get_current_user_id(); |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + /** |
|
| 1695 | + * Output the course progress bar |
|
| 1696 | + * |
|
| 1697 | + * @param $course_id |
|
| 1698 | + * @return void |
|
| 1699 | + */ |
|
| 1700 | + public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1701 | + |
|
| 1702 | + if( empty( $course_id ) ){ |
|
| 1703 | + global $post; |
|
| 1704 | + $course_id = $post->ID; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + if( empty( $user_id ) ){ |
|
| 1708 | + $user_id = get_current_user_id(); |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1712 | + || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1713 | + return; |
|
| 1714 | + } |
|
| 1715 | + $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1716 | + |
|
| 1717 | + echo $this->get_progress_meter( $percentage_completed ); |
|
| 1718 | + |
|
| 1719 | + }// end the_progress_meter |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * Checks how many lessons are completed |
|
| 1723 | + * |
|
| 1724 | + * @since 1.8.0 |
|
| 1725 | + * |
|
| 1726 | + * @param int $course_id |
|
| 1727 | + * @param int $user_id |
|
| 1728 | + * @return array $completed_lesson_ids |
|
| 1729 | + */ |
|
| 1730 | + public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1731 | + |
|
| 1732 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1733 | + $user_id = get_current_user_id(); |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + $completed_lesson_ids = array(); |
|
| 1737 | + |
|
| 1738 | + $course_lessons = $this->course_lessons( $course_id ); |
|
| 1739 | + |
|
| 1740 | + foreach( $course_lessons as $lesson ){ |
|
| 1741 | + |
|
| 1742 | + $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1743 | + if( $is_lesson_completed ){ |
|
| 1744 | + $completed_lesson_ids[] = $lesson->ID; |
|
| 1745 | + } |
|
| 1746 | + |
|
| 1747 | + } |
|
| 1748 | + |
|
| 1749 | + return $completed_lesson_ids; |
|
| 1750 | + |
|
| 1751 | + }// end get_completed_lesson_ids |
|
| 1752 | + |
|
| 1753 | + /** |
|
| 1754 | + * Calculate the perceantage completed in the course |
|
| 1755 | + * |
|
| 1756 | + * @since 1.8.0 |
|
| 1757 | + * |
|
| 1758 | + * @param int $course_id |
|
| 1759 | + * @param int $user_id |
|
| 1760 | + * @return int $percentage |
|
| 1761 | + */ |
|
| 1762 | + public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1763 | + |
|
| 1764 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1765 | + $user_id = get_current_user_id(); |
|
| 1766 | + } |
|
| 1735 | 1767 | |
| 1736 | - $completed_lesson_ids = array(); |
|
| 1768 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1737 | 1769 | |
| 1738 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 1770 | + if( ! ( $completed > 0 ) ){ |
|
| 1771 | + return 0; |
|
| 1772 | + } |
|
| 1739 | 1773 | |
| 1740 | - foreach( $course_lessons as $lesson ){ |
|
| 1774 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1775 | + $percentage = $completed / $total_lessons * 100; |
|
| 1741 | 1776 | |
| 1742 | - $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1743 | - if( $is_lesson_completed ){ |
|
| 1744 | - $completed_lesson_ids[] = $lesson->ID; |
|
| 1745 | - } |
|
| 1746 | - |
|
| 1747 | - } |
|
| 1748 | - |
|
| 1749 | - return $completed_lesson_ids; |
|
| 1777 | + /** |
|
| 1778 | + * |
|
| 1779 | + * Filter the percentage returned for a users course. |
|
| 1780 | + * |
|
| 1781 | + * @param $percentage |
|
| 1782 | + * @param $course_id |
|
| 1783 | + * @param $user_id |
|
| 1784 | + * @since 1.8.0 |
|
| 1785 | + */ |
|
| 1786 | + return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1750 | 1787 | |
| 1751 | - }// end get_completed_lesson_ids |
|
| 1788 | + }// end get_completed_lesson_ids |
|
| 1752 | 1789 | |
| 1753 | - /** |
|
| 1754 | - * Calculate the perceantage completed in the course |
|
| 1755 | - * |
|
| 1756 | - * @since 1.8.0 |
|
| 1757 | - * |
|
| 1758 | - * @param int $course_id |
|
| 1759 | - * @param int $user_id |
|
| 1760 | - * @return int $percentage |
|
| 1761 | - */ |
|
| 1762 | - public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1763 | - |
|
| 1764 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1765 | - $user_id = get_current_user_id(); |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1769 | - |
|
| 1770 | - if( ! ( $completed > 0 ) ){ |
|
| 1771 | - return 0; |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1775 | - $percentage = $completed / $total_lessons * 100; |
|
| 1776 | - |
|
| 1777 | - /** |
|
| 1778 | - * |
|
| 1779 | - * Filter the percentage returned for a users course. |
|
| 1780 | - * |
|
| 1781 | - * @param $percentage |
|
| 1782 | - * @param $course_id |
|
| 1783 | - * @param $user_id |
|
| 1784 | - * @since 1.8.0 |
|
| 1785 | - */ |
|
| 1786 | - return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1790 | + /** |
|
| 1791 | + * Block email notifications for the specific courses |
|
| 1792 | + * that the user disabled the notifications. |
|
| 1793 | + * |
|
| 1794 | + * @since 1.8.0 |
|
| 1795 | + * @param $should_send |
|
| 1796 | + * @return bool |
|
| 1797 | + */ |
|
| 1798 | + public function block_notification_emails( $should_send ){ |
|
| 1799 | + global $sensei_email_data; |
|
| 1800 | + $email = $sensei_email_data; |
|
| 1787 | 1801 | |
| 1788 | - }// end get_completed_lesson_ids |
|
| 1802 | + $course_id = ''; |
|
| 1789 | 1803 | |
| 1790 | - /** |
|
| 1791 | - * Block email notifications for the specific courses |
|
| 1792 | - * that the user disabled the notifications. |
|
| 1793 | - * |
|
| 1794 | - * @since 1.8.0 |
|
| 1795 | - * @param $should_send |
|
| 1796 | - * @return bool |
|
| 1797 | - */ |
|
| 1798 | - public function block_notification_emails( $should_send ){ |
|
| 1799 | - global $sensei_email_data; |
|
| 1800 | - $email = $sensei_email_data; |
|
| 1804 | + if( isset( $email['course_id'] ) ){ |
|
| 1801 | 1805 | |
| 1802 | - $course_id = ''; |
|
| 1806 | + $course_id = $email['course_id']; |
|
| 1803 | 1807 | |
| 1804 | - if( isset( $email['course_id'] ) ){ |
|
| 1808 | + }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1805 | 1809 | |
| 1806 | - $course_id = $email['course_id']; |
|
| 1810 | + $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1807 | 1811 | |
| 1808 | - }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1812 | + }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1809 | 1813 | |
| 1810 | - $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1814 | + $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1815 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1811 | 1816 | |
| 1812 | - }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1817 | + } |
|
| 1813 | 1818 | |
| 1814 | - $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1815 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1819 | + if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1816 | 1820 | |
| 1817 | - } |
|
| 1821 | + $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1818 | 1822 | |
| 1819 | - if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | + if ($course_emails_disabled) { |
|
| 1820 | 1824 | |
| 1821 | - $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | + return false; |
|
| 1822 | 1826 | |
| 1823 | - if ($course_emails_disabled) { |
|
| 1827 | + } |
|
| 1824 | 1828 | |
| 1825 | - return false; |
|
| 1829 | + }// end if |
|
| 1826 | 1830 | |
| 1827 | - } |
|
| 1831 | + return $should_send; |
|
| 1832 | + }// end block_notification_emails |
|
| 1828 | 1833 | |
| 1829 | - }// end if |
|
| 1834 | + /** |
|
| 1835 | + * Render the course notification setting meta box |
|
| 1836 | + * |
|
| 1837 | + * @since 1.8.0 |
|
| 1838 | + * @param $course |
|
| 1839 | + */ |
|
| 1840 | + public function course_notification_meta_box_content( $course ){ |
|
| 1830 | 1841 | |
| 1831 | - return $should_send; |
|
| 1832 | - }// end block_notification_emails |
|
| 1842 | + $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1833 | 1843 | |
| 1834 | - /** |
|
| 1835 | - * Render the course notification setting meta box |
|
| 1836 | - * |
|
| 1837 | - * @since 1.8.0 |
|
| 1838 | - * @param $course |
|
| 1839 | - */ |
|
| 1840 | - public function course_notification_meta_box_content( $course ){ |
|
| 1844 | + // generate checked html |
|
| 1845 | + $checked_html = ''; |
|
| 1846 | + if( $checked ){ |
|
| 1847 | + $checked_html = 'checked="checked"'; |
|
| 1848 | + } |
|
| 1849 | + wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1841 | 1850 | |
| 1842 | - $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1851 | + echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1852 | + echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1843 | 1853 | |
| 1844 | - // generate checked html |
|
| 1845 | - $checked_html = ''; |
|
| 1846 | - if( $checked ){ |
|
| 1847 | - $checked_html = 'checked="checked"'; |
|
| 1848 | - } |
|
| 1849 | - wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1854 | + }// end course_notification_meta_box_content |
|
| 1850 | 1855 | |
| 1851 | - echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1852 | - echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1853 | - |
|
| 1854 | - }// end course_notification_meta_box_content |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * Store the setting for the course notification setting. |
|
| 1858 | - * |
|
| 1859 | - * @hooked int save_post |
|
| 1860 | - * @since 1.8.0 |
|
| 1861 | - * |
|
| 1862 | - * @param $course_id |
|
| 1863 | - */ |
|
| 1864 | - public function save_course_notification_meta_box( $course_id ){ |
|
| 1856 | + /** |
|
| 1857 | + * Store the setting for the course notification setting. |
|
| 1858 | + * |
|
| 1859 | + * @hooked int save_post |
|
| 1860 | + * @since 1.8.0 |
|
| 1861 | + * |
|
| 1862 | + * @param $course_id |
|
| 1863 | + */ |
|
| 1864 | + public function save_course_notification_meta_box( $course_id ){ |
|
| 1865 | 1865 | |
| 1866 | - if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1867 | - || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1868 | - return; |
|
| 1869 | - } |
|
| 1866 | + if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1867 | + || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1868 | + return; |
|
| 1869 | + } |
|
| 1870 | 1870 | |
| 1871 | - if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1872 | - $new_val = true; |
|
| 1873 | - }else{ |
|
| 1874 | - $new_val = false; |
|
| 1875 | - } |
|
| 1871 | + if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1872 | + $new_val = true; |
|
| 1873 | + }else{ |
|
| 1874 | + $new_val = false; |
|
| 1875 | + } |
|
| 1876 | 1876 | |
| 1877 | - update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1877 | + update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1878 | 1878 | |
| 1879 | - }// end save notification meta box |
|
| 1879 | + }// end save notification meta box |
|
| 1880 | 1880 | |
| 1881 | - /** |
|
| 1882 | - * Backwards compatibility hooks added to ensure that |
|
| 1883 | - * plugins and other parts of sensei still works. |
|
| 1884 | - * |
|
| 1885 | - * This function hooks into `sensei_course_content_inside_before` |
|
| 1886 | - * |
|
| 1887 | - * @since 1.9 |
|
| 1888 | - * |
|
| 1889 | - * @param WP_Post $post |
|
| 1890 | - */ |
|
| 1891 | - public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1881 | + /** |
|
| 1882 | + * Backwards compatibility hooks added to ensure that |
|
| 1883 | + * plugins and other parts of sensei still works. |
|
| 1884 | + * |
|
| 1885 | + * This function hooks into `sensei_course_content_inside_before` |
|
| 1886 | + * |
|
| 1887 | + * @since 1.9 |
|
| 1888 | + * |
|
| 1889 | + * @param WP_Post $post |
|
| 1890 | + */ |
|
| 1891 | + public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1892 | 1892 | |
| 1893 | - if( has_action( 'sensei_course_image' ) ){ |
|
| 1893 | + if( has_action( 'sensei_course_image' ) ){ |
|
| 1894 | 1894 | |
| 1895 | - _doing_it_wrong('sensei_course_image','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1896 | - do_action('sensei_course_image', $post->ID ); |
|
| 1895 | + _doing_it_wrong('sensei_course_image','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1896 | + do_action('sensei_course_image', $post->ID ); |
|
| 1897 | 1897 | |
| 1898 | - } |
|
| 1898 | + } |
|
| 1899 | 1899 | |
| 1900 | - if( has_action( 'sensei_course_archive_course_title' ) ){ |
|
| 1900 | + if( has_action( 'sensei_course_archive_course_title' ) ){ |
|
| 1901 | 1901 | |
| 1902 | - _doing_it_wrong('sensei_course_archive_course_title','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1903 | - do_action('sensei_course_archive_course_title', $post ); |
|
| 1902 | + _doing_it_wrong('sensei_course_archive_course_title','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1903 | + do_action('sensei_course_archive_course_title', $post ); |
|
| 1904 | 1904 | |
| 1905 | - } |
|
| 1905 | + } |
|
| 1906 | 1906 | |
| 1907 | - } |
|
| 1907 | + } |
|
| 1908 | 1908 | |
| 1909 | - /** |
|
| 1910 | - * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1911 | - * |
|
| 1912 | - * hooked into 'sensei_loop_course_before' |
|
| 1913 | - * |
|
| 1914 | - * @since 1.9 |
|
| 1915 | - * |
|
| 1916 | - * @global WP_Post $post |
|
| 1917 | - */ |
|
| 1918 | - public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1919 | - |
|
| 1920 | - global $post; |
|
| 1921 | - sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1922 | - |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1927 | - * |
|
| 1928 | - * hooked into 'sensei_course_content_inside_after' |
|
| 1929 | - * |
|
| 1930 | - * @since 1.9.0 |
|
| 1931 | - * |
|
| 1932 | - * @param WP_Post $course |
|
| 1933 | - */ |
|
| 1934 | - public function the_course_free_lesson_preview( $course ){ |
|
| 1935 | - // Meta data |
|
| 1936 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1937 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1938 | - |
|
| 1939 | - if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1940 | - ?> |
|
| 1909 | + /** |
|
| 1910 | + * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1911 | + * |
|
| 1912 | + * hooked into 'sensei_loop_course_before' |
|
| 1913 | + * |
|
| 1914 | + * @since 1.9 |
|
| 1915 | + * |
|
| 1916 | + * @global WP_Post $post |
|
| 1917 | + */ |
|
| 1918 | + public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1919 | + |
|
| 1920 | + global $post; |
|
| 1921 | + sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1922 | + |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1927 | + * |
|
| 1928 | + * hooked into 'sensei_course_content_inside_after' |
|
| 1929 | + * |
|
| 1930 | + * @since 1.9.0 |
|
| 1931 | + * |
|
| 1932 | + * @param WP_Post $course |
|
| 1933 | + */ |
|
| 1934 | + public function the_course_free_lesson_preview( $course ){ |
|
| 1935 | + // Meta data |
|
| 1936 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1937 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1938 | + |
|
| 1939 | + if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1940 | + ?> |
|
| 1941 | 1941 | <p class="sensei-free-lessons"> |
| 1942 | 1942 | <a href="<?php echo get_permalink(); ?>"> |
| 1943 | 1943 | <?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
@@ -1946,22 +1946,22 @@ discard block |
||
| 1946 | 1946 | </p> |
| 1947 | 1947 | |
| 1948 | 1948 | <?php |
| 1949 | - } |
|
| 1950 | - } |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | 1951 | |
| 1952 | - /** |
|
| 1953 | - * Add course mata to the course meta hook |
|
| 1954 | - * |
|
| 1955 | - * @since 1.9.0 |
|
| 1956 | - * @param WP_Post $course |
|
| 1957 | - */ |
|
| 1958 | - public function the_course_meta( $course ){ |
|
| 1959 | - echo '<p class="sensei-course-meta">'; |
|
| 1952 | + /** |
|
| 1953 | + * Add course mata to the course meta hook |
|
| 1954 | + * |
|
| 1955 | + * @since 1.9.0 |
|
| 1956 | + * @param WP_Post $course |
|
| 1957 | + */ |
|
| 1958 | + public function the_course_meta( $course ){ |
|
| 1959 | + echo '<p class="sensei-course-meta">'; |
|
| 1960 | 1960 | |
| 1961 | - $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1962 | - $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1961 | + $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1962 | + $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1963 | 1963 | |
| 1964 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1964 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1965 | 1965 | |
| 1966 | 1966 | <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?> |
| 1967 | 1967 | |
@@ -1979,59 +1979,59 @@ discard block |
||
| 1979 | 1979 | |
| 1980 | 1980 | <?php } // End If Statement |
| 1981 | 1981 | |
| 1982 | - // number of completed lessons |
|
| 1983 | - if( is_user_logged_in() ){ |
|
| 1984 | - $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1985 | - $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1986 | - echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1987 | - } |
|
| 1982 | + // number of completed lessons |
|
| 1983 | + if( is_user_logged_in() ){ |
|
| 1984 | + $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1985 | + $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1986 | + echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1987 | + } |
|
| 1988 | 1988 | |
| 1989 | - sensei_simple_course_price( $course->ID ); |
|
| 1989 | + sensei_simple_course_price( $course->ID ); |
|
| 1990 | 1990 | |
| 1991 | - echo '</p>'; |
|
| 1992 | - } // end the course meta |
|
| 1991 | + echo '</p>'; |
|
| 1992 | + } // end the course meta |
|
| 1993 | 1993 | |
| 1994 | - /** |
|
| 1995 | - * Filter the classes attached to a post types for courses |
|
| 1996 | - * and add a status class for when the user is logged in. |
|
| 1997 | - * |
|
| 1998 | - * @param $classes |
|
| 1999 | - * @param $class |
|
| 2000 | - * @param $post_id |
|
| 2001 | - * |
|
| 2002 | - * @return array $classes |
|
| 2003 | - */ |
|
| 2004 | - public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1994 | + /** |
|
| 1995 | + * Filter the classes attached to a post types for courses |
|
| 1996 | + * and add a status class for when the user is logged in. |
|
| 1997 | + * |
|
| 1998 | + * @param $classes |
|
| 1999 | + * @param $class |
|
| 2000 | + * @param $post_id |
|
| 2001 | + * |
|
| 2002 | + * @return array $classes |
|
| 2003 | + */ |
|
| 2004 | + public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 2005 | 2005 | |
| 2006 | - if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 2006 | + if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 2007 | 2007 | |
| 2008 | - if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2008 | + if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2009 | 2009 | |
| 2010 | - $classes[] = 'user-status-completed'; |
|
| 2010 | + $classes[] = 'user-status-completed'; |
|
| 2011 | 2011 | |
| 2012 | - }else{ |
|
| 2012 | + }else{ |
|
| 2013 | 2013 | |
| 2014 | - $classes[] = 'user-status-active'; |
|
| 2014 | + $classes[] = 'user-status-active'; |
|
| 2015 | 2015 | |
| 2016 | - } |
|
| 2016 | + } |
|
| 2017 | 2017 | |
| 2018 | - } |
|
| 2018 | + } |
|
| 2019 | 2019 | |
| 2020 | - return $classes; |
|
| 2020 | + return $classes; |
|
| 2021 | 2021 | |
| 2022 | - }// end add_course_user_status_class |
|
| 2022 | + }// end add_course_user_status_class |
|
| 2023 | 2023 | |
| 2024 | - /** |
|
| 2025 | - * Prints out the course action buttons links |
|
| 2026 | - * |
|
| 2027 | - * - complete course |
|
| 2028 | - * - delete course |
|
| 2029 | - * |
|
| 2030 | - * @param WP_Post $course |
|
| 2031 | - */ |
|
| 2032 | - public static function the_course_action_buttons( $course ){ |
|
| 2024 | + /** |
|
| 2025 | + * Prints out the course action buttons links |
|
| 2026 | + * |
|
| 2027 | + * - complete course |
|
| 2028 | + * - delete course |
|
| 2029 | + * |
|
| 2030 | + * @param WP_Post $course |
|
| 2031 | + */ |
|
| 2032 | + public static function the_course_action_buttons( $course ){ |
|
| 2033 | 2033 | |
| 2034 | - if( is_user_logged_in() ) { ?> |
|
| 2034 | + if( is_user_logged_in() ) { ?> |
|
| 2035 | 2035 | |
| 2036 | 2036 | <section class="entry-actions"> |
| 2037 | 2037 | <form method="POST" action="<?php echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>"> |
@@ -2050,32 +2050,32 @@ discard block |
||
| 2050 | 2050 | |
| 2051 | 2051 | <?php } // End If Statement |
| 2052 | 2052 | |
| 2053 | - $course_purchased = false; |
|
| 2054 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2055 | - // Get the product ID |
|
| 2056 | - $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2057 | - if ( 0 < $wc_post_id ) { |
|
| 2053 | + $course_purchased = false; |
|
| 2054 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2055 | + // Get the product ID |
|
| 2056 | + $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2057 | + if ( 0 < $wc_post_id ) { |
|
| 2058 | 2058 | |
| 2059 | - $user = wp_get_current_user(); |
|
| 2060 | - $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2059 | + $user = wp_get_current_user(); |
|
| 2060 | + $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2061 | 2061 | |
| 2062 | - } // End If Statement |
|
| 2063 | - } // End If Statement |
|
| 2062 | + } // End If Statement |
|
| 2063 | + } // End If Statement |
|
| 2064 | 2064 | |
| 2065 | - if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2065 | + if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2066 | 2066 | |
| 2067 | 2067 | <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span> |
| 2068 | 2068 | |
| 2069 | 2069 | <?php } // End If Statement |
| 2070 | 2070 | |
| 2071 | - $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2072 | - $results_link = ''; |
|
| 2073 | - if( $has_quizzes ){ |
|
| 2074 | - $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2075 | - } |
|
| 2071 | + $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2072 | + $results_link = ''; |
|
| 2073 | + if( $has_quizzes ){ |
|
| 2074 | + $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2075 | + } |
|
| 2076 | 2076 | |
| 2077 | - // Output only if there is content to display |
|
| 2078 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2077 | + // Output only if there is content to display |
|
| 2078 | + if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2079 | 2079 | |
| 2080 | 2080 | <p class="sensei-results-links"> |
| 2081 | 2081 | <?php echo apply_filters( 'sensei_results_links', $results_link ); ?> |
@@ -2087,440 +2087,440 @@ discard block |
||
| 2087 | 2087 | |
| 2088 | 2088 | <?php }// end if is user logged in |
| 2089 | 2089 | |
| 2090 | - }// end the_course_action_buttons |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * This function alter the main query on the course archive page. |
|
| 2094 | - * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2095 | - * |
|
| 2096 | - * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2097 | - * query parameters via the arguments. |
|
| 2098 | - * |
|
| 2099 | - * This function is hooked into pre_get_posts filter |
|
| 2100 | - * |
|
| 2101 | - * @since 1.9.0 |
|
| 2102 | - * |
|
| 2103 | - * @param WP_Query $query |
|
| 2104 | - * @return WP_Query $query |
|
| 2105 | - */ |
|
| 2106 | - public static function course_query_filter( $query ){ |
|
| 2107 | - |
|
| 2108 | - // exit early for no course queries and admin queries |
|
| 2109 | - if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2110 | - return $query; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - global $post; // used to get the current page id for my courses |
|
| 2114 | - |
|
| 2115 | - // for the course archive page |
|
| 2116 | - if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2117 | - { |
|
| 2118 | - |
|
| 2119 | - $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2120 | - |
|
| 2121 | - } |
|
| 2122 | - // for the my courses page |
|
| 2123 | - elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2124 | - { |
|
| 2125 | - |
|
| 2126 | - $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2127 | - |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - return $query; |
|
| 2131 | - |
|
| 2132 | - }// end course_query_filter |
|
| 2133 | - |
|
| 2134 | - /** |
|
| 2135 | - * Determine the class of the course loop |
|
| 2136 | - * |
|
| 2137 | - * This will output .first or .last and .course-item-number-x |
|
| 2138 | - * |
|
| 2139 | - * @return array $extra_classes |
|
| 2140 | - * @since 1.9.0 |
|
| 2141 | - */ |
|
| 2142 | - public static function get_course_loop_content_class () |
|
| 2143 | - { |
|
| 2144 | - |
|
| 2145 | - global $sensei_course_loop; |
|
| 2146 | - |
|
| 2147 | - |
|
| 2148 | - if( !isset( $sensei_course_loop ) ){ |
|
| 2149 | - $sensei_course_loop = array(); |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - if (!isset($sensei_course_loop['counter'])) { |
|
| 2153 | - $sensei_course_loop['counter'] = 0; |
|
| 2154 | - } |
|
| 2155 | - |
|
| 2156 | - if (!isset($sensei_course_loop['columns'])) { |
|
| 2157 | - $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2158 | - } |
|
| 2159 | - |
|
| 2160 | - // increment the counter |
|
| 2161 | - $sensei_course_loop['counter']++; |
|
| 2162 | - |
|
| 2163 | - $extra_classes = array(); |
|
| 2164 | - if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2165 | - $extra_classes[] = 'first'; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2169 | - $extra_classes[] = 'last'; |
|
| 2170 | - } |
|
| 2171 | - |
|
| 2172 | - // add the item number to the classes as well. |
|
| 2173 | - $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2174 | - |
|
| 2175 | - /** |
|
| 2176 | - * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2177 | - * which is called from the course loop content-course.php |
|
| 2178 | - * |
|
| 2179 | - * @since 1.9.0 |
|
| 2180 | - * |
|
| 2181 | - * @param array $extra_classes |
|
| 2182 | - * @param WP_Post $loop_current_course |
|
| 2183 | - */ |
|
| 2184 | - return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2185 | - |
|
| 2186 | - }// end get_course_loop_class |
|
| 2187 | - |
|
| 2188 | - /** |
|
| 2189 | - * Get the number of columns set for Sensei courses |
|
| 2190 | - * |
|
| 2191 | - * @since 1.9.0 |
|
| 2192 | - * @return mixed|void |
|
| 2193 | - */ |
|
| 2194 | - public static function get_loop_number_of_columns(){ |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * Filter the number of columns on the course archive page. |
|
| 2198 | - * |
|
| 2199 | - * @since 1.9.0 |
|
| 2200 | - * @param int $number_of_columns default 1 |
|
| 2201 | - */ |
|
| 2202 | - return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2203 | - |
|
| 2204 | - } |
|
| 2205 | - |
|
| 2206 | - /** |
|
| 2207 | - * Output the course archive filter markup |
|
| 2208 | - * |
|
| 2209 | - * hooked into sensei_loop_course_before |
|
| 2210 | - * |
|
| 2211 | - * @since 1.9.0 |
|
| 2212 | - * @param |
|
| 2213 | - */ |
|
| 2214 | - public static function course_archive_sorting( $query ){ |
|
| 2215 | - |
|
| 2216 | - // don't show on category pages and other pages |
|
| 2217 | - if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2218 | - return; |
|
| 2219 | - } |
|
| 2220 | - |
|
| 2221 | - /** |
|
| 2222 | - * Filter the sensei archive course order by values |
|
| 2223 | - * |
|
| 2224 | - * @since 1.9.0 |
|
| 2225 | - * @param array $options { |
|
| 2226 | - * @type string $option_value |
|
| 2227 | - * @type string $option_string |
|
| 2228 | - * } |
|
| 2229 | - */ |
|
| 2230 | - $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2231 | - "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2232 | - "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2233 | - )); |
|
| 2234 | - |
|
| 2235 | - // setup the currently selected item |
|
| 2236 | - $selected = 'newness'; |
|
| 2237 | - if( isset( $_GET['orderby'] ) ){ |
|
| 2238 | - |
|
| 2239 | - $selected = $_GET[ 'orderby' ]; |
|
| 2240 | - |
|
| 2241 | - } |
|
| 2242 | - |
|
| 2243 | - ?> |
|
| 2090 | + }// end the_course_action_buttons |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * This function alter the main query on the course archive page. |
|
| 2094 | + * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2095 | + * |
|
| 2096 | + * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2097 | + * query parameters via the arguments. |
|
| 2098 | + * |
|
| 2099 | + * This function is hooked into pre_get_posts filter |
|
| 2100 | + * |
|
| 2101 | + * @since 1.9.0 |
|
| 2102 | + * |
|
| 2103 | + * @param WP_Query $query |
|
| 2104 | + * @return WP_Query $query |
|
| 2105 | + */ |
|
| 2106 | + public static function course_query_filter( $query ){ |
|
| 2107 | + |
|
| 2108 | + // exit early for no course queries and admin queries |
|
| 2109 | + if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2110 | + return $query; |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + global $post; // used to get the current page id for my courses |
|
| 2114 | + |
|
| 2115 | + // for the course archive page |
|
| 2116 | + if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2117 | + { |
|
| 2118 | + |
|
| 2119 | + $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2120 | + |
|
| 2121 | + } |
|
| 2122 | + // for the my courses page |
|
| 2123 | + elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2124 | + { |
|
| 2125 | + |
|
| 2126 | + $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2127 | + |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + return $query; |
|
| 2131 | + |
|
| 2132 | + }// end course_query_filter |
|
| 2133 | + |
|
| 2134 | + /** |
|
| 2135 | + * Determine the class of the course loop |
|
| 2136 | + * |
|
| 2137 | + * This will output .first or .last and .course-item-number-x |
|
| 2138 | + * |
|
| 2139 | + * @return array $extra_classes |
|
| 2140 | + * @since 1.9.0 |
|
| 2141 | + */ |
|
| 2142 | + public static function get_course_loop_content_class () |
|
| 2143 | + { |
|
| 2144 | + |
|
| 2145 | + global $sensei_course_loop; |
|
| 2146 | + |
|
| 2147 | + |
|
| 2148 | + if( !isset( $sensei_course_loop ) ){ |
|
| 2149 | + $sensei_course_loop = array(); |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + if (!isset($sensei_course_loop['counter'])) { |
|
| 2153 | + $sensei_course_loop['counter'] = 0; |
|
| 2154 | + } |
|
| 2155 | + |
|
| 2156 | + if (!isset($sensei_course_loop['columns'])) { |
|
| 2157 | + $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2158 | + } |
|
| 2159 | + |
|
| 2160 | + // increment the counter |
|
| 2161 | + $sensei_course_loop['counter']++; |
|
| 2162 | + |
|
| 2163 | + $extra_classes = array(); |
|
| 2164 | + if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2165 | + $extra_classes[] = 'first'; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2169 | + $extra_classes[] = 'last'; |
|
| 2170 | + } |
|
| 2171 | + |
|
| 2172 | + // add the item number to the classes as well. |
|
| 2173 | + $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2174 | + |
|
| 2175 | + /** |
|
| 2176 | + * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2177 | + * which is called from the course loop content-course.php |
|
| 2178 | + * |
|
| 2179 | + * @since 1.9.0 |
|
| 2180 | + * |
|
| 2181 | + * @param array $extra_classes |
|
| 2182 | + * @param WP_Post $loop_current_course |
|
| 2183 | + */ |
|
| 2184 | + return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2185 | + |
|
| 2186 | + }// end get_course_loop_class |
|
| 2187 | + |
|
| 2188 | + /** |
|
| 2189 | + * Get the number of columns set for Sensei courses |
|
| 2190 | + * |
|
| 2191 | + * @since 1.9.0 |
|
| 2192 | + * @return mixed|void |
|
| 2193 | + */ |
|
| 2194 | + public static function get_loop_number_of_columns(){ |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * Filter the number of columns on the course archive page. |
|
| 2198 | + * |
|
| 2199 | + * @since 1.9.0 |
|
| 2200 | + * @param int $number_of_columns default 1 |
|
| 2201 | + */ |
|
| 2202 | + return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2203 | + |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + /** |
|
| 2207 | + * Output the course archive filter markup |
|
| 2208 | + * |
|
| 2209 | + * hooked into sensei_loop_course_before |
|
| 2210 | + * |
|
| 2211 | + * @since 1.9.0 |
|
| 2212 | + * @param |
|
| 2213 | + */ |
|
| 2214 | + public static function course_archive_sorting( $query ){ |
|
| 2215 | + |
|
| 2216 | + // don't show on category pages and other pages |
|
| 2217 | + if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2218 | + return; |
|
| 2219 | + } |
|
| 2220 | + |
|
| 2221 | + /** |
|
| 2222 | + * Filter the sensei archive course order by values |
|
| 2223 | + * |
|
| 2224 | + * @since 1.9.0 |
|
| 2225 | + * @param array $options { |
|
| 2226 | + * @type string $option_value |
|
| 2227 | + * @type string $option_string |
|
| 2228 | + * } |
|
| 2229 | + */ |
|
| 2230 | + $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2231 | + "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2232 | + "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2233 | + )); |
|
| 2234 | + |
|
| 2235 | + // setup the currently selected item |
|
| 2236 | + $selected = 'newness'; |
|
| 2237 | + if( isset( $_GET['orderby'] ) ){ |
|
| 2238 | + |
|
| 2239 | + $selected = $_GET[ 'orderby' ]; |
|
| 2240 | + |
|
| 2241 | + } |
|
| 2242 | + |
|
| 2243 | + ?> |
|
| 2244 | 2244 | |
| 2245 | 2245 | <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST"> |
| 2246 | 2246 | <select name="course-orderby" class="orderby"> |
| 2247 | 2247 | <?php |
| 2248 | - foreach( $course_order_by_options as $value => $text ){ |
|
| 2248 | + foreach( $course_order_by_options as $value => $text ){ |
|
| 2249 | 2249 | |
| 2250 | - echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2250 | + echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2251 | 2251 | |
| 2252 | - } |
|
| 2253 | - ?> |
|
| 2252 | + } |
|
| 2253 | + ?> |
|
| 2254 | 2254 | </select> |
| 2255 | 2255 | </form> |
| 2256 | 2256 | |
| 2257 | 2257 | <?php |
| 2258 | - }// end course archive filters |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * Output the course archive filter markup |
|
| 2262 | - * |
|
| 2263 | - * hooked into sensei_loop_course_before |
|
| 2264 | - * |
|
| 2265 | - * @since 1.9.0 |
|
| 2266 | - * @param |
|
| 2267 | - */ |
|
| 2268 | - public static function course_archive_filters( $query ){ |
|
| 2269 | - |
|
| 2270 | - // don't show on category pages |
|
| 2271 | - if( is_tax('course-category') ){ |
|
| 2272 | - return; |
|
| 2273 | - } |
|
| 2274 | - |
|
| 2275 | - /** |
|
| 2276 | - * filter the course archive filter buttons |
|
| 2277 | - * |
|
| 2278 | - * @since 1.9.0 |
|
| 2279 | - * @param array $filters{ |
|
| 2280 | - * @type array ( $id, $url , $title ) |
|
| 2281 | - * } |
|
| 2282 | - * |
|
| 2283 | - */ |
|
| 2284 | - $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2285 | - array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2286 | - array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2287 | - )); |
|
| 2288 | - |
|
| 2289 | - |
|
| 2290 | - ?> |
|
| 2258 | + }// end course archive filters |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * Output the course archive filter markup |
|
| 2262 | + * |
|
| 2263 | + * hooked into sensei_loop_course_before |
|
| 2264 | + * |
|
| 2265 | + * @since 1.9.0 |
|
| 2266 | + * @param |
|
| 2267 | + */ |
|
| 2268 | + public static function course_archive_filters( $query ){ |
|
| 2269 | + |
|
| 2270 | + // don't show on category pages |
|
| 2271 | + if( is_tax('course-category') ){ |
|
| 2272 | + return; |
|
| 2273 | + } |
|
| 2274 | + |
|
| 2275 | + /** |
|
| 2276 | + * filter the course archive filter buttons |
|
| 2277 | + * |
|
| 2278 | + * @since 1.9.0 |
|
| 2279 | + * @param array $filters{ |
|
| 2280 | + * @type array ( $id, $url , $title ) |
|
| 2281 | + * } |
|
| 2282 | + * |
|
| 2283 | + */ |
|
| 2284 | + $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2285 | + array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2286 | + array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2287 | + )); |
|
| 2288 | + |
|
| 2289 | + |
|
| 2290 | + ?> |
|
| 2291 | 2291 | <ul class="sensei-course-filters clearfix" > |
| 2292 | 2292 | <?php |
| 2293 | 2293 | |
| 2294 | - //determine the current active url |
|
| 2295 | - $current_url = Sensei_Utils::get_current_url(); |
|
| 2294 | + //determine the current active url |
|
| 2295 | + $current_url = Sensei_Utils::get_current_url(); |
|
| 2296 | 2296 | |
| 2297 | - foreach( $filters as $filter ) { |
|
| 2297 | + foreach( $filters as $filter ) { |
|
| 2298 | 2298 | |
| 2299 | - $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2299 | + $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2300 | 2300 | |
| 2301 | - echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2301 | + echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2302 | 2302 | |
| 2303 | - } |
|
| 2304 | - ?> |
|
| 2303 | + } |
|
| 2304 | + ?> |
|
| 2305 | 2305 | |
| 2306 | 2306 | </ul> |
| 2307 | 2307 | |
| 2308 | 2308 | <?php |
| 2309 | 2309 | |
| 2310 | - } |
|
| 2310 | + } |
|
| 2311 | 2311 | |
| 2312 | - /** |
|
| 2313 | - * if the featured link is clicked on the course archive page |
|
| 2314 | - * filter the courses returned to only show those featured |
|
| 2315 | - * |
|
| 2316 | - * Hooked into pre_get_posts |
|
| 2317 | - * |
|
| 2318 | - * @since 1.9.0 |
|
| 2319 | - * @param WP_Query $query |
|
| 2320 | - * @return WP_Query $query |
|
| 2321 | - */ |
|
| 2322 | - public static function course_archive_featured_filter( $query ){ |
|
| 2323 | - |
|
| 2324 | - if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2325 | - //setup meta query for featured courses |
|
| 2326 | - $query->set( 'meta_value', 'featured' ); |
|
| 2327 | - $query->set( 'meta_key', '_course_featured' ); |
|
| 2328 | - $query->set( 'meta_compare', '=' ); |
|
| 2329 | - } |
|
| 2330 | - |
|
| 2331 | - return $query; |
|
| 2332 | - } |
|
| 2333 | - |
|
| 2334 | - /** |
|
| 2335 | - * if the course order drop down is changed |
|
| 2336 | - * |
|
| 2337 | - * Hooked into pre_get_posts |
|
| 2338 | - * |
|
| 2339 | - * @since 1.9.0 |
|
| 2340 | - * @param WP_Query $query |
|
| 2341 | - * @return WP_Query $query |
|
| 2342 | - */ |
|
| 2343 | - public static function course_archive_order_by_title( $query ){ |
|
| 2344 | - |
|
| 2345 | - if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2346 | - && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2347 | - // setup the order by title for this query |
|
| 2348 | - $query->set( 'orderby', 'title' ); |
|
| 2349 | - $query->set( 'order', 'ASC' ); |
|
| 2350 | - } |
|
| 2351 | - |
|
| 2352 | - return $query; |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - |
|
| 2356 | - /** |
|
| 2357 | - * Get the link to the courses page. This will be the course post type archive |
|
| 2358 | - * page link or the page the user set in their settings |
|
| 2359 | - * |
|
| 2360 | - * @since 1.9.0 |
|
| 2361 | - * @return string $course_page_url |
|
| 2362 | - */ |
|
| 2363 | - public static function get_courses_page_url(){ |
|
| 2364 | - |
|
| 2365 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2366 | - $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2312 | + /** |
|
| 2313 | + * if the featured link is clicked on the course archive page |
|
| 2314 | + * filter the courses returned to only show those featured |
|
| 2315 | + * |
|
| 2316 | + * Hooked into pre_get_posts |
|
| 2317 | + * |
|
| 2318 | + * @since 1.9.0 |
|
| 2319 | + * @param WP_Query $query |
|
| 2320 | + * @return WP_Query $query |
|
| 2321 | + */ |
|
| 2322 | + public static function course_archive_featured_filter( $query ){ |
|
| 2367 | 2323 | |
| 2368 | - return $course_page_url; |
|
| 2369 | - |
|
| 2370 | - }// get_course_url |
|
| 2324 | + if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2325 | + //setup meta query for featured courses |
|
| 2326 | + $query->set( 'meta_value', 'featured' ); |
|
| 2327 | + $query->set( 'meta_key', '_course_featured' ); |
|
| 2328 | + $query->set( 'meta_compare', '=' ); |
|
| 2329 | + } |
|
| 2371 | 2330 | |
| 2372 | - /** |
|
| 2373 | - * Output the headers on the course archive page |
|
| 2374 | - * |
|
| 2375 | - * Hooked into the sensei_archive_title |
|
| 2376 | - * |
|
| 2377 | - * @since 1.9.0 |
|
| 2378 | - * @param string $query_type |
|
| 2379 | - * @param string $before_html |
|
| 2380 | - * @param string $after_html |
|
| 2381 | - * @return void |
|
| 2382 | - */ |
|
| 2383 | - public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2331 | + return $query; |
|
| 2332 | + } |
|
| 2384 | 2333 | |
| 2385 | - if( ! is_post_type_archive('course') ){ |
|
| 2386 | - return; |
|
| 2387 | - } |
|
| 2334 | + /** |
|
| 2335 | + * if the course order drop down is changed |
|
| 2336 | + * |
|
| 2337 | + * Hooked into pre_get_posts |
|
| 2338 | + * |
|
| 2339 | + * @since 1.9.0 |
|
| 2340 | + * @param WP_Query $query |
|
| 2341 | + * @return WP_Query $query |
|
| 2342 | + */ |
|
| 2343 | + public static function course_archive_order_by_title( $query ){ |
|
| 2388 | 2344 | |
| 2389 | - // deprecated since 1.9.0 |
|
| 2390 | - sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2345 | + if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2346 | + && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2347 | + // setup the order by title for this query |
|
| 2348 | + $query->set( 'orderby', 'title' ); |
|
| 2349 | + $query->set( 'order', 'ASC' ); |
|
| 2350 | + } |
|
| 2391 | 2351 | |
| 2392 | - $html = ''; |
|
| 2352 | + return $query; |
|
| 2353 | + } |
|
| 2393 | 2354 | |
| 2394 | - if( empty( $before_html ) ){ |
|
| 2395 | 2355 | |
| 2396 | - $before_html = '<header class="archive-header"><h1>'; |
|
| 2356 | + /** |
|
| 2357 | + * Get the link to the courses page. This will be the course post type archive |
|
| 2358 | + * page link or the page the user set in their settings |
|
| 2359 | + * |
|
| 2360 | + * @since 1.9.0 |
|
| 2361 | + * @return string $course_page_url |
|
| 2362 | + */ |
|
| 2363 | + public static function get_courses_page_url(){ |
|
| 2397 | 2364 | |
| 2398 | - } |
|
| 2365 | + $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2366 | + $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2399 | 2367 | |
| 2400 | - if( empty( $after_html ) ){ |
|
| 2368 | + return $course_page_url; |
|
| 2401 | 2369 | |
| 2402 | - $after_html = '</h1></header>'; |
|
| 2370 | + }// get_course_url |
|
| 2403 | 2371 | |
| 2404 | - } |
|
| 2372 | + /** |
|
| 2373 | + * Output the headers on the course archive page |
|
| 2374 | + * |
|
| 2375 | + * Hooked into the sensei_archive_title |
|
| 2376 | + * |
|
| 2377 | + * @since 1.9.0 |
|
| 2378 | + * @param string $query_type |
|
| 2379 | + * @param string $before_html |
|
| 2380 | + * @param string $after_html |
|
| 2381 | + * @return void |
|
| 2382 | + */ |
|
| 2383 | + public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2405 | 2384 | |
| 2406 | - if ( is_tax( 'course-category' ) ) { |
|
| 2385 | + if( ! is_post_type_archive('course') ){ |
|
| 2386 | + return; |
|
| 2387 | + } |
|
| 2407 | 2388 | |
| 2408 | - global $wp_query; |
|
| 2389 | + // deprecated since 1.9.0 |
|
| 2390 | + sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2409 | 2391 | |
| 2410 | - $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2411 | - $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2412 | - $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2413 | - $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2414 | - echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2415 | - return; |
|
| 2392 | + $html = ''; |
|
| 2416 | 2393 | |
| 2417 | - } // End If Statement |
|
| 2394 | + if( empty( $before_html ) ){ |
|
| 2418 | 2395 | |
| 2419 | - switch ( $query_type ) { |
|
| 2420 | - case 'newcourses': |
|
| 2421 | - $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2422 | - break; |
|
| 2423 | - case 'featuredcourses': |
|
| 2424 | - $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2425 | - break; |
|
| 2426 | - case 'freecourses': |
|
| 2427 | - $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2428 | - break; |
|
| 2429 | - case 'paidcourses': |
|
| 2430 | - $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2431 | - break; |
|
| 2432 | - default: |
|
| 2433 | - $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2434 | - break; |
|
| 2435 | - } // End Switch Statement |
|
| 2396 | + $before_html = '<header class="archive-header"><h1>'; |
|
| 2436 | 2397 | |
| 2437 | - echo apply_filters( 'course_archive_title', $html ); |
|
| 2398 | + } |
|
| 2438 | 2399 | |
| 2439 | - }//course_archive_header |
|
| 2400 | + if( empty( $after_html ) ){ |
|
| 2440 | 2401 | |
| 2402 | + $after_html = '</h1></header>'; |
|
| 2441 | 2403 | |
| 2442 | - /** |
|
| 2443 | - * Filter the single course content |
|
| 2444 | - * taking into account if the user has access. |
|
| 2445 | - * |
|
| 2446 | - * @1.9.0 |
|
| 2447 | - * |
|
| 2448 | - * @param string $content |
|
| 2449 | - * @return string $content or $excerpt |
|
| 2450 | - */ |
|
| 2451 | - public static function single_course_content( $content ){ |
|
| 2404 | + } |
|
| 2452 | 2405 | |
| 2453 | - if( ! is_singular('course') ){ |
|
| 2406 | + if ( is_tax( 'course-category' ) ) { |
|
| 2454 | 2407 | |
| 2455 | - return $content; |
|
| 2408 | + global $wp_query; |
|
| 2456 | 2409 | |
| 2457 | - } |
|
| 2410 | + $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2411 | + $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2412 | + $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2413 | + $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2414 | + echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2415 | + return; |
|
| 2458 | 2416 | |
| 2459 | - // Content Access Permissions |
|
| 2460 | - $access_permission = false; |
|
| 2417 | + } // End If Statement |
|
| 2461 | 2418 | |
| 2462 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2419 | + switch ( $query_type ) { |
|
| 2420 | + case 'newcourses': |
|
| 2421 | + $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2422 | + break; |
|
| 2423 | + case 'featuredcourses': |
|
| 2424 | + $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2425 | + break; |
|
| 2426 | + case 'freecourses': |
|
| 2427 | + $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2428 | + break; |
|
| 2429 | + case 'paidcourses': |
|
| 2430 | + $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2431 | + break; |
|
| 2432 | + default: |
|
| 2433 | + $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2434 | + break; |
|
| 2435 | + } // End Switch Statement |
|
| 2463 | 2436 | |
| 2464 | - $access_permission = true; |
|
| 2437 | + echo apply_filters( 'course_archive_title', $html ); |
|
| 2465 | 2438 | |
| 2466 | - } // End If Statement |
|
| 2439 | + }//course_archive_header |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * Filter the single course content |
|
| 2444 | + * taking into account if the user has access. |
|
| 2445 | + * |
|
| 2446 | + * @1.9.0 |
|
| 2447 | + * |
|
| 2448 | + * @param string $content |
|
| 2449 | + * @return string $content or $excerpt |
|
| 2450 | + */ |
|
| 2451 | + public static function single_course_content( $content ){ |
|
| 2467 | 2452 | |
| 2468 | - // Check if the user is taking the course |
|
| 2469 | - $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2453 | + if( ! is_singular('course') ){ |
|
| 2470 | 2454 | |
| 2471 | - if(Sensei_WC::is_woocommerce_active()) { |
|
| 2455 | + return $content; |
|
| 2472 | 2456 | |
| 2473 | - $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2474 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2457 | + } |
|
| 2475 | 2458 | |
| 2476 | - $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2459 | + // Content Access Permissions |
|
| 2460 | + $access_permission = false; |
|
| 2477 | 2461 | |
| 2478 | - } else { |
|
| 2462 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2479 | 2463 | |
| 2480 | - $has_product_attached = false; |
|
| 2464 | + $access_permission = true; |
|
| 2481 | 2465 | |
| 2482 | - } |
|
| 2466 | + } // End If Statement |
|
| 2483 | 2467 | |
| 2484 | - if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2485 | - || ( $access_permission && !$has_product_attached) |
|
| 2486 | - || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2468 | + // Check if the user is taking the course |
|
| 2469 | + $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2487 | 2470 | |
| 2488 | - return $content; |
|
| 2471 | + if(Sensei_WC::is_woocommerce_active()) { |
|
| 2489 | 2472 | |
| 2490 | - } else { |
|
| 2473 | + $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2474 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2491 | 2475 | |
| 2492 | - return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2476 | + $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2493 | 2477 | |
| 2494 | - } |
|
| 2478 | + } else { |
|
| 2495 | 2479 | |
| 2496 | - }// end single_course_content |
|
| 2480 | + $has_product_attached = false; |
|
| 2497 | 2481 | |
| 2498 | - /** |
|
| 2499 | - * Output the the single course lessons title with markup. |
|
| 2500 | - * |
|
| 2501 | - * @since 1.9.0 |
|
| 2502 | - */ |
|
| 2503 | - public static function the_course_lessons_title(){ |
|
| 2504 | - global $post; |
|
| 2505 | - $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2506 | - $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2482 | + } |
|
| 2507 | 2483 | |
| 2508 | - // title should be Other Lessons if there are lessons belonging to models. |
|
| 2509 | - $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2510 | - if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2484 | + if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2485 | + || ( $access_permission && !$has_product_attached) |
|
| 2486 | + || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2511 | 2487 | |
| 2512 | - $title = __('Lessons', 'woothemes-sensei'); |
|
| 2488 | + return $content; |
|
| 2513 | 2489 | |
| 2514 | - } |
|
| 2490 | + } else { |
|
| 2515 | 2491 | |
| 2516 | - /** |
|
| 2517 | - * hook document in class-woothemes-sensei-message.php |
|
| 2518 | - */ |
|
| 2519 | - $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2492 | + return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2520 | 2493 | |
| 2521 | - ob_start(); // start capturing the following output. |
|
| 2494 | + } |
|
| 2522 | 2495 | |
| 2523 | - ?> |
|
| 2496 | + }// end single_course_content |
|
| 2497 | + |
|
| 2498 | + /** |
|
| 2499 | + * Output the the single course lessons title with markup. |
|
| 2500 | + * |
|
| 2501 | + * @since 1.9.0 |
|
| 2502 | + */ |
|
| 2503 | + public static function the_course_lessons_title(){ |
|
| 2504 | + global $post; |
|
| 2505 | + $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2506 | + $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2507 | + |
|
| 2508 | + // title should be Other Lessons if there are lessons belonging to models. |
|
| 2509 | + $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2510 | + if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2511 | + |
|
| 2512 | + $title = __('Lessons', 'woothemes-sensei'); |
|
| 2513 | + |
|
| 2514 | + } |
|
| 2515 | + |
|
| 2516 | + /** |
|
| 2517 | + * hook document in class-woothemes-sensei-message.php |
|
| 2518 | + */ |
|
| 2519 | + $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2520 | + |
|
| 2521 | + ob_start(); // start capturing the following output. |
|
| 2522 | + |
|
| 2523 | + ?> |
|
| 2524 | 2524 | |
| 2525 | 2525 | <header> |
| 2526 | 2526 | <h2> <?php echo $title; ?> </h2> |
@@ -2528,277 +2528,277 @@ discard block |
||
| 2528 | 2528 | |
| 2529 | 2529 | <?php |
| 2530 | 2530 | |
| 2531 | - /** |
|
| 2532 | - * Filter the title and markup that appears above the lessons on a single course |
|
| 2533 | - * page. |
|
| 2534 | - * |
|
| 2535 | - * @since 1.9.0 |
|
| 2536 | - * @param string $lessons_title_html |
|
| 2537 | - */ |
|
| 2538 | - echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2539 | - |
|
| 2540 | - }// end the_course_lessons_title |
|
| 2541 | - |
|
| 2542 | - /** |
|
| 2543 | - * This function loads the global wp_query object with with lessons |
|
| 2544 | - * of the current course. It is designed to be used on the single-course template |
|
| 2545 | - * and expects the global post to be a singular course. |
|
| 2546 | - * |
|
| 2547 | - * This function excludes lessons belonging to modules as they are |
|
| 2548 | - * queried separately. |
|
| 2549 | - * |
|
| 2550 | - * @since 1.9.0 |
|
| 2551 | - * @global $wp_query |
|
| 2552 | - */ |
|
| 2553 | - public static function load_single_course_lessons_query(){ |
|
| 2531 | + /** |
|
| 2532 | + * Filter the title and markup that appears above the lessons on a single course |
|
| 2533 | + * page. |
|
| 2534 | + * |
|
| 2535 | + * @since 1.9.0 |
|
| 2536 | + * @param string $lessons_title_html |
|
| 2537 | + */ |
|
| 2538 | + echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2554 | 2539 | |
| 2555 | - global $post, $wp_query; |
|
| 2540 | + }// end the_course_lessons_title |
|
| 2556 | 2541 | |
| 2557 | - $course_id = $post->ID; |
|
| 2558 | - |
|
| 2559 | - if( 'course' != get_post_type( $course_id ) ){ |
|
| 2560 | - return; |
|
| 2561 | - } |
|
| 2542 | + /** |
|
| 2543 | + * This function loads the global wp_query object with with lessons |
|
| 2544 | + * of the current course. It is designed to be used on the single-course template |
|
| 2545 | + * and expects the global post to be a singular course. |
|
| 2546 | + * |
|
| 2547 | + * This function excludes lessons belonging to modules as they are |
|
| 2548 | + * queried separately. |
|
| 2549 | + * |
|
| 2550 | + * @since 1.9.0 |
|
| 2551 | + * @global $wp_query |
|
| 2552 | + */ |
|
| 2553 | + public static function load_single_course_lessons_query(){ |
|
| 2562 | 2554 | |
| 2563 | - $course_lesson_query_args = array( |
|
| 2564 | - 'post_type' => 'lesson', |
|
| 2565 | - 'posts_per_page' => 500, |
|
| 2566 | - 'orderby' => 'date', |
|
| 2567 | - 'order' => 'ASC', |
|
| 2568 | - 'meta_query' => array( |
|
| 2569 | - array( |
|
| 2570 | - 'key' => '_lesson_course', |
|
| 2571 | - 'value' => intval( $course_id ), |
|
| 2572 | - ), |
|
| 2573 | - ), |
|
| 2574 | - 'post_status' => 'public', |
|
| 2575 | - 'suppress_filters' => 0, |
|
| 2576 | - ); |
|
| 2555 | + global $post, $wp_query; |
|
| 2577 | 2556 | |
| 2578 | - // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2579 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2580 | - if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2557 | + $course_id = $post->ID; |
|
| 2581 | 2558 | |
| 2582 | - $terms_ids = array(); |
|
| 2583 | - foreach( $modules as $term ){ |
|
| 2559 | + if( 'course' != get_post_type( $course_id ) ){ |
|
| 2560 | + return; |
|
| 2561 | + } |
|
| 2584 | 2562 | |
| 2585 | - $terms_ids[] = $term->term_id; |
|
| 2563 | + $course_lesson_query_args = array( |
|
| 2564 | + 'post_type' => 'lesson', |
|
| 2565 | + 'posts_per_page' => 500, |
|
| 2566 | + 'orderby' => 'date', |
|
| 2567 | + 'order' => 'ASC', |
|
| 2568 | + 'meta_query' => array( |
|
| 2569 | + array( |
|
| 2570 | + 'key' => '_lesson_course', |
|
| 2571 | + 'value' => intval( $course_id ), |
|
| 2572 | + ), |
|
| 2573 | + ), |
|
| 2574 | + 'post_status' => 'public', |
|
| 2575 | + 'suppress_filters' => 0, |
|
| 2576 | + ); |
|
| 2577 | + |
|
| 2578 | + // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2579 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2580 | + if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2581 | + |
|
| 2582 | + $terms_ids = array(); |
|
| 2583 | + foreach( $modules as $term ){ |
|
| 2584 | + |
|
| 2585 | + $terms_ids[] = $term->term_id; |
|
| 2586 | 2586 | |
| 2587 | - } |
|
| 2587 | + } |
|
| 2588 | 2588 | |
| 2589 | - $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2590 | - array( |
|
| 2591 | - 'taxonomy' => 'module', |
|
| 2592 | - 'field' => 'id', |
|
| 2593 | - 'terms' => $terms_ids, |
|
| 2594 | - 'operator' => 'NOT IN', |
|
| 2595 | - ), |
|
| 2596 | - ); |
|
| 2597 | - } |
|
| 2589 | + $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2590 | + array( |
|
| 2591 | + 'taxonomy' => 'module', |
|
| 2592 | + 'field' => 'id', |
|
| 2593 | + 'terms' => $terms_ids, |
|
| 2594 | + 'operator' => 'NOT IN', |
|
| 2595 | + ), |
|
| 2596 | + ); |
|
| 2597 | + } |
|
| 2598 | 2598 | |
| 2599 | - $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2599 | + $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2600 | 2600 | |
| 2601 | - }// load_single_course_lessons |
|
| 2601 | + }// load_single_course_lessons |
|
| 2602 | 2602 | |
| 2603 | - /** |
|
| 2604 | - * Flush the rewrite rules for a course post type |
|
| 2605 | - * |
|
| 2606 | - * @since 1.9.0 |
|
| 2607 | - * |
|
| 2608 | - * @param $post_id |
|
| 2609 | - */ |
|
| 2610 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 2603 | + /** |
|
| 2604 | + * Flush the rewrite rules for a course post type |
|
| 2605 | + * |
|
| 2606 | + * @since 1.9.0 |
|
| 2607 | + * |
|
| 2608 | + * @param $post_id |
|
| 2609 | + */ |
|
| 2610 | + public static function flush_rewrite_rules( $post_id ){ |
|
| 2611 | 2611 | |
| 2612 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2612 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2613 | 2613 | |
| 2614 | - return; |
|
| 2614 | + return; |
|
| 2615 | 2615 | |
| 2616 | - } |
|
| 2616 | + } |
|
| 2617 | 2617 | |
| 2618 | 2618 | |
| 2619 | - if( 'course' == get_post_type( $post_id ) ){ |
|
| 2619 | + if( 'course' == get_post_type( $post_id ) ){ |
|
| 2620 | 2620 | |
| 2621 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 2621 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 2622 | 2622 | |
| 2623 | - } |
|
| 2623 | + } |
|
| 2624 | 2624 | |
| 2625 | - } |
|
| 2625 | + } |
|
| 2626 | 2626 | |
| 2627 | - /** |
|
| 2628 | - * Optionally return the full content on the single course pages |
|
| 2629 | - * depending on the users course_single_content_display setting |
|
| 2630 | - * |
|
| 2631 | - * @since 1.9.0 |
|
| 2632 | - * @param $excerpt |
|
| 2633 | - * @return string |
|
| 2634 | - */ |
|
| 2635 | - public static function full_content_excerpt_override( $excerpt ){ |
|
| 2627 | + /** |
|
| 2628 | + * Optionally return the full content on the single course pages |
|
| 2629 | + * depending on the users course_single_content_display setting |
|
| 2630 | + * |
|
| 2631 | + * @since 1.9.0 |
|
| 2632 | + * @param $excerpt |
|
| 2633 | + * @return string |
|
| 2634 | + */ |
|
| 2635 | + public static function full_content_excerpt_override( $excerpt ){ |
|
| 2636 | 2636 | |
| 2637 | - if ( is_singular('course') && |
|
| 2638 | - 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2637 | + if ( is_singular('course') && |
|
| 2638 | + 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2639 | 2639 | |
| 2640 | - return get_the_content(); |
|
| 2640 | + return get_the_content(); |
|
| 2641 | 2641 | |
| 2642 | - } else { |
|
| 2642 | + } else { |
|
| 2643 | 2643 | |
| 2644 | - return $excerpt; |
|
| 2644 | + return $excerpt; |
|
| 2645 | 2645 | |
| 2646 | - } |
|
| 2646 | + } |
|
| 2647 | 2647 | |
| 2648 | - } |
|
| 2648 | + } |
|
| 2649 | 2649 | |
| 2650 | - /** |
|
| 2651 | - * Output the course actions like start taking course, register, add to cart etc. |
|
| 2652 | - * |
|
| 2653 | - * @since 1.9.0 |
|
| 2654 | - */ |
|
| 2655 | - public static function the_course_enrolment_actions(){ |
|
| 2656 | - ?> |
|
| 2650 | + /** |
|
| 2651 | + * Output the course actions like start taking course, register, add to cart etc. |
|
| 2652 | + * |
|
| 2653 | + * @since 1.9.0 |
|
| 2654 | + */ |
|
| 2655 | + public static function the_course_enrolment_actions(){ |
|
| 2656 | + ?> |
|
| 2657 | 2657 | <section class="course-meta course-enrolment"> |
| 2658 | 2658 | <?php |
| 2659 | - global $post, $current_user; |
|
| 2660 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2661 | - if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2662 | - |
|
| 2663 | - // Get the product ID |
|
| 2664 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2665 | - |
|
| 2666 | - // Check for woocommerce |
|
| 2667 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2668 | - sensei_wc_add_to_cart($post->ID); |
|
| 2669 | - } else { |
|
| 2670 | - sensei_start_course_form($post->ID); |
|
| 2671 | - } // End If Statement |
|
| 2672 | - |
|
| 2673 | - } elseif ( is_user_logged_in() ) { |
|
| 2674 | - |
|
| 2675 | - // Check if course is completed |
|
| 2676 | - $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2677 | - $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2678 | - // Success message |
|
| 2679 | - if ( $completed_course ) { ?> |
|
| 2659 | + global $post, $current_user; |
|
| 2660 | + $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2661 | + if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2662 | + |
|
| 2663 | + // Get the product ID |
|
| 2664 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2665 | + |
|
| 2666 | + // Check for woocommerce |
|
| 2667 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2668 | + sensei_wc_add_to_cart($post->ID); |
|
| 2669 | + } else { |
|
| 2670 | + sensei_start_course_form($post->ID); |
|
| 2671 | + } // End If Statement |
|
| 2672 | + |
|
| 2673 | + } elseif ( is_user_logged_in() ) { |
|
| 2674 | + |
|
| 2675 | + // Check if course is completed |
|
| 2676 | + $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2677 | + $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2678 | + // Success message |
|
| 2679 | + if ( $completed_course ) { ?> |
|
| 2680 | 2680 | <div class="status completed"><?php _e( 'Completed', 'woothemes-sensei' ); ?></div> |
| 2681 | 2681 | <?php |
| 2682 | - $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2683 | - if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2682 | + $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2683 | + if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2684 | 2684 | <p class="sensei-results-links"> |
| 2685 | 2685 | <?php |
| 2686 | - $results_link = ''; |
|
| 2687 | - if( $has_quizzes ) { |
|
| 2688 | - $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2689 | - } |
|
| 2690 | - $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2691 | - echo $results_link; |
|
| 2692 | - ?></p> |
|
| 2686 | + $results_link = ''; |
|
| 2687 | + if( $has_quizzes ) { |
|
| 2688 | + $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2689 | + } |
|
| 2690 | + $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2691 | + echo $results_link; |
|
| 2692 | + ?></p> |
|
| 2693 | 2693 | <?php } ?> |
| 2694 | 2694 | <?php } else { ?> |
| 2695 | 2695 | <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div> |
| 2696 | 2696 | <?php } |
| 2697 | 2697 | |
| 2698 | - } else { |
|
| 2699 | - // Get the product ID |
|
| 2700 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2701 | - // Check for woocommerce |
|
| 2702 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2698 | + } else { |
|
| 2699 | + // Get the product ID |
|
| 2700 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2701 | + // Check for woocommerce |
|
| 2702 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2703 | 2703 | |
| 2704 | - sensei_wc_add_to_cart($post->ID); |
|
| 2704 | + sensei_wc_add_to_cart($post->ID); |
|
| 2705 | 2705 | |
| 2706 | - } else { |
|
| 2706 | + } else { |
|
| 2707 | 2707 | |
| 2708 | - if( get_option( 'users_can_register') ) { |
|
| 2708 | + if( get_option( 'users_can_register') ) { |
|
| 2709 | 2709 | |
| 2710 | 2710 | |
| 2711 | - $my_courses_page_id = ''; |
|
| 2711 | + $my_courses_page_id = ''; |
|
| 2712 | 2712 | |
| 2713 | - /** |
|
| 2714 | - * Filter to force Sensei to output the default WordPress user |
|
| 2715 | - * registration link. |
|
| 2716 | - * |
|
| 2717 | - * @since 1.9.0 |
|
| 2718 | - * @param bool $wp_register_link default false |
|
| 2719 | - */ |
|
| 2713 | + /** |
|
| 2714 | + * Filter to force Sensei to output the default WordPress user |
|
| 2715 | + * registration link. |
|
| 2716 | + * |
|
| 2717 | + * @since 1.9.0 |
|
| 2718 | + * @param bool $wp_register_link default false |
|
| 2719 | + */ |
|
| 2720 | 2720 | |
| 2721 | - $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2721 | + $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2722 | 2722 | |
| 2723 | - $settings = Sensei()->settings->get_settings(); |
|
| 2724 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 2725 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2723 | + $settings = Sensei()->settings->get_settings(); |
|
| 2724 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 2725 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2726 | 2726 | |
| 2727 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2727 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2728 | 2728 | |
| 2729 | - } |
|
| 2729 | + } |
|
| 2730 | 2730 | |
| 2731 | - // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2732 | - // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2733 | - if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2731 | + // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2732 | + // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2733 | + if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2734 | 2734 | |
| 2735 | - $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2736 | - $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2737 | - echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2735 | + $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2736 | + $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2737 | + echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2738 | 2738 | |
| 2739 | - } else{ |
|
| 2739 | + } else{ |
|
| 2740 | 2740 | |
| 2741 | - wp_register( '<div class="status register">', '</div>' ); |
|
| 2741 | + wp_register( '<div class="status register">', '</div>' ); |
|
| 2742 | 2742 | |
| 2743 | - } |
|
| 2743 | + } |
|
| 2744 | 2744 | |
| 2745 | - } // end if user can register |
|
| 2745 | + } // end if user can register |
|
| 2746 | 2746 | |
| 2747 | - } // End If Statement |
|
| 2747 | + } // End If Statement |
|
| 2748 | 2748 | |
| 2749 | - } // End If Statement ?> |
|
| 2749 | + } // End If Statement ?> |
|
| 2750 | 2750 | |
| 2751 | 2751 | </section><?php |
| 2752 | 2752 | |
| 2753 | - }// end the_course_enrolment_actions |
|
| 2753 | + }// end the_course_enrolment_actions |
|
| 2754 | 2754 | |
| 2755 | - /** |
|
| 2756 | - * Output the course video inside the loop. |
|
| 2757 | - * |
|
| 2758 | - * @since 1.9.0 |
|
| 2759 | - */ |
|
| 2760 | - public static function the_course_video(){ |
|
| 2755 | + /** |
|
| 2756 | + * Output the course video inside the loop. |
|
| 2757 | + * |
|
| 2758 | + * @since 1.9.0 |
|
| 2759 | + */ |
|
| 2760 | + public static function the_course_video(){ |
|
| 2761 | 2761 | |
| 2762 | - global $post; |
|
| 2763 | - // Get the meta info |
|
| 2764 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2762 | + global $post; |
|
| 2763 | + // Get the meta info |
|
| 2764 | + $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2765 | 2765 | |
| 2766 | - if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2766 | + if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2767 | 2767 | |
| 2768 | - $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2768 | + $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2769 | 2769 | |
| 2770 | - } // End If Statement |
|
| 2770 | + } // End If Statement |
|
| 2771 | 2771 | |
| 2772 | - if ( '' != $course_video_embed ) { ?> |
|
| 2772 | + if ( '' != $course_video_embed ) { ?> |
|
| 2773 | 2773 | |
| 2774 | 2774 | <div class="course-video"> |
| 2775 | 2775 | <?php echo html_entity_decode($course_video_embed); ?> |
| 2776 | 2776 | </div> |
| 2777 | 2777 | |
| 2778 | 2778 | <?php } // End If Statement |
| 2779 | - } |
|
| 2779 | + } |
|
| 2780 | 2780 | |
| 2781 | - /** |
|
| 2782 | - * Output the title for the single lesson page |
|
| 2783 | - * |
|
| 2784 | - * @global $post |
|
| 2785 | - * @since 1.9.0 |
|
| 2786 | - */ |
|
| 2787 | - public static function the_title(){ |
|
| 2781 | + /** |
|
| 2782 | + * Output the title for the single lesson page |
|
| 2783 | + * |
|
| 2784 | + * @global $post |
|
| 2785 | + * @since 1.9.0 |
|
| 2786 | + */ |
|
| 2787 | + public static function the_title(){ |
|
| 2788 | 2788 | |
| 2789 | - global $post; |
|
| 2789 | + global $post; |
|
| 2790 | 2790 | |
| 2791 | - ?> |
|
| 2791 | + ?> |
|
| 2792 | 2792 | <header> |
| 2793 | 2793 | |
| 2794 | 2794 | <h1> |
| 2795 | 2795 | |
| 2796 | 2796 | <?php |
| 2797 | - /** |
|
| 2798 | - * Filter documented in class-sensei-messages.php the_title |
|
| 2799 | - */ |
|
| 2800 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2801 | - ?> |
|
| 2797 | + /** |
|
| 2798 | + * Filter documented in class-sensei-messages.php the_title |
|
| 2799 | + */ |
|
| 2800 | + echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2801 | + ?> |
|
| 2802 | 2802 | |
| 2803 | 2803 | </h1> |
| 2804 | 2804 | |
@@ -2806,111 +2806,111 @@ discard block |
||
| 2806 | 2806 | |
| 2807 | 2807 | <?php |
| 2808 | 2808 | |
| 2809 | - }//the_title |
|
| 2810 | - |
|
| 2811 | - /** |
|
| 2812 | - * Show the title on the course category pages |
|
| 2813 | - * |
|
| 2814 | - * @since 1.9.0 |
|
| 2815 | - */ |
|
| 2816 | - public static function course_category_title(){ |
|
| 2817 | - |
|
| 2818 | - if( ! is_tax( 'course-category' ) ){ |
|
| 2819 | - return; |
|
| 2820 | - } |
|
| 2821 | - |
|
| 2822 | - $category_slug = get_query_var('course-category'); |
|
| 2823 | - $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2824 | - |
|
| 2825 | - if( ! empty($term) ){ |
|
| 2826 | - |
|
| 2827 | - $title = $term->name; |
|
| 2828 | - |
|
| 2829 | - }else{ |
|
| 2830 | - |
|
| 2831 | - $title = 'Course Category'; |
|
| 2832 | - |
|
| 2833 | - } |
|
| 2834 | - |
|
| 2835 | - $html = '<h2 class="sensei-category-title">'; |
|
| 2836 | - $html .= __('Category') . ' ' . $title; |
|
| 2837 | - $html .= '</h2>'; |
|
| 2838 | - |
|
| 2839 | - echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2840 | - |
|
| 2841 | - }// course_category_title |
|
| 2842 | - |
|
| 2843 | - /** |
|
| 2844 | - * Alter the course query to respect the order set for courses and apply |
|
| 2845 | - * this on the course-category pages. |
|
| 2846 | - * |
|
| 2847 | - * @since 1.9.0 |
|
| 2848 | - * |
|
| 2849 | - * @param WP_Query $query |
|
| 2850 | - * @return WP_Query |
|
| 2851 | - */ |
|
| 2852 | - public static function alter_course_category_order( $query ){ |
|
| 2853 | - |
|
| 2854 | - if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2855 | - return $query; |
|
| 2856 | - } |
|
| 2857 | - |
|
| 2858 | - $order = get_option( 'sensei_course_order', '' ); |
|
| 2859 | - if( !empty( $order ) ){ |
|
| 2860 | - $query->set('orderby', 'menu_order' ); |
|
| 2861 | - $query->set('order', 'ASC' ); |
|
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - return $query; |
|
| 2865 | - |
|
| 2866 | - } |
|
| 2867 | - |
|
| 2868 | - /** |
|
| 2869 | - * The very basic course query arguments |
|
| 2870 | - * so we don't have to repeat this througout |
|
| 2871 | - * the code base. |
|
| 2872 | - * |
|
| 2873 | - * Usage: |
|
| 2874 | - * $args = Sensei_Course::get_default_query_args(); |
|
| 2875 | - * $args['custom_arg'] ='custom value'; |
|
| 2876 | - * $courses = get_posts( $args ) |
|
| 2877 | - * |
|
| 2878 | - * @since 1.9.0 |
|
| 2879 | - * |
|
| 2880 | - * @return array |
|
| 2881 | - */ |
|
| 2882 | - public static function get_default_query_args(){ |
|
| 2883 | - return array( |
|
| 2884 | - 'post_type' => 'course', |
|
| 2885 | - 'posts_per_page' => 1000, |
|
| 2886 | - 'orderby' => 'date', |
|
| 2887 | - 'order' => 'DESC', |
|
| 2888 | - 'suppress_filters' => 0 |
|
| 2889 | - ); |
|
| 2890 | - } |
|
| 2891 | - |
|
| 2892 | - /** |
|
| 2893 | - * Check if the prerequisite course is completed |
|
| 2894 | - * Courses with no pre-requisite should always return true |
|
| 2895 | - * |
|
| 2896 | - * @since 1.9.0 |
|
| 2897 | - * @param $course_id |
|
| 2898 | - * @return bool |
|
| 2899 | - */ |
|
| 2900 | - public static function is_prerequisite_complete( $course_id ){ |
|
| 2901 | - |
|
| 2902 | - $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2903 | - |
|
| 2904 | - // if it has a pre requisite course check it |
|
| 2905 | - if( ! empty( $course_prerequisite_id ) ){ |
|
| 2906 | - |
|
| 2907 | - return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2908 | - |
|
| 2909 | - } |
|
| 2910 | - |
|
| 2911 | - return true; |
|
| 2912 | - |
|
| 2913 | - }// end is_prerequisite_complete |
|
| 2809 | + }//the_title |
|
| 2810 | + |
|
| 2811 | + /** |
|
| 2812 | + * Show the title on the course category pages |
|
| 2813 | + * |
|
| 2814 | + * @since 1.9.0 |
|
| 2815 | + */ |
|
| 2816 | + public static function course_category_title(){ |
|
| 2817 | + |
|
| 2818 | + if( ! is_tax( 'course-category' ) ){ |
|
| 2819 | + return; |
|
| 2820 | + } |
|
| 2821 | + |
|
| 2822 | + $category_slug = get_query_var('course-category'); |
|
| 2823 | + $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2824 | + |
|
| 2825 | + if( ! empty($term) ){ |
|
| 2826 | + |
|
| 2827 | + $title = $term->name; |
|
| 2828 | + |
|
| 2829 | + }else{ |
|
| 2830 | + |
|
| 2831 | + $title = 'Course Category'; |
|
| 2832 | + |
|
| 2833 | + } |
|
| 2834 | + |
|
| 2835 | + $html = '<h2 class="sensei-category-title">'; |
|
| 2836 | + $html .= __('Category') . ' ' . $title; |
|
| 2837 | + $html .= '</h2>'; |
|
| 2838 | + |
|
| 2839 | + echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2840 | + |
|
| 2841 | + }// course_category_title |
|
| 2842 | + |
|
| 2843 | + /** |
|
| 2844 | + * Alter the course query to respect the order set for courses and apply |
|
| 2845 | + * this on the course-category pages. |
|
| 2846 | + * |
|
| 2847 | + * @since 1.9.0 |
|
| 2848 | + * |
|
| 2849 | + * @param WP_Query $query |
|
| 2850 | + * @return WP_Query |
|
| 2851 | + */ |
|
| 2852 | + public static function alter_course_category_order( $query ){ |
|
| 2853 | + |
|
| 2854 | + if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2855 | + return $query; |
|
| 2856 | + } |
|
| 2857 | + |
|
| 2858 | + $order = get_option( 'sensei_course_order', '' ); |
|
| 2859 | + if( !empty( $order ) ){ |
|
| 2860 | + $query->set('orderby', 'menu_order' ); |
|
| 2861 | + $query->set('order', 'ASC' ); |
|
| 2862 | + } |
|
| 2863 | + |
|
| 2864 | + return $query; |
|
| 2865 | + |
|
| 2866 | + } |
|
| 2867 | + |
|
| 2868 | + /** |
|
| 2869 | + * The very basic course query arguments |
|
| 2870 | + * so we don't have to repeat this througout |
|
| 2871 | + * the code base. |
|
| 2872 | + * |
|
| 2873 | + * Usage: |
|
| 2874 | + * $args = Sensei_Course::get_default_query_args(); |
|
| 2875 | + * $args['custom_arg'] ='custom value'; |
|
| 2876 | + * $courses = get_posts( $args ) |
|
| 2877 | + * |
|
| 2878 | + * @since 1.9.0 |
|
| 2879 | + * |
|
| 2880 | + * @return array |
|
| 2881 | + */ |
|
| 2882 | + public static function get_default_query_args(){ |
|
| 2883 | + return array( |
|
| 2884 | + 'post_type' => 'course', |
|
| 2885 | + 'posts_per_page' => 1000, |
|
| 2886 | + 'orderby' => 'date', |
|
| 2887 | + 'order' => 'DESC', |
|
| 2888 | + 'suppress_filters' => 0 |
|
| 2889 | + ); |
|
| 2890 | + } |
|
| 2891 | + |
|
| 2892 | + /** |
|
| 2893 | + * Check if the prerequisite course is completed |
|
| 2894 | + * Courses with no pre-requisite should always return true |
|
| 2895 | + * |
|
| 2896 | + * @since 1.9.0 |
|
| 2897 | + * @param $course_id |
|
| 2898 | + * @return bool |
|
| 2899 | + */ |
|
| 2900 | + public static function is_prerequisite_complete( $course_id ){ |
|
| 2901 | + |
|
| 2902 | + $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2903 | + |
|
| 2904 | + // if it has a pre requisite course check it |
|
| 2905 | + if( ! empty( $course_prerequisite_id ) ){ |
|
| 2906 | + |
|
| 2907 | + return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2908 | + |
|
| 2909 | + } |
|
| 2910 | + |
|
| 2911 | + return true; |
|
| 2912 | + |
|
| 2913 | + }// end is_prerequisite_complete |
|
| 2914 | 2914 | |
| 2915 | 2915 | |
| 2916 | 2916 | }// End Class |
@@ -14,265 +14,265 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Core_Modules |
| 16 | 16 | { |
| 17 | - private $dir; |
|
| 18 | - private $file; |
|
| 19 | - private $assets_dir; |
|
| 20 | - private $assets_url; |
|
| 21 | - private $order_page_slug; |
|
| 22 | - public $taxonomy; |
|
| 23 | - |
|
| 24 | - public function __construct( $file ) |
|
| 25 | - { |
|
| 26 | - $this->file = $file; |
|
| 27 | - $this->dir = dirname($this->file); |
|
| 28 | - $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 29 | - $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
| 30 | - $this->taxonomy = 'module'; |
|
| 31 | - $this->order_page_slug = 'module-order'; |
|
| 32 | - |
|
| 33 | - // setup taxonomy |
|
| 34 | - add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 35 | - |
|
| 36 | - // Manage lesson meta boxes for taxonomy |
|
| 37 | - add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 38 | - |
|
| 39 | - // Save lesson meta box |
|
| 40 | - add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
| 41 | - |
|
| 42 | - //Reset the none modules lessons transient |
|
| 43 | - add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 44 | - |
|
| 45 | - // Frontend styling |
|
| 46 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 47 | - |
|
| 48 | - // Admin styling |
|
| 49 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
| 50 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 51 | - |
|
| 52 | - // Handle module completion record |
|
| 53 | - add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
| 54 | - add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
| 55 | - add_action('wp', array($this, 'save_module_progress'), 10); |
|
| 56 | - |
|
| 57 | - // Handle module ordering |
|
| 58 | - add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 59 | - add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
| 60 | - add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
| 61 | - |
|
| 62 | - // Ensure modules always show under courses |
|
| 63 | - add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | - add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | - add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 66 | - |
|
| 67 | - // Add course field to taxonomy |
|
| 68 | - add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | - add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | - add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | - add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | - add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
| 73 | - |
|
| 74 | - // Manage module taxonomy archive page |
|
| 75 | - add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
| 76 | - add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
| 77 | - add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
| 78 | - add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
| 79 | - add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
| 80 | - add_filter('body_class', array($this, 'module_archive_body_class')); |
|
| 81 | - |
|
| 82 | - // add modules to the single course template |
|
| 83 | - add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 84 | - |
|
| 85 | - //Single Course modules actions. Add to single-course/course-modules.php |
|
| 86 | - add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 87 | - |
|
| 88 | - // Set up display on single lesson page |
|
| 89 | - add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
| 90 | - |
|
| 91 | - // Add 'Modules' columns to Analysis tables |
|
| 92 | - add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
| 93 | - add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
| 94 | - add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
| 95 | - add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
| 96 | - |
|
| 97 | - // Manage module taxonomy columns |
|
| 98 | - add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | - add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | - add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
| 101 | - |
|
| 102 | - //store new modules created on the course edit screen |
|
| 103 | - add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 104 | - |
|
| 105 | - // for non admin users, only show taxonomies that belong to them |
|
| 106 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | - add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 108 | - |
|
| 109 | - // add the teacher name next to the module term in for admin users |
|
| 110 | - add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 111 | - |
|
| 112 | - // remove the default modules metabox |
|
| 113 | - add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 114 | - |
|
| 115 | - } // end constructor |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Alter a module term slug when a new taxonomy term is created |
|
| 119 | - * This will add the creators user name to the slug for uniqueness. |
|
| 120 | - * |
|
| 121 | - * @since 1.8.0 |
|
| 122 | - * |
|
| 123 | - * @param $term_id |
|
| 124 | - * @param $tt_id |
|
| 125 | - * @param $taxonomy |
|
| 126 | - * |
|
| 127 | - * @return void |
|
| 128 | - * @deprecated since 1.9.0 |
|
| 129 | - */ |
|
| 130 | - public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 131 | - |
|
| 132 | - _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 133 | - |
|
| 134 | - }// end add_module_term_group |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Hook in all meta boxes related tot he modules taxonomy |
|
| 138 | - * |
|
| 139 | - * @since 1.8.0 |
|
| 140 | - * |
|
| 141 | - * @param string $post_type |
|
| 142 | - * @param WP_Post $post |
|
| 143 | - * |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function modules_metaboxes( $post_type, $post ) |
|
| 147 | - { |
|
| 148 | - if ('lesson' == $post_type ) { |
|
| 149 | - |
|
| 150 | - // Remove default taxonomy meta box from Lesson edit screen |
|
| 151 | - remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 152 | - |
|
| 153 | - // Add custom meta box to limit module selection to one per lesson |
|
| 154 | - add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if( 'course' == $post_type ){ |
|
| 158 | - // Course modules selection metabox |
|
| 159 | - add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Build content for custom module meta box |
|
| 165 | - * |
|
| 166 | - * @since 1.8.0 |
|
| 167 | - * @param object $post Current post object |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public function lesson_module_metabox($post) |
|
| 171 | - { |
|
| 172 | - |
|
| 173 | - // Get lesson course |
|
| 174 | - $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
| 175 | - |
|
| 176 | - $html = ''; |
|
| 177 | - |
|
| 178 | - // Only show module selection if this lesson is part of a course |
|
| 179 | - if ($lesson_course && $lesson_course > 0) { |
|
| 180 | - |
|
| 181 | - // Get existing lesson module |
|
| 182 | - $lesson_module = 0; |
|
| 183 | - $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
| 184 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 185 | - foreach ($lesson_module_list as $single_module) { |
|
| 186 | - $lesson_module = $single_module->term_id; |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Get the available modules for this lesson's course |
|
| 192 | - $modules = $this->get_course_modules($lesson_course); |
|
| 193 | - |
|
| 194 | - // Build the HTML to output |
|
| 195 | - $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 196 | - if (is_array($modules) && count($modules) > 0) { |
|
| 197 | - $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | - $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 199 | - foreach ($modules as $module) { |
|
| 200 | - $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 201 | - } |
|
| 202 | - $html .= '</select>' . "\n"; |
|
| 203 | - } else { |
|
| 204 | - $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 206 | - } // End If Statement |
|
| 207 | - |
|
| 208 | - } else { |
|
| 209 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 210 | - } // End If Statement |
|
| 211 | - |
|
| 212 | - // Output the HTML |
|
| 213 | - echo $html; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Save module to lesson |
|
| 218 | - * |
|
| 219 | - * @since 1.8.0 |
|
| 220 | - * @param integer $post_id ID of post |
|
| 221 | - * @return mixed Post ID on permissions failure, boolean true on success |
|
| 222 | - */ |
|
| 223 | - public function save_lesson_module($post_id) |
|
| 224 | - { |
|
| 225 | - global $post; |
|
| 226 | - |
|
| 227 | - // Verify post type and nonce |
|
| 228 | - if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | - ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 230 | - return $post_id; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // Check if user has permissions to edit lessons |
|
| 234 | - $post_type = get_post_type_object($post->post_type); |
|
| 235 | - if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | - return $post_id; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Check if user has permissions to edit this specific post |
|
| 240 | - if (!current_user_can('edit_post', $post_id)) { |
|
| 241 | - return $post_id; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Cast module ID as an integer if selected, otherwise leave as empty string |
|
| 245 | - if ( isset( $_POST['lesson_module'] ) ) { |
|
| 246 | - |
|
| 247 | - if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | - wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 249 | - return true; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $module_id = intval( $_POST['lesson_module'] ); |
|
| 253 | - |
|
| 254 | - // Assign lesson to selected module |
|
| 255 | - wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
| 256 | - |
|
| 257 | - // Set default order for lesson inside module |
|
| 258 | - if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | - update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Display course field on new module screen |
|
| 268 | - * |
|
| 269 | - * @since 1.8.0 |
|
| 270 | - * @param object $taxonomy Taxonomy object |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - public function add_module_fields($taxonomy) |
|
| 274 | - { |
|
| 275 | - ?> |
|
| 17 | + private $dir; |
|
| 18 | + private $file; |
|
| 19 | + private $assets_dir; |
|
| 20 | + private $assets_url; |
|
| 21 | + private $order_page_slug; |
|
| 22 | + public $taxonomy; |
|
| 23 | + |
|
| 24 | + public function __construct( $file ) |
|
| 25 | + { |
|
| 26 | + $this->file = $file; |
|
| 27 | + $this->dir = dirname($this->file); |
|
| 28 | + $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 29 | + $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
| 30 | + $this->taxonomy = 'module'; |
|
| 31 | + $this->order_page_slug = 'module-order'; |
|
| 32 | + |
|
| 33 | + // setup taxonomy |
|
| 34 | + add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 35 | + |
|
| 36 | + // Manage lesson meta boxes for taxonomy |
|
| 37 | + add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 38 | + |
|
| 39 | + // Save lesson meta box |
|
| 40 | + add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
| 41 | + |
|
| 42 | + //Reset the none modules lessons transient |
|
| 43 | + add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 44 | + |
|
| 45 | + // Frontend styling |
|
| 46 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 47 | + |
|
| 48 | + // Admin styling |
|
| 49 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
| 50 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 51 | + |
|
| 52 | + // Handle module completion record |
|
| 53 | + add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
| 54 | + add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
| 55 | + add_action('wp', array($this, 'save_module_progress'), 10); |
|
| 56 | + |
|
| 57 | + // Handle module ordering |
|
| 58 | + add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 59 | + add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
| 60 | + add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
| 61 | + |
|
| 62 | + // Ensure modules always show under courses |
|
| 63 | + add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | + add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | + add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 66 | + |
|
| 67 | + // Add course field to taxonomy |
|
| 68 | + add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | + add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | + add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | + add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | + add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
| 73 | + |
|
| 74 | + // Manage module taxonomy archive page |
|
| 75 | + add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
| 76 | + add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
| 77 | + add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
| 78 | + add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
| 79 | + add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
| 80 | + add_filter('body_class', array($this, 'module_archive_body_class')); |
|
| 81 | + |
|
| 82 | + // add modules to the single course template |
|
| 83 | + add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 84 | + |
|
| 85 | + //Single Course modules actions. Add to single-course/course-modules.php |
|
| 86 | + add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 87 | + |
|
| 88 | + // Set up display on single lesson page |
|
| 89 | + add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
| 90 | + |
|
| 91 | + // Add 'Modules' columns to Analysis tables |
|
| 92 | + add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
| 93 | + add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
| 94 | + add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
| 95 | + add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
| 96 | + |
|
| 97 | + // Manage module taxonomy columns |
|
| 98 | + add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | + add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | + add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
| 101 | + |
|
| 102 | + //store new modules created on the course edit screen |
|
| 103 | + add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 104 | + |
|
| 105 | + // for non admin users, only show taxonomies that belong to them |
|
| 106 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | + add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 108 | + |
|
| 109 | + // add the teacher name next to the module term in for admin users |
|
| 110 | + add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 111 | + |
|
| 112 | + // remove the default modules metabox |
|
| 113 | + add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 114 | + |
|
| 115 | + } // end constructor |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Alter a module term slug when a new taxonomy term is created |
|
| 119 | + * This will add the creators user name to the slug for uniqueness. |
|
| 120 | + * |
|
| 121 | + * @since 1.8.0 |
|
| 122 | + * |
|
| 123 | + * @param $term_id |
|
| 124 | + * @param $tt_id |
|
| 125 | + * @param $taxonomy |
|
| 126 | + * |
|
| 127 | + * @return void |
|
| 128 | + * @deprecated since 1.9.0 |
|
| 129 | + */ |
|
| 130 | + public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 131 | + |
|
| 132 | + _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 133 | + |
|
| 134 | + }// end add_module_term_group |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Hook in all meta boxes related tot he modules taxonomy |
|
| 138 | + * |
|
| 139 | + * @since 1.8.0 |
|
| 140 | + * |
|
| 141 | + * @param string $post_type |
|
| 142 | + * @param WP_Post $post |
|
| 143 | + * |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function modules_metaboxes( $post_type, $post ) |
|
| 147 | + { |
|
| 148 | + if ('lesson' == $post_type ) { |
|
| 149 | + |
|
| 150 | + // Remove default taxonomy meta box from Lesson edit screen |
|
| 151 | + remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 152 | + |
|
| 153 | + // Add custom meta box to limit module selection to one per lesson |
|
| 154 | + add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if( 'course' == $post_type ){ |
|
| 158 | + // Course modules selection metabox |
|
| 159 | + add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Build content for custom module meta box |
|
| 165 | + * |
|
| 166 | + * @since 1.8.0 |
|
| 167 | + * @param object $post Current post object |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public function lesson_module_metabox($post) |
|
| 171 | + { |
|
| 172 | + |
|
| 173 | + // Get lesson course |
|
| 174 | + $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
| 175 | + |
|
| 176 | + $html = ''; |
|
| 177 | + |
|
| 178 | + // Only show module selection if this lesson is part of a course |
|
| 179 | + if ($lesson_course && $lesson_course > 0) { |
|
| 180 | + |
|
| 181 | + // Get existing lesson module |
|
| 182 | + $lesson_module = 0; |
|
| 183 | + $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
| 184 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 185 | + foreach ($lesson_module_list as $single_module) { |
|
| 186 | + $lesson_module = $single_module->term_id; |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Get the available modules for this lesson's course |
|
| 192 | + $modules = $this->get_course_modules($lesson_course); |
|
| 193 | + |
|
| 194 | + // Build the HTML to output |
|
| 195 | + $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 196 | + if (is_array($modules) && count($modules) > 0) { |
|
| 197 | + $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | + $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 199 | + foreach ($modules as $module) { |
|
| 200 | + $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 201 | + } |
|
| 202 | + $html .= '</select>' . "\n"; |
|
| 203 | + } else { |
|
| 204 | + $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 206 | + } // End If Statement |
|
| 207 | + |
|
| 208 | + } else { |
|
| 209 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 210 | + } // End If Statement |
|
| 211 | + |
|
| 212 | + // Output the HTML |
|
| 213 | + echo $html; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Save module to lesson |
|
| 218 | + * |
|
| 219 | + * @since 1.8.0 |
|
| 220 | + * @param integer $post_id ID of post |
|
| 221 | + * @return mixed Post ID on permissions failure, boolean true on success |
|
| 222 | + */ |
|
| 223 | + public function save_lesson_module($post_id) |
|
| 224 | + { |
|
| 225 | + global $post; |
|
| 226 | + |
|
| 227 | + // Verify post type and nonce |
|
| 228 | + if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | + ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 230 | + return $post_id; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // Check if user has permissions to edit lessons |
|
| 234 | + $post_type = get_post_type_object($post->post_type); |
|
| 235 | + if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | + return $post_id; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Check if user has permissions to edit this specific post |
|
| 240 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 241 | + return $post_id; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Cast module ID as an integer if selected, otherwise leave as empty string |
|
| 245 | + if ( isset( $_POST['lesson_module'] ) ) { |
|
| 246 | + |
|
| 247 | + if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | + wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 249 | + return true; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $module_id = intval( $_POST['lesson_module'] ); |
|
| 253 | + |
|
| 254 | + // Assign lesson to selected module |
|
| 255 | + wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
| 256 | + |
|
| 257 | + // Set default order for lesson inside module |
|
| 258 | + if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | + update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Display course field on new module screen |
|
| 268 | + * |
|
| 269 | + * @since 1.8.0 |
|
| 270 | + * @param object $taxonomy Taxonomy object |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + public function add_module_fields($taxonomy) |
|
| 274 | + { |
|
| 275 | + ?> |
|
| 276 | 276 | <div class="form-field"> |
| 277 | 277 | <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label> |
| 278 | 278 | <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses" |
@@ -281,44 +281,44 @@ discard block |
||
| 281 | 281 | class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span> |
| 282 | 282 | </div> |
| 283 | 283 | <?php |
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Display course field on module edit screen |
|
| 288 | - * |
|
| 289 | - * @since 1.8.0 |
|
| 290 | - * @param object $module Module term object |
|
| 291 | - * @return void |
|
| 292 | - */ |
|
| 293 | - public function edit_module_fields($module) |
|
| 294 | - { |
|
| 295 | - |
|
| 296 | - $module_id = $module->term_id; |
|
| 297 | - |
|
| 298 | - // Get module's existing courses |
|
| 299 | - $args = array( |
|
| 300 | - 'post_type' => 'course', |
|
| 301 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 302 | - 'posts_per_page' => -1, |
|
| 303 | - 'tax_query' => array( |
|
| 304 | - array( |
|
| 305 | - 'taxonomy' => $this->taxonomy, |
|
| 306 | - 'field' => 'id', |
|
| 307 | - 'terms' => $module_id |
|
| 308 | - ) |
|
| 309 | - ) |
|
| 310 | - ); |
|
| 311 | - $courses = get_posts($args); |
|
| 312 | - |
|
| 313 | - //build the defaults array |
|
| 314 | - $module_courses = array(); |
|
| 315 | - if (isset($courses) && is_array($courses)) { |
|
| 316 | - foreach ($courses as $course) { |
|
| 317 | - $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - ?> |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Display course field on module edit screen |
|
| 288 | + * |
|
| 289 | + * @since 1.8.0 |
|
| 290 | + * @param object $module Module term object |
|
| 291 | + * @return void |
|
| 292 | + */ |
|
| 293 | + public function edit_module_fields($module) |
|
| 294 | + { |
|
| 295 | + |
|
| 296 | + $module_id = $module->term_id; |
|
| 297 | + |
|
| 298 | + // Get module's existing courses |
|
| 299 | + $args = array( |
|
| 300 | + 'post_type' => 'course', |
|
| 301 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 302 | + 'posts_per_page' => -1, |
|
| 303 | + 'tax_query' => array( |
|
| 304 | + array( |
|
| 305 | + 'taxonomy' => $this->taxonomy, |
|
| 306 | + 'field' => 'id', |
|
| 307 | + 'terms' => $module_id |
|
| 308 | + ) |
|
| 309 | + ) |
|
| 310 | + ); |
|
| 311 | + $courses = get_posts($args); |
|
| 312 | + |
|
| 313 | + //build the defaults array |
|
| 314 | + $module_courses = array(); |
|
| 315 | + if (isset($courses) && is_array($courses)) { |
|
| 316 | + foreach ($courses as $course) { |
|
| 317 | + $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + ?> |
|
| 322 | 322 | <tr class="form-field"> |
| 323 | 323 | <th scope="row" valign="top"><label |
| 324 | 324 | for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th> |
@@ -335,1399 +335,1399 @@ discard block |
||
| 335 | 335 | </td> |
| 336 | 336 | </tr> |
| 337 | 337 | <?php |
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Save module course on add/edit |
|
| 342 | - * |
|
| 343 | - * @since 1.8.0 |
|
| 344 | - * @param integer $module_id ID of module |
|
| 345 | - * @return void |
|
| 346 | - */ |
|
| 347 | - public function save_module_course($module_id) |
|
| 348 | - { |
|
| 349 | - |
|
| 350 | - // Get module's existing courses |
|
| 351 | - $args = array( |
|
| 352 | - 'post_type' => 'course', |
|
| 353 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 354 | - 'posts_per_page' => -1, |
|
| 355 | - 'tax_query' => array( |
|
| 356 | - array( |
|
| 357 | - 'taxonomy' => $this->taxonomy, |
|
| 358 | - 'field' => 'id', |
|
| 359 | - 'terms' => $module_id |
|
| 360 | - ) |
|
| 361 | - ) |
|
| 362 | - ); |
|
| 363 | - $courses = get_posts($args); |
|
| 364 | - |
|
| 365 | - // Remove module from existing courses |
|
| 366 | - if (isset($courses) && is_array($courses)) { |
|
| 367 | - foreach ($courses as $course) { |
|
| 368 | - wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Add module to selected courses |
|
| 373 | - if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 374 | - |
|
| 375 | - $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 376 | - |
|
| 377 | - foreach ( $course_ids as $course_id ) { |
|
| 378 | - |
|
| 379 | - wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
| 380 | - |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Ajax function to search for courses matching term |
|
| 387 | - * |
|
| 388 | - * @since 1.8.0 |
|
| 389 | - * @return void |
|
| 390 | - */ |
|
| 391 | - public function search_courses_json() |
|
| 392 | - { |
|
| 393 | - |
|
| 394 | - // Security check |
|
| 395 | - check_ajax_referer('search-courses', 'security'); |
|
| 396 | - |
|
| 397 | - // Set content type |
|
| 398 | - header('Content-Type: application/json; charset=utf-8'); |
|
| 399 | - |
|
| 400 | - // Get user input |
|
| 401 | - $term = urldecode(stripslashes($_GET['term'])); |
|
| 402 | - |
|
| 403 | - // Return nothing if term is empty |
|
| 404 | - if (empty($term)) |
|
| 405 | - die(); |
|
| 406 | - |
|
| 407 | - // Set a default if none is given |
|
| 408 | - $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
| 409 | - |
|
| 410 | - // Set up array of results |
|
| 411 | - $found_courses = array('' => $default); |
|
| 412 | - |
|
| 413 | - // Fetch results |
|
| 414 | - $args = array( |
|
| 415 | - 'post_type' => 'course', |
|
| 416 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 417 | - 'posts_per_page' => -1, |
|
| 418 | - 'orderby' => 'title', |
|
| 419 | - 's' => $term |
|
| 420 | - ); |
|
| 421 | - $courses = get_posts($args); |
|
| 422 | - |
|
| 423 | - // Add results to array |
|
| 424 | - if ($courses) { |
|
| 425 | - foreach ($courses as $course) { |
|
| 426 | - $found_courses[$course->ID] = $course->post_title; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // Encode and return results for processing & selection |
|
| 431 | - echo json_encode($found_courses); |
|
| 432 | - die(); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * display modules on single course pages |
|
| 437 | - * |
|
| 438 | - * @since 1.8.0 |
|
| 439 | - * @return void |
|
| 440 | - */ |
|
| 441 | - public function single_course_modules(){ |
|
| 442 | - |
|
| 443 | - _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | - // only show modules on the course that has modules |
|
| 445 | - if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 446 | - |
|
| 447 | - $this->load_course_module_content_template(); |
|
| 448 | - |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - } // end single_course_modules |
|
| 452 | - |
|
| 453 | - public function sensei_course_preview_titles($title, $lesson_id) |
|
| 454 | - { |
|
| 455 | - global $post, $current_user; |
|
| 456 | - |
|
| 457 | - $course_id = $post->ID; |
|
| 458 | - $title_text = ''; |
|
| 459 | - |
|
| 460 | - if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
| 461 | - $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
| 462 | - if (!$is_user_taking_course) { |
|
| 463 | - if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
| 464 | - $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
| 465 | - // Remove brackets for display here |
|
| 466 | - $title_text = str_replace('(', '', $title_text); |
|
| 467 | - $title_text = str_replace(')', '', $title_text); |
|
| 468 | - $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 469 | - } |
|
| 470 | - $title .= ' ' . $title_text; |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - return $title; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - public function module_breadcrumb_link($html, $separator) |
|
| 478 | - { |
|
| 479 | - global $post; |
|
| 480 | - // Lesson |
|
| 481 | - if (is_singular('lesson')) { |
|
| 482 | - if (has_term('', $this->taxonomy, $post->ID)) { |
|
| 483 | - $module = $this->get_lesson_module($post->ID); |
|
| 484 | - if( $module ) { |
|
| 485 | - $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - // Module |
|
| 490 | - if (is_tax($this->taxonomy)) { |
|
| 491 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 492 | - $course_id = intval($_GET['course_id']); |
|
| 493 | - $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $html; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Set lesson archive template to display on module taxonomy archive page |
|
| 501 | - * |
|
| 502 | - * @since 1.8.0 |
|
| 503 | - * @param string $template Default template |
|
| 504 | - * @return string Modified template |
|
| 505 | - */ |
|
| 506 | - public function module_archive_template($template) { |
|
| 507 | - |
|
| 508 | - if ( ! is_tax($this->taxonomy) ) { |
|
| 509 | - return $template; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - $file = 'archive-lesson.php'; |
|
| 513 | - $find = array( $file, Sensei()->template_url . $file ); |
|
| 514 | - |
|
| 515 | - // locate the template file |
|
| 516 | - $template = locate_template($find); |
|
| 517 | - if (!$template) { |
|
| 518 | - |
|
| 519 | - $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 520 | - |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - return $template; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Modify module taxonomy archive query |
|
| 529 | - * |
|
| 530 | - * @since 1.8.0 |
|
| 531 | - * @param object $query The query object passed by reference |
|
| 532 | - * @return void |
|
| 533 | - */ |
|
| 534 | - public function module_archive_filter($query) |
|
| 535 | - { |
|
| 536 | - if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - // Limit to lessons only |
|
| 540 | - $query->set('post_type', 'lesson'); |
|
| 541 | - |
|
| 542 | - // Set order of lessons |
|
| 543 | - if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 544 | - $module_id = $query->queried_object_id; |
|
| 545 | - $query->set('meta_key', '_order_module_' . $module_id); |
|
| 546 | - $query->set('orderby', 'meta_value_num date'); |
|
| 547 | - } else { |
|
| 548 | - $query->set('orderby', 'menu_order'); |
|
| 549 | - } |
|
| 550 | - $query->set('order', 'ASC'); |
|
| 551 | - |
|
| 552 | - // Limit to specific course if specified |
|
| 553 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 554 | - $course_id = intval($_GET['course_id']); |
|
| 555 | - $meta_query[] = array( |
|
| 556 | - 'key' => '_lesson_course', |
|
| 557 | - 'value' => intval($course_id) |
|
| 558 | - ); |
|
| 559 | - $query->set('meta_query', $meta_query); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Modify archive page title |
|
| 567 | - * |
|
| 568 | - * @since 1.8.0 |
|
| 569 | - * @param string $title Default title |
|
| 570 | - * @return string Modified title |
|
| 571 | - */ |
|
| 572 | - public function module_archive_title($title) |
|
| 573 | - { |
|
| 574 | - if (is_tax($this->taxonomy)) { |
|
| 575 | - $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
| 576 | - } |
|
| 577 | - return $title; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Display module description on taxonomy archive page |
|
| 582 | - * |
|
| 583 | - * @since 1.8.0 |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - public function module_archive_description() |
|
| 587 | - { |
|
| 588 | - if (is_tax($this->taxonomy)) { |
|
| 589 | - |
|
| 590 | - $module = get_queried_object(); |
|
| 591 | - |
|
| 592 | - $module_progress = false; |
|
| 593 | - if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
| 594 | - global $current_user; |
|
| 595 | - wp_get_current_user(); |
|
| 596 | - $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if ($module_progress && $module_progress > 0) { |
|
| 600 | - $status = __('Completed', 'woothemes-sensei'); |
|
| 601 | - $class = 'completed'; |
|
| 602 | - if ($module_progress < 100) { |
|
| 603 | - $status = __('In progress', 'woothemes-sensei'); |
|
| 604 | - $class = 'in-progress'; |
|
| 605 | - } |
|
| 606 | - echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - public function module_archive_body_class($classes) |
|
| 614 | - { |
|
| 615 | - if (is_tax($this->taxonomy)) { |
|
| 616 | - $classes[] = 'module-archive'; |
|
| 617 | - } |
|
| 618 | - return $classes; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Display module navigation links on module taxonomy archive page |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * @return void |
|
| 626 | - */ |
|
| 627 | - public function module_navigation_links() |
|
| 628 | - { |
|
| 629 | - if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
| 630 | - |
|
| 631 | - $queried_module = get_queried_object(); |
|
| 632 | - $course_modules = $this->get_course_modules($_GET['course_id']); |
|
| 633 | - |
|
| 634 | - $prev_module = false; |
|
| 635 | - $next_module = false; |
|
| 636 | - $on_current = false; |
|
| 637 | - foreach ($course_modules as $module) { |
|
| 638 | - $this_module = $module; |
|
| 639 | - if ($on_current) { |
|
| 640 | - $next_module = $this_module; |
|
| 641 | - break; |
|
| 642 | - } |
|
| 643 | - if ($this_module == $queried_module) { |
|
| 644 | - $on_current = true; |
|
| 645 | - } else { |
|
| 646 | - $prev_module = $module; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - ?> |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Save module course on add/edit |
|
| 342 | + * |
|
| 343 | + * @since 1.8.0 |
|
| 344 | + * @param integer $module_id ID of module |
|
| 345 | + * @return void |
|
| 346 | + */ |
|
| 347 | + public function save_module_course($module_id) |
|
| 348 | + { |
|
| 349 | + |
|
| 350 | + // Get module's existing courses |
|
| 351 | + $args = array( |
|
| 352 | + 'post_type' => 'course', |
|
| 353 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 354 | + 'posts_per_page' => -1, |
|
| 355 | + 'tax_query' => array( |
|
| 356 | + array( |
|
| 357 | + 'taxonomy' => $this->taxonomy, |
|
| 358 | + 'field' => 'id', |
|
| 359 | + 'terms' => $module_id |
|
| 360 | + ) |
|
| 361 | + ) |
|
| 362 | + ); |
|
| 363 | + $courses = get_posts($args); |
|
| 364 | + |
|
| 365 | + // Remove module from existing courses |
|
| 366 | + if (isset($courses) && is_array($courses)) { |
|
| 367 | + foreach ($courses as $course) { |
|
| 368 | + wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Add module to selected courses |
|
| 373 | + if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 374 | + |
|
| 375 | + $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 376 | + |
|
| 377 | + foreach ( $course_ids as $course_id ) { |
|
| 378 | + |
|
| 379 | + wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
| 380 | + |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Ajax function to search for courses matching term |
|
| 387 | + * |
|
| 388 | + * @since 1.8.0 |
|
| 389 | + * @return void |
|
| 390 | + */ |
|
| 391 | + public function search_courses_json() |
|
| 392 | + { |
|
| 393 | + |
|
| 394 | + // Security check |
|
| 395 | + check_ajax_referer('search-courses', 'security'); |
|
| 396 | + |
|
| 397 | + // Set content type |
|
| 398 | + header('Content-Type: application/json; charset=utf-8'); |
|
| 399 | + |
|
| 400 | + // Get user input |
|
| 401 | + $term = urldecode(stripslashes($_GET['term'])); |
|
| 402 | + |
|
| 403 | + // Return nothing if term is empty |
|
| 404 | + if (empty($term)) |
|
| 405 | + die(); |
|
| 406 | + |
|
| 407 | + // Set a default if none is given |
|
| 408 | + $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
| 409 | + |
|
| 410 | + // Set up array of results |
|
| 411 | + $found_courses = array('' => $default); |
|
| 412 | + |
|
| 413 | + // Fetch results |
|
| 414 | + $args = array( |
|
| 415 | + 'post_type' => 'course', |
|
| 416 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 417 | + 'posts_per_page' => -1, |
|
| 418 | + 'orderby' => 'title', |
|
| 419 | + 's' => $term |
|
| 420 | + ); |
|
| 421 | + $courses = get_posts($args); |
|
| 422 | + |
|
| 423 | + // Add results to array |
|
| 424 | + if ($courses) { |
|
| 425 | + foreach ($courses as $course) { |
|
| 426 | + $found_courses[$course->ID] = $course->post_title; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // Encode and return results for processing & selection |
|
| 431 | + echo json_encode($found_courses); |
|
| 432 | + die(); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * display modules on single course pages |
|
| 437 | + * |
|
| 438 | + * @since 1.8.0 |
|
| 439 | + * @return void |
|
| 440 | + */ |
|
| 441 | + public function single_course_modules(){ |
|
| 442 | + |
|
| 443 | + _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | + // only show modules on the course that has modules |
|
| 445 | + if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 446 | + |
|
| 447 | + $this->load_course_module_content_template(); |
|
| 448 | + |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + } // end single_course_modules |
|
| 452 | + |
|
| 453 | + public function sensei_course_preview_titles($title, $lesson_id) |
|
| 454 | + { |
|
| 455 | + global $post, $current_user; |
|
| 456 | + |
|
| 457 | + $course_id = $post->ID; |
|
| 458 | + $title_text = ''; |
|
| 459 | + |
|
| 460 | + if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
| 461 | + $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
| 462 | + if (!$is_user_taking_course) { |
|
| 463 | + if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
| 464 | + $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
| 465 | + // Remove brackets for display here |
|
| 466 | + $title_text = str_replace('(', '', $title_text); |
|
| 467 | + $title_text = str_replace(')', '', $title_text); |
|
| 468 | + $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 469 | + } |
|
| 470 | + $title .= ' ' . $title_text; |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + return $title; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + public function module_breadcrumb_link($html, $separator) |
|
| 478 | + { |
|
| 479 | + global $post; |
|
| 480 | + // Lesson |
|
| 481 | + if (is_singular('lesson')) { |
|
| 482 | + if (has_term('', $this->taxonomy, $post->ID)) { |
|
| 483 | + $module = $this->get_lesson_module($post->ID); |
|
| 484 | + if( $module ) { |
|
| 485 | + $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + // Module |
|
| 490 | + if (is_tax($this->taxonomy)) { |
|
| 491 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 492 | + $course_id = intval($_GET['course_id']); |
|
| 493 | + $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $html; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Set lesson archive template to display on module taxonomy archive page |
|
| 501 | + * |
|
| 502 | + * @since 1.8.0 |
|
| 503 | + * @param string $template Default template |
|
| 504 | + * @return string Modified template |
|
| 505 | + */ |
|
| 506 | + public function module_archive_template($template) { |
|
| 507 | + |
|
| 508 | + if ( ! is_tax($this->taxonomy) ) { |
|
| 509 | + return $template; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $file = 'archive-lesson.php'; |
|
| 513 | + $find = array( $file, Sensei()->template_url . $file ); |
|
| 514 | + |
|
| 515 | + // locate the template file |
|
| 516 | + $template = locate_template($find); |
|
| 517 | + if (!$template) { |
|
| 518 | + |
|
| 519 | + $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 520 | + |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + return $template; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * Modify module taxonomy archive query |
|
| 529 | + * |
|
| 530 | + * @since 1.8.0 |
|
| 531 | + * @param object $query The query object passed by reference |
|
| 532 | + * @return void |
|
| 533 | + */ |
|
| 534 | + public function module_archive_filter($query) |
|
| 535 | + { |
|
| 536 | + if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + // Limit to lessons only |
|
| 540 | + $query->set('post_type', 'lesson'); |
|
| 541 | + |
|
| 542 | + // Set order of lessons |
|
| 543 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 544 | + $module_id = $query->queried_object_id; |
|
| 545 | + $query->set('meta_key', '_order_module_' . $module_id); |
|
| 546 | + $query->set('orderby', 'meta_value_num date'); |
|
| 547 | + } else { |
|
| 548 | + $query->set('orderby', 'menu_order'); |
|
| 549 | + } |
|
| 550 | + $query->set('order', 'ASC'); |
|
| 551 | + |
|
| 552 | + // Limit to specific course if specified |
|
| 553 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 554 | + $course_id = intval($_GET['course_id']); |
|
| 555 | + $meta_query[] = array( |
|
| 556 | + 'key' => '_lesson_course', |
|
| 557 | + 'value' => intval($course_id) |
|
| 558 | + ); |
|
| 559 | + $query->set('meta_query', $meta_query); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Modify archive page title |
|
| 567 | + * |
|
| 568 | + * @since 1.8.0 |
|
| 569 | + * @param string $title Default title |
|
| 570 | + * @return string Modified title |
|
| 571 | + */ |
|
| 572 | + public function module_archive_title($title) |
|
| 573 | + { |
|
| 574 | + if (is_tax($this->taxonomy)) { |
|
| 575 | + $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
| 576 | + } |
|
| 577 | + return $title; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Display module description on taxonomy archive page |
|
| 582 | + * |
|
| 583 | + * @since 1.8.0 |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + public function module_archive_description() |
|
| 587 | + { |
|
| 588 | + if (is_tax($this->taxonomy)) { |
|
| 589 | + |
|
| 590 | + $module = get_queried_object(); |
|
| 591 | + |
|
| 592 | + $module_progress = false; |
|
| 593 | + if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
| 594 | + global $current_user; |
|
| 595 | + wp_get_current_user(); |
|
| 596 | + $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + if ($module_progress && $module_progress > 0) { |
|
| 600 | + $status = __('Completed', 'woothemes-sensei'); |
|
| 601 | + $class = 'completed'; |
|
| 602 | + if ($module_progress < 100) { |
|
| 603 | + $status = __('In progress', 'woothemes-sensei'); |
|
| 604 | + $class = 'in-progress'; |
|
| 605 | + } |
|
| 606 | + echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + public function module_archive_body_class($classes) |
|
| 614 | + { |
|
| 615 | + if (is_tax($this->taxonomy)) { |
|
| 616 | + $classes[] = 'module-archive'; |
|
| 617 | + } |
|
| 618 | + return $classes; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Display module navigation links on module taxonomy archive page |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * @return void |
|
| 626 | + */ |
|
| 627 | + public function module_navigation_links() |
|
| 628 | + { |
|
| 629 | + if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
| 630 | + |
|
| 631 | + $queried_module = get_queried_object(); |
|
| 632 | + $course_modules = $this->get_course_modules($_GET['course_id']); |
|
| 633 | + |
|
| 634 | + $prev_module = false; |
|
| 635 | + $next_module = false; |
|
| 636 | + $on_current = false; |
|
| 637 | + foreach ($course_modules as $module) { |
|
| 638 | + $this_module = $module; |
|
| 639 | + if ($on_current) { |
|
| 640 | + $next_module = $this_module; |
|
| 641 | + break; |
|
| 642 | + } |
|
| 643 | + if ($this_module == $queried_module) { |
|
| 644 | + $on_current = true; |
|
| 645 | + } else { |
|
| 646 | + $prev_module = $module; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + ?> |
|
| 651 | 651 | <div id="post-entries" class="post-entries module-navigation fix"> |
| 652 | 652 | <?php if ($next_module) { |
| 653 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
| 654 | - ?> |
|
| 653 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
| 654 | + ?> |
|
| 655 | 655 | <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>" |
| 656 | 656 | title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?> |
| 657 | 657 | <span class="meta-nav"></span></a></div> |
| 658 | 658 | <?php } ?> |
| 659 | 659 | <?php if ($prev_module) { |
| 660 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
| 661 | - ?> |
|
| 660 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
| 661 | + ?> |
|
| 662 | 662 | <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>" |
| 663 | 663 | title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span |
| 664 | 664 | class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div> |
| 665 | 665 | <?php } ?> |
| 666 | 666 | </div> |
| 667 | 667 | <?php |
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
| 673 | - * |
|
| 674 | - * @since 1.8.0 |
|
| 675 | - * @param string $status Status of the lesson for the user |
|
| 676 | - * @param integer $user_id ID of user |
|
| 677 | - * @param integer $lesson_id ID of lesson |
|
| 678 | - * @return void |
|
| 679 | - */ |
|
| 680 | - public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
| 681 | - { |
|
| 682 | - $this->save_lesson_module_progress($user_id, $lesson_id); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Save lesson's module progress for a specific user |
|
| 687 | - * |
|
| 688 | - * @since 1.8.0 |
|
| 689 | - * @param integer $user_id ID of user |
|
| 690 | - * @param integer $lesson_id ID of lesson |
|
| 691 | - * @return void |
|
| 692 | - */ |
|
| 693 | - public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
| 694 | - { |
|
| 695 | - $module = $this->get_lesson_module($lesson_id); |
|
| 696 | - $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 697 | - if ($module && $course_id) { |
|
| 698 | - $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Save progress of module for user |
|
| 704 | - * |
|
| 705 | - * @since 1.8.0 |
|
| 706 | - * @return void |
|
| 707 | - */ |
|
| 708 | - public function save_module_progress() |
|
| 709 | - { |
|
| 710 | - if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 711 | - global $current_user; |
|
| 712 | - wp_get_current_user(); |
|
| 713 | - $user_id = $current_user->ID; |
|
| 714 | - |
|
| 715 | - $module = get_queried_object(); |
|
| 716 | - |
|
| 717 | - $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Save module progess for user |
|
| 723 | - * |
|
| 724 | - * @since 1.8.0 |
|
| 725 | - * |
|
| 726 | - * @param integer $module_id ID of module |
|
| 727 | - * @param integer $course_id ID of course |
|
| 728 | - * @param integer $user_id ID of user |
|
| 729 | - * @return void |
|
| 730 | - */ |
|
| 731 | - public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 732 | - { |
|
| 733 | - $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
| 734 | - update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 735 | - |
|
| 736 | - do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * Get module progress for a user |
|
| 741 | - * |
|
| 742 | - * @since 1.8.0 |
|
| 743 | - * |
|
| 744 | - * @param integer $module_id ID of module |
|
| 745 | - * @param integer $course_id ID of course |
|
| 746 | - * @param integer $user_id ID of user |
|
| 747 | - * @return mixed Module progress percentage on success, false on failure |
|
| 748 | - */ |
|
| 749 | - public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 750 | - { |
|
| 751 | - $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 752 | - if ($module_progress) { |
|
| 753 | - return (float)$module_progress; |
|
| 754 | - } |
|
| 755 | - return false; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Calculate module progess for user |
|
| 760 | - * |
|
| 761 | - * @since 1.8.0 |
|
| 762 | - * |
|
| 763 | - * @param integer $user_id ID of user |
|
| 764 | - * @param integer $module_id ID of module |
|
| 765 | - * @param integer $course_id ID of course |
|
| 766 | - * @return integer Module progress percentage |
|
| 767 | - */ |
|
| 768 | - public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
| 769 | - { |
|
| 770 | - |
|
| 771 | - $args = array( |
|
| 772 | - 'post_type' => 'lesson', |
|
| 773 | - 'post_status' => 'publish', |
|
| 774 | - 'posts_per_page' => -1, |
|
| 775 | - 'tax_query' => array( |
|
| 776 | - array( |
|
| 777 | - 'taxonomy' => $this->taxonomy, |
|
| 778 | - 'field' => 'id', |
|
| 779 | - 'terms' => $module_id |
|
| 780 | - ) |
|
| 781 | - ), |
|
| 782 | - 'meta_query' => array( |
|
| 783 | - array( |
|
| 784 | - 'key' => '_lesson_course', |
|
| 785 | - 'value' => $course_id |
|
| 786 | - ) |
|
| 787 | - ), |
|
| 788 | - 'fields' => 'ids' |
|
| 789 | - ); |
|
| 790 | - $lessons = get_posts($args); |
|
| 791 | - |
|
| 792 | - if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 793 | - |
|
| 794 | - $completed = false; |
|
| 795 | - $lesson_count = 0; |
|
| 796 | - $completed_count = 0; |
|
| 797 | - foreach ($lessons as $lesson_id) { |
|
| 798 | - $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
| 799 | - ++$lesson_count; |
|
| 800 | - if ($completed) { |
|
| 801 | - ++$completed_count; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $module_progress = ($completed_count / $lesson_count) * 100; |
|
| 805 | - |
|
| 806 | - return (float)$module_progress; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Register admin screen for ordering modules |
|
| 811 | - * |
|
| 812 | - * @since 1.8.0 |
|
| 813 | - * |
|
| 814 | - * @return void |
|
| 815 | - */ |
|
| 816 | - public function register_modules_admin_menu_items() |
|
| 817 | - { |
|
| 818 | - //add the modules link under the Course main menu |
|
| 819 | - add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 820 | - |
|
| 821 | - // Regsiter new admin page for module ordering |
|
| 822 | - $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
| 823 | - |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * Display Module Order screen |
|
| 828 | - * |
|
| 829 | - * @since 1.8.0 |
|
| 830 | - * |
|
| 831 | - * @return void |
|
| 832 | - */ |
|
| 833 | - public function module_order_screen() |
|
| 834 | - { |
|
| 835 | - ?> |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
| 673 | + * |
|
| 674 | + * @since 1.8.0 |
|
| 675 | + * @param string $status Status of the lesson for the user |
|
| 676 | + * @param integer $user_id ID of user |
|
| 677 | + * @param integer $lesson_id ID of lesson |
|
| 678 | + * @return void |
|
| 679 | + */ |
|
| 680 | + public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
| 681 | + { |
|
| 682 | + $this->save_lesson_module_progress($user_id, $lesson_id); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Save lesson's module progress for a specific user |
|
| 687 | + * |
|
| 688 | + * @since 1.8.0 |
|
| 689 | + * @param integer $user_id ID of user |
|
| 690 | + * @param integer $lesson_id ID of lesson |
|
| 691 | + * @return void |
|
| 692 | + */ |
|
| 693 | + public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
| 694 | + { |
|
| 695 | + $module = $this->get_lesson_module($lesson_id); |
|
| 696 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 697 | + if ($module && $course_id) { |
|
| 698 | + $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Save progress of module for user |
|
| 704 | + * |
|
| 705 | + * @since 1.8.0 |
|
| 706 | + * @return void |
|
| 707 | + */ |
|
| 708 | + public function save_module_progress() |
|
| 709 | + { |
|
| 710 | + if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 711 | + global $current_user; |
|
| 712 | + wp_get_current_user(); |
|
| 713 | + $user_id = $current_user->ID; |
|
| 714 | + |
|
| 715 | + $module = get_queried_object(); |
|
| 716 | + |
|
| 717 | + $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Save module progess for user |
|
| 723 | + * |
|
| 724 | + * @since 1.8.0 |
|
| 725 | + * |
|
| 726 | + * @param integer $module_id ID of module |
|
| 727 | + * @param integer $course_id ID of course |
|
| 728 | + * @param integer $user_id ID of user |
|
| 729 | + * @return void |
|
| 730 | + */ |
|
| 731 | + public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 732 | + { |
|
| 733 | + $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
| 734 | + update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 735 | + |
|
| 736 | + do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * Get module progress for a user |
|
| 741 | + * |
|
| 742 | + * @since 1.8.0 |
|
| 743 | + * |
|
| 744 | + * @param integer $module_id ID of module |
|
| 745 | + * @param integer $course_id ID of course |
|
| 746 | + * @param integer $user_id ID of user |
|
| 747 | + * @return mixed Module progress percentage on success, false on failure |
|
| 748 | + */ |
|
| 749 | + public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 750 | + { |
|
| 751 | + $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 752 | + if ($module_progress) { |
|
| 753 | + return (float)$module_progress; |
|
| 754 | + } |
|
| 755 | + return false; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Calculate module progess for user |
|
| 760 | + * |
|
| 761 | + * @since 1.8.0 |
|
| 762 | + * |
|
| 763 | + * @param integer $user_id ID of user |
|
| 764 | + * @param integer $module_id ID of module |
|
| 765 | + * @param integer $course_id ID of course |
|
| 766 | + * @return integer Module progress percentage |
|
| 767 | + */ |
|
| 768 | + public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
| 769 | + { |
|
| 770 | + |
|
| 771 | + $args = array( |
|
| 772 | + 'post_type' => 'lesson', |
|
| 773 | + 'post_status' => 'publish', |
|
| 774 | + 'posts_per_page' => -1, |
|
| 775 | + 'tax_query' => array( |
|
| 776 | + array( |
|
| 777 | + 'taxonomy' => $this->taxonomy, |
|
| 778 | + 'field' => 'id', |
|
| 779 | + 'terms' => $module_id |
|
| 780 | + ) |
|
| 781 | + ), |
|
| 782 | + 'meta_query' => array( |
|
| 783 | + array( |
|
| 784 | + 'key' => '_lesson_course', |
|
| 785 | + 'value' => $course_id |
|
| 786 | + ) |
|
| 787 | + ), |
|
| 788 | + 'fields' => 'ids' |
|
| 789 | + ); |
|
| 790 | + $lessons = get_posts($args); |
|
| 791 | + |
|
| 792 | + if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 793 | + |
|
| 794 | + $completed = false; |
|
| 795 | + $lesson_count = 0; |
|
| 796 | + $completed_count = 0; |
|
| 797 | + foreach ($lessons as $lesson_id) { |
|
| 798 | + $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
| 799 | + ++$lesson_count; |
|
| 800 | + if ($completed) { |
|
| 801 | + ++$completed_count; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $module_progress = ($completed_count / $lesson_count) * 100; |
|
| 805 | + |
|
| 806 | + return (float)$module_progress; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Register admin screen for ordering modules |
|
| 811 | + * |
|
| 812 | + * @since 1.8.0 |
|
| 813 | + * |
|
| 814 | + * @return void |
|
| 815 | + */ |
|
| 816 | + public function register_modules_admin_menu_items() |
|
| 817 | + { |
|
| 818 | + //add the modules link under the Course main menu |
|
| 819 | + add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 820 | + |
|
| 821 | + // Regsiter new admin page for module ordering |
|
| 822 | + $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
| 823 | + |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * Display Module Order screen |
|
| 828 | + * |
|
| 829 | + * @since 1.8.0 |
|
| 830 | + * |
|
| 831 | + * @return void |
|
| 832 | + */ |
|
| 833 | + public function module_order_screen() |
|
| 834 | + { |
|
| 835 | + ?> |
|
| 836 | 836 | <div id="<?php echo esc_attr($this->order_page_slug); ?>" |
| 837 | 837 | class="wrap <?php echo esc_attr($this->order_page_slug); ?>"> |
| 838 | 838 | <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php |
| 839 | 839 | |
| 840 | - $html = ''; |
|
| 841 | - |
|
| 842 | - if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
| 843 | - $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
| 844 | - |
|
| 845 | - if ($ordered) { |
|
| 846 | - $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | - $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | - $html .= '</div>' . "\n"; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - $courses = Sensei()->course->get_all_courses(); |
|
| 853 | - |
|
| 854 | - $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | - $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | - $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | - $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | - $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 859 | - |
|
| 860 | - foreach ($courses as $course) { |
|
| 861 | - if (has_term('', $this->taxonomy, $course->ID)) { |
|
| 862 | - $course_id = ''; |
|
| 863 | - if (isset($_GET['course_id'])) { |
|
| 864 | - $course_id = intval($_GET['course_id']); |
|
| 865 | - } |
|
| 866 | - $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - $html .= '</select>' . "\n"; |
|
| 871 | - $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | - $html .= '</form>' . "\n"; |
|
| 873 | - |
|
| 874 | - if (isset($_GET['course_id'])) { |
|
| 875 | - $course_id = intval($_GET['course_id']); |
|
| 876 | - if ($course_id > 0) { |
|
| 877 | - $modules = $this->get_course_modules($course_id); |
|
| 878 | - $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 879 | - if ($modules) { |
|
| 880 | - |
|
| 881 | - $order = $this->get_course_module_order($course_id); |
|
| 882 | - |
|
| 883 | - $order_string=''; |
|
| 884 | - if ($order) { |
|
| 885 | - $order_string = implode(',', $order); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | - $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 890 | - $count = 0; |
|
| 891 | - foreach ($modules as $module) { |
|
| 892 | - $count++; |
|
| 893 | - $class = $this->taxonomy; |
|
| 894 | - if ($count == 1) { |
|
| 895 | - $class .= ' first'; |
|
| 896 | - } |
|
| 897 | - if ($count == count($module)) { |
|
| 898 | - $class .= ' last'; |
|
| 899 | - } |
|
| 900 | - if ($count % 2 != 0) { |
|
| 901 | - $class .= ' alternate'; |
|
| 902 | - } |
|
| 903 | - $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 904 | - } |
|
| 905 | - $html .= '</ul>' . "\n"; |
|
| 906 | - |
|
| 907 | - $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | - $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | - $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - echo $html; |
|
| 916 | - |
|
| 917 | - ?></div><?php |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Add 'Module order' column to courses list table |
|
| 922 | - * |
|
| 923 | - * @since 1.8.0 |
|
| 924 | - * |
|
| 925 | - * @param array $columns Existing columns |
|
| 926 | - * @return array Modifed columns |
|
| 927 | - */ |
|
| 928 | - public function course_columns($columns = array()) |
|
| 929 | - { |
|
| 930 | - $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
| 931 | - return $columns; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * Load content in 'Module order' column |
|
| 936 | - * |
|
| 937 | - * @since 1.8.0 |
|
| 938 | - * |
|
| 939 | - * @param string $column Current column name |
|
| 940 | - * @param integer $course_id ID of course |
|
| 941 | - * @return void |
|
| 942 | - */ |
|
| 943 | - public function course_column_content($column = '', $course_id = 0) |
|
| 944 | - { |
|
| 945 | - if ($column == 'module_order') { |
|
| 946 | - if (has_term('', $this->taxonomy, $course_id)) { |
|
| 947 | - echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * Save module order for course |
|
| 954 | - * |
|
| 955 | - * @since 1.8.0 |
|
| 956 | - * |
|
| 957 | - * @param string $order_string Comma-separated string of module IDs |
|
| 958 | - * @param integer $course_id ID of course |
|
| 959 | - * @return boolean True on success, false on failure |
|
| 960 | - */ |
|
| 961 | - private function save_course_module_order($order_string = '', $course_id = 0) |
|
| 962 | - { |
|
| 963 | - if ($order_string && $course_id) { |
|
| 964 | - $order = explode(',', $order_string); |
|
| 965 | - update_post_meta(intval($course_id), '_module_order', $order); |
|
| 966 | - return true; |
|
| 967 | - } |
|
| 968 | - return false; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Get module order for course |
|
| 973 | - * |
|
| 974 | - * @since 1.8.0 |
|
| 975 | - * |
|
| 976 | - * @param integer $course_id ID of course |
|
| 977 | - * @return mixed Module order on success, false if no module order has been saved |
|
| 978 | - */ |
|
| 979 | - public function get_course_module_order($course_id = 0) |
|
| 980 | - { |
|
| 981 | - if ($course_id) { |
|
| 982 | - $order = get_post_meta(intval($course_id), '_module_order', true); |
|
| 983 | - return $order; |
|
| 984 | - } |
|
| 985 | - return false; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Modify module taxonomy columns |
|
| 990 | - * |
|
| 991 | - * @since 1.8.0 |
|
| 992 | - * |
|
| 993 | - * @param array $columns Default columns |
|
| 994 | - * @return array Modified columns |
|
| 995 | - */ |
|
| 996 | - public function taxonomy_column_headings($columns) |
|
| 997 | - { |
|
| 998 | - |
|
| 999 | - unset($columns['posts']); |
|
| 1000 | - |
|
| 1001 | - $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
| 1002 | - |
|
| 1003 | - return $columns; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Manage content in custom module taxonomy columns |
|
| 1008 | - * |
|
| 1009 | - * @since 1.8.0 |
|
| 1010 | - * |
|
| 1011 | - * @param string $column_data Default data for column |
|
| 1012 | - * @param string $column_name Name of current column |
|
| 1013 | - * @param integer $term_id ID of current term |
|
| 1014 | - * @return string Modified column data |
|
| 1015 | - */ |
|
| 1016 | - public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
| 1017 | - { |
|
| 1018 | - |
|
| 1019 | - $args = array( |
|
| 1020 | - 'post_status' => 'publish', |
|
| 1021 | - 'posts_per_page' => -1, |
|
| 1022 | - 'tax_query' => array( |
|
| 1023 | - array( |
|
| 1024 | - 'taxonomy' => $this->taxonomy, |
|
| 1025 | - 'field' => 'id', |
|
| 1026 | - 'terms' => intval($term_id) |
|
| 1027 | - ) |
|
| 1028 | - ) |
|
| 1029 | - ); |
|
| 1030 | - |
|
| 1031 | - $module = get_term($term_id, $this->taxonomy); |
|
| 1032 | - |
|
| 1033 | - switch ($column_name) { |
|
| 1034 | - |
|
| 1035 | - case 'lessons': |
|
| 1036 | - $args['post_type'] = 'lesson'; |
|
| 1037 | - $lessons = get_posts($args); |
|
| 1038 | - $total_lessons = count($lessons); |
|
| 1039 | - $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1040 | - break; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - return $column_data; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * Add 'Module' columns to Analysis Lesson Overview table |
|
| 1048 | - * |
|
| 1049 | - * @since 1.8.0 |
|
| 1050 | - * |
|
| 1051 | - * @param array $columns Default columns |
|
| 1052 | - * @return array Modified columns |
|
| 1053 | - */ |
|
| 1054 | - public function analysis_overview_column_title($columns) |
|
| 1055 | - { |
|
| 1056 | - |
|
| 1057 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1058 | - $new_columns = array(); |
|
| 1059 | - if (is_array($columns) && 0 < count($columns)) { |
|
| 1060 | - foreach ($columns as $column => $title) { |
|
| 1061 | - $new_columns[$column] = $title; |
|
| 1062 | - if ($column == 'title') { |
|
| 1063 | - $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - if (0 < count($new_columns)) { |
|
| 1069 | - return $new_columns; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $columns; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Data for 'Module' column Analysis Lesson Overview table |
|
| 1078 | - * |
|
| 1079 | - * @since 1.8.0 |
|
| 1080 | - * |
|
| 1081 | - * @param array $columns Table column data |
|
| 1082 | - * @param WP_Post $lesson |
|
| 1083 | - * @return array Updated column data |
|
| 1084 | - */ |
|
| 1085 | - public function analysis_overview_column_data($columns, $lesson ) |
|
| 1086 | - { |
|
| 1087 | - |
|
| 1088 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1089 | - $lesson_module = ''; |
|
| 1090 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1091 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1092 | - foreach ($lesson_module_list as $single_module) { |
|
| 1093 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1094 | - break; |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - $columns['lesson_module'] = $lesson_module; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - return $columns; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Add 'Module' columns to Analysis Course table |
|
| 1106 | - * |
|
| 1107 | - * @since 1.8.0 |
|
| 1108 | - * |
|
| 1109 | - * @param array $columns Default columns |
|
| 1110 | - * @return array Modified columns |
|
| 1111 | - */ |
|
| 1112 | - public function analysis_course_column_title($columns) |
|
| 1113 | - { |
|
| 1114 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1115 | - $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1116 | - } |
|
| 1117 | - return $columns; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * Data for 'Module' column in Analysis Course table |
|
| 1122 | - * |
|
| 1123 | - * @since 1.8.0 |
|
| 1124 | - * |
|
| 1125 | - * @param array $columns Table column data |
|
| 1126 | - * @param WP_Post $lesson |
|
| 1127 | - * @return array Updated columns data |
|
| 1128 | - */ |
|
| 1129 | - public function analysis_course_column_data($columns, $lesson ) |
|
| 1130 | - { |
|
| 1131 | - |
|
| 1132 | - if ( isset( $_GET['course_id'] ) ) { |
|
| 1133 | - $lesson_module = ''; |
|
| 1134 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1135 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1136 | - foreach ($lesson_module_list as $single_module) { |
|
| 1137 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1138 | - break; |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $columns['lesson_module'] = $lesson_module; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - return $columns; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * Get module for lesson |
|
| 1150 | - * |
|
| 1151 | - * This function also checks if the module still |
|
| 1152 | - * exists on the course before returning it. Although |
|
| 1153 | - * the lesson has a module the same module must exist on the |
|
| 1154 | - * course for it to be valid. |
|
| 1155 | - * |
|
| 1156 | - * @since 1.8.0 |
|
| 1157 | - * |
|
| 1158 | - * @param integer $lesson_id ID of lesson |
|
| 1159 | - * @return object Module taxonomy term object |
|
| 1160 | - */ |
|
| 1161 | - public function get_lesson_module($lesson_id = 0) |
|
| 1162 | - { |
|
| 1163 | - $lesson_id = intval($lesson_id); |
|
| 1164 | - if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1165 | - return false; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - // get taxonomy terms on this lesson |
|
| 1169 | - $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
| 1170 | - |
|
| 1171 | - //check if error returned |
|
| 1172 | - if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1173 | - return false; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - // get the last item in the array there should be only be 1 really. |
|
| 1177 | - // this method works for all php versions. |
|
| 1178 | - foreach( $modules as $module ){ |
|
| 1179 | - break; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
| 1183 | - return false; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - $module->url = get_term_link($module, $this->taxonomy); |
|
| 1187 | - $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
| 1188 | - if (isset($course_id) && 0 < $course_id) { |
|
| 1189 | - |
|
| 1190 | - // the course should contain the same module taxonomy term for this to be valid |
|
| 1191 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1192 | - return false; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
| 1196 | - } |
|
| 1197 | - return $module; |
|
| 1198 | - |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * Get ordered array of all modules in course |
|
| 1203 | - * |
|
| 1204 | - * @since 1.8.0 |
|
| 1205 | - * |
|
| 1206 | - * @param integer $course_id ID of course |
|
| 1207 | - * @return array Ordered array of module taxonomy term objects |
|
| 1208 | - */ |
|
| 1209 | - public function get_course_modules($course_id = 0) |
|
| 1210 | - { |
|
| 1211 | - $course_id = intval($course_id); |
|
| 1212 | - if (0 < $course_id) { |
|
| 1213 | - |
|
| 1214 | - // Get modules for course |
|
| 1215 | - $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1216 | - |
|
| 1217 | - // Get custom module order for course |
|
| 1218 | - $order = $this->get_course_module_order($course_id); |
|
| 1219 | - |
|
| 1220 | - // Sort by custom order if custom order exists |
|
| 1221 | - if ($order) { |
|
| 1222 | - $ordered_modules = array(); |
|
| 1223 | - $unordered_modules = array(); |
|
| 1224 | - foreach ($modules as $module) { |
|
| 1225 | - $order_key = array_search($module->term_id, $order); |
|
| 1226 | - if ($order_key !== false) { |
|
| 1227 | - $ordered_modules[$order_key] = $module; |
|
| 1228 | - } else { |
|
| 1229 | - $unordered_modules[] = $module; |
|
| 1230 | - } |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - // Order modules correctly |
|
| 1234 | - ksort($ordered_modules); |
|
| 1235 | - |
|
| 1236 | - // Append modules that have not yet been ordered |
|
| 1237 | - if (count($unordered_modules) > 0) { |
|
| 1238 | - $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - } else { |
|
| 1242 | - |
|
| 1243 | - $ordered_modules = $modules; |
|
| 1244 | - |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - return $ordered_modules; |
|
| 1248 | - |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - return false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Load frontend CSS |
|
| 1256 | - * |
|
| 1257 | - * @since 1.8.0 |
|
| 1258 | - * |
|
| 1259 | - * @return void |
|
| 1260 | - */ |
|
| 1261 | - public function enqueue_styles() |
|
| 1262 | - { |
|
| 1263 | - |
|
| 1264 | - |
|
| 1265 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Load admin Javascript |
|
| 1271 | - * |
|
| 1272 | - * @since 1.8.0 |
|
| 1273 | - * |
|
| 1274 | - * @return void |
|
| 1275 | - */ |
|
| 1276 | - public function admin_enqueue_scripts( $hook ) { |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Filter the page hooks where modules admin script can be loaded on. |
|
| 1280 | - * |
|
| 1281 | - * @param array $white_listed_pages |
|
| 1282 | - */ |
|
| 1283 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | - 'edit-tags.php', |
|
| 1285 | - 'course_page_module-order', |
|
| 1286 | - 'post-new.php', |
|
| 1287 | - 'post.php' |
|
| 1288 | - ) ); |
|
| 1289 | - |
|
| 1290 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1291 | - return; |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | - |
|
| 1296 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | - wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1299 | - |
|
| 1300 | - // localized module data |
|
| 1301 | - $localize_modulesAdmin = array( |
|
| 1302 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1304 | - ); |
|
| 1305 | - |
|
| 1306 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Load admin CSS |
|
| 1311 | - * |
|
| 1312 | - * @since 1.8.0 |
|
| 1313 | - * |
|
| 1314 | - * @return void |
|
| 1315 | - */ |
|
| 1316 | - public function admin_enqueue_styles() { |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1321 | - |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * Show the title modules on the single course template. |
|
| 1326 | - * |
|
| 1327 | - * Function is hooked into sensei_single_course_modules_before. |
|
| 1328 | - * |
|
| 1329 | - * @since 1.8.0 |
|
| 1330 | - * @return void |
|
| 1331 | - */ |
|
| 1332 | - public function course_modules_title( ) { |
|
| 1333 | - |
|
| 1334 | - if( sensei_module_has_lessons() ){ |
|
| 1335 | - |
|
| 1336 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1337 | - |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - /** |
|
| 1343 | - * Display the single course modules content this will only show |
|
| 1344 | - * if the course has modules. |
|
| 1345 | - * |
|
| 1346 | - * @since 1.8.0 |
|
| 1347 | - * @return void |
|
| 1348 | - */ |
|
| 1349 | - public function load_course_module_content_template(){ |
|
| 1350 | - |
|
| 1351 | - // load backwards compatible template name if it exists in the users theme |
|
| 1352 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | - if( $located_template ){ |
|
| 1354 | - |
|
| 1355 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1356 | - return; |
|
| 1357 | - |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1361 | - |
|
| 1362 | - } // end course_module_content |
|
| 1363 | - |
|
| 1364 | - /** |
|
| 1365 | - * Returns all lessons for the given module ID |
|
| 1366 | - * |
|
| 1367 | - * @since 1.8.0 |
|
| 1368 | - * |
|
| 1369 | - * @param $course_id |
|
| 1370 | - * @param $term_id |
|
| 1371 | - * @return array $lessons |
|
| 1372 | - */ |
|
| 1373 | - public function get_lessons( $course_id , $term_id ){ |
|
| 1374 | - |
|
| 1375 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 840 | + $html = ''; |
|
| 841 | + |
|
| 842 | + if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
| 843 | + $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
| 844 | + |
|
| 845 | + if ($ordered) { |
|
| 846 | + $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | + $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | + $html .= '</div>' . "\n"; |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + $courses = Sensei()->course->get_all_courses(); |
|
| 853 | + |
|
| 854 | + $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | + $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | + $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | + $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | + $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 859 | + |
|
| 860 | + foreach ($courses as $course) { |
|
| 861 | + if (has_term('', $this->taxonomy, $course->ID)) { |
|
| 862 | + $course_id = ''; |
|
| 863 | + if (isset($_GET['course_id'])) { |
|
| 864 | + $course_id = intval($_GET['course_id']); |
|
| 865 | + } |
|
| 866 | + $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + $html .= '</select>' . "\n"; |
|
| 871 | + $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | + $html .= '</form>' . "\n"; |
|
| 873 | + |
|
| 874 | + if (isset($_GET['course_id'])) { |
|
| 875 | + $course_id = intval($_GET['course_id']); |
|
| 876 | + if ($course_id > 0) { |
|
| 877 | + $modules = $this->get_course_modules($course_id); |
|
| 878 | + $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 879 | + if ($modules) { |
|
| 880 | + |
|
| 881 | + $order = $this->get_course_module_order($course_id); |
|
| 882 | + |
|
| 883 | + $order_string=''; |
|
| 884 | + if ($order) { |
|
| 885 | + $order_string = implode(',', $order); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | + $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 890 | + $count = 0; |
|
| 891 | + foreach ($modules as $module) { |
|
| 892 | + $count++; |
|
| 893 | + $class = $this->taxonomy; |
|
| 894 | + if ($count == 1) { |
|
| 895 | + $class .= ' first'; |
|
| 896 | + } |
|
| 897 | + if ($count == count($module)) { |
|
| 898 | + $class .= ' last'; |
|
| 899 | + } |
|
| 900 | + if ($count % 2 != 0) { |
|
| 901 | + $class .= ' alternate'; |
|
| 902 | + } |
|
| 903 | + $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 904 | + } |
|
| 905 | + $html .= '</ul>' . "\n"; |
|
| 906 | + |
|
| 907 | + $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | + $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | + $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | + $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + echo $html; |
|
| 916 | + |
|
| 917 | + ?></div><?php |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Add 'Module order' column to courses list table |
|
| 922 | + * |
|
| 923 | + * @since 1.8.0 |
|
| 924 | + * |
|
| 925 | + * @param array $columns Existing columns |
|
| 926 | + * @return array Modifed columns |
|
| 927 | + */ |
|
| 928 | + public function course_columns($columns = array()) |
|
| 929 | + { |
|
| 930 | + $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
| 931 | + return $columns; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * Load content in 'Module order' column |
|
| 936 | + * |
|
| 937 | + * @since 1.8.0 |
|
| 938 | + * |
|
| 939 | + * @param string $column Current column name |
|
| 940 | + * @param integer $course_id ID of course |
|
| 941 | + * @return void |
|
| 942 | + */ |
|
| 943 | + public function course_column_content($column = '', $course_id = 0) |
|
| 944 | + { |
|
| 945 | + if ($column == 'module_order') { |
|
| 946 | + if (has_term('', $this->taxonomy, $course_id)) { |
|
| 947 | + echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * Save module order for course |
|
| 954 | + * |
|
| 955 | + * @since 1.8.0 |
|
| 956 | + * |
|
| 957 | + * @param string $order_string Comma-separated string of module IDs |
|
| 958 | + * @param integer $course_id ID of course |
|
| 959 | + * @return boolean True on success, false on failure |
|
| 960 | + */ |
|
| 961 | + private function save_course_module_order($order_string = '', $course_id = 0) |
|
| 962 | + { |
|
| 963 | + if ($order_string && $course_id) { |
|
| 964 | + $order = explode(',', $order_string); |
|
| 965 | + update_post_meta(intval($course_id), '_module_order', $order); |
|
| 966 | + return true; |
|
| 967 | + } |
|
| 968 | + return false; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Get module order for course |
|
| 973 | + * |
|
| 974 | + * @since 1.8.0 |
|
| 975 | + * |
|
| 976 | + * @param integer $course_id ID of course |
|
| 977 | + * @return mixed Module order on success, false if no module order has been saved |
|
| 978 | + */ |
|
| 979 | + public function get_course_module_order($course_id = 0) |
|
| 980 | + { |
|
| 981 | + if ($course_id) { |
|
| 982 | + $order = get_post_meta(intval($course_id), '_module_order', true); |
|
| 983 | + return $order; |
|
| 984 | + } |
|
| 985 | + return false; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Modify module taxonomy columns |
|
| 990 | + * |
|
| 991 | + * @since 1.8.0 |
|
| 992 | + * |
|
| 993 | + * @param array $columns Default columns |
|
| 994 | + * @return array Modified columns |
|
| 995 | + */ |
|
| 996 | + public function taxonomy_column_headings($columns) |
|
| 997 | + { |
|
| 998 | + |
|
| 999 | + unset($columns['posts']); |
|
| 1000 | + |
|
| 1001 | + $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
| 1002 | + |
|
| 1003 | + return $columns; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Manage content in custom module taxonomy columns |
|
| 1008 | + * |
|
| 1009 | + * @since 1.8.0 |
|
| 1010 | + * |
|
| 1011 | + * @param string $column_data Default data for column |
|
| 1012 | + * @param string $column_name Name of current column |
|
| 1013 | + * @param integer $term_id ID of current term |
|
| 1014 | + * @return string Modified column data |
|
| 1015 | + */ |
|
| 1016 | + public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
| 1017 | + { |
|
| 1018 | + |
|
| 1019 | + $args = array( |
|
| 1020 | + 'post_status' => 'publish', |
|
| 1021 | + 'posts_per_page' => -1, |
|
| 1022 | + 'tax_query' => array( |
|
| 1023 | + array( |
|
| 1024 | + 'taxonomy' => $this->taxonomy, |
|
| 1025 | + 'field' => 'id', |
|
| 1026 | + 'terms' => intval($term_id) |
|
| 1027 | + ) |
|
| 1028 | + ) |
|
| 1029 | + ); |
|
| 1030 | + |
|
| 1031 | + $module = get_term($term_id, $this->taxonomy); |
|
| 1032 | + |
|
| 1033 | + switch ($column_name) { |
|
| 1034 | + |
|
| 1035 | + case 'lessons': |
|
| 1036 | + $args['post_type'] = 'lesson'; |
|
| 1037 | + $lessons = get_posts($args); |
|
| 1038 | + $total_lessons = count($lessons); |
|
| 1039 | + $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1040 | + break; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + return $column_data; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * Add 'Module' columns to Analysis Lesson Overview table |
|
| 1048 | + * |
|
| 1049 | + * @since 1.8.0 |
|
| 1050 | + * |
|
| 1051 | + * @param array $columns Default columns |
|
| 1052 | + * @return array Modified columns |
|
| 1053 | + */ |
|
| 1054 | + public function analysis_overview_column_title($columns) |
|
| 1055 | + { |
|
| 1056 | + |
|
| 1057 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1058 | + $new_columns = array(); |
|
| 1059 | + if (is_array($columns) && 0 < count($columns)) { |
|
| 1060 | + foreach ($columns as $column => $title) { |
|
| 1061 | + $new_columns[$column] = $title; |
|
| 1062 | + if ($column == 'title') { |
|
| 1063 | + $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + if (0 < count($new_columns)) { |
|
| 1069 | + return $new_columns; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $columns; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Data for 'Module' column Analysis Lesson Overview table |
|
| 1078 | + * |
|
| 1079 | + * @since 1.8.0 |
|
| 1080 | + * |
|
| 1081 | + * @param array $columns Table column data |
|
| 1082 | + * @param WP_Post $lesson |
|
| 1083 | + * @return array Updated column data |
|
| 1084 | + */ |
|
| 1085 | + public function analysis_overview_column_data($columns, $lesson ) |
|
| 1086 | + { |
|
| 1087 | + |
|
| 1088 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1089 | + $lesson_module = ''; |
|
| 1090 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1091 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1092 | + foreach ($lesson_module_list as $single_module) { |
|
| 1093 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1094 | + break; |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + $columns['lesson_module'] = $lesson_module; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + return $columns; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Add 'Module' columns to Analysis Course table |
|
| 1106 | + * |
|
| 1107 | + * @since 1.8.0 |
|
| 1108 | + * |
|
| 1109 | + * @param array $columns Default columns |
|
| 1110 | + * @return array Modified columns |
|
| 1111 | + */ |
|
| 1112 | + public function analysis_course_column_title($columns) |
|
| 1113 | + { |
|
| 1114 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1115 | + $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1116 | + } |
|
| 1117 | + return $columns; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * Data for 'Module' column in Analysis Course table |
|
| 1122 | + * |
|
| 1123 | + * @since 1.8.0 |
|
| 1124 | + * |
|
| 1125 | + * @param array $columns Table column data |
|
| 1126 | + * @param WP_Post $lesson |
|
| 1127 | + * @return array Updated columns data |
|
| 1128 | + */ |
|
| 1129 | + public function analysis_course_column_data($columns, $lesson ) |
|
| 1130 | + { |
|
| 1131 | + |
|
| 1132 | + if ( isset( $_GET['course_id'] ) ) { |
|
| 1133 | + $lesson_module = ''; |
|
| 1134 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1135 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1136 | + foreach ($lesson_module_list as $single_module) { |
|
| 1137 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1138 | + break; |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $columns['lesson_module'] = $lesson_module; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + return $columns; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * Get module for lesson |
|
| 1150 | + * |
|
| 1151 | + * This function also checks if the module still |
|
| 1152 | + * exists on the course before returning it. Although |
|
| 1153 | + * the lesson has a module the same module must exist on the |
|
| 1154 | + * course for it to be valid. |
|
| 1155 | + * |
|
| 1156 | + * @since 1.8.0 |
|
| 1157 | + * |
|
| 1158 | + * @param integer $lesson_id ID of lesson |
|
| 1159 | + * @return object Module taxonomy term object |
|
| 1160 | + */ |
|
| 1161 | + public function get_lesson_module($lesson_id = 0) |
|
| 1162 | + { |
|
| 1163 | + $lesson_id = intval($lesson_id); |
|
| 1164 | + if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1165 | + return false; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + // get taxonomy terms on this lesson |
|
| 1169 | + $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
| 1170 | + |
|
| 1171 | + //check if error returned |
|
| 1172 | + if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1173 | + return false; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + // get the last item in the array there should be only be 1 really. |
|
| 1177 | + // this method works for all php versions. |
|
| 1178 | + foreach( $modules as $module ){ |
|
| 1179 | + break; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
| 1183 | + return false; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + $module->url = get_term_link($module, $this->taxonomy); |
|
| 1187 | + $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
| 1188 | + if (isset($course_id) && 0 < $course_id) { |
|
| 1189 | + |
|
| 1190 | + // the course should contain the same module taxonomy term for this to be valid |
|
| 1191 | + if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1192 | + return false; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
| 1196 | + } |
|
| 1197 | + return $module; |
|
| 1198 | + |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * Get ordered array of all modules in course |
|
| 1203 | + * |
|
| 1204 | + * @since 1.8.0 |
|
| 1205 | + * |
|
| 1206 | + * @param integer $course_id ID of course |
|
| 1207 | + * @return array Ordered array of module taxonomy term objects |
|
| 1208 | + */ |
|
| 1209 | + public function get_course_modules($course_id = 0) |
|
| 1210 | + { |
|
| 1211 | + $course_id = intval($course_id); |
|
| 1212 | + if (0 < $course_id) { |
|
| 1213 | + |
|
| 1214 | + // Get modules for course |
|
| 1215 | + $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1216 | + |
|
| 1217 | + // Get custom module order for course |
|
| 1218 | + $order = $this->get_course_module_order($course_id); |
|
| 1219 | + |
|
| 1220 | + // Sort by custom order if custom order exists |
|
| 1221 | + if ($order) { |
|
| 1222 | + $ordered_modules = array(); |
|
| 1223 | + $unordered_modules = array(); |
|
| 1224 | + foreach ($modules as $module) { |
|
| 1225 | + $order_key = array_search($module->term_id, $order); |
|
| 1226 | + if ($order_key !== false) { |
|
| 1227 | + $ordered_modules[$order_key] = $module; |
|
| 1228 | + } else { |
|
| 1229 | + $unordered_modules[] = $module; |
|
| 1230 | + } |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + // Order modules correctly |
|
| 1234 | + ksort($ordered_modules); |
|
| 1235 | + |
|
| 1236 | + // Append modules that have not yet been ordered |
|
| 1237 | + if (count($unordered_modules) > 0) { |
|
| 1238 | + $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + } else { |
|
| 1242 | + |
|
| 1243 | + $ordered_modules = $modules; |
|
| 1244 | + |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + return $ordered_modules; |
|
| 1248 | + |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + return false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Load frontend CSS |
|
| 1256 | + * |
|
| 1257 | + * @since 1.8.0 |
|
| 1258 | + * |
|
| 1259 | + * @return void |
|
| 1260 | + */ |
|
| 1261 | + public function enqueue_styles() |
|
| 1262 | + { |
|
| 1263 | + |
|
| 1264 | + |
|
| 1265 | + wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | + wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Load admin Javascript |
|
| 1271 | + * |
|
| 1272 | + * @since 1.8.0 |
|
| 1273 | + * |
|
| 1274 | + * @return void |
|
| 1275 | + */ |
|
| 1276 | + public function admin_enqueue_scripts( $hook ) { |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Filter the page hooks where modules admin script can be loaded on. |
|
| 1280 | + * |
|
| 1281 | + * @param array $white_listed_pages |
|
| 1282 | + */ |
|
| 1283 | + $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | + 'edit-tags.php', |
|
| 1285 | + 'course_page_module-order', |
|
| 1286 | + 'post-new.php', |
|
| 1287 | + 'post.php' |
|
| 1288 | + ) ); |
|
| 1289 | + |
|
| 1290 | + if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1291 | + return; |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | + |
|
| 1296 | + wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | + wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1299 | + |
|
| 1300 | + // localized module data |
|
| 1301 | + $localize_modulesAdmin = array( |
|
| 1302 | + 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | + 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1304 | + ); |
|
| 1305 | + |
|
| 1306 | + wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Load admin CSS |
|
| 1311 | + * |
|
| 1312 | + * @since 1.8.0 |
|
| 1313 | + * |
|
| 1314 | + * @return void |
|
| 1315 | + */ |
|
| 1316 | + public function admin_enqueue_styles() { |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | + wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1321 | + |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * Show the title modules on the single course template. |
|
| 1326 | + * |
|
| 1327 | + * Function is hooked into sensei_single_course_modules_before. |
|
| 1328 | + * |
|
| 1329 | + * @since 1.8.0 |
|
| 1330 | + * @return void |
|
| 1331 | + */ |
|
| 1332 | + public function course_modules_title( ) { |
|
| 1333 | + |
|
| 1334 | + if( sensei_module_has_lessons() ){ |
|
| 1335 | + |
|
| 1336 | + echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1337 | + |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + /** |
|
| 1343 | + * Display the single course modules content this will only show |
|
| 1344 | + * if the course has modules. |
|
| 1345 | + * |
|
| 1346 | + * @since 1.8.0 |
|
| 1347 | + * @return void |
|
| 1348 | + */ |
|
| 1349 | + public function load_course_module_content_template(){ |
|
| 1350 | + |
|
| 1351 | + // load backwards compatible template name if it exists in the users theme |
|
| 1352 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | + if( $located_template ){ |
|
| 1354 | + |
|
| 1355 | + Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1356 | + return; |
|
| 1357 | + |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1361 | + |
|
| 1362 | + } // end course_module_content |
|
| 1363 | + |
|
| 1364 | + /** |
|
| 1365 | + * Returns all lessons for the given module ID |
|
| 1366 | + * |
|
| 1367 | + * @since 1.8.0 |
|
| 1368 | + * |
|
| 1369 | + * @param $course_id |
|
| 1370 | + * @param $term_id |
|
| 1371 | + * @return array $lessons |
|
| 1372 | + */ |
|
| 1373 | + public function get_lessons( $course_id , $term_id ){ |
|
| 1374 | + |
|
| 1375 | + $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1376 | 1376 | |
| 1377 | - if( isset( $lesson_query->posts ) ){ |
|
| 1377 | + if( isset( $lesson_query->posts ) ){ |
|
| 1378 | 1378 | |
| 1379 | - return $lesson_query->posts; |
|
| 1379 | + return $lesson_query->posts; |
|
| 1380 | 1380 | |
| 1381 | - }else{ |
|
| 1381 | + }else{ |
|
| 1382 | 1382 | |
| 1383 | - return array(); |
|
| 1383 | + return array(); |
|
| 1384 | 1384 | |
| 1385 | - } |
|
| 1385 | + } |
|
| 1386 | 1386 | |
| 1387 | - } // end get lessons |
|
| 1387 | + } // end get lessons |
|
| 1388 | 1388 | |
| 1389 | - /** |
|
| 1390 | - * Returns all lessons for the given module ID |
|
| 1391 | - * |
|
| 1392 | - * @since 1.8.0 |
|
| 1393 | - * |
|
| 1394 | - * @param $course_id |
|
| 1395 | - * @param $term_id |
|
| 1396 | - * @return WP_Query $lessons_query |
|
| 1397 | - */ |
|
| 1398 | - public function get_lessons_query( $course_id , $term_id ){ |
|
| 1399 | - |
|
| 1400 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1401 | - |
|
| 1402 | - return array(); |
|
| 1403 | - |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - $args = array( |
|
| 1407 | - 'post_type' => 'lesson', |
|
| 1408 | - 'post_status' => 'publish', |
|
| 1409 | - 'posts_per_page' => -1, |
|
| 1410 | - 'meta_query' => array( |
|
| 1411 | - array( |
|
| 1412 | - 'key' => '_lesson_course', |
|
| 1413 | - 'value' => intval($course_id), |
|
| 1414 | - 'compare' => '=' |
|
| 1415 | - ) |
|
| 1416 | - ), |
|
| 1417 | - 'tax_query' => array( |
|
| 1418 | - array( |
|
| 1419 | - 'taxonomy' => 'module', |
|
| 1420 | - 'field' => 'id', |
|
| 1421 | - 'terms' => intval( $term_id ) |
|
| 1422 | - ) |
|
| 1423 | - ), |
|
| 1424 | - 'orderby' => 'menu_order', |
|
| 1425 | - 'order' => 'ASC', |
|
| 1426 | - 'suppress_filters' => 0 |
|
| 1427 | - ); |
|
| 1428 | - |
|
| 1429 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1431 | - $args['orderby'] = 'meta_value_num date'; |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - $lessons_query = new WP_Query( $args ); |
|
| 1435 | - |
|
| 1436 | - return $lessons_query; |
|
| 1437 | - |
|
| 1438 | - } // end get lessons |
|
| 1439 | - |
|
| 1440 | - /** |
|
| 1441 | - * Find the lesson in the given course that doesn't belong |
|
| 1442 | - * to any of the courses modules |
|
| 1443 | - * |
|
| 1444 | - * |
|
| 1445 | - * @param $course_id |
|
| 1446 | - * |
|
| 1447 | - * @return array $non_module_lessons |
|
| 1448 | - */ |
|
| 1449 | - public function get_none_module_lessons( $course_id ){ |
|
| 1450 | - |
|
| 1451 | - $non_module_lessons = array(); |
|
| 1452 | - |
|
| 1453 | - //exit if there is no course id passed in |
|
| 1454 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1455 | - |
|
| 1456 | - return $non_module_lessons; |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - //save some time and check if we already have the saved |
|
| 1460 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1461 | - |
|
| 1462 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1463 | - |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - // create terms array which must be excluded from other arrays |
|
| 1467 | - $course_modules = $this->get_course_modules( $course_id ); |
|
| 1468 | - |
|
| 1469 | - //exit if there are no module on this course |
|
| 1470 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1471 | - |
|
| 1472 | - return Sensei()->course->course_lessons( $course_id ); |
|
| 1473 | - |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - $terms = array(); |
|
| 1477 | - foreach( $course_modules as $module ){ |
|
| 1478 | - |
|
| 1479 | - array_push( $terms , $module->term_id ); |
|
| 1480 | - |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $args = array( |
|
| 1484 | - 'post_type' => 'lesson', |
|
| 1485 | - 'post_status' => 'publish', |
|
| 1486 | - 'posts_per_page' => -1, |
|
| 1487 | - 'meta_query' => array( |
|
| 1488 | - array( |
|
| 1489 | - 'key' => '_lesson_course', |
|
| 1490 | - 'value' => intval( $course_id ), |
|
| 1491 | - 'compare' => '=' |
|
| 1492 | - ) |
|
| 1493 | - ), |
|
| 1494 | - 'tax_query' => array( |
|
| 1495 | - array( |
|
| 1496 | - 'taxonomy' => 'module', |
|
| 1497 | - 'field' => 'id', |
|
| 1498 | - 'terms' => $terms, |
|
| 1499 | - 'operator' => 'NOT IN' |
|
| 1500 | - ) |
|
| 1501 | - ), |
|
| 1502 | - 'orderby' => 'menu_order', |
|
| 1503 | - 'order' => 'ASC', |
|
| 1504 | - 'suppress_filters' => 0 |
|
| 1505 | - ); |
|
| 1506 | - |
|
| 1507 | - $wp_lessons_query = new WP_Query( $args ); |
|
| 1508 | - |
|
| 1509 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1510 | - $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1511 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - return $non_module_lessons; |
|
| 1515 | - } // end get_none_module_lessons |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Register the modules taxonomy |
|
| 1519 | - * |
|
| 1520 | - * @since 1.8.0 |
|
| 1521 | - */ |
|
| 1522 | - public function setup_modules_taxonomy(){ |
|
| 1523 | - |
|
| 1524 | - $labels = array( |
|
| 1525 | - 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1526 | - 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1527 | - 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1528 | - 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1529 | - 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1530 | - 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1531 | - 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1532 | - 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1533 | - 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1534 | - 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1535 | - 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | - ); |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * Filter to alter the Sensei Modules rewrite slug |
|
| 1540 | - * |
|
| 1541 | - * @since 1.8.0 |
|
| 1542 | - * @param string default 'modules' |
|
| 1543 | - */ |
|
| 1544 | - $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1545 | - |
|
| 1546 | - $args = array( |
|
| 1547 | - 'public' => true, |
|
| 1548 | - 'hierarchical' => true, |
|
| 1549 | - 'show_admin_column' => true, |
|
| 1550 | - 'capabilities' => array( |
|
| 1551 | - 'manage_terms' => 'manage_categories', |
|
| 1552 | - 'edit_terms' => 'edit_courses', |
|
| 1553 | - 'delete_terms' => 'manage_categories', |
|
| 1554 | - 'assign_terms' => 'edit_courses' |
|
| 1555 | - ), |
|
| 1556 | - 'show_in_nav_menus' => false, |
|
| 1557 | - 'show_in_quick_edit' => false, |
|
| 1558 | - 'show_ui' => true, |
|
| 1559 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1560 | - 'labels' => $labels |
|
| 1561 | - ); |
|
| 1562 | - |
|
| 1563 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1564 | - |
|
| 1565 | - }// end setup_modules_taxonomy |
|
| 1566 | - |
|
| 1567 | - /** |
|
| 1568 | - * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1569 | - * |
|
| 1570 | - * This function is hooked into the admin_menu |
|
| 1571 | - * |
|
| 1572 | - * @since 1.8.0 |
|
| 1573 | - * @return void |
|
| 1574 | - */ |
|
| 1575 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1576 | - |
|
| 1577 | - global $typenow , $taxnow; |
|
| 1578 | - |
|
| 1579 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - }// end redirect to course taxonomy |
|
| 1584 | - |
|
| 1585 | - /** |
|
| 1586 | - * Completely remove the module menu item under lessons. |
|
| 1587 | - * |
|
| 1588 | - * This function is hooked into the admin_menu |
|
| 1589 | - * |
|
| 1590 | - * @since 1.8.0 |
|
| 1591 | - * @return void |
|
| 1592 | - */ |
|
| 1593 | - public function remove_lessons_menu_model_taxonomy(){ |
|
| 1594 | - global $submenu; |
|
| 1595 | - |
|
| 1596 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1597 | - return; // exit |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1601 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1602 | - |
|
| 1603 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1605 | - } |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - }// end remove lesson module tax |
|
| 1609 | - |
|
| 1610 | - /** |
|
| 1611 | - * Completely remove the second modules under courses |
|
| 1612 | - * |
|
| 1613 | - * This function is hooked into the admin_menu |
|
| 1614 | - * |
|
| 1615 | - * @since 1.8.0 |
|
| 1616 | - * @return void |
|
| 1617 | - */ |
|
| 1618 | - public function remove_courses_menu_model_taxonomy(){ |
|
| 1619 | - global $submenu; |
|
| 1620 | - |
|
| 1621 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1622 | - return; // exit |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1626 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1627 | - |
|
| 1628 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1630 | - } |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - }// end remove courses module tax |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * Determine the author of a module term term by looking at |
|
| 1637 | - * the prefixed author id. This function will query the full term object. |
|
| 1638 | - * Will return the admin user author could not be determined. |
|
| 1639 | - * |
|
| 1640 | - * @since 1.8.0 |
|
| 1641 | - * |
|
| 1642 | - * @param string $term_name |
|
| 1643 | - * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1644 | - */ |
|
| 1645 | - public static function get_term_authors( $term_name ){ |
|
| 1646 | - |
|
| 1647 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1648 | - |
|
| 1649 | - $owners = array(); |
|
| 1650 | - if( empty( $terms ) ){ |
|
| 1651 | - |
|
| 1652 | - return $owners; |
|
| 1389 | + /** |
|
| 1390 | + * Returns all lessons for the given module ID |
|
| 1391 | + * |
|
| 1392 | + * @since 1.8.0 |
|
| 1393 | + * |
|
| 1394 | + * @param $course_id |
|
| 1395 | + * @param $term_id |
|
| 1396 | + * @return WP_Query $lessons_query |
|
| 1397 | + */ |
|
| 1398 | + public function get_lessons_query( $course_id , $term_id ){ |
|
| 1399 | + |
|
| 1400 | + if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1401 | + |
|
| 1402 | + return array(); |
|
| 1403 | + |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + $args = array( |
|
| 1407 | + 'post_type' => 'lesson', |
|
| 1408 | + 'post_status' => 'publish', |
|
| 1409 | + 'posts_per_page' => -1, |
|
| 1410 | + 'meta_query' => array( |
|
| 1411 | + array( |
|
| 1412 | + 'key' => '_lesson_course', |
|
| 1413 | + 'value' => intval($course_id), |
|
| 1414 | + 'compare' => '=' |
|
| 1415 | + ) |
|
| 1416 | + ), |
|
| 1417 | + 'tax_query' => array( |
|
| 1418 | + array( |
|
| 1419 | + 'taxonomy' => 'module', |
|
| 1420 | + 'field' => 'id', |
|
| 1421 | + 'terms' => intval( $term_id ) |
|
| 1422 | + ) |
|
| 1423 | + ), |
|
| 1424 | + 'orderby' => 'menu_order', |
|
| 1425 | + 'order' => 'ASC', |
|
| 1426 | + 'suppress_filters' => 0 |
|
| 1427 | + ); |
|
| 1428 | + |
|
| 1429 | + if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | + $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1431 | + $args['orderby'] = 'meta_value_num date'; |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + $lessons_query = new WP_Query( $args ); |
|
| 1435 | + |
|
| 1436 | + return $lessons_query; |
|
| 1437 | + |
|
| 1438 | + } // end get lessons |
|
| 1439 | + |
|
| 1440 | + /** |
|
| 1441 | + * Find the lesson in the given course that doesn't belong |
|
| 1442 | + * to any of the courses modules |
|
| 1443 | + * |
|
| 1444 | + * |
|
| 1445 | + * @param $course_id |
|
| 1446 | + * |
|
| 1447 | + * @return array $non_module_lessons |
|
| 1448 | + */ |
|
| 1449 | + public function get_none_module_lessons( $course_id ){ |
|
| 1450 | + |
|
| 1451 | + $non_module_lessons = array(); |
|
| 1452 | + |
|
| 1453 | + //exit if there is no course id passed in |
|
| 1454 | + if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1455 | + |
|
| 1456 | + return $non_module_lessons; |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + //save some time and check if we already have the saved |
|
| 1460 | + if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1461 | + |
|
| 1462 | + return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1463 | + |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + // create terms array which must be excluded from other arrays |
|
| 1467 | + $course_modules = $this->get_course_modules( $course_id ); |
|
| 1468 | + |
|
| 1469 | + //exit if there are no module on this course |
|
| 1470 | + if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1471 | + |
|
| 1472 | + return Sensei()->course->course_lessons( $course_id ); |
|
| 1473 | + |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + $terms = array(); |
|
| 1477 | + foreach( $course_modules as $module ){ |
|
| 1478 | + |
|
| 1479 | + array_push( $terms , $module->term_id ); |
|
| 1480 | + |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + $args = array( |
|
| 1484 | + 'post_type' => 'lesson', |
|
| 1485 | + 'post_status' => 'publish', |
|
| 1486 | + 'posts_per_page' => -1, |
|
| 1487 | + 'meta_query' => array( |
|
| 1488 | + array( |
|
| 1489 | + 'key' => '_lesson_course', |
|
| 1490 | + 'value' => intval( $course_id ), |
|
| 1491 | + 'compare' => '=' |
|
| 1492 | + ) |
|
| 1493 | + ), |
|
| 1494 | + 'tax_query' => array( |
|
| 1495 | + array( |
|
| 1496 | + 'taxonomy' => 'module', |
|
| 1497 | + 'field' => 'id', |
|
| 1498 | + 'terms' => $terms, |
|
| 1499 | + 'operator' => 'NOT IN' |
|
| 1500 | + ) |
|
| 1501 | + ), |
|
| 1502 | + 'orderby' => 'menu_order', |
|
| 1503 | + 'order' => 'ASC', |
|
| 1504 | + 'suppress_filters' => 0 |
|
| 1505 | + ); |
|
| 1506 | + |
|
| 1507 | + $wp_lessons_query = new WP_Query( $args ); |
|
| 1508 | + |
|
| 1509 | + if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1510 | + $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1511 | + set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + return $non_module_lessons; |
|
| 1515 | + } // end get_none_module_lessons |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Register the modules taxonomy |
|
| 1519 | + * |
|
| 1520 | + * @since 1.8.0 |
|
| 1521 | + */ |
|
| 1522 | + public function setup_modules_taxonomy(){ |
|
| 1523 | + |
|
| 1524 | + $labels = array( |
|
| 1525 | + 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1526 | + 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1527 | + 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1528 | + 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1529 | + 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1530 | + 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1531 | + 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1532 | + 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1533 | + 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1534 | + 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1535 | + 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | + ); |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * Filter to alter the Sensei Modules rewrite slug |
|
| 1540 | + * |
|
| 1541 | + * @since 1.8.0 |
|
| 1542 | + * @param string default 'modules' |
|
| 1543 | + */ |
|
| 1544 | + $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1545 | + |
|
| 1546 | + $args = array( |
|
| 1547 | + 'public' => true, |
|
| 1548 | + 'hierarchical' => true, |
|
| 1549 | + 'show_admin_column' => true, |
|
| 1550 | + 'capabilities' => array( |
|
| 1551 | + 'manage_terms' => 'manage_categories', |
|
| 1552 | + 'edit_terms' => 'edit_courses', |
|
| 1553 | + 'delete_terms' => 'manage_categories', |
|
| 1554 | + 'assign_terms' => 'edit_courses' |
|
| 1555 | + ), |
|
| 1556 | + 'show_in_nav_menus' => false, |
|
| 1557 | + 'show_in_quick_edit' => false, |
|
| 1558 | + 'show_ui' => true, |
|
| 1559 | + 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1560 | + 'labels' => $labels |
|
| 1561 | + ); |
|
| 1562 | + |
|
| 1563 | + register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1564 | + |
|
| 1565 | + }// end setup_modules_taxonomy |
|
| 1566 | + |
|
| 1567 | + /** |
|
| 1568 | + * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1569 | + * |
|
| 1570 | + * This function is hooked into the admin_menu |
|
| 1571 | + * |
|
| 1572 | + * @since 1.8.0 |
|
| 1573 | + * @return void |
|
| 1574 | + */ |
|
| 1575 | + function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1576 | + |
|
| 1577 | + global $typenow , $taxnow; |
|
| 1578 | + |
|
| 1579 | + if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | + wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + }// end redirect to course taxonomy |
|
| 1584 | + |
|
| 1585 | + /** |
|
| 1586 | + * Completely remove the module menu item under lessons. |
|
| 1587 | + * |
|
| 1588 | + * This function is hooked into the admin_menu |
|
| 1589 | + * |
|
| 1590 | + * @since 1.8.0 |
|
| 1591 | + * @return void |
|
| 1592 | + */ |
|
| 1593 | + public function remove_lessons_menu_model_taxonomy(){ |
|
| 1594 | + global $submenu; |
|
| 1595 | + |
|
| 1596 | + if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1597 | + return; // exit |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1601 | + foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1602 | + |
|
| 1603 | + if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | + unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1605 | + } |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + }// end remove lesson module tax |
|
| 1609 | + |
|
| 1610 | + /** |
|
| 1611 | + * Completely remove the second modules under courses |
|
| 1612 | + * |
|
| 1613 | + * This function is hooked into the admin_menu |
|
| 1614 | + * |
|
| 1615 | + * @since 1.8.0 |
|
| 1616 | + * @return void |
|
| 1617 | + */ |
|
| 1618 | + public function remove_courses_menu_model_taxonomy(){ |
|
| 1619 | + global $submenu; |
|
| 1620 | + |
|
| 1621 | + if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1622 | + return; // exit |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1626 | + foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1627 | + |
|
| 1628 | + if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | + unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1630 | + } |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + }// end remove courses module tax |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * Determine the author of a module term term by looking at |
|
| 1637 | + * the prefixed author id. This function will query the full term object. |
|
| 1638 | + * Will return the admin user author could not be determined. |
|
| 1639 | + * |
|
| 1640 | + * @since 1.8.0 |
|
| 1641 | + * |
|
| 1642 | + * @param string $term_name |
|
| 1643 | + * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1644 | + */ |
|
| 1645 | + public static function get_term_authors( $term_name ){ |
|
| 1646 | + |
|
| 1647 | + $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1648 | + |
|
| 1649 | + $owners = array(); |
|
| 1650 | + if( empty( $terms ) ){ |
|
| 1651 | + |
|
| 1652 | + return $owners; |
|
| 1653 | 1653 | |
| 1654 | - } |
|
| 1654 | + } |
|
| 1655 | 1655 | |
| 1656 | - // setup the admin user |
|
| 1656 | + // setup the admin user |
|
| 1657 | 1657 | |
| 1658 | 1658 | |
| 1659 | - //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1660 | - foreach( $terms as $term){ |
|
| 1661 | - if( $term->name == $term_name ){ |
|
| 1659 | + //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1660 | + foreach( $terms as $term){ |
|
| 1661 | + if( $term->name == $term_name ){ |
|
| 1662 | 1662 | |
| 1663 | - // look for the author in the slug |
|
| 1664 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1663 | + // look for the author in the slug |
|
| 1664 | + $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1665 | 1665 | |
| 1666 | - }// end if term name |
|
| 1666 | + }// end if term name |
|
| 1667 | 1667 | |
| 1668 | - } // end for each |
|
| 1668 | + } // end for each |
|
| 1669 | 1669 | |
| 1670 | - return $owners; |
|
| 1670 | + return $owners; |
|
| 1671 | 1671 | |
| 1672 | - }// end get_term_author |
|
| 1672 | + }// end get_term_author |
|
| 1673 | 1673 | |
| 1674 | - /** |
|
| 1675 | - * Looks at a term slug and figures out |
|
| 1676 | - * which author created the slug. The author was |
|
| 1677 | - * appended when the user saved the module term in the course edit |
|
| 1678 | - * screen. |
|
| 1679 | - * |
|
| 1680 | - * @since 1.8.0 |
|
| 1681 | - * |
|
| 1682 | - * @param $slug |
|
| 1683 | - * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1684 | - */ |
|
| 1685 | - public static function get_term_author( $slug='' ){ |
|
| 1674 | + /** |
|
| 1675 | + * Looks at a term slug and figures out |
|
| 1676 | + * which author created the slug. The author was |
|
| 1677 | + * appended when the user saved the module term in the course edit |
|
| 1678 | + * screen. |
|
| 1679 | + * |
|
| 1680 | + * @since 1.8.0 |
|
| 1681 | + * |
|
| 1682 | + * @param $slug |
|
| 1683 | + * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1684 | + */ |
|
| 1685 | + public static function get_term_author( $slug='' ){ |
|
| 1686 | 1686 | |
| 1687 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1687 | + $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1688 | 1688 | |
| 1689 | - if( empty( $slug ) ){ |
|
| 1689 | + if( empty( $slug ) ){ |
|
| 1690 | 1690 | |
| 1691 | - return $term_owner; |
|
| 1691 | + return $term_owner; |
|
| 1692 | 1692 | |
| 1693 | - } |
|
| 1693 | + } |
|
| 1694 | 1694 | |
| 1695 | - // look for the author in the slug |
|
| 1696 | - $slug_parts = explode( '-', $slug ); |
|
| 1695 | + // look for the author in the slug |
|
| 1696 | + $slug_parts = explode( '-', $slug ); |
|
| 1697 | 1697 | |
| 1698 | - if( count( $slug_parts ) > 1 ){ |
|
| 1698 | + if( count( $slug_parts ) > 1 ){ |
|
| 1699 | 1699 | |
| 1700 | - // get the user data |
|
| 1701 | - $possible_user_id = $slug_parts[0]; |
|
| 1702 | - $author = get_userdata( $possible_user_id ); |
|
| 1700 | + // get the user data |
|
| 1701 | + $possible_user_id = $slug_parts[0]; |
|
| 1702 | + $author = get_userdata( $possible_user_id ); |
|
| 1703 | 1703 | |
| 1704 | - // if the user doesnt exist for the first part of the slug |
|
| 1705 | - // then this slug was also created by admin |
|
| 1706 | - if( is_a( $author, 'WP_User' ) ){ |
|
| 1704 | + // if the user doesnt exist for the first part of the slug |
|
| 1705 | + // then this slug was also created by admin |
|
| 1706 | + if( is_a( $author, 'WP_User' ) ){ |
|
| 1707 | 1707 | |
| 1708 | - $term_owner = $author; |
|
| 1708 | + $term_owner = $author; |
|
| 1709 | 1709 | |
| 1710 | - } |
|
| 1711 | - } |
|
| 1710 | + } |
|
| 1711 | + } |
|
| 1712 | 1712 | |
| 1713 | - return $term_owner; |
|
| 1714 | - } |
|
| 1713 | + return $term_owner; |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - /** |
|
| 1717 | - * Display the Sensei modules taxonomy terms metabox |
|
| 1718 | - * |
|
| 1719 | - * @since 1.8.0 |
|
| 1720 | - * |
|
| 1721 | - * @hooked into add_meta_box |
|
| 1722 | - * |
|
| 1723 | - * @param WP_Post $post Post object. |
|
| 1724 | - */ |
|
| 1725 | - public function course_module_metabox( $post ) { |
|
| 1716 | + /** |
|
| 1717 | + * Display the Sensei modules taxonomy terms metabox |
|
| 1718 | + * |
|
| 1719 | + * @since 1.8.0 |
|
| 1720 | + * |
|
| 1721 | + * @hooked into add_meta_box |
|
| 1722 | + * |
|
| 1723 | + * @param WP_Post $post Post object. |
|
| 1724 | + */ |
|
| 1725 | + public function course_module_metabox( $post ) { |
|
| 1726 | 1726 | |
| 1727 | - $tax_name = 'module'; |
|
| 1728 | - $taxonomy = get_taxonomy( 'module' ); |
|
| 1727 | + $tax_name = 'module'; |
|
| 1728 | + $taxonomy = get_taxonomy( 'module' ); |
|
| 1729 | 1729 | |
| 1730 | - ?> |
|
| 1730 | + ?> |
|
| 1731 | 1731 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 1732 | 1732 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 1733 | 1733 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
@@ -1742,9 +1742,9 @@ discard block |
||
| 1742 | 1742 | |
| 1743 | 1743 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
| 1744 | 1744 | <?php |
| 1745 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1746 | - echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 1747 | - ?> |
|
| 1745 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1746 | + echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 1747 | + ?> |
|
| 1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
| 1749 | 1749 | <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
| 1750 | 1750 | </ul> |
@@ -1754,9 +1754,9 @@ discard block |
||
| 1754 | 1754 | <h4> |
| 1755 | 1755 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
| 1756 | 1756 | <?php |
| 1757 | - /* translators: %s: add new taxonomy label */ |
|
| 1758 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1759 | - ?> |
|
| 1757 | + /* translators: %s: add new taxonomy label */ |
|
| 1758 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1759 | + ?> |
|
| 1760 | 1760 | </a> |
| 1761 | 1761 | </h4> |
| 1762 | 1762 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -1771,331 +1771,331 @@ discard block |
||
| 1771 | 1771 | </div> |
| 1772 | 1772 | <?php |
| 1773 | 1773 | |
| 1774 | - } // end course_module_metabox |
|
| 1774 | + } // end course_module_metabox |
|
| 1775 | 1775 | |
| 1776 | 1776 | |
| 1777 | - /** |
|
| 1778 | - * Submits a new module term prefixed with the |
|
| 1779 | - * the current author id. |
|
| 1780 | - * |
|
| 1781 | - * @since 1.8.0 |
|
| 1782 | - */ |
|
| 1783 | - public static function add_new_module_term( ) { |
|
| 1777 | + /** |
|
| 1778 | + * Submits a new module term prefixed with the |
|
| 1779 | + * the current author id. |
|
| 1780 | + * |
|
| 1781 | + * @since 1.8.0 |
|
| 1782 | + */ |
|
| 1783 | + public static function add_new_module_term( ) { |
|
| 1784 | 1784 | |
| 1785 | 1785 | |
| 1786 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1788 | - } |
|
| 1786 | + if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | + wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1788 | + } |
|
| 1789 | 1789 | |
| 1790 | - // get the term an create the new term storing infomration |
|
| 1791 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1790 | + // get the term an create the new term storing infomration |
|
| 1791 | + $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1792 | 1792 | |
| 1793 | - if( current_user_can('manage_options' ) ) { |
|
| 1793 | + if( current_user_can('manage_options' ) ) { |
|
| 1794 | 1794 | |
| 1795 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1795 | + $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1796 | 1796 | |
| 1797 | - } else { |
|
| 1797 | + } else { |
|
| 1798 | 1798 | |
| 1799 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1799 | + $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1800 | 1800 | |
| 1801 | - } |
|
| 1801 | + } |
|
| 1802 | 1802 | |
| 1803 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1803 | + $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1804 | 1804 | |
| 1805 | - // save the term |
|
| 1806 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1805 | + // save the term |
|
| 1806 | + $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1807 | 1807 | |
| 1808 | - // send error for all errors except term exits |
|
| 1809 | - if( is_wp_error( $slug ) ){ |
|
| 1808 | + // send error for all errors except term exits |
|
| 1809 | + if( is_wp_error( $slug ) ){ |
|
| 1810 | 1810 | |
| 1811 | - // prepare for possible term name and id to be passed down if term exists |
|
| 1812 | - $term_data = array(); |
|
| 1811 | + // prepare for possible term name and id to be passed down if term exists |
|
| 1812 | + $term_data = array(); |
|
| 1813 | 1813 | |
| 1814 | - // if term exists also send back the term name and id |
|
| 1815 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1814 | + // if term exists also send back the term name and id |
|
| 1815 | + if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1816 | 1816 | |
| 1817 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1818 | - $term_data['name'] = $term_name; |
|
| 1819 | - $term_data['id'] = $term->term_id; |
|
| 1817 | + $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1818 | + $term_data['name'] = $term_name; |
|
| 1819 | + $term_data['id'] = $term->term_id; |
|
| 1820 | 1820 | |
| 1821 | - // set the object terms |
|
| 1822 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1823 | - } |
|
| 1821 | + // set the object terms |
|
| 1822 | + wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1823 | + } |
|
| 1824 | 1824 | |
| 1825 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1825 | + wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1826 | 1826 | |
| 1827 | - } |
|
| 1827 | + } |
|
| 1828 | 1828 | |
| 1829 | - //make sure the new term is checked for this course |
|
| 1829 | + //make sure the new term is checked for this course |
|
| 1830 | 1830 | |
| 1831 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1831 | + wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1832 | 1832 | |
| 1833 | - // Handle request then generate response using WP_Ajax_Response |
|
| 1834 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1833 | + // Handle request then generate response using WP_Ajax_Response |
|
| 1834 | + wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1835 | 1835 | |
| 1836 | - } |
|
| 1836 | + } |
|
| 1837 | 1837 | |
| 1838 | - /** |
|
| 1839 | - * Limit the course module metabox |
|
| 1840 | - * term list to only those on courses belonging to current teacher. |
|
| 1841 | - * |
|
| 1842 | - * Hooked into 'get_terms' |
|
| 1843 | - * |
|
| 1844 | - * @since 1.8.0 |
|
| 1845 | - */ |
|
| 1846 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1838 | + /** |
|
| 1839 | + * Limit the course module metabox |
|
| 1840 | + * term list to only those on courses belonging to current teacher. |
|
| 1841 | + * |
|
| 1842 | + * Hooked into 'get_terms' |
|
| 1843 | + * |
|
| 1844 | + * @since 1.8.0 |
|
| 1845 | + */ |
|
| 1846 | + public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1847 | 1847 | |
| 1848 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1849 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1850 | - return $terms; |
|
| 1851 | - } |
|
| 1848 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1849 | + if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1850 | + return $terms; |
|
| 1851 | + } |
|
| 1852 | 1852 | |
| 1853 | - // avoid infinite call loop |
|
| 1854 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1853 | + // avoid infinite call loop |
|
| 1854 | + remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1855 | 1855 | |
| 1856 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1857 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1858 | - // change only scrub the terms ids form the array keys |
|
| 1859 | - $terms = array_keys( $terms ); |
|
| 1860 | - } |
|
| 1856 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1857 | + if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1858 | + // change only scrub the terms ids form the array keys |
|
| 1859 | + $terms = array_keys( $terms ); |
|
| 1860 | + } |
|
| 1861 | 1861 | |
| 1862 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1862 | + $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1863 | 1863 | |
| 1864 | - // add filter again as removed above |
|
| 1865 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1864 | + // add filter again as removed above |
|
| 1865 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1866 | 1866 | |
| 1867 | - return $teachers_terms; |
|
| 1868 | - }// end filter_module_terms |
|
| 1867 | + return $teachers_terms; |
|
| 1868 | + }// end filter_module_terms |
|
| 1869 | 1869 | |
| 1870 | - /** |
|
| 1871 | - * For the selected items on a course module only return those |
|
| 1872 | - * for the current user. This does not apply to admin and super admin users. |
|
| 1873 | - * |
|
| 1874 | - * hooked into get_object_terms |
|
| 1875 | - * |
|
| 1876 | - * @since 1.8.0 |
|
| 1877 | - */ |
|
| 1878 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1870 | + /** |
|
| 1871 | + * For the selected items on a course module only return those |
|
| 1872 | + * for the current user. This does not apply to admin and super admin users. |
|
| 1873 | + * |
|
| 1874 | + * hooked into get_object_terms |
|
| 1875 | + * |
|
| 1876 | + * @since 1.8.0 |
|
| 1877 | + */ |
|
| 1878 | + public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1879 | 1879 | |
| 1880 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1881 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1882 | - // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1883 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1884 | - return $terms; |
|
| 1885 | - } |
|
| 1880 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1881 | + if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1882 | + // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1883 | + || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1884 | + return $terms; |
|
| 1885 | + } |
|
| 1886 | 1886 | |
| 1887 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1887 | + $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1888 | 1888 | |
| 1889 | - // if term objects were passed in send back objects |
|
| 1890 | - // if term id were passed in send that back |
|
| 1891 | - if( is_object( $terms[0] ) ){ |
|
| 1892 | - return $term_objects; |
|
| 1893 | - } |
|
| 1889 | + // if term objects were passed in send back objects |
|
| 1890 | + // if term id were passed in send that back |
|
| 1891 | + if( is_object( $terms[0] ) ){ |
|
| 1892 | + return $term_objects; |
|
| 1893 | + } |
|
| 1894 | 1894 | |
| 1895 | - $terms = array(); |
|
| 1896 | - foreach( $term_objects as $term_object ){ |
|
| 1897 | - $terms[] = $term_object->term_id; |
|
| 1898 | - } |
|
| 1895 | + $terms = array(); |
|
| 1896 | + foreach( $term_objects as $term_object ){ |
|
| 1897 | + $terms[] = $term_object->term_id; |
|
| 1898 | + } |
|
| 1899 | 1899 | |
| 1900 | - return $terms; |
|
| 1900 | + return $terms; |
|
| 1901 | 1901 | |
| 1902 | 1902 | |
| 1903 | - }// end filter_course_selected_terms |
|
| 1903 | + }// end filter_course_selected_terms |
|
| 1904 | 1904 | |
| 1905 | - /** |
|
| 1906 | - * Filter the given terms and only return the |
|
| 1907 | - * terms that belong to the given user id. |
|
| 1908 | - * |
|
| 1909 | - * @since 1.8.0 |
|
| 1910 | - * @param $terms |
|
| 1911 | - * @param $user_id |
|
| 1912 | - * @return array |
|
| 1913 | - */ |
|
| 1914 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1905 | + /** |
|
| 1906 | + * Filter the given terms and only return the |
|
| 1907 | + * terms that belong to the given user id. |
|
| 1908 | + * |
|
| 1909 | + * @since 1.8.0 |
|
| 1910 | + * @param $terms |
|
| 1911 | + * @param $user_id |
|
| 1912 | + * @return array |
|
| 1913 | + */ |
|
| 1914 | + public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1915 | 1915 | |
| 1916 | - $users_terms = array(); |
|
| 1916 | + $users_terms = array(); |
|
| 1917 | 1917 | |
| 1918 | - foreach( $terms as $index => $term ){ |
|
| 1918 | + foreach( $terms as $index => $term ){ |
|
| 1919 | 1919 | |
| 1920 | - if( is_numeric( $term ) ){ |
|
| 1921 | - // the term id was given, get the term object |
|
| 1922 | - $term = get_term( $term, 'module' ); |
|
| 1923 | - } |
|
| 1920 | + if( is_numeric( $term ) ){ |
|
| 1921 | + // the term id was given, get the term object |
|
| 1922 | + $term = get_term( $term, 'module' ); |
|
| 1923 | + } |
|
| 1924 | 1924 | |
| 1925 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1925 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1926 | 1926 | |
| 1927 | - if ( $user_id == $author->ID ) { |
|
| 1928 | - // add the term to the teachers terms |
|
| 1929 | - $users_terms[] = $term; |
|
| 1930 | - } |
|
| 1927 | + if ( $user_id == $author->ID ) { |
|
| 1928 | + // add the term to the teachers terms |
|
| 1929 | + $users_terms[] = $term; |
|
| 1930 | + } |
|
| 1931 | 1931 | |
| 1932 | - } |
|
| 1932 | + } |
|
| 1933 | 1933 | |
| 1934 | - return $users_terms; |
|
| 1934 | + return $users_terms; |
|
| 1935 | 1935 | |
| 1936 | - } // end filter terms by owner |
|
| 1936 | + } // end filter terms by owner |
|
| 1937 | 1937 | |
| 1938 | - /** |
|
| 1939 | - * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1940 | - * This will not add name to terms belonging to admin user. |
|
| 1941 | - * |
|
| 1942 | - * Hooked into 'get_terms' |
|
| 1943 | - * |
|
| 1944 | - * @since 1.8.0 |
|
| 1945 | - */ |
|
| 1946 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1947 | - { |
|
| 1938 | + /** |
|
| 1939 | + * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1940 | + * This will not add name to terms belonging to admin user. |
|
| 1941 | + * |
|
| 1942 | + * Hooked into 'get_terms' |
|
| 1943 | + * |
|
| 1944 | + * @since 1.8.0 |
|
| 1945 | + */ |
|
| 1946 | + public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1947 | + { |
|
| 1948 | 1948 | |
| 1949 | - // only for admin users ont he module taxonomy |
|
| 1950 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1951 | - return $terms; |
|
| 1952 | - } |
|
| 1949 | + // only for admin users ont he module taxonomy |
|
| 1950 | + if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1951 | + return $terms; |
|
| 1952 | + } |
|
| 1953 | 1953 | |
| 1954 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1955 | - // simply return this as wp doesn't need an array of stdObject Term |
|
| 1956 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1954 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1955 | + // simply return this as wp doesn't need an array of stdObject Term |
|
| 1956 | + if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1957 | 1957 | |
| 1958 | - return $terms; |
|
| 1958 | + return $terms; |
|
| 1959 | 1959 | |
| 1960 | - } |
|
| 1960 | + } |
|
| 1961 | 1961 | |
| 1962 | - // loop through and update all terms adding the author name |
|
| 1963 | - foreach( $terms as $index => $term ){ |
|
| 1962 | + // loop through and update all terms adding the author name |
|
| 1963 | + foreach( $terms as $index => $term ){ |
|
| 1964 | 1964 | |
| 1965 | - if( is_numeric( $term ) ){ |
|
| 1966 | - // the term id was given, get the term object |
|
| 1967 | - $term = get_term( $term, 'module' ); |
|
| 1968 | - } |
|
| 1965 | + if( is_numeric( $term ) ){ |
|
| 1966 | + // the term id was given, get the term object |
|
| 1967 | + $term = get_term( $term, 'module' ); |
|
| 1968 | + } |
|
| 1969 | 1969 | |
| 1970 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1970 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1971 | 1971 | |
| 1972 | - if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1974 | - } |
|
| 1972 | + if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | + $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1974 | + } |
|
| 1975 | 1975 | |
| 1976 | - // add the term to the teachers terms |
|
| 1977 | - $users_terms[] = $term; |
|
| 1976 | + // add the term to the teachers terms |
|
| 1977 | + $users_terms[] = $term; |
|
| 1978 | 1978 | |
| 1979 | - } |
|
| 1979 | + } |
|
| 1980 | 1980 | |
| 1981 | - return $users_terms; |
|
| 1982 | - } |
|
| 1981 | + return $users_terms; |
|
| 1982 | + } |
|
| 1983 | 1983 | |
| 1984 | - /** |
|
| 1985 | - * Remove modules metabox that come by default |
|
| 1986 | - * with the modules taxonomy. We are removing this as |
|
| 1987 | - * we have created our own custom meta box. |
|
| 1988 | - */ |
|
| 1989 | - public static function remove_default_modules_box() { |
|
| 1984 | + /** |
|
| 1985 | + * Remove modules metabox that come by default |
|
| 1986 | + * with the modules taxonomy. We are removing this as |
|
| 1987 | + * we have created our own custom meta box. |
|
| 1988 | + */ |
|
| 1989 | + public static function remove_default_modules_box() { |
|
| 1990 | 1990 | |
| 1991 | - remove_meta_box('modulediv', 'course', 'side'); |
|
| 1991 | + remove_meta_box('modulediv', 'course', 'side'); |
|
| 1992 | 1992 | |
| 1993 | - } |
|
| 1993 | + } |
|
| 1994 | 1994 | |
| 1995 | - /** |
|
| 1996 | - * When a course is save make sure to reset the transient set |
|
| 1997 | - * for it when determining the none module lessons. |
|
| 1998 | - * |
|
| 1999 | - * @sine 1.9.0 |
|
| 2000 | - * @param $post_id |
|
| 2001 | - */ |
|
| 2002 | - public static function reset_none_modules_transient ( $post_id ){ |
|
| 1995 | + /** |
|
| 1996 | + * When a course is save make sure to reset the transient set |
|
| 1997 | + * for it when determining the none module lessons. |
|
| 1998 | + * |
|
| 1999 | + * @sine 1.9.0 |
|
| 2000 | + * @param $post_id |
|
| 2001 | + */ |
|
| 2002 | + public static function reset_none_modules_transient ( $post_id ){ |
|
| 2003 | 2003 | |
| 2004 | - // this should only apply to course and lesson post types |
|
| 2005 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2004 | + // this should only apply to course and lesson post types |
|
| 2005 | + if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2006 | 2006 | |
| 2007 | - $course_id = ''; |
|
| 2007 | + $course_id = ''; |
|
| 2008 | 2008 | |
| 2009 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2009 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2010 | 2010 | |
| 2011 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2011 | + $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2012 | 2012 | |
| 2013 | - } |
|
| 2013 | + } |
|
| 2014 | 2014 | |
| 2015 | 2015 | |
| 2016 | - if( !empty( $course_id ) ){ |
|
| 2016 | + if( !empty( $course_id ) ){ |
|
| 2017 | 2017 | |
| 2018 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2018 | + delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2019 | 2019 | |
| 2020 | - } |
|
| 2020 | + } |
|
| 2021 | 2021 | |
| 2022 | - } // end if is a course or a lesson |
|
| 2022 | + } // end if is a course or a lesson |
|
| 2023 | 2023 | |
| 2024 | - } // end reset_none_modules_transient |
|
| 2024 | + } // end reset_none_modules_transient |
|
| 2025 | 2025 | |
| 2026 | - /** |
|
| 2027 | - * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2028 | - * |
|
| 2029 | - * @since 1.9.0 |
|
| 2030 | - * @deprecated since 1.9.0 |
|
| 2031 | - * |
|
| 2032 | - */ |
|
| 2033 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2026 | + /** |
|
| 2027 | + * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2028 | + * |
|
| 2029 | + * @since 1.9.0 |
|
| 2030 | + * @deprecated since 1.9.0 |
|
| 2031 | + * |
|
| 2032 | + */ |
|
| 2033 | + public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2034 | 2034 | |
| 2035 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2035 | + sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2036 | 2036 | |
| 2037 | - } |
|
| 2037 | + } |
|
| 2038 | 2038 | |
| 2039 | - /** |
|
| 2040 | - * Setup the single course module loop. |
|
| 2041 | - * |
|
| 2042 | - * Setup the global $sensei_modules_loop |
|
| 2043 | - * |
|
| 2044 | - * @since 1.9.0 |
|
| 2045 | - */ |
|
| 2046 | - public static function setup_single_course_module_loop(){ |
|
| 2039 | + /** |
|
| 2040 | + * Setup the single course module loop. |
|
| 2041 | + * |
|
| 2042 | + * Setup the global $sensei_modules_loop |
|
| 2043 | + * |
|
| 2044 | + * @since 1.9.0 |
|
| 2045 | + */ |
|
| 2046 | + public static function setup_single_course_module_loop(){ |
|
| 2047 | 2047 | |
| 2048 | - global $sensei_modules_loop, $post; |
|
| 2049 | - $course_id = $post->ID; |
|
| 2048 | + global $sensei_modules_loop, $post; |
|
| 2049 | + $course_id = $post->ID; |
|
| 2050 | 2050 | |
| 2051 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2051 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2052 | 2052 | |
| 2053 | - //initial setup |
|
| 2054 | - $sensei_modules_loop['total'] = 0; |
|
| 2055 | - $sensei_modules_loop['modules'] = array(); |
|
| 2056 | - $sensei_modules_loop['current'] = -1; |
|
| 2053 | + //initial setup |
|
| 2054 | + $sensei_modules_loop['total'] = 0; |
|
| 2055 | + $sensei_modules_loop['modules'] = array(); |
|
| 2056 | + $sensei_modules_loop['current'] = -1; |
|
| 2057 | 2057 | |
| 2058 | - // exit if this course doesn't have modules |
|
| 2059 | - if( !$modules || empty( $modules ) ){ |
|
| 2060 | - return; |
|
| 2061 | - } |
|
| 2058 | + // exit if this course doesn't have modules |
|
| 2059 | + if( !$modules || empty( $modules ) ){ |
|
| 2060 | + return; |
|
| 2061 | + } |
|
| 2062 | 2062 | |
| 2063 | 2063 | |
| 2064 | - $lessons_in_all_modules = array(); |
|
| 2065 | - foreach( $modules as $term ){ |
|
| 2064 | + $lessons_in_all_modules = array(); |
|
| 2065 | + foreach( $modules as $term ){ |
|
| 2066 | 2066 | |
| 2067 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2067 | + $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | + $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2069 | 2069 | |
| 2070 | - } |
|
| 2070 | + } |
|
| 2071 | 2071 | |
| 2072 | 2072 | |
| 2073 | - //setup all of the modules loop variables |
|
| 2074 | - $sensei_modules_loop['total'] = count( $modules ); |
|
| 2075 | - $sensei_modules_loop['modules'] = $modules; |
|
| 2076 | - $sensei_modules_loop['current'] = -1; |
|
| 2077 | - $sensei_modules_loop['course_id'] = $course_id; |
|
| 2073 | + //setup all of the modules loop variables |
|
| 2074 | + $sensei_modules_loop['total'] = count( $modules ); |
|
| 2075 | + $sensei_modules_loop['modules'] = $modules; |
|
| 2076 | + $sensei_modules_loop['current'] = -1; |
|
| 2077 | + $sensei_modules_loop['course_id'] = $course_id; |
|
| 2078 | 2078 | |
| 2079 | - }// end setup_single_course_module_loop |
|
| 2079 | + }// end setup_single_course_module_loop |
|
| 2080 | 2080 | |
| 2081 | - /** |
|
| 2082 | - * Tear down the course module loop. |
|
| 2083 | - * |
|
| 2084 | - * @since 1.9.0 |
|
| 2085 | - * |
|
| 2086 | - */ |
|
| 2087 | - public static function teardown_single_course_module_loop(){ |
|
| 2081 | + /** |
|
| 2082 | + * Tear down the course module loop. |
|
| 2083 | + * |
|
| 2084 | + * @since 1.9.0 |
|
| 2085 | + * |
|
| 2086 | + */ |
|
| 2087 | + public static function teardown_single_course_module_loop(){ |
|
| 2088 | 2088 | |
| 2089 | - global $sensei_modules_loop, $wp_query, $post; |
|
| 2089 | + global $sensei_modules_loop, $wp_query, $post; |
|
| 2090 | 2090 | |
| 2091 | - //reset all of the modules loop variables |
|
| 2092 | - $sensei_modules_loop['total'] = 0; |
|
| 2093 | - $sensei_modules_loop['modules'] = array(); |
|
| 2094 | - $sensei_modules_loop['current'] = -1; |
|
| 2091 | + //reset all of the modules loop variables |
|
| 2092 | + $sensei_modules_loop['total'] = 0; |
|
| 2093 | + $sensei_modules_loop['modules'] = array(); |
|
| 2094 | + $sensei_modules_loop['current'] = -1; |
|
| 2095 | 2095 | |
| 2096 | - // set the current course to be the global post again |
|
| 2097 | - wp_reset_query(); |
|
| 2098 | - $post = $wp_query->post; |
|
| 2099 | - }// end teardown_single_course_module_loop |
|
| 2096 | + // set the current course to be the global post again |
|
| 2097 | + wp_reset_query(); |
|
| 2098 | + $post = $wp_query->post; |
|
| 2099 | + }// end teardown_single_course_module_loop |
|
| 2100 | 2100 | |
| 2101 | 2101 | } // end modules class |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | // Setup meta fields for this post type |
| 25 | 25 | $this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' ); |
| 26 | 26 | |
| 27 | - $this->question_order = ''; |
|
| 27 | + $this->question_order = ''; |
|
| 28 | 28 | |
| 29 | 29 | // Admin actions |
| 30 | 30 | if ( is_admin() ) { |
@@ -82,18 +82,18 @@ discard block |
||
| 82 | 82 | add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) ); |
| 83 | 83 | add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) ); |
| 84 | 84 | |
| 85 | - // output bulk edit fields |
|
| 86 | - add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 ); |
|
| 87 | - add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 ); |
|
| 85 | + // output bulk edit fields |
|
| 86 | + add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 ); |
|
| 87 | + add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 ); |
|
| 88 | 88 | |
| 89 | - // load quick edit default values |
|
| 90 | - add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2); |
|
| 89 | + // load quick edit default values |
|
| 90 | + add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2); |
|
| 91 | 91 | |
| 92 | - // save bulk edit fields |
|
| 93 | - add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) ); |
|
| 92 | + // save bulk edit fields |
|
| 93 | + add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) ); |
|
| 94 | 94 | |
| 95 | - // flush rewrite rules when saving a lesson |
|
| 96 | - add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
| 95 | + // flush rewrite rules when saving a lesson |
|
| 96 | + add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
| 97 | 97 | |
| 98 | 98 | } else { |
| 99 | 99 | // Frontend actions |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | $post_args = array( 'post_type' => 'lesson', |
| 188 | 188 | 'posts_per_page' => -1, |
| 189 | 189 | 'orderby' => 'title', |
| 190 | - 'order' => 'ASC', |
|
| 191 | - 'exclude' => $post->ID, |
|
| 190 | + 'order' => 'ASC', |
|
| 191 | + 'exclude' => $post->ID, |
|
| 192 | 192 | 'suppress_filters' => 0 |
| 193 | 193 | ); |
| 194 | 194 | $posts_array = get_posts( $post_args ); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | $checked = ''; |
| 226 | 226 | if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) { |
| 227 | - $checked = checked( 'preview', $lesson_preview, false ); |
|
| 227 | + $checked = checked( 'preview', $lesson_preview, false ); |
|
| 228 | 228 | } // End If Statement |
| 229 | 229 | |
| 230 | 230 | $html .= '<label for="lesson_preview">'; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | |
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | - * Update the lesson quiz and all the post meta |
|
| 276 | + * Update the lesson quiz and all the post meta |
|
| 277 | 277 | * |
| 278 | 278 | * @access public |
| 279 | 279 | * @return void |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | // Temporarily disable the filter |
| 297 | - remove_action( 'save_post', array( $this, 'quiz_update' ) ); |
|
| 297 | + remove_action( 'save_post', array( $this, 'quiz_update' ) ); |
|
| 298 | 298 | // Save the Quiz |
| 299 | 299 | $quiz_id = $this->lesson_quizzes( $post_id, 'any'); |
| 300 | 300 | |
@@ -309,11 +309,11 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | // Setup Query Arguments |
| 311 | 311 | $post_type_args = array( 'post_content' => $post_content, |
| 312 | - 'post_status' => $post_status, |
|
| 313 | - 'post_title' => $post_title, |
|
| 314 | - 'post_type' => 'quiz', |
|
| 315 | - 'post_parent' => $post_id, |
|
| 316 | - ); |
|
| 312 | + 'post_status' => $post_status, |
|
| 313 | + 'post_title' => $post_title, |
|
| 314 | + 'post_type' => 'quiz', |
|
| 315 | + 'post_parent' => $post_id, |
|
| 316 | + ); |
|
| 317 | 317 | |
| 318 | 318 | $settings = $this->get_quiz_settings(); |
| 319 | 319 | |
@@ -321,48 +321,48 @@ discard block |
||
| 321 | 321 | if ( 0 < $quiz_id ) { |
| 322 | 322 | // Update the Quiz |
| 323 | 323 | $post_type_args[ 'ID' ] = $quiz_id; |
| 324 | - wp_update_post($post_type_args); |
|
| 325 | - |
|
| 326 | - // Update the post meta data |
|
| 327 | - update_post_meta( $quiz_id, '_quiz_lesson', $post_id ); |
|
| 328 | - |
|
| 329 | - foreach( $settings as $field ) { |
|
| 330 | - if( 'random_question_order' != $field['id'] ) { |
|
| 331 | - $value = $this->get_submitted_setting_value( $field ); |
|
| 332 | - if( isset( $value ) ) { |
|
| 333 | - update_post_meta( $quiz_id, '_' . $field['id'], $value ); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - // Set the post terms for quiz-type |
|
| 339 | - wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' ); |
|
| 324 | + wp_update_post($post_type_args); |
|
| 325 | + |
|
| 326 | + // Update the post meta data |
|
| 327 | + update_post_meta( $quiz_id, '_quiz_lesson', $post_id ); |
|
| 328 | + |
|
| 329 | + foreach( $settings as $field ) { |
|
| 330 | + if( 'random_question_order' != $field['id'] ) { |
|
| 331 | + $value = $this->get_submitted_setting_value( $field ); |
|
| 332 | + if( isset( $value ) ) { |
|
| 333 | + update_post_meta( $quiz_id, '_' . $field['id'], $value ); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + // Set the post terms for quiz-type |
|
| 339 | + wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' ); |
|
| 340 | 340 | } else { |
| 341 | 341 | // Create the Quiz |
| 342 | - $quiz_id = wp_insert_post($post_type_args); |
|
| 343 | - |
|
| 344 | - // Add the post meta data WP will add it if it doesn't exist |
|
| 345 | - update_post_meta( $quiz_id, '_quiz_lesson', $post_id ); |
|
| 346 | - |
|
| 347 | - foreach( $settings as $field ) { |
|
| 348 | - if( 'random_question_order' != $field['id'] ) { |
|
| 349 | - |
|
| 350 | - //ignore values not posted to avoid |
|
| 351 | - // overwriting with empty or default values |
|
| 352 | - // when the values are posted from bulk edit or quick edit |
|
| 353 | - if( !isset( $_POST[ $field['id'] ] ) ){ |
|
| 354 | - continue; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $value = $this->get_submitted_setting_value( $field ); |
|
| 358 | - if( isset( $value ) ) { |
|
| 359 | - add_post_meta( $quiz_id, '_' . $field['id'], $value ); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - // Set the post terms for quiz-type |
|
| 365 | - wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' ); |
|
| 342 | + $quiz_id = wp_insert_post($post_type_args); |
|
| 343 | + |
|
| 344 | + // Add the post meta data WP will add it if it doesn't exist |
|
| 345 | + update_post_meta( $quiz_id, '_quiz_lesson', $post_id ); |
|
| 346 | + |
|
| 347 | + foreach( $settings as $field ) { |
|
| 348 | + if( 'random_question_order' != $field['id'] ) { |
|
| 349 | + |
|
| 350 | + //ignore values not posted to avoid |
|
| 351 | + // overwriting with empty or default values |
|
| 352 | + // when the values are posted from bulk edit or quick edit |
|
| 353 | + if( !isset( $_POST[ $field['id'] ] ) ){ |
|
| 354 | + continue; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $value = $this->get_submitted_setting_value( $field ); |
|
| 358 | + if( isset( $value ) ) { |
|
| 359 | + add_post_meta( $quiz_id, '_' . $field['id'], $value ); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + // Set the post terms for quiz-type |
|
| 365 | + wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' ); |
|
| 366 | 366 | } // End If Statement |
| 367 | 367 | |
| 368 | 368 | // Add default lesson order meta value |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | // Restore the previously disabled filter |
| 387 | - add_action( 'save_post', array( $this, 'quiz_update' ) ); |
|
| 387 | + add_action( 'save_post', array( $this, 'quiz_update' ) ); |
|
| 388 | 388 | |
| 389 | 389 | } // End post_updated() |
| 390 | 390 | |
@@ -424,22 +424,22 @@ discard block |
||
| 424 | 424 | // Get the meta key. |
| 425 | 425 | $meta_key = '_' . $post_key; |
| 426 | 426 | |
| 427 | - //ignore fields are not posted |
|
| 427 | + //ignore fields are not posted |
|
| 428 | 428 | |
| 429 | - if( !isset( $_POST[ $post_key ] ) ){ |
|
| 429 | + if( !isset( $_POST[ $post_key ] ) ){ |
|
| 430 | 430 | |
| 431 | - // except for lesson preview checkbox field |
|
| 432 | - if( 'lesson_preview' == $post_key ){ |
|
| 431 | + // except for lesson preview checkbox field |
|
| 432 | + if( 'lesson_preview' == $post_key ){ |
|
| 433 | 433 | |
| 434 | - $_POST[ $post_key ] = ''; |
|
| 434 | + $_POST[ $post_key ] = ''; |
|
| 435 | 435 | |
| 436 | - } else { |
|
| 436 | + } else { |
|
| 437 | 437 | |
| 438 | - return false; |
|
| 438 | + return false; |
|
| 439 | 439 | |
| 440 | - } |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - } |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | 444 | // Get the posted data and sanitize it for use as an HTML class. |
| 445 | 445 | if ( 'lesson_video_embed' == $post_key) { |
@@ -448,10 +448,10 @@ discard block |
||
| 448 | 448 | $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
| 449 | 449 | } // End If Statement |
| 450 | 450 | |
| 451 | - // update field with the new value |
|
| 452 | - if( -1 != $new_meta_value ){ |
|
| 453 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 454 | - } |
|
| 451 | + // update field with the new value |
|
| 452 | + if( -1 != $new_meta_value ){ |
|
| 453 | + return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | 456 | } // End save_post_meta() |
| 457 | 457 | |
@@ -476,9 +476,9 @@ discard block |
||
| 476 | 476 | $post_args = array( 'post_type' => 'course', |
| 477 | 477 | 'posts_per_page' => -1, |
| 478 | 478 | 'orderby' => 'title', |
| 479 | - 'order' => 'ASC', |
|
| 480 | - 'post_status' => 'any', |
|
| 481 | - 'suppress_filters' => 0, |
|
| 479 | + 'order' => 'ASC', |
|
| 480 | + 'post_status' => 'any', |
|
| 481 | + 'suppress_filters' => 0, |
|
| 482 | 482 | ); |
| 483 | 483 | $posts_array = get_posts( $post_args ); |
| 484 | 484 | // Buid the HTML to Output |
@@ -486,20 +486,20 @@ discard block |
||
| 486 | 486 | // Nonce |
| 487 | 487 | $html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false ); |
| 488 | 488 | |
| 489 | - // Select the course for the lesson |
|
| 490 | - $drop_down_args = array( |
|
| 491 | - 'name'=>'lesson_course', |
|
| 492 | - 'id' => 'lesson-course-options' |
|
| 493 | - ); |
|
| 489 | + // Select the course for the lesson |
|
| 490 | + $drop_down_args = array( |
|
| 491 | + 'name'=>'lesson_course', |
|
| 492 | + 'id' => 'lesson-course-options' |
|
| 493 | + ); |
|
| 494 | 494 | |
| 495 | - $courses = WooThemes_Sensei_Course::get_all_courses(); |
|
| 496 | - $courses_options = array(); |
|
| 497 | - foreach( $courses as $course ){ |
|
| 498 | - $courses_options[ $course->ID ] = get_the_title( $course ) ; |
|
| 499 | - } |
|
| 500 | - $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args ); |
|
| 495 | + $courses = WooThemes_Sensei_Course::get_all_courses(); |
|
| 496 | + $courses_options = array(); |
|
| 497 | + foreach( $courses as $course ){ |
|
| 498 | + $courses_options[ $course->ID ] = get_the_title( $course ) ; |
|
| 499 | + } |
|
| 500 | + $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args ); |
|
| 501 | 501 | |
| 502 | - // Course Actions Panel |
|
| 502 | + // Course Actions Panel |
|
| 503 | 503 | if ( current_user_can( 'publish_courses' )) { |
| 504 | 504 | $html .= '<div id="lesson-course-actions">'; |
| 505 | 505 | $html .= '<p>'; |
@@ -525,16 +525,16 @@ discard block |
||
| 525 | 525 | } // End For Loop |
| 526 | 526 | $html .= '</select>' . "\n"; |
| 527 | 527 | // Course Product |
| 528 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 528 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 529 | 529 | // Get the Products |
| 530 | 530 | $select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true ); |
| 531 | 531 | |
| 532 | 532 | $product_args = array( 'post_type' => array( 'product', 'product_variation' ), |
| 533 | 533 | 'posts_per_page' => -1, |
| 534 | 534 | 'orderby' => 'title', |
| 535 | - 'order' => 'DESC', |
|
| 536 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 537 | - 'tax_query' => array( |
|
| 535 | + 'order' => 'DESC', |
|
| 536 | + 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 537 | + 'tax_query' => array( |
|
| 538 | 538 | array( |
| 539 | 539 | 'taxonomy' => 'product_type', |
| 540 | 540 | 'field' => 'slug', |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | 'operator' => 'NOT IN' |
| 543 | 543 | ) |
| 544 | 544 | ), |
| 545 | - 'suppress_filters' => 0 |
|
| 545 | + 'suppress_filters' => 0 |
|
| 546 | 546 | ); |
| 547 | 547 | $products_array = get_posts( $product_args ); |
| 548 | 548 | $html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> '; |
@@ -870,58 +870,58 @@ discard block |
||
| 870 | 870 | $html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">'; |
| 871 | 871 | $html .= '<td colspan="5">'; |
| 872 | 872 | $html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>'; |
| 873 | - $html .= '<div class="question_required_fields">'; |
|
| 874 | - |
|
| 875 | - // Question title |
|
| 876 | - $html .= '<div>'; |
|
| 877 | - $html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> '; |
|
| 878 | - $html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />'; |
|
| 879 | - $html .= '</div>'; |
|
| 880 | - |
|
| 881 | - // Question description |
|
| 882 | - $html .= '<div>'; |
|
| 883 | - $html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> '; |
|
| 884 | - $html .= '</div>'; |
|
| 885 | - $html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>'; |
|
| 886 | - |
|
| 887 | - // Question grade |
|
| 888 | - $html .= '<div>'; |
|
| 889 | - $html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> '; |
|
| 890 | - $html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />'; |
|
| 891 | - $html .= '</div>'; |
|
| 892 | - |
|
| 893 | - // Random order |
|
| 894 | - if( $question_type == 'multiple-choice' ) { |
|
| 895 | - $html .= '<div>'; |
|
| 896 | - $html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>'; |
|
| 897 | - $html .= '</div>'; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - // Question media |
|
| 901 | - $html .= '<div>'; |
|
| 902 | - $html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>'; |
|
| 903 | - $html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>'; |
|
| 904 | - $html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>'; |
|
| 905 | - $html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>'; |
|
| 906 | - $html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>'; |
|
| 907 | - $html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />'; |
|
| 908 | - $html .= '</div>'; |
|
| 909 | - |
|
| 910 | - $html .= '</div>'; |
|
| 911 | - |
|
| 912 | - $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter ); |
|
| 913 | - |
|
| 914 | - $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />'; |
|
| 873 | + $html .= '<div class="question_required_fields">'; |
|
| 874 | + |
|
| 875 | + // Question title |
|
| 876 | + $html .= '<div>'; |
|
| 877 | + $html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> '; |
|
| 878 | + $html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />'; |
|
| 879 | + $html .= '</div>'; |
|
| 880 | + |
|
| 881 | + // Question description |
|
| 882 | + $html .= '<div>'; |
|
| 883 | + $html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> '; |
|
| 884 | + $html .= '</div>'; |
|
| 885 | + $html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>'; |
|
| 886 | + |
|
| 887 | + // Question grade |
|
| 888 | + $html .= '<div>'; |
|
| 889 | + $html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> '; |
|
| 890 | + $html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />'; |
|
| 891 | + $html .= '</div>'; |
|
| 892 | + |
|
| 893 | + // Random order |
|
| 894 | + if( $question_type == 'multiple-choice' ) { |
|
| 895 | + $html .= '<div>'; |
|
| 896 | + $html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>'; |
|
| 897 | + $html .= '</div>'; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + // Question media |
|
| 901 | + $html .= '<div>'; |
|
| 902 | + $html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>'; |
|
| 903 | + $html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>'; |
|
| 904 | + $html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>'; |
|
| 905 | + $html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>'; |
|
| 906 | + $html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>'; |
|
| 907 | + $html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />'; |
|
| 908 | + $html .= '</div>'; |
|
| 909 | + |
|
| 910 | + $html .= '</div>'; |
|
| 911 | + |
|
| 912 | + $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter ); |
|
| 913 | + |
|
| 914 | + $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />'; |
|
| 915 | 915 | $html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />'; |
| 916 | 916 | |
| 917 | 917 | if( 'quiz' == $context ) { |
| 918 | - $html .= '<div class="update-question">'; |
|
| 919 | - $html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> '; |
|
| 920 | - $html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>'; |
|
| 921 | - $html .= '</div>'; |
|
| 922 | - } |
|
| 918 | + $html .= '<div class="update-question">'; |
|
| 919 | + $html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> '; |
|
| 920 | + $html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>'; |
|
| 921 | + $html .= '</div>'; |
|
| 922 | + } |
|
| 923 | 923 | |
| 924 | - $html .= '</td>'; |
|
| 924 | + $html .= '</td>'; |
|
| 925 | 925 | $html .= '</tr>'; |
| 926 | 926 | } |
| 927 | 927 | |
@@ -942,20 +942,20 @@ discard block |
||
| 942 | 942 | $question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) ); |
| 943 | 943 | |
| 944 | 944 | if( 'quiz' == $context ) { |
| 945 | - $html .= '<h2 class="nav-tab-wrapper add-question-tabs">'; |
|
| 946 | - $html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question' , 'woothemes-sensei' ) . '</a>'; |
|
| 947 | - $html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions' , 'woothemes-sensei' ) . '</a>'; |
|
| 948 | - if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) && ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 949 | - $html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions' , 'woothemes-sensei' ) . '</a>'; |
|
| 950 | - } |
|
| 951 | - $html .= '</h2>'; |
|
| 952 | - } |
|
| 945 | + $html .= '<h2 class="nav-tab-wrapper add-question-tabs">'; |
|
| 946 | + $html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question' , 'woothemes-sensei' ) . '</a>'; |
|
| 947 | + $html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions' , 'woothemes-sensei' ) . '</a>'; |
|
| 948 | + if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) && ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 949 | + $html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions' , 'woothemes-sensei' ) . '</a>'; |
|
| 950 | + } |
|
| 951 | + $html .= '</h2>'; |
|
| 952 | + } |
|
| 953 | 953 | |
| 954 | - $html .= '<div class="tab-content" id="tab-new-content">'; |
|
| 954 | + $html .= '<div class="tab-content" id="tab-new-content">'; |
|
| 955 | 955 | |
| 956 | - if( 'quiz' == $context ) { |
|
| 957 | - $html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>'; |
|
| 958 | - } |
|
| 956 | + if( 'quiz' == $context ) { |
|
| 957 | + $html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>'; |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | 960 | $html .= '<div class="question">'; |
| 961 | 961 | $html .= '<div class="question_required_fields">'; |
@@ -997,18 +997,18 @@ discard block |
||
| 997 | 997 | |
| 998 | 998 | // Random order |
| 999 | 999 | $html .= '<p class="add_question_random_order">'; |
| 1000 | - $html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>'; |
|
| 1001 | - $html .= '</p>'; |
|
| 1000 | + $html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>'; |
|
| 1001 | + $html .= '</p>'; |
|
| 1002 | 1002 | |
| 1003 | - // Question media |
|
| 1003 | + // Question media |
|
| 1004 | 1004 | $html .= '<p>'; |
| 1005 | - $html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>'; |
|
| 1006 | - $html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>'; |
|
| 1007 | - $html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>'; |
|
| 1008 | - $html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>'; |
|
| 1009 | - $html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>'; |
|
| 1010 | - $html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />'; |
|
| 1011 | - $html .= '</p>'; |
|
| 1005 | + $html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>'; |
|
| 1006 | + $html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>'; |
|
| 1007 | + $html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>'; |
|
| 1008 | + $html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>'; |
|
| 1009 | + $html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>'; |
|
| 1010 | + $html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />'; |
|
| 1011 | + $html .= '</p>'; |
|
| 1012 | 1012 | |
| 1013 | 1013 | $html .= '</div>'; |
| 1014 | 1014 | $html .= '</div>'; |
@@ -1019,19 +1019,19 @@ discard block |
||
| 1019 | 1019 | |
| 1020 | 1020 | if( 'quiz' == $context ) { |
| 1021 | 1021 | $html .= '<div class="add-question">'; |
| 1022 | - $html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>'; |
|
| 1023 | - $html .= '</div>'; |
|
| 1024 | - } |
|
| 1022 | + $html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>'; |
|
| 1023 | + $html .= '</div>'; |
|
| 1024 | + } |
|
| 1025 | 1025 | |
| 1026 | - $html .= '</div>'; |
|
| 1026 | + $html .= '</div>'; |
|
| 1027 | 1027 | |
| 1028 | - if( 'quiz' == $context ) { |
|
| 1028 | + if( 'quiz' == $context ) { |
|
| 1029 | 1029 | |
| 1030 | - $html .= '<div class="tab-content hidden" id="tab-existing-content">'; |
|
| 1030 | + $html .= '<div class="tab-content hidden" id="tab-existing-content">'; |
|
| 1031 | 1031 | |
| 1032 | - $html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>'; |
|
| 1032 | + $html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>'; |
|
| 1033 | 1033 | |
| 1034 | - $html .= '<div id="existing-filters" class="alignleft actions"> |
|
| 1034 | + $html .= '<div id="existing-filters" class="alignleft actions"> |
|
| 1035 | 1035 | <select id="existing-status"> |
| 1036 | 1036 | <option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option> |
| 1037 | 1037 | <option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option> |
@@ -1039,23 +1039,23 @@ discard block |
||
| 1039 | 1039 | </select> |
| 1040 | 1040 | <select id="existing-type"> |
| 1041 | 1041 | <option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>'; |
| 1042 | - foreach ( $question_types as $type => $label ) { |
|
| 1042 | + foreach ( $question_types as $type => $label ) { |
|
| 1043 | 1043 | $html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>'; |
| 1044 | 1044 | } |
| 1045 | - $html .= '</select> |
|
| 1045 | + $html .= '</select> |
|
| 1046 | 1046 | <select id="existing-category"> |
| 1047 | 1047 | <option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>'; |
| 1048 | - foreach( $question_cats as $cat ) { |
|
| 1048 | + foreach( $question_cats as $cat ) { |
|
| 1049 | 1049 | $html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>'; |
| 1050 | 1050 | } |
| 1051 | - $html .= '</select> |
|
| 1051 | + $html .= '</select> |
|
| 1052 | 1052 | <input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" /> |
| 1053 | 1053 | <a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a> |
| 1054 | 1054 | </div>'; |
| 1055 | 1055 | |
| 1056 | - $html .= '<table id="existing-table" class="widefat">'; |
|
| 1056 | + $html .= '<table id="existing-table" class="widefat">'; |
|
| 1057 | 1057 | |
| 1058 | - $html .= '<thead> |
|
| 1058 | + $html .= '<thead> |
|
| 1059 | 1059 | <tr> |
| 1060 | 1060 | <th scope="col" class="column-cb check-column"><input type="checkbox" /></th> |
| 1061 | 1061 | <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th> |
@@ -1083,28 +1083,28 @@ discard block |
||
| 1083 | 1083 | |
| 1084 | 1084 | $html .= '</tbody>'; |
| 1085 | 1085 | |
| 1086 | - $html .= '</table>'; |
|
| 1086 | + $html .= '</table>'; |
|
| 1087 | 1087 | |
| 1088 | - $next_class = ''; |
|
| 1089 | - if( $questions['count'] <= 10 ) { |
|
| 1090 | - $next_class = 'hidden'; |
|
| 1091 | - } |
|
| 1088 | + $next_class = ''; |
|
| 1089 | + if( $questions['count'] <= 10 ) { |
|
| 1090 | + $next_class = 'hidden'; |
|
| 1091 | + } |
|
| 1092 | 1092 | |
| 1093 | - $html .= '<div id="existing-pagination">'; |
|
| 1094 | - $html .= '<input type="hidden" id="existing-page" value="1" />'; |
|
| 1095 | - $html .= '<a class="prev no-paging">← ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' →</a>'; |
|
| 1096 | - $html .= '</div>'; |
|
| 1093 | + $html .= '<div id="existing-pagination">'; |
|
| 1094 | + $html .= '<input type="hidden" id="existing-page" value="1" />'; |
|
| 1095 | + $html .= '<a class="prev no-paging">← ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' →</a>'; |
|
| 1096 | + $html .= '</div>'; |
|
| 1097 | 1097 | |
| 1098 | - $html .= '<div class="existing-actions">'; |
|
| 1099 | - $html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>'; |
|
| 1100 | - $html .= '</div>'; |
|
| 1098 | + $html .= '<div class="existing-actions">'; |
|
| 1099 | + $html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>'; |
|
| 1100 | + $html .= '</div>'; |
|
| 1101 | 1101 | |
| 1102 | - $html .= '</div>'; |
|
| 1102 | + $html .= '</div>'; |
|
| 1103 | 1103 | |
| 1104 | - if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) { |
|
| 1105 | - $html .= '<div class="tab-content hidden" id="tab-multiple-content">'; |
|
| 1104 | + if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) { |
|
| 1105 | + $html .= '<div class="tab-content hidden" id="tab-multiple-content">'; |
|
| 1106 | 1106 | |
| 1107 | - $html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>'; |
|
| 1107 | + $html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>'; |
|
| 1108 | 1108 | |
| 1109 | 1109 | $html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n"; |
| 1110 | 1110 | $html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n"; |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | |
| 1118 | 1118 | $html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>'; |
| 1119 | 1119 | |
| 1120 | - $html .= '</div>'; |
|
| 1120 | + $html .= '</div>'; |
|
| 1121 | 1121 | } |
| 1122 | 1122 | } |
| 1123 | 1123 | |
@@ -1190,14 +1190,14 @@ discard block |
||
| 1190 | 1190 | |
| 1191 | 1191 | $qry = new WP_Query( $args ); |
| 1192 | 1192 | |
| 1193 | - /** |
|
| 1194 | - * Filter existing questions query |
|
| 1195 | - * |
|
| 1196 | - * @since 1.8.0 |
|
| 1197 | - * |
|
| 1198 | - * @param WP_Query $wp_query |
|
| 1199 | - */ |
|
| 1200 | - $qry = apply_filters( 'sensei_existing_questions_query_results', $qry ); |
|
| 1193 | + /** |
|
| 1194 | + * Filter existing questions query |
|
| 1195 | + * |
|
| 1196 | + * @since 1.8.0 |
|
| 1197 | + * |
|
| 1198 | + * @param WP_Query $wp_query |
|
| 1199 | + */ |
|
| 1200 | + $qry = apply_filters( 'sensei_existing_questions_query_results', $qry ); |
|
| 1201 | 1201 | |
| 1202 | 1202 | $questions['questions'] = $qry->posts; |
| 1203 | 1203 | $questions['count'] = intval( $qry->found_posts ); |
@@ -1212,14 +1212,14 @@ discard block |
||
| 1212 | 1212 | |
| 1213 | 1213 | if( ! $question_id ) { |
| 1214 | 1214 | |
| 1215 | - return; |
|
| 1215 | + return; |
|
| 1216 | 1216 | |
| 1217 | - } |
|
| 1217 | + } |
|
| 1218 | 1218 | |
| 1219 | 1219 | $existing_class = ''; |
| 1220 | 1220 | if( $row % 2 ) { |
| 1221 | - $existing_class = 'alternate'; |
|
| 1222 | - } |
|
| 1221 | + $existing_class = 'alternate'; |
|
| 1222 | + } |
|
| 1223 | 1223 | |
| 1224 | 1224 | $question_type = Sensei()->question->get_question_type( $question_id ); |
| 1225 | 1225 | |
@@ -1353,67 +1353,67 @@ discard block |
||
| 1353 | 1353 | } |
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - // Calculate total wrong answers available (defaults to 4) |
|
| 1357 | - $total_wrong = 0; |
|
| 1358 | - if( $question_id ) { |
|
| 1359 | - $total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true ); |
|
| 1360 | - } |
|
| 1361 | - if( 0 == intval( $total_wrong ) ) { |
|
| 1362 | - $total_wrong = 1; |
|
| 1363 | - } |
|
| 1356 | + // Calculate total wrong answers available (defaults to 4) |
|
| 1357 | + $total_wrong = 0; |
|
| 1358 | + if( $question_id ) { |
|
| 1359 | + $total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true ); |
|
| 1360 | + } |
|
| 1361 | + if( 0 == intval( $total_wrong ) ) { |
|
| 1362 | + $total_wrong = 1; |
|
| 1363 | + } |
|
| 1364 | 1364 | |
| 1365 | - // Setup Wrong Answer HTML |
|
| 1366 | - foreach ( $wrong_answers as $i => $answer ){ |
|
| 1365 | + // Setup Wrong Answer HTML |
|
| 1366 | + foreach ( $wrong_answers as $i => $answer ){ |
|
| 1367 | 1367 | |
| 1368 | - $answer_id = $this->get_answer_id( $answer ); |
|
| 1369 | - $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ; |
|
| 1370 | - $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ; |
|
| 1371 | - $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>'; |
|
| 1372 | - if( $question_id ) { |
|
| 1368 | + $answer_id = $this->get_answer_id( $answer ); |
|
| 1369 | + $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ; |
|
| 1370 | + $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ; |
|
| 1371 | + $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>'; |
|
| 1372 | + if( $question_id ) { |
|
| 1373 | 1373 | |
| 1374 | - $answers[ $answer_id ] = $wrong_answer; |
|
| 1374 | + $answers[ $answer_id ] = $wrong_answer; |
|
| 1375 | 1375 | |
| 1376 | - } else { |
|
| 1376 | + } else { |
|
| 1377 | 1377 | |
| 1378 | - $answers[] = $wrong_answer; |
|
| 1378 | + $answers[] = $wrong_answer; |
|
| 1379 | 1379 | |
| 1380 | - } |
|
| 1380 | + } |
|
| 1381 | 1381 | |
| 1382 | - } // end for each |
|
| 1382 | + } // end for each |
|
| 1383 | 1383 | |
| 1384 | - $answers_sorted = $answers; |
|
| 1385 | - if( $question_id && count( $answer_order ) > 0 ) { |
|
| 1386 | - $answers_sorted = array(); |
|
| 1387 | - foreach( $answer_order as $answer_id ) { |
|
| 1388 | - if( isset( $answers[ $answer_id ] ) ) { |
|
| 1389 | - $answers_sorted[ $answer_id ] = $answers[ $answer_id ]; |
|
| 1390 | - unset( $answers[ $answer_id ] ); |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 1384 | + $answers_sorted = $answers; |
|
| 1385 | + if( $question_id && count( $answer_order ) > 0 ) { |
|
| 1386 | + $answers_sorted = array(); |
|
| 1387 | + foreach( $answer_order as $answer_id ) { |
|
| 1388 | + if( isset( $answers[ $answer_id ] ) ) { |
|
| 1389 | + $answers_sorted[ $answer_id ] = $answers[ $answer_id ]; |
|
| 1390 | + unset( $answers[ $answer_id ] ); |
|
| 1391 | + } |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - if( count( $answers ) > 0 ) { |
|
| 1395 | - foreach( $answers as $id => $answer ) { |
|
| 1396 | - $answers_sorted[ $id ] = $answer; |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1394 | + if( count( $answers ) > 0 ) { |
|
| 1395 | + foreach( $answers as $id => $answer ) { |
|
| 1396 | + $answers_sorted[ $id ] = $answer; |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | 1400 | |
| 1401 | 1401 | foreach( $answers_sorted as $id => $answer ) { |
| 1402 | - $html .= $answer; |
|
| 1403 | - } |
|
| 1402 | + $html .= $answer; |
|
| 1403 | + } |
|
| 1404 | 1404 | |
| 1405 | - $html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />'; |
|
| 1406 | - $html .= '<span class="hidden right_answer_count">' . $total_right . '</span>'; |
|
| 1407 | - $html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>'; |
|
| 1405 | + $html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />'; |
|
| 1406 | + $html .= '<span class="hidden right_answer_count">' . $total_right . '</span>'; |
|
| 1407 | + $html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>'; |
|
| 1408 | 1408 | |
| 1409 | - $html .= '<div class="add_answer_options">'; |
|
| 1410 | - $html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>'; |
|
| 1411 | - $html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>'; |
|
| 1412 | - $html .= '</div>'; |
|
| 1409 | + $html .= '<div class="add_answer_options">'; |
|
| 1410 | + $html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>'; |
|
| 1411 | + $html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>'; |
|
| 1412 | + $html .= '</div>'; |
|
| 1413 | 1413 | |
| 1414 | - $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' ); |
|
| 1414 | + $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' ); |
|
| 1415 | 1415 | |
| 1416 | - $html .= '</div>'; |
|
| 1416 | + $html .= '</div>'; |
|
| 1417 | 1417 | break; |
| 1418 | 1418 | case 'boolean': |
| 1419 | 1419 | $html .= '<div class="question_boolean_fields ' . $question_class . '">'; |
@@ -1426,7 +1426,7 @@ discard block |
||
| 1426 | 1426 | $html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>'; |
| 1427 | 1427 | $html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>'; |
| 1428 | 1428 | |
| 1429 | - $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' ); |
|
| 1429 | + $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' ); |
|
| 1430 | 1430 | |
| 1431 | 1431 | $html .= '</div>'; |
| 1432 | 1432 | break; |
@@ -1501,17 +1501,17 @@ discard block |
||
| 1501 | 1501 | |
| 1502 | 1502 | public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) { |
| 1503 | 1503 | |
| 1504 | - // default field name |
|
| 1505 | - $field_name = 'answer_feedback'; |
|
| 1506 | - if( 'boolean' == $question_type ){ |
|
| 1504 | + // default field name |
|
| 1505 | + $field_name = 'answer_feedback'; |
|
| 1506 | + if( 'boolean' == $question_type ){ |
|
| 1507 | 1507 | |
| 1508 | - $field_name = 'answer_feedback_boolean'; |
|
| 1508 | + $field_name = 'answer_feedback_boolean'; |
|
| 1509 | 1509 | |
| 1510 | - }elseif( 'multiple-choice' == $question_type ){ |
|
| 1510 | + }elseif( 'multiple-choice' == $question_type ){ |
|
| 1511 | 1511 | |
| 1512 | - $field_name = 'answer_feedback_multiple_choice'; |
|
| 1512 | + $field_name = 'answer_feedback_multiple_choice'; |
|
| 1513 | 1513 | |
| 1514 | - }// end if |
|
| 1514 | + }// end if |
|
| 1515 | 1515 | |
| 1516 | 1516 | if( $question_counter ) { |
| 1517 | 1517 | $field_name = 'answer_' . $question_counter . '_feedback'; |
@@ -1716,15 +1716,15 @@ discard block |
||
| 1716 | 1716 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 1717 | 1717 | |
| 1718 | 1718 | // Load the lessons script |
| 1719 | - wp_enqueue_media(); |
|
| 1719 | + wp_enqueue_media(); |
|
| 1720 | 1720 | wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'select2' ,'jquery-ui-sortable' ), Sensei()->version, true ); |
| 1721 | 1721 | wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true ); |
| 1722 | 1722 | wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true ); |
| 1723 | 1723 | |
| 1724 | - // Load the bulk edit screen script |
|
| 1725 | - if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) { |
|
| 1726 | - wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1727 | - } |
|
| 1724 | + // Load the bulk edit screen script |
|
| 1725 | + if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) { |
|
| 1726 | + wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1727 | + } |
|
| 1728 | 1728 | |
| 1729 | 1729 | // Localise script |
| 1730 | 1730 | $translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) ); |
@@ -2027,12 +2027,12 @@ discard block |
||
| 2027 | 2027 | |
| 2028 | 2028 | $quizzes = get_post_meta( $question_id, '_quiz_id', false ); |
| 2029 | 2029 | if( ! in_array( $quiz_id, $quizzes ) ) { |
| 2030 | - add_post_meta( $question_id, '_quiz_id', $quiz_id, false ); |
|
| 2030 | + add_post_meta( $question_id, '_quiz_id', $quiz_id, false ); |
|
| 2031 | 2031 | $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
| 2032 | 2032 | update_post_meta( $lesson_id, '_quiz_has_questions', '1' ); |
| 2033 | - } |
|
| 2033 | + } |
|
| 2034 | 2034 | |
| 2035 | - add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count ); |
|
| 2035 | + add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count ); |
|
| 2036 | 2036 | $question_type = Sensei()->question->get_question_type( $question_id ); |
| 2037 | 2037 | |
| 2038 | 2038 | $return .= $this->quiz_panel_question( $question_type, $question_count, $question_id ); |
@@ -2138,34 +2138,34 @@ discard block |
||
| 2138 | 2138 | $post_content = $course_content; |
| 2139 | 2139 | // Course Query Arguments |
| 2140 | 2140 | $post_type_args = array( 'post_content' => $post_content, |
| 2141 | - 'post_status' => $post_status, |
|
| 2142 | - 'post_title' => $post_title, |
|
| 2143 | - 'post_type' => $post_type |
|
| 2144 | - ); |
|
| 2141 | + 'post_status' => $post_status, |
|
| 2142 | + 'post_title' => $post_title, |
|
| 2143 | + 'post_type' => $post_type |
|
| 2144 | + ); |
|
| 2145 | 2145 | // Only save if there is a valid title |
| 2146 | 2146 | if ( $post_title != '' ) { |
| 2147 | - // Check for prerequisite courses & product id |
|
| 2148 | - $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] ); |
|
| 2149 | - $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] ); |
|
| 2150 | - $course_category_id = absint( $data[ 'course_category' ] ); |
|
| 2151 | - if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; } |
|
| 2152 | - // Insert or Update the Lesson Quiz |
|
| 2153 | - if ( 0 < $course_id ) { |
|
| 2154 | - $post_type_args[ 'ID' ] = $course_id; |
|
| 2155 | - $course_id = wp_update_post($post_type_args); |
|
| 2156 | - update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id ); |
|
| 2157 | - update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id ); |
|
| 2158 | - if ( 0 < $course_category_id ) { |
|
| 2159 | - wp_set_object_terms( $course_id, $course_category_id, 'course-category' ); |
|
| 2160 | - } // End If Statement |
|
| 2161 | - } else { |
|
| 2162 | - $course_id = wp_insert_post($post_type_args); |
|
| 2163 | - add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id ); |
|
| 2164 | - add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id ); |
|
| 2165 | - if ( 0 < $course_category_id ) { |
|
| 2166 | - wp_set_object_terms( $course_id, $course_category_id, 'course-category' ); |
|
| 2167 | - } // End If Statement |
|
| 2168 | - } // End If Statement |
|
| 2147 | + // Check for prerequisite courses & product id |
|
| 2148 | + $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] ); |
|
| 2149 | + $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] ); |
|
| 2150 | + $course_category_id = absint( $data[ 'course_category' ] ); |
|
| 2151 | + if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; } |
|
| 2152 | + // Insert or Update the Lesson Quiz |
|
| 2153 | + if ( 0 < $course_id ) { |
|
| 2154 | + $post_type_args[ 'ID' ] = $course_id; |
|
| 2155 | + $course_id = wp_update_post($post_type_args); |
|
| 2156 | + update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id ); |
|
| 2157 | + update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id ); |
|
| 2158 | + if ( 0 < $course_category_id ) { |
|
| 2159 | + wp_set_object_terms( $course_id, $course_category_id, 'course-category' ); |
|
| 2160 | + } // End If Statement |
|
| 2161 | + } else { |
|
| 2162 | + $course_id = wp_insert_post($post_type_args); |
|
| 2163 | + add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id ); |
|
| 2164 | + add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id ); |
|
| 2165 | + if ( 0 < $course_category_id ) { |
|
| 2166 | + wp_set_object_terms( $course_id, $course_category_id, 'course-category' ); |
|
| 2167 | + } // End If Statement |
|
| 2168 | + } // End If Statement |
|
| 2169 | 2169 | } // End If Statement |
| 2170 | 2170 | // Check that the insert or update saved by testing the post id |
| 2171 | 2171 | if ( 0 < $course_id ) { |
@@ -2256,17 +2256,17 @@ discard block |
||
| 2256 | 2256 | $answer_feedback = ''; |
| 2257 | 2257 | if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) { |
| 2258 | 2258 | |
| 2259 | - $answer_feedback = $data[ 'answer_feedback_boolean' ]; |
|
| 2259 | + $answer_feedback = $data[ 'answer_feedback_boolean' ]; |
|
| 2260 | 2260 | |
| 2261 | 2261 | }elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){ |
| 2262 | 2262 | |
| 2263 | - $answer_feedback = $data[ 'answer_feedback_multiple_choice' ]; |
|
| 2263 | + $answer_feedback = $data[ 'answer_feedback_multiple_choice' ]; |
|
| 2264 | 2264 | |
| 2265 | - }elseif( isset( $data[ 'answer_feedback' ] ) ){ |
|
| 2265 | + }elseif( isset( $data[ 'answer_feedback' ] ) ){ |
|
| 2266 | 2266 | |
| 2267 | - $answer_feedback = $data[ 'answer_feedback' ]; |
|
| 2267 | + $answer_feedback = $data[ 'answer_feedback' ]; |
|
| 2268 | 2268 | |
| 2269 | - } // End If Statement |
|
| 2269 | + } // End If Statement |
|
| 2270 | 2270 | |
| 2271 | 2271 | $post_title = $question_text; |
| 2272 | 2272 | $post_author = $data[ 'post_author' ]; |
@@ -2281,10 +2281,10 @@ discard block |
||
| 2281 | 2281 | } |
| 2282 | 2282 | // Question Query Arguments |
| 2283 | 2283 | $post_type_args = array( 'post_content' => $post_content, |
| 2284 | - 'post_status' => $post_status, |
|
| 2285 | - 'post_title' => $post_title, |
|
| 2286 | - 'post_type' => $post_type |
|
| 2287 | - ); |
|
| 2284 | + 'post_status' => $post_status, |
|
| 2285 | + 'post_title' => $post_title, |
|
| 2286 | + 'post_type' => $post_type |
|
| 2287 | + ); |
|
| 2288 | 2288 | |
| 2289 | 2289 | // Remove empty values and reindex the array |
| 2290 | 2290 | if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) { |
@@ -2320,14 +2320,14 @@ discard block |
||
| 2320 | 2320 | if ( $post_title != '' ) { |
| 2321 | 2321 | |
| 2322 | 2322 | // Get Quiz ID for the question |
| 2323 | - $quiz_id = $data['quiz_id']; |
|
| 2323 | + $quiz_id = $data['quiz_id']; |
|
| 2324 | 2324 | |
| 2325 | - // Get question media |
|
| 2325 | + // Get question media |
|
| 2326 | 2326 | $question_media = $data['question_media']; |
| 2327 | 2327 | |
| 2328 | - // Get answer order |
|
| 2329 | - $answer_order = ''; |
|
| 2330 | - if( isset( $data['answer_order'] ) ) { |
|
| 2328 | + // Get answer order |
|
| 2329 | + $answer_order = ''; |
|
| 2330 | + if( isset( $data['answer_order'] ) ) { |
|
| 2331 | 2331 | $answer_order = $data['answer_order']; |
| 2332 | 2332 | } |
| 2333 | 2333 | |
@@ -2337,38 +2337,38 @@ discard block |
||
| 2337 | 2337 | $random_order = $data['random_order']; |
| 2338 | 2338 | } |
| 2339 | 2339 | |
| 2340 | - // Insert or Update the question |
|
| 2341 | - if ( 0 < $question_id ) { |
|
| 2342 | - |
|
| 2343 | - $post_type_args[ 'ID' ] = $question_id; |
|
| 2344 | - $question_id = wp_update_post( $post_type_args ); |
|
| 2345 | - |
|
| 2346 | - // Update poast meta |
|
| 2347 | - if( 'quiz' == $context ) { |
|
| 2348 | - $quizzes = get_post_meta( $question_id, '_quiz_id', false ); |
|
| 2349 | - if( ! in_array( $quiz_id, $quizzes ) ) { |
|
| 2350 | - add_post_meta( $question_id, '_quiz_id', $quiz_id, false ); |
|
| 2351 | - } |
|
| 2352 | - } |
|
| 2353 | - |
|
| 2354 | - update_post_meta( $question_id, '_question_grade', $question_grade ); |
|
| 2355 | - update_post_meta( $question_id, '_question_right_answer', $question_right_answer ); |
|
| 2356 | - update_post_meta( $question_id, '_right_answer_count', $right_answer_count ); |
|
| 2357 | - update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers ); |
|
| 2358 | - update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count ); |
|
| 2359 | - update_post_meta( $question_id, '_question_media', $question_media ); |
|
| 2360 | - update_post_meta( $question_id, '_answer_order', $answer_order ); |
|
| 2361 | - update_post_meta( $question_id, '_random_order', $random_order ); |
|
| 2362 | - |
|
| 2363 | - if( 'quiz' != $context ) { |
|
| 2364 | - wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false ); |
|
| 2365 | - } |
|
| 2340 | + // Insert or Update the question |
|
| 2341 | + if ( 0 < $question_id ) { |
|
| 2342 | + |
|
| 2343 | + $post_type_args[ 'ID' ] = $question_id; |
|
| 2344 | + $question_id = wp_update_post( $post_type_args ); |
|
| 2345 | + |
|
| 2346 | + // Update poast meta |
|
| 2347 | + if( 'quiz' == $context ) { |
|
| 2348 | + $quizzes = get_post_meta( $question_id, '_quiz_id', false ); |
|
| 2349 | + if( ! in_array( $quiz_id, $quizzes ) ) { |
|
| 2350 | + add_post_meta( $question_id, '_quiz_id', $quiz_id, false ); |
|
| 2351 | + } |
|
| 2352 | + } |
|
| 2353 | + |
|
| 2354 | + update_post_meta( $question_id, '_question_grade', $question_grade ); |
|
| 2355 | + update_post_meta( $question_id, '_question_right_answer', $question_right_answer ); |
|
| 2356 | + update_post_meta( $question_id, '_right_answer_count', $right_answer_count ); |
|
| 2357 | + update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers ); |
|
| 2358 | + update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count ); |
|
| 2359 | + update_post_meta( $question_id, '_question_media', $question_media ); |
|
| 2360 | + update_post_meta( $question_id, '_answer_order', $answer_order ); |
|
| 2361 | + update_post_meta( $question_id, '_random_order', $random_order ); |
|
| 2362 | + |
|
| 2363 | + if( 'quiz' != $context ) { |
|
| 2364 | + wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false ); |
|
| 2365 | + } |
|
| 2366 | 2366 | // Don't store empty value, no point |
| 2367 | 2367 | if ( !empty($answer_feedback) ) { |
| 2368 | 2368 | update_post_meta( $question_id, '_answer_feedback', $answer_feedback ); |
| 2369 | 2369 | } |
| 2370 | 2370 | |
| 2371 | - } else { |
|
| 2371 | + } else { |
|
| 2372 | 2372 | $question_id = wp_insert_post( $post_type_args ); |
| 2373 | 2373 | $question_count = intval( $data['question_count'] ); |
| 2374 | 2374 | ++$question_count; |
@@ -2381,29 +2381,29 @@ discard block |
||
| 2381 | 2381 | } |
| 2382 | 2382 | |
| 2383 | 2383 | if( isset( $question_grade ) ) { |
| 2384 | - add_post_meta( $question_id, '_question_grade', $question_grade ); |
|
| 2385 | - } |
|
| 2386 | - add_post_meta( $question_id, '_question_right_answer', $question_right_answer ); |
|
| 2387 | - add_post_meta( $question_id, '_right_answer_count', $right_answer_count ); |
|
| 2388 | - add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers ); |
|
| 2389 | - add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count ); |
|
| 2390 | - add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count ); |
|
| 2391 | - add_post_meta( $question_id, '_question_media', $question_media ); |
|
| 2392 | - add_post_meta( $question_id, '_answer_order', $answer_order ); |
|
| 2393 | - add_post_meta( $question_id, '_random_order', $random_order ); |
|
| 2384 | + add_post_meta( $question_id, '_question_grade', $question_grade ); |
|
| 2385 | + } |
|
| 2386 | + add_post_meta( $question_id, '_question_right_answer', $question_right_answer ); |
|
| 2387 | + add_post_meta( $question_id, '_right_answer_count', $right_answer_count ); |
|
| 2388 | + add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers ); |
|
| 2389 | + add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count ); |
|
| 2390 | + add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count ); |
|
| 2391 | + add_post_meta( $question_id, '_question_media', $question_media ); |
|
| 2392 | + add_post_meta( $question_id, '_answer_order', $answer_order ); |
|
| 2393 | + add_post_meta( $question_id, '_random_order', $random_order ); |
|
| 2394 | 2394 | // Don't store empty value, no point |
| 2395 | 2395 | if ( !empty($answer_feedback) ) { |
| 2396 | 2396 | add_post_meta( $question_id, '_answer_feedback', $answer_feedback ); |
| 2397 | 2397 | } |
| 2398 | 2398 | |
| 2399 | - // Set the post terms for question-type |
|
| 2400 | - wp_set_post_terms( $question_id, array( $question_type ), 'question-type' ); |
|
| 2399 | + // Set the post terms for question-type |
|
| 2400 | + wp_set_post_terms( $question_id, array( $question_type ), 'question-type' ); |
|
| 2401 | 2401 | |
| 2402 | - if( $question_category ) { |
|
| 2403 | - wp_set_post_terms( $question_id, array( $question_category ), 'question-category' ); |
|
| 2404 | - } |
|
| 2402 | + if( $question_category ) { |
|
| 2403 | + wp_set_post_terms( $question_id, array( $question_category ), 'question-category' ); |
|
| 2404 | + } |
|
| 2405 | 2405 | |
| 2406 | - } // End If Statement |
|
| 2406 | + } // End If Statement |
|
| 2407 | 2407 | } // End If Statement |
| 2408 | 2408 | // Check that the insert or update saved by testing the post id |
| 2409 | 2409 | if ( 0 < $question_id ) { |
@@ -2452,7 +2452,7 @@ discard block |
||
| 2452 | 2452 | public function lesson_complexities() { |
| 2453 | 2453 | |
| 2454 | 2454 | // V2 - make filter for this array |
| 2455 | - $lesson_complexities = array( 'easy' => __( 'Easy', 'woothemes-sensei' ), |
|
| 2455 | + $lesson_complexities = array( 'easy' => __( 'Easy', 'woothemes-sensei' ), |
|
| 2456 | 2456 | 'std' => __( 'Standard', 'woothemes-sensei' ), |
| 2457 | 2457 | 'hard' => __( 'Hard', 'woothemes-sensei' ) |
| 2458 | 2458 | ); |
@@ -2519,14 +2519,14 @@ discard block |
||
| 2519 | 2519 | $post_args = array( 'post_type' => 'quiz', |
| 2520 | 2520 | 'posts_per_page' => 1, |
| 2521 | 2521 | 'orderby' => 'title', |
| 2522 | - 'order' => 'DESC', |
|
| 2523 | - 'post_parent' => $lesson_id, |
|
| 2524 | - 'post_status' => $post_status, |
|
| 2522 | + 'order' => 'DESC', |
|
| 2523 | + 'post_parent' => $lesson_id, |
|
| 2524 | + 'post_status' => $post_status, |
|
| 2525 | 2525 | 'suppress_filters' => 0, |
| 2526 | 2526 | 'fields' => $fields |
| 2527 | 2527 | ); |
| 2528 | 2528 | $posts_array = get_posts( $post_args ); |
| 2529 | - $quiz_id = array_shift($posts_array); |
|
| 2529 | + $quiz_id = array_shift($posts_array); |
|
| 2530 | 2530 | |
| 2531 | 2531 | return $quiz_id; |
| 2532 | 2532 | } // End lesson_quizzes() |
@@ -2534,34 +2534,34 @@ discard block |
||
| 2534 | 2534 | |
| 2535 | 2535 | /** |
| 2536 | 2536 | * Fetches all the questions for a quiz depending on certain conditions. |
| 2537 | - * |
|
| 2538 | - * Determine which questions should be shown depending on: |
|
| 2539 | - * - admin/teacher selected questions to be shown |
|
| 2540 | - * - questions shown to a user previously (saved as asked questions) |
|
| 2541 | - * - limit number of questions lesson setting |
|
| 2542 | 2537 | * |
| 2543 | - * @since 1.0 |
|
| 2538 | + * Determine which questions should be shown depending on: |
|
| 2539 | + * - admin/teacher selected questions to be shown |
|
| 2540 | + * - questions shown to a user previously (saved as asked questions) |
|
| 2541 | + * - limit number of questions lesson setting |
|
| 2542 | + * |
|
| 2543 | + * @since 1.0 |
|
| 2544 | 2544 | * @param int $quiz_id (default: 0) |
| 2545 | 2545 | * @param string $post_status (default: 'publish') |
| 2546 | 2546 | * @param string $orderby (default: 'meta_value_num title') |
| 2547 | 2547 | * @param string $order (default: 'ASC') |
| 2548 | - * |
|
| 2548 | + * |
|
| 2549 | 2549 | * @return array $questions { $question type WP_Post } |
| 2550 | 2550 | */ |
| 2551 | 2551 | public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) { |
| 2552 | 2552 | |
| 2553 | 2553 | $quiz_id = (string) $quiz_id; |
| 2554 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 2554 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 2555 | 2555 | |
| 2556 | - // setup the user id |
|
| 2557 | - if( is_admin() ) { |
|
| 2558 | - $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ; |
|
| 2559 | - } else { |
|
| 2560 | - $user_id = get_current_user_id(); |
|
| 2561 | - } |
|
| 2556 | + // setup the user id |
|
| 2557 | + if( is_admin() ) { |
|
| 2558 | + $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ; |
|
| 2559 | + } else { |
|
| 2560 | + $user_id = get_current_user_id(); |
|
| 2561 | + } |
|
| 2562 | 2562 | |
| 2563 | - // get the users current status on the lesson |
|
| 2564 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id ); |
|
| 2563 | + // get the users current status on the lesson |
|
| 2564 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id ); |
|
| 2565 | 2565 | |
| 2566 | 2566 | // Set the default question order if it has not already been set for this quiz |
| 2567 | 2567 | $this->set_default_question_order( $quiz_id ); |
@@ -2591,14 +2591,14 @@ discard block |
||
| 2591 | 2591 | 'suppress_filters' => 0 |
| 2592 | 2592 | ); |
| 2593 | 2593 | |
| 2594 | - //query the questions |
|
| 2594 | + //query the questions |
|
| 2595 | 2595 | $questions_query = new WP_Query( $question_query_args ); |
| 2596 | 2596 | |
| 2597 | - // Set return array to initially include all items |
|
| 2598 | - $questions = $questions_query->posts; |
|
| 2597 | + // Set return array to initially include all items |
|
| 2598 | + $questions = $questions_query->posts; |
|
| 2599 | 2599 | |
| 2600 | - // set the questions array that will be manipulated within this function |
|
| 2601 | - $questions_array = $questions_query->posts; |
|
| 2600 | + // set the questions array that will be manipulated within this function |
|
| 2601 | + $questions_array = $questions_query->posts; |
|
| 2602 | 2602 | |
| 2603 | 2603 | // If viewing quiz on frontend or in grading then only single questions must be shown |
| 2604 | 2604 | $selected_questions = false; |
@@ -2711,36 +2711,36 @@ discard block |
||
| 2711 | 2711 | } |
| 2712 | 2712 | } |
| 2713 | 2713 | |
| 2714 | - // Save the questions that will be asked for the current user |
|
| 2715 | - // this happens only once per user/quiz, unless the user resets the quiz |
|
| 2716 | - if( ! is_admin() ){ |
|
| 2714 | + // Save the questions that will be asked for the current user |
|
| 2715 | + // this happens only once per user/quiz, unless the user resets the quiz |
|
| 2716 | + if( ! is_admin() ){ |
|
| 2717 | 2717 | |
| 2718 | - if( $user_lesson_status ) { |
|
| 2718 | + if( $user_lesson_status ) { |
|
| 2719 | 2719 | |
| 2720 | - $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); |
|
| 2721 | - if ( empty($questions_asked) && $user_lesson_status) { |
|
| 2720 | + $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); |
|
| 2721 | + if ( empty($questions_asked) && $user_lesson_status) { |
|
| 2722 | 2722 | |
| 2723 | - $questions_asked = array(); |
|
| 2724 | - foreach ($questions as $question) { |
|
| 2723 | + $questions_asked = array(); |
|
| 2724 | + foreach ($questions as $question) { |
|
| 2725 | 2725 | |
| 2726 | - $questions_asked[] = $question->ID; |
|
| 2726 | + $questions_asked[] = $question->ID; |
|
| 2727 | 2727 | |
| 2728 | - } |
|
| 2728 | + } |
|
| 2729 | 2729 | |
| 2730 | - // save the questions asked id |
|
| 2731 | - $questions_asked_csv = implode(',', $questions_asked); |
|
| 2732 | - update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv); |
|
| 2730 | + // save the questions asked id |
|
| 2731 | + $questions_asked_csv = implode(',', $questions_asked); |
|
| 2732 | + update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv); |
|
| 2733 | 2733 | |
| 2734 | - } |
|
| 2735 | - } |
|
| 2736 | - } |
|
| 2734 | + } |
|
| 2735 | + } |
|
| 2736 | + } |
|
| 2737 | 2737 | |
| 2738 | - /** |
|
| 2739 | - * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions |
|
| 2740 | - * |
|
| 2741 | - * @hooked Sensei_Teacher::allow_teacher_access_to_questions |
|
| 2742 | - * @since 1.8.0 |
|
| 2743 | - */ |
|
| 2738 | + /** |
|
| 2739 | + * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions |
|
| 2740 | + * |
|
| 2741 | + * @hooked Sensei_Teacher::allow_teacher_access_to_questions |
|
| 2742 | + * @since 1.8.0 |
|
| 2743 | + */ |
|
| 2744 | 2744 | return apply_filters( 'sensei_lesson_quiz_questions', $questions, $quiz_id ); |
| 2745 | 2745 | |
| 2746 | 2746 | } // End lesson_quiz_questions() |
@@ -2844,7 +2844,7 @@ discard block |
||
| 2844 | 2844 | // Display Image Placeholder if none |
| 2845 | 2845 | if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) { |
| 2846 | 2846 | |
| 2847 | - $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 2847 | + $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 2848 | 2848 | |
| 2849 | 2849 | } // End If Statement |
| 2850 | 2850 | |
@@ -2860,401 +2860,401 @@ discard block |
||
| 2860 | 2860 | * Returns the the lesson excerpt. |
| 2861 | 2861 | * |
| 2862 | 2862 | * @param WP_Post $lesson |
| 2863 | - * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop() |
|
| 2863 | + * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop() |
|
| 2864 | 2864 | * @return string |
| 2865 | 2865 | */ |
| 2866 | 2866 | public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) { |
| 2867 | 2867 | $html = ''; |
| 2868 | 2868 | if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) { |
| 2869 | 2869 | |
| 2870 | - $excerpt = $lesson->post_excerpt; |
|
| 2870 | + $excerpt = $lesson->post_excerpt; |
|
| 2871 | 2871 | |
| 2872 | - // if $add_p_tags true wrap with <p> else return the excerpt as is |
|
| 2873 | - $html = $add_p_tags ? wpautop( $excerpt ) : $excerpt; |
|
| 2872 | + // if $add_p_tags true wrap with <p> else return the excerpt as is |
|
| 2873 | + $html = $add_p_tags ? wpautop( $excerpt ) : $excerpt; |
|
| 2874 | 2874 | |
| 2875 | 2875 | } |
| 2876 | 2876 | return apply_filters( 'sensei_lesson_excerpt', $html ); |
| 2877 | 2877 | |
| 2878 | 2878 | } // End lesson_excerpt() |
| 2879 | 2879 | |
| 2880 | - /** |
|
| 2881 | - * Returns the course for a given lesson |
|
| 2882 | - * |
|
| 2883 | - * @since 1.7.4 |
|
| 2884 | - * @access public |
|
| 2885 | - * |
|
| 2886 | - * @param int $lesson_id |
|
| 2887 | - * @return int|bool $course_id or bool when nothing is found. |
|
| 2888 | - */ |
|
| 2889 | - public function get_course_id( $lesson_id ){ |
|
| 2890 | - |
|
| 2891 | - if( ! isset( $lesson_id ) || empty( $lesson_id ) |
|
| 2892 | - || 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 2893 | - return false; |
|
| 2894 | - } |
|
| 2895 | - |
|
| 2896 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true); |
|
| 2897 | - |
|
| 2898 | - // make sure the course id is valid |
|
| 2899 | - if( empty( $lesson_course_id ) |
|
| 2900 | - || is_array( $lesson_course_id ) |
|
| 2901 | - || intval( $lesson_course_id ) < 1 |
|
| 2902 | - || 'course' != get_post_type( $lesson_course_id ) ){ |
|
| 2903 | - |
|
| 2904 | - return false; |
|
| 2905 | - |
|
| 2906 | - } |
|
| 2907 | - |
|
| 2908 | - return $lesson_course_id; |
|
| 2909 | - |
|
| 2910 | - }// en get_course_id |
|
| 2911 | - |
|
| 2912 | - /** |
|
| 2913 | - * Add the admin all lessons screen edit options. |
|
| 2914 | - * |
|
| 2915 | - * The fields in this function work for both quick and bulk edit. The ID attributes is used |
|
| 2916 | - * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then |
|
| 2917 | - * name attribute is will be used by the quick edit and submitted via standard POST. This |
|
| 2918 | - * will use this classes save_post_meta function to save the new field data. |
|
| 2919 | - * |
|
| 2920 | - * @hooked quick_edit_custom_box |
|
| 2921 | - * @hooked bulk_edit_custom_box |
|
| 2922 | - * |
|
| 2923 | - * @since 1.8.0 |
|
| 2924 | - * |
|
| 2925 | - * @param string $column_name |
|
| 2926 | - * @param string $post_type |
|
| 2927 | - * @return void |
|
| 2928 | - */ |
|
| 2929 | - public function all_lessons_edit_fields( $column_name, $post_type ) { |
|
| 2930 | - |
|
| 2931 | - // only show these options ont he lesson post type edit screen |
|
| 2932 | - if( 'lesson' != $post_type || 'lesson-course' != $column_name ){ |
|
| 2933 | - return; |
|
| 2934 | - } |
|
| 2935 | - |
|
| 2936 | - ?> |
|
| 2880 | + /** |
|
| 2881 | + * Returns the course for a given lesson |
|
| 2882 | + * |
|
| 2883 | + * @since 1.7.4 |
|
| 2884 | + * @access public |
|
| 2885 | + * |
|
| 2886 | + * @param int $lesson_id |
|
| 2887 | + * @return int|bool $course_id or bool when nothing is found. |
|
| 2888 | + */ |
|
| 2889 | + public function get_course_id( $lesson_id ){ |
|
| 2890 | + |
|
| 2891 | + if( ! isset( $lesson_id ) || empty( $lesson_id ) |
|
| 2892 | + || 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 2893 | + return false; |
|
| 2894 | + } |
|
| 2895 | + |
|
| 2896 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true); |
|
| 2897 | + |
|
| 2898 | + // make sure the course id is valid |
|
| 2899 | + if( empty( $lesson_course_id ) |
|
| 2900 | + || is_array( $lesson_course_id ) |
|
| 2901 | + || intval( $lesson_course_id ) < 1 |
|
| 2902 | + || 'course' != get_post_type( $lesson_course_id ) ){ |
|
| 2903 | + |
|
| 2904 | + return false; |
|
| 2905 | + |
|
| 2906 | + } |
|
| 2907 | + |
|
| 2908 | + return $lesson_course_id; |
|
| 2909 | + |
|
| 2910 | + }// en get_course_id |
|
| 2911 | + |
|
| 2912 | + /** |
|
| 2913 | + * Add the admin all lessons screen edit options. |
|
| 2914 | + * |
|
| 2915 | + * The fields in this function work for both quick and bulk edit. The ID attributes is used |
|
| 2916 | + * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then |
|
| 2917 | + * name attribute is will be used by the quick edit and submitted via standard POST. This |
|
| 2918 | + * will use this classes save_post_meta function to save the new field data. |
|
| 2919 | + * |
|
| 2920 | + * @hooked quick_edit_custom_box |
|
| 2921 | + * @hooked bulk_edit_custom_box |
|
| 2922 | + * |
|
| 2923 | + * @since 1.8.0 |
|
| 2924 | + * |
|
| 2925 | + * @param string $column_name |
|
| 2926 | + * @param string $post_type |
|
| 2927 | + * @return void |
|
| 2928 | + */ |
|
| 2929 | + public function all_lessons_edit_fields( $column_name, $post_type ) { |
|
| 2930 | + |
|
| 2931 | + // only show these options ont he lesson post type edit screen |
|
| 2932 | + if( 'lesson' != $post_type || 'lesson-course' != $column_name ){ |
|
| 2933 | + return; |
|
| 2934 | + } |
|
| 2935 | + |
|
| 2936 | + ?> |
|
| 2937 | 2937 | <fieldset class="sensei-edit-field-set inline-edit-lesson"> |
| 2938 | 2938 | <div class="sensei-inline-edit-col column-<?php echo $column_name ?>"> |
| 2939 | 2939 | <?php |
| 2940 | - echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>'; |
|
| 2941 | - // create a nonce field to be used as a security measure when saving the data |
|
| 2942 | - wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' ); |
|
| 2943 | - wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce' ); |
|
| 2944 | - |
|
| 2945 | - // unchanged option - we need this in because |
|
| 2946 | - // the default option in bulk edit should not be empty. If it is |
|
| 2947 | - // the user will erase data they didn't want to touch. |
|
| 2948 | - $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --'; |
|
| 2949 | - |
|
| 2950 | - // |
|
| 2951 | - //course selection |
|
| 2952 | - // |
|
| 2953 | - $courses = WooThemes_Sensei_Course::get_all_courses(); |
|
| 2954 | - $course_options = array(); |
|
| 2955 | - if ( count( $courses ) > 0 ) { |
|
| 2956 | - foreach ($courses as $course ){ |
|
| 2957 | - $course_options[ $course->ID ] = get_the_title( $course->ID ); |
|
| 2958 | - } |
|
| 2959 | - } |
|
| 2960 | - //pre-append the no change option |
|
| 2961 | - $course_options['-1']= $no_change_text; |
|
| 2962 | - $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' ); |
|
| 2963 | - $course_field = Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes ); |
|
| 2964 | - echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'), $course_field ); |
|
| 2965 | - |
|
| 2966 | - // |
|
| 2967 | - // lesson complexity selection |
|
| 2968 | - // |
|
| 2969 | - $lesson_complexities = $this->lesson_complexities(); |
|
| 2970 | - //pre-append the no change option |
|
| 2971 | - $lesson_complexities['-1']= $no_change_text; |
|
| 2972 | - $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' '); |
|
| 2973 | - $complexity_filed = Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes ); |
|
| 2974 | - echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'), $complexity_filed ); |
|
| 2975 | - |
|
| 2976 | - ?> |
|
| 2940 | + echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>'; |
|
| 2941 | + // create a nonce field to be used as a security measure when saving the data |
|
| 2942 | + wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' ); |
|
| 2943 | + wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce' ); |
|
| 2944 | + |
|
| 2945 | + // unchanged option - we need this in because |
|
| 2946 | + // the default option in bulk edit should not be empty. If it is |
|
| 2947 | + // the user will erase data they didn't want to touch. |
|
| 2948 | + $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --'; |
|
| 2949 | + |
|
| 2950 | + // |
|
| 2951 | + //course selection |
|
| 2952 | + // |
|
| 2953 | + $courses = WooThemes_Sensei_Course::get_all_courses(); |
|
| 2954 | + $course_options = array(); |
|
| 2955 | + if ( count( $courses ) > 0 ) { |
|
| 2956 | + foreach ($courses as $course ){ |
|
| 2957 | + $course_options[ $course->ID ] = get_the_title( $course->ID ); |
|
| 2958 | + } |
|
| 2959 | + } |
|
| 2960 | + //pre-append the no change option |
|
| 2961 | + $course_options['-1']= $no_change_text; |
|
| 2962 | + $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' ); |
|
| 2963 | + $course_field = Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes ); |
|
| 2964 | + echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'), $course_field ); |
|
| 2965 | + |
|
| 2966 | + // |
|
| 2967 | + // lesson complexity selection |
|
| 2968 | + // |
|
| 2969 | + $lesson_complexities = $this->lesson_complexities(); |
|
| 2970 | + //pre-append the no change option |
|
| 2971 | + $lesson_complexities['-1']= $no_change_text; |
|
| 2972 | + $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' '); |
|
| 2973 | + $complexity_filed = Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes ); |
|
| 2974 | + echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'), $complexity_filed ); |
|
| 2975 | + |
|
| 2976 | + ?> |
|
| 2977 | 2977 | |
| 2978 | 2978 | <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4> |
| 2979 | 2979 | |
| 2980 | 2980 | <?php |
| 2981 | 2981 | |
| 2982 | - // |
|
| 2983 | - // Lesson require pass to complete |
|
| 2984 | - // |
|
| 2985 | - $pass_required_options = array( |
|
| 2986 | - '-1' => $no_change_text, |
|
| 2987 | - '0' => __('No','woothemes'), |
|
| 2988 | - '1' => __('Yes','woothemes'), |
|
| 2989 | - ); |
|
| 2990 | - |
|
| 2991 | - $pass_required_select_attributes = array( 'name'=> 'pass_required', |
|
| 2992 | - 'id'=> 'sensei-edit-lesson-pass-required', |
|
| 2993 | - 'class'=>' ' ); |
|
| 2994 | - $require_pass_field = Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false ); |
|
| 2995 | - echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'), $require_pass_field ); |
|
| 2996 | - |
|
| 2997 | - // |
|
| 2998 | - // Quiz pass percentage |
|
| 2999 | - // |
|
| 3000 | - $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />'; |
|
| 3001 | - echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field ); |
|
| 3002 | - |
|
| 3003 | - // |
|
| 3004 | - // Enable quiz reset button |
|
| 3005 | - // |
|
| 3006 | - $quiz_reset_select__options = array( |
|
| 3007 | - '-1' => $no_change_text, |
|
| 3008 | - '0' => __('No','woothemes'), |
|
| 3009 | - '1' => __('Yes','woothemes'), |
|
| 3010 | - ); |
|
| 3011 | - $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset'; |
|
| 3012 | - $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' ); |
|
| 3013 | - $quiz_reset_field = Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false ); |
|
| 3014 | - echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field ); |
|
| 3015 | - |
|
| 3016 | - ?> |
|
| 2982 | + // |
|
| 2983 | + // Lesson require pass to complete |
|
| 2984 | + // |
|
| 2985 | + $pass_required_options = array( |
|
| 2986 | + '-1' => $no_change_text, |
|
| 2987 | + '0' => __('No','woothemes'), |
|
| 2988 | + '1' => __('Yes','woothemes'), |
|
| 2989 | + ); |
|
| 2990 | + |
|
| 2991 | + $pass_required_select_attributes = array( 'name'=> 'pass_required', |
|
| 2992 | + 'id'=> 'sensei-edit-lesson-pass-required', |
|
| 2993 | + 'class'=>' ' ); |
|
| 2994 | + $require_pass_field = Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false ); |
|
| 2995 | + echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'), $require_pass_field ); |
|
| 2996 | + |
|
| 2997 | + // |
|
| 2998 | + // Quiz pass percentage |
|
| 2999 | + // |
|
| 3000 | + $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />'; |
|
| 3001 | + echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field ); |
|
| 3002 | + |
|
| 3003 | + // |
|
| 3004 | + // Enable quiz reset button |
|
| 3005 | + // |
|
| 3006 | + $quiz_reset_select__options = array( |
|
| 3007 | + '-1' => $no_change_text, |
|
| 3008 | + '0' => __('No','woothemes'), |
|
| 3009 | + '1' => __('Yes','woothemes'), |
|
| 3010 | + ); |
|
| 3011 | + $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset'; |
|
| 3012 | + $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' ); |
|
| 3013 | + $quiz_reset_field = Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false ); |
|
| 3014 | + echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field ); |
|
| 3015 | + |
|
| 3016 | + ?> |
|
| 3017 | 3017 | </div> |
| 3018 | 3018 | </fieldset> |
| 3019 | 3019 | <?php |
| 3020 | - }// all_lessons_edit_fields |
|
| 3021 | - |
|
| 3022 | - /** |
|
| 3023 | - * Create the html for the edit field |
|
| 3024 | - * |
|
| 3025 | - * Wraps the passed in field and title combination with the correct html. |
|
| 3026 | - * |
|
| 3027 | - * @since 1.8.0 |
|
| 3028 | - * |
|
| 3029 | - * @param string $title that will stand to the left of the field. |
|
| 3030 | - * @param string $field type markup for the field that must be wrapped. |
|
| 3031 | - * @return string $field_html |
|
| 3032 | - */ |
|
| 3033 | - public function generate_all_lessons_edit_field( $title ,$field ){ |
|
| 3034 | - |
|
| 3035 | - $html = ''; |
|
| 3036 | - $html = '<div class="inline-edit-group" >'; |
|
| 3037 | - $html .= '<span class="title">'. $title .'</span> '; |
|
| 3038 | - $html .= '<span class="input-text-wrap">'; |
|
| 3039 | - $html .= $field; |
|
| 3040 | - $html .= '</span>'; |
|
| 3041 | - $html .= '</label></div>'; |
|
| 3042 | - |
|
| 3043 | - return $html ; |
|
| 3044 | - |
|
| 3045 | - }//end generate_all_lessons_edit_field |
|
| 3046 | - |
|
| 3047 | - /** |
|
| 3048 | - * Respond to the ajax call from the bulk edit save function. This comes |
|
| 3049 | - * from the admin all lesson screen. |
|
| 3050 | - * |
|
| 3051 | - * @since 1.8.0 |
|
| 3052 | - * @return void |
|
| 3053 | - */ |
|
| 3054 | - function save_all_lessons_edit_fields() { |
|
| 3055 | - |
|
| 3056 | - // verify all the data before attempting to save |
|
| 3057 | - if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' ) |
|
| 3058 | - || empty( $_POST[ 'post_ids' ] ) || ! is_array( $_POST[ 'post_ids' ] ) ) { |
|
| 3059 | - die(); |
|
| 3060 | - } |
|
| 3061 | - |
|
| 3062 | - // get our variables |
|
| 3063 | - $new_course = sanitize_text_field( $_POST['sensei_edit_lesson_course'] ); |
|
| 3064 | - $new_complexity = sanitize_text_field( $_POST['sensei_edit_complexity'] ); |
|
| 3065 | - $new_pass_required = sanitize_text_field( $_POST['sensei_edit_pass_required'] ); |
|
| 3066 | - $new_pass_percentage = sanitize_text_field( $_POST['sensei_edit_pass_percentage'] ); |
|
| 3067 | - $new_enable_quiz_reset = sanitize_text_field( $_POST['sensei_edit_enable_quiz_reset'] ); |
|
| 3068 | - // store the values for all selected posts |
|
| 3069 | - foreach( $_POST[ 'post_ids' ] as $lesson_id ) { |
|
| 3070 | - |
|
| 3071 | - // get the quiz id needed for the quiz meta |
|
| 3072 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 3073 | - |
|
| 3074 | - // do not save the items if the value is -1 as this |
|
| 3075 | - // means it was not changed |
|
| 3076 | - |
|
| 3077 | - // update lesson course |
|
| 3078 | - if( -1 != $new_course ){ |
|
| 3079 | - update_post_meta( $lesson_id, '_lesson_course', $new_course ); |
|
| 3080 | - } |
|
| 3081 | - // update lesson complexity |
|
| 3082 | - if( -1 != $new_complexity ){ |
|
| 3083 | - update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity ); |
|
| 3084 | - } |
|
| 3085 | - |
|
| 3086 | - // Quiz Related settings |
|
| 3087 | - if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) { |
|
| 3088 | - |
|
| 3089 | - // update pass required |
|
| 3090 | - if (-1 != $new_pass_required) { |
|
| 3091 | - |
|
| 3092 | - $checked = $new_pass_required ? 'on' : ''; |
|
| 3093 | - update_post_meta($quiz_id, '_pass_required', $checked); |
|
| 3094 | - unset( $checked ); |
|
| 3095 | - } |
|
| 3020 | + }// all_lessons_edit_fields |
|
| 3021 | + |
|
| 3022 | + /** |
|
| 3023 | + * Create the html for the edit field |
|
| 3024 | + * |
|
| 3025 | + * Wraps the passed in field and title combination with the correct html. |
|
| 3026 | + * |
|
| 3027 | + * @since 1.8.0 |
|
| 3028 | + * |
|
| 3029 | + * @param string $title that will stand to the left of the field. |
|
| 3030 | + * @param string $field type markup for the field that must be wrapped. |
|
| 3031 | + * @return string $field_html |
|
| 3032 | + */ |
|
| 3033 | + public function generate_all_lessons_edit_field( $title ,$field ){ |
|
| 3034 | + |
|
| 3035 | + $html = ''; |
|
| 3036 | + $html = '<div class="inline-edit-group" >'; |
|
| 3037 | + $html .= '<span class="title">'. $title .'</span> '; |
|
| 3038 | + $html .= '<span class="input-text-wrap">'; |
|
| 3039 | + $html .= $field; |
|
| 3040 | + $html .= '</span>'; |
|
| 3041 | + $html .= '</label></div>'; |
|
| 3042 | + |
|
| 3043 | + return $html ; |
|
| 3044 | + |
|
| 3045 | + }//end generate_all_lessons_edit_field |
|
| 3046 | + |
|
| 3047 | + /** |
|
| 3048 | + * Respond to the ajax call from the bulk edit save function. This comes |
|
| 3049 | + * from the admin all lesson screen. |
|
| 3050 | + * |
|
| 3051 | + * @since 1.8.0 |
|
| 3052 | + * @return void |
|
| 3053 | + */ |
|
| 3054 | + function save_all_lessons_edit_fields() { |
|
| 3096 | 3055 | |
| 3097 | - // update pass percentage |
|
| 3098 | - if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){ |
|
| 3056 | + // verify all the data before attempting to save |
|
| 3057 | + if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' ) |
|
| 3058 | + || empty( $_POST[ 'post_ids' ] ) || ! is_array( $_POST[ 'post_ids' ] ) ) { |
|
| 3059 | + die(); |
|
| 3060 | + } |
|
| 3099 | 3061 | |
| 3100 | - update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage); |
|
| 3062 | + // get our variables |
|
| 3063 | + $new_course = sanitize_text_field( $_POST['sensei_edit_lesson_course'] ); |
|
| 3064 | + $new_complexity = sanitize_text_field( $_POST['sensei_edit_complexity'] ); |
|
| 3065 | + $new_pass_required = sanitize_text_field( $_POST['sensei_edit_pass_required'] ); |
|
| 3066 | + $new_pass_percentage = sanitize_text_field( $_POST['sensei_edit_pass_percentage'] ); |
|
| 3067 | + $new_enable_quiz_reset = sanitize_text_field( $_POST['sensei_edit_enable_quiz_reset'] ); |
|
| 3068 | + // store the values for all selected posts |
|
| 3069 | + foreach( $_POST[ 'post_ids' ] as $lesson_id ) { |
|
| 3101 | 3070 | |
| 3102 | - } |
|
| 3071 | + // get the quiz id needed for the quiz meta |
|
| 3072 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 3103 | 3073 | |
| 3104 | - // |
|
| 3105 | - // update enable quiz reset |
|
| 3106 | - // |
|
| 3107 | - if (-1 != $new_enable_quiz_reset ) { |
|
| 3074 | + // do not save the items if the value is -1 as this |
|
| 3075 | + // means it was not changed |
|
| 3108 | 3076 | |
| 3109 | - $checked = $new_enable_quiz_reset ? 'on' : '' ; |
|
| 3110 | - update_post_meta($quiz_id, '_enable_quiz_reset', $checked); |
|
| 3111 | - unset( $checked ); |
|
| 3077 | + // update lesson course |
|
| 3078 | + if( -1 != $new_course ){ |
|
| 3079 | + update_post_meta( $lesson_id, '_lesson_course', $new_course ); |
|
| 3080 | + } |
|
| 3081 | + // update lesson complexity |
|
| 3082 | + if( -1 != $new_complexity ){ |
|
| 3083 | + update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity ); |
|
| 3084 | + } |
|
| 3112 | 3085 | |
| 3113 | - } |
|
| 3086 | + // Quiz Related settings |
|
| 3087 | + if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) { |
|
| 3114 | 3088 | |
| 3089 | + // update pass required |
|
| 3090 | + if (-1 != $new_pass_required) { |
|
| 3115 | 3091 | |
| 3116 | - } // end if quiz |
|
| 3092 | + $checked = $new_pass_required ? 'on' : ''; |
|
| 3093 | + update_post_meta($quiz_id, '_pass_required', $checked); |
|
| 3094 | + unset( $checked ); |
|
| 3095 | + } |
|
| 3117 | 3096 | |
| 3118 | - }// end for each |
|
| 3097 | + // update pass percentage |
|
| 3098 | + if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){ |
|
| 3119 | 3099 | |
| 3120 | - die(); |
|
| 3100 | + update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage); |
|
| 3121 | 3101 | |
| 3122 | - } // end save_all_lessons_edit_fields |
|
| 3102 | + } |
|
| 3123 | 3103 | |
| 3124 | - /** |
|
| 3125 | - * Loading the quick edit fields defaults. |
|
| 3126 | - * |
|
| 3127 | - * This function will localise the default values along with the script that will |
|
| 3128 | - * add these values to the inputs. |
|
| 3129 | - * |
|
| 3130 | - * NOTE: this function runs for each row in the edit column |
|
| 3131 | - * |
|
| 3132 | - * @since 1.8.0 |
|
| 3133 | - * @return void |
|
| 3134 | - */ |
|
| 3135 | - public function set_quick_edit_admin_defaults( $column_name, $post_id ){ |
|
| 3104 | + // |
|
| 3105 | + // update enable quiz reset |
|
| 3106 | + // |
|
| 3107 | + if (-1 != $new_enable_quiz_reset ) { |
|
| 3136 | 3108 | |
| 3137 | - if( 'lesson-course' != $column_name ){ |
|
| 3138 | - return; |
|
| 3139 | - } |
|
| 3140 | - // load the script |
|
| 3141 | - $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 3142 | - wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true ); |
|
| 3109 | + $checked = $new_enable_quiz_reset ? 'on' : '' ; |
|
| 3110 | + update_post_meta($quiz_id, '_enable_quiz_reset', $checked); |
|
| 3111 | + unset( $checked ); |
|
| 3143 | 3112 | |
| 3144 | - // setup the values for all meta fields |
|
| 3145 | - $data = array(); |
|
| 3146 | - foreach( $this->meta_fields as $field ){ |
|
| 3113 | + } |
|
| 3147 | 3114 | |
| 3148 | - $data[$field] = get_post_meta( $post_id, '_'.$field, true ); |
|
| 3149 | 3115 | |
| 3150 | - } |
|
| 3151 | - // add quiz meta fields |
|
| 3152 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id ); |
|
| 3153 | - foreach( Sensei()->quiz->meta_fields as $field ){ |
|
| 3116 | + } // end if quiz |
|
| 3154 | 3117 | |
| 3155 | - $data[$field] = get_post_meta( $quiz_id, '_'.$field, true ); |
|
| 3118 | + }// end for each |
|
| 3156 | 3119 | |
| 3157 | - } |
|
| 3120 | + die(); |
|
| 3158 | 3121 | |
| 3159 | - wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data ); |
|
| 3122 | + } // end save_all_lessons_edit_fields |
|
| 3160 | 3123 | |
| 3161 | - }// end quick edit admin defaults |
|
| 3124 | + /** |
|
| 3125 | + * Loading the quick edit fields defaults. |
|
| 3126 | + * |
|
| 3127 | + * This function will localise the default values along with the script that will |
|
| 3128 | + * add these values to the inputs. |
|
| 3129 | + * |
|
| 3130 | + * NOTE: this function runs for each row in the edit column |
|
| 3131 | + * |
|
| 3132 | + * @since 1.8.0 |
|
| 3133 | + * @return void |
|
| 3134 | + */ |
|
| 3135 | + public function set_quick_edit_admin_defaults( $column_name, $post_id ){ |
|
| 3162 | 3136 | |
| 3163 | - /** |
|
| 3164 | - * Filter the classes for lessons on the single course page. |
|
| 3165 | - * |
|
| 3166 | - * Adds the nesecary classes depending on the user data |
|
| 3167 | - * |
|
| 3168 | - * @since 1.9.0 |
|
| 3169 | - * @param array $classes |
|
| 3170 | - * @return array $classes |
|
| 3171 | - */ |
|
| 3172 | - public static function single_course_lessons_classes( $classes ){ |
|
| 3137 | + if( 'lesson-course' != $column_name ){ |
|
| 3138 | + return; |
|
| 3139 | + } |
|
| 3140 | + // load the script |
|
| 3141 | + $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 3142 | + wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true ); |
|
| 3143 | + |
|
| 3144 | + // setup the values for all meta fields |
|
| 3145 | + $data = array(); |
|
| 3146 | + foreach( $this->meta_fields as $field ){ |
|
| 3147 | + |
|
| 3148 | + $data[$field] = get_post_meta( $post_id, '_'.$field, true ); |
|
| 3149 | + |
|
| 3150 | + } |
|
| 3151 | + // add quiz meta fields |
|
| 3152 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id ); |
|
| 3153 | + foreach( Sensei()->quiz->meta_fields as $field ){ |
|
| 3154 | + |
|
| 3155 | + $data[$field] = get_post_meta( $quiz_id, '_'.$field, true ); |
|
| 3156 | + |
|
| 3157 | + } |
|
| 3158 | + |
|
| 3159 | + wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data ); |
|
| 3160 | + |
|
| 3161 | + }// end quick edit admin defaults |
|
| 3162 | + |
|
| 3163 | + /** |
|
| 3164 | + * Filter the classes for lessons on the single course page. |
|
| 3165 | + * |
|
| 3166 | + * Adds the nesecary classes depending on the user data |
|
| 3167 | + * |
|
| 3168 | + * @since 1.9.0 |
|
| 3169 | + * @param array $classes |
|
| 3170 | + * @return array $classes |
|
| 3171 | + */ |
|
| 3172 | + public static function single_course_lessons_classes( $classes ){ |
|
| 3173 | 3173 | |
| 3174 | - if( is_singular('course') ){ |
|
| 3174 | + if( is_singular('course') ){ |
|
| 3175 | 3175 | |
| 3176 | - global $post; |
|
| 3177 | - $course_id = $post->ID; |
|
| 3176 | + global $post; |
|
| 3177 | + $course_id = $post->ID; |
|
| 3178 | 3178 | |
| 3179 | - $lesson_classes = array( 'course', 'post' ); |
|
| 3180 | - if ( is_user_logged_in() ) { |
|
| 3179 | + $lesson_classes = array( 'course', 'post' ); |
|
| 3180 | + if ( is_user_logged_in() ) { |
|
| 3181 | 3181 | |
| 3182 | - // Check if Lesson is complete |
|
| 3183 | - $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() ); |
|
| 3184 | - if ( $single_lesson_complete ) { |
|
| 3182 | + // Check if Lesson is complete |
|
| 3183 | + $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() ); |
|
| 3184 | + if ( $single_lesson_complete ) { |
|
| 3185 | 3185 | |
| 3186 | - $lesson_classes[] = 'lesson-completed'; |
|
| 3186 | + $lesson_classes[] = 'lesson-completed'; |
|
| 3187 | 3187 | |
| 3188 | - } // End If Statement |
|
| 3188 | + } // End If Statement |
|
| 3189 | 3189 | |
| 3190 | - } // End If Statement |
|
| 3190 | + } // End If Statement |
|
| 3191 | 3191 | |
| 3192 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 3193 | - if ( Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) { |
|
| 3192 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 3193 | + if ( Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) { |
|
| 3194 | 3194 | |
| 3195 | - $lesson_classes[] = 'lesson-preview'; |
|
| 3195 | + $lesson_classes[] = 'lesson-preview'; |
|
| 3196 | 3196 | |
| 3197 | - } |
|
| 3197 | + } |
|
| 3198 | 3198 | |
| 3199 | - $classes = array_merge( $classes, $lesson_classes ); |
|
| 3199 | + $classes = array_merge( $classes, $lesson_classes ); |
|
| 3200 | 3200 | |
| 3201 | - } |
|
| 3201 | + } |
|
| 3202 | 3202 | |
| 3203 | - return $classes; |
|
| 3203 | + return $classes; |
|
| 3204 | 3204 | |
| 3205 | - }// end single_course_lessons_classes |
|
| 3205 | + }// end single_course_lessons_classes |
|
| 3206 | 3206 | |
| 3207 | - /** |
|
| 3208 | - * Output the lesson meta for the given lesson |
|
| 3209 | - * |
|
| 3210 | - * @since 1.9.0 |
|
| 3211 | - * @param $lesson_id |
|
| 3212 | - */ |
|
| 3213 | - public static function the_lesson_meta( $lesson_id ){ |
|
| 3207 | + /** |
|
| 3208 | + * Output the lesson meta for the given lesson |
|
| 3209 | + * |
|
| 3210 | + * @since 1.9.0 |
|
| 3211 | + * @param $lesson_id |
|
| 3212 | + */ |
|
| 3213 | + public static function the_lesson_meta( $lesson_id ){ |
|
| 3214 | 3214 | |
| 3215 | - global $wp_query; |
|
| 3216 | - $loop_lesson_number = $wp_query->current_post + 1; |
|
| 3215 | + global $wp_query; |
|
| 3216 | + $loop_lesson_number = $wp_query->current_post + 1; |
|
| 3217 | 3217 | |
| 3218 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 3219 | - $single_lesson_complete = false; |
|
| 3220 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 3218 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 3219 | + $single_lesson_complete = false; |
|
| 3220 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 3221 | 3221 | |
| 3222 | - // Get Lesson data |
|
| 3223 | - $complexity_array = Sensei()->lesson->lesson_complexities(); |
|
| 3222 | + // Get Lesson data |
|
| 3223 | + $complexity_array = Sensei()->lesson->lesson_complexities(); |
|
| 3224 | 3224 | |
| 3225 | - $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true ); |
|
| 3226 | - if ( '' != $lesson_complexity ) { |
|
| 3225 | + $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true ); |
|
| 3226 | + if ( '' != $lesson_complexity ) { |
|
| 3227 | 3227 | |
| 3228 | - $lesson_complexity = $complexity_array[$lesson_complexity]; |
|
| 3228 | + $lesson_complexity = $complexity_array[$lesson_complexity]; |
|
| 3229 | 3229 | |
| 3230 | - } |
|
| 3231 | - $user_info = get_userdata( absint( get_post()->post_author ) ); |
|
| 3232 | - $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id); |
|
| 3233 | - $preview_label = ''; |
|
| 3234 | - if ( $is_preview && !$is_user_taking_course ) { |
|
| 3230 | + } |
|
| 3231 | + $user_info = get_userdata( absint( get_post()->post_author ) ); |
|
| 3232 | + $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id); |
|
| 3233 | + $preview_label = ''; |
|
| 3234 | + if ( $is_preview && !$is_user_taking_course ) { |
|
| 3235 | 3235 | |
| 3236 | - $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id); |
|
| 3237 | - $preview_label = '<span class="preview-heading">' . $preview_label . '</span>'; |
|
| 3236 | + $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id); |
|
| 3237 | + $preview_label = '<span class="preview-heading">' . $preview_label . '</span>'; |
|
| 3238 | 3238 | |
| 3239 | - } |
|
| 3239 | + } |
|
| 3240 | 3240 | |
| 3241 | 3241 | |
| 3242 | - $count_markup= ''; |
|
| 3243 | - /** |
|
| 3244 | - * Filter for if you want the $lesson_count to show next to the lesson. |
|
| 3245 | - * |
|
| 3246 | - * @since 1.0 |
|
| 3247 | - * @param bool default false. |
|
| 3248 | - */ |
|
| 3249 | - if( apply_filters( 'sensei_show_lesson_numbers', false ) ) { |
|
| 3242 | + $count_markup= ''; |
|
| 3243 | + /** |
|
| 3244 | + * Filter for if you want the $lesson_count to show next to the lesson. |
|
| 3245 | + * |
|
| 3246 | + * @since 1.0 |
|
| 3247 | + * @param bool default false. |
|
| 3248 | + */ |
|
| 3249 | + if( apply_filters( 'sensei_show_lesson_numbers', false ) ) { |
|
| 3250 | 3250 | |
| 3251 | - $count_markup = '<span class="lesson-number">' . $loop_lesson_number. '</span>'; |
|
| 3251 | + $count_markup = '<span class="lesson-number">' . $loop_lesson_number. '</span>'; |
|
| 3252 | 3252 | |
| 3253 | - } |
|
| 3253 | + } |
|
| 3254 | 3254 | |
| 3255 | - $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) ); |
|
| 3255 | + $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) ); |
|
| 3256 | 3256 | |
| 3257 | - ?> |
|
| 3257 | + ?> |
|
| 3258 | 3258 | <header> |
| 3259 | 3259 | <h2> |
| 3260 | 3260 | <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>" |
@@ -3267,40 +3267,40 @@ discard block |
||
| 3267 | 3267 | |
| 3268 | 3268 | <?php |
| 3269 | 3269 | |
| 3270 | - $meta_html = ''; |
|
| 3271 | - $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() ); |
|
| 3270 | + $meta_html = ''; |
|
| 3271 | + $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() ); |
|
| 3272 | 3272 | |
| 3273 | - $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true ); |
|
| 3274 | - if ( '' != $lesson_length ) { |
|
| 3273 | + $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true ); |
|
| 3274 | + if ( '' != $lesson_length ) { |
|
| 3275 | 3275 | |
| 3276 | - $meta_html .= '<span class="lesson-length">' . __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>'; |
|
| 3276 | + $meta_html .= '<span class="lesson-length">' . __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>'; |
|
| 3277 | 3277 | |
| 3278 | - } |
|
| 3278 | + } |
|
| 3279 | 3279 | |
| 3280 | - if ( Sensei()->settings->get( 'lesson_author' ) ) { |
|
| 3280 | + if ( Sensei()->settings->get( 'lesson_author' ) ) { |
|
| 3281 | 3281 | |
| 3282 | - $meta_html .= '<span class="lesson-author">' . __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 3282 | + $meta_html .= '<span class="lesson-author">' . __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 3283 | 3283 | |
| 3284 | - } // End If Statement |
|
| 3285 | - if ( '' != $lesson_complexity ) { |
|
| 3284 | + } // End If Statement |
|
| 3285 | + if ( '' != $lesson_complexity ) { |
|
| 3286 | 3286 | |
| 3287 | - $meta_html .= '<span class="lesson-complexity">' . __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>'; |
|
| 3287 | + $meta_html .= '<span class="lesson-complexity">' . __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>'; |
|
| 3288 | 3288 | |
| 3289 | - } |
|
| 3289 | + } |
|
| 3290 | 3290 | |
| 3291 | - if ( $single_lesson_complete ) { |
|
| 3291 | + if ( $single_lesson_complete ) { |
|
| 3292 | 3292 | |
| 3293 | - $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>'; |
|
| 3293 | + $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>'; |
|
| 3294 | 3294 | |
| 3295 | - } elseif ( $user_lesson_status ) { |
|
| 3295 | + } elseif ( $user_lesson_status ) { |
|
| 3296 | 3296 | |
| 3297 | - $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>'; |
|
| 3297 | + $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>'; |
|
| 3298 | 3298 | |
| 3299 | - } // End If Statement |
|
| 3299 | + } // End If Statement |
|
| 3300 | 3300 | |
| 3301 | - echo $meta_html; |
|
| 3301 | + echo $meta_html; |
|
| 3302 | 3302 | |
| 3303 | - ?> |
|
| 3303 | + ?> |
|
| 3304 | 3304 | |
| 3305 | 3305 | </p> <!-- lesson meta --> |
| 3306 | 3306 | |
@@ -3308,132 +3308,132 @@ discard block |
||
| 3308 | 3308 | |
| 3309 | 3309 | <?php |
| 3310 | 3310 | |
| 3311 | - } // end the_lesson_meta |
|
| 3311 | + } // end the_lesson_meta |
|
| 3312 | 3312 | |
| 3313 | - /** |
|
| 3314 | - * Output the lessons thumbnail |
|
| 3315 | - * |
|
| 3316 | - * 1.9.0 |
|
| 3317 | - * |
|
| 3318 | - * @param $lesson_id |
|
| 3319 | - */ |
|
| 3320 | - public static function the_lesson_thumbnail( $lesson_id ){ |
|
| 3313 | + /** |
|
| 3314 | + * Output the lessons thumbnail |
|
| 3315 | + * |
|
| 3316 | + * 1.9.0 |
|
| 3317 | + * |
|
| 3318 | + * @param $lesson_id |
|
| 3319 | + */ |
|
| 3320 | + public static function the_lesson_thumbnail( $lesson_id ){ |
|
| 3321 | 3321 | |
| 3322 | - if( empty( $lesson_id ) ){ |
|
| 3322 | + if( empty( $lesson_id ) ){ |
|
| 3323 | 3323 | |
| 3324 | - $lesson_id = get_the_ID(); |
|
| 3324 | + $lesson_id = get_the_ID(); |
|
| 3325 | 3325 | |
| 3326 | - } |
|
| 3326 | + } |
|
| 3327 | 3327 | |
| 3328 | - if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 3329 | - return; |
|
| 3330 | - } |
|
| 3328 | + if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 3329 | + return; |
|
| 3330 | + } |
|
| 3331 | 3331 | |
| 3332 | - echo Sensei()->lesson->lesson_image( $lesson_id ); |
|
| 3333 | - } |
|
| 3332 | + echo Sensei()->lesson->lesson_image( $lesson_id ); |
|
| 3333 | + } |
|
| 3334 | 3334 | |
| 3335 | 3335 | |
| 3336 | - /** |
|
| 3337 | - * Alter the sensei lesson excerpt. |
|
| 3338 | - * |
|
| 3339 | - * @since 1.9.0 |
|
| 3340 | - * @param string $excerpt |
|
| 3341 | - * @return string $excerpt |
|
| 3342 | - */ |
|
| 3343 | - public static function alter_the_lesson_excerpt( $excerpt ) { |
|
| 3336 | + /** |
|
| 3337 | + * Alter the sensei lesson excerpt. |
|
| 3338 | + * |
|
| 3339 | + * @since 1.9.0 |
|
| 3340 | + * @param string $excerpt |
|
| 3341 | + * @return string $excerpt |
|
| 3342 | + */ |
|
| 3343 | + public static function alter_the_lesson_excerpt( $excerpt ) { |
|
| 3344 | 3344 | |
| 3345 | - if ('lesson' == get_post_type(get_the_ID())){ |
|
| 3345 | + if ('lesson' == get_post_type(get_the_ID())){ |
|
| 3346 | 3346 | |
| 3347 | - // remove this hooks to avoid an infinite loop. |
|
| 3348 | - remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') ); |
|
| 3347 | + // remove this hooks to avoid an infinite loop. |
|
| 3348 | + remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') ); |
|
| 3349 | 3349 | |
| 3350 | - return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) ); |
|
| 3351 | - } |
|
| 3350 | + return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) ); |
|
| 3351 | + } |
|
| 3352 | 3352 | |
| 3353 | - return $excerpt; |
|
| 3353 | + return $excerpt; |
|
| 3354 | 3354 | |
| 3355 | - }// end the_lesson_excerpt |
|
| 3355 | + }// end the_lesson_excerpt |
|
| 3356 | 3356 | |
| 3357 | - /** |
|
| 3358 | - * Returns the lesson prerequisite for the given lesson id. |
|
| 3359 | - * |
|
| 3360 | - * @since 1.9.0 |
|
| 3361 | - * |
|
| 3362 | - * @param $current_lesson_id |
|
| 3363 | - * @return mixed | bool | int $prerequisite_lesson_id or false |
|
| 3364 | - */ |
|
| 3365 | - public static function get_lesson_prerequisite_id( $current_lesson_id ){ |
|
| 3357 | + /** |
|
| 3358 | + * Returns the lesson prerequisite for the given lesson id. |
|
| 3359 | + * |
|
| 3360 | + * @since 1.9.0 |
|
| 3361 | + * |
|
| 3362 | + * @param $current_lesson_id |
|
| 3363 | + * @return mixed | bool | int $prerequisite_lesson_id or false |
|
| 3364 | + */ |
|
| 3365 | + public static function get_lesson_prerequisite_id( $current_lesson_id ){ |
|
| 3366 | 3366 | |
| 3367 | - $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true ); |
|
| 3367 | + $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true ); |
|
| 3368 | 3368 | |
| 3369 | - // set ti to false if not a valid prerequisite lesson id |
|
| 3370 | - if( empty( $prerequisite_lesson_id ) |
|
| 3371 | - || 'lesson' != get_post_type( $prerequisite_lesson_id ) |
|
| 3372 | - || $prerequisite_lesson_id == $current_lesson_id ) { |
|
| 3369 | + // set ti to false if not a valid prerequisite lesson id |
|
| 3370 | + if( empty( $prerequisite_lesson_id ) |
|
| 3371 | + || 'lesson' != get_post_type( $prerequisite_lesson_id ) |
|
| 3372 | + || $prerequisite_lesson_id == $current_lesson_id ) { |
|
| 3373 | 3373 | |
| 3374 | - $prerequisite_lesson_id = false; |
|
| 3374 | + $prerequisite_lesson_id = false; |
|
| 3375 | 3375 | |
| 3376 | - } |
|
| 3376 | + } |
|
| 3377 | 3377 | |
| 3378 | - return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id ); |
|
| 3378 | + return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id ); |
|
| 3379 | 3379 | |
| 3380 | - } |
|
| 3380 | + } |
|
| 3381 | 3381 | |
| 3382 | - /** |
|
| 3383 | - * This function requires that you pass in the lesson you would like to check for |
|
| 3384 | - * a pre-requisite and not the pre-requisite. It will check if the |
|
| 3385 | - * lesson has a pre-requiste and then check if it is completed. |
|
| 3386 | - * |
|
| 3387 | - * @since 1.9.0 |
|
| 3388 | - * |
|
| 3389 | - * @param $lesson_id |
|
| 3390 | - * @param $user_id |
|
| 3391 | - * @return bool |
|
| 3392 | - */ |
|
| 3393 | - public static function is_prerequisite_complete( $lesson_id, $user_id ){ |
|
| 3382 | + /** |
|
| 3383 | + * This function requires that you pass in the lesson you would like to check for |
|
| 3384 | + * a pre-requisite and not the pre-requisite. It will check if the |
|
| 3385 | + * lesson has a pre-requiste and then check if it is completed. |
|
| 3386 | + * |
|
| 3387 | + * @since 1.9.0 |
|
| 3388 | + * |
|
| 3389 | + * @param $lesson_id |
|
| 3390 | + * @param $user_id |
|
| 3391 | + * @return bool |
|
| 3392 | + */ |
|
| 3393 | + public static function is_prerequisite_complete( $lesson_id, $user_id ){ |
|
| 3394 | 3394 | |
| 3395 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 3396 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 3397 | - || ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){ |
|
| 3395 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 3396 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 3397 | + || ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){ |
|
| 3398 | 3398 | |
| 3399 | - return false; |
|
| 3399 | + return false; |
|
| 3400 | 3400 | |
| 3401 | - } |
|
| 3401 | + } |
|
| 3402 | 3402 | |
| 3403 | - $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id ); |
|
| 3403 | + $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id ); |
|
| 3404 | 3404 | |
| 3405 | - // not a valid pre-requisite so pre-requisite is completed |
|
| 3406 | - if( 'lesson' != get_post_type( $pre_requisite_id ) |
|
| 3407 | - || ! is_numeric( $pre_requisite_id ) ){ |
|
| 3405 | + // not a valid pre-requisite so pre-requisite is completed |
|
| 3406 | + if( 'lesson' != get_post_type( $pre_requisite_id ) |
|
| 3407 | + || ! is_numeric( $pre_requisite_id ) ){ |
|
| 3408 | 3408 | |
| 3409 | - return true; |
|
| 3409 | + return true; |
|
| 3410 | 3410 | |
| 3411 | - } |
|
| 3411 | + } |
|
| 3412 | 3412 | |
| 3413 | - return Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id ); |
|
| 3413 | + return Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id ); |
|
| 3414 | 3414 | |
| 3415 | - }// end is_prerequisite_complete |
|
| 3415 | + }// end is_prerequisite_complete |
|
| 3416 | 3416 | |
| 3417 | - /** |
|
| 3418 | - * Show the user not taking course message if it is the case |
|
| 3419 | - * |
|
| 3420 | - * @since 1.9.0 |
|
| 3421 | - */ |
|
| 3422 | - public static function user_not_taking_course_message(){ |
|
| 3417 | + /** |
|
| 3418 | + * Show the user not taking course message if it is the case |
|
| 3419 | + * |
|
| 3420 | + * @since 1.9.0 |
|
| 3421 | + */ |
|
| 3422 | + public static function user_not_taking_course_message(){ |
|
| 3423 | 3423 | |
| 3424 | - $lesson_id = get_the_ID(); |
|
| 3424 | + $lesson_id = get_the_ID(); |
|
| 3425 | 3425 | |
| 3426 | - if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 3427 | - return; |
|
| 3428 | - } |
|
| 3426 | + if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 3427 | + return; |
|
| 3428 | + } |
|
| 3429 | 3429 | |
| 3430 | - $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id ); |
|
| 3431 | - $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() ); |
|
| 3432 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 3433 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 3430 | + $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id ); |
|
| 3431 | + $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() ); |
|
| 3432 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 3433 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 3434 | 3434 | |
| 3435 | - if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) { |
|
| 3436 | - ?> |
|
| 3435 | + if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) { |
|
| 3436 | + ?> |
|
| 3437 | 3437 | |
| 3438 | 3438 | <div class="sensei-message alert"> |
| 3439 | 3439 | <?php echo Sensei()->permissions_message['message']; ?> |
@@ -3441,46 +3441,46 @@ discard block |
||
| 3441 | 3441 | |
| 3442 | 3442 | <?php |
| 3443 | 3443 | |
| 3444 | - }// end if |
|
| 3444 | + }// end if |
|
| 3445 | 3445 | |
| 3446 | - } // end user_not_taking_course_message |
|
| 3446 | + } // end user_not_taking_course_message |
|
| 3447 | 3447 | |
| 3448 | - /** |
|
| 3449 | - * Outputs the lessons course signup lingk |
|
| 3450 | - * |
|
| 3451 | - * This hook runs inside the single lesson page. |
|
| 3452 | - * |
|
| 3453 | - * @since 1.9.0 |
|
| 3454 | - */ |
|
| 3455 | - public static function course_signup_link( ){ |
|
| 3448 | + /** |
|
| 3449 | + * Outputs the lessons course signup lingk |
|
| 3450 | + * |
|
| 3451 | + * This hook runs inside the single lesson page. |
|
| 3452 | + * |
|
| 3453 | + * @since 1.9.0 |
|
| 3454 | + */ |
|
| 3455 | + public static function course_signup_link( ){ |
|
| 3456 | 3456 | |
| 3457 | - $course_id = Sensei()->lesson->get_course_id( get_the_ID() ); |
|
| 3457 | + $course_id = Sensei()->lesson->get_course_id( get_the_ID() ); |
|
| 3458 | 3458 | |
| 3459 | - if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) { |
|
| 3459 | + if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) { |
|
| 3460 | 3460 | |
| 3461 | - return; |
|
| 3461 | + return; |
|
| 3462 | 3462 | |
| 3463 | - } |
|
| 3464 | - ?> |
|
| 3463 | + } |
|
| 3464 | + ?> |
|
| 3465 | 3465 | |
| 3466 | 3466 | <section class="course-signup lesson-meta"> |
| 3467 | 3467 | |
| 3468 | 3468 | <?php |
| 3469 | - $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 3469 | + $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 3470 | 3470 | |
| 3471 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 3471 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 3472 | 3472 | |
| 3473 | - global $current_user; |
|
| 3474 | - if( is_user_logged_in() ) { |
|
| 3475 | - wp_get_current_user(); |
|
| 3473 | + global $current_user; |
|
| 3474 | + if( is_user_logged_in() ) { |
|
| 3475 | + wp_get_current_user(); |
|
| 3476 | 3476 | |
| 3477 | - $course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id ); |
|
| 3477 | + $course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id ); |
|
| 3478 | 3478 | |
| 3479 | - if( $course_purchased ) { |
|
| 3479 | + if( $course_purchased ) { |
|
| 3480 | 3480 | |
| 3481 | - $prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true ); |
|
| 3482 | - $course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' ) . '</a>'; |
|
| 3483 | - ?> |
|
| 3481 | + $prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true ); |
|
| 3482 | + $course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' ) . '</a>'; |
|
| 3483 | + ?> |
|
| 3484 | 3484 | <div class="sensei-message info"> |
| 3485 | 3485 | |
| 3486 | 3486 | <?php echo sprintf( __( 'Please complete %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); ?> |
@@ -3492,14 +3492,14 @@ discard block |
||
| 3492 | 3492 | <div class="sensei-message info"> |
| 3493 | 3493 | |
| 3494 | 3494 | <?php |
| 3495 | - $course_link = '<a href="' . esc_url( get_permalink( $course_id ) ) |
|
| 3496 | - . '"title="' . __( 'Sign Up', 'woothemes-sensei' ) |
|
| 3497 | - . '">' . __( 'course', 'woothemes-sensei' ) |
|
| 3498 | - . '</a>'; |
|
| 3495 | + $course_link = '<a href="' . esc_url( get_permalink( $course_id ) ) |
|
| 3496 | + . '"title="' . __( 'Sign Up', 'woothemes-sensei' ) |
|
| 3497 | + . '">' . __( 'course', 'woothemes-sensei' ) |
|
| 3498 | + . '</a>'; |
|
| 3499 | 3499 | |
| 3500 | - echo sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 3500 | + echo sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 3501 | 3501 | |
| 3502 | - ?> |
|
| 3502 | + ?> |
|
| 3503 | 3503 | |
| 3504 | 3504 | </div> |
| 3505 | 3505 | <?php } ?> |
@@ -3516,14 +3516,14 @@ discard block |
||
| 3516 | 3516 | |
| 3517 | 3517 | <div class="sensei-message info"> |
| 3518 | 3518 | <?php |
| 3519 | - $course_link = '<a href="' |
|
| 3520 | - . esc_url( get_permalink( $course_id ) ) |
|
| 3521 | - . '" title="' . __( 'Sign Up', 'woothemes-sensei' ) |
|
| 3522 | - . '">' . __( 'course', 'woothemes-sensei' ) |
|
| 3523 | - . '</a>'; |
|
| 3524 | - |
|
| 3525 | - echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 3526 | - ?> |
|
| 3519 | + $course_link = '<a href="' |
|
| 3520 | + . esc_url( get_permalink( $course_id ) ) |
|
| 3521 | + . '" title="' . __( 'Sign Up', 'woothemes-sensei' ) |
|
| 3522 | + . '">' . __( 'course', 'woothemes-sensei' ) |
|
| 3523 | + . '</a>'; |
|
| 3524 | + |
|
| 3525 | + echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 3526 | + ?> |
|
| 3527 | 3527 | </div> |
| 3528 | 3528 | |
| 3529 | 3529 | <?php endif; ?> |
@@ -3533,75 +3533,75 @@ discard block |
||
| 3533 | 3533 | </section> |
| 3534 | 3534 | |
| 3535 | 3535 | <?php |
| 3536 | - }// end course_signup_link |
|
| 3536 | + }// end course_signup_link |
|
| 3537 | 3537 | |
| 3538 | - /** |
|
| 3539 | - * Show a message telling the user to complete the previous message if they haven't done so yet |
|
| 3540 | - * |
|
| 3541 | - * @since 1.9.0 |
|
| 3542 | - */ |
|
| 3543 | - public static function prerequisite_complete_message(){ |
|
| 3538 | + /** |
|
| 3539 | + * Show a message telling the user to complete the previous message if they haven't done so yet |
|
| 3540 | + * |
|
| 3541 | + * @since 1.9.0 |
|
| 3542 | + */ |
|
| 3543 | + public static function prerequisite_complete_message(){ |
|
| 3544 | 3544 | |
| 3545 | - $lesson_prerequisite = WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() ); |
|
| 3546 | - $lesson_has_pre_requisite = $lesson_prerequisite > 0; |
|
| 3547 | - if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete( get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) { |
|
| 3545 | + $lesson_prerequisite = WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() ); |
|
| 3546 | + $lesson_has_pre_requisite = $lesson_prerequisite > 0; |
|
| 3547 | + if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete( get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) { |
|
| 3548 | 3548 | |
| 3549 | - $prerequisite_lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr( sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>'; |
|
| 3550 | - echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link ); |
|
| 3549 | + $prerequisite_lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr( sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>'; |
|
| 3550 | + echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link ); |
|
| 3551 | 3551 | |
| 3552 | - } |
|
| 3552 | + } |
|
| 3553 | 3553 | |
| 3554 | - } |
|
| 3554 | + } |
|
| 3555 | 3555 | |
| 3556 | - /** |
|
| 3557 | - * Deprecate the sensei_lesson_archive_header hook but keep it |
|
| 3558 | - * active for backwards compatibility. |
|
| 3559 | - * |
|
| 3560 | - * @deprecated since 1.9.0 |
|
| 3561 | - */ |
|
| 3562 | - public static function deprecate_sensei_lesson_archive_header_hook(){ |
|
| 3556 | + /** |
|
| 3557 | + * Deprecate the sensei_lesson_archive_header hook but keep it |
|
| 3558 | + * active for backwards compatibility. |
|
| 3559 | + * |
|
| 3560 | + * @deprecated since 1.9.0 |
|
| 3561 | + */ |
|
| 3562 | + public static function deprecate_sensei_lesson_archive_header_hook(){ |
|
| 3563 | 3563 | |
| 3564 | - sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before'); |
|
| 3564 | + sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before'); |
|
| 3565 | 3565 | |
| 3566 | - } |
|
| 3566 | + } |
|
| 3567 | 3567 | |
| 3568 | - /** |
|
| 3569 | - * Outputs the the lesson archive header. |
|
| 3570 | - * |
|
| 3571 | - * @since 1.9.0 |
|
| 3572 | - * @return void |
|
| 3573 | - */ |
|
| 3574 | - public function the_archive_header( ) { |
|
| 3568 | + /** |
|
| 3569 | + * Outputs the the lesson archive header. |
|
| 3570 | + * |
|
| 3571 | + * @since 1.9.0 |
|
| 3572 | + * @return void |
|
| 3573 | + */ |
|
| 3574 | + public function the_archive_header( ) { |
|
| 3575 | 3575 | |
| 3576 | - $before_html = '<header class="archive-header"><h1>'; |
|
| 3577 | - $after_html = '</h1></header>'; |
|
| 3578 | - $html = $before_html . __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html; |
|
| 3576 | + $before_html = '<header class="archive-header"><h1>'; |
|
| 3577 | + $after_html = '</h1></header>'; |
|
| 3578 | + $html = $before_html . __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html; |
|
| 3579 | 3579 | |
| 3580 | - echo apply_filters( 'sensei_lesson_archive_title', $html ); |
|
| 3580 | + echo apply_filters( 'sensei_lesson_archive_title', $html ); |
|
| 3581 | 3581 | |
| 3582 | - } // sensei_course_archive_header() |
|
| 3582 | + } // sensei_course_archive_header() |
|
| 3583 | 3583 | |
| 3584 | - /** |
|
| 3585 | - * Output the title for the single lesson page |
|
| 3586 | - * |
|
| 3587 | - * @global $post |
|
| 3588 | - * @since 1.9.0 |
|
| 3589 | - */ |
|
| 3590 | - public static function the_title(){ |
|
| 3584 | + /** |
|
| 3585 | + * Output the title for the single lesson page |
|
| 3586 | + * |
|
| 3587 | + * @global $post |
|
| 3588 | + * @since 1.9.0 |
|
| 3589 | + */ |
|
| 3590 | + public static function the_title(){ |
|
| 3591 | 3591 | |
| 3592 | - global $post; |
|
| 3592 | + global $post; |
|
| 3593 | 3593 | |
| 3594 | - ?> |
|
| 3594 | + ?> |
|
| 3595 | 3595 | <header> |
| 3596 | 3596 | |
| 3597 | 3597 | <h1> |
| 3598 | 3598 | |
| 3599 | 3599 | <?php |
| 3600 | - /** |
|
| 3601 | - * Filter documented in class-sensei-messages.php the_title |
|
| 3602 | - */ |
|
| 3603 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 3604 | - ?> |
|
| 3600 | + /** |
|
| 3601 | + * Filter documented in class-sensei-messages.php the_title |
|
| 3602 | + */ |
|
| 3603 | + echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 3604 | + ?> |
|
| 3605 | 3605 | |
| 3606 | 3606 | </h1> |
| 3607 | 3607 | |
@@ -3609,68 +3609,68 @@ discard block |
||
| 3609 | 3609 | |
| 3610 | 3610 | <?php |
| 3611 | 3611 | |
| 3612 | - }//the_title |
|
| 3612 | + }//the_title |
|
| 3613 | 3613 | |
| 3614 | - /** |
|
| 3615 | - * Flush the rewrite rules for a lesson post type |
|
| 3616 | - * |
|
| 3617 | - * @since 1.9.0 |
|
| 3618 | - * |
|
| 3619 | - * @param $post_id |
|
| 3620 | - */ |
|
| 3621 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 3614 | + /** |
|
| 3615 | + * Flush the rewrite rules for a lesson post type |
|
| 3616 | + * |
|
| 3617 | + * @since 1.9.0 |
|
| 3618 | + * |
|
| 3619 | + * @param $post_id |
|
| 3620 | + */ |
|
| 3621 | + public static function flush_rewrite_rules( $post_id ){ |
|
| 3622 | 3622 | |
| 3623 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 3623 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 3624 | 3624 | |
| 3625 | - return; |
|
| 3625 | + return; |
|
| 3626 | 3626 | |
| 3627 | - } |
|
| 3627 | + } |
|
| 3628 | 3628 | |
| 3629 | 3629 | |
| 3630 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 3630 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 3631 | 3631 | |
| 3632 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 3632 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 3633 | 3633 | |
| 3634 | - } |
|
| 3634 | + } |
|
| 3635 | 3635 | |
| 3636 | - } |
|
| 3636 | + } |
|
| 3637 | 3637 | |
| 3638 | - /** |
|
| 3639 | - * Output the quiz specific buttons and messaging on the single lesson page |
|
| 3640 | - * |
|
| 3641 | - * |
|
| 3642 | - * @since 1.0.0 moved here from frontend class |
|
| 3643 | - * |
|
| 3644 | - * @param int $lesson_id |
|
| 3645 | - * @param int $user_id |
|
| 3646 | - */ |
|
| 3647 | - public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) { |
|
| 3638 | + /** |
|
| 3639 | + * Output the quiz specific buttons and messaging on the single lesson page |
|
| 3640 | + * |
|
| 3641 | + * |
|
| 3642 | + * @since 1.0.0 moved here from frontend class |
|
| 3643 | + * |
|
| 3644 | + * @param int $lesson_id |
|
| 3645 | + * @param int $user_id |
|
| 3646 | + */ |
|
| 3647 | + public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) { |
|
| 3648 | 3648 | |
| 3649 | 3649 | |
| 3650 | - $lesson_id = empty( $lesson_id ) ? get_the_ID() : $lesson_id; |
|
| 3651 | - $user_id = empty( $lesson_id ) ? get_current_user_id() : $user_id; |
|
| 3652 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 3653 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 3654 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 3655 | - $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id ); |
|
| 3656 | - $show_actions = is_user_logged_in() ? true : false; |
|
| 3650 | + $lesson_id = empty( $lesson_id ) ? get_the_ID() : $lesson_id; |
|
| 3651 | + $user_id = empty( $lesson_id ) ? get_current_user_id() : $user_id; |
|
| 3652 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 3653 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 3654 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 3655 | + $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id ); |
|
| 3656 | + $show_actions = is_user_logged_in() ? true : false; |
|
| 3657 | 3657 | |
| 3658 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 3658 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 3659 | 3659 | |
| 3660 | - // If the user hasn't completed the prereq then hide the current actions |
|
| 3661 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id ); |
|
| 3660 | + // If the user hasn't completed the prereq then hide the current actions |
|
| 3661 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id ); |
|
| 3662 | 3662 | |
| 3663 | - } |
|
| 3664 | - ?> |
|
| 3663 | + } |
|
| 3664 | + ?> |
|
| 3665 | 3665 | |
| 3666 | 3666 | <footer> |
| 3667 | 3667 | |
| 3668 | 3668 | <?php |
| 3669 | - if( $show_actions && $quiz_id && Sensei()->access_settings() ) { |
|
| 3669 | + if( $show_actions && $quiz_id && Sensei()->access_settings() ) { |
|
| 3670 | 3670 | |
| 3671 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 3672 | - if( $has_quiz_questions ) { |
|
| 3673 | - ?> |
|
| 3671 | + $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 3672 | + if( $has_quiz_questions ) { |
|
| 3673 | + ?> |
|
| 3674 | 3674 | |
| 3675 | 3675 | <p> |
| 3676 | 3676 | |
@@ -3685,87 +3685,87 @@ discard block |
||
| 3685 | 3685 | </p> |
| 3686 | 3686 | |
| 3687 | 3687 | <?php |
| 3688 | - } |
|
| 3688 | + } |
|
| 3689 | 3689 | |
| 3690 | - } // End If Statement |
|
| 3690 | + } // End If Statement |
|
| 3691 | 3691 | |
| 3692 | - if ( $show_actions && ! $has_user_completed_lesson ) { |
|
| 3692 | + if ( $show_actions && ! $has_user_completed_lesson ) { |
|
| 3693 | 3693 | |
| 3694 | - sensei_complete_lesson_button(); |
|
| 3694 | + sensei_complete_lesson_button(); |
|
| 3695 | 3695 | |
| 3696 | - } elseif( $show_actions ) { |
|
| 3696 | + } elseif( $show_actions ) { |
|
| 3697 | 3697 | |
| 3698 | - sensei_reset_lesson_button(); |
|
| 3698 | + sensei_reset_lesson_button(); |
|
| 3699 | 3699 | |
| 3700 | - } // End If Statement |
|
| 3701 | - ?> |
|
| 3700 | + } // End If Statement |
|
| 3701 | + ?> |
|
| 3702 | 3702 | |
| 3703 | 3703 | </footer> |
| 3704 | 3704 | |
| 3705 | 3705 | <?php |
| 3706 | - } // End sensei_lesson_quiz_meta() |
|
| 3706 | + } // End sensei_lesson_quiz_meta() |
|
| 3707 | 3707 | |
| 3708 | - /** |
|
| 3709 | - * Show the lesson comments. This should be used in the loop. |
|
| 3710 | - * |
|
| 3711 | - * @since 1.9.0 |
|
| 3712 | - */ |
|
| 3713 | - public static function output_comments(){ |
|
| 3708 | + /** |
|
| 3709 | + * Show the lesson comments. This should be used in the loop. |
|
| 3710 | + * |
|
| 3711 | + * @since 1.9.0 |
|
| 3712 | + */ |
|
| 3713 | + public static function output_comments(){ |
|
| 3714 | 3714 | |
| 3715 | - if( ! is_user_logged_in() ){ |
|
| 3716 | - return; |
|
| 3717 | - } |
|
| 3715 | + if( ! is_user_logged_in() ){ |
|
| 3716 | + return; |
|
| 3717 | + } |
|
| 3718 | 3718 | |
| 3719 | - $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() ); |
|
| 3720 | - $course_id = Sensei()->lesson->get_course_id( get_the_ID() ); |
|
| 3721 | - $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ]; |
|
| 3722 | - $user_taking_course = Sensei_Utils::user_started_course($course_id ); |
|
| 3719 | + $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() ); |
|
| 3720 | + $course_id = Sensei()->lesson->get_course_id( get_the_ID() ); |
|
| 3721 | + $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ]; |
|
| 3722 | + $user_taking_course = Sensei_Utils::user_started_course($course_id ); |
|
| 3723 | 3723 | |
| 3724 | - $lesson_allow_comments = $allow_comments && $pre_requisite_complete && $user_taking_course; |
|
| 3724 | + $lesson_allow_comments = $allow_comments && $pre_requisite_complete && $user_taking_course; |
|
| 3725 | 3725 | |
| 3726 | - if ( $lesson_allow_comments || is_singular( 'sensei_message' ) ) { |
|
| 3726 | + if ( $lesson_allow_comments || is_singular( 'sensei_message' ) ) { |
|
| 3727 | 3727 | |
| 3728 | - comments_template(); |
|
| 3728 | + comments_template(); |
|
| 3729 | 3729 | |
| 3730 | - } // End If Statement |
|
| 3730 | + } // End If Statement |
|
| 3731 | 3731 | |
| 3732 | - } //output_comments |
|
| 3732 | + } //output_comments |
|
| 3733 | 3733 | |
| 3734 | - /** |
|
| 3735 | - * Display the leeson quiz status if it should be shown |
|
| 3736 | - * |
|
| 3737 | - * @param int $lesson_id defaults to the global lesson id |
|
| 3738 | - * @param int $user_id defaults to the current user id |
|
| 3739 | - * |
|
| 3740 | - * @since 1.9.0 |
|
| 3741 | - */ |
|
| 3742 | - public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){ |
|
| 3734 | + /** |
|
| 3735 | + * Display the leeson quiz status if it should be shown |
|
| 3736 | + * |
|
| 3737 | + * @param int $lesson_id defaults to the global lesson id |
|
| 3738 | + * @param int $user_id defaults to the current user id |
|
| 3739 | + * |
|
| 3740 | + * @since 1.9.0 |
|
| 3741 | + */ |
|
| 3742 | + public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){ |
|
| 3743 | 3743 | |
| 3744 | - $lesson_id = empty( $lesson_id ) ? get_the_ID() : $lesson_id; |
|
| 3745 | - $user_id = empty( $lesson_id ) ? get_current_user_id() : $user_id; |
|
| 3746 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 3747 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 3748 | - $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id ); |
|
| 3744 | + $lesson_id = empty( $lesson_id ) ? get_the_ID() : $lesson_id; |
|
| 3745 | + $user_id = empty( $lesson_id ) ? get_current_user_id() : $user_id; |
|
| 3746 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 3747 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 3748 | + $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id ); |
|
| 3749 | 3749 | |
| 3750 | 3750 | |
| 3751 | - if ( $quiz_id && is_user_logged_in() |
|
| 3752 | - && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) { |
|
| 3751 | + if ( $quiz_id && is_user_logged_in() |
|
| 3752 | + && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) { |
|
| 3753 | 3753 | |
| 3754 | - $no_quiz_count = 0; |
|
| 3755 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 3754 | + $no_quiz_count = 0; |
|
| 3755 | + $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 3756 | 3756 | |
| 3757 | - // Display lesson quiz status message |
|
| 3758 | - if ( $has_user_completed_lesson || $has_quiz_questions ) { |
|
| 3759 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true ); |
|
| 3760 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 3761 | - if( $has_quiz_questions ) { |
|
| 3762 | - // echo $status['extra']; |
|
| 3763 | - } // End If Statement |
|
| 3764 | - } // End If Statement |
|
| 3757 | + // Display lesson quiz status message |
|
| 3758 | + if ( $has_user_completed_lesson || $has_quiz_questions ) { |
|
| 3759 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true ); |
|
| 3760 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 3761 | + if( $has_quiz_questions ) { |
|
| 3762 | + // echo $status['extra']; |
|
| 3763 | + } // End If Statement |
|
| 3764 | + } // End If Statement |
|
| 3765 | 3765 | |
| 3766 | - } |
|
| 3766 | + } |
|
| 3767 | 3767 | |
| 3768 | - } |
|
| 3768 | + } |
|
| 3769 | 3769 | |
| 3770 | 3770 | } // End Class |
| 3771 | 3771 | |
@@ -14,251 +14,251 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Teacher { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * $teacher_role |
|
| 19 | - * |
|
| 20 | - * Keeps a reference to the teacher role object |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @since 1.8.0 |
|
| 24 | - */ |
|
| 25 | - protected $teacher_role; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $token |
|
| 29 | - * |
|
| 30 | - * Keeps a reference to the global sensei token |
|
| 31 | - * |
|
| 32 | - * @access protected |
|
| 33 | - * @since 1.8.0 |
|
| 34 | - */ |
|
| 35 | - public $token; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Sensei_Teacher::__constructor |
|
| 39 | - * |
|
| 40 | - * Constructor Function |
|
| 41 | - * |
|
| 42 | - * @since 1.8.0 |
|
| 43 | - * @access public |
|
| 44 | - */ |
|
| 45 | - public function __construct ( ) { |
|
| 46 | - |
|
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | - |
|
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | - |
|
| 55 | - //filter the quiz submissions |
|
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | - |
|
| 58 | - //grading totals count only those belonging to the teacher |
|
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | - |
|
| 61 | - // show the courses owned by a user on his author archive page |
|
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | - |
|
| 64 | - // notify admin when a teacher creates a course |
|
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | - |
|
| 67 | - // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | - |
|
| 70 | - // give teacher access to question post type |
|
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | - |
|
| 73 | - // Teacher column on the courses list on the admin edit screen |
|
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | - |
|
| 77 | - //admin edit messages query limit teacher |
|
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | - |
|
| 80 | - //add filter by teacher on courses list |
|
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | - |
|
| 84 | - // Handle media library restrictions |
|
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | - |
|
| 88 | - // update lesson owner to course teacher when saved |
|
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | - |
|
| 91 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - } // end __constructor() |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Sensei_Teacher::create_teacher_role |
|
| 103 | - * |
|
| 104 | - * This function checks if the role exist, if not it creates it. |
|
| 105 | - * for the teacher role |
|
| 106 | - * |
|
| 107 | - * @since 1.8.0 |
|
| 108 | - * @access public |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function create_role ( ) { |
|
| 112 | - |
|
| 113 | - // check if the role exists |
|
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | - |
|
| 116 | - // if the the teacher is not a valid WordPress role create it |
|
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | - // create the role |
|
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // add the capabilities before returning |
|
| 123 | - $this->add_capabilities(); |
|
| 124 | - |
|
| 125 | - }// end create_teacher_role |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Sensei_Teacher::add_capabilities |
|
| 129 | - * |
|
| 130 | - * @since 1.8.0 |
|
| 131 | - * @access protected |
|
| 132 | - */ |
|
| 133 | - protected function add_capabilities ( ) { |
|
| 134 | - |
|
| 135 | - // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Sensei teachers capabilities array filter |
|
| 142 | - * |
|
| 143 | - * These capabilities will be applied to the teacher role |
|
| 144 | - * @param array $capabilities |
|
| 145 | - * keys: (string) $cap_name => (bool) $grant |
|
| 146 | - */ |
|
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | - // General access rules |
|
| 149 | - 'read' => true, |
|
| 150 | - 'manage_sensei_grades' => true, |
|
| 151 | - 'moderate_comments'=> true, |
|
| 152 | - 'upload_files' => true, |
|
| 153 | - 'edit_files' => true, |
|
| 154 | - |
|
| 155 | - //Lessons |
|
| 156 | - 'publish_lessons' => true, |
|
| 157 | - 'manage_lesson_categories' => true, |
|
| 158 | - 'edit_lessons' => true, |
|
| 159 | - 'edit_published_lessons' => true, |
|
| 160 | - 'edit_private_lessons' => true, |
|
| 161 | - 'read_private_lessons' => true, |
|
| 162 | - 'delete_published_lessons' => true, |
|
| 163 | - |
|
| 164 | - // Courses |
|
| 165 | - 'create_courses' => true, |
|
| 166 | - 'publish_courses' => false, |
|
| 167 | - 'manage_course_categories' => true, |
|
| 168 | - 'edit_courses' => true, |
|
| 169 | - 'edit_published_courses' => true, |
|
| 170 | - 'edit_private_courses' => true, |
|
| 171 | - 'read_private_courses' => true, |
|
| 172 | - 'delete_published_courses' => true, |
|
| 173 | - |
|
| 174 | - // Quiz |
|
| 175 | - 'publish_quizzes' => true, |
|
| 176 | - 'edit_quizzes' => true, |
|
| 177 | - 'edit_published_quizzes' => true, |
|
| 178 | - 'edit_private_quizzes' => true, |
|
| 179 | - 'read_private_quizzes' => true, |
|
| 180 | - |
|
| 181 | - // Questions |
|
| 182 | - 'publish_questions' => true, |
|
| 183 | - 'edit_questions' => true, |
|
| 184 | - 'edit_published_questions' => true, |
|
| 185 | - 'edit_private_questions' => true, |
|
| 186 | - 'read_private_questions' => true, |
|
| 187 | - |
|
| 188 | - //messages |
|
| 189 | - 'publish_sensei_messages' => true, |
|
| 190 | - 'edit_sensei_messages' => true, |
|
| 191 | - 'edit_published_sensei_messages' => true, |
|
| 192 | - 'edit_private_sensei_messages' => true, |
|
| 193 | - 'read_private_sensei_messages' => true, |
|
| 194 | - |
|
| 195 | - // Comments - |
|
| 196 | - // Necessary cap so Teachers can moderate comments |
|
| 197 | - // on their own lessons. We restrict access to other |
|
| 198 | - // post types in $this->restrict_posts_menu_page() |
|
| 199 | - |
|
| 200 | - 'edit_posts' => true, |
|
| 201 | - |
|
| 202 | - )); |
|
| 203 | - |
|
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 205 | - |
|
| 206 | - // load the capability on to the teacher role |
|
| 207 | - $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | - |
|
| 209 | - } // end for each |
|
| 210 | - |
|
| 211 | - }// end add_cap |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Sensei_Teacher::teacher_meta_box |
|
| 215 | - * |
|
| 216 | - * Add the teacher metabox to the course post type edit screen |
|
| 217 | - * |
|
| 218 | - * @since 1.8.0 |
|
| 219 | - * @access public |
|
| 220 | - * @parameter string $post_type |
|
| 221 | - * @parameter WP_Post $post |
|
| 222 | - * @return void |
|
| 223 | - */ |
|
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | - |
|
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 227 | - return; |
|
| 228 | - } |
|
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | - 'course', |
|
| 231 | - 'side', |
|
| 232 | - 'core' |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - } // end teacher_meta_box() |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | - * |
|
| 240 | - * Render the teacher meta box markup |
|
| 241 | - * |
|
| 242 | - * @since 1.8.0 |
|
| 243 | - * @access public |
|
| 244 | - * @parameters |
|
| 245 | - */ |
|
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 247 | - |
|
| 248 | - // get the current author |
|
| 249 | - $current_author = $post->post_author; |
|
| 250 | - |
|
| 251 | - //get the users authorised to author courses |
|
| 252 | - $users = $this->get_teachers_and_authors(); |
|
| 253 | - |
|
| 254 | - ?> |
|
| 17 | + /** |
|
| 18 | + * $teacher_role |
|
| 19 | + * |
|
| 20 | + * Keeps a reference to the teacher role object |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @since 1.8.0 |
|
| 24 | + */ |
|
| 25 | + protected $teacher_role; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $token |
|
| 29 | + * |
|
| 30 | + * Keeps a reference to the global sensei token |
|
| 31 | + * |
|
| 32 | + * @access protected |
|
| 33 | + * @since 1.8.0 |
|
| 34 | + */ |
|
| 35 | + public $token; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Sensei_Teacher::__constructor |
|
| 39 | + * |
|
| 40 | + * Constructor Function |
|
| 41 | + * |
|
| 42 | + * @since 1.8.0 |
|
| 43 | + * @access public |
|
| 44 | + */ |
|
| 45 | + public function __construct ( ) { |
|
| 46 | + |
|
| 47 | + add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | + add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | + add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | + add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | + add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | + |
|
| 53 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | + |
|
| 55 | + //filter the quiz submissions |
|
| 56 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | + |
|
| 58 | + //grading totals count only those belonging to the teacher |
|
| 59 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | + |
|
| 61 | + // show the courses owned by a user on his author archive page |
|
| 62 | + add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | + |
|
| 64 | + // notify admin when a teacher creates a course |
|
| 65 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | + |
|
| 67 | + // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | + add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | + |
|
| 70 | + // give teacher access to question post type |
|
| 71 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | + |
|
| 73 | + // Teacher column on the courses list on the admin edit screen |
|
| 74 | + add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | + add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | + |
|
| 77 | + //admin edit messages query limit teacher |
|
| 78 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | + |
|
| 80 | + //add filter by teacher on courses list |
|
| 81 | + add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | + add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | + |
|
| 84 | + // Handle media library restrictions |
|
| 85 | + add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | + add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | + |
|
| 88 | + // update lesson owner to course teacher when saved |
|
| 89 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | + |
|
| 91 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + } // end __constructor() |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Sensei_Teacher::create_teacher_role |
|
| 103 | + * |
|
| 104 | + * This function checks if the role exist, if not it creates it. |
|
| 105 | + * for the teacher role |
|
| 106 | + * |
|
| 107 | + * @since 1.8.0 |
|
| 108 | + * @access public |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function create_role ( ) { |
|
| 112 | + |
|
| 113 | + // check if the role exists |
|
| 114 | + $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | + |
|
| 116 | + // if the the teacher is not a valid WordPress role create it |
|
| 117 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | + // create the role |
|
| 119 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // add the capabilities before returning |
|
| 123 | + $this->add_capabilities(); |
|
| 124 | + |
|
| 125 | + }// end create_teacher_role |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Sensei_Teacher::add_capabilities |
|
| 129 | + * |
|
| 130 | + * @since 1.8.0 |
|
| 131 | + * @access protected |
|
| 132 | + */ |
|
| 133 | + protected function add_capabilities ( ) { |
|
| 134 | + |
|
| 135 | + // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | + if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Sensei teachers capabilities array filter |
|
| 142 | + * |
|
| 143 | + * These capabilities will be applied to the teacher role |
|
| 144 | + * @param array $capabilities |
|
| 145 | + * keys: (string) $cap_name => (bool) $grant |
|
| 146 | + */ |
|
| 147 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | + // General access rules |
|
| 149 | + 'read' => true, |
|
| 150 | + 'manage_sensei_grades' => true, |
|
| 151 | + 'moderate_comments'=> true, |
|
| 152 | + 'upload_files' => true, |
|
| 153 | + 'edit_files' => true, |
|
| 154 | + |
|
| 155 | + //Lessons |
|
| 156 | + 'publish_lessons' => true, |
|
| 157 | + 'manage_lesson_categories' => true, |
|
| 158 | + 'edit_lessons' => true, |
|
| 159 | + 'edit_published_lessons' => true, |
|
| 160 | + 'edit_private_lessons' => true, |
|
| 161 | + 'read_private_lessons' => true, |
|
| 162 | + 'delete_published_lessons' => true, |
|
| 163 | + |
|
| 164 | + // Courses |
|
| 165 | + 'create_courses' => true, |
|
| 166 | + 'publish_courses' => false, |
|
| 167 | + 'manage_course_categories' => true, |
|
| 168 | + 'edit_courses' => true, |
|
| 169 | + 'edit_published_courses' => true, |
|
| 170 | + 'edit_private_courses' => true, |
|
| 171 | + 'read_private_courses' => true, |
|
| 172 | + 'delete_published_courses' => true, |
|
| 173 | + |
|
| 174 | + // Quiz |
|
| 175 | + 'publish_quizzes' => true, |
|
| 176 | + 'edit_quizzes' => true, |
|
| 177 | + 'edit_published_quizzes' => true, |
|
| 178 | + 'edit_private_quizzes' => true, |
|
| 179 | + 'read_private_quizzes' => true, |
|
| 180 | + |
|
| 181 | + // Questions |
|
| 182 | + 'publish_questions' => true, |
|
| 183 | + 'edit_questions' => true, |
|
| 184 | + 'edit_published_questions' => true, |
|
| 185 | + 'edit_private_questions' => true, |
|
| 186 | + 'read_private_questions' => true, |
|
| 187 | + |
|
| 188 | + //messages |
|
| 189 | + 'publish_sensei_messages' => true, |
|
| 190 | + 'edit_sensei_messages' => true, |
|
| 191 | + 'edit_published_sensei_messages' => true, |
|
| 192 | + 'edit_private_sensei_messages' => true, |
|
| 193 | + 'read_private_sensei_messages' => true, |
|
| 194 | + |
|
| 195 | + // Comments - |
|
| 196 | + // Necessary cap so Teachers can moderate comments |
|
| 197 | + // on their own lessons. We restrict access to other |
|
| 198 | + // post types in $this->restrict_posts_menu_page() |
|
| 199 | + |
|
| 200 | + 'edit_posts' => true, |
|
| 201 | + |
|
| 202 | + )); |
|
| 203 | + |
|
| 204 | + foreach ( $caps as $cap => $grant ) { |
|
| 205 | + |
|
| 206 | + // load the capability on to the teacher role |
|
| 207 | + $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | + |
|
| 209 | + } // end for each |
|
| 210 | + |
|
| 211 | + }// end add_cap |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Sensei_Teacher::teacher_meta_box |
|
| 215 | + * |
|
| 216 | + * Add the teacher metabox to the course post type edit screen |
|
| 217 | + * |
|
| 218 | + * @since 1.8.0 |
|
| 219 | + * @access public |
|
| 220 | + * @parameter string $post_type |
|
| 221 | + * @parameter WP_Post $post |
|
| 222 | + * @return void |
|
| 223 | + */ |
|
| 224 | + public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | + |
|
| 226 | + if( !current_user_can('manage_options') ){ |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | + 'course', |
|
| 231 | + 'side', |
|
| 232 | + 'core' |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + } // end teacher_meta_box() |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | + * |
|
| 240 | + * Render the teacher meta box markup |
|
| 241 | + * |
|
| 242 | + * @since 1.8.0 |
|
| 243 | + * @access public |
|
| 244 | + * @parameters |
|
| 245 | + */ |
|
| 246 | + public function teacher_meta_box_content ( $post ) { |
|
| 247 | + |
|
| 248 | + // get the current author |
|
| 249 | + $current_author = $post->post_author; |
|
| 250 | + |
|
| 251 | + //get the users authorised to author courses |
|
| 252 | + $users = $this->get_teachers_and_authors(); |
|
| 253 | + |
|
| 254 | + ?> |
|
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | 257 | <?php foreach ( $users as $user_id ) { ?> |
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | - $user = get_user_by('id', $user_id); |
|
| 261 | - ?> |
|
| 260 | + $user = get_user_by('id', $user_id); |
|
| 261 | + ?> |
|
| 262 | 262 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
@@ -269,1289 +269,1289 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | <?php |
| 271 | 271 | |
| 272 | - } // end render_teacher_meta_box() |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | - * |
|
| 277 | - * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | - * |
|
| 279 | - * @since 1.8.0 |
|
| 280 | - * @access public |
|
| 281 | - * @parameters |
|
| 282 | - * @return array $users user id array |
|
| 283 | - */ |
|
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 285 | - |
|
| 286 | - $author_query_args = array( |
|
| 287 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | - 'fields' => 'any', |
|
| 289 | - 'who' => 'authors' |
|
| 290 | - ); |
|
| 291 | - |
|
| 292 | - $authors = get_users( $author_query_args ); |
|
| 293 | - |
|
| 294 | - $teacher_query_args = array( |
|
| 295 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | - 'fields' => 'any', |
|
| 297 | - 'role' => 'teacher', |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 301 | - |
|
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | - |
|
| 304 | - }// end get_teachers_and_authors |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | - * |
|
| 309 | - * Save the new teacher / author to course and all lessons |
|
| 310 | - * |
|
| 311 | - * Hooked into admin_init |
|
| 312 | - * |
|
| 313 | - * @since 1.8.0 |
|
| 314 | - * @access public |
|
| 315 | - * @parameters |
|
| 316 | - * @return array $users user id array |
|
| 317 | - */ |
|
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 272 | + } // end render_teacher_meta_box() |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | + * |
|
| 277 | + * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | + * |
|
| 279 | + * @since 1.8.0 |
|
| 280 | + * @access public |
|
| 281 | + * @parameters |
|
| 282 | + * @return array $users user id array |
|
| 283 | + */ |
|
| 284 | + public function get_teachers_and_authors ( ){ |
|
| 285 | + |
|
| 286 | + $author_query_args = array( |
|
| 287 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | + 'fields' => 'any', |
|
| 289 | + 'who' => 'authors' |
|
| 290 | + ); |
|
| 291 | + |
|
| 292 | + $authors = get_users( $author_query_args ); |
|
| 293 | + |
|
| 294 | + $teacher_query_args = array( |
|
| 295 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | + 'fields' => 'any', |
|
| 297 | + 'role' => 'teacher', |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + $teachers = get_users( $teacher_query_args ); |
|
| 301 | + |
|
| 302 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | + |
|
| 304 | + }// end get_teachers_and_authors |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | + * |
|
| 309 | + * Save the new teacher / author to course and all lessons |
|
| 310 | + * |
|
| 311 | + * Hooked into admin_init |
|
| 312 | + * |
|
| 313 | + * @since 1.8.0 |
|
| 314 | + * @access public |
|
| 315 | + * @parameters |
|
| 316 | + * @return array $users user id array |
|
| 317 | + */ |
|
| 318 | + public function save_teacher_meta_box ( $course_id ){ |
|
| 319 | 319 | |
| 320 | - // check if this is a post from saving the teacher, if not exit early |
|
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // check if this is a post from saving the teacher, if not exit early |
|
| 321 | + if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - //don't fire this hook again |
|
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 325 | + //don't fire this hook again |
|
| 326 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 327 | 327 | |
| 328 | - // get the current post object |
|
| 329 | - $post = get_post( $course_id ); |
|
| 328 | + // get the current post object |
|
| 329 | + $post = get_post( $course_id ); |
|
| 330 | 330 | |
| 331 | - // get the current teacher/author |
|
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 331 | + // get the current teacher/author |
|
| 332 | + $current_author = absint( $post->post_author ); |
|
| 333 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 334 | 334 | |
| 335 | - // loop through all post lessons to update their authors as well |
|
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 335 | + // loop through all post lessons to update their authors as well |
|
| 336 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 337 | 337 | |
| 338 | - // do not do any processing if the selected author is the same as the current author |
|
| 339 | - if( $current_author == $new_author ){ |
|
| 340 | - return; |
|
| 341 | - } |
|
| 338 | + // do not do any processing if the selected author is the same as the current author |
|
| 339 | + if( $current_author == $new_author ){ |
|
| 340 | + return; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - // save the course author |
|
| 344 | - $post_updates = array( |
|
| 345 | - 'ID' => $post->ID , |
|
| 346 | - 'post_author' => $new_author |
|
| 347 | - ); |
|
| 348 | - wp_update_post( $post_updates ); |
|
| 343 | + // save the course author |
|
| 344 | + $post_updates = array( |
|
| 345 | + 'ID' => $post->ID , |
|
| 346 | + 'post_author' => $new_author |
|
| 347 | + ); |
|
| 348 | + wp_update_post( $post_updates ); |
|
| 349 | 349 | |
| 350 | - // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 350 | + // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | + Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 352 | 352 | |
| 353 | - // notify the new teacher |
|
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 353 | + // notify the new teacher |
|
| 354 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 355 | 355 | |
| 356 | - } // end save_teacher_meta_box |
|
| 356 | + } // end save_teacher_meta_box |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | - * the new author. Making sure the course terms are maintained. |
|
| 361 | - * |
|
| 362 | - * This function also checks if terms are shared, with other courses |
|
| 363 | - * |
|
| 364 | - * @param $course_id |
|
| 365 | - * @param $new_teacher_id |
|
| 366 | - * @return void |
|
| 367 | - */ |
|
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 358 | + /** |
|
| 359 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | + * the new author. Making sure the course terms are maintained. |
|
| 361 | + * |
|
| 362 | + * This function also checks if terms are shared, with other courses |
|
| 363 | + * |
|
| 364 | + * @param $course_id |
|
| 365 | + * @param $new_teacher_id |
|
| 366 | + * @return void |
|
| 367 | + */ |
|
| 368 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 370 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 377 | - return; |
|
| 378 | - } |
|
| 376 | + if( empty( $terms_selected_on_course ) ){ |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach( $terms_selected_on_course as $term ){ |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | + if( $new_teacher_id != $term_author->ID ){ |
|
| 384 | 384 | |
| 385 | - $new_term = ''; |
|
| 385 | + $new_term = ''; |
|
| 386 | 386 | |
| 387 | - //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 387 | + //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | + if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 394 | - // insert it even if it exists |
|
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | - } |
|
| 397 | - } |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | + $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | + $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | + if( !empty( $existing_admin_terms ) ){ |
|
| 394 | + // insert it even if it exists |
|
| 395 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if( empty ( $new_term ) ){ |
|
| 400 | 400 | |
| 401 | - //setup the new slug |
|
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | - |
|
| 404 | - // create new term and set it |
|
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | - |
|
| 407 | - } |
|
| 401 | + //setup the new slug |
|
| 402 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | + |
|
| 404 | + // create new term and set it |
|
| 405 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | + |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | - // if term exists |
|
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 411 | + // if term exists |
|
| 412 | + if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | - $term_id = $existing_term->term_id; |
|
| 414 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | + $term_id = $existing_term->term_id; |
|
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + }else{ |
|
| 418 | 418 | |
| 419 | - // for a new term simply get the term from the returned value |
|
| 420 | - $term_id = $new_term['term_id']; |
|
| 419 | + // for a new term simply get the term from the returned value |
|
| 420 | + $term_id = $new_term['term_id']; |
|
| 421 | 421 | |
| 422 | - } // end if term exist |
|
| 422 | + } // end if term exist |
|
| 423 | 423 | |
| 424 | - // set the terms selected on the course |
|
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 424 | + // set the terms selected on the course |
|
| 425 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 426 | 426 | |
| 427 | - // remove old term |
|
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 427 | + // remove old term |
|
| 428 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 429 | 429 | |
| 430 | - // update the lessons within the current module term |
|
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 430 | + // update the lessons within the current module term |
|
| 431 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | + foreach( $lessons as $lesson ){ |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 435 | 435 | |
| 436 | - // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | - // with the new term. |
|
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | - } |
|
| 436 | + // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | + // with the new term. |
|
| 438 | + wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | + update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - }// end for each |
|
| 442 | + }// end for each |
|
| 443 | 443 | |
| 444 | - } |
|
| 445 | - } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - }// end update_course_module_terms_author |
|
| 447 | + }// end update_course_module_terms_author |
|
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * Sensei_Teacher::update_course_lessons_author |
|
| 451 | - * |
|
| 452 | - * Update all course lessons and their quiz with a new author |
|
| 453 | - * |
|
| 454 | - * @since 1.8.0 |
|
| 455 | - * @access public |
|
| 456 | - * @parameters |
|
| 457 | - * @return array $users user id array |
|
| 458 | - */ |
|
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 449 | + /** |
|
| 450 | + * Sensei_Teacher::update_course_lessons_author |
|
| 451 | + * |
|
| 452 | + * Update all course lessons and their quiz with a new author |
|
| 453 | + * |
|
| 454 | + * @since 1.8.0 |
|
| 455 | + * @access public |
|
| 456 | + * @parameters |
|
| 457 | + * @return array $users user id array |
|
| 458 | + */ |
|
| 459 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 462 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - //get a list of course lessons |
|
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 466 | + //get a list of course lessons |
|
| 467 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 469 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - // update each lesson and quiz author |
|
| 474 | - foreach( $lessons as $lesson ){ |
|
| 473 | + // update each lesson and quiz author |
|
| 474 | + foreach( $lessons as $lesson ){ |
|
| 475 | 475 | |
| 476 | - // don't update if the author is tha same as the new author |
|
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 478 | - continue; |
|
| 479 | - } |
|
| 476 | + // don't update if the author is tha same as the new author |
|
| 477 | + if( $new_author == $lesson->post_author ){ |
|
| 478 | + continue; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - // update lesson author |
|
| 482 | - wp_update_post( array( |
|
| 483 | - 'ID'=> $lesson->ID, |
|
| 484 | - 'post_author' => $new_author |
|
| 485 | - ) ); |
|
| 481 | + // update lesson author |
|
| 482 | + wp_update_post( array( |
|
| 483 | + 'ID'=> $lesson->ID, |
|
| 484 | + 'post_author' => $new_author |
|
| 485 | + ) ); |
|
| 486 | 486 | |
| 487 | - // update quiz author |
|
| 488 | - //get the lessons quiz |
|
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | - // update quiz with new author |
|
| 493 | - wp_update_post( array( |
|
| 494 | - 'ID' => $quiz_id, |
|
| 495 | - 'post_author' => $new_author |
|
| 496 | - ) ); |
|
| 497 | - } |
|
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 500 | - 'ID' => $lesson_quizzes, |
|
| 501 | - 'post_author' => $new_author |
|
| 502 | - ) ); |
|
| 503 | - } |
|
| 487 | + // update quiz author |
|
| 488 | + //get the lessons quiz |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | + if( is_array( $lesson_quizzes ) ){ |
|
| 491 | + foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | + // update quiz with new author |
|
| 493 | + wp_update_post( array( |
|
| 494 | + 'ID' => $quiz_id, |
|
| 495 | + 'post_author' => $new_author |
|
| 496 | + ) ); |
|
| 497 | + } |
|
| 498 | + }else{ |
|
| 499 | + wp_update_post( array( |
|
| 500 | + 'ID' => $lesson_quizzes, |
|
| 501 | + 'post_author' => $new_author |
|
| 502 | + ) ); |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | - } // end for each lessons |
|
| 505 | + } // end for each lessons |
|
| 506 | 506 | |
| 507 | - return true; |
|
| 507 | + return true; |
|
| 508 | 508 | |
| 509 | - }// end update_course_lessons_author |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | - * |
|
| 516 | - * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | - * |
|
| 518 | - * @since 1.8.0 |
|
| 519 | - * @access public |
|
| 520 | - * @parameters $query |
|
| 521 | - * @return array $users user id array |
|
| 522 | - */ |
|
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | - |
|
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | - return $query; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | - return $query; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $screen = get_current_screen(); |
|
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | - |
|
| 536 | - // exit early for the following conditions |
|
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | - |
|
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | - return $query; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - global $current_user; |
|
| 545 | - // set the query author to the current user to only show those those posts |
|
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 547 | - return $query; |
|
| 548 | - |
|
| 549 | - }// end course_analysis_teacher_access_limit |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | - * |
|
| 555 | - * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | - * |
|
| 557 | - * @since 1.8.0 |
|
| 558 | - * @access public |
|
| 559 | - * @parameters array $wp_query |
|
| 560 | - * @return bool $is_admin_teacher |
|
| 561 | - */ |
|
| 562 | - public function is_admin_teacher ( ){ |
|
| 563 | - |
|
| 564 | - if( ! is_user_logged_in()){ |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $is_admin_teacher = false; |
|
| 568 | - |
|
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | - |
|
| 571 | - $is_admin_teacher = true; |
|
| 572 | - |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $is_admin_teacher; |
|
| 576 | - |
|
| 577 | - } // end is_admin_teacher |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Show correct post counts on list table for Sensei post types |
|
| 581 | - * |
|
| 582 | - * @since 1.8.0 |
|
| 583 | - * |
|
| 584 | - * @param object $counts Default status counts |
|
| 585 | - * @param string $type Current post type |
|
| 586 | - * @param string $perm User permission level |
|
| 587 | - * @return object Modified status counts |
|
| 588 | - */ |
|
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | - global $current_user; |
|
| 591 | - |
|
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | - return $counts; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 597 | - return $counts; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $args = array( |
|
| 601 | - 'post_type' => $type, |
|
| 602 | - 'author' => $current_user->ID, |
|
| 603 | - 'posts_per_page' => -1 |
|
| 604 | - ); |
|
| 605 | - |
|
| 606 | - // Get all available statuses |
|
| 607 | - $stati = get_post_stati(); |
|
| 608 | - |
|
| 609 | - // Update count object |
|
| 610 | - foreach( $stati as $status ) { |
|
| 611 | - $args['post_status'] = $status; |
|
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - return $counts; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Filter the post queries to show |
|
| 621 | - * only lesson /course and users that belong |
|
| 622 | - * to the current logged teacher. |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * |
|
| 626 | - */ |
|
| 627 | - public function filter_queries ( $query ) { |
|
| 628 | - global $current_user; |
|
| 629 | - |
|
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 631 | - return; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $screen = get_current_screen(); |
|
| 639 | - if( empty( $screen ) ) { |
|
| 640 | - return $query; |
|
| 641 | - } |
|
| 642 | - switch( $screen->id ) { |
|
| 643 | - case 'sensei_page_sensei_grading': |
|
| 644 | - case 'sensei_page_sensei_analysis': |
|
| 645 | - case 'sensei_page_sensei_learners': |
|
| 646 | - case 'lesson': |
|
| 647 | - case 'course': |
|
| 648 | - case 'question': |
|
| 649 | - case 'lesson_page_module-order': |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * sensei_filter_queries_set_author |
|
| 653 | - * Filter the author Sensei set for queries |
|
| 654 | - * |
|
| 655 | - * @since 1.8.0 |
|
| 656 | - * |
|
| 657 | - * @param int $user_id |
|
| 658 | - * @param string $screen_id |
|
| 659 | - * |
|
| 660 | - */ |
|
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | - * . This excludes the admin user. |
|
| 669 | - * |
|
| 670 | - * @since 1.8.0 |
|
| 671 | - * @hooked into the_comments |
|
| 672 | - * @param array $comments |
|
| 673 | - * |
|
| 674 | - * @return array $comments |
|
| 675 | - */ |
|
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 677 | - |
|
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - //check if we're on the grading screen |
|
| 683 | - $screen = get_current_screen(); |
|
| 684 | - |
|
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | - return $comments; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - // get the course and determine if the current teacher is the owner |
|
| 690 | - // if not remove it from the list of comments to be returned |
|
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | - //remove this as the teacher should see this. |
|
| 697 | - unset( $comments[ $key ] ); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - return $comments ; |
|
| 701 | - |
|
| 702 | - }// end function filter grading |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Limit the grading screen totals to only show lessons in the course |
|
| 706 | - * belonging to the currently logged in teacher. This only applies to |
|
| 707 | - * the teacher role. |
|
| 708 | - * |
|
| 709 | - * @since 1.8.0 |
|
| 710 | - * |
|
| 711 | - * @hooked into sensei_count_statuses_args |
|
| 712 | - * @param array $args |
|
| 713 | - * |
|
| 714 | - * @return array $args |
|
| 715 | - */ |
|
| 716 | - public function limit_grading_totals( $args ){ |
|
| 717 | - |
|
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - //get the teachers courses |
|
| 723 | - // the query is already filtered to only the teacher |
|
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 725 | - |
|
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | - return $args; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - //setup the lessons quizzes to limit the grading totals to |
|
| 731 | - $quiz_scope = array(); |
|
| 732 | - foreach( $courses as $course ){ |
|
| 733 | - |
|
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | - |
|
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | - |
|
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 739 | - |
|
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 742 | - |
|
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 744 | - |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - $args['post__in'] = $quiz_scope; |
|
| 754 | - |
|
| 755 | - return $args; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * It ensures that the author archive shows course by the current user. |
|
| 760 | - * |
|
| 761 | - * This function is hooked into the pre_get_posts filter |
|
| 762 | - * |
|
| 763 | - * @param WP_Query $query |
|
| 764 | - * @return WP_Query $query |
|
| 765 | - */ |
|
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 767 | - |
|
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | - return $query; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // this should only apply to users with the teacher role |
|
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | - |
|
| 776 | - return $query; |
|
| 777 | - |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // Change post types depending on what is set already |
|
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 783 | - |
|
| 784 | - // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 786 | - |
|
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 788 | - |
|
| 789 | - // merge the post types instead of overwriting it |
|
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | - |
|
| 792 | - }else{ |
|
| 793 | - |
|
| 794 | - // in this instance it is probably just one post type in string format |
|
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | - |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - // change the query before returning it |
|
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Change the query on the teacher author archive template |
|
| 804 | - * |
|
| 805 | - * @since 1.8.4 |
|
| 806 | - * @param WP_Query $query |
|
| 807 | - */ |
|
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | - |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * Notify teacher when someone assigns a course to their account. |
|
| 814 | - * |
|
| 815 | - * @since 1.8.0 |
|
| 816 | - * |
|
| 817 | - * @param $teacher_id |
|
| 818 | - * @param $course_id |
|
| 819 | - * @return bool |
|
| 820 | - */ |
|
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | - |
|
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - // if new user is the same as the current logged user, they don't need an email |
|
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 829 | - return true; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - // load the email class |
|
| 833 | - include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | - $email = new Teacher_New_Course_Assignment(); |
|
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 836 | - |
|
| 837 | - return true; |
|
| 838 | - } // end teacher_course_assigned_notification |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Email the admin when a teacher creates a new course |
|
| 842 | - * |
|
| 843 | - * This function hooks into wp_insert_post |
|
| 844 | - * |
|
| 845 | - * @since 1.8.0 |
|
| 846 | - * @param int $course_id |
|
| 847 | - * @return bool |
|
| 848 | - */ |
|
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | - |
|
| 851 | - $course_id = $post->ID; |
|
| 852 | - |
|
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | - |
|
| 856 | - return false; |
|
| 857 | - |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Filter the option to send admin notification emails when teachers creation |
|
| 862 | - * course. |
|
| 863 | - * |
|
| 864 | - * @since 1.8.0 |
|
| 865 | - * |
|
| 866 | - * @param bool $on default true |
|
| 867 | - */ |
|
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | - return false; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // setting up the data needed by the email template |
|
| 873 | - global $sensei_email_data; |
|
| 874 | - $template = 'admin-teacher-new-course-created'; |
|
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 877 | - $recipient = get_option('admin_email', true); |
|
| 878 | - |
|
| 879 | - // don't send if the course is created by admin |
|
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 881 | - return; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | - * |
|
| 887 | - * @since 1.8.0 |
|
| 888 | - * @param string $template |
|
| 889 | - */ |
|
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Filter the email subject for the the |
|
| 894 | - * admin-teacher-new-course-created template |
|
| 895 | - * |
|
| 896 | - * @since 1.8.0 |
|
| 897 | - * @param string $subject default New course assigned to you |
|
| 898 | - * @param string $template |
|
| 899 | - */ |
|
| 900 | - $subject = apply_filters('sensei_email_subject', |
|
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 903 | - |
|
| 904 | - //course edit link |
|
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | - |
|
| 907 | - // Construct data array |
|
| 908 | - $email_data = array( |
|
| 909 | - 'template' => $template, |
|
| 910 | - 'heading' => $heading, |
|
| 911 | - 'teacher' => $teacher, |
|
| 912 | - 'course_id' => $course_id, |
|
| 913 | - 'course_name' => $course->post_title, |
|
| 914 | - 'course_edit_link' => $course_edit_link, |
|
| 915 | - ); |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | - * |
|
| 920 | - * @since 1.8.0 |
|
| 921 | - * @param array $email_data |
|
| 922 | - * @param string $template |
|
| 923 | - */ |
|
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | - |
|
| 926 | - // Send mail |
|
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | - |
|
| 929 | - }// end notify admin of course creation |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | - * |
|
| 934 | - * Hooked into sensei_analysis_get_learners |
|
| 935 | - * @param array $args WP_User_Query arguments |
|
| 936 | - * @return array $learners_query_results |
|
| 937 | - */ |
|
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 939 | - |
|
| 940 | - // show default for none teachers |
|
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | - return $args; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - // for teachers all courses only return those which belong to the teacher |
|
| 946 | - // as they don't have access to course belonging to other users |
|
| 947 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 509 | + }// end update_course_lessons_author |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | + * |
|
| 516 | + * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | + * |
|
| 518 | + * @since 1.8.0 |
|
| 519 | + * @access public |
|
| 520 | + * @parameters $query |
|
| 521 | + * @return array $users user id array |
|
| 522 | + */ |
|
| 523 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | + |
|
| 525 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | + return $query; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | + return $query; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $screen = get_current_screen(); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | + |
|
| 536 | + // exit early for the following conditions |
|
| 537 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | + |
|
| 539 | + if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | + || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | + return $query; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + global $current_user; |
|
| 545 | + // set the query author to the current user to only show those those posts |
|
| 546 | + $query->set( 'author', $current_user->ID ); |
|
| 547 | + return $query; |
|
| 548 | + |
|
| 549 | + }// end course_analysis_teacher_access_limit |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | + * |
|
| 555 | + * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | + * |
|
| 557 | + * @since 1.8.0 |
|
| 558 | + * @access public |
|
| 559 | + * @parameters array $wp_query |
|
| 560 | + * @return bool $is_admin_teacher |
|
| 561 | + */ |
|
| 562 | + public function is_admin_teacher ( ){ |
|
| 563 | + |
|
| 564 | + if( ! is_user_logged_in()){ |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $is_admin_teacher = false; |
|
| 568 | + |
|
| 569 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | + |
|
| 571 | + $is_admin_teacher = true; |
|
| 572 | + |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $is_admin_teacher; |
|
| 576 | + |
|
| 577 | + } // end is_admin_teacher |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Show correct post counts on list table for Sensei post types |
|
| 581 | + * |
|
| 582 | + * @since 1.8.0 |
|
| 583 | + * |
|
| 584 | + * @param object $counts Default status counts |
|
| 585 | + * @param string $type Current post type |
|
| 586 | + * @param string $perm User permission level |
|
| 587 | + * @return object Modified status counts |
|
| 588 | + */ |
|
| 589 | + public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | + global $current_user; |
|
| 591 | + |
|
| 592 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | + return $counts; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if( ! $this->is_admin_teacher() ) { |
|
| 597 | + return $counts; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $args = array( |
|
| 601 | + 'post_type' => $type, |
|
| 602 | + 'author' => $current_user->ID, |
|
| 603 | + 'posts_per_page' => -1 |
|
| 604 | + ); |
|
| 605 | + |
|
| 606 | + // Get all available statuses |
|
| 607 | + $stati = get_post_stati(); |
|
| 608 | + |
|
| 609 | + // Update count object |
|
| 610 | + foreach( $stati as $status ) { |
|
| 611 | + $args['post_status'] = $status; |
|
| 612 | + $posts = get_posts( $args ); |
|
| 613 | + $counts->$status = count( $posts ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + return $counts; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Filter the post queries to show |
|
| 621 | + * only lesson /course and users that belong |
|
| 622 | + * to the current logged teacher. |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * |
|
| 626 | + */ |
|
| 627 | + public function filter_queries ( $query ) { |
|
| 628 | + global $current_user; |
|
| 629 | + |
|
| 630 | + if( ! $this->is_admin_teacher() ) { |
|
| 631 | + return; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $screen = get_current_screen(); |
|
| 639 | + if( empty( $screen ) ) { |
|
| 640 | + return $query; |
|
| 641 | + } |
|
| 642 | + switch( $screen->id ) { |
|
| 643 | + case 'sensei_page_sensei_grading': |
|
| 644 | + case 'sensei_page_sensei_analysis': |
|
| 645 | + case 'sensei_page_sensei_learners': |
|
| 646 | + case 'lesson': |
|
| 647 | + case 'course': |
|
| 648 | + case 'question': |
|
| 649 | + case 'lesson_page_module-order': |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * sensei_filter_queries_set_author |
|
| 653 | + * Filter the author Sensei set for queries |
|
| 654 | + * |
|
| 655 | + * @since 1.8.0 |
|
| 656 | + * |
|
| 657 | + * @param int $user_id |
|
| 658 | + * @param string $screen_id |
|
| 659 | + * |
|
| 660 | + */ |
|
| 661 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | + * . This excludes the admin user. |
|
| 669 | + * |
|
| 670 | + * @since 1.8.0 |
|
| 671 | + * @hooked into the_comments |
|
| 672 | + * @param array $comments |
|
| 673 | + * |
|
| 674 | + * @return array $comments |
|
| 675 | + */ |
|
| 676 | + public function filter_grading_activity_queries( $comments ){ |
|
| 677 | + |
|
| 678 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | + return $comments ; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + //check if we're on the grading screen |
|
| 683 | + $screen = get_current_screen(); |
|
| 684 | + |
|
| 685 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | + return $comments; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + // get the course and determine if the current teacher is the owner |
|
| 690 | + // if not remove it from the list of comments to be returned |
|
| 691 | + foreach( $comments as $key => $comment){ |
|
| 692 | + $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | + $course = get_post( $course_id ); |
|
| 695 | + if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | + //remove this as the teacher should see this. |
|
| 697 | + unset( $comments[ $key ] ); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + return $comments ; |
|
| 701 | + |
|
| 702 | + }// end function filter grading |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Limit the grading screen totals to only show lessons in the course |
|
| 706 | + * belonging to the currently logged in teacher. This only applies to |
|
| 707 | + * the teacher role. |
|
| 708 | + * |
|
| 709 | + * @since 1.8.0 |
|
| 710 | + * |
|
| 711 | + * @hooked into sensei_count_statuses_args |
|
| 712 | + * @param array $args |
|
| 713 | + * |
|
| 714 | + * @return array $args |
|
| 715 | + */ |
|
| 716 | + public function limit_grading_totals( $args ){ |
|
| 717 | + |
|
| 718 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | + return $args ; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + //get the teachers courses |
|
| 723 | + // the query is already filtered to only the teacher |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | + |
|
| 726 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | + return $args; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + //setup the lessons quizzes to limit the grading totals to |
|
| 731 | + $quiz_scope = array(); |
|
| 732 | + foreach( $courses as $course ){ |
|
| 733 | + |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | + |
|
| 736 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | + |
|
| 738 | + foreach( $course_lessons as $lesson ){ |
|
| 739 | + |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | + if( !empty( $quiz_id ) ) { |
|
| 742 | + |
|
| 743 | + array_push( $quiz_scope, $quiz_id ); |
|
| 744 | + |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + $args['post__in'] = $quiz_scope; |
|
| 754 | + |
|
| 755 | + return $args; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * It ensures that the author archive shows course by the current user. |
|
| 760 | + * |
|
| 761 | + * This function is hooked into the pre_get_posts filter |
|
| 762 | + * |
|
| 763 | + * @param WP_Query $query |
|
| 764 | + * @return WP_Query $query |
|
| 765 | + */ |
|
| 766 | + public function add_courses_to_author_archive( $query ) { |
|
| 767 | + |
|
| 768 | + if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | + return $query; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // this should only apply to users with the teacher role |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | + if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | + |
|
| 776 | + return $query; |
|
| 777 | + |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // Change post types depending on what is set already |
|
| 781 | + $current_post_types = $query->get( 'post_type' ); |
|
| 782 | + if( empty( $current_post_types ) ){ |
|
| 783 | + |
|
| 784 | + // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | + $new_post_types = array( 'post', 'course' ); |
|
| 786 | + |
|
| 787 | + } elseif( is_array( $current_post_types ) ) { |
|
| 788 | + |
|
| 789 | + // merge the post types instead of overwriting it |
|
| 790 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | + |
|
| 792 | + }else{ |
|
| 793 | + |
|
| 794 | + // in this instance it is probably just one post type in string format |
|
| 795 | + $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | + |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + // change the query before returning it |
|
| 800 | + $query->set('post_type', $new_post_types ); |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Change the query on the teacher author archive template |
|
| 804 | + * |
|
| 805 | + * @since 1.8.4 |
|
| 806 | + * @param WP_Query $query |
|
| 807 | + */ |
|
| 808 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | + |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * Notify teacher when someone assigns a course to their account. |
|
| 814 | + * |
|
| 815 | + * @since 1.8.0 |
|
| 816 | + * |
|
| 817 | + * @param $teacher_id |
|
| 818 | + * @param $course_id |
|
| 819 | + * @return bool |
|
| 820 | + */ |
|
| 821 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | + |
|
| 823 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + // if new user is the same as the current logged user, they don't need an email |
|
| 828 | + if( $teacher_id == get_current_user_id() ){ |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + // load the email class |
|
| 833 | + include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | + $email = new Teacher_New_Course_Assignment(); |
|
| 835 | + $email->trigger( $teacher_id, $course_id ); |
|
| 836 | + |
|
| 837 | + return true; |
|
| 838 | + } // end teacher_course_assigned_notification |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Email the admin when a teacher creates a new course |
|
| 842 | + * |
|
| 843 | + * This function hooks into wp_insert_post |
|
| 844 | + * |
|
| 845 | + * @since 1.8.0 |
|
| 846 | + * @param int $course_id |
|
| 847 | + * @return bool |
|
| 848 | + */ |
|
| 849 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | + |
|
| 851 | + $course_id = $post->ID; |
|
| 852 | + |
|
| 853 | + if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | + || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | + |
|
| 856 | + return false; |
|
| 857 | + |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Filter the option to send admin notification emails when teachers creation |
|
| 862 | + * course. |
|
| 863 | + * |
|
| 864 | + * @since 1.8.0 |
|
| 865 | + * |
|
| 866 | + * @param bool $on default true |
|
| 867 | + */ |
|
| 868 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | + return false; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // setting up the data needed by the email template |
|
| 873 | + global $sensei_email_data; |
|
| 874 | + $template = 'admin-teacher-new-course-created'; |
|
| 875 | + $course = get_post( $course_id ); |
|
| 876 | + $teacher = new WP_User( $course->post_author ); |
|
| 877 | + $recipient = get_option('admin_email', true); |
|
| 878 | + |
|
| 879 | + // don't send if the course is created by admin |
|
| 880 | + if( $recipient == $teacher->user_email ){ |
|
| 881 | + return; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | + * |
|
| 887 | + * @since 1.8.0 |
|
| 888 | + * @param string $template |
|
| 889 | + */ |
|
| 890 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Filter the email subject for the the |
|
| 894 | + * admin-teacher-new-course-created template |
|
| 895 | + * |
|
| 896 | + * @since 1.8.0 |
|
| 897 | + * @param string $subject default New course assigned to you |
|
| 898 | + * @param string $template |
|
| 899 | + */ |
|
| 900 | + $subject = apply_filters('sensei_email_subject', |
|
| 901 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | + $template ); |
|
| 903 | + |
|
| 904 | + //course edit link |
|
| 905 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | + |
|
| 907 | + // Construct data array |
|
| 908 | + $email_data = array( |
|
| 909 | + 'template' => $template, |
|
| 910 | + 'heading' => $heading, |
|
| 911 | + 'teacher' => $teacher, |
|
| 912 | + 'course_id' => $course_id, |
|
| 913 | + 'course_name' => $course->post_title, |
|
| 914 | + 'course_edit_link' => $course_edit_link, |
|
| 915 | + ); |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | + * |
|
| 920 | + * @since 1.8.0 |
|
| 921 | + * @param array $email_data |
|
| 922 | + * @param string $template |
|
| 923 | + */ |
|
| 924 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | + |
|
| 926 | + // Send mail |
|
| 927 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | + |
|
| 929 | + }// end notify admin of course creation |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | + * |
|
| 934 | + * Hooked into sensei_analysis_get_learners |
|
| 935 | + * @param array $args WP_User_Query arguments |
|
| 936 | + * @return array $learners_query_results |
|
| 937 | + */ |
|
| 938 | + public function limit_analysis_learners( $args ){ |
|
| 939 | + |
|
| 940 | + // show default for none teachers |
|
| 941 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | + return $args; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + // for teachers all courses only return those which belong to the teacher |
|
| 946 | + // as they don't have access to course belonging to other users |
|
| 947 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 948 | 948 | |
| 949 | - // if the user has no courses they should see no users |
|
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | - // tell the query to return 0 students |
|
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 953 | - return $args; |
|
| 954 | - |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - $learner_ids_for_teacher_courses = array(); |
|
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 959 | - |
|
| 960 | - $course_learner_ids = array(); |
|
| 961 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | - |
|
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | - continue; // skip to the next course as there are no users on this course |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - // it could be an array of comments or a single comment |
|
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 949 | + // if the user has no courses they should see no users |
|
| 950 | + if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | + // tell the query to return 0 students |
|
| 952 | + $args[ 'include'] = array( 0 ); |
|
| 953 | + return $args; |
|
| 954 | + |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + $learner_ids_for_teacher_courses = array(); |
|
| 958 | + foreach( $teacher_courses as $course ){ |
|
| 959 | + |
|
| 960 | + $course_learner_ids = array(); |
|
| 961 | + $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | + |
|
| 963 | + if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | + continue; // skip to the next course as there are no users on this course |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + // it could be an array of comments or a single comment |
|
| 968 | + if( is_array( $activity_comments ) ){ |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach( $activity_comments as $comment ){ |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata( $comment->user_id ); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 975 | - // next comment in this array |
|
| 976 | - continue; |
|
| 977 | - } |
|
| 974 | + if( empty( $user ) ){ |
|
| 975 | + // next comment in this array |
|
| 976 | + continue; |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - $course_learner_ids[] = $user->ID; |
|
| 980 | - } |
|
| 979 | + $course_learner_ids[] = $user->ID; |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + }else{ |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | - $course_learner_ids[] = $user->ID; |
|
| 984 | + $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | + $course_learner_ids[] = $user->ID; |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | - // add learners on this course to the all courses learner list |
|
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 989 | + // add learners on this course to the all courses learner list |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 991 | 991 | |
| 992 | - } |
|
| 992 | + } |
|
| 993 | 993 | |
| 994 | - // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 994 | + // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | + if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args[ 'include'] = array( 0 ); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + }else{ |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | - } |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | - // return the WP_Use_Query arguments |
|
| 1006 | - return $args; |
|
| 1005 | + // return the WP_Use_Query arguments |
|
| 1006 | + return $args; |
|
| 1007 | 1007 | |
| 1008 | - }// end limit_analysis_learners |
|
| 1008 | + }// end limit_analysis_learners |
|
| 1009 | 1009 | |
| 1010 | - /** |
|
| 1011 | - * Give teacher full admin access to the question post type |
|
| 1012 | - * in certain cases. |
|
| 1013 | - * |
|
| 1014 | - * @since 1.8.0 |
|
| 1015 | - * @param $questions |
|
| 1016 | - * @return mixed |
|
| 1017 | - */ |
|
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1010 | + /** |
|
| 1011 | + * Give teacher full admin access to the question post type |
|
| 1012 | + * in certain cases. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.8.0 |
|
| 1015 | + * @param $questions |
|
| 1016 | + * @return mixed |
|
| 1017 | + */ |
|
| 1018 | + public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1021 | - return $questions; |
|
| 1022 | - } |
|
| 1020 | + if( ! $this->is_admin_teacher() ){ |
|
| 1021 | + return $questions; |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - $screen = get_current_screen(); |
|
| 1024 | + $screen = get_current_screen(); |
|
| 1025 | 1025 | |
| 1026 | - // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1026 | + // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | + remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1030 | 1030 | |
| 1031 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1031 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | + if( ! empty($admin_user) ){ |
|
| 1033 | 1033 | |
| 1034 | - $current_teacher_id = get_current_user_id(); |
|
| 1034 | + $current_teacher_id = get_current_user_id(); |
|
| 1035 | 1035 | |
| 1036 | - // set current user to admin so teacher can view all questions |
|
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1036 | + // set current user to admin so teacher can view all questions |
|
| 1037 | + wp_set_current_user( $admin_user->ID ); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1039 | 1039 | |
| 1040 | - // set the teacher as the current use again |
|
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1042 | - } |
|
| 1040 | + // set the teacher as the current use again |
|
| 1041 | + wp_set_current_user( $current_teacher_id ); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - } |
|
| 1045 | - // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1044 | + } |
|
| 1045 | + // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1047 | 1047 | |
| 1048 | - return $questions; |
|
| 1049 | - } |
|
| 1048 | + return $questions; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Give the teacher role access to questions from the question bank |
|
| 1053 | - * |
|
| 1054 | - * @since 1.8.0 |
|
| 1055 | - * @param $wp_query |
|
| 1056 | - * @return mixed |
|
| 1057 | - */ |
|
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1051 | + /** |
|
| 1052 | + * Give the teacher role access to questions from the question bank |
|
| 1053 | + * |
|
| 1054 | + * @since 1.8.0 |
|
| 1055 | + * @param $wp_query |
|
| 1056 | + * @return mixed |
|
| 1057 | + */ |
|
| 1058 | + public function give_access_to_all_questions( $wp_query ){ |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1061 | 1061 | |
| 1062 | - return $wp_query; |
|
| 1063 | - } |
|
| 1062 | + return $wp_query; |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | - $screen = get_current_screen(); |
|
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1065 | + $screen = get_current_screen(); |
|
| 1066 | + if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | + || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1068 | 1068 | |
| 1069 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1069 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | + if( ! empty($admin_user) ){ |
|
| 1071 | 1071 | |
| 1072 | - $current_teacher_id = get_current_user_id(); |
|
| 1072 | + $current_teacher_id = get_current_user_id(); |
|
| 1073 | 1073 | |
| 1074 | - // set current user to admin so teacher can view all questions |
|
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1074 | + // set current user to admin so teacher can view all questions |
|
| 1075 | + wp_set_current_user( $admin_user->ID ); |
|
| 1076 | 1076 | |
| 1077 | - //run new query as admin |
|
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1077 | + //run new query as admin |
|
| 1078 | + $wp_query = new WP_Query( $wp_query->query ); |
|
| 1079 | 1079 | |
| 1080 | - //set the teache as current use again |
|
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1080 | + //set the teache as current use again |
|
| 1081 | + wp_set_current_user( $current_teacher_id ); |
|
| 1082 | 1082 | |
| 1083 | - } |
|
| 1084 | - } |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - return $wp_query; |
|
| 1087 | - }// end give_access_to_all_questions |
|
| 1086 | + return $wp_query; |
|
| 1087 | + }// end give_access_to_all_questions |
|
| 1088 | 1088 | |
| 1089 | - /** |
|
| 1090 | - * Add new column heading to the course admin edit list |
|
| 1091 | - * |
|
| 1092 | - * @since 1.8.0 |
|
| 1093 | - * @param $columns |
|
| 1094 | - * @return array |
|
| 1095 | - */ |
|
| 1096 | - public function course_column_heading($columns) { |
|
| 1089 | + /** |
|
| 1090 | + * Add new column heading to the course admin edit list |
|
| 1091 | + * |
|
| 1092 | + * @since 1.8.0 |
|
| 1093 | + * @param $columns |
|
| 1094 | + * @return array |
|
| 1095 | + */ |
|
| 1096 | + public function course_column_heading($columns) { |
|
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1099 | - return $columns; |
|
| 1100 | - } |
|
| 1101 | - $new_columns = array( |
|
| 1102 | - 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | - ); |
|
| 1104 | - return array_merge($columns, $new_columns); |
|
| 1098 | + if( $this->is_admin_teacher() ){ |
|
| 1099 | + return $columns; |
|
| 1100 | + } |
|
| 1101 | + $new_columns = array( |
|
| 1102 | + 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | + ); |
|
| 1104 | + return array_merge($columns, $new_columns); |
|
| 1105 | 1105 | |
| 1106 | - }// end teacher column add |
|
| 1106 | + }// end teacher column add |
|
| 1107 | 1107 | |
| 1108 | - /** |
|
| 1109 | - * Print out teacher column data |
|
| 1110 | - * |
|
| 1111 | - * @since 1.8.0 |
|
| 1112 | - * @param $column |
|
| 1113 | - * @param $course_id |
|
| 1114 | - */ |
|
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1108 | + /** |
|
| 1109 | + * Print out teacher column data |
|
| 1110 | + * |
|
| 1111 | + * @since 1.8.0 |
|
| 1112 | + * @param $column |
|
| 1113 | + * @param $course_id |
|
| 1114 | + */ |
|
| 1115 | + public function course_column_data( $column, $course_id ){ |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | - return; |
|
| 1119 | - } |
|
| 1117 | + if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | + return; |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post( $course_id ); |
|
| 1122 | + $teacher = get_userdata( $course->post_author ); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1125 | - return; |
|
| 1126 | - } |
|
| 1124 | + if( !$teacher ){ |
|
| 1125 | + return; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | - }// end course_column_ data |
|
| 1130 | + }// end course_column_ data |
|
| 1131 | 1131 | |
| 1132 | - /** |
|
| 1133 | - * Return only courses belonging to the given teacher. |
|
| 1134 | - * |
|
| 1135 | - * |
|
| 1136 | - * @since 1.8.0 |
|
| 1137 | - * |
|
| 1138 | - * @param int $teacher_id |
|
| 1139 | - * @param bool $return_ids_only |
|
| 1140 | - * |
|
| 1141 | - * @return array $teachers_courses |
|
| 1142 | - */ |
|
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1132 | + /** |
|
| 1133 | + * Return only courses belonging to the given teacher. |
|
| 1134 | + * |
|
| 1135 | + * |
|
| 1136 | + * @since 1.8.0 |
|
| 1137 | + * |
|
| 1138 | + * @param int $teacher_id |
|
| 1139 | + * @param bool $return_ids_only |
|
| 1140 | + * |
|
| 1141 | + * @return array $teachers_courses |
|
| 1142 | + */ |
|
| 1143 | + public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1144 | 1144 | |
| 1145 | - $teachers_courses = array(); |
|
| 1145 | + $teachers_courses = array(); |
|
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1148 | - $teacher_id = get_current_user_id(); |
|
| 1149 | - } |
|
| 1147 | + if( empty( $teacher_id ) ){ |
|
| 1148 | + $teacher_id = get_current_user_id(); |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | - $all_courses = Sensei()->course->get_all_courses(); |
|
| 1151 | + $all_courses = Sensei()->course->get_all_courses(); |
|
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1154 | - return $all_courses; |
|
| 1155 | - } |
|
| 1153 | + if( empty( $all_courses ) ){ |
|
| 1154 | + return $all_courses; |
|
| 1155 | + } |
|
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach( $all_courses as $course ){ |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1160 | - continue; |
|
| 1161 | - } |
|
| 1159 | + if( $course->post_author != $teacher_id ){ |
|
| 1160 | + continue; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if( $return_ids_only ){ |
|
| 1164 | 1164 | |
| 1165 | - $teachers_courses[] = $course->ID; |
|
| 1165 | + $teachers_courses[] = $course->ID; |
|
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + }else{ |
|
| 1168 | 1168 | |
| 1169 | - $teachers_courses[] = $course; |
|
| 1169 | + $teachers_courses[] = $course; |
|
| 1170 | 1170 | |
| 1171 | - } |
|
| 1171 | + } |
|
| 1172 | 1172 | |
| 1173 | - } |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - return $teachers_courses; |
|
| 1175 | + return $teachers_courses; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * Limit the message display to only those sent to the current teacher |
|
| 1181 | - * |
|
| 1182 | - * @since 1.8.0 |
|
| 1183 | - * |
|
| 1184 | - * @param $query |
|
| 1185 | - * @return mixed |
|
| 1186 | - */ |
|
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | - return $query; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - $teacher = wp_get_current_user(); |
|
| 1193 | - |
|
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | - $meta_query_args = array( |
|
| 1196 | - 'key' => '_receiver', |
|
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1198 | - 'compare' => '=' |
|
| 1199 | - ); |
|
| 1179 | + /** |
|
| 1180 | + * Limit the message display to only those sent to the current teacher |
|
| 1181 | + * |
|
| 1182 | + * @since 1.8.0 |
|
| 1183 | + * |
|
| 1184 | + * @param $query |
|
| 1185 | + * @return mixed |
|
| 1186 | + */ |
|
| 1187 | + public function limit_edit_messages_query( $query ){ |
|
| 1188 | + if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | + return $query; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + $teacher = wp_get_current_user(); |
|
| 1193 | + |
|
| 1194 | + $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | + $meta_query_args = array( |
|
| 1196 | + 'key' => '_receiver', |
|
| 1197 | + 'value' => $teacher->get('user_login') , |
|
| 1198 | + 'compare' => '=' |
|
| 1199 | + ); |
|
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args ); |
|
| 1202 | 1202 | |
| 1203 | - return $query; |
|
| 1204 | - } |
|
| 1203 | + return $query; |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * Add options to filter courses by teacher |
|
| 1209 | - * |
|
| 1210 | - * @since 1.8.0 |
|
| 1211 | - * |
|
| 1212 | - * @return void |
|
| 1213 | - */ |
|
| 1214 | - public function course_teacher_filter_options() { |
|
| 1215 | - global $typenow; |
|
| 1207 | + /** |
|
| 1208 | + * Add options to filter courses by teacher |
|
| 1209 | + * |
|
| 1210 | + * @since 1.8.0 |
|
| 1211 | + * |
|
| 1212 | + * @return void |
|
| 1213 | + */ |
|
| 1214 | + public function course_teacher_filter_options() { |
|
| 1215 | + global $typenow; |
|
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | - return; |
|
| 1219 | - } |
|
| 1217 | + if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | + return; |
|
| 1219 | + } |
|
| 1220 | 1220 | |
| 1221 | - // get all roles |
|
| 1222 | - $roles = get_editable_roles(); |
|
| 1221 | + // get all roles |
|
| 1222 | + $roles = get_editable_roles(); |
|
| 1223 | 1223 | |
| 1224 | - // get roles with the course edit capability |
|
| 1225 | - // and then get the users with those roles |
|
| 1226 | - $users_who_can_edit_courses = array(); |
|
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1224 | + // get roles with the course edit capability |
|
| 1225 | + // and then get the users with those roles |
|
| 1226 | + $users_who_can_edit_courses = array(); |
|
| 1227 | + foreach( $roles as $role_item ){ |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1235 | 1235 | |
| 1236 | - // add user from the current $user_role to all users |
|
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1236 | + // add user from the current $user_role to all users |
|
| 1237 | + $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1238 | 1238 | |
| 1239 | - } |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | - } |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - // Create the select element with the given users who can edit course |
|
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | - $course_options = ''; |
|
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | - } |
|
| 1243 | + // Create the select element with the given users who can edit course |
|
| 1244 | + $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | + $course_options = ''; |
|
| 1246 | + foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | + $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | - $output .= $course_options; |
|
| 1253 | - $output .= '</select>'; |
|
| 1250 | + $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | + $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | + $output .= $course_options; |
|
| 1253 | + $output .= '</select>'; |
|
| 1254 | 1254 | |
| 1255 | - echo $output; |
|
| 1256 | - } |
|
| 1255 | + echo $output; |
|
| 1256 | + } |
|
| 1257 | 1257 | |
| 1258 | - /** |
|
| 1259 | - * Modify the main query on the admin course list screen |
|
| 1260 | - * |
|
| 1261 | - * @since 1.8.0 |
|
| 1262 | - * |
|
| 1263 | - * @param $query |
|
| 1264 | - * @return $query |
|
| 1265 | - */ |
|
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1267 | - global $typenow; |
|
| 1258 | + /** |
|
| 1259 | + * Modify the main query on the admin course list screen |
|
| 1260 | + * |
|
| 1261 | + * @since 1.8.0 |
|
| 1262 | + * |
|
| 1263 | + * @param $query |
|
| 1264 | + * @return $query |
|
| 1265 | + */ |
|
| 1266 | + public function teacher_filter_query_modify( $query ){ |
|
| 1267 | + global $typenow; |
|
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | - return $query; |
|
| 1271 | - } |
|
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | - |
|
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1275 | - return $query; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - $query['author'] = $course_teacher; |
|
| 1279 | - return $query; |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Only show current teacher's media in the media library |
|
| 1284 | - * @param array $request Default request arguments |
|
| 1285 | - * @return array Modified request arguments |
|
| 1286 | - */ |
|
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1288 | - |
|
| 1289 | - if( ! is_admin() ) { |
|
| 1290 | - return $request; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1294 | - return $request; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - $screen = get_current_screen(); |
|
| 1298 | - |
|
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1301 | - |
|
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1304 | - } |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - return $request; |
|
| 1308 | - } // End restrict_media_library() |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | - * @param array $query Default query arguments |
|
| 1313 | - * @return array Modified query arguments |
|
| 1314 | - */ |
|
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | - |
|
| 1317 | - if( ! is_admin() ) { |
|
| 1318 | - return $query; |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1322 | - return $query; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1326 | - |
|
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - return $query; |
|
| 1332 | - } // End restrict_media_library_modal() |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | - * |
|
| 1337 | - * @since 1.8.0 |
|
| 1338 | - * |
|
| 1339 | - * @param int $lesson_id |
|
| 1340 | - */ |
|
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | - |
|
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1344 | - return; |
|
| 1345 | - } |
|
| 1269 | + if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | + return $query; |
|
| 1271 | + } |
|
| 1272 | + $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | + |
|
| 1274 | + if( empty( $course_teacher ) ) { |
|
| 1275 | + return $query; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + $query['author'] = $course_teacher; |
|
| 1279 | + return $query; |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Only show current teacher's media in the media library |
|
| 1284 | + * @param array $request Default request arguments |
|
| 1285 | + * @return array Modified request arguments |
|
| 1286 | + */ |
|
| 1287 | + public function restrict_media_library( $request = array() ) { |
|
| 1288 | + |
|
| 1289 | + if( ! is_admin() ) { |
|
| 1290 | + return $request; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + if( ! $this->is_admin_teacher() ) { |
|
| 1294 | + return $request; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + $screen = get_current_screen(); |
|
| 1298 | + |
|
| 1299 | + if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | + $teacher = intval( get_current_user_id() ); |
|
| 1301 | + |
|
| 1302 | + if( $teacher ) { |
|
| 1303 | + $request['author__in'] = array( $teacher ); |
|
| 1304 | + } |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + return $request; |
|
| 1308 | + } // End restrict_media_library() |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | + * @param array $query Default query arguments |
|
| 1313 | + * @return array Modified query arguments |
|
| 1314 | + */ |
|
| 1315 | + public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | + |
|
| 1317 | + if( ! is_admin() ) { |
|
| 1318 | + return $query; |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + if( ! $this->is_admin_teacher() ) { |
|
| 1322 | + return $query; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + $teacher = intval( get_current_user_id() ); |
|
| 1326 | + |
|
| 1327 | + if( $teacher ) { |
|
| 1328 | + $query['author__in'] = array( $teacher ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + return $query; |
|
| 1332 | + } // End restrict_media_library_modal() |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | + * |
|
| 1337 | + * @since 1.8.0 |
|
| 1338 | + * |
|
| 1339 | + * @param int $lesson_id |
|
| 1340 | + */ |
|
| 1341 | + public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | + |
|
| 1343 | + if( 'lesson'!= get_post_type() ){ |
|
| 1344 | + return; |
|
| 1345 | + } |
|
| 1346 | 1346 | |
| 1347 | - // this should only run once per request cycle |
|
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1347 | + // this should only run once per request cycle |
|
| 1348 | + remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | - return; |
|
| 1354 | - } |
|
| 1352 | + if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | + return; |
|
| 1354 | + } |
|
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post( $course_id ); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1360 | - 'post_author' => $course->post_author |
|
| 1361 | - ); |
|
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1358 | + $lesson_update_args= array( |
|
| 1359 | + 'ID' => $lesson_id , |
|
| 1360 | + 'post_author' => $course->post_author |
|
| 1361 | + ); |
|
| 1362 | + wp_update_post( $lesson_update_args ); |
|
| 1363 | 1363 | |
| 1364 | - } // end update_lesson_teacher |
|
| 1364 | + } // end update_lesson_teacher |
|
| 1365 | 1365 | |
| 1366 | - /** |
|
| 1367 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | - * |
|
| 1369 | - * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | - * |
|
| 1371 | - * @since 1.8.0 |
|
| 1372 | - * @access public |
|
| 1373 | - * @parameters array $wp_query |
|
| 1374 | - * @return WP_Query $wp_query |
|
| 1375 | - */ |
|
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | - global $current_user; |
|
| 1366 | + /** |
|
| 1367 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | + * |
|
| 1369 | + * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | + * |
|
| 1371 | + * @since 1.8.0 |
|
| 1372 | + * @access public |
|
| 1373 | + * @parameters array $wp_query |
|
| 1374 | + * @return WP_Query $wp_query |
|
| 1375 | + */ |
|
| 1376 | + public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | + global $current_user; |
|
| 1378 | 1378 | |
| 1379 | - //exit early |
|
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1381 | - return $wp_query; |
|
| 1382 | - } |
|
| 1379 | + //exit early |
|
| 1380 | + if( ! $this->is_admin_teacher() ){ |
|
| 1381 | + return $wp_query; |
|
| 1382 | + } |
|
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | - return $wp_query; |
|
| 1386 | - } |
|
| 1384 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | + return $wp_query; |
|
| 1386 | + } |
|
| 1387 | 1387 | |
| 1388 | - $screen = get_current_screen(); |
|
| 1388 | + $screen = get_current_screen(); |
|
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1391 | - return $wp_query; |
|
| 1392 | - } |
|
| 1390 | + if( empty( $screen ) ){ |
|
| 1391 | + return $wp_query; |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - // for any of these conditions limit what the teacher will see |
|
| 1395 | - $limit_screens = array( |
|
| 1396 | - 'edit-lesson', |
|
| 1397 | - 'edit-course', |
|
| 1398 | - 'edit-question', |
|
| 1399 | - 'course_page_course-order', |
|
| 1400 | - 'lesson_page_lesson-order', |
|
| 1401 | - ); |
|
| 1394 | + // for any of these conditions limit what the teacher will see |
|
| 1395 | + $limit_screens = array( |
|
| 1396 | + 'edit-lesson', |
|
| 1397 | + 'edit-course', |
|
| 1398 | + 'edit-question', |
|
| 1399 | + 'course_page_course-order', |
|
| 1400 | + 'lesson_page_lesson-order', |
|
| 1401 | + ); |
|
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if( in_array($screen->id , $limit_screens ) ) { |
|
| 1404 | 1404 | |
| 1405 | - // set the query author to the current user to only show those those posts |
|
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | - } |
|
| 1405 | + // set the query author to the current user to only show those those posts |
|
| 1406 | + $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | + } |
|
| 1408 | 1408 | |
| 1409 | - return $wp_query; |
|
| 1409 | + return $wp_query; |
|
| 1410 | 1410 | |
| 1411 | - } // end limit_teacher_edit_screen_post_types() |
|
| 1411 | + } // end limit_teacher_edit_screen_post_types() |
|
| 1412 | 1412 | |
| 1413 | 1413 | |
| 1414 | - /** |
|
| 1415 | - * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | - * |
|
| 1417 | - * Redirect teachers to /wp-admin/ after login |
|
| 1418 | - * |
|
| 1419 | - * @since 1.8.7 |
|
| 1420 | - * @access public |
|
| 1421 | - * @param string $user_login |
|
| 1422 | - * @param object $user |
|
| 1423 | - * @return void |
|
| 1424 | - */ |
|
| 1414 | + /** |
|
| 1415 | + * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | + * |
|
| 1417 | + * Redirect teachers to /wp-admin/ after login |
|
| 1418 | + * |
|
| 1419 | + * @since 1.8.7 |
|
| 1420 | + * @access public |
|
| 1421 | + * @param string $user_login |
|
| 1422 | + * @param object $user |
|
| 1423 | + * @return void |
|
| 1424 | + */ |
|
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect( $user_login, $user ) { |
|
| 1427 | 1427 | |
| 1428 | - if (user_can($user, 'edit_courses')) { |
|
| 1428 | + if (user_can($user, 'edit_courses')) { |
|
| 1429 | 1429 | |
| 1430 | - if (isset($_POST['redirect_to'])) { |
|
| 1430 | + if (isset($_POST['redirect_to'])) { |
|
| 1431 | 1431 | |
| 1432 | - wp_redirect($_POST['redirect_to'], 303); |
|
| 1432 | + wp_redirect($_POST['redirect_to'], 303); |
|
| 1433 | 1433 | |
| 1434 | - exit; |
|
| 1434 | + exit; |
|
| 1435 | 1435 | |
| 1436 | - } else { |
|
| 1436 | + } else { |
|
| 1437 | 1437 | |
| 1438 | - wp_redirect(admin_url(), 303); |
|
| 1438 | + wp_redirect(admin_url(), 303); |
|
| 1439 | 1439 | |
| 1440 | - exit; |
|
| 1440 | + exit; |
|
| 1441 | 1441 | |
| 1442 | - } |
|
| 1443 | - } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | - } // end teacher_login_redirect() |
|
| 1445 | + } // end teacher_login_redirect() |
|
| 1446 | 1446 | |
| 1447 | 1447 | |
| 1448 | 1448 | |
| 1449 | - /** |
|
| 1450 | - * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | - * |
|
| 1452 | - * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | - * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | - * so they can 'moderate_comments' as well. |
|
| 1455 | - * |
|
| 1456 | - * @since 1.8.7 |
|
| 1457 | - * @access public |
|
| 1458 | - * @parameters void |
|
| 1459 | - * @return void |
|
| 1460 | - */ |
|
| 1449 | + /** |
|
| 1450 | + * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | + * |
|
| 1452 | + * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | + * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | + * so they can 'moderate_comments' as well. |
|
| 1455 | + * |
|
| 1456 | + * @since 1.8.7 |
|
| 1457 | + * @access public |
|
| 1458 | + * @parameters void |
|
| 1459 | + * @return void |
|
| 1460 | + */ |
|
| 1461 | 1461 | |
| 1462 | - public function restrict_posts_menu_page() { |
|
| 1462 | + public function restrict_posts_menu_page() { |
|
| 1463 | 1463 | |
| 1464 | - global $pagenow, $typenow; |
|
| 1464 | + global $pagenow, $typenow; |
|
| 1465 | 1465 | |
| 1466 | - $user = wp_get_current_user(); |
|
| 1466 | + $user = wp_get_current_user(); |
|
| 1467 | 1467 | |
| 1468 | - /** |
|
| 1469 | - * Filter the option to hide the Posts menu page. |
|
| 1470 | - * |
|
| 1471 | - * @since 1.8.7 |
|
| 1472 | - * |
|
| 1473 | - * @param bool $restrict default true |
|
| 1474 | - */ |
|
| 1468 | + /** |
|
| 1469 | + * Filter the option to hide the Posts menu page. |
|
| 1470 | + * |
|
| 1471 | + * @since 1.8.7 |
|
| 1472 | + * |
|
| 1473 | + * @param bool $restrict default true |
|
| 1474 | + */ |
|
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | - remove_menu_page('edit.php'); |
|
| 1480 | + remove_menu_page('edit.php'); |
|
| 1481 | 1481 | |
| 1482 | - if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1482 | + if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1483 | 1483 | |
| 1484 | - if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1484 | + if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1485 | 1485 | |
| 1486 | - wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1486 | + wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1487 | 1487 | |
| 1488 | - } |
|
| 1488 | + } |
|
| 1489 | 1489 | |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - } |
|
| 1492 | + } |
|
| 1493 | 1493 | |
| 1494 | - } // end restrict_posts_menu_page() |
|
| 1494 | + } // end restrict_posts_menu_page() |
|
| 1495 | 1495 | |
| 1496 | - /** |
|
| 1497 | - * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | - * |
|
| 1499 | - * Restrict commendation moderation for teachers |
|
| 1500 | - * so they can only moderate comments made to posts they own. |
|
| 1501 | - * |
|
| 1502 | - * @since 1.8.7 |
|
| 1503 | - * @access public |
|
| 1504 | - * @parameters obj $clauses |
|
| 1505 | - * @return obj $clauses |
|
| 1506 | - */ |
|
| 1496 | + /** |
|
| 1497 | + * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | + * |
|
| 1499 | + * Restrict commendation moderation for teachers |
|
| 1500 | + * so they can only moderate comments made to posts they own. |
|
| 1501 | + * |
|
| 1502 | + * @since 1.8.7 |
|
| 1503 | + * @access public |
|
| 1504 | + * @parameters obj $clauses |
|
| 1505 | + * @return obj $clauses |
|
| 1506 | + */ |
|
| 1507 | 1507 | |
| 1508 | - public function restrict_comment_moderation($clauses) { |
|
| 1508 | + public function restrict_comment_moderation($clauses) { |
|
| 1509 | 1509 | |
| 1510 | - global $pagenow; |
|
| 1510 | + global $pagenow; |
|
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | - $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1514 | + $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1515 | 1515 | |
| 1516 | - } |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - return $clauses; |
|
| 1518 | + return $clauses; |
|
| 1519 | 1519 | |
| 1520 | - } // end restrict_comment_moderation() |
|
| 1520 | + } // end restrict_comment_moderation() |
|
| 1521 | 1521 | |
| 1522 | - /** |
|
| 1523 | - * Determine if a user is a teacher by ID |
|
| 1524 | - * |
|
| 1525 | - * @param int $user_id |
|
| 1526 | - * |
|
| 1527 | - * @return bool |
|
| 1528 | - */ |
|
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1522 | + /** |
|
| 1523 | + * Determine if a user is a teacher by ID |
|
| 1524 | + * |
|
| 1525 | + * @param int $user_id |
|
| 1526 | + * |
|
| 1527 | + * @return bool |
|
| 1528 | + */ |
|
| 1529 | + public static function is_a_teacher( $user_id ){ |
|
| 1530 | 1530 | |
| 1531 | - $user = get_user_by('id', $user_id); |
|
| 1531 | + $user = get_user_by('id', $user_id); |
|
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1534 | 1534 | |
| 1535 | - return true; |
|
| 1535 | + return true; |
|
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + }else{ |
|
| 1538 | 1538 | |
| 1539 | - return false; |
|
| 1539 | + return false; |
|
| 1540 | 1540 | |
| 1541 | - } |
|
| 1541 | + } |
|
| 1542 | 1542 | |
| 1543 | - }// end is_a_teacher |
|
| 1543 | + }// end is_a_teacher |
|
| 1544 | 1544 | |
| 1545 | - /** |
|
| 1546 | - * The archive title on the teacher archive filter |
|
| 1547 | - * |
|
| 1548 | - * @since 1.9.0 |
|
| 1549 | - */ |
|
| 1550 | - public static function archive_title(){ |
|
| 1545 | + /** |
|
| 1546 | + * The archive title on the teacher archive filter |
|
| 1547 | + * |
|
| 1548 | + * @since 1.9.0 |
|
| 1549 | + */ |
|
| 1550 | + public static function archive_title(){ |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | - $author_name = $author->display_name; |
|
| 1554 | - ?> |
|
| 1552 | + $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | + $author_name = $author->display_name; |
|
| 1554 | + ?> |
|
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | 1557 | <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
@@ -1559,17 +1559,17 @@ discard block |
||
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
| 1561 | 1561 | |
| 1562 | - }// archive title |
|
| 1562 | + }// archive title |
|
| 1563 | 1563 | |
| 1564 | - /** |
|
| 1565 | - * Removing course meta on the teacher archive page |
|
| 1566 | - * |
|
| 1567 | - * @since 1.9.0 |
|
| 1568 | - */ |
|
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1564 | + /** |
|
| 1565 | + * Removing course meta on the teacher archive page |
|
| 1566 | + * |
|
| 1567 | + * @since 1.9.0 |
|
| 1568 | + */ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive(){ |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1572 | 1572 | |
| 1573 | - } |
|
| 1573 | + } |
|
| 1574 | 1574 | |
| 1575 | 1575 | } // End Class |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function sensei_all_access() { |
| 42 | 42 | |
| 43 | - $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Filter sensei_all_access function result |
|
| 47 | - * which determinse if the current user |
|
| 48 | - * can access all of Sensei without restrictions |
|
| 49 | - * |
|
| 50 | - * @since 1.4.0 |
|
| 51 | - * @param bool $access |
|
| 52 | - */ |
|
| 43 | + $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Filter sensei_all_access function result |
|
| 47 | + * which determinse if the current user |
|
| 48 | + * can access all of Sensei without restrictions |
|
| 49 | + * |
|
| 50 | + * @since 1.4.0 |
|
| 51 | + * @param bool $access |
|
| 52 | + */ |
|
| 53 | 53 | return apply_filters( 'sensei_all_access', $access ); |
| 54 | 54 | |
| 55 | 55 | } // End sensei_all_access() |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
| 69 | 69 | |
| 70 | - $hex = str_replace( '#', '', $color ); |
|
| 70 | + $hex = str_replace( '#', '', $color ); |
|
| 71 | 71 | |
| 72 | 72 | $c_r = hexdec( substr( $hex, 0, 2 ) ); |
| 73 | 73 | $c_g = hexdec( substr( $hex, 2, 2 ) ); |
@@ -114,15 +114,15 @@ discard block |
||
| 114 | 114 | $color = '#'; |
| 115 | 115 | |
| 116 | 116 | foreach ($base as $k => $v) : |
| 117 | - $amount = $v / 100; |
|
| 118 | - $amount = round($amount * $factor); |
|
| 119 | - $new_decimal = $v - $amount; |
|
| 120 | - |
|
| 121 | - $new_hex_component = dechex($new_decimal); |
|
| 122 | - if(strlen($new_hex_component) < 2) : |
|
| 123 | - $new_hex_component = "0".$new_hex_component; |
|
| 124 | - endif; |
|
| 125 | - $color .= $new_hex_component; |
|
| 117 | + $amount = $v / 100; |
|
| 118 | + $amount = round($amount * $factor); |
|
| 119 | + $new_decimal = $v - $amount; |
|
| 120 | + |
|
| 121 | + $new_hex_component = dechex($new_decimal); |
|
| 122 | + if(strlen($new_hex_component) < 2) : |
|
| 123 | + $new_hex_component = "0".$new_hex_component; |
|
| 124 | + endif; |
|
| 125 | + $color .= $new_hex_component; |
|
| 126 | 126 | endforeach; |
| 127 | 127 | |
| 128 | 128 | return $color; |
@@ -143,17 +143,17 @@ discard block |
||
| 143 | 143 | $base = sensei_rgb_from_hex( $color ); |
| 144 | 144 | $color = '#'; |
| 145 | 145 | |
| 146 | - foreach ($base as $k => $v) : |
|
| 147 | - $amount = 255 - $v; |
|
| 148 | - $amount = $amount / 100; |
|
| 149 | - $amount = round($amount * $factor); |
|
| 150 | - $new_decimal = $v + $amount; |
|
| 151 | - |
|
| 152 | - $new_hex_component = dechex($new_decimal); |
|
| 153 | - if(strlen($new_hex_component) < 2) : |
|
| 154 | - $new_hex_component = "0".$new_hex_component; |
|
| 155 | - endif; |
|
| 156 | - $color .= $new_hex_component; |
|
| 146 | + foreach ($base as $k => $v) : |
|
| 147 | + $amount = 255 - $v; |
|
| 148 | + $amount = $amount / 100; |
|
| 149 | + $amount = round($amount * $factor); |
|
| 150 | + $new_decimal = $v + $amount; |
|
| 151 | + |
|
| 152 | + $new_hex_component = dechex($new_decimal); |
|
| 153 | + if(strlen($new_hex_component) < 2) : |
|
| 154 | + $new_hex_component = "0".$new_hex_component; |
|
| 155 | + endif; |
|
| 156 | + $color .= $new_hex_component; |
|
| 157 | 157 | endforeach; |
| 158 | 158 | |
| 159 | 159 | return $color; |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active() |
| 168 | 168 | */ |
| 169 | 169 | if ( ! function_exists( 'is_woocommerce_active' ) ) { |
| 170 | - function is_woocommerce_active() { |
|
| 171 | - // calling is present instead of is active here |
|
| 172 | - // as this function can override other is_woocommerce_active |
|
| 173 | - // function in other woo plugins and Sensei_WC::is_woocommerce_active |
|
| 174 | - // also check the sensei settings for enable WooCommerce support, which |
|
| 175 | - // other plugins should not check against. |
|
| 176 | - return Sensei_WC::is_woocommerce_present(); |
|
| 177 | - } |
|
| 170 | + function is_woocommerce_active() { |
|
| 171 | + // calling is present instead of is active here |
|
| 172 | + // as this function can override other is_woocommerce_active |
|
| 173 | + // function in other woo plugins and Sensei_WC::is_woocommerce_active |
|
| 174 | + // also check the sensei settings for enable WooCommerce support, which |
|
| 175 | + // other plugins should not check against. |
|
| 176 | + return Sensei_WC::is_woocommerce_present(); |
|
| 177 | + } |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -190,20 +190,20 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array() ){ |
| 192 | 192 | |
| 193 | - if( has_action( $hook_tag ) ){ |
|
| 193 | + if( has_action( $hook_tag ) ){ |
|
| 194 | 194 | |
| 195 | - $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
|
| 195 | + $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
|
| 196 | 196 | |
| 197 | - if( !empty( $alternative ) ){ |
|
| 197 | + if( !empty( $alternative ) ){ |
|
| 198 | 198 | |
| 199 | - $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
|
| 199 | + $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
|
| 200 | 200 | |
| 201 | - } |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - trigger_error( $error_message ); |
|
| 204 | - do_action( $hook_tag , $args ); |
|
| 203 | + trigger_error( $error_message ); |
|
| 204 | + do_action( $hook_tag , $args ); |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | }// end sensei_do_deprecated_action |
| 209 | 209 | |