@@ -463,6 +463,9 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | } // End sensei_save_quiz_answers() |
| 465 | 465 | |
| 466 | + /** |
|
| 467 | + * @return string |
|
| 468 | + */ |
|
| 466 | 469 | public static function upload_file( $file = array() ) { |
| 467 | 470 | |
| 468 | 471 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
@@ -635,7 +638,7 @@ discard block |
||
| 635 | 638 | * @param integer $lesson_id |
| 636 | 639 | * @param bool $complete |
| 637 | 640 | * |
| 638 | - * @return mixed boolean or comment_ID |
|
| 641 | + * @return boolean|string boolean or comment_ID |
|
| 639 | 642 | */ |
| 640 | 643 | public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
| 641 | 644 | |
@@ -654,7 +657,7 @@ discard block |
||
| 654 | 657 | * @param int| string $user_id default 0 |
| 655 | 658 | * @param bool $complete default false |
| 656 | 659 | * |
| 657 | - * @return mixed boolean or comment_ID |
|
| 660 | + * @return boolean|string boolean or comment_ID |
|
| 658 | 661 | */ |
| 659 | 662 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
| 660 | 663 | |
@@ -836,7 +839,7 @@ discard block |
||
| 836 | 839 | /** |
| 837 | 840 | * Returns the user_grade for a specific question and user, or sensei_user_answer entry |
| 838 | 841 | * |
| 839 | - * @param mixed $question |
|
| 842 | + * @param integer $question |
|
| 840 | 843 | * @param int $user_id |
| 841 | 844 | * @return string |
| 842 | 845 | */ |
@@ -864,7 +867,7 @@ discard block |
||
| 864 | 867 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 865 | 868 | * |
| 866 | 869 | * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
| 867 | - * @param mixed $question |
|
| 870 | + * @param integer $question |
|
| 868 | 871 | * @param int $user_id |
| 869 | 872 | * @return string |
| 870 | 873 | */ |
@@ -977,7 +980,7 @@ discard block |
||
| 977 | 980 | * sort_array_by_key sorts array by key |
| 978 | 981 | * @since 1.3.0 |
| 979 | 982 | * @param array $array by ref |
| 980 | - * @param $key string column name in array |
|
| 983 | + * @param string $key string column name in array |
|
| 981 | 984 | * @return void |
| 982 | 985 | */ |
| 983 | 986 | public static function sort_array_by_key( $array, $key ) { |
@@ -1024,7 +1027,7 @@ discard block |
||
| 1024 | 1027 | /** |
| 1025 | 1028 | * Get pass mark for course |
| 1026 | 1029 | * @param integer $course_id ID of course |
| 1027 | - * @return integer Pass mark for course |
|
| 1030 | + * @return double Pass mark for course |
|
| 1028 | 1031 | */ |
| 1029 | 1032 | public static function sensei_course_pass_grade( $course_id = 0 ) { |
| 1030 | 1033 | |
@@ -1065,7 +1068,7 @@ discard block |
||
| 1065 | 1068 | * Get user total grade for course |
| 1066 | 1069 | * @param integer $course_id ID of course |
| 1067 | 1070 | * @param integer $user_id ID of user |
| 1068 | - * @return integer User's total grade |
|
| 1071 | + * @return double User's total grade |
|
| 1069 | 1072 | */ |
| 1070 | 1073 | public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
| 1071 | 1074 | |
@@ -1434,7 +1437,7 @@ discard block |
||
| 1434 | 1437 | * @since 1.7.0 |
| 1435 | 1438 | * @param integer $course_id Course ID |
| 1436 | 1439 | * @param integer $user_id User ID |
| 1437 | - * @return int |
|
| 1440 | + * @return boolean |
|
| 1438 | 1441 | */ |
| 1439 | 1442 | public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
| 1440 | 1443 | global $wp_version; |
@@ -1592,7 +1595,7 @@ discard block |
||
| 1592 | 1595 | * @since 1.7.0 |
| 1593 | 1596 | * @param int $lesson_id |
| 1594 | 1597 | * @param int $user_id |
| 1595 | - * @return mixed false or comment_ID |
|
| 1598 | + * @return string|false false or comment_ID |
|
| 1596 | 1599 | */ |
| 1597 | 1600 | public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
| 1598 | 1601 | |
@@ -1619,7 +1622,7 @@ discard block |
||
| 1619 | 1622 | * Check if a user has completed a lesson or not |
| 1620 | 1623 | * |
| 1621 | 1624 | * @uses Sensei() |
| 1622 | - * @param mixed $lesson lesson_id or sensei_lesson_status entry |
|
| 1625 | + * @param integer $lesson lesson_id or sensei_lesson_status entry |
|
| 1623 | 1626 | * @param int $user_id |
| 1624 | 1627 | * @return boolean |
| 1625 | 1628 | */ |
@@ -1717,7 +1720,7 @@ discard block |
||
| 1717 | 1720 | * @since 1.7.0 |
| 1718 | 1721 | * @param int $lesson_id |
| 1719 | 1722 | * @param int $user_id |
| 1720 | - * @return object | bool |
|
| 1723 | + * @return integer | bool |
|
| 1721 | 1724 | */ |
| 1722 | 1725 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1723 | 1726 | |
@@ -1776,11 +1779,11 @@ discard block |
||
| 1776 | 1779 | * @since 1.7.0 |
| 1777 | 1780 | * |
| 1778 | 1781 | * @param int|string $user_id |
| 1779 | - * @param int|string $lesson_id |
|
| 1782 | + * @param integer $lesson_id |
|
| 1780 | 1783 | * @param string $status |
| 1781 | 1784 | * @param array $metadata |
| 1782 | 1785 | * |
| 1783 | - * @return mixed false or comment_ID |
|
| 1786 | + * @return boolean false or comment_ID |
|
| 1784 | 1787 | */ |
| 1785 | 1788 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
| 1786 | 1789 | $comment_id = false; |
@@ -1818,7 +1821,7 @@ discard block |
||
| 1818 | 1821 | * @param int $course_id |
| 1819 | 1822 | * @param string $status |
| 1820 | 1823 | * @param array $metadata |
| 1821 | - * @return mixed false or comment_ID |
|
| 1824 | + * @return boolean false or comment_ID |
|
| 1822 | 1825 | */ |
| 1823 | 1826 | public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
| 1824 | 1827 | $comment_id = false; |
@@ -2008,7 +2011,7 @@ discard block |
||
| 2008 | 2011 | * |
| 2009 | 2012 | * @since 1.7.4 |
| 2010 | 2013 | * |
| 2011 | - * @param $data_key |
|
| 2014 | + * @param string $data_key |
|
| 2012 | 2015 | * @param $post_id |
| 2013 | 2016 | * @param int $user_id |
| 2014 | 2017 | * |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Check if WooCommerce is present. |
| 28 | - * |
|
| 29 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
| 28 | + * |
|
| 29 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
| 30 | 30 | * @access public |
| 31 | 31 | * @since 1.0.2 |
| 32 | 32 | * @static |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public static function sensei_is_woocommerce_present () { |
| 36 | 36 | |
| 37 | - return Sensei_WC::is_woocommerce_present(); |
|
| 37 | + return Sensei_WC::is_woocommerce_present(); |
|
| 38 | 38 | |
| 39 | 39 | } // End sensei_is_woocommerce_present() |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Check if WooCommerce is active. |
| 43 | - * |
|
| 44 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
| 43 | + * |
|
| 44 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
| 45 | 45 | * @access public |
| 46 | 46 | * @since 1.0.2 |
| 47 | 47 | * @static |
@@ -186,15 +186,15 @@ discard block |
||
| 186 | 186 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - //Get the comments |
|
| 190 | - /** |
|
| 191 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 192 | - * |
|
| 193 | - * It runs while getting the comments for the given request. |
|
| 194 | - * |
|
| 195 | - * @param int|array $comments |
|
| 196 | - */ |
|
| 197 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 189 | + //Get the comments |
|
| 190 | + /** |
|
| 191 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 192 | + * |
|
| 193 | + * It runs while getting the comments for the given request. |
|
| 194 | + * |
|
| 195 | + * @param int|array $comments |
|
| 196 | + */ |
|
| 197 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 198 | 198 | |
| 199 | 199 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
| 200 | 200 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -279,18 +279,18 @@ discard block |
||
| 279 | 279 | return $dataset_changes; |
| 280 | 280 | } // End sensei_delete_activities() |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Delete all activity for specified user |
|
| 284 | - * @access public |
|
| 282 | + /** |
|
| 283 | + * Delete all activity for specified user |
|
| 284 | + * @access public |
|
| 285 | 285 | * @since 1.5.0 |
| 286 | - * @param integer $user_id User ID |
|
| 287 | - * @return boolean |
|
| 288 | - */ |
|
| 289 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 286 | + * @param integer $user_id User ID |
|
| 287 | + * @return boolean |
|
| 288 | + */ |
|
| 289 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 290 | 290 | |
| 291 | - $dataset_changes = false; |
|
| 291 | + $dataset_changes = false; |
|
| 292 | 292 | |
| 293 | - if( $user_id ) { |
|
| 293 | + if( $user_id ) { |
|
| 294 | 294 | |
| 295 | 295 | $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
| 296 | 296 | |
@@ -334,35 +334,35 @@ discard block |
||
| 334 | 334 | return $activity_value; |
| 335 | 335 | } // End sensei_get_activity_value() |
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * Checks if a user (by email) has bought an item. |
|
| 339 | - * |
|
| 340 | - * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 341 | - * @access public |
|
| 342 | - * @since 1.0.0 |
|
| 343 | - * @param string $customer_email |
|
| 344 | - * @param int $user_id |
|
| 345 | - * @param int $product_id |
|
| 346 | - * @return bool |
|
| 347 | - */ |
|
| 348 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 337 | + /** |
|
| 338 | + * Checks if a user (by email) has bought an item. |
|
| 339 | + * |
|
| 340 | + * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 341 | + * @access public |
|
| 342 | + * @since 1.0.0 |
|
| 343 | + * @param string $customer_email |
|
| 344 | + * @param int $user_id |
|
| 345 | + * @param int $product_id |
|
| 346 | + * @return bool |
|
| 347 | + */ |
|
| 348 | + public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 349 | 349 | |
| 350 | - $emails = array(); |
|
| 350 | + $emails = array(); |
|
| 351 | 351 | |
| 352 | - if ( $user_id ) { |
|
| 353 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 354 | - $emails[] = $user->user_email; |
|
| 355 | - } |
|
| 352 | + if ( $user_id ) { |
|
| 353 | + $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 354 | + $emails[] = $user->user_email; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - if ( is_email( $customer_email ) ) |
|
| 358 | - $emails[] = $customer_email; |
|
| 357 | + if ( is_email( $customer_email ) ) |
|
| 358 | + $emails[] = $customer_email; |
|
| 359 | 359 | |
| 360 | - if ( sizeof( $emails ) == 0 ) |
|
| 361 | - return false; |
|
| 360 | + if ( sizeof( $emails ) == 0 ) |
|
| 361 | + return false; |
|
| 362 | 362 | |
| 363 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 363 | + return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 364 | 364 | |
| 365 | - } // End sensei_customer_bought_product() |
|
| 365 | + } // End sensei_customer_bought_product() |
|
| 366 | 366 | |
| 367 | 367 | /** |
| 368 | 368 | * Load the WordPress rich text editor |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | /** |
| 399 | 399 | * Save quiz answers submitted by users |
| 400 | 400 | * @param array $submitted User's quiz answers |
| 401 | - * @param int $user_id |
|
| 401 | + * @param int $user_id |
|
| 402 | 402 | * @return boolean Whether the answers were saved or not |
| 403 | 403 | */ |
| 404 | 404 | public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
@@ -467,72 +467,72 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
| 469 | 469 | |
| 470 | - /** |
|
| 471 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
| 472 | - * |
|
| 473 | - * This filter was mainly added for Unit Testing purposes. |
|
| 474 | - * |
|
| 475 | - * @since 1.7.4 |
|
| 476 | - * |
|
| 477 | - * @param array $file_upload_args { |
|
| 478 | - * array of current values |
|
| 479 | - * |
|
| 480 | - * @type string test_form set to false by default |
|
| 481 | - * } |
|
| 482 | - */ |
|
| 483 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 470 | + /** |
|
| 471 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
| 472 | + * |
|
| 473 | + * This filter was mainly added for Unit Testing purposes. |
|
| 474 | + * |
|
| 475 | + * @since 1.7.4 |
|
| 476 | + * |
|
| 477 | + * @param array $file_upload_args { |
|
| 478 | + * array of current values |
|
| 479 | + * |
|
| 480 | + * @type string test_form set to false by default |
|
| 481 | + * } |
|
| 482 | + */ |
|
| 483 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 484 | 484 | |
| 485 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 485 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 486 | 486 | |
| 487 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 488 | - return false; |
|
| 489 | - } else { |
|
| 487 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 488 | + return false; |
|
| 489 | + } else { |
|
| 490 | 490 | |
| 491 | - $filename = $file_return['file']; |
|
| 491 | + $filename = $file_return['file']; |
|
| 492 | 492 | |
| 493 | - $attachment = array( |
|
| 494 | - 'post_mime_type' => $file_return['type'], |
|
| 495 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 496 | - 'post_content' => '', |
|
| 497 | - 'post_status' => 'inherit', |
|
| 498 | - 'guid' => $file_return['url'] |
|
| 499 | - ); |
|
| 493 | + $attachment = array( |
|
| 494 | + 'post_mime_type' => $file_return['type'], |
|
| 495 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 496 | + 'post_content' => '', |
|
| 497 | + 'post_status' => 'inherit', |
|
| 498 | + 'guid' => $file_return['url'] |
|
| 499 | + ); |
|
| 500 | 500 | |
| 501 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 501 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 502 | 502 | |
| 503 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 504 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 505 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 503 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 504 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 505 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 506 | 506 | |
| 507 | - if( 0 < intval( $attachment_id ) ) { |
|
| 508 | - return $attachment_id; |
|
| 509 | - } |
|
| 510 | - } |
|
| 507 | + if( 0 < intval( $attachment_id ) ) { |
|
| 508 | + return $attachment_id; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | - return false; |
|
| 512 | + return false; |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
| 516 | 516 | * Grade quiz automatically |
| 517 | - * |
|
| 518 | - * This function grades each question automatically if the are auto gradable. |
|
| 519 | - * It store all question grades. |
|
| 520 | - * |
|
| 521 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 522 | - * |
|
| 517 | + * |
|
| 518 | + * This function grades each question automatically if the are auto gradable. |
|
| 519 | + * It store all question grades. |
|
| 520 | + * |
|
| 521 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 522 | + * |
|
| 523 | 523 | * @param integer $quiz_id ID of quiz |
| 524 | 524 | * @param array $submitted questions id ans answers { |
| 525 | - * @type int $question_id |
|
| 526 | - * @type mixed $answer |
|
| 527 | - * } |
|
| 525 | + * @type int $question_id |
|
| 526 | + * @type mixed $answer |
|
| 527 | + * } |
|
| 528 | 528 | * @param integer $total_questions Total questions in quiz (not used) |
| 529 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 530 | - * |
|
| 529 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 530 | + * |
|
| 531 | 531 | * @return int $quiz_grade total sum of all question grades |
| 532 | 532 | */ |
| 533 | 533 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
| 534 | 534 | |
| 535 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 535 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 536 | 536 | |
| 537 | 537 | } // End sensei_grade_quiz_auto() |
| 538 | 538 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | * @param integer $quiz_id ID of quiz |
| 542 | 542 | * @param integer $grade Grade received |
| 543 | 543 | * @param integer $user_id ID of user being graded |
| 544 | - * @param string $quiz_grade_type default 'auto' |
|
| 544 | + * @param string $quiz_grade_type default 'auto' |
|
| 545 | 545 | * @return boolean |
| 546 | 546 | */ |
| 547 | 547 | public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
@@ -565,21 +565,21 @@ discard block |
||
| 565 | 565 | |
| 566 | 566 | /** |
| 567 | 567 | * Grade question automatically |
| 568 | - * |
|
| 569 | - * This function checks the question typ and then grades it accordingly. |
|
| 570 | - * |
|
| 571 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 572 | - * |
|
| 568 | + * |
|
| 569 | + * This function checks the question typ and then grades it accordingly. |
|
| 570 | + * |
|
| 571 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 572 | + * |
|
| 573 | 573 | * @param integer $question_id |
| 574 | - * @param string $question_type of the standard Sensei question types |
|
| 574 | + * @param string $question_type of the standard Sensei question types |
|
| 575 | 575 | * @param string $answer |
| 576 | - * @param int $user_id |
|
| 577 | - * |
|
| 576 | + * @param int $user_id |
|
| 577 | + * |
|
| 578 | 578 | * @return int $question_grade |
| 579 | 579 | */ |
| 580 | 580 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
| 581 | 581 | |
| 582 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 582 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 583 | 583 | |
| 584 | 584 | } // end sensei_grade_question_auto |
| 585 | 585 | |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * Grade question |
| 588 | 588 | * @param integer $question_id ID of question |
| 589 | 589 | * @param integer $grade Grade received |
| 590 | - * @param int $user_id |
|
| 590 | + * @param int $user_id |
|
| 591 | 591 | * @return boolean |
| 592 | 592 | */ |
| 593 | 593 | public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
@@ -626,35 +626,35 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | |
| 629 | - /** |
|
| 630 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 631 | - * |
|
| 632 | - * @since 1.7.4 |
|
| 633 | - * |
|
| 634 | - * @param integer $user_id |
|
| 635 | - * @param integer $lesson_id |
|
| 636 | - * @param bool $complete |
|
| 637 | - * |
|
| 638 | - * @return mixed boolean or comment_ID |
|
| 639 | - */ |
|
| 640 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 629 | + /** |
|
| 630 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 631 | + * |
|
| 632 | + * @since 1.7.4 |
|
| 633 | + * |
|
| 634 | + * @param integer $user_id |
|
| 635 | + * @param integer $lesson_id |
|
| 636 | + * @param bool $complete |
|
| 637 | + * |
|
| 638 | + * @return mixed boolean or comment_ID |
|
| 639 | + */ |
|
| 640 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 641 | 641 | |
| 642 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 642 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 643 | 643 | |
| 644 | - }// end user_start_lesson() |
|
| 644 | + }// end user_start_lesson() |
|
| 645 | 645 | |
| 646 | 646 | /** |
| 647 | 647 | * Mark a lesson as started for user |
| 648 | - * |
|
| 649 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 650 | - * |
|
| 651 | - * @since 1.6.0 |
|
| 652 | - * |
|
| 648 | + * |
|
| 649 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 650 | + * |
|
| 651 | + * @since 1.6.0 |
|
| 652 | + * |
|
| 653 | 653 | * @param integer $lesson_id ID of lesson |
| 654 | 654 | * @param int| string $user_id default 0 |
| 655 | - * @param bool $complete default false |
|
| 656 | - * |
|
| 657 | - * @return mixed boolean or comment_ID |
|
| 655 | + * @param bool $complete default false |
|
| 656 | + * |
|
| 657 | + * @return mixed boolean or comment_ID |
|
| 658 | 658 | */ |
| 659 | 659 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
| 660 | 660 | |
@@ -700,21 +700,21 @@ discard block |
||
| 700 | 700 | $metadata['start'] = current_time('mysql'); |
| 701 | 701 | $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
| 702 | 702 | |
| 703 | - } else { |
|
| 703 | + } else { |
|
| 704 | 704 | |
| 705 | - // if users is already taking the lesson and the status changes to complete update it |
|
| 706 | - $current_user_activity = get_comment($activity_logged); |
|
| 707 | - if( $status=='complete' && |
|
| 708 | - $status != $current_user_activity->comment_approved ){ |
|
| 705 | + // if users is already taking the lesson and the status changes to complete update it |
|
| 706 | + $current_user_activity = get_comment($activity_logged); |
|
| 707 | + if( $status=='complete' && |
|
| 708 | + $status != $current_user_activity->comment_approved ){ |
|
| 709 | 709 | |
| 710 | - $comment = array(); |
|
| 711 | - $comment['comment_ID'] = $activity_logged; |
|
| 712 | - $comment['comment_approved'] = $status; |
|
| 713 | - wp_update_comment( $comment ); |
|
| 710 | + $comment = array(); |
|
| 711 | + $comment['comment_ID'] = $activity_logged; |
|
| 712 | + $comment['comment_approved'] = $status; |
|
| 713 | + wp_update_comment( $comment ); |
|
| 714 | 714 | |
| 715 | - } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - } |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | 719 | if ( $complete ) { |
| 720 | 720 | // Run this *after* the lesson status has been created/updated |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | /** |
| 864 | 864 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 865 | 865 | * |
| 866 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 866 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 867 | 867 | * @param mixed $question |
| 868 | 868 | * @param int $user_id |
| 869 | 869 | * @return string |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | * Add answer notes to question |
| 924 | 924 | * @param integer $question_id ID of question |
| 925 | 925 | * @param integer $user_id ID of user |
| 926 | - * @param string $notes |
|
| 926 | + * @param string $notes |
|
| 927 | 927 | * @return boolean |
| 928 | 928 | */ |
| 929 | 929 | public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
@@ -981,17 +981,17 @@ discard block |
||
| 981 | 981 | * @return void |
| 982 | 982 | */ |
| 983 | 983 | public static function sort_array_by_key( $array, $key ) { |
| 984 | - $sorter = array(); |
|
| 985 | - $ret = array(); |
|
| 986 | - reset( $array ); |
|
| 987 | - foreach ( $array as $ii => $va ) { |
|
| 988 | - $sorter[$ii] = $va[$key]; |
|
| 989 | - } // End For Loop |
|
| 990 | - asort( $sorter ); |
|
| 991 | - foreach ( $sorter as $ii => $va ) { |
|
| 992 | - $ret[$ii] = $array[$ii]; |
|
| 993 | - } // End For Loop |
|
| 994 | - $array = $ret; |
|
| 984 | + $sorter = array(); |
|
| 985 | + $ret = array(); |
|
| 986 | + reset( $array ); |
|
| 987 | + foreach ( $array as $ii => $va ) { |
|
| 988 | + $sorter[$ii] = $va[$key]; |
|
| 989 | + } // End For Loop |
|
| 990 | + asort( $sorter ); |
|
| 991 | + foreach ( $sorter as $ii => $va ) { |
|
| 992 | + $ret[$ii] = $array[$ii]; |
|
| 993 | + } // End For Loop |
|
| 994 | + $array = $ret; |
|
| 995 | 995 | } // End sort_array_by_key() |
| 996 | 996 | |
| 997 | 997 | /** |
@@ -1004,21 +1004,21 @@ discard block |
||
| 1004 | 1004 | $questions_array = array(); |
| 1005 | 1005 | if ( 0 < $quiz_id ) { |
| 1006 | 1006 | $question_args = array( 'post_type' => 'question', |
| 1007 | - 'posts_per_page' => -1, |
|
| 1008 | - 'orderby' => 'ID', |
|
| 1009 | - 'order' => 'ASC', |
|
| 1010 | - 'meta_query' => array( |
|
| 1007 | + 'posts_per_page' => -1, |
|
| 1008 | + 'orderby' => 'ID', |
|
| 1009 | + 'order' => 'ASC', |
|
| 1010 | + 'meta_query' => array( |
|
| 1011 | 1011 | array( |
| 1012 | 1012 | 'key' => '_quiz_id', |
| 1013 | 1013 | 'value' => $quiz_id, |
| 1014 | 1014 | ) |
| 1015 | 1015 | ), |
| 1016 | - 'post_status' => 'any', |
|
| 1017 | - 'suppress_filters' => 0 |
|
| 1018 | - ); |
|
| 1019 | - $questions_array = get_posts( $question_args ); |
|
| 1020 | - } // End If Statement |
|
| 1021 | - return $questions_array; |
|
| 1016 | + 'post_status' => 'any', |
|
| 1017 | + 'suppress_filters' => 0 |
|
| 1018 | + ); |
|
| 1019 | + $questions_array = get_posts( $question_args ); |
|
| 1020 | + } // End If Statement |
|
| 1021 | + return $questions_array; |
|
| 1022 | 1022 | } // End lesson_quiz_questions() |
| 1023 | 1023 | |
| 1024 | 1024 | /** |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | * Set the status message displayed to the user for a quiz |
| 1179 | 1179 | * @param integer $lesson_id ID of quiz lesson |
| 1180 | 1180 | * @param integer $user_id ID of user |
| 1181 | - * @param bool $is_lesson |
|
| 1181 | + * @param bool $is_lesson |
|
| 1182 | 1182 | * @return array Status code and message |
| 1183 | 1183 | */ |
| 1184 | 1184 | public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
@@ -1261,20 +1261,20 @@ discard block |
||
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | - // add next lesson button |
|
| 1265 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1266 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1264 | + // add next lesson button |
|
| 1265 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1266 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1267 | 1267 | |
| 1268 | - // Output HTML |
|
| 1269 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1270 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1271 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1272 | - .'</a>'; |
|
| 1268 | + // Output HTML |
|
| 1269 | + if ( ( 0 < $next_lesson_id ) ) { |
|
| 1270 | + $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1271 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1272 | + .'</a>'; |
|
| 1273 | 1273 | |
| 1274 | - } |
|
| 1274 | + } |
|
| 1275 | 1275 | |
| 1276 | 1276 | } |
| 1277 | - // Lesson/Quiz not complete |
|
| 1277 | + // Lesson/Quiz not complete |
|
| 1278 | 1278 | else { |
| 1279 | 1279 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1280 | 1280 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1332,7 +1332,7 @@ discard block |
||
| 1332 | 1332 | $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
| 1333 | 1333 | |
| 1334 | 1334 | if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
| 1335 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1335 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1336 | 1336 | $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>'; |
| 1337 | 1337 | } |
| 1338 | 1338 | |
@@ -1393,18 +1393,18 @@ discard block |
||
| 1393 | 1393 | $user_id = get_current_user_id(); |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | - if ( ! $user_id > 0 ) { |
|
| 1396 | + if ( ! $user_id > 0 ) { |
|
| 1397 | 1397 | |
| 1398 | - $user_started_course = false; |
|
| 1398 | + $user_started_course = false; |
|
| 1399 | 1399 | |
| 1400 | - } else { |
|
| 1400 | + } else { |
|
| 1401 | 1401 | |
| 1402 | - $activity_args = array( |
|
| 1403 | - 'post_id' => $course_id, |
|
| 1404 | - 'user_id' => $user_id, |
|
| 1405 | - 'type' => 'sensei_course_status', |
|
| 1406 | - 'field' => 'comment_ID' |
|
| 1407 | - ); |
|
| 1402 | + $activity_args = array( |
|
| 1403 | + 'post_id' => $course_id, |
|
| 1404 | + 'user_id' => $user_id, |
|
| 1405 | + 'type' => 'sensei_course_status', |
|
| 1406 | + 'field' => 'comment_ID' |
|
| 1407 | + ); |
|
| 1408 | 1408 | |
| 1409 | 1409 | $user_course_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
| 1410 | 1410 | |
@@ -1413,7 +1413,7 @@ discard block |
||
| 1413 | 1413 | $user_started_course = $user_course_status_id; |
| 1414 | 1414 | |
| 1415 | 1415 | } |
| 1416 | - } |
|
| 1416 | + } |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | /** |
@@ -1542,7 +1542,7 @@ discard block |
||
| 1542 | 1542 | * Check if a user has completed a course or not |
| 1543 | 1543 | * |
| 1544 | 1544 | * @param int | WP_Post | WP_Comment $course course_id or sensei_course_status entry |
| 1545 | - * |
|
| 1545 | + * |
|
| 1546 | 1546 | * @param int $user_id |
| 1547 | 1547 | * @return boolean |
| 1548 | 1548 | */ |
@@ -1569,14 +1569,14 @@ discard block |
||
| 1569 | 1569 | } |
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1573 | - $course = $course->ID; |
|
| 1574 | - } |
|
| 1572 | + if( is_a( $course, 'WP_Post' ) ){ |
|
| 1573 | + $course = $course->ID; |
|
| 1574 | + } |
|
| 1575 | 1575 | |
| 1576 | 1576 | $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
| 1577 | 1577 | if( isset( $user_course_status->comment_approved ) ){ |
| 1578 | - $user_course_status = $user_course_status->comment_approved; |
|
| 1579 | - } |
|
| 1578 | + $user_course_status = $user_course_status->comment_approved; |
|
| 1579 | + } |
|
| 1580 | 1580 | |
| 1581 | 1581 | } |
| 1582 | 1582 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1601,11 +1601,11 @@ discard block |
||
| 1601 | 1601 | $user_id = get_current_user_id(); |
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | - $activity_args = array( |
|
| 1605 | - 'post_id' => $lesson_id, |
|
| 1606 | - 'user_id' => $user_id, |
|
| 1607 | - 'type' => 'sensei_lesson_status', |
|
| 1608 | - 'field' => 'comment_ID' ); |
|
| 1604 | + $activity_args = array( |
|
| 1605 | + 'post_id' => $lesson_id, |
|
| 1606 | + 'user_id' => $user_id, |
|
| 1607 | + 'type' => 'sensei_lesson_status', |
|
| 1608 | + 'field' => 'comment_ID' ); |
|
| 1609 | 1609 | |
| 1610 | 1610 | $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
| 1611 | 1611 | if( $user_lesson_status_id ) { |
@@ -1618,7 +1618,7 @@ discard block |
||
| 1618 | 1618 | /** |
| 1619 | 1619 | * Check if a user has completed a lesson or not |
| 1620 | 1620 | * |
| 1621 | - * @uses Sensei() |
|
| 1621 | + * @uses Sensei() |
|
| 1622 | 1622 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
| 1623 | 1623 | * @param int $user_id |
| 1624 | 1624 | * @return boolean |
@@ -1639,10 +1639,10 @@ discard block |
||
| 1639 | 1639 | $user_id = get_current_user_id(); |
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | - // the user is not logged in |
|
| 1643 | - if( ! $user_id > 0 ){ |
|
| 1644 | - return false; |
|
| 1645 | - } |
|
| 1642 | + // the user is not logged in |
|
| 1643 | + if( ! $user_id > 0 ){ |
|
| 1644 | + return false; |
|
| 1645 | + } |
|
| 1646 | 1646 | $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
| 1647 | 1647 | |
| 1648 | 1648 | if ( $_user_lesson_status ) { |
@@ -1721,9 +1721,9 @@ discard block |
||
| 1721 | 1721 | */ |
| 1722 | 1722 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1723 | 1723 | |
| 1724 | - if( ! $user_id ) { |
|
| 1725 | - $user_id = get_current_user_id(); |
|
| 1726 | - } |
|
| 1724 | + if( ! $user_id ) { |
|
| 1725 | + $user_id = get_current_user_id(); |
|
| 1726 | + } |
|
| 1727 | 1727 | |
| 1728 | 1728 | if( $lesson_id > 0 && $user_id > 0 ) { |
| 1729 | 1729 | |
@@ -1774,12 +1774,12 @@ discard block |
||
| 1774 | 1774 | * Sets the status for the lesson |
| 1775 | 1775 | * |
| 1776 | 1776 | * @since 1.7.0 |
| 1777 | - * |
|
| 1777 | + * |
|
| 1778 | 1778 | * @param int|string $user_id |
| 1779 | 1779 | * @param int|string $lesson_id |
| 1780 | 1780 | * @param string $status |
| 1781 | 1781 | * @param array $metadata |
| 1782 | - * |
|
| 1782 | + * |
|
| 1783 | 1783 | * @return mixed false or comment_ID |
| 1784 | 1784 | */ |
| 1785 | 1785 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1895,7 +1895,7 @@ discard block |
||
| 1895 | 1895 | /** |
| 1896 | 1896 | * Adjust the comment query to be faster on the database, used by Analysis admin |
| 1897 | 1897 | * @since 1.7.0 |
| 1898 | - * @param array $pieces |
|
| 1898 | + * @param array $pieces |
|
| 1899 | 1899 | * @return array $pieces |
| 1900 | 1900 | */ |
| 1901 | 1901 | public static function comment_total_sum_meta_value_filter( $pieces ) { |
@@ -1930,360 +1930,360 @@ discard block |
||
| 1930 | 1930 | return $pieces; |
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | - /** |
|
| 1934 | - * |
|
| 1935 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1936 | - * @since 1.7.4 |
|
| 1937 | - * |
|
| 1938 | - * @param string $data_key maximum 39 characters allowed |
|
| 1939 | - * @param int $post_id |
|
| 1940 | - * @param mixed $value |
|
| 1941 | - * @param int $user_id |
|
| 1942 | - * |
|
| 1943 | - * @return bool $success |
|
| 1944 | - */ |
|
| 1945 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1946 | - |
|
| 1947 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1948 | - |
|
| 1949 | - }// end add_user_data |
|
| 1950 | - |
|
| 1951 | - /** |
|
| 1952 | - * add user specific data to the passed in sensei post type id |
|
| 1953 | - * |
|
| 1954 | - * This function saves comment meta on the users current status. If no status is available |
|
| 1955 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1956 | - * |
|
| 1957 | - * @since 1.7.4 |
|
| 1958 | - * |
|
| 1959 | - * @param string $data_key maximum 39 characters allowed |
|
| 1960 | - * @param int $post_id |
|
| 1961 | - * @param mixed $value |
|
| 1962 | - * @param int $user_id |
|
| 1963 | - * |
|
| 1964 | - * @return bool $success |
|
| 1965 | - */ |
|
| 1966 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1967 | - |
|
| 1968 | - if( ! ( $user_id > 0 ) ){ |
|
| 1969 | - $user_id = get_current_user_id(); |
|
| 1970 | - } |
|
| 1971 | - |
|
| 1972 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1973 | - $post_type = get_post_type( $post_id ); |
|
| 1974 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1975 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1976 | - || !get_userdata( $user_id ) |
|
| 1977 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1978 | - |
|
| 1979 | - return false; |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1983 | - // and get the activity ID |
|
| 1984 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1985 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1986 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1987 | - |
|
| 1988 | - $start_function = 'user_start_'.$post_type; |
|
| 1989 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1990 | - |
|
| 1991 | - }else{ |
|
| 1992 | - |
|
| 1993 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1994 | - |
|
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - // store the data |
|
| 1998 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1999 | - |
|
| 2000 | - return $success; |
|
| 2001 | - |
|
| 2002 | - }//update_user_data |
|
| 2003 | - |
|
| 2004 | - /** |
|
| 2005 | - * Get the user data stored on the passed in post type |
|
| 2006 | - * |
|
| 2007 | - * This function gets the comment meta on the lesson or course status |
|
| 2008 | - * |
|
| 2009 | - * @since 1.7.4 |
|
| 2010 | - * |
|
| 2011 | - * @param $data_key |
|
| 2012 | - * @param $post_id |
|
| 2013 | - * @param int $user_id |
|
| 2014 | - * |
|
| 2015 | - * @return mixed $user_data_value |
|
| 2016 | - */ |
|
| 2017 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 2018 | - |
|
| 2019 | - $user_data_value = true; |
|
| 2020 | - |
|
| 2021 | - if( ! ( $user_id > 0 ) ){ |
|
| 2022 | - $user_id = get_current_user_id(); |
|
| 2023 | - } |
|
| 2024 | - |
|
| 2025 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2026 | - $post_type = get_post_type( $post_id ); |
|
| 2027 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2028 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2029 | - || ! get_userdata( $user_id ) |
|
| 2030 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2031 | - |
|
| 2032 | - return false; |
|
| 2033 | - } |
|
| 2034 | - |
|
| 2035 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2036 | - // and get the activity ID |
|
| 2037 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2038 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2039 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2040 | - return false; |
|
| 2041 | - } |
|
| 2042 | - |
|
| 2043 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2044 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2045 | - |
|
| 2046 | - return $user_data_value; |
|
| 2047 | - |
|
| 2048 | - }// end get_user_data |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 2052 | - * |
|
| 2053 | - * @param int $data_key |
|
| 2054 | - * @param int $post_id |
|
| 2055 | - * @param int $user_id |
|
| 2056 | - * |
|
| 2057 | - * @return bool $deleted |
|
| 2058 | - */ |
|
| 2059 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2060 | - $deleted = true; |
|
| 1933 | + /** |
|
| 1934 | + * |
|
| 1935 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1936 | + * @since 1.7.4 |
|
| 1937 | + * |
|
| 1938 | + * @param string $data_key maximum 39 characters allowed |
|
| 1939 | + * @param int $post_id |
|
| 1940 | + * @param mixed $value |
|
| 1941 | + * @param int $user_id |
|
| 1942 | + * |
|
| 1943 | + * @return bool $success |
|
| 1944 | + */ |
|
| 1945 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1946 | + |
|
| 1947 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1948 | + |
|
| 1949 | + }// end add_user_data |
|
| 1950 | + |
|
| 1951 | + /** |
|
| 1952 | + * add user specific data to the passed in sensei post type id |
|
| 1953 | + * |
|
| 1954 | + * This function saves comment meta on the users current status. If no status is available |
|
| 1955 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1956 | + * |
|
| 1957 | + * @since 1.7.4 |
|
| 1958 | + * |
|
| 1959 | + * @param string $data_key maximum 39 characters allowed |
|
| 1960 | + * @param int $post_id |
|
| 1961 | + * @param mixed $value |
|
| 1962 | + * @param int $user_id |
|
| 1963 | + * |
|
| 1964 | + * @return bool $success |
|
| 1965 | + */ |
|
| 1966 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1967 | + |
|
| 1968 | + if( ! ( $user_id > 0 ) ){ |
|
| 1969 | + $user_id = get_current_user_id(); |
|
| 1970 | + } |
|
| 1971 | + |
|
| 1972 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1973 | + $post_type = get_post_type( $post_id ); |
|
| 1974 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1975 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1976 | + || !get_userdata( $user_id ) |
|
| 1977 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 2061 | 1978 | |
| 2062 | - if( ! ( $user_id > 0 ) ){ |
|
| 2063 | - $user_id = get_current_user_id(); |
|
| 2064 | - } |
|
| 1979 | + return false; |
|
| 1980 | + } |
|
| 2065 | 1981 | |
| 2066 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2067 | - $post_type = get_post_type( $post_id ); |
|
| 2068 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2069 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2070 | - || ! get_userdata( $user_id ) |
|
| 2071 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1982 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1983 | + // and get the activity ID |
|
| 1984 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1985 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1986 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2072 | 1987 | |
| 2073 | - return false; |
|
| 2074 | - } |
|
| 1988 | + $start_function = 'user_start_'.$post_type; |
|
| 1989 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 2075 | 1990 | |
| 2076 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2077 | - // and get the activity ID |
|
| 2078 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2079 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2080 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2081 | - return false; |
|
| 2082 | - } |
|
| 1991 | + }else{ |
|
| 2083 | 1992 | |
| 2084 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2085 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 1993 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2086 | 1994 | |
| 2087 | - return $deleted; |
|
| 1995 | + } |
|
| 2088 | 1996 | |
| 2089 | - }// end delete_user_data |
|
| 1997 | + // store the data |
|
| 1998 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 2090 | 1999 | |
| 2000 | + return $success; |
|
| 2091 | 2001 | |
| 2092 | - /** |
|
| 2093 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2094 | - * |
|
| 2095 | - * @since 1.8.0 |
|
| 2096 | - * |
|
| 2097 | - * @param string $selected_value |
|
| 2098 | - * @param $options{ |
|
| 2099 | - * @type string $value the value saved in the database |
|
| 2100 | - * @type string $option what the user will see in the list of items |
|
| 2101 | - * } |
|
| 2102 | - * @param array $attributes{ |
|
| 2103 | - * @type string $attribute type such name or id etc. |
|
| 2104 | - * @type string $value |
|
| 2105 | - * } |
|
| 2106 | - * @param bool $enable_none_option |
|
| 2107 | - * |
|
| 2108 | - * @return string $drop_down_element |
|
| 2109 | - */ |
|
| 2110 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2002 | + }//update_user_data |
|
| 2111 | 2003 | |
| 2112 | - $drop_down_element = ''; |
|
| 2004 | + /** |
|
| 2005 | + * Get the user data stored on the passed in post type |
|
| 2006 | + * |
|
| 2007 | + * This function gets the comment meta on the lesson or course status |
|
| 2008 | + * |
|
| 2009 | + * @since 1.7.4 |
|
| 2010 | + * |
|
| 2011 | + * @param $data_key |
|
| 2012 | + * @param $post_id |
|
| 2013 | + * @param int $user_id |
|
| 2014 | + * |
|
| 2015 | + * @return mixed $user_data_value |
|
| 2016 | + */ |
|
| 2017 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 2113 | 2018 | |
| 2114 | - // setup the basic attributes |
|
| 2115 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2019 | + $user_data_value = true; |
|
| 2116 | 2020 | |
| 2117 | - $attributes['name'] = 'sensei-options'; |
|
| 2021 | + if( ! ( $user_id > 0 ) ){ |
|
| 2022 | + $user_id = get_current_user_id(); |
|
| 2023 | + } |
|
| 2118 | 2024 | |
| 2119 | - } |
|
| 2025 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 2026 | + $post_type = get_post_type( $post_id ); |
|
| 2027 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2028 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2029 | + || ! get_userdata( $user_id ) |
|
| 2030 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2120 | 2031 | |
| 2121 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2032 | + return false; |
|
| 2033 | + } |
|
| 2122 | 2034 | |
| 2123 | - $attributes['id'] = 'sensei-options'; |
|
| 2035 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2036 | + // and get the activity ID |
|
| 2037 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2038 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2039 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2040 | + return false; |
|
| 2041 | + } |
|
| 2124 | 2042 | |
| 2125 | - } |
|
| 2043 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2044 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2126 | 2045 | |
| 2127 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2046 | + return $user_data_value; |
|
| 2128 | 2047 | |
| 2129 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2048 | + }// end get_user_data |
|
| 2130 | 2049 | |
| 2131 | - } |
|
| 2050 | + /** |
|
| 2051 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 2052 | + * |
|
| 2053 | + * @param int $data_key |
|
| 2054 | + * @param int $post_id |
|
| 2055 | + * @param int $user_id |
|
| 2056 | + * |
|
| 2057 | + * @return bool $deleted |
|
| 2058 | + */ |
|
| 2059 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2060 | + $deleted = true; |
|
| 2132 | 2061 | |
| 2133 | - // create element attributes |
|
| 2134 | - $combined_attributes = ''; |
|
| 2135 | - foreach( $attributes as $attribute => $value ){ |
|
| 2062 | + if( ! ( $user_id > 0 ) ){ |
|
| 2063 | + $user_id = get_current_user_id(); |
|
| 2064 | + } |
|
| 2136 | 2065 | |
| 2137 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2066 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 2067 | + $post_type = get_post_type( $post_id ); |
|
| 2068 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2069 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2070 | + || ! get_userdata( $user_id ) |
|
| 2071 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2138 | 2072 | |
| 2139 | - }// end for each |
|
| 2073 | + return false; |
|
| 2074 | + } |
|
| 2140 | 2075 | |
| 2076 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2077 | + // and get the activity ID |
|
| 2078 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2079 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2080 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2081 | + return false; |
|
| 2082 | + } |
|
| 2141 | 2083 | |
| 2142 | - // create the select element |
|
| 2143 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2084 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2085 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2144 | 2086 | |
| 2145 | - // show the none option if the client requested |
|
| 2146 | - if( $enable_none_option ) { |
|
| 2147 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2148 | - } |
|
| 2087 | + return $deleted; |
|
| 2149 | 2088 | |
| 2150 | - if ( count( $options ) > 0 ) { |
|
| 2089 | + }// end delete_user_data |
|
| 2151 | 2090 | |
| 2152 | - foreach ($options as $value => $option ){ |
|
| 2153 | 2091 | |
| 2154 | - $element = ''; |
|
| 2155 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2156 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2157 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2092 | + /** |
|
| 2093 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2094 | + * |
|
| 2095 | + * @since 1.8.0 |
|
| 2096 | + * |
|
| 2097 | + * @param string $selected_value |
|
| 2098 | + * @param $options{ |
|
| 2099 | + * @type string $value the value saved in the database |
|
| 2100 | + * @type string $option what the user will see in the list of items |
|
| 2101 | + * } |
|
| 2102 | + * @param array $attributes{ |
|
| 2103 | + * @type string $attribute type such name or id etc. |
|
| 2104 | + * @type string $value |
|
| 2105 | + * } |
|
| 2106 | + * @param bool $enable_none_option |
|
| 2107 | + * |
|
| 2108 | + * @return string $drop_down_element |
|
| 2109 | + */ |
|
| 2110 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2158 | 2111 | |
| 2159 | - // add the element to the select html |
|
| 2160 | - $drop_down_element.= $element; |
|
| 2161 | - } // End For Loop |
|
| 2112 | + $drop_down_element = ''; |
|
| 2162 | 2113 | |
| 2163 | - } // End If Statement |
|
| 2114 | + // setup the basic attributes |
|
| 2115 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2164 | 2116 | |
| 2165 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2117 | + $attributes['name'] = 'sensei-options'; |
|
| 2166 | 2118 | |
| 2167 | - return $drop_down_element; |
|
| 2119 | + } |
|
| 2168 | 2120 | |
| 2169 | - }// generate_drop_down |
|
| 2121 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2170 | 2122 | |
| 2171 | - /** |
|
| 2172 | - * Wrapper for the default php round() function. |
|
| 2173 | - * This allows us to give more control to a user on how they can round Sensei |
|
| 2174 | - * decimals passed through this function. |
|
| 2175 | - * |
|
| 2176 | - * @since 1.8.5 |
|
| 2177 | - * |
|
| 2178 | - * @param double $val |
|
| 2179 | - * @param int $precision |
|
| 2180 | - * @param $mode |
|
| 2181 | - * @param string $context |
|
| 2182 | - * |
|
| 2183 | - * @return double $val |
|
| 2184 | - */ |
|
| 2185 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2123 | + $attributes['id'] = 'sensei-options'; |
|
| 2186 | 2124 | |
| 2187 | - /**å |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2128 | + |
|
| 2129 | + $attributes['class'] ='chosen_select widefat'; |
|
| 2130 | + |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + // create element attributes |
|
| 2134 | + $combined_attributes = ''; |
|
| 2135 | + foreach( $attributes as $attribute => $value ){ |
|
| 2136 | + |
|
| 2137 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2138 | + |
|
| 2139 | + }// end for each |
|
| 2140 | + |
|
| 2141 | + |
|
| 2142 | + // create the select element |
|
| 2143 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2144 | + |
|
| 2145 | + // show the none option if the client requested |
|
| 2146 | + if( $enable_none_option ) { |
|
| 2147 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2148 | + } |
|
| 2149 | + |
|
| 2150 | + if ( count( $options ) > 0 ) { |
|
| 2151 | + |
|
| 2152 | + foreach ($options as $value => $option ){ |
|
| 2153 | + |
|
| 2154 | + $element = ''; |
|
| 2155 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2156 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2157 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2158 | + |
|
| 2159 | + // add the element to the select html |
|
| 2160 | + $drop_down_element.= $element; |
|
| 2161 | + } // End For Loop |
|
| 2162 | + |
|
| 2163 | + } // End If Statement |
|
| 2164 | + |
|
| 2165 | + $drop_down_element .= '</select>' . "\n"; |
|
| 2166 | + |
|
| 2167 | + return $drop_down_element; |
|
| 2168 | + |
|
| 2169 | + }// generate_drop_down |
|
| 2170 | + |
|
| 2171 | + /** |
|
| 2172 | + * Wrapper for the default php round() function. |
|
| 2173 | + * This allows us to give more control to a user on how they can round Sensei |
|
| 2174 | + * decimals passed through this function. |
|
| 2175 | + * |
|
| 2176 | + * @since 1.8.5 |
|
| 2177 | + * |
|
| 2178 | + * @param double $val |
|
| 2179 | + * @param int $precision |
|
| 2180 | + * @param $mode |
|
| 2181 | + * @param string $context |
|
| 2182 | + * |
|
| 2183 | + * @return double $val |
|
| 2184 | + */ |
|
| 2185 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2186 | + |
|
| 2187 | + /**å |
|
| 2188 | 2188 | * Change the precision for the Sensei_Utils::round function. |
| 2189 | 2189 | * the precision given will be passed into the php round function |
| 2190 | 2190 | * @since 1.8.5 |
| 2191 | 2191 | */ |
| 2192 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2193 | - |
|
| 2194 | - /** |
|
| 2195 | - * Change the mode for the Sensei_Utils::round function. |
|
| 2196 | - * the mode given will be passed into the php round function |
|
| 2197 | - * |
|
| 2198 | - * This applies only to PHP version 5.3.0 and greater |
|
| 2199 | - * |
|
| 2200 | - * @since 1.8.5 |
|
| 2201 | - */ |
|
| 2202 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2192 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2193 | + |
|
| 2194 | + /** |
|
| 2195 | + * Change the mode for the Sensei_Utils::round function. |
|
| 2196 | + * the mode given will be passed into the php round function |
|
| 2197 | + * |
|
| 2198 | + * This applies only to PHP version 5.3.0 and greater |
|
| 2199 | + * |
|
| 2200 | + * @since 1.8.5 |
|
| 2201 | + */ |
|
| 2202 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2203 | 2203 | |
| 2204 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2204 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2205 | 2205 | |
| 2206 | - return round( $val, $precision, $mode ); |
|
| 2206 | + return round( $val, $precision, $mode ); |
|
| 2207 | 2207 | |
| 2208 | - }else{ |
|
| 2208 | + }else{ |
|
| 2209 | 2209 | |
| 2210 | - return round( $val, $precision ); |
|
| 2210 | + return round( $val, $precision ); |
|
| 2211 | 2211 | |
| 2212 | - } |
|
| 2212 | + } |
|
| 2213 | 2213 | |
| 2214 | - } |
|
| 2214 | + } |
|
| 2215 | 2215 | |
| 2216 | - /** |
|
| 2217 | - * Returns the current url with all the query vars |
|
| 2218 | - * |
|
| 2219 | - * @since 1.9.0 |
|
| 2220 | - * @return string $url |
|
| 2221 | - */ |
|
| 2222 | - public static function get_current_url(){ |
|
| 2216 | + /** |
|
| 2217 | + * Returns the current url with all the query vars |
|
| 2218 | + * |
|
| 2219 | + * @since 1.9.0 |
|
| 2220 | + * @return string $url |
|
| 2221 | + */ |
|
| 2222 | + public static function get_current_url(){ |
|
| 2223 | 2223 | |
| 2224 | - global $wp; |
|
| 2225 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2226 | - if ( isset( $_GET ) ) { |
|
| 2224 | + global $wp; |
|
| 2225 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2226 | + if ( isset( $_GET ) ) { |
|
| 2227 | 2227 | |
| 2228 | - foreach ($_GET as $param => $val ) { |
|
| 2228 | + foreach ($_GET as $param => $val ) { |
|
| 2229 | 2229 | |
| 2230 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2230 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2231 | 2231 | |
| 2232 | - } |
|
| 2233 | - } |
|
| 2232 | + } |
|
| 2233 | + } |
|
| 2234 | 2234 | |
| 2235 | - return $current_url; |
|
| 2236 | - } |
|
| 2235 | + return $current_url; |
|
| 2236 | + } |
|
| 2237 | 2237 | |
| 2238 | - /** |
|
| 2239 | - * Restore the global WP_Query |
|
| 2240 | - * |
|
| 2241 | - * @since 1.9.0 |
|
| 2242 | - */ |
|
| 2243 | - public static function restore_wp_query() { |
|
| 2238 | + /** |
|
| 2239 | + * Restore the global WP_Query |
|
| 2240 | + * |
|
| 2241 | + * @since 1.9.0 |
|
| 2242 | + */ |
|
| 2243 | + public static function restore_wp_query() { |
|
| 2244 | 2244 | |
| 2245 | - wp_reset_query(); |
|
| 2245 | + wp_reset_query(); |
|
| 2246 | 2246 | |
| 2247 | - } |
|
| 2247 | + } |
|
| 2248 | 2248 | |
| 2249 | - /** |
|
| 2250 | - * Merge two arrays in a zip like fashion. |
|
| 2251 | - * If one array is longer than the other the elements will be apended |
|
| 2252 | - * to the end of the resulting array. |
|
| 2253 | - * |
|
| 2254 | - * @since 1.9.0 |
|
| 2255 | - * |
|
| 2256 | - * @param array $array_a |
|
| 2257 | - * @param array $array_b |
|
| 2258 | - * @return array $merged_array |
|
| 2259 | - */ |
|
| 2260 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2249 | + /** |
|
| 2250 | + * Merge two arrays in a zip like fashion. |
|
| 2251 | + * If one array is longer than the other the elements will be apended |
|
| 2252 | + * to the end of the resulting array. |
|
| 2253 | + * |
|
| 2254 | + * @since 1.9.0 |
|
| 2255 | + * |
|
| 2256 | + * @param array $array_a |
|
| 2257 | + * @param array $array_b |
|
| 2258 | + * @return array $merged_array |
|
| 2259 | + */ |
|
| 2260 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2261 | 2261 | |
| 2262 | - if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
| 2263 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2264 | - } |
|
| 2262 | + if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
| 2263 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2264 | + } |
|
| 2265 | 2265 | |
| 2266 | - $merged_array = array(); |
|
| 2267 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2266 | + $merged_array = array(); |
|
| 2267 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2268 | 2268 | |
| 2269 | - // Zip arrays |
|
| 2270 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2269 | + // Zip arrays |
|
| 2270 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2271 | 2271 | |
| 2272 | - // if has an element at current index push a on top |
|
| 2273 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2274 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2275 | - } |
|
| 2272 | + // if has an element at current index push a on top |
|
| 2273 | + if( isset( $array_a[ $i ] ) ){ |
|
| 2274 | + $merged_array[] = $array_a[ $i ] ; |
|
| 2275 | + } |
|
| 2276 | 2276 | |
| 2277 | - // next if $array_b has an element at current index push a on top of the element |
|
| 2278 | - // from a if there was one, if not the element before that. |
|
| 2279 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2280 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2281 | - } |
|
| 2277 | + // next if $array_b has an element at current index push a on top of the element |
|
| 2278 | + // from a if there was one, if not the element before that. |
|
| 2279 | + if( isset( $array_b[ $i ] ) ){ |
|
| 2280 | + $merged_array[] = $array_b[ $i ] ; |
|
| 2281 | + } |
|
| 2282 | 2282 | |
| 2283 | - } |
|
| 2283 | + } |
|
| 2284 | 2284 | |
| 2285 | - return $merged_array; |
|
| 2286 | - } |
|
| 2285 | + return $merged_array; |
|
| 2286 | + } |
|
| 2287 | 2287 | |
| 2288 | 2288 | } // End Class |
| 2289 | 2289 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Utilities Class |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | * @since 1.0.0 |
| 19 | 19 | * @return string The URL to the placeholder thumbnail image. |
| 20 | 20 | */ |
| 21 | - public static function get_placeholder_image () { |
|
| 21 | + public static function get_placeholder_image() { |
|
| 22 | 22 | |
| 23 | - return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) ); |
|
| 23 | + return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png')); |
|
| 24 | 24 | } // End get_placeholder_image() |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @static |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public static function sensei_is_woocommerce_present () { |
|
| 35 | + public static function sensei_is_woocommerce_present() { |
|
| 36 | 36 | |
| 37 | 37 | return Sensei_WC::is_woocommerce_present(); |
| 38 | 38 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @static |
| 48 | 48 | * @return boolean |
| 49 | 49 | */ |
| 50 | - public static function sensei_is_woocommerce_activated () { |
|
| 50 | + public static function sensei_is_woocommerce_activated() { |
|
| 51 | 51 | |
| 52 | 52 | return Sensei_WC::is_woocommerce_active(); |
| 53 | 53 | |
@@ -60,70 +60,70 @@ discard block |
||
| 60 | 60 | * @param array $args (default: array()) |
| 61 | 61 | * @return bool | int |
| 62 | 62 | */ |
| 63 | - public static function sensei_log_activity ( $args = array() ) { |
|
| 63 | + public static function sensei_log_activity($args = array()) { |
|
| 64 | 64 | global $wpdb; |
| 65 | 65 | |
| 66 | 66 | // Args, minimum data required for WP |
| 67 | 67 | $data = array( |
| 68 | - 'comment_post_ID' => intval( $args['post_id'] ), |
|
| 68 | + 'comment_post_ID' => intval($args['post_id']), |
|
| 69 | 69 | 'comment_author' => '', // Not needed |
| 70 | 70 | 'comment_author_email' => '', // Not needed |
| 71 | 71 | 'comment_author_url' => '', // Not needed |
| 72 | - 'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '', |
|
| 73 | - 'comment_type' => esc_attr( $args['type'] ), |
|
| 74 | - 'user_id' => intval( $args['user_id'] ), |
|
| 75 | - 'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer' |
|
| 72 | + 'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '', |
|
| 73 | + 'comment_type' => esc_attr($args['type']), |
|
| 74 | + 'user_id' => intval($args['user_id']), |
|
| 75 | + 'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer' |
|
| 76 | 76 | ); |
| 77 | 77 | // Allow extra data |
| 78 | - if ( !empty($args['username']) ) { |
|
| 79 | - $data['comment_author'] = sanitize_user( $args['username'] ); |
|
| 78 | + if ( ! empty($args['username'])) { |
|
| 79 | + $data['comment_author'] = sanitize_user($args['username']); |
|
| 80 | 80 | } |
| 81 | - if ( !empty($args['user_email']) ) { |
|
| 82 | - $data['comment_author_email'] = sanitize_email( $args['user_email'] ); |
|
| 81 | + if ( ! empty($args['user_email'])) { |
|
| 82 | + $data['comment_author_email'] = sanitize_email($args['user_email']); |
|
| 83 | 83 | } |
| 84 | - if ( !empty($args['user_url']) ) { |
|
| 85 | - $data['comment_author_url'] = esc_url( $args['user_url'] ); |
|
| 84 | + if ( ! empty($args['user_url'])) { |
|
| 85 | + $data['comment_author_url'] = esc_url($args['user_url']); |
|
| 86 | 86 | } |
| 87 | - if ( !empty($args['parent']) ) { |
|
| 87 | + if ( ! empty($args['parent'])) { |
|
| 88 | 88 | $data['comment_parent'] = $args['parent']; |
| 89 | 89 | } |
| 90 | 90 | // Sanity check |
| 91 | - if ( empty($args['user_id']) ) { |
|
| 92 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
| 91 | + if (empty($args['user_id'])) { |
|
| 92 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - do_action( 'sensei_log_activity_before', $args, $data ); |
|
| 96 | + do_action('sensei_log_activity_before', $args, $data); |
|
| 97 | 97 | |
| 98 | 98 | $flush_cache = false; |
| 99 | 99 | |
| 100 | 100 | // Custom Logic |
| 101 | 101 | // Check if comment exists first |
| 102 | - $comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) ); |
|
| 103 | - if ( ! $comment_id ) { |
|
| 102 | + $comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'])); |
|
| 103 | + if ( ! $comment_id) { |
|
| 104 | 104 | // Add the comment |
| 105 | - $comment_id = wp_insert_comment( $data ); |
|
| 105 | + $comment_id = wp_insert_comment($data); |
|
| 106 | 106 | |
| 107 | 107 | $flush_cache = true; |
| 108 | - } elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) { |
|
| 108 | + } elseif (isset($args['action']) && 'update' == $args['action']) { |
|
| 109 | 109 | // Update the comment if an update was requested |
| 110 | 110 | $data['comment_ID'] = $comment_id; |
| 111 | 111 | // By default update the timestamp of the comment |
| 112 | - if ( empty($args['keep_time']) ) { |
|
| 112 | + if (empty($args['keep_time'])) { |
|
| 113 | 113 | $data['comment_date'] = current_time('mysql'); |
| 114 | 114 | } |
| 115 | - wp_update_comment( $data ); |
|
| 115 | + wp_update_comment($data); |
|
| 116 | 116 | $flush_cache = true; |
| 117 | 117 | } // End If Statement |
| 118 | 118 | |
| 119 | 119 | // Manually Flush the Cache |
| 120 | - if ( $flush_cache ) { |
|
| 120 | + if ($flush_cache) { |
|
| 121 | 121 | wp_cache_flush(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - do_action( 'sensei_log_activity_after', $args, $data, $comment_id ); |
|
| 124 | + do_action('sensei_log_activity_after', $args, $data, $comment_id); |
|
| 125 | 125 | |
| 126 | - if ( 0 < $comment_id ) { |
|
| 126 | + if (0 < $comment_id) { |
|
| 127 | 127 | // Return the ID so that it can be used for meta data storage |
| 128 | 128 | return $comment_id; |
| 129 | 129 | } else { |
@@ -140,41 +140,41 @@ discard block |
||
| 140 | 140 | * @param bool $return_comments (default: false) |
| 141 | 141 | * @return mixed | int |
| 142 | 142 | */ |
| 143 | - public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) { |
|
| 143 | + public static function sensei_check_for_activity($args = array(), $return_comments = false) { |
|
| 144 | 144 | |
| 145 | 145 | global $wp_version; |
| 146 | - if ( !$return_comments ) { |
|
| 146 | + if ( ! $return_comments) { |
|
| 147 | 147 | $args['count'] = true; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Are we only retrieving a single entry, or not care about the order... |
| 151 | - if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){ |
|
| 151 | + if (isset($args['count']) || isset($args['post_id'])) { |
|
| 152 | 152 | |
| 153 | 153 | // ...then we don't need to ask the db to order the results, this overrides WP default behaviour |
| 154 | - if ( version_compare( $wp_version, '4.1', '>=' ) ) { |
|
| 154 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 155 | 155 | $args['order'] = false; |
| 156 | 156 | $args['orderby'] = false; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // A user ID of 0 is in valid, so shortcut this |
| 161 | - if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) { |
|
| 162 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
| 161 | + if (isset($args['user_id']) && 0 == intval($args['user_id'])) { |
|
| 162 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | // Check for legacy code |
| 166 | - if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) { |
|
| 167 | - _deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) ); |
|
| 166 | + if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) { |
|
| 167 | + _deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'])); |
|
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | // Are we checking for specific comment_approved statuses? |
| 171 | - if ( isset($args['status']) ) { |
|
| 171 | + if (isset($args['status'])) { |
|
| 172 | 172 | // Temporarily store as a custom status if requesting an array... |
| 173 | - if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
| 173 | + if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
| 174 | 174 | // Encode now, decode later |
| 175 | - $args['status'] = implode( ",", $args['status'] ); |
|
| 175 | + $args['status'] = implode(",", $args['status']); |
|
| 176 | 176 | // ...use a filter to switch the encoding back |
| 177 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
| 177 | + add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | else { |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 ' |
| 185 | - if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
| 186 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
| 185 | + if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
| 186 | + add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | //Get the comments |
@@ -194,14 +194,14 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param int|array $comments |
| 196 | 196 | */ |
| 197 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 197 | + $comments = apply_filters('sensei_check_for_activity', get_comments($args)); |
|
| 198 | 198 | |
| 199 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
| 200 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
| 199 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
| 200 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
| 201 | 201 | // Return comments |
| 202 | - if ( $return_comments ) { |
|
| 202 | + if ($return_comments) { |
|
| 203 | 203 | // Could check for array of 1 and just return the 1 item? |
| 204 | - if ( is_array($comments) && 1 == count($comments) ) { |
|
| 204 | + if (is_array($comments) && 1 == count($comments)) { |
|
| 205 | 205 | $comments = array_shift($comments); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -219,31 +219,31 @@ discard block |
||
| 219 | 219 | * @param array $args (default: array()) |
| 220 | 220 | * @return array |
| 221 | 221 | */ |
| 222 | - public static function sensei_activity_ids ( $args = array() ) { |
|
| 222 | + public static function sensei_activity_ids($args = array()) { |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | - $comments = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
| 225 | + $comments = Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 226 | 226 | // Need to always use an array, even with only 1 item |
| 227 | - if ( !is_array($comments) ) { |
|
| 228 | - $comments = array( $comments ); |
|
| 227 | + if ( ! is_array($comments)) { |
|
| 228 | + $comments = array($comments); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $post_ids = array(); |
| 232 | 232 | // Count comments |
| 233 | - if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) { |
|
| 234 | - foreach ( $comments as $key => $value ) { |
|
| 233 | + if (is_array($comments) && (0 < intval(count($comments)))) { |
|
| 234 | + foreach ($comments as $key => $value) { |
|
| 235 | 235 | // Add matches to id array |
| 236 | - if ( isset( $args['field'] ) && 'comment' == $args['field'] ) { |
|
| 237 | - array_push( $post_ids, $value->comment_ID ); |
|
| 238 | - } elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) { |
|
| 239 | - array_push( $post_ids, $value->user_id ); |
|
| 236 | + if (isset($args['field']) && 'comment' == $args['field']) { |
|
| 237 | + array_push($post_ids, $value->comment_ID); |
|
| 238 | + } elseif (isset($args['field']) && 'user_id' == $args['field']) { |
|
| 239 | + array_push($post_ids, $value->user_id); |
|
| 240 | 240 | } else { |
| 241 | - array_push( $post_ids, $value->comment_post_ID ); |
|
| 241 | + array_push($post_ids, $value->comment_post_ID); |
|
| 242 | 242 | } // End If Statement |
| 243 | 243 | } // End For Loop |
| 244 | 244 | // Reset array indexes |
| 245 | - $post_ids = array_unique( $post_ids ); |
|
| 246 | - $post_ids = array_values( $post_ids ); |
|
| 245 | + $post_ids = array_unique($post_ids); |
|
| 246 | + $post_ids = array_values($post_ids); |
|
| 247 | 247 | } // End If Statement |
| 248 | 248 | |
| 249 | 249 | return $post_ids; |
@@ -257,20 +257,20 @@ discard block |
||
| 257 | 257 | * @param array $args (default: array()) |
| 258 | 258 | * @return boolean |
| 259 | 259 | */ |
| 260 | - public static function sensei_delete_activities ( $args = array() ) { |
|
| 260 | + public static function sensei_delete_activities($args = array()) { |
|
| 261 | 261 | |
| 262 | 262 | $dataset_changes = false; |
| 263 | 263 | |
| 264 | 264 | // If activity exists remove activity from log |
| 265 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true ); |
|
| 266 | - if( $comments ) { |
|
| 265 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true); |
|
| 266 | + if ($comments) { |
|
| 267 | 267 | // Need to always return an array, even with only 1 item |
| 268 | - if ( !is_array( $comments ) ) { |
|
| 269 | - $comments = array( $comments ); |
|
| 268 | + if ( ! is_array($comments)) { |
|
| 269 | + $comments = array($comments); |
|
| 270 | 270 | } |
| 271 | - foreach ( $comments as $key => $value ) { |
|
| 272 | - if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) { |
|
| 273 | - $dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true ); |
|
| 271 | + foreach ($comments as $key => $value) { |
|
| 272 | + if (isset($value->comment_ID) && 0 < $value->comment_ID) { |
|
| 273 | + $dataset_changes = wp_delete_comment(intval($value->comment_ID), true); |
|
| 274 | 274 | } // End If Statement |
| 275 | 275 | } // End For Loop |
| 276 | 276 | // Manually flush the cache |
@@ -286,25 +286,25 @@ discard block |
||
| 286 | 286 | * @param integer $user_id User ID |
| 287 | 287 | * @return boolean |
| 288 | 288 | */ |
| 289 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 289 | + public static function delete_all_user_activity($user_id = 0) { |
|
| 290 | 290 | |
| 291 | 291 | $dataset_changes = false; |
| 292 | 292 | |
| 293 | - if( $user_id ) { |
|
| 293 | + if ($user_id) { |
|
| 294 | 294 | |
| 295 | - $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
|
| 295 | + $activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true); |
|
| 296 | 296 | |
| 297 | - if( $activities ) { |
|
| 297 | + if ($activities) { |
|
| 298 | 298 | |
| 299 | 299 | // Need to always return an array, even with only 1 item |
| 300 | - if ( ! is_array( $activities ) ) { |
|
| 301 | - $activities = array( $activities ); |
|
| 300 | + if ( ! is_array($activities)) { |
|
| 301 | + $activities = array($activities); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - foreach( $activities as $activity ) { |
|
| 305 | - if( '' == $activity->comment_type ) continue; |
|
| 306 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 307 | - $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
| 304 | + foreach ($activities as $activity) { |
|
| 305 | + if ('' == $activity->comment_type) continue; |
|
| 306 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 307 | + $dataset_changes = wp_delete_comment(intval($activity->comment_ID), true); |
|
| 308 | 308 | wp_cache_flush(); |
| 309 | 309 | } |
| 310 | 310 | } |
@@ -321,13 +321,13 @@ discard block |
||
| 321 | 321 | * @param array $args (default: array()) |
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | - public static function sensei_get_activity_value ( $args = array() ) { |
|
| 324 | + public static function sensei_get_activity_value($args = array()) { |
|
| 325 | 325 | |
| 326 | 326 | $activity_value = false; |
| 327 | - if ( !empty($args['field']) ) { |
|
| 328 | - $comment = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
| 327 | + if ( ! empty($args['field'])) { |
|
| 328 | + $comment = Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 329 | 329 | |
| 330 | - if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
| 330 | + if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
| 331 | 331 | $activity_value = $comment->{$args['field']}; |
| 332 | 332 | } // End If Statement |
| 333 | 333 | } |
@@ -345,22 +345,22 @@ discard block |
||
| 345 | 345 | * @param int $product_id |
| 346 | 346 | * @return bool |
| 347 | 347 | */ |
| 348 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 348 | + public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) { |
|
| 349 | 349 | |
| 350 | 350 | $emails = array(); |
| 351 | 351 | |
| 352 | - if ( $user_id ) { |
|
| 353 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 352 | + if ($user_id) { |
|
| 353 | + $user = get_user_by('id', intval($user_id)); |
|
| 354 | 354 | $emails[] = $user->user_email; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if ( is_email( $customer_email ) ) |
|
| 357 | + if (is_email($customer_email)) |
|
| 358 | 358 | $emails[] = $customer_email; |
| 359 | 359 | |
| 360 | - if ( sizeof( $emails ) == 0 ) |
|
| 360 | + if (sizeof($emails) == 0) |
|
| 361 | 361 | return false; |
| 362 | 362 | |
| 363 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 363 | + return Sensei_WC::has_customer_bought_product($user_id, $product_id); |
|
| 364 | 364 | |
| 365 | 365 | } // End sensei_customer_bought_product() |
| 366 | 366 | |
@@ -371,9 +371,9 @@ discard block |
||
| 371 | 371 | * @param string $input_name Name for text area form element |
| 372 | 372 | * @return void |
| 373 | 373 | */ |
| 374 | - public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
|
| 374 | + public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') { |
|
| 375 | 375 | |
| 376 | - if( ! $input_name ) $input_name = $editor_id; |
|
| 376 | + if ( ! $input_name) $input_name = $editor_id; |
|
| 377 | 377 | |
| 378 | 378 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
| 379 | 379 | |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | 'quicktags' => false |
| 392 | 392 | ); |
| 393 | 393 | |
| 394 | - wp_editor( $content, $editor_id, $settings ); |
|
| 394 | + wp_editor($content, $editor_id, $settings); |
|
| 395 | 395 | |
| 396 | 396 | } // End sensei_text_editor() |
| 397 | 397 | |
@@ -401,57 +401,57 @@ discard block |
||
| 401 | 401 | * @param int $user_id |
| 402 | 402 | * @return boolean Whether the answers were saved or not |
| 403 | 403 | */ |
| 404 | - public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
|
| 404 | + public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) { |
|
| 405 | 405 | |
| 406 | - if( intval( $user_id ) == 0 ) { |
|
| 406 | + if (intval($user_id) == 0) { |
|
| 407 | 407 | $user_id = get_current_user_id(); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $answers_saved = false; |
| 411 | 411 | |
| 412 | - if( $submitted && intval( $user_id ) > 0 ) { |
|
| 412 | + if ($submitted && intval($user_id) > 0) { |
|
| 413 | 413 | |
| 414 | - foreach( $submitted as $question_id => $answer ) { |
|
| 414 | + foreach ($submitted as $question_id => $answer) { |
|
| 415 | 415 | |
| 416 | 416 | // Get question type |
| 417 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
| 418 | 418 | |
| 419 | 419 | // Sanitise answer |
| 420 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 421 | - $answer = wp_unslash( $answer ); |
|
| 420 | + if (0 == get_magic_quotes_gpc()) { |
|
| 421 | + $answer = wp_unslash($answer); |
|
| 422 | 422 | } |
| 423 | - switch( $question_type ) { |
|
| 424 | - case 'multi-line': $answer = nl2br( $answer ); break; |
|
| 423 | + switch ($question_type) { |
|
| 424 | + case 'multi-line': $answer = nl2br($answer); break; |
|
| 425 | 425 | case 'single-line': break; |
| 426 | 426 | case 'gap-fill': break; |
| 427 | - default: $answer = maybe_serialize( $answer ); break; |
|
| 427 | + default: $answer = maybe_serialize($answer); break; |
|
| 428 | 428 | } |
| 429 | 429 | $args = array( |
| 430 | 430 | 'post_id' => $question_id, |
| 431 | - 'data' => base64_encode( $answer ), |
|
| 431 | + 'data' => base64_encode($answer), |
|
| 432 | 432 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
| 433 | 433 | 'user_id' => $user_id, |
| 434 | 434 | 'action' => 'update' |
| 435 | 435 | ); |
| 436 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
| 436 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Handle file upload questions |
| 440 | - if( isset( $_FILES ) ) { |
|
| 441 | - foreach( $_FILES as $field => $file ) { |
|
| 442 | - if( strpos( $field, 'file_upload_' ) !== false ) { |
|
| 443 | - $question_id = str_replace( 'file_upload_', '', $field ); |
|
| 444 | - if( $file && $question_id ) { |
|
| 445 | - $attachment_id = self::upload_file( $file ); |
|
| 446 | - if( $attachment_id ) { |
|
| 440 | + if (isset($_FILES)) { |
|
| 441 | + foreach ($_FILES as $field => $file) { |
|
| 442 | + if (strpos($field, 'file_upload_') !== false) { |
|
| 443 | + $question_id = str_replace('file_upload_', '', $field); |
|
| 444 | + if ($file && $question_id) { |
|
| 445 | + $attachment_id = self::upload_file($file); |
|
| 446 | + if ($attachment_id) { |
|
| 447 | 447 | $args = array( |
| 448 | 448 | 'post_id' => $question_id, |
| 449 | - 'data' => base64_encode( $attachment_id ), |
|
| 449 | + 'data' => base64_encode($attachment_id), |
|
| 450 | 450 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
| 451 | 451 | 'user_id' => $user_id, |
| 452 | 452 | 'action' => 'update' |
| 453 | 453 | ); |
| 454 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
| 454 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | } |
@@ -463,9 +463,9 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | } // End sensei_save_quiz_answers() |
| 465 | 465 | |
| 466 | - public static function upload_file( $file = array() ) { |
|
| 466 | + public static function upload_file($file = array()) { |
|
| 467 | 467 | |
| 468 | - require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
|
| 468 | + require_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
| 469 | 469 | |
| 470 | 470 | /** |
| 471 | 471 | * Filter the data array for the Sensei wp_handle_upload function call |
@@ -480,11 +480,11 @@ discard block |
||
| 480 | 480 | * @type string test_form set to false by default |
| 481 | 481 | * } |
| 482 | 482 | */ |
| 483 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 483 | + $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false)); |
|
| 484 | 484 | |
| 485 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 485 | + $file_return = wp_handle_upload($file, $file_upload_args); |
|
| 486 | 486 | |
| 487 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 487 | + if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) { |
|
| 488 | 488 | return false; |
| 489 | 489 | } else { |
| 490 | 490 | |
@@ -492,19 +492,19 @@ discard block |
||
| 492 | 492 | |
| 493 | 493 | $attachment = array( |
| 494 | 494 | 'post_mime_type' => $file_return['type'], |
| 495 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 495 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
| 496 | 496 | 'post_content' => '', |
| 497 | 497 | 'post_status' => 'inherit', |
| 498 | 498 | 'guid' => $file_return['url'] |
| 499 | 499 | ); |
| 500 | 500 | |
| 501 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 501 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
| 502 | 502 | |
| 503 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 504 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 505 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 503 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 504 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
| 505 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
| 506 | 506 | |
| 507 | - if( 0 < intval( $attachment_id ) ) { |
|
| 507 | + if (0 < intval($attachment_id)) { |
|
| 508 | 508 | return $attachment_id; |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -530,9 +530,9 @@ discard block |
||
| 530 | 530 | * |
| 531 | 531 | * @return int $quiz_grade total sum of all question grades |
| 532 | 532 | */ |
| 533 | - public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 533 | + public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
| 534 | 534 | |
| 535 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 535 | + return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type); |
|
| 536 | 536 | |
| 537 | 537 | } // End sensei_grade_quiz_auto() |
| 538 | 538 | |
@@ -544,20 +544,20 @@ discard block |
||
| 544 | 544 | * @param string $quiz_grade_type default 'auto' |
| 545 | 545 | * @return boolean |
| 546 | 546 | */ |
| 547 | - public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
|
| 548 | - if( intval( $user_id ) == 0 ) { |
|
| 547 | + public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') { |
|
| 548 | + if (intval($user_id) == 0) { |
|
| 549 | 549 | $user_id = get_current_user_id(); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $activity_logged = false; |
| 553 | - if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) { |
|
| 554 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 555 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 556 | - $activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade ); |
|
| 553 | + if (intval($quiz_id) > 0 && intval($user_id) > 0) { |
|
| 554 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 555 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 556 | + $activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade); |
|
| 557 | 557 | |
| 558 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 558 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 559 | 559 | |
| 560 | - do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type ); |
|
| 560 | + do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | return $activity_logged; |
@@ -577,9 +577,9 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @return int $question_grade |
| 579 | 579 | */ |
| 580 | - public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 580 | + public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
| 581 | 581 | |
| 582 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 582 | + return WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
| 583 | 583 | |
| 584 | 584 | } // end sensei_grade_question_auto |
| 585 | 585 | |
@@ -590,20 +590,20 @@ discard block |
||
| 590 | 590 | * @param int $user_id |
| 591 | 591 | * @return boolean |
| 592 | 592 | */ |
| 593 | - public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
|
| 594 | - if( intval( $user_id ) == 0 ) { |
|
| 593 | + public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) { |
|
| 594 | + if (intval($user_id) == 0) { |
|
| 595 | 595 | $user_id = get_current_user_id(); |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | $activity_logged = false; |
| 599 | - if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) { |
|
| 599 | + if (intval($question_id) > 0 && intval($user_id) > 0) { |
|
| 600 | 600 | |
| 601 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 602 | - $activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade ); |
|
| 601 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 602 | + $activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade); |
|
| 603 | 603 | |
| 604 | - $answer_notes = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 605 | - if ( !empty($answer_notes) ) { |
|
| 606 | - update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) ); |
|
| 604 | + $answer_notes = get_post_meta($question_id, '_answer_feedback', true); |
|
| 605 | + if ( ! empty($answer_notes)) { |
|
| 606 | + update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes)); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | } |
@@ -611,15 +611,15 @@ discard block |
||
| 611 | 611 | return $activity_logged; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) { |
|
| 615 | - if( intval( $user_id ) == 0 ) { |
|
| 614 | + public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) { |
|
| 615 | + if (intval($user_id) == 0) { |
|
| 616 | 616 | $user_id = get_current_user_id(); |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | $activity_logged = false; |
| 620 | - if( intval( $question_id ) > 0 ) { |
|
| 621 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 622 | - $activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' ); |
|
| 620 | + if (intval($question_id) > 0) { |
|
| 621 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 622 | + $activity_logged = delete_comment_meta($user_answer_id, 'user_grade'); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | return $activity_logged; |
@@ -637,9 +637,9 @@ discard block |
||
| 637 | 637 | * |
| 638 | 638 | * @return mixed boolean or comment_ID |
| 639 | 639 | */ |
| 640 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 640 | + public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) { |
|
| 641 | 641 | |
| 642 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 642 | + return self::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
| 643 | 643 | |
| 644 | 644 | }// end user_start_lesson() |
| 645 | 645 | |
@@ -656,22 +656,22 @@ discard block |
||
| 656 | 656 | * |
| 657 | 657 | * @return mixed boolean or comment_ID |
| 658 | 658 | */ |
| 659 | - public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
|
| 659 | + public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) { |
|
| 660 | 660 | |
| 661 | 661 | |
| 662 | - if( intval( $user_id ) == 0 ) { |
|
| 662 | + if (intval($user_id) == 0) { |
|
| 663 | 663 | $user_id = get_current_user_id(); |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | $activity_logged = false; |
| 667 | 667 | |
| 668 | - if( intval( $lesson_id ) > 0 ) { |
|
| 668 | + if (intval($lesson_id) > 0) { |
|
| 669 | 669 | |
| 670 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 671 | - if( $course_id ) { |
|
| 672 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 673 | - if( ! $is_user_taking_course ) { |
|
| 674 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 670 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 671 | + if ($course_id) { |
|
| 672 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 673 | + if ( ! $is_user_taking_course) { |
|
| 674 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
@@ -679,12 +679,12 @@ discard block |
||
| 679 | 679 | $status = 'in-progress'; |
| 680 | 680 | |
| 681 | 681 | // Note: When this action runs the lesson status may not yet exist |
| 682 | - do_action( 'sensei_user_lesson_start', $user_id, $lesson_id ); |
|
| 682 | + do_action('sensei_user_lesson_start', $user_id, $lesson_id); |
|
| 683 | 683 | |
| 684 | - if( $complete ) { |
|
| 684 | + if ($complete) { |
|
| 685 | 685 | |
| 686 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 687 | - if ( $has_questions ) { |
|
| 686 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 687 | + if ($has_questions) { |
|
| 688 | 688 | $status = 'passed'; // Force a pass |
| 689 | 689 | $metadata['grade'] = 0; |
| 690 | 690 | } |
@@ -694,31 +694,31 @@ discard block |
||
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | // Check if user is already taking the lesson |
| 697 | - $activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id ); |
|
| 698 | - if( ! $activity_logged ) { |
|
| 697 | + $activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id); |
|
| 698 | + if ( ! $activity_logged) { |
|
| 699 | 699 | |
| 700 | 700 | $metadata['start'] = current_time('mysql'); |
| 701 | - $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
|
| 701 | + $activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata); |
|
| 702 | 702 | |
| 703 | 703 | } else { |
| 704 | 704 | |
| 705 | 705 | // if users is already taking the lesson and the status changes to complete update it |
| 706 | 706 | $current_user_activity = get_comment($activity_logged); |
| 707 | - if( $status=='complete' && |
|
| 708 | - $status != $current_user_activity->comment_approved ){ |
|
| 707 | + if ($status == 'complete' && |
|
| 708 | + $status != $current_user_activity->comment_approved) { |
|
| 709 | 709 | |
| 710 | 710 | $comment = array(); |
| 711 | 711 | $comment['comment_ID'] = $activity_logged; |
| 712 | 712 | $comment['comment_approved'] = $status; |
| 713 | - wp_update_comment( $comment ); |
|
| 713 | + wp_update_comment($comment); |
|
| 714 | 714 | |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - if ( $complete ) { |
|
| 719 | + if ($complete) { |
|
| 720 | 720 | // Run this *after* the lesson status has been created/updated |
| 721 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 721 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | } |
@@ -733,23 +733,23 @@ discard block |
||
| 733 | 733 | * @param int $user_id |
| 734 | 734 | * @return boolean |
| 735 | 735 | */ |
| 736 | - public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
|
| 736 | + public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) { |
|
| 737 | 737 | |
| 738 | - if( ! $lesson_id ) return false; |
|
| 738 | + if ( ! $lesson_id) return false; |
|
| 739 | 739 | |
| 740 | - if( intval( $user_id ) == 0 ) { |
|
| 740 | + if (intval($user_id) == 0) { |
|
| 741 | 741 | $user_id = get_current_user_id(); |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // Process quiz |
| 745 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 745 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 746 | 746 | |
| 747 | 747 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
| 748 | - Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id ); |
|
| 748 | + Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id); |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | // Delete quiz saved answers |
| 752 | - Sensei()->quiz->reset_user_lesson_data( $lesson_id, $user_id ); |
|
| 752 | + Sensei()->quiz->reset_user_lesson_data($lesson_id, $user_id); |
|
| 753 | 753 | |
| 754 | 754 | // Delete lesson status |
| 755 | 755 | $args = array( |
@@ -758,10 +758,10 @@ discard block |
||
| 758 | 758 | 'user_id' => $user_id, |
| 759 | 759 | ); |
| 760 | 760 | // This auto deletes the corresponding meta data, such as the quiz grade, and questions asked |
| 761 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
| 761 | + Sensei_Utils::sensei_delete_activities($args); |
|
| 762 | 762 | |
| 763 | - if( ! $from_course ) { |
|
| 764 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 763 | + if ( ! $from_course) { |
|
| 764 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | return true; |
@@ -774,19 +774,19 @@ discard block |
||
| 774 | 774 | * @param int $user_id |
| 775 | 775 | * @return boolean |
| 776 | 776 | */ |
| 777 | - public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
|
| 777 | + public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) { |
|
| 778 | 778 | |
| 779 | 779 | |
| 780 | - if( ! $course_id ) return false; |
|
| 780 | + if ( ! $course_id) return false; |
|
| 781 | 781 | |
| 782 | - if( intval( $user_id ) == 0 ) { |
|
| 782 | + if (intval($user_id) == 0) { |
|
| 783 | 783 | $user_id = get_current_user_id(); |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 786 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 787 | 787 | |
| 788 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 789 | - Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true ); |
|
| 788 | + foreach ($lesson_ids as $lesson_id) { |
|
| 789 | + Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | // Delete course status |
@@ -796,36 +796,36 @@ discard block |
||
| 796 | 796 | 'user_id' => $user_id, |
| 797 | 797 | ); |
| 798 | 798 | |
| 799 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
| 799 | + Sensei_Utils::sensei_delete_activities($args); |
|
| 800 | 800 | |
| 801 | - do_action( 'sensei_user_course_reset', $user_id, $course_id ); |
|
| 801 | + do_action('sensei_user_course_reset', $user_id, $course_id); |
|
| 802 | 802 | |
| 803 | 803 | return true; |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - public static function sensei_get_quiz_questions( $quiz_id = 0 ) { |
|
| 806 | + public static function sensei_get_quiz_questions($quiz_id = 0) { |
|
| 807 | 807 | |
| 808 | 808 | |
| 809 | 809 | $questions = array(); |
| 810 | 810 | |
| 811 | - if( intval( $quiz_id ) > 0 ) { |
|
| 812 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 813 | - $questions = Sensei_Utils::array_sort_reorder( $questions ); |
|
| 811 | + if (intval($quiz_id) > 0) { |
|
| 812 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 813 | + $questions = Sensei_Utils::array_sort_reorder($questions); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | return $questions; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - public static function sensei_get_quiz_total( $quiz_id = 0 ) { |
|
| 819 | + public static function sensei_get_quiz_total($quiz_id = 0) { |
|
| 820 | 820 | |
| 821 | 821 | |
| 822 | 822 | $quiz_total = 0; |
| 823 | 823 | |
| 824 | - if( $quiz_id > 0 ) { |
|
| 825 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 824 | + if ($quiz_id > 0) { |
|
| 825 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 826 | 826 | $question_grade = 0; |
| 827 | - foreach( $questions as $question ) { |
|
| 828 | - $question_grade = Sensei()->question->get_question_grade( $question->ID ); |
|
| 827 | + foreach ($questions as $question) { |
|
| 828 | + $question_grade = Sensei()->question->get_question_grade($question->ID); |
|
| 829 | 829 | $quiz_total += $question_grade; |
| 830 | 830 | } |
| 831 | 831 | } |
@@ -840,20 +840,20 @@ discard block |
||
| 840 | 840 | * @param int $user_id |
| 841 | 841 | * @return string |
| 842 | 842 | */ |
| 843 | - public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) { |
|
| 843 | + public static function sensei_get_user_question_grade($question = 0, $user_id = 0) { |
|
| 844 | 844 | $question_grade = false; |
| 845 | - if( $question ) { |
|
| 846 | - if ( is_object( $question ) ) { |
|
| 845 | + if ($question) { |
|
| 846 | + if (is_object($question)) { |
|
| 847 | 847 | $user_answer_id = $question->comment_ID; |
| 848 | 848 | } |
| 849 | 849 | else { |
| 850 | - if( intval( $user_id ) == 0 ) { |
|
| 850 | + if (intval($user_id) == 0) { |
|
| 851 | 851 | $user_id = get_current_user_id(); |
| 852 | 852 | } |
| 853 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 853 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 854 | 854 | } |
| 855 | - if ( $user_answer_id ) { |
|
| 856 | - $question_grade = get_comment_meta( $user_answer_id, 'user_grade', true ); |
|
| 855 | + if ($user_answer_id) { |
|
| 856 | + $question_grade = get_comment_meta($user_answer_id, 'user_grade', true); |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | |
@@ -868,52 +868,52 @@ discard block |
||
| 868 | 868 | * @param int $user_id |
| 869 | 869 | * @return string |
| 870 | 870 | */ |
| 871 | - public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) { |
|
| 871 | + public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) { |
|
| 872 | 872 | $answer_notes = false; |
| 873 | - if( $question ) { |
|
| 874 | - if ( is_object( $question ) ) { |
|
| 873 | + if ($question) { |
|
| 874 | + if (is_object($question)) { |
|
| 875 | 875 | $user_answer_id = $question->comment_ID; |
| 876 | 876 | } |
| 877 | 877 | else { |
| 878 | - if( intval( $user_id ) == 0 ) { |
|
| 878 | + if (intval($user_id) == 0) { |
|
| 879 | 879 | $user_id = get_current_user_id(); |
| 880 | 880 | } |
| 881 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 881 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 882 | 882 | } |
| 883 | - if ( $user_answer_id ) { |
|
| 884 | - $answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) ); |
|
| 883 | + if ($user_answer_id) { |
|
| 884 | + $answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true)); |
|
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | return $answer_notes; |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) { |
|
| 892 | - if( intval( $user_id ) == 0 ) { |
|
| 891 | + public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) { |
|
| 892 | + if (intval($user_id) == 0) { |
|
| 893 | 893 | $user_id = get_current_user_id(); |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | $delete_answers = false; |
| 897 | - if( intval( $quiz_id ) > 0 ) { |
|
| 898 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 899 | - foreach( $questions as $question ) { |
|
| 900 | - $delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) ); |
|
| 897 | + if (intval($quiz_id) > 0) { |
|
| 898 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 899 | + foreach ($questions as $question) { |
|
| 900 | + $delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer')); |
|
| 901 | 901 | } |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | return $delete_answers; |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | - public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) { |
|
| 908 | - if( intval( $user_id ) == 0 ) { |
|
| 907 | + public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) { |
|
| 908 | + if (intval($user_id) == 0) { |
|
| 909 | 909 | $user_id = get_current_user_id(); |
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | $delete_grade = false; |
| 913 | - if( intval( $quiz_id ) > 0 ) { |
|
| 914 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 915 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 916 | - $delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' ); |
|
| 913 | + if (intval($quiz_id) > 0) { |
|
| 914 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 915 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 916 | + $delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade'); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | return $delete_grade; |
@@ -926,20 +926,20 @@ discard block |
||
| 926 | 926 | * @param string $notes |
| 927 | 927 | * @return boolean |
| 928 | 928 | */ |
| 929 | - public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
|
| 930 | - if( intval( $user_id ) == 0 ) { |
|
| 929 | + public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') { |
|
| 930 | + if (intval($user_id) == 0) { |
|
| 931 | 931 | $user_id = get_current_user_id(); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | $activity_logged = false; |
| 935 | 935 | |
| 936 | - if( intval( $question_id ) > 0 ) { |
|
| 937 | - $notes = base64_encode( $notes ); |
|
| 936 | + if (intval($question_id) > 0) { |
|
| 937 | + $notes = base64_encode($notes); |
|
| 938 | 938 | |
| 939 | 939 | // Don't store empty values, no point |
| 940 | - if ( !empty($notes) ) { |
|
| 941 | - $user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 942 | - $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
|
| 940 | + if ( ! empty($notes)) { |
|
| 941 | + $user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 942 | + $activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes); |
|
| 943 | 943 | } |
| 944 | 944 | else { |
| 945 | 945 | $activity_logged = true; |
@@ -955,16 +955,16 @@ discard block |
||
| 955 | 955 | * @param array $return_array data to be ordered |
| 956 | 956 | * @return array $return_array ordered data |
| 957 | 957 | */ |
| 958 | - public static function array_sort_reorder( $return_array ) { |
|
| 959 | - if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) { |
|
| 958 | + public static function array_sort_reorder($return_array) { |
|
| 959 | + if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) { |
|
| 960 | 960 | $sort_key = ''; |
| 961 | 961 | // if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) { |
| 962 | 962 | // $sort_key = esc_html( $_GET['orderby'] ); |
| 963 | 963 | // } // End If Statement |
| 964 | - if ( '' != $sort_key ) { |
|
| 965 | - Sensei_Utils::sort_array_by_key($return_array,$sort_key); |
|
| 966 | - if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) { |
|
| 967 | - $return_array = array_reverse( $return_array, true ); |
|
| 964 | + if ('' != $sort_key) { |
|
| 965 | + Sensei_Utils::sort_array_by_key($return_array, $sort_key); |
|
| 966 | + if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) { |
|
| 967 | + $return_array = array_reverse($return_array, true); |
|
| 968 | 968 | } // End If Statement |
| 969 | 969 | } // End If Statement |
| 970 | 970 | return $return_array; |
@@ -980,15 +980,15 @@ discard block |
||
| 980 | 980 | * @param $key string column name in array |
| 981 | 981 | * @return void |
| 982 | 982 | */ |
| 983 | - public static function sort_array_by_key( $array, $key ) { |
|
| 983 | + public static function sort_array_by_key($array, $key) { |
|
| 984 | 984 | $sorter = array(); |
| 985 | 985 | $ret = array(); |
| 986 | - reset( $array ); |
|
| 987 | - foreach ( $array as $ii => $va ) { |
|
| 986 | + reset($array); |
|
| 987 | + foreach ($array as $ii => $va) { |
|
| 988 | 988 | $sorter[$ii] = $va[$key]; |
| 989 | 989 | } // End For Loop |
| 990 | - asort( $sorter ); |
|
| 991 | - foreach ( $sorter as $ii => $va ) { |
|
| 990 | + asort($sorter); |
|
| 991 | + foreach ($sorter as $ii => $va) { |
|
| 992 | 992 | $ret[$ii] = $array[$ii]; |
| 993 | 993 | } // End For Loop |
| 994 | 994 | $array = $ret; |
@@ -1000,10 +1000,10 @@ discard block |
||
| 1000 | 1000 | * @param integer $quiz_id |
| 1001 | 1001 | * @return array of quiz questions |
| 1002 | 1002 | */ |
| 1003 | - public static function lesson_quiz_questions( $quiz_id = 0 ) { |
|
| 1003 | + public static function lesson_quiz_questions($quiz_id = 0) { |
|
| 1004 | 1004 | $questions_array = array(); |
| 1005 | - if ( 0 < $quiz_id ) { |
|
| 1006 | - $question_args = array( 'post_type' => 'question', |
|
| 1005 | + if (0 < $quiz_id) { |
|
| 1006 | + $question_args = array('post_type' => 'question', |
|
| 1007 | 1007 | 'posts_per_page' => -1, |
| 1008 | 1008 | 'orderby' => 'ID', |
| 1009 | 1009 | 'order' => 'ASC', |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | 'post_status' => 'any', |
| 1017 | 1017 | 'suppress_filters' => 0 |
| 1018 | 1018 | ); |
| 1019 | - $questions_array = get_posts( $question_args ); |
|
| 1019 | + $questions_array = get_posts($question_args); |
|
| 1020 | 1020 | } // End If Statement |
| 1021 | 1021 | return $questions_array; |
| 1022 | 1022 | } // End lesson_quiz_questions() |
@@ -1026,25 +1026,25 @@ discard block |
||
| 1026 | 1026 | * @param integer $course_id ID of course |
| 1027 | 1027 | * @return integer Pass mark for course |
| 1028 | 1028 | */ |
| 1029 | - public static function sensei_course_pass_grade( $course_id = 0 ) { |
|
| 1029 | + public static function sensei_course_pass_grade($course_id = 0) { |
|
| 1030 | 1030 | |
| 1031 | 1031 | |
| 1032 | 1032 | $course_passmark = 0; |
| 1033 | 1033 | |
| 1034 | - if( $course_id > 0 ) { |
|
| 1035 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1034 | + if ($course_id > 0) { |
|
| 1035 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 1036 | 1036 | $lesson_count = 0; |
| 1037 | 1037 | $total_passmark = 0; |
| 1038 | - foreach( $lessons as $lesson ) { |
|
| 1038 | + foreach ($lessons as $lesson) { |
|
| 1039 | 1039 | |
| 1040 | 1040 | // Get Quiz ID |
| 1041 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 1041 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 1042 | 1042 | |
| 1043 | 1043 | // Check for a pass being required |
| 1044 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 1045 | - if ( $pass_required ) { |
|
| 1044 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 1045 | + if ($pass_required) { |
|
| 1046 | 1046 | // Get quiz passmark |
| 1047 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 1047 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 1048 | 1048 | |
| 1049 | 1049 | // Add up total passmark |
| 1050 | 1050 | $total_passmark += $quiz_passmark; |
@@ -1053,12 +1053,12 @@ discard block |
||
| 1053 | 1053 | } |
| 1054 | 1054 | } |
| 1055 | 1055 | // Might be a case of no required lessons |
| 1056 | - if ( $lesson_count ) { |
|
| 1057 | - $course_passmark = ( $total_passmark / $lesson_count ); |
|
| 1056 | + if ($lesson_count) { |
|
| 1057 | + $course_passmark = ($total_passmark / $lesson_count); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | - return Sensei_Utils::round( $course_passmark ); |
|
| 1061 | + return Sensei_Utils::round($course_passmark); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -1067,31 +1067,31 @@ discard block |
||
| 1067 | 1067 | * @param integer $user_id ID of user |
| 1068 | 1068 | * @return integer User's total grade |
| 1069 | 1069 | */ |
| 1070 | - public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
|
| 1070 | + public static function sensei_course_user_grade($course_id = 0, $user_id = 0) { |
|
| 1071 | 1071 | |
| 1072 | 1072 | |
| 1073 | - if( intval( $user_id ) == 0 ) { |
|
| 1073 | + if (intval($user_id) == 0) { |
|
| 1074 | 1074 | $user_id = get_current_user_id(); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | $total_grade = 0; |
| 1078 | 1078 | |
| 1079 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1080 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1079 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1080 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 1081 | 1081 | $lesson_count = 0; |
| 1082 | 1082 | $total_grade = 0; |
| 1083 | - foreach( $lessons as $lesson ) { |
|
| 1083 | + foreach ($lessons as $lesson) { |
|
| 1084 | 1084 | |
| 1085 | 1085 | // Check for lesson having questions, thus a quiz, thus having a grade |
| 1086 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 1087 | - if ( $has_questions ) { |
|
| 1088 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id ); |
|
| 1086 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
| 1087 | + if ($has_questions) { |
|
| 1088 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id); |
|
| 1089 | 1089 | |
| 1090 | - if( empty( $user_lesson_status ) ){ |
|
| 1090 | + if (empty($user_lesson_status)) { |
|
| 1091 | 1091 | continue; |
| 1092 | 1092 | } |
| 1093 | 1093 | // Get user quiz grade |
| 1094 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1094 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1095 | 1095 | |
| 1096 | 1096 | // Add up total grade |
| 1097 | 1097 | $total_grade += $quiz_grade; |
@@ -1101,13 +1101,13 @@ discard block |
||
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | // Might be a case of no lessons with quizzes |
| 1104 | - if ( $lesson_count ) { |
|
| 1105 | - $total_grade = ( $total_grade / $lesson_count ); |
|
| 1104 | + if ($lesson_count) { |
|
| 1105 | + $total_grade = ($total_grade / $lesson_count); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - return Sensei_Utils::round( $total_grade ); |
|
| 1110 | + return Sensei_Utils::round($total_grade); |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1116,18 +1116,18 @@ discard block |
||
| 1116 | 1116 | * @param integer $user_id ID of user |
| 1117 | 1117 | * @return boolean |
| 1118 | 1118 | */ |
| 1119 | - public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) { |
|
| 1120 | - if( intval( $user_id ) == 0 ) { |
|
| 1119 | + public static function sensei_user_passed_course($course_id = 0, $user_id = 0) { |
|
| 1120 | + if (intval($user_id) == 0) { |
|
| 1121 | 1121 | $user_id = get_current_user_id(); |
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | $pass = false; |
| 1125 | 1125 | |
| 1126 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1127 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); |
|
| 1128 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); |
|
| 1126 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1127 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); |
|
| 1128 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); |
|
| 1129 | 1129 | |
| 1130 | - if( $user_grade >= $passmark ) { |
|
| 1130 | + if ($user_grade >= $passmark) { |
|
| 1131 | 1131 | $pass = true; |
| 1132 | 1132 | } |
| 1133 | 1133 | } |
@@ -1141,37 +1141,37 @@ discard block |
||
| 1141 | 1141 | * @param integer $course_id ID of course |
| 1142 | 1142 | * @param integer $user_id ID of user |
| 1143 | 1143 | */ |
| 1144 | - public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) { |
|
| 1145 | - if( intval( $user_id ) == 0 ) { |
|
| 1144 | + public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) { |
|
| 1145 | + if (intval($user_id) == 0) { |
|
| 1146 | 1146 | $user_id = get_current_user_id(); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | $status = 'not_started'; |
| 1150 | 1150 | $box_class = 'info'; |
| 1151 | - $message = __( 'You have not started this course yet.', 'woothemes-sensei' ); |
|
| 1151 | + $message = __('You have not started this course yet.', 'woothemes-sensei'); |
|
| 1152 | 1152 | |
| 1153 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1153 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1154 | 1154 | |
| 1155 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1155 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1156 | 1156 | |
| 1157 | - if( $started_course ) { |
|
| 1158 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()! |
|
| 1159 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()! |
|
| 1160 | - if( $user_grade >= $passmark ) { |
|
| 1157 | + if ($started_course) { |
|
| 1158 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()! |
|
| 1159 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()! |
|
| 1160 | + if ($user_grade >= $passmark) { |
|
| 1161 | 1161 | $status = 'passed'; |
| 1162 | 1162 | $box_class = 'tick'; |
| 1163 | - $message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade ); |
|
| 1163 | + $message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade); |
|
| 1164 | 1164 | } else { |
| 1165 | 1165 | $status = 'failed'; |
| 1166 | 1166 | $box_class = 'alert'; |
| 1167 | - $message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade ); |
|
| 1167 | + $message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | - $message = apply_filters( 'sensei_user_course_status_' . $status, $message ); |
|
| 1174 | - Sensei()->notices->add_notice( $message, $box_class ); |
|
| 1173 | + $message = apply_filters('sensei_user_course_status_'.$status, $message); |
|
| 1174 | + Sensei()->notices->add_notice($message, $box_class); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | /** |
@@ -1181,94 +1181,94 @@ discard block |
||
| 1181 | 1181 | * @param bool $is_lesson |
| 1182 | 1182 | * @return array Status code and message |
| 1183 | 1183 | */ |
| 1184 | - public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
|
| 1184 | + public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) { |
|
| 1185 | 1185 | global $current_user; |
| 1186 | - if( intval( $user_id ) == 0 ) { |
|
| 1186 | + if (intval($user_id) == 0) { |
|
| 1187 | 1187 | $user_id = $current_user->ID; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | $status = 'not_started'; |
| 1191 | 1191 | $box_class = 'info'; |
| 1192 | - $message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' ); |
|
| 1192 | + $message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei'); |
|
| 1193 | 1193 | $extra = ''; |
| 1194 | 1194 | |
| 1195 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
| 1195 | + if ($lesson_id > 0 && $user_id > 0) { |
|
| 1196 | 1196 | |
| 1197 | 1197 | // Prerequisite lesson |
| 1198 | - $prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1198 | + $prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 1199 | 1199 | |
| 1200 | 1200 | // Course ID |
| 1201 | - $course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) ); |
|
| 1201 | + $course_id = absint(get_post_meta($lesson_id, '_lesson_course', true)); |
|
| 1202 | 1202 | |
| 1203 | 1203 | // Has user started course |
| 1204 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1204 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1205 | 1205 | |
| 1206 | 1206 | // Has user completed lesson |
| 1207 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1208 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 1207 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1208 | + $lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
| 1209 | 1209 | |
| 1210 | 1210 | // Quiz ID |
| 1211 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1211 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1212 | 1212 | |
| 1213 | 1213 | // Quiz grade |
| 1214 | 1214 | $quiz_grade = 0; |
| 1215 | - if ( $user_lesson_status ) { |
|
| 1216 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1215 | + if ($user_lesson_status) { |
|
| 1216 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | // Quiz passmark |
| 1220 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 1220 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 1221 | 1221 | $quiz_passmark_float = (float) $quiz_passmark; |
| 1222 | 1222 | |
| 1223 | 1223 | // Pass required |
| 1224 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 1224 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 1225 | 1225 | |
| 1226 | 1226 | // Quiz questions |
| 1227 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1227 | + $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1228 | 1228 | |
| 1229 | - if ( ! $started_course ) { |
|
| 1229 | + if ( ! $started_course) { |
|
| 1230 | 1230 | |
| 1231 | 1231 | $status = 'not_started_course'; |
| 1232 | 1232 | $box_class = 'info'; |
| 1233 | - $message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' ); |
|
| 1233 | + $message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>'); |
|
| 1234 | 1234 | |
| 1235 | - } elseif ( ! is_user_logged_in() ) { |
|
| 1235 | + } elseif ( ! is_user_logged_in()) { |
|
| 1236 | 1236 | |
| 1237 | 1237 | $status = 'login_required'; |
| 1238 | 1238 | $box_class = 'info'; |
| 1239 | - $message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' ); |
|
| 1239 | + $message = __('You must be logged in to take this quiz', 'woothemes-sensei'); |
|
| 1240 | 1240 | |
| 1241 | 1241 | } |
| 1242 | 1242 | // Lesson/Quiz is marked as complete thus passing any quiz restrictions |
| 1243 | - elseif ( $lesson_complete ) { |
|
| 1243 | + elseif ($lesson_complete) { |
|
| 1244 | 1244 | |
| 1245 | 1245 | $status = 'passed'; |
| 1246 | 1246 | $box_class = 'tick'; |
| 1247 | 1247 | // Lesson status will be "complete" (has no Quiz) |
| 1248 | - if ( ! $has_quiz_questions ) { |
|
| 1249 | - $message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) ); |
|
| 1248 | + if ( ! $has_quiz_questions) { |
|
| 1249 | + $message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei')); |
|
| 1250 | 1250 | } |
| 1251 | 1251 | // Lesson status will be "graded" (no passmark required so might have failed all the questions) |
| 1252 | - elseif ( empty( $quiz_grade ) ) { |
|
| 1253 | - $message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) ); |
|
| 1252 | + elseif (empty($quiz_grade)) { |
|
| 1253 | + $message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei')); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | // Lesson status will be "passed" (passmark reached) |
| 1256 | - elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) { |
|
| 1257 | - if( $is_lesson ) { |
|
| 1258 | - $message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1256 | + elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) { |
|
| 1257 | + if ($is_lesson) { |
|
| 1258 | + $message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
| 1259 | 1259 | } else { |
| 1260 | - $message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1260 | + $message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | // add next lesson button |
| 1265 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1266 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1265 | + $nav_id_array = sensei_get_prev_next_lessons($lesson_id); |
|
| 1266 | + $next_lesson_id = absint($nav_id_array['next_lesson']); |
|
| 1267 | 1267 | |
| 1268 | 1268 | // Output HTML |
| 1269 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1270 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1271 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1269 | + if ((0 < $next_lesson_id)) { |
|
| 1270 | + $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id)) |
|
| 1271 | + . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei') |
|
| 1272 | 1272 | .'</a>'; |
| 1273 | 1273 | |
| 1274 | 1274 | } |
@@ -1277,51 +1277,51 @@ discard block |
||
| 1277 | 1277 | // Lesson/Quiz not complete |
| 1278 | 1278 | else { |
| 1279 | 1279 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1280 | - if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
|
| 1280 | + if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) { |
|
| 1281 | 1281 | $status = 'complete'; |
| 1282 | 1282 | $box_class = 'info'; |
| 1283 | - if( $is_lesson ) { |
|
| 1284 | - $message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' ); |
|
| 1283 | + if ($is_lesson) { |
|
| 1284 | + $message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>'); |
|
| 1285 | 1285 | } else { |
| 1286 | - $message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1286 | + $message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | } |
| 1289 | 1289 | // Lesson status must be "failed" |
| 1290 | - elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) { |
|
| 1290 | + elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) { |
|
| 1291 | 1291 | $status = 'failed'; |
| 1292 | 1292 | $box_class = 'alert'; |
| 1293 | - if( $is_lesson ) { |
|
| 1294 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1293 | + if ($is_lesson) { |
|
| 1294 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
| 1295 | 1295 | } else { |
| 1296 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1296 | + $message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | } |
| 1299 | 1299 | // Lesson/Quiz requires a pass |
| 1300 | - elseif( $pass_required ) { |
|
| 1300 | + elseif ($pass_required) { |
|
| 1301 | 1301 | $status = 'not_started'; |
| 1302 | 1302 | $box_class = 'info'; |
| 1303 | - if( $is_lesson ) { |
|
| 1304 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1303 | + if ($is_lesson) { |
|
| 1304 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
| 1305 | 1305 | } else { |
| 1306 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1306 | + $message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
| 1307 | 1307 | } |
| 1308 | 1308 | } |
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | - }else{ |
|
| 1311 | + } else { |
|
| 1312 | 1312 | |
| 1313 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1314 | - $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' ) . '">'; |
|
| 1315 | - $a_element .= __( 'course', 'woothemes-sensei' ); |
|
| 1313 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1314 | + $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">'; |
|
| 1315 | + $a_element .= __('course', 'woothemes-sensei'); |
|
| 1316 | 1316 | $a_element .= '</a>'; |
| 1317 | 1317 | |
| 1318 | - if ( Sensei_WC::is_course_purchasable( $course_id ) ){ |
|
| 1318 | + if (Sensei_WC::is_course_purchasable($course_id)) { |
|
| 1319 | 1319 | |
| 1320 | - $message = sprintf( __( 'Please purchase the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element ); |
|
| 1320 | + $message = sprintf(__('Please purchase the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element); |
|
| 1321 | 1321 | |
| 1322 | 1322 | } else { |
| 1323 | 1323 | |
| 1324 | - $message = sprintf( __( 'Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element ); |
|
| 1324 | + $message = sprintf(__('Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element); |
|
| 1325 | 1325 | |
| 1326 | 1326 | } |
| 1327 | 1327 | |
@@ -1329,15 +1329,15 @@ discard block |
||
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | // Legacy filter |
| 1332 | - $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
|
| 1332 | + $message = apply_filters('sensei_user_quiz_status_'.$status, $message); |
|
| 1333 | 1333 | |
| 1334 | - if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
|
| 1335 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1336 | - $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>'; |
|
| 1334 | + if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) { |
|
| 1335 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1336 | + $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>'; |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | // Filter of all messages |
| 1340 | - return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson ); |
|
| 1340 | + return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson); |
|
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | /** |
@@ -1347,14 +1347,14 @@ discard block |
||
| 1347 | 1347 | * @param integer $course_id Course ID |
| 1348 | 1348 | * @return mixed boolean or comment_ID |
| 1349 | 1349 | */ |
| 1350 | - public static function user_start_course( $user_id = 0, $course_id = 0 ) { |
|
| 1350 | + public static function user_start_course($user_id = 0, $course_id = 0) { |
|
| 1351 | 1351 | |
| 1352 | 1352 | $activity_logged = false; |
| 1353 | 1353 | |
| 1354 | - if( $user_id && $course_id ) { |
|
| 1354 | + if ($user_id && $course_id) { |
|
| 1355 | 1355 | // Check if user is already on the Course |
| 1356 | - $activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1357 | - if ( ! $activity_logged ) { |
|
| 1356 | + $activity_logged = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1357 | + if ( ! $activity_logged) { |
|
| 1358 | 1358 | |
| 1359 | 1359 | // Add user to course |
| 1360 | 1360 | $course_metadata = array( |
@@ -1363,11 +1363,11 @@ discard block |
||
| 1363 | 1363 | 'complete' => 0, |
| 1364 | 1364 | ); |
| 1365 | 1365 | |
| 1366 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata ); |
|
| 1366 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata); |
|
| 1367 | 1367 | |
| 1368 | 1368 | // Allow further actions |
| 1369 | - if ( $activity_logged ) { |
|
| 1370 | - do_action( 'sensei_user_course_start', $user_id, $course_id ); |
|
| 1369 | + if ($activity_logged) { |
|
| 1370 | + do_action('sensei_user_course_start', $user_id, $course_id); |
|
| 1371 | 1371 | } |
| 1372 | 1372 | } |
| 1373 | 1373 | } |
@@ -1383,19 +1383,19 @@ discard block |
||
| 1383 | 1383 | * @param int $user_id |
| 1384 | 1384 | * @return mixed false or comment_ID |
| 1385 | 1385 | */ |
| 1386 | - public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
|
| 1386 | + public static function user_started_course($course_id = 0, $user_id = 0) { |
|
| 1387 | 1387 | |
| 1388 | 1388 | $user_started_course = false; |
| 1389 | 1389 | |
| 1390 | - if( $course_id ) { |
|
| 1390 | + if ($course_id) { |
|
| 1391 | 1391 | |
| 1392 | - if( ! $user_id ) { |
|
| 1392 | + if ( ! $user_id) { |
|
| 1393 | 1393 | $user_id = get_current_user_id(); |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | - if ( ! $user_id > 0 ) { |
|
| 1396 | + if ( ! $user_id > 0) { |
|
| 1397 | 1397 | |
| 1398 | - $user_started_course = false; |
|
| 1398 | + $user_started_course = false; |
|
| 1399 | 1399 | |
| 1400 | 1400 | } else { |
| 1401 | 1401 | |
@@ -1406,9 +1406,9 @@ discard block |
||
| 1406 | 1406 | 'field' => 'comment_ID' |
| 1407 | 1407 | ); |
| 1408 | 1408 | |
| 1409 | - $user_course_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
|
| 1409 | + $user_course_status_id = Sensei_Utils::sensei_get_activity_value($activity_args); |
|
| 1410 | 1410 | |
| 1411 | - if ( $user_course_status_id ) { |
|
| 1411 | + if ($user_course_status_id) { |
|
| 1412 | 1412 | |
| 1413 | 1413 | $user_started_course = $user_course_status_id; |
| 1414 | 1414 | |
@@ -1424,7 +1424,7 @@ discard block |
||
| 1424 | 1424 | * @param bool $user_started_course |
| 1425 | 1425 | * @param integer $course_id |
| 1426 | 1426 | */ |
| 1427 | - return apply_filters( 'sensei_user_started_course', $user_started_course, $course_id, $user_id ); |
|
| 1427 | + return apply_filters('sensei_user_started_course', $user_started_course, $course_id, $user_id); |
|
| 1428 | 1428 | |
| 1429 | 1429 | } |
| 1430 | 1430 | |
@@ -1436,17 +1436,17 @@ discard block |
||
| 1436 | 1436 | * @param integer $user_id User ID |
| 1437 | 1437 | * @return int |
| 1438 | 1438 | */ |
| 1439 | - public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
|
| 1439 | + public static function user_complete_course($course_id = 0, $user_id = 0) { |
|
| 1440 | 1440 | global $wp_version; |
| 1441 | 1441 | |
| 1442 | - if( $course_id ) { |
|
| 1443 | - if( ! $user_id ) { |
|
| 1442 | + if ($course_id) { |
|
| 1443 | + if ( ! $user_id) { |
|
| 1444 | 1444 | $user_id = get_current_user_id(); |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | 1447 | $course_status = 'in-progress'; |
| 1448 | 1448 | $course_metadata = array(); |
| 1449 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
| 1449 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
| 1450 | 1450 | $lessons_completed = $total_lessons = 0; |
| 1451 | 1451 | $lesson_status_args = array( |
| 1452 | 1452 | 'user_id' => $user_id, |
@@ -1455,8 +1455,8 @@ discard block |
||
| 1455 | 1455 | ); |
| 1456 | 1456 | |
| 1457 | 1457 | // Grab all of this Courses' lessons, looping through each... |
| 1458 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 1459 | - $total_lessons = count( $lesson_ids ); |
|
| 1458 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 1459 | + $total_lessons = count($lesson_ids); |
|
| 1460 | 1460 | // ...if course completion not set to 'passed', and all lessons are complete or graded, |
| 1461 | 1461 | // ......then all lessons are 'passed' |
| 1462 | 1462 | // ...else if course completion is set to 'passed', check if each lesson has questions... |
@@ -1469,29 +1469,29 @@ discard block |
||
| 1469 | 1469 | // The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson() |
| 1470 | 1470 | $all_lesson_statuses = array(); |
| 1471 | 1471 | // In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs |
| 1472 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1472 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1473 | 1473 | $lesson_status_args['post__in'] = $lesson_ids; |
| 1474 | - $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
| 1474 | + $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
| 1475 | 1475 | // Need to always return an array, even with only 1 item |
| 1476 | - if ( !is_array($all_lesson_statuses) ) { |
|
| 1477 | - $all_lesson_statuses = array( $all_lesson_statuses ); |
|
| 1476 | + if ( ! is_array($all_lesson_statuses)) { |
|
| 1477 | + $all_lesson_statuses = array($all_lesson_statuses); |
|
| 1478 | 1478 | } |
| 1479 | 1479 | } |
| 1480 | 1480 | // ...otherwise check each one |
| 1481 | 1481 | else { |
| 1482 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 1482 | + foreach ($lesson_ids as $lesson_id) { |
|
| 1483 | 1483 | $lesson_status_args['post_id'] = $lesson_id; |
| 1484 | - $each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
| 1484 | + $each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
| 1485 | 1485 | // Check for valid return before using |
| 1486 | - if ( !empty($each_lesson_status->comment_approved) ) { |
|
| 1486 | + if ( ! empty($each_lesson_status->comment_approved)) { |
|
| 1487 | 1487 | $all_lesson_statuses[] = $each_lesson_status; |
| 1488 | 1488 | } |
| 1489 | 1489 | } |
| 1490 | 1490 | } |
| 1491 | - foreach( $all_lesson_statuses as $lesson_status ) { |
|
| 1491 | + foreach ($all_lesson_statuses as $lesson_status) { |
|
| 1492 | 1492 | // If lessons are complete without needing quizzes to be passed |
| 1493 | - if ( 'passed' != $course_completion ) { |
|
| 1494 | - switch ( $lesson_status->comment_approved ) { |
|
| 1493 | + if ('passed' != $course_completion) { |
|
| 1494 | + switch ($lesson_status->comment_approved) { |
|
| 1495 | 1495 | // A user cannot 'complete' a course if a lesson... |
| 1496 | 1496 | case 'in-progress': // ...is still in progress |
| 1497 | 1497 | case 'ungraded': // ...hasn't yet been graded |
@@ -1503,7 +1503,7 @@ discard block |
||
| 1503 | 1503 | } |
| 1504 | 1504 | } |
| 1505 | 1505 | else { |
| 1506 | - switch ( $lesson_status->comment_approved ) { |
|
| 1506 | + switch ($lesson_status->comment_approved) { |
|
| 1507 | 1507 | case 'complete': // Lesson has no quiz/questions |
| 1508 | 1508 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1509 | 1509 | case 'passed': // Lesson has quiz and the user passed |
@@ -1517,20 +1517,20 @@ discard block |
||
| 1517 | 1517 | } |
| 1518 | 1518 | } |
| 1519 | 1519 | } // Each lesson |
| 1520 | - if ( $lessons_completed == $total_lessons ) { |
|
| 1520 | + if ($lessons_completed == $total_lessons) { |
|
| 1521 | 1521 | $course_status = 'complete'; |
| 1522 | 1522 | } |
| 1523 | 1523 | |
| 1524 | 1524 | // Update meta data on how many lessons have been completed |
| 1525 | 1525 | $course_metadata['complete'] = $lessons_completed; |
| 1526 | 1526 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
| 1527 | - $course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
| 1527 | + $course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
| 1528 | 1528 | |
| 1529 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata ); |
|
| 1529 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata); |
|
| 1530 | 1530 | |
| 1531 | 1531 | // Allow further actions |
| 1532 | - if ( 'complete' == $course_status ) { |
|
| 1533 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
| 1532 | + if ('complete' == $course_status) { |
|
| 1533 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | return $activity_logged; |
| 1536 | 1536 | } |
@@ -1546,40 +1546,40 @@ discard block |
||
| 1546 | 1546 | * @param int $user_id |
| 1547 | 1547 | * @return boolean |
| 1548 | 1548 | */ |
| 1549 | - public static function user_completed_course( $course , $user_id = 0 ) { |
|
| 1549 | + public static function user_completed_course($course, $user_id = 0) { |
|
| 1550 | 1550 | |
| 1551 | - if( $course ) { |
|
| 1552 | - if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
|
| 1551 | + if ($course) { |
|
| 1552 | + if (is_object($course) && is_a($course, 'WP_Comment')) { |
|
| 1553 | 1553 | $user_course_status = $course->comment_approved; |
| 1554 | 1554 | } |
| 1555 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
| 1555 | + elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) { |
|
| 1556 | 1556 | $user_course_status = $course; |
| 1557 | 1557 | } |
| 1558 | 1558 | else { |
| 1559 | 1559 | |
| 1560 | 1560 | // check the user_id |
| 1561 | - if( ! $user_id ) { |
|
| 1561 | + if ( ! $user_id) { |
|
| 1562 | 1562 | |
| 1563 | 1563 | $user_id = get_current_user_id(); |
| 1564 | 1564 | |
| 1565 | - if( empty( $user_id ) ){ |
|
| 1565 | + if (empty($user_id)) { |
|
| 1566 | 1566 | |
| 1567 | 1567 | return false; |
| 1568 | 1568 | |
| 1569 | 1569 | } |
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1573 | - $course = $course->ID; |
|
| 1572 | + if (is_a($course, 'WP_Post')) { |
|
| 1573 | + $course = $course->ID; |
|
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | - $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
|
| 1577 | - if( isset( $user_course_status->comment_approved ) ){ |
|
| 1576 | + $user_course_status = Sensei_Utils::user_course_status($course, $user_id); |
|
| 1577 | + if (isset($user_course_status->comment_approved)) { |
|
| 1578 | 1578 | $user_course_status = $user_course_status->comment_approved; |
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | } |
| 1582 | - if( $user_course_status && 'complete' == $user_course_status ) { |
|
| 1582 | + if ($user_course_status && 'complete' == $user_course_status) { |
|
| 1583 | 1583 | return true; |
| 1584 | 1584 | } |
| 1585 | 1585 | } |
@@ -1594,10 +1594,10 @@ discard block |
||
| 1594 | 1594 | * @param int $user_id |
| 1595 | 1595 | * @return mixed false or comment_ID |
| 1596 | 1596 | */ |
| 1597 | - public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
|
| 1597 | + public static function user_started_lesson($lesson_id = 0, $user_id = 0) { |
|
| 1598 | 1598 | |
| 1599 | - if( $lesson_id ) { |
|
| 1600 | - if( ! $user_id ) { |
|
| 1599 | + if ($lesson_id) { |
|
| 1600 | + if ( ! $user_id) { |
|
| 1601 | 1601 | $user_id = get_current_user_id(); |
| 1602 | 1602 | } |
| 1603 | 1603 | |
@@ -1607,8 +1607,8 @@ discard block |
||
| 1607 | 1607 | 'type' => 'sensei_lesson_status', |
| 1608 | 1608 | 'field' => 'comment_ID' ); |
| 1609 | 1609 | |
| 1610 | - $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
|
| 1611 | - if( $user_lesson_status_id ) { |
|
| 1610 | + $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args); |
|
| 1611 | + if ($user_lesson_status_id) { |
|
| 1612 | 1612 | return $user_lesson_status_id; |
| 1613 | 1613 | } |
| 1614 | 1614 | } |
@@ -1623,29 +1623,29 @@ discard block |
||
| 1623 | 1623 | * @param int $user_id |
| 1624 | 1624 | * @return boolean |
| 1625 | 1625 | */ |
| 1626 | - public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) { |
|
| 1626 | + public static function user_completed_lesson($lesson = 0, $user_id = 0) { |
|
| 1627 | 1627 | |
| 1628 | - if( $lesson ) { |
|
| 1628 | + if ($lesson) { |
|
| 1629 | 1629 | $lesson_id = 0; |
| 1630 | - if ( is_object( $lesson ) ) { |
|
| 1630 | + if (is_object($lesson)) { |
|
| 1631 | 1631 | $user_lesson_status = $lesson->comment_approved; |
| 1632 | 1632 | $lesson_id = $lesson->comment_post_ID; |
| 1633 | 1633 | } |
| 1634 | - elseif ( ! is_numeric( $lesson ) ) { |
|
| 1634 | + elseif ( ! is_numeric($lesson)) { |
|
| 1635 | 1635 | $user_lesson_status = $lesson; |
| 1636 | 1636 | } |
| 1637 | 1637 | else { |
| 1638 | - if( ! $user_id ) { |
|
| 1638 | + if ( ! $user_id) { |
|
| 1639 | 1639 | $user_id = get_current_user_id(); |
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | // the user is not logged in |
| 1643 | - if( ! $user_id > 0 ){ |
|
| 1643 | + if ( ! $user_id > 0) { |
|
| 1644 | 1644 | return false; |
| 1645 | 1645 | } |
| 1646 | - $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
|
| 1646 | + $_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id); |
|
| 1647 | 1647 | |
| 1648 | - if ( $_user_lesson_status ) { |
|
| 1648 | + if ($_user_lesson_status) { |
|
| 1649 | 1649 | $user_lesson_status = $_user_lesson_status->comment_approved; |
| 1650 | 1650 | } |
| 1651 | 1651 | else { |
@@ -1653,12 +1653,12 @@ discard block |
||
| 1653 | 1653 | } |
| 1654 | 1654 | $lesson_id = $lesson; |
| 1655 | 1655 | } |
| 1656 | - if ( 'in-progress' != $user_lesson_status ) { |
|
| 1656 | + if ('in-progress' != $user_lesson_status) { |
|
| 1657 | 1657 | // Check for Passed or Completed Setting |
| 1658 | 1658 | // Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting |
| 1659 | 1659 | // $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
| 1660 | 1660 | // if ( 'passed' == $course_completion ) { |
| 1661 | - switch( $user_lesson_status ) { |
|
| 1661 | + switch ($user_lesson_status) { |
|
| 1662 | 1662 | case 'complete': |
| 1663 | 1663 | case 'graded': |
| 1664 | 1664 | case 'passed': |
@@ -1667,13 +1667,13 @@ discard block |
||
| 1667 | 1667 | |
| 1668 | 1668 | case 'failed': |
| 1669 | 1669 | // This may be 'completed' depending on... |
| 1670 | - if ( $lesson_id ) { |
|
| 1670 | + if ($lesson_id) { |
|
| 1671 | 1671 | // Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson |
| 1672 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1673 | - if ( $lesson_quiz_id ) { |
|
| 1672 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1673 | + if ($lesson_quiz_id) { |
|
| 1674 | 1674 | // ...the quiz pass setting |
| 1675 | - $pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true ); |
|
| 1676 | - if ( empty($pass_required) ) { |
|
| 1675 | + $pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true); |
|
| 1676 | + if (empty($pass_required)) { |
|
| 1677 | 1677 | // We just require the user to have done the quiz, not to have passed |
| 1678 | 1678 | return true; |
| 1679 | 1679 | } |
@@ -1696,15 +1696,15 @@ discard block |
||
| 1696 | 1696 | * @param int $user_id |
| 1697 | 1697 | * @return object |
| 1698 | 1698 | */ |
| 1699 | - public static function user_course_status( $course_id = 0, $user_id = 0 ) { |
|
| 1699 | + public static function user_course_status($course_id = 0, $user_id = 0) { |
|
| 1700 | 1700 | |
| 1701 | 1701 | |
| 1702 | - if( $course_id ) { |
|
| 1703 | - if( ! $user_id ) { |
|
| 1702 | + if ($course_id) { |
|
| 1703 | + if ( ! $user_id) { |
|
| 1704 | 1704 | $user_id = get_current_user_id(); |
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | - $user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true ); |
|
| 1707 | + $user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true); |
|
| 1708 | 1708 | return $user_course_status; |
| 1709 | 1709 | } |
| 1710 | 1710 | |
@@ -1719,27 +1719,27 @@ discard block |
||
| 1719 | 1719 | * @param int $user_id |
| 1720 | 1720 | * @return object | bool |
| 1721 | 1721 | */ |
| 1722 | - public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
|
| 1722 | + public static function user_lesson_status($lesson_id = 0, $user_id = 0) { |
|
| 1723 | 1723 | |
| 1724 | - if( ! $user_id ) { |
|
| 1724 | + if ( ! $user_id) { |
|
| 1725 | 1725 | $user_id = get_current_user_id(); |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
| 1728 | + if ($lesson_id > 0 && $user_id > 0) { |
|
| 1729 | 1729 | |
| 1730 | - $user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true ); |
|
| 1730 | + $user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true); |
|
| 1731 | 1731 | return $user_lesson_status; |
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | 1734 | return false; |
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | - public static function is_preview_lesson( $lesson_id ) { |
|
| 1737 | + public static function is_preview_lesson($lesson_id) { |
|
| 1738 | 1738 | $is_preview = false; |
| 1739 | 1739 | |
| 1740 | - if( 'lesson' == get_post_type( $lesson_id ) ) { |
|
| 1741 | - $lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true ); |
|
| 1742 | - if ( isset( $lesson_preview ) && '' != $lesson_preview ) { |
|
| 1740 | + if ('lesson' == get_post_type($lesson_id)) { |
|
| 1741 | + $lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true); |
|
| 1742 | + if (isset($lesson_preview) && '' != $lesson_preview) { |
|
| 1743 | 1743 | $is_preview = true; |
| 1744 | 1744 | } |
| 1745 | 1745 | } |
@@ -1747,22 +1747,22 @@ discard block |
||
| 1747 | 1747 | return $is_preview; |
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | - public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
|
| 1750 | + public static function user_passed_quiz($quiz_id = 0, $user_id = 0) { |
|
| 1751 | 1751 | |
| 1752 | - if( ! $quiz_id ) return false; |
|
| 1752 | + if ( ! $quiz_id) return false; |
|
| 1753 | 1753 | |
| 1754 | - if( ! $user_id ) { |
|
| 1754 | + if ( ! $user_id) { |
|
| 1755 | 1755 | $user_id = get_current_user_id(); |
| 1756 | 1756 | } |
| 1757 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 1757 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 1758 | 1758 | |
| 1759 | 1759 | // Quiz Grade |
| 1760 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1761 | - $quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 1760 | + $lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1761 | + $quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
| 1762 | 1762 | |
| 1763 | 1763 | // Check if Grade is greater than or equal to pass percentage |
| 1764 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 1765 | - if ( $quiz_passmark <= intval( $quiz_grade ) ) { |
|
| 1764 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 1765 | + if ($quiz_passmark <= intval($quiz_grade)) { |
|
| 1766 | 1766 | return true; |
| 1767 | 1767 | } |
| 1768 | 1768 | |
@@ -1782,9 +1782,9 @@ discard block |
||
| 1782 | 1782 | * |
| 1783 | 1783 | * @return mixed false or comment_ID |
| 1784 | 1784 | */ |
| 1785 | - public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
|
| 1785 | + public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) { |
|
| 1786 | 1786 | $comment_id = false; |
| 1787 | - if ( !empty($status) ) { |
|
| 1787 | + if ( ! empty($status)) { |
|
| 1788 | 1788 | $args = array( |
| 1789 | 1789 | 'user_id' => $user_id, |
| 1790 | 1790 | 'post_id' => $lesson_id, |
@@ -1793,18 +1793,18 @@ discard block |
||
| 1793 | 1793 | 'action' => 'update', // Update the existing status... |
| 1794 | 1794 | 'keep_time' => true, // ...but don't change the existing timestamp |
| 1795 | 1795 | ); |
| 1796 | - if( 'in-progress' == $status ) { |
|
| 1797 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
| 1796 | + if ('in-progress' == $status) { |
|
| 1797 | + unset($args['keep_time']); // Keep updating what's happened |
|
| 1798 | 1798 | } |
| 1799 | 1799 | |
| 1800 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
| 1801 | - if ( $comment_id && !empty($metadata) ) { |
|
| 1802 | - foreach( $metadata as $key => $value ) { |
|
| 1803 | - update_comment_meta( $comment_id, $key, $value ); |
|
| 1800 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
| 1801 | + if ($comment_id && ! empty($metadata)) { |
|
| 1802 | + foreach ($metadata as $key => $value) { |
|
| 1803 | + update_comment_meta($comment_id, $key, $value); |
|
| 1804 | 1804 | } |
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | - do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id ); |
|
| 1807 | + do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id); |
|
| 1808 | 1808 | } |
| 1809 | 1809 | return $comment_id; |
| 1810 | 1810 | } |
@@ -1820,9 +1820,9 @@ discard block |
||
| 1820 | 1820 | * @param array $metadata |
| 1821 | 1821 | * @return mixed false or comment_ID |
| 1822 | 1822 | */ |
| 1823 | - public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
|
| 1823 | + public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) { |
|
| 1824 | 1824 | $comment_id = false; |
| 1825 | - if ( !empty($status) ) { |
|
| 1825 | + if ( ! empty($status)) { |
|
| 1826 | 1826 | $args = array( |
| 1827 | 1827 | 'user_id' => $user_id, |
| 1828 | 1828 | 'post_id' => $course_id, |
@@ -1831,17 +1831,17 @@ discard block |
||
| 1831 | 1831 | 'action' => 'update', // Update the existing status... |
| 1832 | 1832 | 'keep_time' => true, // ...but don't change the existing timestamp |
| 1833 | 1833 | ); |
| 1834 | - if( 'in-progress' == $status ) { |
|
| 1835 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
| 1834 | + if ('in-progress' == $status) { |
|
| 1835 | + unset($args['keep_time']); // Keep updating what's happened |
|
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
| 1839 | - if ( $comment_id && !empty($metadata) ) { |
|
| 1840 | - foreach( $metadata as $key => $value ) { |
|
| 1841 | - update_comment_meta( $comment_id, $key, $value ); |
|
| 1838 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
| 1839 | + if ($comment_id && ! empty($metadata)) { |
|
| 1840 | + foreach ($metadata as $key => $value) { |
|
| 1841 | + update_comment_meta($comment_id, $key, $value); |
|
| 1842 | 1842 | } |
| 1843 | 1843 | } |
| 1844 | - do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id ); |
|
| 1844 | + do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id); |
|
| 1845 | 1845 | } |
| 1846 | 1846 | return $comment_id; |
| 1847 | 1847 | } |
@@ -1853,9 +1853,9 @@ discard block |
||
| 1853 | 1853 | * @param array $pieces (default: array()) |
| 1854 | 1854 | * @return array |
| 1855 | 1855 | */ |
| 1856 | - public static function single_comment_filter( $pieces ) { |
|
| 1857 | - unset( $pieces['orderby'] ); |
|
| 1858 | - unset( $pieces['order'] ); |
|
| 1856 | + public static function single_comment_filter($pieces) { |
|
| 1857 | + unset($pieces['orderby']); |
|
| 1858 | + unset($pieces['order']); |
|
| 1859 | 1859 | |
| 1860 | 1860 | return $pieces; |
| 1861 | 1861 | } |
@@ -1867,9 +1867,9 @@ discard block |
||
| 1867 | 1867 | * @param array $pieces (default: array()) |
| 1868 | 1868 | * @return array |
| 1869 | 1869 | */ |
| 1870 | - public static function comment_any_status_filter( $pieces ) { |
|
| 1870 | + public static function comment_any_status_filter($pieces) { |
|
| 1871 | 1871 | |
| 1872 | - $pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] ); |
|
| 1872 | + $pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']); |
|
| 1873 | 1873 | |
| 1874 | 1874 | return $pieces; |
| 1875 | 1875 | } |
@@ -1881,12 +1881,12 @@ discard block |
||
| 1881 | 1881 | * @param array $pieces (default: array()) |
| 1882 | 1882 | * @return array |
| 1883 | 1883 | */ |
| 1884 | - public static function comment_multiple_status_filter( $pieces ) { |
|
| 1884 | + public static function comment_multiple_status_filter($pieces) { |
|
| 1885 | 1885 | |
| 1886 | - preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder ); |
|
| 1887 | - if ( !empty($placeholder[1]) ) { |
|
| 1888 | - $statuses = explode( ',', $placeholder[1] ); |
|
| 1889 | - $pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] ); |
|
| 1886 | + preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder); |
|
| 1887 | + if ( ! empty($placeholder[1])) { |
|
| 1888 | + $statuses = explode(',', $placeholder[1]); |
|
| 1889 | + $pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']); |
|
| 1890 | 1890 | } |
| 1891 | 1891 | |
| 1892 | 1892 | return $pieces; |
@@ -1898,12 +1898,12 @@ discard block |
||
| 1898 | 1898 | * @param array $pieces |
| 1899 | 1899 | * @return array $pieces |
| 1900 | 1900 | */ |
| 1901 | - public static function comment_total_sum_meta_value_filter( $pieces ) { |
|
| 1901 | + public static function comment_total_sum_meta_value_filter($pieces) { |
|
| 1902 | 1902 | global $wpdb, $wp_version; |
| 1903 | 1903 | |
| 1904 | 1904 | $pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum "; |
| 1905 | - unset( $pieces['groupby'] ); |
|
| 1906 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1905 | + unset($pieces['groupby']); |
|
| 1906 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1907 | 1907 | $args['order'] = false; |
| 1908 | 1908 | $args['orderby'] = false; |
| 1909 | 1909 | } |
@@ -1918,12 +1918,12 @@ discard block |
||
| 1918 | 1918 | * @param array $pieces (default: array()) |
| 1919 | 1919 | * @return array |
| 1920 | 1920 | */ |
| 1921 | - public static function get_posts_count_only_filter( $pieces ) { |
|
| 1921 | + public static function get_posts_count_only_filter($pieces) { |
|
| 1922 | 1922 | global $wp_version; |
| 1923 | 1923 | |
| 1924 | 1924 | $pieces['fields'] = " COUNT(*) AS total "; |
| 1925 | - unset( $pieces['groupby'] ); |
|
| 1926 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1925 | + unset($pieces['groupby']); |
|
| 1926 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1927 | 1927 | $args['order'] = false; |
| 1928 | 1928 | $args['orderby'] = false; |
| 1929 | 1929 | } |
@@ -1942,9 +1942,9 @@ discard block |
||
| 1942 | 1942 | * |
| 1943 | 1943 | * @return bool $success |
| 1944 | 1944 | */ |
| 1945 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1945 | + public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
| 1946 | 1946 | |
| 1947 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1947 | + return self::update_user_data($data_key, $post_id, $value, $user_id); |
|
| 1948 | 1948 | |
| 1949 | 1949 | }// end add_user_data |
| 1950 | 1950 | |
@@ -1963,18 +1963,18 @@ discard block |
||
| 1963 | 1963 | * |
| 1964 | 1964 | * @return bool $success |
| 1965 | 1965 | */ |
| 1966 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1966 | + public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
| 1967 | 1967 | |
| 1968 | - if( ! ( $user_id > 0 ) ){ |
|
| 1968 | + if ( ! ($user_id > 0)) { |
|
| 1969 | 1969 | $user_id = get_current_user_id(); |
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1973 | - $post_type = get_post_type( $post_id ); |
|
| 1974 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1975 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1976 | - || !get_userdata( $user_id ) |
|
| 1977 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1972 | + $supported_post_types = array('course', 'lesson'); |
|
| 1973 | + $post_type = get_post_type($post_id); |
|
| 1974 | + if (empty($post_id) || empty($data_key) |
|
| 1975 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 1976 | + || ! get_userdata($user_id) |
|
| 1977 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 1978 | 1978 | |
| 1979 | 1979 | return false; |
| 1980 | 1980 | } |
@@ -1982,20 +1982,20 @@ discard block |
||
| 1982 | 1982 | // check if there and existing Sensei status on this post type if not create it |
| 1983 | 1983 | // and get the activity ID |
| 1984 | 1984 | $status_function = 'user_'.$post_type.'_status'; |
| 1985 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1986 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1985 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 1986 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 1987 | 1987 | |
| 1988 | 1988 | $start_function = 'user_start_'.$post_type; |
| 1989 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1989 | + $sensei_user_activity_id = self::$start_function($user_id, $post_id); |
|
| 1990 | 1990 | |
| 1991 | - }else{ |
|
| 1991 | + } else { |
|
| 1992 | 1992 | |
| 1993 | 1993 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 1994 | 1994 | |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | 1997 | // store the data |
| 1998 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1998 | + $success = update_comment_meta($sensei_user_activity_id, $data_key, $value); |
|
| 1999 | 1999 | |
| 2000 | 2000 | return $success; |
| 2001 | 2001 | |
@@ -2014,20 +2014,20 @@ discard block |
||
| 2014 | 2014 | * |
| 2015 | 2015 | * @return mixed $user_data_value |
| 2016 | 2016 | */ |
| 2017 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 2017 | + public static function get_user_data($data_key, $post_id, $user_id = 0) { |
|
| 2018 | 2018 | |
| 2019 | 2019 | $user_data_value = true; |
| 2020 | 2020 | |
| 2021 | - if( ! ( $user_id > 0 ) ){ |
|
| 2021 | + if ( ! ($user_id > 0)) { |
|
| 2022 | 2022 | $user_id = get_current_user_id(); |
| 2023 | 2023 | } |
| 2024 | 2024 | |
| 2025 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2026 | - $post_type = get_post_type( $post_id ); |
|
| 2027 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2028 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2029 | - || ! get_userdata( $user_id ) |
|
| 2030 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2025 | + $supported_post_types = array('course', 'lesson'); |
|
| 2026 | + $post_type = get_post_type($post_id); |
|
| 2027 | + if (empty($post_id) || empty($data_key) |
|
| 2028 | + || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 2029 | + || ! get_userdata($user_id) |
|
| 2030 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 2031 | 2031 | |
| 2032 | 2032 | return false; |
| 2033 | 2033 | } |
@@ -2035,13 +2035,13 @@ discard block |
||
| 2035 | 2035 | // check if there and existing Sensei status on this post type if not create it |
| 2036 | 2036 | // and get the activity ID |
| 2037 | 2037 | $status_function = 'user_'.$post_type.'_status'; |
| 2038 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2039 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2038 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 2039 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 2040 | 2040 | return false; |
| 2041 | 2041 | } |
| 2042 | 2042 | |
| 2043 | 2043 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 2044 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2044 | + $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true); |
|
| 2045 | 2045 | |
| 2046 | 2046 | return $user_data_value; |
| 2047 | 2047 | |
@@ -2056,19 +2056,19 @@ discard block |
||
| 2056 | 2056 | * |
| 2057 | 2057 | * @return bool $deleted |
| 2058 | 2058 | */ |
| 2059 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2059 | + public static function delete_user_data($data_key, $post_id, $user_id) { |
|
| 2060 | 2060 | $deleted = true; |
| 2061 | 2061 | |
| 2062 | - if( ! ( $user_id > 0 ) ){ |
|
| 2062 | + if ( ! ($user_id > 0)) { |
|
| 2063 | 2063 | $user_id = get_current_user_id(); |
| 2064 | 2064 | } |
| 2065 | 2065 | |
| 2066 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2067 | - $post_type = get_post_type( $post_id ); |
|
| 2068 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2069 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2070 | - || ! get_userdata( $user_id ) |
|
| 2071 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2066 | + $supported_post_types = array('course', 'lesson'); |
|
| 2067 | + $post_type = get_post_type($post_id); |
|
| 2068 | + if (empty($post_id) || empty($data_key) |
|
| 2069 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 2070 | + || ! get_userdata($user_id) |
|
| 2071 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 2072 | 2072 | |
| 2073 | 2073 | return false; |
| 2074 | 2074 | } |
@@ -2076,13 +2076,13 @@ discard block |
||
| 2076 | 2076 | // check if there and existing Sensei status on this post type if not create it |
| 2077 | 2077 | // and get the activity ID |
| 2078 | 2078 | $status_function = 'user_'.$post_type.'_status'; |
| 2079 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2080 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2079 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 2080 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 2081 | 2081 | return false; |
| 2082 | 2082 | } |
| 2083 | 2083 | |
| 2084 | 2084 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 2085 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2085 | + $deleted = delete_comment_meta($sensei_user_activity_id, $data_key); |
|
| 2086 | 2086 | |
| 2087 | 2087 | return $deleted; |
| 2088 | 2088 | |
@@ -2107,62 +2107,62 @@ discard block |
||
| 2107 | 2107 | * |
| 2108 | 2108 | * @return string $drop_down_element |
| 2109 | 2109 | */ |
| 2110 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2110 | + public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) { |
|
| 2111 | 2111 | |
| 2112 | 2112 | $drop_down_element = ''; |
| 2113 | 2113 | |
| 2114 | 2114 | // setup the basic attributes |
| 2115 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2115 | + if ( ! isset($attributes['name']) || empty($attributes['name'])) { |
|
| 2116 | 2116 | |
| 2117 | 2117 | $attributes['name'] = 'sensei-options'; |
| 2118 | 2118 | |
| 2119 | 2119 | } |
| 2120 | 2120 | |
| 2121 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2121 | + if ( ! isset($attributes['id']) || empty($attributes['id'])) { |
|
| 2122 | 2122 | |
| 2123 | 2123 | $attributes['id'] = 'sensei-options'; |
| 2124 | 2124 | |
| 2125 | 2125 | } |
| 2126 | 2126 | |
| 2127 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2127 | + if ( ! isset($attributes['class']) || empty($attributes['class'])) { |
|
| 2128 | 2128 | |
| 2129 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2129 | + $attributes['class'] = 'chosen_select widefat'; |
|
| 2130 | 2130 | |
| 2131 | 2131 | } |
| 2132 | 2132 | |
| 2133 | 2133 | // create element attributes |
| 2134 | 2134 | $combined_attributes = ''; |
| 2135 | - foreach( $attributes as $attribute => $value ){ |
|
| 2135 | + foreach ($attributes as $attribute => $value) { |
|
| 2136 | 2136 | |
| 2137 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2137 | + $combined_attributes .= $attribute.'="'.$value.'"'.' '; |
|
| 2138 | 2138 | |
| 2139 | 2139 | }// end for each |
| 2140 | 2140 | |
| 2141 | 2141 | |
| 2142 | 2142 | // create the select element |
| 2143 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2143 | + $drop_down_element .= '<select '.$combined_attributes.' >'."\n"; |
|
| 2144 | 2144 | |
| 2145 | 2145 | // show the none option if the client requested |
| 2146 | - if( $enable_none_option ) { |
|
| 2147 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2146 | + if ($enable_none_option) { |
|
| 2147 | + $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
| 2148 | 2148 | } |
| 2149 | 2149 | |
| 2150 | - if ( count( $options ) > 0 ) { |
|
| 2150 | + if (count($options) > 0) { |
|
| 2151 | 2151 | |
| 2152 | - foreach ($options as $value => $option ){ |
|
| 2152 | + foreach ($options as $value => $option) { |
|
| 2153 | 2153 | |
| 2154 | 2154 | $element = ''; |
| 2155 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2156 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2157 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2155 | + $element .= '<option value="'.esc_attr($value).'"'; |
|
| 2156 | + $element .= selected($value, $selected_value, false).'>'; |
|
| 2157 | + $element .= esc_html($option).'</option>'."\n"; |
|
| 2158 | 2158 | |
| 2159 | 2159 | // add the element to the select html |
| 2160 | - $drop_down_element.= $element; |
|
| 2160 | + $drop_down_element .= $element; |
|
| 2161 | 2161 | } // End For Loop |
| 2162 | 2162 | |
| 2163 | 2163 | } // End If Statement |
| 2164 | 2164 | |
| 2165 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2165 | + $drop_down_element .= '</select>'."\n"; |
|
| 2166 | 2166 | |
| 2167 | 2167 | return $drop_down_element; |
| 2168 | 2168 | |
@@ -2182,14 +2182,14 @@ discard block |
||
| 2182 | 2182 | * |
| 2183 | 2183 | * @return double $val |
| 2184 | 2184 | */ |
| 2185 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2185 | + public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') { |
|
| 2186 | 2186 | |
| 2187 | 2187 | /**å |
| 2188 | 2188 | * Change the precision for the Sensei_Utils::round function. |
| 2189 | 2189 | * the precision given will be passed into the php round function |
| 2190 | 2190 | * @since 1.8.5 |
| 2191 | 2191 | */ |
| 2192 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2192 | + $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode); |
|
| 2193 | 2193 | |
| 2194 | 2194 | /** |
| 2195 | 2195 | * Change the mode for the Sensei_Utils::round function. |
@@ -2199,15 +2199,15 @@ discard block |
||
| 2199 | 2199 | * |
| 2200 | 2200 | * @since 1.8.5 |
| 2201 | 2201 | */ |
| 2202 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2202 | + $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision); |
|
| 2203 | 2203 | |
| 2204 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2204 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
| 2205 | 2205 | |
| 2206 | - return round( $val, $precision, $mode ); |
|
| 2206 | + return round($val, $precision, $mode); |
|
| 2207 | 2207 | |
| 2208 | - }else{ |
|
| 2208 | + } else { |
|
| 2209 | 2209 | |
| 2210 | - return round( $val, $precision ); |
|
| 2210 | + return round($val, $precision); |
|
| 2211 | 2211 | |
| 2212 | 2212 | } |
| 2213 | 2213 | |
@@ -2219,15 +2219,15 @@ discard block |
||
| 2219 | 2219 | * @since 1.9.0 |
| 2220 | 2220 | * @return string $url |
| 2221 | 2221 | */ |
| 2222 | - public static function get_current_url(){ |
|
| 2222 | + public static function get_current_url() { |
|
| 2223 | 2223 | |
| 2224 | 2224 | global $wp; |
| 2225 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2226 | - if ( isset( $_GET ) ) { |
|
| 2225 | + $current_url = trailingslashit(home_url($wp->request)); |
|
| 2226 | + if (isset($_GET)) { |
|
| 2227 | 2227 | |
| 2228 | - foreach ($_GET as $param => $val ) { |
|
| 2228 | + foreach ($_GET as $param => $val) { |
|
| 2229 | 2229 | |
| 2230 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2230 | + $current_url = add_query_arg($param, $val, $current_url); |
|
| 2231 | 2231 | |
| 2232 | 2232 | } |
| 2233 | 2233 | } |
@@ -2257,27 +2257,27 @@ discard block |
||
| 2257 | 2257 | * @param array $array_b |
| 2258 | 2258 | * @return array $merged_array |
| 2259 | 2259 | */ |
| 2260 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2260 | + public static function array_zip_merge($array_a, $array_b) { |
|
| 2261 | 2261 | |
| 2262 | - if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
| 2262 | + if ( ! is_array($array_a) || ! is_array($array_b)) { |
|
| 2263 | 2263 | trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | 2266 | $merged_array = array(); |
| 2267 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2267 | + $total_elements = count($array_a) + count($array_b); |
|
| 2268 | 2268 | |
| 2269 | 2269 | // Zip arrays |
| 2270 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2270 | + for ($i = 0; $i < $total_elements; $i++) { |
|
| 2271 | 2271 | |
| 2272 | 2272 | // if has an element at current index push a on top |
| 2273 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2274 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2273 | + if (isset($array_a[$i])) { |
|
| 2274 | + $merged_array[] = $array_a[$i]; |
|
| 2275 | 2275 | } |
| 2276 | 2276 | |
| 2277 | 2277 | // next if $array_b has an element at current index push a on top of the element |
| 2278 | 2278 | // from a if there was one, if not the element before that. |
| 2279 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2280 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2279 | + if (isset($array_b[$i])) { |
|
| 2280 | + $merged_array[] = $array_b[$i]; |
|
| 2281 | 2281 | } |
| 2282 | 2282 | |
| 2283 | 2283 | } |
@@ -2292,4 +2292,4 @@ discard block |
||
| 2292 | 2292 | * @ignore only for backward compatibility |
| 2293 | 2293 | * @since 1.9.0 |
| 2294 | 2294 | */ |
| 2295 | -class WooThemes_Sensei_Utils extends Sensei_Utils{} |
|
| 2296 | 2295 | \ No newline at end of file |
| 2296 | +class WooThemes_Sensei_Utils extends Sensei_Utils {} |
|
| 2297 | 2297 | \ No newline at end of file |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | * @since 1.2.0 |
| 995 | 995 | * @since 1.9.0 move to class Sensei_WC |
| 996 | 996 | * |
| 997 | - * @param WC_Order $order |
|
| 997 | + * @param integer $order |
|
| 998 | 998 | * |
| 999 | 999 | * @return void |
| 1000 | 1000 | */ |
@@ -1212,6 +1212,7 @@ discard block |
||
| 1212 | 1212 | * @since 1.2.0 |
| 1213 | 1213 | * @since 1.9.0 Move function to the Sensei_WC class |
| 1214 | 1214 | * @param integer| WC_Order $order_id order ID |
| 1215 | + * @param integer $order_id |
|
| 1215 | 1216 | * @return void |
| 1216 | 1217 | */ |
| 1217 | 1218 | public static function cancel_order ( $order_id ) { |
@@ -1402,7 +1403,7 @@ discard block |
||
| 1402 | 1403 | * |
| 1403 | 1404 | * @param boolean $guest_checkout Current guest checkout setting |
| 1404 | 1405 | * |
| 1405 | - * @return boolean Modified guest checkout setting |
|
| 1406 | + * @return string|boolean Modified guest checkout setting |
|
| 1406 | 1407 | */ |
| 1407 | 1408 | public static function disable_guest_checkout( $guest_checkout ) { |
| 1408 | 1409 | |
@@ -1639,7 +1640,7 @@ discard block |
||
| 1639 | 1640 | * Get all the valid subscription types. |
| 1640 | 1641 | * |
| 1641 | 1642 | * @since 1.9.0 |
| 1642 | - * @return array |
|
| 1643 | + * @return string[] |
|
| 1643 | 1644 | */ |
| 1644 | 1645 | public static function get_subscription_types(){ |
| 1645 | 1646 | |
@@ -1658,7 +1659,7 @@ discard block |
||
| 1658 | 1659 | * @since 1.9.0 |
| 1659 | 1660 | * |
| 1660 | 1661 | * @param $user_id |
| 1661 | - * @param $product_id |
|
| 1662 | + * @param string $product_id |
|
| 1662 | 1663 | * @param $course_id |
| 1663 | 1664 | * |
| 1664 | 1665 | * @return bool |
@@ -1725,7 +1726,7 @@ discard block |
||
| 1725 | 1726 | * Get all the orders for a specific user and product combination |
| 1726 | 1727 | * |
| 1727 | 1728 | * @param int $user_id |
| 1728 | - * @param $product_id |
|
| 1729 | + * @param integer $product_id |
|
| 1729 | 1730 | * |
| 1730 | 1731 | * @return array $orders |
| 1731 | 1732 | */ |
@@ -13,756 +13,756 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | Class Sensei_WC{ |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Load the files needed for the woocommerce integration. |
|
| 18 | - * |
|
| 19 | - * @since 1.9.0 |
|
| 20 | - */ |
|
| 21 | - public static function load_woocommerce_integration_hooks(){ |
|
| 16 | + /** |
|
| 17 | + * Load the files needed for the woocommerce integration. |
|
| 18 | + * |
|
| 19 | + * @since 1.9.0 |
|
| 20 | + */ |
|
| 21 | + public static function load_woocommerce_integration_hooks(){ |
|
| 22 | 22 | |
| 23 | - $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php'; |
|
| 24 | - require_once( $woocommerce_hooks_file_path ); |
|
| 23 | + $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php'; |
|
| 24 | + require_once( $woocommerce_hooks_file_path ); |
|
| 25 | 25 | |
| 26 | - } |
|
| 27 | - /** |
|
| 28 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 29 | - * |
|
| 30 | - * @since 1.9.0 |
|
| 31 | - * @return bool |
|
| 32 | - */ |
|
| 33 | - public static function is_woocommerce_active(){ |
|
| 26 | + } |
|
| 27 | + /** |
|
| 28 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 29 | + * |
|
| 30 | + * @since 1.9.0 |
|
| 31 | + * @return bool |
|
| 32 | + */ |
|
| 33 | + public static function is_woocommerce_active(){ |
|
| 34 | 34 | |
| 35 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 36 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 35 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 36 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 37 | 37 | |
| 38 | - } // end is_woocommerce_active |
|
| 38 | + } // end is_woocommerce_active |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Checks if the WooCommerce plugin is installed and activation. |
|
| 42 | - * |
|
| 43 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 44 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 45 | - * |
|
| 46 | - * @since 1.9.0 |
|
| 47 | - * |
|
| 48 | - * @return bool |
|
| 49 | - */ |
|
| 50 | - public static function is_woocommerce_present(){ |
|
| 40 | + /** |
|
| 41 | + * Checks if the WooCommerce plugin is installed and activation. |
|
| 42 | + * |
|
| 43 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 44 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 45 | + * |
|
| 46 | + * @since 1.9.0 |
|
| 47 | + * |
|
| 48 | + * @return bool |
|
| 49 | + */ |
|
| 50 | + public static function is_woocommerce_present(){ |
|
| 51 | 51 | |
| 52 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 52 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 53 | 53 | |
| 54 | - if ( is_multisite() ){ |
|
| 54 | + if ( is_multisite() ){ |
|
| 55 | 55 | |
| 56 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 56 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 57 | 57 | |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 60 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 61 | 61 | |
| 62 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 62 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 63 | 63 | |
| 64 | - }// end is_woocommerce_present |
|
| 64 | + }// end is_woocommerce_present |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 68 | - * |
|
| 69 | - * If multiple exist we will return the latest order. |
|
| 70 | - * |
|
| 71 | - * @param $user_id |
|
| 72 | - * @param $course_id |
|
| 73 | - * @return array $user_course_orders |
|
| 74 | - */ |
|
| 75 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 66 | + /** |
|
| 67 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 68 | + * |
|
| 69 | + * If multiple exist we will return the latest order. |
|
| 70 | + * |
|
| 71 | + * @param $user_id |
|
| 72 | + * @param $course_id |
|
| 73 | + * @return array $user_course_orders |
|
| 74 | + */ |
|
| 75 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 76 | + |
|
| 77 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 78 | + |
|
| 79 | + $orders_query = new WP_Query( array( |
|
| 80 | + 'post_type' => 'shop_order', |
|
| 81 | + 'posts_per_page' => -1, |
|
| 82 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 83 | + 'meta_key'=> '_customer_user', |
|
| 84 | + 'meta_value'=> $user_id, |
|
| 85 | + ) ); |
|
| 86 | + |
|
| 87 | + if( $orders_query->post_count == 0 ){ |
|
| 88 | + |
|
| 89 | + return false; |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + foreach( $orders_query->get_posts() as $order ){ |
|
| 94 | + |
|
| 95 | + $order = new WC_Order( $order->ID ); |
|
| 96 | + $items = $order->get_items(); |
|
| 97 | + |
|
| 98 | + $user_orders = array(); |
|
| 76 | 99 | |
| 77 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 100 | + foreach( $items as $item ){ |
|
| 78 | 101 | |
| 79 | - $orders_query = new WP_Query( array( |
|
| 80 | - 'post_type' => 'shop_order', |
|
| 81 | - 'posts_per_page' => -1, |
|
| 82 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 83 | - 'meta_key'=> '_customer_user', |
|
| 84 | - 'meta_value'=> $user_id, |
|
| 85 | - ) ); |
|
| 102 | + // if the product id on the order and the one given to this function |
|
| 103 | + // this order has been placed by the given user on the given course. |
|
| 104 | + $product = wc_get_product( $item['product_id'] ); |
|
| 86 | 105 | |
| 87 | - if( $orders_query->post_count == 0 ){ |
|
| 106 | + if ( is_object( $product ) && $product->is_type( 'variable' )) { |
|
| 88 | 107 | |
| 89 | - return false; |
|
| 108 | + $item_product_id = $item['variation_id']; |
|
| 90 | 109 | |
| 91 | - } |
|
| 110 | + } else { |
|
| 92 | 111 | |
| 93 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 112 | + $item_product_id = $item['product_id']; |
|
| 94 | 113 | |
| 95 | - $order = new WC_Order( $order->ID ); |
|
| 96 | - $items = $order->get_items(); |
|
| 114 | + } |
|
| 97 | 115 | |
| 98 | - $user_orders = array(); |
|
| 116 | + if( $course_product_id == $item_product_id ){ |
|
| 99 | 117 | |
| 100 | - foreach( $items as $item ){ |
|
| 118 | + return $order->id; |
|
| 101 | 119 | |
| 102 | - // if the product id on the order and the one given to this function |
|
| 103 | - // this order has been placed by the given user on the given course. |
|
| 104 | - $product = wc_get_product( $item['product_id'] ); |
|
| 120 | + } |
|
| 105 | 121 | |
| 106 | - if ( is_object( $product ) && $product->is_type( 'variable' )) { |
|
| 107 | 122 | |
| 108 | - $item_product_id = $item['variation_id']; |
|
| 123 | + }//end for each order item |
|
| 109 | 124 | |
| 110 | - } else { |
|
| 125 | + } // end for each order |
|
| 111 | 126 | |
| 112 | - $item_product_id = $item['product_id']; |
|
| 127 | + // if we reach this place we found no order |
|
| 128 | + return false; |
|
| 113 | 129 | |
| 114 | - } |
|
| 130 | + } // end get_learner_course_active_order_ids |
|
| 115 | 131 | |
| 116 | - if( $course_product_id == $item_product_id ){ |
|
| 132 | + /** |
|
| 133 | + * Output WooCommerce specific course filters |
|
| 134 | + * Removing the paged argument |
|
| 135 | + * |
|
| 136 | + * @since 1.9.0 |
|
| 137 | + * @param $filter_links |
|
| 138 | + * @return mixed |
|
| 139 | + */ |
|
| 140 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 141 | + |
|
| 142 | + $free_courses = self::get_free_courses(); |
|
| 143 | + $paid_courses = self::get_paid_courses(); |
|
| 144 | + |
|
| 145 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 146 | + // do not show any WooCommerce filters if all courses are |
|
| 147 | + // free or if all courses are paid |
|
| 148 | + return $filter_links; |
|
| 117 | 149 | |
| 118 | - return $order->id; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $filter_links[] = array( |
|
| 153 | + 'id'=>'paid' , |
|
| 154 | + 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 155 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 156 | + ); |
|
| 157 | + |
|
| 158 | + $filter_links[] = array( |
|
| 159 | + 'id'=>'free', |
|
| 160 | + 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 161 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 162 | + ); |
|
| 119 | 163 | |
| 120 | - } |
|
| 164 | + return $filter_links; |
|
| 121 | 165 | |
| 166 | + }// end add_course_archive_wc_filter_links |
|
| 122 | 167 | |
| 123 | - }//end for each order item |
|
| 168 | + /** |
|
| 169 | + * Apply the free filter the the course query |
|
| 170 | + * getting all course with no products or products with zero price |
|
| 171 | + * |
|
| 172 | + * hooked into pre_get_posts |
|
| 173 | + * |
|
| 174 | + * @since 1.9.0 |
|
| 175 | + * @param WP_Query $query |
|
| 176 | + * @return WP_Query $query |
|
| 177 | + */ |
|
| 178 | + public static function course_archive_wc_filter_free( $query ){ |
|
| 124 | 179 | |
| 125 | - } // end for each order |
|
| 180 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 181 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 126 | 182 | |
| 127 | - // if we reach this place we found no order |
|
| 128 | - return false; |
|
| 183 | + // setup the course meta query |
|
| 184 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
| 129 | 185 | |
| 130 | - } // end get_learner_course_active_order_ids |
|
| 186 | + // manipulate the query to return free courses |
|
| 187 | + $query->set('meta_query', $meta_query ); |
|
| 131 | 188 | |
| 132 | - /** |
|
| 133 | - * Output WooCommerce specific course filters |
|
| 134 | - * Removing the paged argument |
|
| 135 | - * |
|
| 136 | - * @since 1.9.0 |
|
| 137 | - * @param $filter_links |
|
| 138 | - * @return mixed |
|
| 139 | - */ |
|
| 140 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 189 | + // don't show any paid courses |
|
| 190 | + $courses = self::get_paid_courses(); |
|
| 191 | + $ids = array(); |
|
| 192 | + foreach( $courses as $course ){ |
|
| 193 | + $ids[] = $course->ID; |
|
| 194 | + } |
|
| 195 | + $query->set( 'post__not_in', $ids ); |
|
| 141 | 196 | |
| 142 | - $free_courses = self::get_free_courses(); |
|
| 143 | - $paid_courses = self::get_paid_courses(); |
|
| 197 | + }// end if course_filter |
|
| 144 | 198 | |
| 145 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 146 | - // do not show any WooCommerce filters if all courses are |
|
| 147 | - // free or if all courses are paid |
|
| 148 | - return $filter_links; |
|
| 199 | + return $query; |
|
| 149 | 200 | |
| 150 | - } |
|
| 201 | + }// course_archive_wc_filter_free |
|
| 151 | 202 | |
| 152 | - $filter_links[] = array( |
|
| 153 | - 'id'=>'paid' , |
|
| 154 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 155 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 156 | - ); |
|
| 203 | + /** |
|
| 204 | + * Apply the paid filter to the course query on the courses page |
|
| 205 | + * will include all course with a product attached with a price |
|
| 206 | + * more than 0 |
|
| 207 | + * |
|
| 208 | + * hooked into pre_get_posts |
|
| 209 | + * |
|
| 210 | + * @since 1.9.0 |
|
| 211 | + * @param WP_Query $query |
|
| 212 | + * @return WP_Query $query |
|
| 213 | + */ |
|
| 214 | + public static function course_archive_wc_filter_paid( $query ){ |
|
| 157 | 215 | |
| 158 | - $filter_links[] = array( |
|
| 159 | - 'id'=>'free', |
|
| 160 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 161 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 162 | - ); |
|
| 216 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 217 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 163 | 218 | |
| 164 | - return $filter_links; |
|
| 219 | + // setup the course meta query |
|
| 220 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 165 | 221 | |
| 166 | - }// end add_course_archive_wc_filter_links |
|
| 222 | + // manipulate the query to return free courses |
|
| 223 | + $query->set('meta_query', $meta_query ); |
|
| 167 | 224 | |
| 168 | - /** |
|
| 169 | - * Apply the free filter the the course query |
|
| 170 | - * getting all course with no products or products with zero price |
|
| 171 | - * |
|
| 172 | - * hooked into pre_get_posts |
|
| 173 | - * |
|
| 174 | - * @since 1.9.0 |
|
| 175 | - * @param WP_Query $query |
|
| 176 | - * @return WP_Query $query |
|
| 177 | - */ |
|
| 178 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 225 | + } |
|
| 179 | 226 | |
| 180 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 181 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 227 | + return $query; |
|
| 182 | 228 | |
| 183 | - // setup the course meta query |
|
| 184 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
| 229 | + } |
|
| 185 | 230 | |
| 186 | - // manipulate the query to return free courses |
|
| 187 | - $query->set('meta_query', $meta_query ); |
|
| 231 | + /** |
|
| 232 | + * Load the WooCommerce single product actions above |
|
| 233 | + * single courses if woocommerce is active allowing purchase |
|
| 234 | + * information and actions to be hooked from WooCommerce. |
|
| 235 | + */ |
|
| 236 | + public static function do_single_course_wc_single_product_action(){ |
|
| 188 | 237 | |
| 189 | - // don't show any paid courses |
|
| 190 | - $courses = self::get_paid_courses(); |
|
| 191 | - $ids = array(); |
|
| 192 | - foreach( $courses as $course ){ |
|
| 193 | - $ids[] = $course->ID; |
|
| 194 | - } |
|
| 195 | - $query->set( 'post__not_in', $ids ); |
|
| 238 | + /** |
|
| 239 | + * this hooks is documented within the WooCommerce plugin. |
|
| 240 | + */ |
|
| 241 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 196 | 242 | |
| 197 | - }// end if course_filter |
|
| 243 | + do_action( 'woocommerce_before_single_product' ); |
|
| 198 | 244 | |
| 199 | - return $query; |
|
| 245 | + } // End If Statement |
|
| 200 | 246 | |
| 201 | - }// course_archive_wc_filter_free |
|
| 247 | + }// end do_single_course_wc_single_product_action |
|
| 202 | 248 | |
| 203 | - /** |
|
| 204 | - * Apply the paid filter to the course query on the courses page |
|
| 205 | - * will include all course with a product attached with a price |
|
| 206 | - * more than 0 |
|
| 207 | - * |
|
| 208 | - * hooked into pre_get_posts |
|
| 209 | - * |
|
| 210 | - * @since 1.9.0 |
|
| 211 | - * @param WP_Query $query |
|
| 212 | - * @return WP_Query $query |
|
| 213 | - */ |
|
| 214 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 249 | + /** |
|
| 250 | + * Hooking into the single lesson page to alter the |
|
| 251 | + * user access permissions based on if they have purchased the |
|
| 252 | + * course the lesson belongs to. |
|
| 253 | + * |
|
| 254 | + * This function will only return false or the passed in user_access value. |
|
| 255 | + * It doesn't return true in order to avoid altering other options. |
|
| 256 | + * |
|
| 257 | + * @since 1.9.0 |
|
| 258 | + * |
|
| 259 | + * @param $can_user_view_lesson |
|
| 260 | + * @param $lesson_id |
|
| 261 | + * @param $user_id |
|
| 262 | + * @return bool |
|
| 263 | + */ |
|
| 264 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 215 | 265 | |
| 216 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 217 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 218 | - |
|
| 219 | - // setup the course meta query |
|
| 220 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 221 | - |
|
| 222 | - // manipulate the query to return free courses |
|
| 223 | - $query->set('meta_query', $meta_query ); |
|
| 224 | - |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $query; |
|
| 228 | - |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Load the WooCommerce single product actions above |
|
| 233 | - * single courses if woocommerce is active allowing purchase |
|
| 234 | - * information and actions to be hooked from WooCommerce. |
|
| 235 | - */ |
|
| 236 | - public static function do_single_course_wc_single_product_action(){ |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * this hooks is documented within the WooCommerce plugin. |
|
| 240 | - */ |
|
| 241 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 242 | - |
|
| 243 | - do_action( 'woocommerce_before_single_product' ); |
|
| 244 | - |
|
| 245 | - } // End If Statement |
|
| 246 | - |
|
| 247 | - }// end do_single_course_wc_single_product_action |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Hooking into the single lesson page to alter the |
|
| 251 | - * user access permissions based on if they have purchased the |
|
| 252 | - * course the lesson belongs to. |
|
| 253 | - * |
|
| 254 | - * This function will only return false or the passed in user_access value. |
|
| 255 | - * It doesn't return true in order to avoid altering other options. |
|
| 256 | - * |
|
| 257 | - * @since 1.9.0 |
|
| 258 | - * |
|
| 259 | - * @param $can_user_view_lesson |
|
| 260 | - * @param $lesson_id |
|
| 261 | - * @param $user_id |
|
| 262 | - * @return bool |
|
| 263 | - */ |
|
| 264 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 265 | - |
|
| 266 | - // do not override access to admins |
|
| 267 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 268 | - if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) |
|
| 269 | - || Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 266 | + // do not override access to admins |
|
| 267 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 268 | + if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) |
|
| 269 | + || Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 270 | 270 | |
| 271 | 271 | return true; |
| 272 | 272 | |
| 273 | - } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - // check if the course has a valid product attached to it |
|
| 276 | - // which the user should have purchased if they want to access |
|
| 277 | - // the current lesson |
|
| 278 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 279 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 280 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 281 | - if( isset ($product) && is_object($product) ){ |
|
| 275 | + // check if the course has a valid product attached to it |
|
| 276 | + // which the user should have purchased if they want to access |
|
| 277 | + // the current lesson |
|
| 278 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 279 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 280 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 281 | + if( isset ($product) && is_object($product) ){ |
|
| 282 | 282 | |
| 283 | - // valid product found |
|
| 284 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 283 | + // valid product found |
|
| 284 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 285 | 285 | |
| 286 | - // product has a successful order so this user may access the content |
|
| 287 | - // this function may only return false or the default |
|
| 288 | - // returning true may override other negatives which we don't want |
|
| 289 | - if( ! $order_id ){ |
|
| 286 | + // product has a successful order so this user may access the content |
|
| 287 | + // this function may only return false or the default |
|
| 288 | + // returning true may override other negatives which we don't want |
|
| 289 | + if( ! $order_id ){ |
|
| 290 | 290 | |
| 291 | - return false; |
|
| 291 | + return false; |
|
| 292 | 292 | |
| 293 | - } |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - // return the passed in value |
|
| 298 | - return $can_user_view_lesson; |
|
| 297 | + // return the passed in value |
|
| 298 | + return $can_user_view_lesson; |
|
| 299 | 299 | |
| 300 | - } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Add course link to order thank you and details pages. |
|
| 304 | - * |
|
| 305 | - * @since 1.4.5 |
|
| 306 | - * @access public |
|
| 307 | - * |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - public static function course_link_from_order( ) { |
|
| 302 | + /** |
|
| 303 | + * Add course link to order thank you and details pages. |
|
| 304 | + * |
|
| 305 | + * @since 1.4.5 |
|
| 306 | + * @access public |
|
| 307 | + * |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + public static function course_link_from_order( ) { |
|
| 311 | 311 | |
| 312 | - if( ! is_order_received_page() ){ |
|
| 313 | - return; |
|
| 314 | - } |
|
| 312 | + if( ! is_order_received_page() ){ |
|
| 313 | + return; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - $order_id = get_query_var( 'order-received' ); |
|
| 316 | + $order_id = get_query_var( 'order-received' ); |
|
| 317 | 317 | $order = new WC_Order( $order_id ); |
| 318 | 318 | |
| 319 | 319 | // exit early if not wc-completed or wc-processing |
| 320 | 320 | if( 'wc-completed' != $order->post_status |
| 321 | - && 'wc-processing' != $order->post_status ) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 321 | + && 'wc-processing' != $order->post_status ) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - $course_links = array(); // store the for links for courses purchased |
|
| 325 | + $course_links = array(); // store the for links for courses purchased |
|
| 326 | 326 | foreach ( $order->get_items() as $item ) { |
| 327 | 327 | |
| 328 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 328 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 329 | 329 | |
| 330 | - // If item has variation_id then its a variation of the product |
|
| 331 | - $item_id = $item['variation_id']; |
|
| 330 | + // If item has variation_id then its a variation of the product |
|
| 331 | + $item_id = $item['variation_id']; |
|
| 332 | 332 | |
| 333 | - } else { |
|
| 333 | + } else { |
|
| 334 | 334 | |
| 335 | - //If not its real product set its id to item_id |
|
| 336 | - $item_id = $item['product_id']; |
|
| 335 | + //If not its real product set its id to item_id |
|
| 336 | + $item_id = $item['product_id']; |
|
| 337 | 337 | |
| 338 | - } // End If Statement |
|
| 338 | + } // End If Statement |
|
| 339 | 339 | |
| 340 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 340 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 341 | 341 | |
| 342 | - if( $user_id ) { |
|
| 342 | + if( $user_id ) { |
|
| 343 | 343 | |
| 344 | - // Get all courses for product |
|
| 345 | - $args = Sensei_Course::get_default_query_args(); |
|
| 346 | - $args['meta_query'] = array( array( |
|
| 347 | - 'key' => '_course_woocommerce_product', |
|
| 348 | - 'value' => $item_id |
|
| 349 | - ) ); |
|
| 350 | - $args['orderby'] = 'menu_order date'; |
|
| 351 | - $args['order'] = 'ASC'; |
|
| 344 | + // Get all courses for product |
|
| 345 | + $args = Sensei_Course::get_default_query_args(); |
|
| 346 | + $args['meta_query'] = array( array( |
|
| 347 | + 'key' => '_course_woocommerce_product', |
|
| 348 | + 'value' => $item_id |
|
| 349 | + ) ); |
|
| 350 | + $args['orderby'] = 'menu_order date'; |
|
| 351 | + $args['order'] = 'ASC'; |
|
| 352 | 352 | |
| 353 | - // loop through courses |
|
| 354 | - $courses = get_posts( $args ); |
|
| 355 | - if( $courses && count( $courses ) > 0 ) { |
|
| 353 | + // loop through courses |
|
| 354 | + $courses = get_posts( $args ); |
|
| 355 | + if( $courses && count( $courses ) > 0 ) { |
|
| 356 | 356 | |
| 357 | - foreach( $courses as $course ) { |
|
| 357 | + foreach( $courses as $course ) { |
|
| 358 | 358 | |
| 359 | - $title = $course->post_title; |
|
| 360 | - $permalink = get_permalink( $course->ID ); |
|
| 361 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 359 | + $title = $course->post_title; |
|
| 360 | + $permalink = get_permalink( $course->ID ); |
|
| 361 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 362 | 362 | |
| 363 | - } // end for each |
|
| 363 | + } // end for each |
|
| 364 | 364 | |
| 365 | - // close the message div |
|
| 365 | + // close the message div |
|
| 366 | 366 | |
| 367 | - }// end if $courses check |
|
| 368 | - } |
|
| 369 | - }// end loop through orders |
|
| 367 | + }// end if $courses check |
|
| 368 | + } |
|
| 369 | + }// end loop through orders |
|
| 370 | 370 | |
| 371 | - // add the courses to the WooCommerce notice |
|
| 372 | - if( ! empty( $course_links) ){ |
|
| 371 | + // add the courses to the WooCommerce notice |
|
| 372 | + if( ! empty( $course_links) ){ |
|
| 373 | 373 | |
| 374 | - $courses_html = _nx( |
|
| 375 | - 'You have purchased the following course:', |
|
| 376 | - 'You have purchased the following courses:', |
|
| 377 | - count( $course_links ), |
|
| 378 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 379 | - ); |
|
| 374 | + $courses_html = _nx( |
|
| 375 | + 'You have purchased the following course:', |
|
| 376 | + 'You have purchased the following courses:', |
|
| 377 | + count( $course_links ), |
|
| 378 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 379 | + ); |
|
| 380 | 380 | |
| 381 | - foreach( $course_links as $link ){ |
|
| 381 | + foreach( $course_links as $link ){ |
|
| 382 | 382 | |
| 383 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 383 | + $courses_html .= '<li>' . $link . '</li>'; |
|
| 384 | 384 | |
| 385 | - } |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - $courses_html .= ' </ul>'; |
|
| 387 | + $courses_html .= ' </ul>'; |
|
| 388 | 388 | |
| 389 | - wc_add_notice( $courses_html, 'success' ); |
|
| 390 | - } |
|
| 389 | + wc_add_notice( $courses_html, 'success' ); |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | 392 | } // end course_link_order_form |
| 393 | 393 | |
| 394 | - /** |
|
| 395 | - * Show the message that a user should complete |
|
| 396 | - * their purchase if the course is in the cart |
|
| 397 | - * |
|
| 398 | - * This should be used within the course loop or single course page |
|
| 399 | - * |
|
| 400 | - * @since 1.9.0 |
|
| 401 | - */ |
|
| 402 | - public static function course_in_cart_message(){ |
|
| 394 | + /** |
|
| 395 | + * Show the message that a user should complete |
|
| 396 | + * their purchase if the course is in the cart |
|
| 397 | + * |
|
| 398 | + * This should be used within the course loop or single course page |
|
| 399 | + * |
|
| 400 | + * @since 1.9.0 |
|
| 401 | + */ |
|
| 402 | + public static function course_in_cart_message(){ |
|
| 403 | 403 | |
| 404 | - global $post; |
|
| 404 | + global $post; |
|
| 405 | 405 | |
| 406 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 406 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 407 | 407 | |
| 408 | 408 | <div class="sensei-message info"> |
| 409 | 409 | <?php |
| 410 | 410 | |
| 411 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 412 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 413 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 411 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 412 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 413 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 414 | 414 | |
| 415 | - echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 415 | + echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 416 | 416 | |
| 417 | - ?> |
|
| 417 | + ?> |
|
| 418 | 418 | </div> |
| 419 | 419 | <?php } |
| 420 | 420 | |
| 421 | - } // End sensei_woocommerce_in_cart_message() |
|
| 421 | + } // End sensei_woocommerce_in_cart_message() |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Checks the cart to see if a course is in the cart. |
|
| 425 | + * |
|
| 426 | + * @param $course_id |
|
| 427 | + * @return bool |
|
| 428 | + */ |
|
| 429 | + public static function is_course_in_cart( $course_id ){ |
|
| 430 | + |
|
| 431 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 432 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 433 | + |
|
| 434 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 435 | + |
|
| 436 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 437 | + |
|
| 438 | + return true; |
|
| 439 | + |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return false; |
|
| 445 | + |
|
| 446 | + }// is_course_in_cart |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Check the cart to see if the product is in the cart |
|
| 450 | + * |
|
| 451 | + * @param $product_id |
|
| 452 | + * @return bool |
|
| 453 | + */ |
|
| 454 | + public static function is_product_in_cart( $product_id ){ |
|
| 455 | + |
|
| 456 | + if ( 0 < $product_id ) { |
|
| 457 | + |
|
| 458 | + $product = wc_get_product( $product_id ); |
|
| 459 | + |
|
| 460 | + $parent_id = ''; |
|
| 461 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 462 | + $wc_product_id = $product->parent->id; |
|
| 463 | + } |
|
| 464 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 465 | + |
|
| 466 | + $cart_product = $values['data']; |
|
| 467 | + if( $product_id == $cart_product->id ) { |
|
| 468 | + |
|
| 469 | + return true; |
|
| 470 | + |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + } |
|
| 474 | + } // End If Statement |
|
| 475 | + |
|
| 476 | + return false; |
|
| 477 | + |
|
| 478 | + } // end is_product_in_car |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * Get all free WooCommerce products |
|
| 482 | + * |
|
| 483 | + * @since 1.9.0 |
|
| 484 | + * |
|
| 485 | + * @return array $free_products{ |
|
| 486 | + * @type int $wp_post_id |
|
| 487 | + * } |
|
| 488 | + */ |
|
| 489 | + public static function get_free_product_ids(){ |
|
| 490 | + |
|
| 491 | + return get_posts( array( |
|
| 492 | + 'post_type' => 'product', |
|
| 493 | + 'posts_per_page' => '1000', |
|
| 494 | + 'fields' => 'ids', |
|
| 495 | + 'meta_query'=> array( |
|
| 496 | + 'relation' => 'OR', |
|
| 497 | + array( |
|
| 498 | + 'key'=> '_regular_price', |
|
| 499 | + 'value' => 0, |
|
| 500 | + ), |
|
| 501 | + array( |
|
| 502 | + 'key'=> '_sale_price', |
|
| 503 | + 'value' => 0, |
|
| 504 | + ), |
|
| 505 | + ), |
|
| 506 | + )); |
|
| 507 | + |
|
| 508 | + }// end get free product query |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * The metat query for courses that are free |
|
| 512 | + * |
|
| 513 | + * @since 1.9.0 |
|
| 514 | + * @return array $wp_meta_query_param |
|
| 515 | + */ |
|
| 516 | + public static function get_free_courses_meta_query_args(){ |
|
| 517 | + |
|
| 518 | + return array( |
|
| 519 | + 'relation' => 'OR', |
|
| 520 | + array( |
|
| 521 | + 'key' => '_course_woocommerce_product', |
|
| 522 | + 'value' => '-', |
|
| 523 | + 'compare' => '=', |
|
| 524 | + ), |
|
| 525 | + array( |
|
| 526 | + 'key' => '_course_woocommerce_product', |
|
| 527 | + 'value' => self::get_free_product_ids(), |
|
| 528 | + 'compare' => 'IN', |
|
| 529 | + ), |
|
| 530 | + ); |
|
| 422 | 531 | |
| 423 | - /** |
|
| 424 | - * Checks the cart to see if a course is in the cart. |
|
| 425 | - * |
|
| 426 | - * @param $course_id |
|
| 427 | - * @return bool |
|
| 428 | - */ |
|
| 429 | - public static function is_course_in_cart( $course_id ){ |
|
| 430 | - |
|
| 431 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 432 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 433 | - |
|
| 434 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 435 | - |
|
| 436 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 437 | - |
|
| 438 | - return true; |
|
| 439 | - |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return false; |
|
| 445 | - |
|
| 446 | - }// is_course_in_cart |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Check the cart to see if the product is in the cart |
|
| 450 | - * |
|
| 451 | - * @param $product_id |
|
| 452 | - * @return bool |
|
| 453 | - */ |
|
| 454 | - public static function is_product_in_cart( $product_id ){ |
|
| 455 | - |
|
| 456 | - if ( 0 < $product_id ) { |
|
| 457 | - |
|
| 458 | - $product = wc_get_product( $product_id ); |
|
| 459 | - |
|
| 460 | - $parent_id = ''; |
|
| 461 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 462 | - $wc_product_id = $product->parent->id; |
|
| 463 | - } |
|
| 464 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 465 | - |
|
| 466 | - $cart_product = $values['data']; |
|
| 467 | - if( $product_id == $cart_product->id ) { |
|
| 468 | - |
|
| 469 | - return true; |
|
| 470 | - |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - } |
|
| 474 | - } // End If Statement |
|
| 475 | - |
|
| 476 | - return false; |
|
| 477 | - |
|
| 478 | - } // end is_product_in_car |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * Get all free WooCommerce products |
|
| 482 | - * |
|
| 483 | - * @since 1.9.0 |
|
| 484 | - * |
|
| 485 | - * @return array $free_products{ |
|
| 486 | - * @type int $wp_post_id |
|
| 487 | - * } |
|
| 488 | - */ |
|
| 489 | - public static function get_free_product_ids(){ |
|
| 490 | - |
|
| 491 | - return get_posts( array( |
|
| 492 | - 'post_type' => 'product', |
|
| 493 | - 'posts_per_page' => '1000', |
|
| 494 | - 'fields' => 'ids', |
|
| 495 | - 'meta_query'=> array( |
|
| 496 | - 'relation' => 'OR', |
|
| 497 | - array( |
|
| 498 | - 'key'=> '_regular_price', |
|
| 499 | - 'value' => 0, |
|
| 500 | - ), |
|
| 501 | - array( |
|
| 502 | - 'key'=> '_sale_price', |
|
| 503 | - 'value' => 0, |
|
| 504 | - ), |
|
| 505 | - ), |
|
| 506 | - )); |
|
| 507 | - |
|
| 508 | - }// end get free product query |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * The metat query for courses that are free |
|
| 512 | - * |
|
| 513 | - * @since 1.9.0 |
|
| 514 | - * @return array $wp_meta_query_param |
|
| 515 | - */ |
|
| 516 | - public static function get_free_courses_meta_query_args(){ |
|
| 517 | - |
|
| 518 | - return array( |
|
| 519 | - 'relation' => 'OR', |
|
| 520 | - array( |
|
| 521 | - 'key' => '_course_woocommerce_product', |
|
| 522 | - 'value' => '-', |
|
| 523 | - 'compare' => '=', |
|
| 524 | - ), |
|
| 525 | - array( |
|
| 526 | - 'key' => '_course_woocommerce_product', |
|
| 527 | - 'value' => self::get_free_product_ids(), |
|
| 528 | - 'compare' => 'IN', |
|
| 529 | - ), |
|
| 530 | - ); |
|
| 531 | - |
|
| 532 | - }// get_free_courses_meta_query |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * The metat query for courses that are free |
|
| 536 | - * |
|
| 537 | - * @since 1.9.0 |
|
| 538 | - * @return array $wp_query_meta_query_args_param |
|
| 539 | - */ |
|
| 540 | - public static function get_paid_courses_meta_query_args(){ |
|
| 541 | - |
|
| 542 | - $paid_product_ids = self::get_paid_product_ids(); |
|
| 543 | - |
|
| 544 | - return array( |
|
| 545 | - array( |
|
| 546 | - 'key' => '_course_woocommerce_product', |
|
| 547 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 548 | - // query |
|
| 549 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 550 | - 'compare' => 'IN', |
|
| 551 | - ), |
|
| 552 | - ); |
|
| 553 | - |
|
| 554 | - }// get_free_courses_meta_query |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * The WordPress Query args |
|
| 558 | - * for paid products on sale |
|
| 559 | - * |
|
| 560 | - * @since 1.9.0 |
|
| 561 | - * @return array $product_query_args |
|
| 562 | - */ |
|
| 563 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 564 | - |
|
| 565 | - $args = array( |
|
| 566 | - 'post_type' => 'product', |
|
| 567 | - 'posts_per_page' => 1000, |
|
| 568 | - 'orderby' => 'date', |
|
| 569 | - 'order' => 'DESC', |
|
| 570 | - 'suppress_filters' => 0 |
|
| 571 | - ); |
|
| 572 | - |
|
| 573 | - $args[ 'fields' ] = 'ids'; |
|
| 574 | - |
|
| 575 | - $args[ 'meta_query' ] = array( |
|
| 576 | - 'relation' => 'AND', |
|
| 577 | - array( |
|
| 578 | - 'key'=> '_regular_price', |
|
| 579 | - 'compare' => '>', |
|
| 580 | - 'value' => 0, |
|
| 581 | - ), |
|
| 582 | - array( |
|
| 583 | - 'key'=> '_sale_price', |
|
| 584 | - 'compare' => '>', |
|
| 585 | - 'value' => 0, |
|
| 586 | - ), |
|
| 587 | - ); |
|
| 588 | - |
|
| 589 | - return $args; |
|
| 590 | - |
|
| 591 | - } // get_paid_products_on_sale_query_args |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Return the WordPress query args for |
|
| 596 | - * products not on sale but that is not a free |
|
| 597 | - * |
|
| 598 | - * @since 1.9.0 |
|
| 599 | - * |
|
| 600 | - * @return array |
|
| 601 | - */ |
|
| 602 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 603 | - |
|
| 604 | - $args = array( |
|
| 605 | - 'post_type' => 'product', |
|
| 606 | - 'posts_per_page' => 1000, |
|
| 607 | - 'orderby' => 'date', |
|
| 608 | - 'order' => 'DESC', |
|
| 609 | - 'suppress_filters' => 0 |
|
| 610 | - ); |
|
| 611 | - |
|
| 612 | - $args[ 'fields' ] = 'ids'; |
|
| 613 | - $args[ 'meta_query' ] = array( |
|
| 614 | - 'relation' => 'AND', |
|
| 615 | - array( |
|
| 616 | - 'key'=> '_regular_price', |
|
| 617 | - 'compare' => '>', |
|
| 618 | - 'value' => 0, |
|
| 619 | - ), |
|
| 620 | - array( |
|
| 621 | - 'key'=> '_sale_price', |
|
| 622 | - 'compare' => '=', |
|
| 623 | - 'value' => '', |
|
| 624 | - ), |
|
| 625 | - ); |
|
| 626 | - |
|
| 627 | - return $args; |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - } // get_paid_courses_meta_query |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Get all WooCommerce non-free product id's |
|
| 634 | - * |
|
| 635 | - * @since 1.9.0 |
|
| 636 | - * |
|
| 637 | - * @return array $woocommerce_paid_product_ids |
|
| 638 | - */ |
|
| 639 | - public static function get_paid_product_ids(){ |
|
| 640 | - |
|
| 641 | - // get all the paid WooCommerce products that has regular |
|
| 642 | - // and sale price greater than 0 |
|
| 643 | - // will be used later to check for course with the id as meta |
|
| 644 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 645 | - |
|
| 646 | - // get all the paid WooCommerce products that has regular price |
|
| 647 | - // greater than 0 without a sale price |
|
| 648 | - // will be used later to check for course with the id as meta |
|
| 649 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 650 | - |
|
| 651 | - // combine products ID's with regular and sale price grater than zero and those without |
|
| 652 | - // sale but regular price greater than zero |
|
| 653 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 654 | - |
|
| 655 | - // if |
|
| 656 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 657 | - return array( ); |
|
| 658 | - } |
|
| 659 | - return $woocommerce_paid_product_ids; |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Get all free courses. |
|
| 665 | - * |
|
| 666 | - * This course that have a WC product attached |
|
| 667 | - * that has a price or sale price of zero and |
|
| 668 | - * other courses with no WooCommerce products |
|
| 669 | - * attached. |
|
| 670 | - * |
|
| 671 | - * @since 1.9.0 |
|
| 672 | - * |
|
| 673 | - * @param array $args |
|
| 674 | - * @return array |
|
| 675 | - */ |
|
| 676 | - public static function get_free_courses( $args = array() ){ |
|
| 677 | - |
|
| 678 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 679 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 680 | - |
|
| 681 | - if( !empty( $args ) ){ |
|
| 682 | - wp_parse_args( $args, $free_course_query_args ); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - // don't show any paid courses |
|
| 686 | - $courses = self::get_paid_courses(); |
|
| 687 | - $ids = array(); |
|
| 688 | - foreach( $courses as $course ){ |
|
| 689 | - $ids[] = $course->ID; |
|
| 690 | - } |
|
| 691 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 692 | - |
|
| 693 | - return get_posts( $free_course_query_args ); |
|
| 694 | - |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Return all products that are not free |
|
| 699 | - * |
|
| 700 | - * @since 1.9.0 |
|
| 701 | - * @param array $args override default arg values |
|
| 702 | - * |
|
| 703 | - * @return array |
|
| 704 | - */ |
|
| 705 | - public static function get_paid_courses( $args = array() ){ |
|
| 706 | - |
|
| 707 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 708 | - |
|
| 709 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 710 | - |
|
| 711 | - if( !empty( $args ) ){ |
|
| 712 | - wp_parse_args( $args, $paid_course_query_args ); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - return get_posts( $paid_course_query_args ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Show the WooCommerce add to cart button for the current course |
|
| 720 | - * |
|
| 721 | - * The function will only show the button if |
|
| 722 | - * 1- the user can buy the course |
|
| 723 | - * 2- if they have completed their pre-requisite |
|
| 724 | - * 3- if the course has a valid product attached |
|
| 725 | - * |
|
| 726 | - * @since 1.9.0 |
|
| 727 | - * @param int $course_id |
|
| 728 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 729 | - */ |
|
| 730 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 731 | - |
|
| 732 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id ) || self::is_course_in_cart( $course_id ) ) { |
|
| 733 | - return ''; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 737 | - |
|
| 738 | - // Check if customer purchased the product |
|
| 739 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 740 | - || empty( $wc_post_id ) ) { |
|
| 741 | - |
|
| 742 | - return ''; |
|
| 743 | - |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 747 | - // Get the product |
|
| 748 | - $product = self::get_product_object( $wc_post_id ); |
|
| 749 | - |
|
| 750 | - // do not show the button for invalid products, non purchasable products, out |
|
| 751 | - // of stock product or if course is already in cart |
|
| 752 | - if ( ! isset ( $product ) |
|
| 753 | - || ! is_object( $product ) |
|
| 754 | - || ! $product->is_purchasable() |
|
| 755 | - || ! $product->is_in_stock() |
|
| 756 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 757 | - |
|
| 758 | - return ''; |
|
| 759 | - |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - // |
|
| 763 | - // button output: |
|
| 764 | - // |
|
| 765 | - ?> |
|
| 532 | + }// get_free_courses_meta_query |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * The metat query for courses that are free |
|
| 536 | + * |
|
| 537 | + * @since 1.9.0 |
|
| 538 | + * @return array $wp_query_meta_query_args_param |
|
| 539 | + */ |
|
| 540 | + public static function get_paid_courses_meta_query_args(){ |
|
| 541 | + |
|
| 542 | + $paid_product_ids = self::get_paid_product_ids(); |
|
| 543 | + |
|
| 544 | + return array( |
|
| 545 | + array( |
|
| 546 | + 'key' => '_course_woocommerce_product', |
|
| 547 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 548 | + // query |
|
| 549 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 550 | + 'compare' => 'IN', |
|
| 551 | + ), |
|
| 552 | + ); |
|
| 553 | + |
|
| 554 | + }// get_free_courses_meta_query |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * The WordPress Query args |
|
| 558 | + * for paid products on sale |
|
| 559 | + * |
|
| 560 | + * @since 1.9.0 |
|
| 561 | + * @return array $product_query_args |
|
| 562 | + */ |
|
| 563 | + public static function get_paid_products_on_sale_query_args(){ |
|
| 564 | + |
|
| 565 | + $args = array( |
|
| 566 | + 'post_type' => 'product', |
|
| 567 | + 'posts_per_page' => 1000, |
|
| 568 | + 'orderby' => 'date', |
|
| 569 | + 'order' => 'DESC', |
|
| 570 | + 'suppress_filters' => 0 |
|
| 571 | + ); |
|
| 572 | + |
|
| 573 | + $args[ 'fields' ] = 'ids'; |
|
| 574 | + |
|
| 575 | + $args[ 'meta_query' ] = array( |
|
| 576 | + 'relation' => 'AND', |
|
| 577 | + array( |
|
| 578 | + 'key'=> '_regular_price', |
|
| 579 | + 'compare' => '>', |
|
| 580 | + 'value' => 0, |
|
| 581 | + ), |
|
| 582 | + array( |
|
| 583 | + 'key'=> '_sale_price', |
|
| 584 | + 'compare' => '>', |
|
| 585 | + 'value' => 0, |
|
| 586 | + ), |
|
| 587 | + ); |
|
| 588 | + |
|
| 589 | + return $args; |
|
| 590 | + |
|
| 591 | + } // get_paid_products_on_sale_query_args |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Return the WordPress query args for |
|
| 596 | + * products not on sale but that is not a free |
|
| 597 | + * |
|
| 598 | + * @since 1.9.0 |
|
| 599 | + * |
|
| 600 | + * @return array |
|
| 601 | + */ |
|
| 602 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
| 603 | + |
|
| 604 | + $args = array( |
|
| 605 | + 'post_type' => 'product', |
|
| 606 | + 'posts_per_page' => 1000, |
|
| 607 | + 'orderby' => 'date', |
|
| 608 | + 'order' => 'DESC', |
|
| 609 | + 'suppress_filters' => 0 |
|
| 610 | + ); |
|
| 611 | + |
|
| 612 | + $args[ 'fields' ] = 'ids'; |
|
| 613 | + $args[ 'meta_query' ] = array( |
|
| 614 | + 'relation' => 'AND', |
|
| 615 | + array( |
|
| 616 | + 'key'=> '_regular_price', |
|
| 617 | + 'compare' => '>', |
|
| 618 | + 'value' => 0, |
|
| 619 | + ), |
|
| 620 | + array( |
|
| 621 | + 'key'=> '_sale_price', |
|
| 622 | + 'compare' => '=', |
|
| 623 | + 'value' => '', |
|
| 624 | + ), |
|
| 625 | + ); |
|
| 626 | + |
|
| 627 | + return $args; |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + } // get_paid_courses_meta_query |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Get all WooCommerce non-free product id's |
|
| 634 | + * |
|
| 635 | + * @since 1.9.0 |
|
| 636 | + * |
|
| 637 | + * @return array $woocommerce_paid_product_ids |
|
| 638 | + */ |
|
| 639 | + public static function get_paid_product_ids(){ |
|
| 640 | + |
|
| 641 | + // get all the paid WooCommerce products that has regular |
|
| 642 | + // and sale price greater than 0 |
|
| 643 | + // will be used later to check for course with the id as meta |
|
| 644 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 645 | + |
|
| 646 | + // get all the paid WooCommerce products that has regular price |
|
| 647 | + // greater than 0 without a sale price |
|
| 648 | + // will be used later to check for course with the id as meta |
|
| 649 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 650 | + |
|
| 651 | + // combine products ID's with regular and sale price grater than zero and those without |
|
| 652 | + // sale but regular price greater than zero |
|
| 653 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 654 | + |
|
| 655 | + // if |
|
| 656 | + if( empty($woocommerce_paid_product_ids) ){ |
|
| 657 | + return array( ); |
|
| 658 | + } |
|
| 659 | + return $woocommerce_paid_product_ids; |
|
| 660 | + |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Get all free courses. |
|
| 665 | + * |
|
| 666 | + * This course that have a WC product attached |
|
| 667 | + * that has a price or sale price of zero and |
|
| 668 | + * other courses with no WooCommerce products |
|
| 669 | + * attached. |
|
| 670 | + * |
|
| 671 | + * @since 1.9.0 |
|
| 672 | + * |
|
| 673 | + * @param array $args |
|
| 674 | + * @return array |
|
| 675 | + */ |
|
| 676 | + public static function get_free_courses( $args = array() ){ |
|
| 677 | + |
|
| 678 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 679 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 680 | + |
|
| 681 | + if( !empty( $args ) ){ |
|
| 682 | + wp_parse_args( $args, $free_course_query_args ); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + // don't show any paid courses |
|
| 686 | + $courses = self::get_paid_courses(); |
|
| 687 | + $ids = array(); |
|
| 688 | + foreach( $courses as $course ){ |
|
| 689 | + $ids[] = $course->ID; |
|
| 690 | + } |
|
| 691 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 692 | + |
|
| 693 | + return get_posts( $free_course_query_args ); |
|
| 694 | + |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Return all products that are not free |
|
| 699 | + * |
|
| 700 | + * @since 1.9.0 |
|
| 701 | + * @param array $args override default arg values |
|
| 702 | + * |
|
| 703 | + * @return array |
|
| 704 | + */ |
|
| 705 | + public static function get_paid_courses( $args = array() ){ |
|
| 706 | + |
|
| 707 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 708 | + |
|
| 709 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 710 | + |
|
| 711 | + if( !empty( $args ) ){ |
|
| 712 | + wp_parse_args( $args, $paid_course_query_args ); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + return get_posts( $paid_course_query_args ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Show the WooCommerce add to cart button for the current course |
|
| 720 | + * |
|
| 721 | + * The function will only show the button if |
|
| 722 | + * 1- the user can buy the course |
|
| 723 | + * 2- if they have completed their pre-requisite |
|
| 724 | + * 3- if the course has a valid product attached |
|
| 725 | + * |
|
| 726 | + * @since 1.9.0 |
|
| 727 | + * @param int $course_id |
|
| 728 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 729 | + */ |
|
| 730 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
| 731 | + |
|
| 732 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id ) || self::is_course_in_cart( $course_id ) ) { |
|
| 733 | + return ''; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 737 | + |
|
| 738 | + // Check if customer purchased the product |
|
| 739 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 740 | + || empty( $wc_post_id ) ) { |
|
| 741 | + |
|
| 742 | + return ''; |
|
| 743 | + |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 747 | + // Get the product |
|
| 748 | + $product = self::get_product_object( $wc_post_id ); |
|
| 749 | + |
|
| 750 | + // do not show the button for invalid products, non purchasable products, out |
|
| 751 | + // of stock product or if course is already in cart |
|
| 752 | + if ( ! isset ( $product ) |
|
| 753 | + || ! is_object( $product ) |
|
| 754 | + || ! $product->is_purchasable() |
|
| 755 | + || ! $product->is_in_stock() |
|
| 756 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 757 | + |
|
| 758 | + return ''; |
|
| 759 | + |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + // |
|
| 763 | + // button output: |
|
| 764 | + // |
|
| 765 | + ?> |
|
| 766 | 766 | |
| 767 | 767 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
| 768 | 768 | class="cart" |
@@ -791,83 +791,83 @@ discard block |
||
| 791 | 791 | <button type="submit" class="single_add_to_cart_button button alt"> |
| 792 | 792 | <?php $button_text = $product->get_price_html() . ' - ' . __( 'Purchase this Course', 'woothemes-sensei' ); ?> |
| 793 | 793 | <?php |
| 794 | - /** |
|
| 795 | - * Filter Add to Cart button text |
|
| 796 | - * |
|
| 797 | - * @since 1.9.1 |
|
| 798 | - * |
|
| 799 | - * @param string $button_text |
|
| 800 | - */ |
|
| 801 | - echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text ); |
|
| 802 | - ?> |
|
| 794 | + /** |
|
| 795 | + * Filter Add to Cart button text |
|
| 796 | + * |
|
| 797 | + * @since 1.9.1 |
|
| 798 | + * |
|
| 799 | + * @param string $button_text |
|
| 800 | + */ |
|
| 801 | + echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text ); |
|
| 802 | + ?> |
|
| 803 | 803 | </button> |
| 804 | 804 | |
| 805 | 805 | </form> |
| 806 | 806 | |
| 807 | 807 | <?php |
| 808 | - } // end the_add_to_cart_button_html |
|
| 808 | + } // end the_add_to_cart_button_html |
|
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * Alter the no permissions message on the single course page |
|
| 812 | - * Changes the message to a WooCommerce specific message. |
|
| 813 | - * |
|
| 814 | - * @since 1.9.0 |
|
| 815 | - * |
|
| 816 | - * @param $message |
|
| 817 | - * @param $post_id |
|
| 818 | - * |
|
| 819 | - * @return string $message |
|
| 820 | - */ |
|
| 821 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 810 | + /** |
|
| 811 | + * Alter the no permissions message on the single course page |
|
| 812 | + * Changes the message to a WooCommerce specific message. |
|
| 813 | + * |
|
| 814 | + * @since 1.9.0 |
|
| 815 | + * |
|
| 816 | + * @param $message |
|
| 817 | + * @param $post_id |
|
| 818 | + * |
|
| 819 | + * @return string $message |
|
| 820 | + */ |
|
| 821 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 822 | 822 | |
| 823 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 824 | - return $message; |
|
| 825 | - } |
|
| 823 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 824 | + return $message; |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 827 | + $product_id = self::get_course_product_id( $post_id ); |
|
| 828 | 828 | |
| 829 | - if( ! $product_id |
|
| 830 | - || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 829 | + if( ! $product_id |
|
| 830 | + || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 831 | 831 | |
| 832 | - return $message; |
|
| 832 | + return $message; |
|
| 833 | 833 | |
| 834 | - } |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - ob_start(); |
|
| 837 | - self::the_course_no_permissions_message( $post_id ); |
|
| 838 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 836 | + ob_start(); |
|
| 837 | + self::the_course_no_permissions_message( $post_id ); |
|
| 838 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 839 | 839 | |
| 840 | - return $woocommerce_course_no_permissions_message ; |
|
| 840 | + return $woocommerce_course_no_permissions_message ; |
|
| 841 | 841 | |
| 842 | - } |
|
| 843 | - /** |
|
| 844 | - * Show the no permissions message when a user is logged in |
|
| 845 | - * and have not yet purchased the current course |
|
| 846 | - * |
|
| 847 | - * @since 1.9.0 |
|
| 848 | - */ |
|
| 849 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 842 | + } |
|
| 843 | + /** |
|
| 844 | + * Show the no permissions message when a user is logged in |
|
| 845 | + * and have not yet purchased the current course |
|
| 846 | + * |
|
| 847 | + * @since 1.9.0 |
|
| 848 | + */ |
|
| 849 | + public static function the_course_no_permissions_message( $course_id ){ |
|
| 850 | 850 | |
| 851 | - // login link |
|
| 852 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 853 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 854 | - $wc_product_id = self::get_course_product_id( $course_id ); |
|
| 851 | + // login link |
|
| 852 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 853 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 854 | + $wc_product_id = self::get_course_product_id( $course_id ); |
|
| 855 | 855 | |
| 856 | - if ( self::is_product_in_cart( $wc_product_id ) ) { |
|
| 856 | + if ( self::is_product_in_cart( $wc_product_id ) ) { |
|
| 857 | 857 | |
| 858 | - $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>'; |
|
| 858 | + $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>'; |
|
| 859 | 859 | |
| 860 | - $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link ); |
|
| 861 | - ?> |
|
| 860 | + $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link ); |
|
| 861 | + ?> |
|
| 862 | 862 | <span class="add-to-cart-login"> |
| 863 | 863 | <?php echo $message; ?> |
| 864 | 864 | </span> |
| 865 | 865 | |
| 866 | 866 | <?php |
| 867 | 867 | |
| 868 | - } elseif ( is_user_logged_in() ) { |
|
| 868 | + } elseif ( is_user_logged_in() ) { |
|
| 869 | 869 | |
| 870 | - ?> |
|
| 870 | + ?> |
|
| 871 | 871 | <style> |
| 872 | 872 | .sensei-message.alert { |
| 873 | 873 | display: none; |
@@ -876,345 +876,345 @@ discard block |
||
| 876 | 876 | |
| 877 | 877 | <?php |
| 878 | 878 | |
| 879 | - } else { |
|
| 880 | - $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); |
|
| 881 | - ?> |
|
| 879 | + } else { |
|
| 880 | + $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); |
|
| 881 | + ?> |
|
| 882 | 882 | <span class="add-to-cart-login"> |
| 883 | 883 | <?php echo $message; ?> |
| 884 | 884 | </span> |
| 885 | 885 | |
| 886 | 886 | <?php |
| 887 | - } |
|
| 888 | - } |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - /** |
|
| 891 | - * Checks if a user has bought a product item. |
|
| 892 | - * |
|
| 893 | - * @since 1.9.0 |
|
| 894 | - * |
|
| 895 | - * @param int $user_id |
|
| 896 | - * @param int $product_id |
|
| 897 | - * |
|
| 898 | - * @return bool |
|
| 899 | - */ |
|
| 900 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 901 | - |
|
| 902 | - $orders = self::get_user_product_orders( $user_id, $product_id ); |
|
| 903 | - |
|
| 904 | - foreach ( $orders as $order_id ) { |
|
| 905 | - |
|
| 906 | - $order = new WC_Order( $order_id->ID ); |
|
| 907 | - |
|
| 908 | - // wc-active is the subscriptions complete status |
|
| 909 | - if ( ! in_array( $order->post_status, array( 'wc-processing', 'wc-completed' ) ) |
|
| 910 | - || ! ( 0 < sizeof( $order->get_items() ) ) ){ |
|
| 911 | - |
|
| 912 | - continue; |
|
| 890 | + /** |
|
| 891 | + * Checks if a user has bought a product item. |
|
| 892 | + * |
|
| 893 | + * @since 1.9.0 |
|
| 894 | + * |
|
| 895 | + * @param int $user_id |
|
| 896 | + * @param int $product_id |
|
| 897 | + * |
|
| 898 | + * @return bool |
|
| 899 | + */ |
|
| 900 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 913 | 901 | |
| 914 | - } |
|
| 902 | + $orders = self::get_user_product_orders( $user_id, $product_id ); |
|
| 915 | 903 | |
| 916 | - foreach( $order->get_items() as $item ) { |
|
| 904 | + foreach ( $orders as $order_id ) { |
|
| 917 | 905 | |
| 918 | - // Check if user has bought product |
|
| 919 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 906 | + $order = new WC_Order( $order_id->ID ); |
|
| 920 | 907 | |
| 921 | - // Check if user has an active subscription for product |
|
| 922 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 923 | - $sub_key = wcs_get_subscription( $order ); |
|
| 924 | - if( $sub_key ) { |
|
| 925 | - $sub = wcs_get_subscription( $sub_key ); |
|
| 926 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 927 | - if( 'active' == $sub['status'] ) { |
|
| 928 | - return true; |
|
| 929 | - } else { |
|
| 930 | - return false; |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } |
|
| 908 | + // wc-active is the subscriptions complete status |
|
| 909 | + if ( ! in_array( $order->post_status, array( 'wc-processing', 'wc-completed' ) ) |
|
| 910 | + || ! ( 0 < sizeof( $order->get_items() ) ) ){ |
|
| 935 | 911 | |
| 936 | - // Customer has bought product |
|
| 937 | - return true; |
|
| 938 | - } // End If Statement |
|
| 912 | + continue; |
|
| 939 | 913 | |
| 940 | - } // End For each item |
|
| 914 | + } |
|
| 941 | 915 | |
| 942 | - } // End For each order |
|
| 916 | + foreach( $order->get_items() as $item ) { |
|
| 943 | 917 | |
| 944 | - // default is no order |
|
| 945 | - return false; |
|
| 918 | + // Check if user has bought product |
|
| 919 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 946 | 920 | |
| 947 | - } // end has customer bought product |
|
| 921 | + // Check if user has an active subscription for product |
|
| 922 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 923 | + $sub_key = wcs_get_subscription( $order ); |
|
| 924 | + if( $sub_key ) { |
|
| 925 | + $sub = wcs_get_subscription( $sub_key ); |
|
| 926 | + if( $sub && isset( $sub['status'] ) ) { |
|
| 927 | + if( 'active' == $sub['status'] ) { |
|
| 928 | + return true; |
|
| 929 | + } else { |
|
| 930 | + return false; |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } |
|
| 948 | 935 | |
| 949 | - /** |
|
| 950 | - * Return the product id for the given course |
|
| 951 | - * |
|
| 952 | - * @since 1.9.0 |
|
| 953 | - * |
|
| 954 | - * @param int $course_id |
|
| 955 | - * |
|
| 956 | - * @return string $woocommerce_product_id or false if none exist |
|
| 957 | - * |
|
| 958 | - */ |
|
| 959 | - public static function get_course_product_id( $course_id ){ |
|
| 936 | + // Customer has bought product |
|
| 937 | + return true; |
|
| 938 | + } // End If Statement |
|
| 960 | 939 | |
| 961 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 940 | + } // End For each item |
|
| 962 | 941 | |
| 963 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 964 | - return false; |
|
| 965 | - } |
|
| 942 | + } // End For each order |
|
| 966 | 943 | |
| 967 | - return $product_id; |
|
| 944 | + // default is no order |
|
| 945 | + return false; |
|
| 968 | 946 | |
| 969 | - } |
|
| 947 | + } // end has customer bought product |
|
| 970 | 948 | |
| 971 | - /** |
|
| 972 | - * Alter the body classes adding WooCommerce to the body |
|
| 973 | - * |
|
| 974 | - * Speciall cases where this is needed is template no-permissions.php |
|
| 975 | - * |
|
| 976 | - * @param array $classes |
|
| 977 | - * @return array |
|
| 978 | - */ |
|
| 979 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 949 | + /** |
|
| 950 | + * Return the product id for the given course |
|
| 951 | + * |
|
| 952 | + * @since 1.9.0 |
|
| 953 | + * |
|
| 954 | + * @param int $course_id |
|
| 955 | + * |
|
| 956 | + * @return string $woocommerce_product_id or false if none exist |
|
| 957 | + * |
|
| 958 | + */ |
|
| 959 | + public static function get_course_product_id( $course_id ){ |
|
| 980 | 960 | |
| 981 | - if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){ |
|
| 961 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 982 | 962 | |
| 983 | - $classes[] ='woocommerce'; |
|
| 963 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 964 | + return false; |
|
| 965 | + } |
|
| 984 | 966 | |
| 985 | - } |
|
| 967 | + return $product_id; |
|
| 986 | 968 | |
| 987 | - return $classes; |
|
| 969 | + } |
|
| 988 | 970 | |
| 989 | - } |
|
| 971 | + /** |
|
| 972 | + * Alter the body classes adding WooCommerce to the body |
|
| 973 | + * |
|
| 974 | + * Speciall cases where this is needed is template no-permissions.php |
|
| 975 | + * |
|
| 976 | + * @param array $classes |
|
| 977 | + * @return array |
|
| 978 | + */ |
|
| 979 | + public static function add_woocommerce_body_class( $classes ){ |
|
| 990 | 980 | |
| 991 | - /** |
|
| 992 | - * Responds to when a subscription product is purchased |
|
| 993 | - * |
|
| 994 | - * @since 1.2.0 |
|
| 995 | - * @since 1.9.0 move to class Sensei_WC |
|
| 996 | - * |
|
| 997 | - * @param WC_Order $order |
|
| 998 | - * |
|
| 999 | - * @return void |
|
| 1000 | - */ |
|
| 1001 | - public static function activate_subscription( $order ) { |
|
| 981 | + if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){ |
|
| 1002 | 982 | |
| 1003 | - $order_user = get_user_by('id', $order->user_id); |
|
| 1004 | - $user['ID'] = $order_user->ID; |
|
| 1005 | - $user['user_login'] = $order_user->user_login; |
|
| 1006 | - $user['user_email'] = $order_user->user_email; |
|
| 1007 | - $user['user_url'] = $order_user->user_url; |
|
| 983 | + $classes[] ='woocommerce'; |
|
| 1008 | 984 | |
| 1009 | - // Run through each product ordered |
|
| 1010 | - if ( ! sizeof($order->get_items() )>0 ) { |
|
| 985 | + } |
|
| 1011 | 986 | |
| 1012 | - return; |
|
| 987 | + return $classes; |
|
| 1013 | 988 | |
| 1014 | - } |
|
| 989 | + } |
|
| 1015 | 990 | |
| 1016 | - foreach($order->get_items() as $item) { |
|
| 991 | + /** |
|
| 992 | + * Responds to when a subscription product is purchased |
|
| 993 | + * |
|
| 994 | + * @since 1.2.0 |
|
| 995 | + * @since 1.9.0 move to class Sensei_WC |
|
| 996 | + * |
|
| 997 | + * @param WC_Order $order |
|
| 998 | + * |
|
| 999 | + * @return void |
|
| 1000 | + */ |
|
| 1001 | + public static function activate_subscription( $order ) { |
|
| 1017 | 1002 | |
| 1018 | - $product_type = ''; |
|
| 1003 | + $order_user = get_user_by('id', $order->user_id); |
|
| 1004 | + $user['ID'] = $order_user->ID; |
|
| 1005 | + $user['user_login'] = $order_user->user_login; |
|
| 1006 | + $user['user_email'] = $order_user->user_email; |
|
| 1007 | + $user['user_url'] = $order_user->user_url; |
|
| 1019 | 1008 | |
| 1020 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1009 | + // Run through each product ordered |
|
| 1010 | + if ( ! sizeof($order->get_items() )>0 ) { |
|
| 1021 | 1011 | |
| 1022 | - $item_id = $item['variation_id']; |
|
| 1023 | - $product_type = 'subscription_variation'; |
|
| 1012 | + return; |
|
| 1024 | 1013 | |
| 1025 | - } else { |
|
| 1014 | + } |
|
| 1026 | 1015 | |
| 1027 | - $item_id = $item['product_id']; |
|
| 1016 | + foreach($order->get_items() as $item) { |
|
| 1028 | 1017 | |
| 1029 | - } // End If Statement |
|
| 1018 | + $product_type = ''; |
|
| 1030 | 1019 | |
| 1031 | - $_product = self::get_product_object( $item_id, $product_type ); |
|
| 1020 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1032 | 1021 | |
| 1033 | - // Get courses that use the WC product |
|
| 1034 | - $courses = array(); |
|
| 1022 | + $item_id = $item['variation_id']; |
|
| 1023 | + $product_type = 'subscription_variation'; |
|
| 1035 | 1024 | |
| 1036 | - if ( ! in_array( $product_type, self::get_subscription_types() ) ) { |
|
| 1025 | + } else { |
|
| 1037 | 1026 | |
| 1038 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
| 1027 | + $item_id = $item['product_id']; |
|
| 1039 | 1028 | |
| 1040 | - } // End If Statement |
|
| 1029 | + } // End If Statement |
|
| 1041 | 1030 | |
| 1042 | - // Loop and add the user to the course. |
|
| 1043 | - foreach ( $courses as $course_item ){ |
|
| 1031 | + $_product = self::get_product_object( $item_id, $product_type ); |
|
| 1044 | 1032 | |
| 1045 | - Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID ); |
|
| 1033 | + // Get courses that use the WC product |
|
| 1034 | + $courses = array(); |
|
| 1046 | 1035 | |
| 1047 | - } // End For Loop |
|
| 1036 | + if ( ! in_array( $product_type, self::get_subscription_types() ) ) { |
|
| 1048 | 1037 | |
| 1049 | - } // End For Loop |
|
| 1038 | + $courses = Sensei()->course->get_product_courses( $item_id ); |
|
| 1050 | 1039 | |
| 1051 | - } // End activate_subscription() |
|
| 1040 | + } // End If Statement |
|
| 1052 | 1041 | |
| 1053 | - /** |
|
| 1054 | - * Adds detail to to the WooCommerce order |
|
| 1055 | - * |
|
| 1056 | - * @since 1.4.5 |
|
| 1057 | - * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details |
|
| 1058 | - * |
|
| 1059 | - * @param WC_Order $order |
|
| 1060 | - * |
|
| 1061 | - * @return void |
|
| 1062 | - */ |
|
| 1063 | - public static function email_course_details( $order ){ |
|
| 1042 | + // Loop and add the user to the course. |
|
| 1043 | + foreach ( $courses as $course_item ){ |
|
| 1064 | 1044 | |
| 1065 | - global $woocommerce; |
|
| 1045 | + Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID ); |
|
| 1066 | 1046 | |
| 1067 | - // exit early if not wc-completed or wc-processing |
|
| 1068 | - if( 'wc-completed' != $order->post_status |
|
| 1069 | - && 'wc-processing' != $order->post_status ) { |
|
| 1070 | - return; |
|
| 1071 | - } |
|
| 1047 | + } // End For Loop |
|
| 1072 | 1048 | |
| 1073 | - $order_items = $order->get_items(); |
|
| 1074 | - $order_id = $order->id; |
|
| 1049 | + } // End For Loop |
|
| 1075 | 1050 | |
| 1076 | - //If object have items go through them all to find course |
|
| 1077 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1051 | + } // End activate_subscription() |
|
| 1078 | 1052 | |
| 1079 | - $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1080 | - $order_contains_courses = false; |
|
| 1053 | + /** |
|
| 1054 | + * Adds detail to to the WooCommerce order |
|
| 1055 | + * |
|
| 1056 | + * @since 1.4.5 |
|
| 1057 | + * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details |
|
| 1058 | + * |
|
| 1059 | + * @param WC_Order $order |
|
| 1060 | + * |
|
| 1061 | + * @return void |
|
| 1062 | + */ |
|
| 1063 | + public static function email_course_details( $order ){ |
|
| 1081 | 1064 | |
| 1065 | + global $woocommerce; |
|
| 1082 | 1066 | |
| 1083 | - foreach ( $order_items as $item ) { |
|
| 1067 | + // exit early if not wc-completed or wc-processing |
|
| 1068 | + if( 'wc-completed' != $order->post_status |
|
| 1069 | + && 'wc-processing' != $order->post_status ) { |
|
| 1070 | + return; |
|
| 1071 | + } |
|
| 1084 | 1072 | |
| 1085 | - $product_type = ''; |
|
| 1086 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1087 | - // If item has variation_id then its from variation |
|
| 1088 | - $item_id = $item['variation_id']; |
|
| 1089 | - $product_type = 'variation'; |
|
| 1090 | - } else { |
|
| 1091 | - // If not its real product set its id to item_id |
|
| 1092 | - $item_id = $item['product_id']; |
|
| 1093 | - } // End If Statement |
|
| 1073 | + $order_items = $order->get_items(); |
|
| 1074 | + $order_id = $order->id; |
|
| 1094 | 1075 | |
| 1095 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1076 | + //If object have items go through them all to find course |
|
| 1077 | + if ( 0 < sizeof( $order_items ) ) { |
|
| 1096 | 1078 | |
| 1097 | - if( $user_id ) { |
|
| 1079 | + $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1080 | + $order_contains_courses = false; |
|
| 1098 | 1081 | |
| 1099 | - // Get all courses for product |
|
| 1100 | - $args = array( |
|
| 1101 | - 'posts_per_page' => -1, |
|
| 1102 | - 'post_type' => 'course', |
|
| 1103 | - 'meta_query' => array( |
|
| 1104 | - array( |
|
| 1105 | - 'key' => '_course_woocommerce_product', |
|
| 1106 | - 'value' => $item_id |
|
| 1107 | - ) |
|
| 1108 | - ), |
|
| 1109 | - 'orderby' => 'menu_order date', |
|
| 1110 | - 'order' => 'ASC', |
|
| 1111 | - ); |
|
| 1112 | - $courses = get_posts( $args ); |
|
| 1113 | 1082 | |
| 1114 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1083 | + foreach ( $order_items as $item ) { |
|
| 1115 | 1084 | |
| 1116 | - foreach( $courses as $course ) { |
|
| 1085 | + $product_type = ''; |
|
| 1086 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1087 | + // If item has variation_id then its from variation |
|
| 1088 | + $item_id = $item['variation_id']; |
|
| 1089 | + $product_type = 'variation'; |
|
| 1090 | + } else { |
|
| 1091 | + // If not its real product set its id to item_id |
|
| 1092 | + $item_id = $item['product_id']; |
|
| 1093 | + } // End If Statement |
|
| 1117 | 1094 | |
| 1118 | - $title = $course->post_title; |
|
| 1119 | - $permalink = get_permalink( $course->ID ); |
|
| 1120 | - $order_contains_courses = true; |
|
| 1121 | - $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1122 | - } |
|
| 1095 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1123 | 1096 | |
| 1097 | + if( $user_id ) { |
|
| 1124 | 1098 | |
| 1125 | - } // end if has courses |
|
| 1099 | + // Get all courses for product |
|
| 1100 | + $args = array( |
|
| 1101 | + 'posts_per_page' => -1, |
|
| 1102 | + 'post_type' => 'course', |
|
| 1103 | + 'meta_query' => array( |
|
| 1104 | + array( |
|
| 1105 | + 'key' => '_course_woocommerce_product', |
|
| 1106 | + 'value' => $item_id |
|
| 1107 | + ) |
|
| 1108 | + ), |
|
| 1109 | + 'orderby' => 'menu_order date', |
|
| 1110 | + 'order' => 'ASC', |
|
| 1111 | + ); |
|
| 1112 | + $courses = get_posts( $args ); |
|
| 1126 | 1113 | |
| 1127 | - } // end if $userPid |
|
| 1114 | + if( $courses && count( $courses ) > 0 ) { |
|
| 1128 | 1115 | |
| 1129 | - } // end for each order item |
|
| 1116 | + foreach( $courses as $course ) { |
|
| 1130 | 1117 | |
| 1131 | - // Output Course details |
|
| 1132 | - if( $order_contains_courses ){ |
|
| 1118 | + $title = $course->post_title; |
|
| 1119 | + $permalink = get_permalink( $course->ID ); |
|
| 1120 | + $order_contains_courses = true; |
|
| 1121 | + $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1122 | + } |
|
| 1133 | 1123 | |
| 1134 | - echo $course_details_html; |
|
| 1135 | 1124 | |
| 1136 | - } |
|
| 1125 | + } // end if has courses |
|
| 1137 | 1126 | |
| 1127 | + } // end if $userPid |
|
| 1138 | 1128 | |
| 1139 | - } // end if order items not empty |
|
| 1129 | + } // end for each order item |
|
| 1140 | 1130 | |
| 1141 | - }// end email_course_details |
|
| 1131 | + // Output Course details |
|
| 1132 | + if( $order_contains_courses ){ |
|
| 1142 | 1133 | |
| 1143 | - /** |
|
| 1144 | - * sensei_woocommerce_complete_order description |
|
| 1145 | - * @since 1.0.3 |
|
| 1146 | - * @access public |
|
| 1147 | - * @param int $order_id WC order ID |
|
| 1148 | - * @return void |
|
| 1149 | - */ |
|
| 1150 | - public static function complete_order ( $order_id = 0 ) { |
|
| 1134 | + echo $course_details_html; |
|
| 1151 | 1135 | |
| 1152 | - $order_user = array(); |
|
| 1136 | + } |
|
| 1153 | 1137 | |
| 1154 | - // Check for WooCommerce |
|
| 1155 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 1156 | - // Get order object |
|
| 1157 | - $order = new WC_Order( $order_id ); |
|
| 1158 | 1138 | |
| 1159 | - if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) { |
|
| 1139 | + } // end if order items not empty |
|
| 1160 | 1140 | |
| 1161 | - return; |
|
| 1141 | + }// end email_course_details |
|
| 1162 | 1142 | |
| 1163 | - } |
|
| 1143 | + /** |
|
| 1144 | + * sensei_woocommerce_complete_order description |
|
| 1145 | + * @since 1.0.3 |
|
| 1146 | + * @access public |
|
| 1147 | + * @param int $order_id WC order ID |
|
| 1148 | + * @return void |
|
| 1149 | + */ |
|
| 1150 | + public static function complete_order ( $order_id = 0 ) { |
|
| 1151 | + |
|
| 1152 | + $order_user = array(); |
|
| 1164 | 1153 | |
| 1165 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 1166 | - $order_user['ID'] = $user->ID; |
|
| 1167 | - $order_user['user_login'] = $user->user_login; |
|
| 1168 | - $order_user['user_email'] = $user->user_email; |
|
| 1169 | - $order_user['user_url'] = $user->user_url; |
|
| 1170 | - // Run through each product ordered |
|
| 1171 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 1154 | + // Check for WooCommerce |
|
| 1155 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 1156 | + // Get order object |
|
| 1157 | + $order = new WC_Order( $order_id ); |
|
| 1172 | 1158 | |
| 1173 | - foreach( $order->get_items() as $item ) { |
|
| 1159 | + if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) { |
|
| 1174 | 1160 | |
| 1175 | - $product_type = ''; |
|
| 1176 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1161 | + return; |
|
| 1162 | + |
|
| 1163 | + } |
|
| 1177 | 1164 | |
| 1178 | - $item_id = $item['variation_id']; |
|
| 1179 | - $product_type = 'variation'; |
|
| 1165 | + $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 1166 | + $order_user['ID'] = $user->ID; |
|
| 1167 | + $order_user['user_login'] = $user->user_login; |
|
| 1168 | + $order_user['user_email'] = $user->user_email; |
|
| 1169 | + $order_user['user_url'] = $user->user_url; |
|
| 1170 | + // Run through each product ordered |
|
| 1171 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 1180 | 1172 | |
| 1181 | - } else { |
|
| 1173 | + foreach( $order->get_items() as $item ) { |
|
| 1182 | 1174 | |
| 1183 | - $item_id = $item['product_id']; |
|
| 1175 | + $product_type = ''; |
|
| 1176 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1184 | 1177 | |
| 1185 | - } // End If Statement |
|
| 1178 | + $item_id = $item['variation_id']; |
|
| 1179 | + $product_type = 'variation'; |
|
| 1186 | 1180 | |
| 1187 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
| 1181 | + } else { |
|
| 1188 | 1182 | |
| 1189 | - // Get courses that use the WC product |
|
| 1190 | - $courses = Sensei()->course->get_product_courses( $_product->id ); |
|
| 1183 | + $item_id = $item['product_id']; |
|
| 1191 | 1184 | |
| 1192 | - // Loop and update those courses |
|
| 1193 | - foreach ( $courses as $course_item ) { |
|
| 1185 | + } // End If Statement |
|
| 1194 | 1186 | |
| 1195 | - $update_course = self::course_update( $course_item->ID, $order_user ); |
|
| 1187 | + $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
| 1196 | 1188 | |
| 1197 | - } // End For Loop |
|
| 1189 | + // Get courses that use the WC product |
|
| 1190 | + $courses = Sensei()->course->get_product_courses( $_product->id ); |
|
| 1198 | 1191 | |
| 1199 | - } // End For Loop |
|
| 1192 | + // Loop and update those courses |
|
| 1193 | + foreach ( $courses as $course_item ) { |
|
| 1200 | 1194 | |
| 1201 | - } // End If Statement |
|
| 1202 | - // Add meta to indicate that payment has been completed successfully |
|
| 1203 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 1195 | + $update_course = self::course_update( $course_item->ID, $order_user ); |
|
| 1204 | 1196 | |
| 1205 | - } // End If Statement |
|
| 1197 | + } // End For Loop |
|
| 1206 | 1198 | |
| 1207 | - } // End sensei_woocommerce_complete_order() |
|
| 1199 | + } // End For Loop |
|
| 1208 | 1200 | |
| 1209 | - /** |
|
| 1210 | - * Responds to when an order is cancelled. |
|
| 1211 | - * |
|
| 1212 | - * @since 1.2.0 |
|
| 1213 | - * @since 1.9.0 Move function to the Sensei_WC class |
|
| 1214 | - * @param integer| WC_Order $order_id order ID |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - public static function cancel_order ( $order_id ) { |
|
| 1201 | + } // End If Statement |
|
| 1202 | + // Add meta to indicate that payment has been completed successfully |
|
| 1203 | + update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 1204 | + |
|
| 1205 | + } // End If Statement |
|
| 1206 | + |
|
| 1207 | + } // End sensei_woocommerce_complete_order() |
|
| 1208 | + |
|
| 1209 | + /** |
|
| 1210 | + * Responds to when an order is cancelled. |
|
| 1211 | + * |
|
| 1212 | + * @since 1.2.0 |
|
| 1213 | + * @since 1.9.0 Move function to the Sensei_WC class |
|
| 1214 | + * @param integer| WC_Order $order_id order ID |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + public static function cancel_order ( $order_id ) { |
|
| 1218 | 1218 | |
| 1219 | 1219 | // Get order object |
| 1220 | 1220 | if( is_object( $order_id ) ){ |
@@ -1232,345 +1232,345 @@ discard block |
||
| 1232 | 1232 | |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | - // Run through each product ordered |
|
| 1236 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 1235 | + // Run through each product ordered |
|
| 1236 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 1237 | 1237 | |
| 1238 | - // Get order user |
|
| 1239 | - $user_id = $order->__get( 'user_id' ); |
|
| 1238 | + // Get order user |
|
| 1239 | + $user_id = $order->__get( 'user_id' ); |
|
| 1240 | 1240 | |
| 1241 | - foreach( $order->get_items() as $item ) { |
|
| 1241 | + foreach( $order->get_items() as $item ) { |
|
| 1242 | 1242 | |
| 1243 | - $product_type = ''; |
|
| 1244 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1243 | + $product_type = ''; |
|
| 1244 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1245 | 1245 | |
| 1246 | - $item_id = $item['variation_id']; |
|
| 1247 | - $product_type = 'variation'; |
|
| 1246 | + $item_id = $item['variation_id']; |
|
| 1247 | + $product_type = 'variation'; |
|
| 1248 | 1248 | |
| 1249 | - } else { |
|
| 1249 | + } else { |
|
| 1250 | 1250 | |
| 1251 | - $item_id = $item['product_id']; |
|
| 1251 | + $item_id = $item['product_id']; |
|
| 1252 | 1252 | |
| 1253 | - } // End If Statement |
|
| 1253 | + } // End If Statement |
|
| 1254 | 1254 | |
| 1255 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
| 1255 | + $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
| 1256 | 1256 | |
| 1257 | - // Get courses that use the WC product |
|
| 1258 | - $courses = array(); |
|
| 1259 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
| 1257 | + // Get courses that use the WC product |
|
| 1258 | + $courses = array(); |
|
| 1259 | + $courses = Sensei()->course->get_product_courses( $item_id ); |
|
| 1260 | 1260 | |
| 1261 | - // Loop and update those courses |
|
| 1262 | - foreach ($courses as $course_item){ |
|
| 1261 | + // Loop and update those courses |
|
| 1262 | + foreach ($courses as $course_item){ |
|
| 1263 | 1263 | |
| 1264 | - if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){ |
|
| 1265 | - continue; |
|
| 1266 | - } |
|
| 1267 | - // Check and Remove course from courses user meta |
|
| 1268 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 1264 | + if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){ |
|
| 1265 | + continue; |
|
| 1266 | + } |
|
| 1267 | + // Check and Remove course from courses user meta |
|
| 1268 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 1269 | 1269 | |
| 1270 | - } // End For Loop |
|
| 1270 | + } // End For Loop |
|
| 1271 | 1271 | |
| 1272 | - } // End For Loop |
|
| 1272 | + } // End For Loop |
|
| 1273 | 1273 | |
| 1274 | - } // End If Statement |
|
| 1274 | + } // End If Statement |
|
| 1275 | 1275 | |
| 1276 | - } // End sensei_woocommerce_cancel_order() |
|
| 1276 | + } // End sensei_woocommerce_cancel_order() |
|
| 1277 | 1277 | |
| 1278 | - /** |
|
| 1279 | - * Returns the WooCommerce Product Object |
|
| 1280 | - * |
|
| 1281 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 1282 | - * |
|
| 1283 | - * @since 1.1.1 |
|
| 1284 | - * @access public |
|
| 1285 | - * @param integer $wc_product_id Product ID or Variation ID |
|
| 1286 | - * @param string $product_type '' or 'variation' |
|
| 1287 | - * @return WC_Product $wc_product_object |
|
| 1288 | - */ |
|
| 1289 | - public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1278 | + /** |
|
| 1279 | + * Returns the WooCommerce Product Object |
|
| 1280 | + * |
|
| 1281 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 1282 | + * |
|
| 1283 | + * @since 1.1.1 |
|
| 1284 | + * @access public |
|
| 1285 | + * @param integer $wc_product_id Product ID or Variation ID |
|
| 1286 | + * @param string $product_type '' or 'variation' |
|
| 1287 | + * @return WC_Product $wc_product_object |
|
| 1288 | + */ |
|
| 1289 | + public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1290 | 1290 | |
| 1291 | - $wc_product_object = false; |
|
| 1292 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1291 | + $wc_product_object = false; |
|
| 1292 | + if ( 0 < intval( $wc_product_id ) ) { |
|
| 1293 | 1293 | |
| 1294 | - // Get the product |
|
| 1295 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1294 | + // Get the product |
|
| 1295 | + if ( function_exists( 'wc_get_product' ) ) { |
|
| 1296 | 1296 | |
| 1297 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1297 | + $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1298 | 1298 | |
| 1299 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1299 | + } elseif ( function_exists( 'get_product' ) ) { |
|
| 1300 | 1300 | |
| 1301 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1301 | + $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1302 | 1302 | |
| 1303 | - } else { |
|
| 1303 | + } else { |
|
| 1304 | 1304 | |
| 1305 | - // Pre WC 2.0 |
|
| 1306 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1305 | + // Pre WC 2.0 |
|
| 1306 | + if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1307 | 1307 | |
| 1308 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1308 | + $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1309 | 1309 | |
| 1310 | - } else { |
|
| 1310 | + } else { |
|
| 1311 | 1311 | |
| 1312 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1312 | + $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1313 | 1313 | |
| 1314 | - } // End If Statement |
|
| 1314 | + } // End If Statement |
|
| 1315 | 1315 | |
| 1316 | - } // End If Statement |
|
| 1316 | + } // End If Statement |
|
| 1317 | 1317 | |
| 1318 | - } // End If Statement |
|
| 1318 | + } // End If Statement |
|
| 1319 | 1319 | |
| 1320 | - return $wc_product_object; |
|
| 1320 | + return $wc_product_object; |
|
| 1321 | 1321 | |
| 1322 | - } // End sensei_get_woocommerce_product_object() |
|
| 1322 | + } // End sensei_get_woocommerce_product_object() |
|
| 1323 | 1323 | |
| 1324 | - /** |
|
| 1325 | - * If customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 1326 | - * |
|
| 1327 | - * @since 1.0.0 |
|
| 1328 | - * @since 1.9.0 move to class Sensei_WC |
|
| 1329 | - * |
|
| 1330 | - * @param int $course_id (default: 0) |
|
| 1331 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 1332 | - * |
|
| 1333 | - * @return bool|int |
|
| 1334 | - */ |
|
| 1335 | - public static function course_update ( $course_id = 0, $order_user = array() ) { |
|
| 1324 | + /** |
|
| 1325 | + * If customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 1326 | + * |
|
| 1327 | + * @since 1.0.0 |
|
| 1328 | + * @since 1.9.0 move to class Sensei_WC |
|
| 1329 | + * |
|
| 1330 | + * @param int $course_id (default: 0) |
|
| 1331 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 1332 | + * |
|
| 1333 | + * @return bool|int |
|
| 1334 | + */ |
|
| 1335 | + public static function course_update ( $course_id = 0, $order_user = array() ) { |
|
| 1336 | 1336 | |
| 1337 | - global $current_user; |
|
| 1337 | + global $current_user; |
|
| 1338 | 1338 | |
| 1339 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 1339 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 1340 | 1340 | |
| 1341 | - $data_update = false; |
|
| 1341 | + $data_update = false; |
|
| 1342 | 1342 | |
| 1343 | - // Get the product ID |
|
| 1344 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 1343 | + // Get the product ID |
|
| 1344 | + $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 1345 | 1345 | |
| 1346 | - // Check if in the admin |
|
| 1347 | - if ( is_admin() ) { |
|
| 1346 | + // Check if in the admin |
|
| 1347 | + if ( is_admin() ) { |
|
| 1348 | 1348 | |
| 1349 | - $user_login = $order_user['user_login']; |
|
| 1350 | - $user_email = $order_user['user_email']; |
|
| 1351 | - $user_url = $order_user['user_url']; |
|
| 1352 | - $user_id = $order_user['ID']; |
|
| 1349 | + $user_login = $order_user['user_login']; |
|
| 1350 | + $user_email = $order_user['user_email']; |
|
| 1351 | + $user_url = $order_user['user_url']; |
|
| 1352 | + $user_id = $order_user['ID']; |
|
| 1353 | 1353 | |
| 1354 | - } else { |
|
| 1354 | + } else { |
|
| 1355 | 1355 | |
| 1356 | - $user_login = $current_user->user_login; |
|
| 1357 | - $user_email = $current_user->user_email; |
|
| 1358 | - $user_url = $current_user->user_url; |
|
| 1359 | - $user_id = $current_user->ID; |
|
| 1356 | + $user_login = $current_user->user_login; |
|
| 1357 | + $user_email = $current_user->user_email; |
|
| 1358 | + $user_url = $current_user->user_url; |
|
| 1359 | + $user_id = $current_user->ID; |
|
| 1360 | 1360 | |
| 1361 | - } // End If Statement |
|
| 1361 | + } // End If Statement |
|
| 1362 | 1362 | |
| 1363 | - // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 1364 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 1365 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 1363 | + // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 1364 | + $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 1365 | + if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 1366 | 1366 | |
| 1367 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 1368 | - if ( ! $prereq_course_complete ) { |
|
| 1367 | + $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 1368 | + if ( ! $prereq_course_complete ) { |
|
| 1369 | 1369 | |
| 1370 | - // Remove all course user meta |
|
| 1371 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 1370 | + // Remove all course user meta |
|
| 1371 | + return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 1372 | 1372 | |
| 1373 | - } |
|
| 1374 | - } |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | 1375 | |
| 1376 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 1376 | + $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 1377 | 1377 | |
| 1378 | - if ( ! $is_user_taking_course |
|
| 1379 | - && Sensei_WC::is_woocommerce_active() |
|
| 1380 | - && 0 < $wc_post_id |
|
| 1381 | - && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) { |
|
| 1378 | + if ( ! $is_user_taking_course |
|
| 1379 | + && Sensei_WC::is_woocommerce_active() |
|
| 1380 | + && 0 < $wc_post_id |
|
| 1381 | + && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) { |
|
| 1382 | 1382 | |
| 1383 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) ); |
|
| 1383 | + $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) ); |
|
| 1384 | 1384 | |
| 1385 | - if ( true == $activity_logged ) { |
|
| 1385 | + if ( true == $activity_logged ) { |
|
| 1386 | 1386 | |
| 1387 | - $is_user_taking_course = true; |
|
| 1387 | + $is_user_taking_course = true; |
|
| 1388 | 1388 | |
| 1389 | - } // End If Statement |
|
| 1389 | + } // End If Statement |
|
| 1390 | 1390 | |
| 1391 | - }// end if is user taking course |
|
| 1391 | + }// end if is user taking course |
|
| 1392 | 1392 | |
| 1393 | - return $is_user_taking_course; |
|
| 1393 | + return $is_user_taking_course; |
|
| 1394 | 1394 | |
| 1395 | - } // End course_update() |
|
| 1395 | + } // End course_update() |
|
| 1396 | 1396 | |
| 1397 | - /** |
|
| 1398 | - * Disable guest checkout if a course product is in the cart |
|
| 1399 | - * |
|
| 1400 | - * @since 1.1.0 |
|
| 1401 | - * @since 1.9.0 move to class Sensei_WC |
|
| 1402 | - * |
|
| 1403 | - * @param boolean $guest_checkout Current guest checkout setting |
|
| 1404 | - * |
|
| 1405 | - * @return boolean Modified guest checkout setting |
|
| 1406 | - */ |
|
| 1407 | - public static function disable_guest_checkout( $guest_checkout ) { |
|
| 1397 | + /** |
|
| 1398 | + * Disable guest checkout if a course product is in the cart |
|
| 1399 | + * |
|
| 1400 | + * @since 1.1.0 |
|
| 1401 | + * @since 1.9.0 move to class Sensei_WC |
|
| 1402 | + * |
|
| 1403 | + * @param boolean $guest_checkout Current guest checkout setting |
|
| 1404 | + * |
|
| 1405 | + * @return boolean Modified guest checkout setting |
|
| 1406 | + */ |
|
| 1407 | + public static function disable_guest_checkout( $guest_checkout ) { |
|
| 1408 | 1408 | |
| 1409 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 1409 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 1410 | 1410 | |
| 1411 | - if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) { |
|
| 1411 | + if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) { |
|
| 1412 | 1412 | |
| 1413 | - foreach( WC()->cart->cart_contents as $cart_key => $product ) { |
|
| 1414 | - if( isset( $product['product_id'] ) ) { |
|
| 1413 | + foreach( WC()->cart->cart_contents as $cart_key => $product ) { |
|
| 1414 | + if( isset( $product['product_id'] ) ) { |
|
| 1415 | 1415 | |
| 1416 | - $args = array( |
|
| 1417 | - 'posts_per_page' => -1, |
|
| 1418 | - 'post_type' => 'course', |
|
| 1419 | - 'meta_query' => array( |
|
| 1420 | - array( |
|
| 1421 | - 'key' => '_course_woocommerce_product', |
|
| 1422 | - 'value' => $product['product_id'] |
|
| 1423 | - ) |
|
| 1424 | - ) |
|
| 1425 | - ); |
|
| 1416 | + $args = array( |
|
| 1417 | + 'posts_per_page' => -1, |
|
| 1418 | + 'post_type' => 'course', |
|
| 1419 | + 'meta_query' => array( |
|
| 1420 | + array( |
|
| 1421 | + 'key' => '_course_woocommerce_product', |
|
| 1422 | + 'value' => $product['product_id'] |
|
| 1423 | + ) |
|
| 1424 | + ) |
|
| 1425 | + ); |
|
| 1426 | 1426 | |
| 1427 | - $posts = get_posts( $args ); |
|
| 1427 | + $posts = get_posts( $args ); |
|
| 1428 | 1428 | |
| 1429 | - if( $posts && count( $posts ) > 0 ) { |
|
| 1429 | + if( $posts && count( $posts ) > 0 ) { |
|
| 1430 | 1430 | |
| 1431 | - foreach( $posts as $course ) { |
|
| 1432 | - $guest_checkout = ''; |
|
| 1433 | - break; |
|
| 1431 | + foreach( $posts as $course ) { |
|
| 1432 | + $guest_checkout = ''; |
|
| 1433 | + break; |
|
| 1434 | 1434 | |
| 1435 | - } |
|
| 1436 | - } |
|
| 1435 | + } |
|
| 1436 | + } |
|
| 1437 | 1437 | |
| 1438 | - } |
|
| 1438 | + } |
|
| 1439 | 1439 | |
| 1440 | - } |
|
| 1440 | + } |
|
| 1441 | 1441 | |
| 1442 | - } |
|
| 1443 | - } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | - return $guest_checkout; |
|
| 1445 | + return $guest_checkout; |
|
| 1446 | 1446 | |
| 1447 | - }// end disable_guest_checkout |
|
| 1447 | + }// end disable_guest_checkout |
|
| 1448 | 1448 | |
| 1449 | - /** |
|
| 1450 | - * Change order status with virtual products to completed |
|
| 1451 | - * |
|
| 1452 | - * @since 1.1.0 |
|
| 1453 | - * @since 1.9.0 move to class Sensei_WC |
|
| 1454 | - * |
|
| 1455 | - * @param string $order_status |
|
| 1456 | - * @param int $order_id |
|
| 1457 | - * |
|
| 1458 | - * @return string |
|
| 1459 | - **/ |
|
| 1460 | - public static function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 1449 | + /** |
|
| 1450 | + * Change order status with virtual products to completed |
|
| 1451 | + * |
|
| 1452 | + * @since 1.1.0 |
|
| 1453 | + * @since 1.9.0 move to class Sensei_WC |
|
| 1454 | + * |
|
| 1455 | + * @param string $order_status |
|
| 1456 | + * @param int $order_id |
|
| 1457 | + * |
|
| 1458 | + * @return string |
|
| 1459 | + **/ |
|
| 1460 | + public static function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 1461 | 1461 | |
| 1462 | - $order = new WC_Order( $order_id ); |
|
| 1462 | + $order = new WC_Order( $order_id ); |
|
| 1463 | 1463 | |
| 1464 | - if ( ! isset ( $order ) ) return ''; |
|
| 1464 | + if ( ! isset ( $order ) ) return ''; |
|
| 1465 | 1465 | |
| 1466 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 1466 | + if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 1467 | 1467 | |
| 1468 | - $virtual_order = true; |
|
| 1468 | + $virtual_order = true; |
|
| 1469 | 1469 | |
| 1470 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 1470 | + if ( count( $order->get_items() ) > 0 ) { |
|
| 1471 | 1471 | |
| 1472 | - foreach( $order->get_items() as $item ) { |
|
| 1472 | + foreach( $order->get_items() as $item ) { |
|
| 1473 | 1473 | |
| 1474 | - if ( $item['product_id'] > 0 ) { |
|
| 1475 | - $_product = $order->get_product_from_item( $item ); |
|
| 1476 | - if ( ! $_product->is_virtual() ) { |
|
| 1474 | + if ( $item['product_id'] > 0 ) { |
|
| 1475 | + $_product = $order->get_product_from_item( $item ); |
|
| 1476 | + if ( ! $_product->is_virtual() ) { |
|
| 1477 | 1477 | |
| 1478 | - $virtual_order = false; |
|
| 1479 | - break; |
|
| 1478 | + $virtual_order = false; |
|
| 1479 | + break; |
|
| 1480 | 1480 | |
| 1481 | - } // End If Statement |
|
| 1481 | + } // End If Statement |
|
| 1482 | 1482 | |
| 1483 | - } // End If Statement |
|
| 1483 | + } // End If Statement |
|
| 1484 | 1484 | |
| 1485 | - } // End For Loop |
|
| 1485 | + } // End For Loop |
|
| 1486 | 1486 | |
| 1487 | - } // End If Statement |
|
| 1487 | + } // End If Statement |
|
| 1488 | 1488 | |
| 1489 | - // virtual order, mark as completed |
|
| 1490 | - if ( $virtual_order ) { |
|
| 1489 | + // virtual order, mark as completed |
|
| 1490 | + if ( $virtual_order ) { |
|
| 1491 | 1491 | |
| 1492 | - return 'completed'; |
|
| 1492 | + return 'completed'; |
|
| 1493 | 1493 | |
| 1494 | - } // End If Statement |
|
| 1494 | + } // End If Statement |
|
| 1495 | 1495 | |
| 1496 | - } // End If Statement |
|
| 1496 | + } // End If Statement |
|
| 1497 | 1497 | |
| 1498 | - return $order_status; |
|
| 1498 | + return $order_status; |
|
| 1499 | 1499 | |
| 1500 | - }// end virtual_order_payment_complete |
|
| 1500 | + }// end virtual_order_payment_complete |
|
| 1501 | 1501 | |
| 1502 | 1502 | |
| 1503 | - /** |
|
| 1504 | - * Determine if the user has and active subscription to give them access |
|
| 1505 | - * to the requested resource. |
|
| 1506 | - * |
|
| 1507 | - * @since 1.9.0 |
|
| 1508 | - * |
|
| 1509 | - * @param boolean$user_access_permission |
|
| 1510 | - * @param integer $user_id |
|
| 1511 | - * @return boolean $user_access_permission |
|
| 1512 | - */ |
|
| 1513 | - public static function get_subscription_permission( $user_access_permission , $user_id ){ |
|
| 1503 | + /** |
|
| 1504 | + * Determine if the user has and active subscription to give them access |
|
| 1505 | + * to the requested resource. |
|
| 1506 | + * |
|
| 1507 | + * @since 1.9.0 |
|
| 1508 | + * |
|
| 1509 | + * @param boolean$user_access_permission |
|
| 1510 | + * @param integer $user_id |
|
| 1511 | + * @return boolean $user_access_permission |
|
| 1512 | + */ |
|
| 1513 | + public static function get_subscription_permission( $user_access_permission , $user_id ){ |
|
| 1514 | 1514 | |
| 1515 | - global $post; |
|
| 1515 | + global $post; |
|
| 1516 | 1516 | |
| 1517 | - // ignore the current case if the following conditions are met |
|
| 1518 | - if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id ) |
|
| 1519 | - || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) ) |
|
| 1520 | - || ! wcs_user_has_subscription( $user_id) ){ |
|
| 1517 | + // ignore the current case if the following conditions are met |
|
| 1518 | + if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id ) |
|
| 1519 | + || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) ) |
|
| 1520 | + || ! wcs_user_has_subscription( $user_id) ){ |
|
| 1521 | 1521 | |
| 1522 | - return $user_access_permission; |
|
| 1522 | + return $user_access_permission; |
|
| 1523 | 1523 | |
| 1524 | - } |
|
| 1524 | + } |
|
| 1525 | 1525 | |
| 1526 | - // at this user has a subscription |
|
| 1527 | - // is the subscription on the the current course? |
|
| 1526 | + // at this user has a subscription |
|
| 1527 | + // is the subscription on the the current course? |
|
| 1528 | 1528 | |
| 1529 | - $course_id = 0; |
|
| 1530 | - if ( 'course' == $post->post_type ){ |
|
| 1529 | + $course_id = 0; |
|
| 1530 | + if ( 'course' == $post->post_type ){ |
|
| 1531 | 1531 | |
| 1532 | - $course_id = $post->ID; |
|
| 1532 | + $course_id = $post->ID; |
|
| 1533 | 1533 | |
| 1534 | - } elseif ( 'lesson' == $post->post_type ) { |
|
| 1534 | + } elseif ( 'lesson' == $post->post_type ) { |
|
| 1535 | 1535 | |
| 1536 | - $course_id = Sensei()->lesson->get_course_id( $post->ID ); |
|
| 1536 | + $course_id = Sensei()->lesson->get_course_id( $post->ID ); |
|
| 1537 | 1537 | |
| 1538 | - } else { |
|
| 1538 | + } else { |
|
| 1539 | 1539 | |
| 1540 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 1541 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1540 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 1541 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1542 | 1542 | |
| 1543 | - } |
|
| 1543 | + } |
|
| 1544 | 1544 | |
| 1545 | - // if the course has no subscription WooCommerce product attached to return the permissions as is |
|
| 1546 | - $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
| 1547 | - $product = wc_get_product( $product_id ); |
|
| 1548 | - if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
| 1545 | + // if the course has no subscription WooCommerce product attached to return the permissions as is |
|
| 1546 | + $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
| 1547 | + $product = wc_get_product( $product_id ); |
|
| 1548 | + if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
| 1549 | 1549 | |
| 1550 | - return $user_access_permission; |
|
| 1550 | + return $user_access_permission; |
|
| 1551 | 1551 | |
| 1552 | - } |
|
| 1552 | + } |
|
| 1553 | 1553 | |
| 1554 | - // give access if user has active subscription on the product otherwise restrict it. |
|
| 1555 | - // also check if the user was added to the course directly after the subscription started. |
|
| 1556 | - if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
| 1557 | - || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
| 1558 | - || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
| 1554 | + // give access if user has active subscription on the product otherwise restrict it. |
|
| 1555 | + // also check if the user was added to the course directly after the subscription started. |
|
| 1556 | + if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
| 1557 | + || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
| 1558 | + || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
| 1559 | 1559 | |
| 1560 | - $user_access_permission = true; |
|
| 1560 | + $user_access_permission = true; |
|
| 1561 | 1561 | |
| 1562 | - }else{ |
|
| 1562 | + }else{ |
|
| 1563 | 1563 | |
| 1564 | - $user_access_permission = false; |
|
| 1565 | - // do not show the WC permissions message |
|
| 1566 | - remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
| 1567 | - Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' ); |
|
| 1568 | - Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' ); |
|
| 1569 | - } |
|
| 1564 | + $user_access_permission = false; |
|
| 1565 | + // do not show the WC permissions message |
|
| 1566 | + remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
| 1567 | + Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' ); |
|
| 1568 | + Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' ); |
|
| 1569 | + } |
|
| 1570 | 1570 | |
| 1571 | - return $user_access_permission; |
|
| 1571 | + return $user_access_permission; |
|
| 1572 | 1572 | |
| 1573 | - } // end get_subscription_permission |
|
| 1573 | + } // end get_subscription_permission |
|
| 1574 | 1574 | |
| 1575 | 1575 | /** |
| 1576 | 1576 | * @since 1.9.0 |
@@ -1619,8 +1619,8 @@ discard block |
||
| 1619 | 1619 | // give access if user has active subscription on the product otherwise restrict it. |
| 1620 | 1620 | // also check if the user was added to the course directly after the subscription started. |
| 1621 | 1621 | if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
| 1622 | - || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
| 1623 | - || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
| 1622 | + || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
| 1623 | + || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
| 1624 | 1624 | |
| 1625 | 1625 | $has_user_started_course = true; |
| 1626 | 1626 | |
@@ -1635,91 +1635,91 @@ discard block |
||
| 1635 | 1635 | |
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | - /** |
|
| 1639 | - * Get all the valid subscription types. |
|
| 1640 | - * |
|
| 1641 | - * @since 1.9.0 |
|
| 1642 | - * @return array |
|
| 1643 | - */ |
|
| 1644 | - public static function get_subscription_types(){ |
|
| 1638 | + /** |
|
| 1639 | + * Get all the valid subscription types. |
|
| 1640 | + * |
|
| 1641 | + * @since 1.9.0 |
|
| 1642 | + * @return array |
|
| 1643 | + */ |
|
| 1644 | + public static function get_subscription_types(){ |
|
| 1645 | 1645 | |
| 1646 | - return array( 'subscription','subscription_variation','variable-subscription' ); |
|
| 1646 | + return array( 'subscription','subscription_variation','variable-subscription' ); |
|
| 1647 | 1647 | |
| 1648 | - } |
|
| 1648 | + } |
|
| 1649 | 1649 | |
| 1650 | - /** |
|
| 1651 | - * Compare the user's subscriptions end date with the date |
|
| 1652 | - * the user was added to the course. If the user was added after |
|
| 1653 | - * the subscription ended they were manually added and this will return |
|
| 1654 | - * true. |
|
| 1655 | - * |
|
| 1656 | - * Important to note that all subscriptions for the user is compared. |
|
| 1657 | - * |
|
| 1658 | - * @since 1.9.0 |
|
| 1659 | - * |
|
| 1660 | - * @param $user_id |
|
| 1661 | - * @param $product_id |
|
| 1662 | - * @param $course_id |
|
| 1663 | - * |
|
| 1664 | - * @return bool |
|
| 1665 | - */ |
|
| 1666 | - public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){ |
|
| 1650 | + /** |
|
| 1651 | + * Compare the user's subscriptions end date with the date |
|
| 1652 | + * the user was added to the course. If the user was added after |
|
| 1653 | + * the subscription ended they were manually added and this will return |
|
| 1654 | + * true. |
|
| 1655 | + * |
|
| 1656 | + * Important to note that all subscriptions for the user is compared. |
|
| 1657 | + * |
|
| 1658 | + * @since 1.9.0 |
|
| 1659 | + * |
|
| 1660 | + * @param $user_id |
|
| 1661 | + * @param $product_id |
|
| 1662 | + * @param $course_id |
|
| 1663 | + * |
|
| 1664 | + * @return bool |
|
| 1665 | + */ |
|
| 1666 | + public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){ |
|
| 1667 | 1667 | |
| 1668 | - $course_start_date = ''; |
|
| 1669 | - $subscription_start_date = ''; |
|
| 1670 | - $is_a_subscription =''; |
|
| 1671 | - $was_user_added_without_subscription = false; |
|
| 1668 | + $course_start_date = ''; |
|
| 1669 | + $subscription_start_date = ''; |
|
| 1670 | + $is_a_subscription =''; |
|
| 1671 | + $was_user_added_without_subscription = false; |
|
| 1672 | 1672 | |
| 1673 | - // if user is not on the course they were not added |
|
| 1674 | - remove_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 1675 | - if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1673 | + // if user is not on the course they were not added |
|
| 1674 | + remove_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 1675 | + if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1676 | 1676 | |
| 1677 | - return false; |
|
| 1677 | + return false; |
|
| 1678 | 1678 | |
| 1679 | - } |
|
| 1679 | + } |
|
| 1680 | 1680 | |
| 1681 | - // if user doesn't have a subscription and is taking the course |
|
| 1682 | - // they were added manually |
|
| 1683 | - if ( ! wcs_user_has_subscription($user_id, $product_id) |
|
| 1684 | - && Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){ |
|
| 1681 | + // if user doesn't have a subscription and is taking the course |
|
| 1682 | + // they were added manually |
|
| 1683 | + if ( ! wcs_user_has_subscription($user_id, $product_id) |
|
| 1684 | + && Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){ |
|
| 1685 | 1685 | |
| 1686 | - return true; |
|
| 1686 | + return true; |
|
| 1687 | 1687 | |
| 1688 | - } |
|
| 1688 | + } |
|
| 1689 | 1689 | |
| 1690 | - add_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 1690 | + add_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 1691 | 1691 | |
| 1692 | - $course_status = Sensei_Utils::user_course_status( $course_id, $user_id ); |
|
| 1692 | + $course_status = Sensei_Utils::user_course_status( $course_id, $user_id ); |
|
| 1693 | 1693 | |
| 1694 | - // comparing dates setup data |
|
| 1695 | - $course_start_date = date_create( $course_status->comment_date ); |
|
| 1696 | - $subscriptions = wcs_get_users_subscriptions( $user_id ); |
|
| 1694 | + // comparing dates setup data |
|
| 1695 | + $course_start_date = date_create( $course_status->comment_date ); |
|
| 1696 | + $subscriptions = wcs_get_users_subscriptions( $user_id ); |
|
| 1697 | 1697 | |
| 1698 | - // comparing every subscription |
|
| 1699 | - foreach( $subscriptions as $subscription ){ |
|
| 1698 | + // comparing every subscription |
|
| 1699 | + foreach( $subscriptions as $subscription ){ |
|
| 1700 | 1700 | |
| 1701 | - // for the following statuses we know the user was not added |
|
| 1702 | - // manually |
|
| 1703 | - $status = $subscription->get_status(); |
|
| 1704 | - if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) { |
|
| 1701 | + // for the following statuses we know the user was not added |
|
| 1702 | + // manually |
|
| 1703 | + $status = $subscription->get_status(); |
|
| 1704 | + if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) { |
|
| 1705 | 1705 | |
| 1706 | - continue; |
|
| 1706 | + continue; |
|
| 1707 | 1707 | |
| 1708 | - } |
|
| 1708 | + } |
|
| 1709 | 1709 | |
| 1710 | - $current_subscription_start_date = date_create( $subscription->modified_date ); |
|
| 1710 | + $current_subscription_start_date = date_create( $subscription->modified_date ); |
|
| 1711 | 1711 | |
| 1712 | - // is the last updated subscription date newer than course start date |
|
| 1713 | - if ( $current_subscription_start_date > $course_start_date ) { |
|
| 1712 | + // is the last updated subscription date newer than course start date |
|
| 1713 | + if ( $current_subscription_start_date > $course_start_date ) { |
|
| 1714 | 1714 | |
| 1715 | - return false; |
|
| 1715 | + return false; |
|
| 1716 | 1716 | |
| 1717 | - } |
|
| 1717 | + } |
|
| 1718 | 1718 | |
| 1719 | - } |
|
| 1719 | + } |
|
| 1720 | 1720 | |
| 1721 | - return $was_user_added_without_subscription; |
|
| 1722 | - } |
|
| 1721 | + return $was_user_added_without_subscription; |
|
| 1722 | + } |
|
| 1723 | 1723 | |
| 1724 | 1724 | /** |
| 1725 | 1725 | * Get all the orders for a specific user and product combination |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei WooCommerce class |
@@ -11,17 +11,17 @@ discard block |
||
| 11 | 11 | * @since 1.9.0 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -Class Sensei_WC{ |
|
| 14 | +Class Sensei_WC { |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * Load the files needed for the woocommerce integration. |
| 18 | 18 | * |
| 19 | 19 | * @since 1.9.0 |
| 20 | 20 | */ |
| 21 | - public static function load_woocommerce_integration_hooks(){ |
|
| 21 | + public static function load_woocommerce_integration_hooks() { |
|
| 22 | 22 | |
| 23 | - $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php'; |
|
| 24 | - require_once( $woocommerce_hooks_file_path ); |
|
| 23 | + $woocommerce_hooks_file_path = Sensei()->plugin_path().'includes/hooks/woocommerce.php'; |
|
| 24 | + require_once($woocommerce_hooks_file_path); |
|
| 25 | 25 | |
| 26 | 26 | } |
| 27 | 27 | /** |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @since 1.9.0 |
| 31 | 31 | * @return bool |
| 32 | 32 | */ |
| 33 | - public static function is_woocommerce_active(){ |
|
| 33 | + public static function is_woocommerce_active() { |
|
| 34 | 34 | |
| 35 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 35 | + $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 36 | 36 | return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
| 37 | 37 | |
| 38 | 38 | } // end is_woocommerce_active |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return bool |
| 49 | 49 | */ |
| 50 | - public static function is_woocommerce_present(){ |
|
| 50 | + public static function is_woocommerce_present() { |
|
| 51 | 51 | |
| 52 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 52 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
| 53 | 53 | |
| 54 | - if ( is_multisite() ){ |
|
| 54 | + if (is_multisite()) { |
|
| 55 | 55 | |
| 56 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 56 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
| 57 | 57 | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 60 | + $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins); |
|
| 61 | 61 | |
| 62 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 62 | + return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated; |
|
| 63 | 63 | |
| 64 | 64 | }// end is_woocommerce_present |
| 65 | 65 | |
@@ -72,48 +72,48 @@ discard block |
||
| 72 | 72 | * @param $course_id |
| 73 | 73 | * @return array $user_course_orders |
| 74 | 74 | */ |
| 75 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 75 | + public static function get_learner_course_active_order_id($user_id, $course_id) { |
|
| 76 | 76 | |
| 77 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 77 | + $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 78 | 78 | |
| 79 | - $orders_query = new WP_Query( array( |
|
| 79 | + $orders_query = new WP_Query(array( |
|
| 80 | 80 | 'post_type' => 'shop_order', |
| 81 | 81 | 'posts_per_page' => -1, |
| 82 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 82 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 83 | 83 | 'meta_key'=> '_customer_user', |
| 84 | 84 | 'meta_value'=> $user_id, |
| 85 | - ) ); |
|
| 85 | + )); |
|
| 86 | 86 | |
| 87 | - if( $orders_query->post_count == 0 ){ |
|
| 87 | + if ($orders_query->post_count == 0) { |
|
| 88 | 88 | |
| 89 | 89 | return false; |
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 93 | + foreach ($orders_query->get_posts() as $order) { |
|
| 94 | 94 | |
| 95 | - $order = new WC_Order( $order->ID ); |
|
| 95 | + $order = new WC_Order($order->ID); |
|
| 96 | 96 | $items = $order->get_items(); |
| 97 | 97 | |
| 98 | - $user_orders = array(); |
|
| 98 | + $user_orders = array(); |
|
| 99 | 99 | |
| 100 | - foreach( $items as $item ){ |
|
| 100 | + foreach ($items as $item) { |
|
| 101 | 101 | |
| 102 | 102 | // if the product id on the order and the one given to this function |
| 103 | 103 | // this order has been placed by the given user on the given course. |
| 104 | - $product = wc_get_product( $item['product_id'] ); |
|
| 104 | + $product = wc_get_product($item['product_id']); |
|
| 105 | 105 | |
| 106 | - if ( is_object( $product ) && $product->is_type( 'variable' )) { |
|
| 106 | + if (is_object($product) && $product->is_type('variable')) { |
|
| 107 | 107 | |
| 108 | 108 | $item_product_id = $item['variation_id']; |
| 109 | 109 | |
| 110 | 110 | } else { |
| 111 | 111 | |
| 112 | - $item_product_id = $item['product_id']; |
|
| 112 | + $item_product_id = $item['product_id']; |
|
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if( $course_product_id == $item_product_id ){ |
|
| 116 | + if ($course_product_id == $item_product_id) { |
|
| 117 | 117 | |
| 118 | 118 | return $order->id; |
| 119 | 119 | |
@@ -137,12 +137,12 @@ discard block |
||
| 137 | 137 | * @param $filter_links |
| 138 | 138 | * @return mixed |
| 139 | 139 | */ |
| 140 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 140 | + public static function add_course_archive_wc_filter_links($filter_links) { |
|
| 141 | 141 | |
| 142 | 142 | $free_courses = self::get_free_courses(); |
| 143 | 143 | $paid_courses = self::get_paid_courses(); |
| 144 | 144 | |
| 145 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 145 | + if (empty($free_courses) || empty($paid_courses)) { |
|
| 146 | 146 | // do not show any WooCommerce filters if all courses are |
| 147 | 147 | // free or if all courses are paid |
| 148 | 148 | return $filter_links; |
@@ -150,15 +150,15 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $filter_links[] = array( |
| 153 | - 'id'=>'paid' , |
|
| 154 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 155 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 153 | + 'id'=>'paid', |
|
| 154 | + 'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()), |
|
| 155 | + 'title'=>__('Paid', 'woothemes-sensei') |
|
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | 158 | $filter_links[] = array( |
| 159 | 159 | 'id'=>'free', |
| 160 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 161 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | + 'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()), |
|
| 161 | + 'title'=>__('Free', 'woothemes-sensei') |
|
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | 164 | return $filter_links; |
@@ -175,24 +175,24 @@ discard block |
||
| 175 | 175 | * @param WP_Query $query |
| 176 | 176 | * @return WP_Query $query |
| 177 | 177 | */ |
| 178 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 178 | + public static function course_archive_wc_filter_free($query) { |
|
| 179 | 179 | |
| 180 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 181 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 180 | + if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter'] |
|
| 181 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 182 | 182 | |
| 183 | 183 | // setup the course meta query |
| 184 | 184 | $meta_query = self::get_free_courses_meta_query_args(); |
| 185 | 185 | |
| 186 | 186 | // manipulate the query to return free courses |
| 187 | - $query->set('meta_query', $meta_query ); |
|
| 187 | + $query->set('meta_query', $meta_query); |
|
| 188 | 188 | |
| 189 | 189 | // don't show any paid courses |
| 190 | 190 | $courses = self::get_paid_courses(); |
| 191 | 191 | $ids = array(); |
| 192 | - foreach( $courses as $course ){ |
|
| 192 | + foreach ($courses as $course) { |
|
| 193 | 193 | $ids[] = $course->ID; |
| 194 | 194 | } |
| 195 | - $query->set( 'post__not_in', $ids ); |
|
| 195 | + $query->set('post__not_in', $ids); |
|
| 196 | 196 | |
| 197 | 197 | }// end if course_filter |
| 198 | 198 | |
@@ -211,16 +211,16 @@ discard block |
||
| 211 | 211 | * @param WP_Query $query |
| 212 | 212 | * @return WP_Query $query |
| 213 | 213 | */ |
| 214 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 214 | + public static function course_archive_wc_filter_paid($query) { |
|
| 215 | 215 | |
| 216 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 217 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | + if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter'] |
|
| 217 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 218 | 218 | |
| 219 | 219 | // setup the course meta query |
| 220 | 220 | $meta_query = self::get_paid_courses_meta_query_args(); |
| 221 | 221 | |
| 222 | 222 | // manipulate the query to return free courses |
| 223 | - $query->set('meta_query', $meta_query ); |
|
| 223 | + $query->set('meta_query', $meta_query); |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | * single courses if woocommerce is active allowing purchase |
| 234 | 234 | * information and actions to be hooked from WooCommerce. |
| 235 | 235 | */ |
| 236 | - public static function do_single_course_wc_single_product_action(){ |
|
| 236 | + public static function do_single_course_wc_single_product_action() { |
|
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * this hooks is documented within the WooCommerce plugin. |
| 240 | 240 | */ |
| 241 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 241 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 242 | 242 | |
| 243 | - do_action( 'woocommerce_before_single_product' ); |
|
| 243 | + do_action('woocommerce_before_single_product'); |
|
| 244 | 244 | |
| 245 | 245 | } // End If Statement |
| 246 | 246 | |
@@ -261,12 +261,12 @@ discard block |
||
| 261 | 261 | * @param $user_id |
| 262 | 262 | * @return bool |
| 263 | 263 | */ |
| 264 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 264 | + public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) { |
|
| 265 | 265 | |
| 266 | 266 | // do not override access to admins |
| 267 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 268 | - if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) |
|
| 269 | - || Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 267 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 268 | + if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id) |
|
| 269 | + || Sensei_Utils::user_started_course($course_id, $user_id)) { |
|
| 270 | 270 | |
| 271 | 271 | return true; |
| 272 | 272 | |
@@ -275,18 +275,18 @@ discard block |
||
| 275 | 275 | // check if the course has a valid product attached to it |
| 276 | 276 | // which the user should have purchased if they want to access |
| 277 | 277 | // the current lesson |
| 278 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 279 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 278 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 279 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 280 | 280 | $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
| 281 | - if( isset ($product) && is_object($product) ){ |
|
| 281 | + if (isset ($product) && is_object($product)) { |
|
| 282 | 282 | |
| 283 | 283 | // valid product found |
| 284 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 284 | + $order_id = self::get_learner_course_active_order_id($user_id, $course_id); |
|
| 285 | 285 | |
| 286 | 286 | // product has a successful order so this user may access the content |
| 287 | 287 | // this function may only return false or the default |
| 288 | 288 | // returning true may override other negatives which we don't want |
| 289 | - if( ! $order_id ){ |
|
| 289 | + if ( ! $order_id) { |
|
| 290 | 290 | |
| 291 | 291 | return false; |
| 292 | 292 | |
@@ -309,23 +309,23 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public static function course_link_from_order( ) { |
| 311 | 311 | |
| 312 | - if( ! is_order_received_page() ){ |
|
| 312 | + if ( ! is_order_received_page()) { |
|
| 313 | 313 | return; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $order_id = get_query_var( 'order-received' ); |
|
| 317 | - $order = new WC_Order( $order_id ); |
|
| 316 | + $order_id = get_query_var('order-received'); |
|
| 317 | + $order = new WC_Order($order_id); |
|
| 318 | 318 | |
| 319 | 319 | // exit early if not wc-completed or wc-processing |
| 320 | - if( 'wc-completed' != $order->post_status |
|
| 321 | - && 'wc-processing' != $order->post_status ) { |
|
| 320 | + if ('wc-completed' != $order->post_status |
|
| 321 | + && 'wc-processing' != $order->post_status) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | $course_links = array(); // store the for links for courses purchased |
| 326 | - foreach ( $order->get_items() as $item ) { |
|
| 326 | + foreach ($order->get_items() as $item) { |
|
| 327 | 327 | |
| 328 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 328 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 329 | 329 | |
| 330 | 330 | // If item has variation_id then its a variation of the product |
| 331 | 331 | $item_id = $item['variation_id']; |
@@ -337,28 +337,28 @@ discard block |
||
| 337 | 337 | |
| 338 | 338 | } // End If Statement |
| 339 | 339 | |
| 340 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 340 | + $user_id = get_post_meta($order->id, '_customer_user', true); |
|
| 341 | 341 | |
| 342 | - if( $user_id ) { |
|
| 342 | + if ($user_id) { |
|
| 343 | 343 | |
| 344 | 344 | // Get all courses for product |
| 345 | 345 | $args = Sensei_Course::get_default_query_args(); |
| 346 | - $args['meta_query'] = array( array( |
|
| 346 | + $args['meta_query'] = array(array( |
|
| 347 | 347 | 'key' => '_course_woocommerce_product', |
| 348 | 348 | 'value' => $item_id |
| 349 | - ) ); |
|
| 349 | + )); |
|
| 350 | 350 | $args['orderby'] = 'menu_order date'; |
| 351 | 351 | $args['order'] = 'ASC'; |
| 352 | 352 | |
| 353 | 353 | // loop through courses |
| 354 | - $courses = get_posts( $args ); |
|
| 355 | - if( $courses && count( $courses ) > 0 ) { |
|
| 354 | + $courses = get_posts($args); |
|
| 355 | + if ($courses && count($courses) > 0) { |
|
| 356 | 356 | |
| 357 | - foreach( $courses as $course ) { |
|
| 357 | + foreach ($courses as $course) { |
|
| 358 | 358 | |
| 359 | 359 | $title = $course->post_title; |
| 360 | - $permalink = get_permalink( $course->ID ); |
|
| 361 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 360 | + $permalink = get_permalink($course->ID); |
|
| 361 | + $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> '; |
|
| 362 | 362 | |
| 363 | 363 | } // end for each |
| 364 | 364 | |
@@ -369,24 +369,24 @@ discard block |
||
| 369 | 369 | }// end loop through orders |
| 370 | 370 | |
| 371 | 371 | // add the courses to the WooCommerce notice |
| 372 | - if( ! empty( $course_links) ){ |
|
| 372 | + if ( ! empty($course_links)) { |
|
| 373 | 373 | |
| 374 | 374 | $courses_html = _nx( |
| 375 | 375 | 'You have purchased the following course:', |
| 376 | 376 | 'You have purchased the following courses:', |
| 377 | - count( $course_links ), |
|
| 377 | + count($course_links), |
|
| 378 | 378 | 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
| 379 | 379 | ); |
| 380 | 380 | |
| 381 | - foreach( $course_links as $link ){ |
|
| 381 | + foreach ($course_links as $link) { |
|
| 382 | 382 | |
| 383 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 383 | + $courses_html .= '<li>'.$link.'</li>'; |
|
| 384 | 384 | |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | $courses_html .= ' </ul>'; |
| 388 | 388 | |
| 389 | - wc_add_notice( $courses_html, 'success' ); |
|
| 389 | + wc_add_notice($courses_html, 'success'); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | } // end course_link_order_form |
@@ -399,20 +399,20 @@ discard block |
||
| 399 | 399 | * |
| 400 | 400 | * @since 1.9.0 |
| 401 | 401 | */ |
| 402 | - public static function course_in_cart_message(){ |
|
| 402 | + public static function course_in_cart_message() { |
|
| 403 | 403 | |
| 404 | 404 | global $post; |
| 405 | 405 | |
| 406 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 406 | + if (self::is_course_in_cart($post->ID)) { ?> |
|
| 407 | 407 | |
| 408 | 408 | <div class="sensei-message info"> |
| 409 | 409 | <?php |
| 410 | 410 | |
| 411 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 412 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 413 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 411 | + $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url() |
|
| 412 | + . '" title="'.__('complete purchase', 'woothemes-sensei').'">' |
|
| 413 | + . __('complete the purchase', 'woothemes-sensei').'</a>'; |
|
| 414 | 414 | |
| 415 | - echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 415 | + echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link); |
|
| 416 | 416 | |
| 417 | 417 | ?> |
| 418 | 418 | </div> |
@@ -426,14 +426,14 @@ discard block |
||
| 426 | 426 | * @param $course_id |
| 427 | 427 | * @return bool |
| 428 | 428 | */ |
| 429 | - public static function is_course_in_cart( $course_id ){ |
|
| 429 | + public static function is_course_in_cart($course_id) { |
|
| 430 | 430 | |
| 431 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 432 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 431 | + $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true)); |
|
| 432 | + $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
| 433 | 433 | |
| 434 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 434 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
| 435 | 435 | |
| 436 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 436 | + if (self::is_product_in_cart($wc_post_id)) { |
|
| 437 | 437 | |
| 438 | 438 | return true; |
| 439 | 439 | |
@@ -451,20 +451,20 @@ discard block |
||
| 451 | 451 | * @param $product_id |
| 452 | 452 | * @return bool |
| 453 | 453 | */ |
| 454 | - public static function is_product_in_cart( $product_id ){ |
|
| 454 | + public static function is_product_in_cart($product_id) { |
|
| 455 | 455 | |
| 456 | - if ( 0 < $product_id ) { |
|
| 456 | + if (0 < $product_id) { |
|
| 457 | 457 | |
| 458 | - $product = wc_get_product( $product_id ); |
|
| 458 | + $product = wc_get_product($product_id); |
|
| 459 | 459 | |
| 460 | 460 | $parent_id = ''; |
| 461 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 461 | + if (isset($product->variation_id) && 0 < intval($product->variation_id)) { |
|
| 462 | 462 | $wc_product_id = $product->parent->id; |
| 463 | 463 | } |
| 464 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 464 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 465 | 465 | |
| 466 | 466 | $cart_product = $values['data']; |
| 467 | - if( $product_id == $cart_product->id ) { |
|
| 467 | + if ($product_id == $cart_product->id) { |
|
| 468 | 468 | |
| 469 | 469 | return true; |
| 470 | 470 | |
@@ -486,9 +486,9 @@ discard block |
||
| 486 | 486 | * @type int $wp_post_id |
| 487 | 487 | * } |
| 488 | 488 | */ |
| 489 | - public static function get_free_product_ids(){ |
|
| 489 | + public static function get_free_product_ids() { |
|
| 490 | 490 | |
| 491 | - return get_posts( array( |
|
| 491 | + return get_posts(array( |
|
| 492 | 492 | 'post_type' => 'product', |
| 493 | 493 | 'posts_per_page' => '1000', |
| 494 | 494 | 'fields' => 'ids', |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | * @since 1.9.0 |
| 514 | 514 | * @return array $wp_meta_query_param |
| 515 | 515 | */ |
| 516 | - public static function get_free_courses_meta_query_args(){ |
|
| 516 | + public static function get_free_courses_meta_query_args() { |
|
| 517 | 517 | |
| 518 | 518 | return array( |
| 519 | 519 | 'relation' => 'OR', |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | * @since 1.9.0 |
| 538 | 538 | * @return array $wp_query_meta_query_args_param |
| 539 | 539 | */ |
| 540 | - public static function get_paid_courses_meta_query_args(){ |
|
| 540 | + public static function get_paid_courses_meta_query_args() { |
|
| 541 | 541 | |
| 542 | 542 | $paid_product_ids = self::get_paid_product_ids(); |
| 543 | 543 | |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | 'key' => '_course_woocommerce_product', |
| 547 | 547 | // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
| 548 | 548 | // query |
| 549 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 549 | + 'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids, |
|
| 550 | 550 | 'compare' => 'IN', |
| 551 | 551 | ), |
| 552 | 552 | ); |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @since 1.9.0 |
| 561 | 561 | * @return array $product_query_args |
| 562 | 562 | */ |
| 563 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 563 | + public static function get_paid_products_on_sale_query_args() { |
|
| 564 | 564 | |
| 565 | 565 | $args = array( |
| 566 | 566 | 'post_type' => 'product', |
@@ -570,9 +570,9 @@ discard block |
||
| 570 | 570 | 'suppress_filters' => 0 |
| 571 | 571 | ); |
| 572 | 572 | |
| 573 | - $args[ 'fields' ] = 'ids'; |
|
| 573 | + $args['fields'] = 'ids'; |
|
| 574 | 574 | |
| 575 | - $args[ 'meta_query' ] = array( |
|
| 575 | + $args['meta_query'] = array( |
|
| 576 | 576 | 'relation' => 'AND', |
| 577 | 577 | array( |
| 578 | 578 | 'key'=> '_regular_price', |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | * |
| 600 | 600 | * @return array |
| 601 | 601 | */ |
| 602 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 602 | + public static function get_paid_products_not_on_sale_query_args() { |
|
| 603 | 603 | |
| 604 | 604 | $args = array( |
| 605 | 605 | 'post_type' => 'product', |
@@ -609,8 +609,8 @@ discard block |
||
| 609 | 609 | 'suppress_filters' => 0 |
| 610 | 610 | ); |
| 611 | 611 | |
| 612 | - $args[ 'fields' ] = 'ids'; |
|
| 613 | - $args[ 'meta_query' ] = array( |
|
| 612 | + $args['fields'] = 'ids'; |
|
| 613 | + $args['meta_query'] = array( |
|
| 614 | 614 | 'relation' => 'AND', |
| 615 | 615 | array( |
| 616 | 616 | 'key'=> '_regular_price', |
@@ -636,24 +636,24 @@ discard block |
||
| 636 | 636 | * |
| 637 | 637 | * @return array $woocommerce_paid_product_ids |
| 638 | 638 | */ |
| 639 | - public static function get_paid_product_ids(){ |
|
| 639 | + public static function get_paid_product_ids() { |
|
| 640 | 640 | |
| 641 | 641 | // get all the paid WooCommerce products that has regular |
| 642 | 642 | // and sale price greater than 0 |
| 643 | 643 | // will be used later to check for course with the id as meta |
| 644 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 644 | + $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args()); |
|
| 645 | 645 | |
| 646 | 646 | // get all the paid WooCommerce products that has regular price |
| 647 | 647 | // greater than 0 without a sale price |
| 648 | 648 | // will be used later to check for course with the id as meta |
| 649 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 649 | + $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args()); |
|
| 650 | 650 | |
| 651 | 651 | // combine products ID's with regular and sale price grater than zero and those without |
| 652 | 652 | // sale but regular price greater than zero |
| 653 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 653 | + $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale); |
|
| 654 | 654 | |
| 655 | 655 | // if |
| 656 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 656 | + if (empty($woocommerce_paid_product_ids)) { |
|
| 657 | 657 | return array( ); |
| 658 | 658 | } |
| 659 | 659 | return $woocommerce_paid_product_ids; |
@@ -673,24 +673,24 @@ discard block |
||
| 673 | 673 | * @param array $args |
| 674 | 674 | * @return array |
| 675 | 675 | */ |
| 676 | - public static function get_free_courses( $args = array() ){ |
|
| 676 | + public static function get_free_courses($args = array()) { |
|
| 677 | 677 | |
| 678 | 678 | $free_course_query_args = Sensei_Course::get_default_query_args(); |
| 679 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 679 | + $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args(); |
|
| 680 | 680 | |
| 681 | - if( !empty( $args ) ){ |
|
| 682 | - wp_parse_args( $args, $free_course_query_args ); |
|
| 681 | + if ( ! empty($args)) { |
|
| 682 | + wp_parse_args($args, $free_course_query_args); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | // don't show any paid courses |
| 686 | 686 | $courses = self::get_paid_courses(); |
| 687 | 687 | $ids = array(); |
| 688 | - foreach( $courses as $course ){ |
|
| 688 | + foreach ($courses as $course) { |
|
| 689 | 689 | $ids[] = $course->ID; |
| 690 | 690 | } |
| 691 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 691 | + $free_course_query_args['post__not_in'] = $ids; |
|
| 692 | 692 | |
| 693 | - return get_posts( $free_course_query_args ); |
|
| 693 | + return get_posts($free_course_query_args); |
|
| 694 | 694 | |
| 695 | 695 | } |
| 696 | 696 | |
@@ -702,17 +702,17 @@ discard block |
||
| 702 | 702 | * |
| 703 | 703 | * @return array |
| 704 | 704 | */ |
| 705 | - public static function get_paid_courses( $args = array() ){ |
|
| 705 | + public static function get_paid_courses($args = array()) { |
|
| 706 | 706 | |
| 707 | 707 | $paid_course_query_args = Sensei_Course::get_default_query_args(); |
| 708 | 708 | |
| 709 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 709 | + $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args(); |
|
| 710 | 710 | |
| 711 | - if( !empty( $args ) ){ |
|
| 712 | - wp_parse_args( $args, $paid_course_query_args ); |
|
| 711 | + if ( ! empty($args)) { |
|
| 712 | + wp_parse_args($args, $paid_course_query_args); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - return get_posts( $paid_course_query_args ); |
|
| 715 | + return get_posts($paid_course_query_args); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /** |
@@ -727,17 +727,17 @@ discard block |
||
| 727 | 727 | * @param int $course_id |
| 728 | 728 | * @return string $html markup for the button or nothing if user not allowed to buy |
| 729 | 729 | */ |
| 730 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 730 | + public static function the_add_to_cart_button_html($course_id) { |
|
| 731 | 731 | |
| 732 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id ) || self::is_course_in_cart( $course_id ) ) { |
|
| 732 | + if ( ! Sensei_Course::is_prerequisite_complete($course_id) || self::is_course_in_cart($course_id)) { |
|
| 733 | 733 | return ''; |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 736 | + $wc_post_id = self::get_course_product_id($course_id); |
|
| 737 | 737 | |
| 738 | 738 | // Check if customer purchased the product |
| 739 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 740 | - || empty( $wc_post_id ) ) { |
|
| 739 | + if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) |
|
| 740 | + || empty($wc_post_id)) { |
|
| 741 | 741 | |
| 742 | 742 | return ''; |
| 743 | 743 | |
@@ -745,15 +745,15 @@ discard block |
||
| 745 | 745 | |
| 746 | 746 | // based on simple.php in WC templates/single-product/add-to-cart/ |
| 747 | 747 | // Get the product |
| 748 | - $product = self::get_product_object( $wc_post_id ); |
|
| 748 | + $product = self::get_product_object($wc_post_id); |
|
| 749 | 749 | |
| 750 | 750 | // do not show the button for invalid products, non purchasable products, out |
| 751 | 751 | // of stock product or if course is already in cart |
| 752 | - if ( ! isset ( $product ) |
|
| 753 | - || ! is_object( $product ) |
|
| 752 | + if ( ! isset ($product) |
|
| 753 | + || ! is_object($product) |
|
| 754 | 754 | || ! $product->is_purchasable() |
| 755 | 755 | || ! $product->is_in_stock() |
| 756 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 756 | + || self::is_course_in_cart($wc_post_id)) { |
|
| 757 | 757 | |
| 758 | 758 | return ''; |
| 759 | 759 | |
@@ -764,23 +764,23 @@ discard block |
||
| 764 | 764 | // |
| 765 | 765 | ?> |
| 766 | 766 | |
| 767 | - <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
|
| 767 | + <form action="<?php echo esc_url($product->add_to_cart_url()); ?>" |
|
| 768 | 768 | class="cart" |
| 769 | 769 | method="post" |
| 770 | 770 | enctype="multipart/form-data"> |
| 771 | 771 | |
| 772 | - <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" /> |
|
| 772 | + <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" /> |
|
| 773 | 773 | |
| 774 | 774 | <input type="hidden" name="quantity" value="1" /> |
| 775 | 775 | |
| 776 | - <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?> |
|
| 776 | + <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> |
|
| 777 | 777 | |
| 778 | 778 | <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" /> |
| 779 | - <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?> |
|
| 779 | + <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> |
|
| 780 | 780 | |
| 781 | - <?php foreach( $product->variation_data as $att => $val ) { ?> |
|
| 781 | + <?php foreach ($product->variation_data as $att => $val) { ?> |
|
| 782 | 782 | |
| 783 | - <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" /> |
|
| 783 | + <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" /> |
|
| 784 | 784 | |
| 785 | 785 | <?php } ?> |
| 786 | 786 | |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | <?php } ?> |
| 790 | 790 | |
| 791 | 791 | <button type="submit" class="single_add_to_cart_button button alt"> |
| 792 | - <?php $button_text = $product->get_price_html() . ' - ' . __( 'Purchase this Course', 'woothemes-sensei' ); ?> |
|
| 792 | + <?php $button_text = $product->get_price_html().' - '.__('Purchase this Course', 'woothemes-sensei'); ?> |
|
| 793 | 793 | <?php |
| 794 | 794 | /** |
| 795 | 795 | * Filter Add to Cart button text |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | * |
| 799 | 799 | * @param string $button_text |
| 800 | 800 | */ |
| 801 | - echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text ); |
|
| 801 | + echo apply_filters('sensei_wc_single_add_to_cart_button_text', $button_text); |
|
| 802 | 802 | ?> |
| 803 | 803 | </button> |
| 804 | 804 | |
@@ -818,26 +818,26 @@ discard block |
||
| 818 | 818 | * |
| 819 | 819 | * @return string $message |
| 820 | 820 | */ |
| 821 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 821 | + public static function alter_no_permissions_message($message, $post_id) { |
|
| 822 | 822 | |
| 823 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 823 | + if (empty($post_id) || 'course' != get_post_type($post_id)) { |
|
| 824 | 824 | return $message; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 827 | + $product_id = self::get_course_product_id($post_id); |
|
| 828 | 828 | |
| 829 | - if( ! $product_id |
|
| 830 | - || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 829 | + if ( ! $product_id |
|
| 830 | + || ! self::has_customer_bought_product(get_current_user_id(), $product_id)) { |
|
| 831 | 831 | |
| 832 | 832 | return $message; |
| 833 | 833 | |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | ob_start(); |
| 837 | - self::the_course_no_permissions_message( $post_id ); |
|
| 837 | + self::the_course_no_permissions_message($post_id); |
|
| 838 | 838 | $woocommerce_course_no_permissions_message = ob_get_clean(); |
| 839 | 839 | |
| 840 | - return $woocommerce_course_no_permissions_message ; |
|
| 840 | + return $woocommerce_course_no_permissions_message; |
|
| 841 | 841 | |
| 842 | 842 | } |
| 843 | 843 | /** |
@@ -846,18 +846,18 @@ discard block |
||
| 846 | 846 | * |
| 847 | 847 | * @since 1.9.0 |
| 848 | 848 | */ |
| 849 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 849 | + public static function the_course_no_permissions_message($course_id) { |
|
| 850 | 850 | |
| 851 | 851 | // login link |
| 852 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 853 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 854 | - $wc_product_id = self::get_course_product_id( $course_id ); |
|
| 852 | + $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
| 853 | + $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>'; |
|
| 854 | + $wc_product_id = self::get_course_product_id($course_id); |
|
| 855 | 855 | |
| 856 | - if ( self::is_product_in_cart( $wc_product_id ) ) { |
|
| 856 | + if (self::is_product_in_cart($wc_product_id)) { |
|
| 857 | 857 | |
| 858 | - $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>'; |
|
| 858 | + $cart_link = '<a href="'.wc_get_checkout_url().'" title="'.__('Checkout', 'woocommerce').'">'.__('checkout', 'woocommerce').'</a>'; |
|
| 859 | 859 | |
| 860 | - $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link ); |
|
| 860 | + $message = sprintf(__('This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei'), $cart_link); |
|
| 861 | 861 | ?> |
| 862 | 862 | <span class="add-to-cart-login"> |
| 863 | 863 | <?php echo $message; ?> |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | |
| 866 | 866 | <?php |
| 867 | 867 | |
| 868 | - } elseif ( is_user_logged_in() ) { |
|
| 868 | + } elseif (is_user_logged_in()) { |
|
| 869 | 869 | |
| 870 | 870 | ?> |
| 871 | 871 | <style> |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | <?php |
| 878 | 878 | |
| 879 | 879 | } else { |
| 880 | - $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); |
|
| 880 | + $message = sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); |
|
| 881 | 881 | ?> |
| 882 | 882 | <span class="add-to-cart-login"> |
| 883 | 883 | <?php echo $message; ?> |
@@ -897,34 +897,34 @@ discard block |
||
| 897 | 897 | * |
| 898 | 898 | * @return bool |
| 899 | 899 | */ |
| 900 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 900 | + public static function has_customer_bought_product($user_id, $product_id) { |
|
| 901 | 901 | |
| 902 | - $orders = self::get_user_product_orders( $user_id, $product_id ); |
|
| 902 | + $orders = self::get_user_product_orders($user_id, $product_id); |
|
| 903 | 903 | |
| 904 | - foreach ( $orders as $order_id ) { |
|
| 904 | + foreach ($orders as $order_id) { |
|
| 905 | 905 | |
| 906 | - $order = new WC_Order( $order_id->ID ); |
|
| 906 | + $order = new WC_Order($order_id->ID); |
|
| 907 | 907 | |
| 908 | 908 | // wc-active is the subscriptions complete status |
| 909 | - if ( ! in_array( $order->post_status, array( 'wc-processing', 'wc-completed' ) ) |
|
| 910 | - || ! ( 0 < sizeof( $order->get_items() ) ) ){ |
|
| 909 | + if ( ! in_array($order->post_status, array('wc-processing', 'wc-completed')) |
|
| 910 | + || ! (0 < sizeof($order->get_items()))) { |
|
| 911 | 911 | |
| 912 | 912 | continue; |
| 913 | 913 | |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | - foreach( $order->get_items() as $item ) { |
|
| 916 | + foreach ($order->get_items() as $item) { |
|
| 917 | 917 | |
| 918 | 918 | // Check if user has bought product |
| 919 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 919 | + if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) { |
|
| 920 | 920 | |
| 921 | 921 | // Check if user has an active subscription for product |
| 922 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 923 | - $sub_key = wcs_get_subscription( $order ); |
|
| 924 | - if( $sub_key ) { |
|
| 925 | - $sub = wcs_get_subscription( $sub_key ); |
|
| 926 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 927 | - if( 'active' == $sub['status'] ) { |
|
| 922 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
| 923 | + $sub_key = wcs_get_subscription($order); |
|
| 924 | + if ($sub_key) { |
|
| 925 | + $sub = wcs_get_subscription($sub_key); |
|
| 926 | + if ($sub && isset($sub['status'])) { |
|
| 927 | + if ('active' == $sub['status']) { |
|
| 928 | 928 | return true; |
| 929 | 929 | } else { |
| 930 | 930 | return false; |
@@ -956,11 +956,11 @@ discard block |
||
| 956 | 956 | * @return string $woocommerce_product_id or false if none exist |
| 957 | 957 | * |
| 958 | 958 | */ |
| 959 | - public static function get_course_product_id( $course_id ){ |
|
| 959 | + public static function get_course_product_id($course_id) { |
|
| 960 | 960 | |
| 961 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 961 | + $product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 962 | 962 | |
| 963 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 963 | + if (empty($product_id) || 'product' != get_post_type($product_id)) { |
|
| 964 | 964 | return false; |
| 965 | 965 | } |
| 966 | 966 | |
@@ -976,11 +976,11 @@ discard block |
||
| 976 | 976 | * @param array $classes |
| 977 | 977 | * @return array |
| 978 | 978 | */ |
| 979 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 979 | + public static function add_woocommerce_body_class($classes) { |
|
| 980 | 980 | |
| 981 | - if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){ |
|
| 981 | + if ( ! in_array('woocommerce', $classes) && defined('SENSEI_NO_PERMISSION') && SENSEI_NO_PERMISSION) { |
|
| 982 | 982 | |
| 983 | - $classes[] ='woocommerce'; |
|
| 983 | + $classes[] = 'woocommerce'; |
|
| 984 | 984 | |
| 985 | 985 | } |
| 986 | 986 | |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | * |
| 999 | 999 | * @return void |
| 1000 | 1000 | */ |
| 1001 | - public static function activate_subscription( $order ) { |
|
| 1001 | + public static function activate_subscription($order) { |
|
| 1002 | 1002 | |
| 1003 | 1003 | $order_user = get_user_by('id', $order->user_id); |
| 1004 | 1004 | $user['ID'] = $order_user->ID; |
@@ -1007,13 +1007,13 @@ discard block |
||
| 1007 | 1007 | $user['user_url'] = $order_user->user_url; |
| 1008 | 1008 | |
| 1009 | 1009 | // Run through each product ordered |
| 1010 | - if ( ! sizeof($order->get_items() )>0 ) { |
|
| 1010 | + if ( ! sizeof($order->get_items()) > 0) { |
|
| 1011 | 1011 | |
| 1012 | 1012 | return; |
| 1013 | 1013 | |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | - foreach($order->get_items() as $item) { |
|
| 1016 | + foreach ($order->get_items() as $item) { |
|
| 1017 | 1017 | |
| 1018 | 1018 | $product_type = ''; |
| 1019 | 1019 | |
@@ -1028,21 +1028,21 @@ discard block |
||
| 1028 | 1028 | |
| 1029 | 1029 | } // End If Statement |
| 1030 | 1030 | |
| 1031 | - $_product = self::get_product_object( $item_id, $product_type ); |
|
| 1031 | + $_product = self::get_product_object($item_id, $product_type); |
|
| 1032 | 1032 | |
| 1033 | 1033 | // Get courses that use the WC product |
| 1034 | 1034 | $courses = array(); |
| 1035 | 1035 | |
| 1036 | - if ( ! in_array( $product_type, self::get_subscription_types() ) ) { |
|
| 1036 | + if ( ! in_array($product_type, self::get_subscription_types())) { |
|
| 1037 | 1037 | |
| 1038 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
| 1038 | + $courses = Sensei()->course->get_product_courses($item_id); |
|
| 1039 | 1039 | |
| 1040 | 1040 | } // End If Statement |
| 1041 | 1041 | |
| 1042 | 1042 | // Loop and add the user to the course. |
| 1043 | - foreach ( $courses as $course_item ){ |
|
| 1043 | + foreach ($courses as $course_item) { |
|
| 1044 | 1044 | |
| 1045 | - Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID ); |
|
| 1045 | + Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID); |
|
| 1046 | 1046 | |
| 1047 | 1047 | } // End For Loop |
| 1048 | 1048 | |
@@ -1060,13 +1060,13 @@ discard block |
||
| 1060 | 1060 | * |
| 1061 | 1061 | * @return void |
| 1062 | 1062 | */ |
| 1063 | - public static function email_course_details( $order ){ |
|
| 1063 | + public static function email_course_details($order) { |
|
| 1064 | 1064 | |
| 1065 | 1065 | global $woocommerce; |
| 1066 | 1066 | |
| 1067 | 1067 | // exit early if not wc-completed or wc-processing |
| 1068 | - if( 'wc-completed' != $order->post_status |
|
| 1069 | - && 'wc-processing' != $order->post_status ) { |
|
| 1068 | + if ('wc-completed' != $order->post_status |
|
| 1069 | + && 'wc-processing' != $order->post_status) { |
|
| 1070 | 1070 | return; |
| 1071 | 1071 | } |
| 1072 | 1072 | |
@@ -1074,16 +1074,16 @@ discard block |
||
| 1074 | 1074 | $order_id = $order->id; |
| 1075 | 1075 | |
| 1076 | 1076 | //If object have items go through them all to find course |
| 1077 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1077 | + if (0 < sizeof($order_items)) { |
|
| 1078 | 1078 | |
| 1079 | - $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1079 | + $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>'; |
|
| 1080 | 1080 | $order_contains_courses = false; |
| 1081 | 1081 | |
| 1082 | 1082 | |
| 1083 | - foreach ( $order_items as $item ) { |
|
| 1083 | + foreach ($order_items as $item) { |
|
| 1084 | 1084 | |
| 1085 | 1085 | $product_type = ''; |
| 1086 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1086 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1087 | 1087 | // If item has variation_id then its from variation |
| 1088 | 1088 | $item_id = $item['variation_id']; |
| 1089 | 1089 | $product_type = 'variation'; |
@@ -1092,9 +1092,9 @@ discard block |
||
| 1092 | 1092 | $item_id = $item['product_id']; |
| 1093 | 1093 | } // End If Statement |
| 1094 | 1094 | |
| 1095 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1095 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
| 1096 | 1096 | |
| 1097 | - if( $user_id ) { |
|
| 1097 | + if ($user_id) { |
|
| 1098 | 1098 | |
| 1099 | 1099 | // Get all courses for product |
| 1100 | 1100 | $args = array( |
@@ -1109,16 +1109,16 @@ discard block |
||
| 1109 | 1109 | 'orderby' => 'menu_order date', |
| 1110 | 1110 | 'order' => 'ASC', |
| 1111 | 1111 | ); |
| 1112 | - $courses = get_posts( $args ); |
|
| 1112 | + $courses = get_posts($args); |
|
| 1113 | 1113 | |
| 1114 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1114 | + if ($courses && count($courses) > 0) { |
|
| 1115 | 1115 | |
| 1116 | - foreach( $courses as $course ) { |
|
| 1116 | + foreach ($courses as $course) { |
|
| 1117 | 1117 | |
| 1118 | 1118 | $title = $course->post_title; |
| 1119 | - $permalink = get_permalink( $course->ID ); |
|
| 1119 | + $permalink = get_permalink($course->ID); |
|
| 1120 | 1120 | $order_contains_courses = true; |
| 1121 | - $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1121 | + $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>'; |
|
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | } // end for each order item |
| 1130 | 1130 | |
| 1131 | 1131 | // Output Course details |
| 1132 | - if( $order_contains_courses ){ |
|
| 1132 | + if ($order_contains_courses) { |
|
| 1133 | 1133 | |
| 1134 | 1134 | echo $course_details_html; |
| 1135 | 1135 | |
@@ -1147,33 +1147,33 @@ discard block |
||
| 1147 | 1147 | * @param int $order_id WC order ID |
| 1148 | 1148 | * @return void |
| 1149 | 1149 | */ |
| 1150 | - public static function complete_order ( $order_id = 0 ) { |
|
| 1150 | + public static function complete_order($order_id = 0) { |
|
| 1151 | 1151 | |
| 1152 | 1152 | $order_user = array(); |
| 1153 | 1153 | |
| 1154 | 1154 | // Check for WooCommerce |
| 1155 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 1155 | + if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) { |
|
| 1156 | 1156 | // Get order object |
| 1157 | - $order = new WC_Order( $order_id ); |
|
| 1157 | + $order = new WC_Order($order_id); |
|
| 1158 | 1158 | |
| 1159 | - if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) { |
|
| 1159 | + if ( ! in_array($order->get_status(), array('complete', 'processing'))) { |
|
| 1160 | 1160 | |
| 1161 | 1161 | return; |
| 1162 | 1162 | |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 1165 | + $user = get_user_by('id', $order->get_user_id()); |
|
| 1166 | 1166 | $order_user['ID'] = $user->ID; |
| 1167 | 1167 | $order_user['user_login'] = $user->user_login; |
| 1168 | 1168 | $order_user['user_email'] = $user->user_email; |
| 1169 | 1169 | $order_user['user_url'] = $user->user_url; |
| 1170 | 1170 | // Run through each product ordered |
| 1171 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 1171 | + if (0 < sizeof($order->get_items())) { |
|
| 1172 | 1172 | |
| 1173 | - foreach( $order->get_items() as $item ) { |
|
| 1173 | + foreach ($order->get_items() as $item) { |
|
| 1174 | 1174 | |
| 1175 | 1175 | $product_type = ''; |
| 1176 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1176 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1177 | 1177 | |
| 1178 | 1178 | $item_id = $item['variation_id']; |
| 1179 | 1179 | $product_type = 'variation'; |
@@ -1184,15 +1184,15 @@ discard block |
||
| 1184 | 1184 | |
| 1185 | 1185 | } // End If Statement |
| 1186 | 1186 | |
| 1187 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
| 1187 | + $_product = Sensei_WC::get_product_object($item_id, $product_type); |
|
| 1188 | 1188 | |
| 1189 | 1189 | // Get courses that use the WC product |
| 1190 | - $courses = Sensei()->course->get_product_courses( $_product->id ); |
|
| 1190 | + $courses = Sensei()->course->get_product_courses($_product->id); |
|
| 1191 | 1191 | |
| 1192 | 1192 | // Loop and update those courses |
| 1193 | - foreach ( $courses as $course_item ) { |
|
| 1193 | + foreach ($courses as $course_item) { |
|
| 1194 | 1194 | |
| 1195 | - $update_course = self::course_update( $course_item->ID, $order_user ); |
|
| 1195 | + $update_course = self::course_update($course_item->ID, $order_user); |
|
| 1196 | 1196 | |
| 1197 | 1197 | } // End For Loop |
| 1198 | 1198 | |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | |
| 1201 | 1201 | } // End If Statement |
| 1202 | 1202 | // Add meta to indicate that payment has been completed successfully |
| 1203 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 1203 | + update_post_meta($order_id, 'sensei_payment_complete', '1'); |
|
| 1204 | 1204 | |
| 1205 | 1205 | } // End If Statement |
| 1206 | 1206 | |
@@ -1214,34 +1214,34 @@ discard block |
||
| 1214 | 1214 | * @param integer| WC_Order $order_id order ID |
| 1215 | 1215 | * @return void |
| 1216 | 1216 | */ |
| 1217 | - public static function cancel_order ( $order_id ) { |
|
| 1217 | + public static function cancel_order($order_id) { |
|
| 1218 | 1218 | |
| 1219 | 1219 | // Get order object |
| 1220 | - if( is_object( $order_id ) ){ |
|
| 1220 | + if (is_object($order_id)) { |
|
| 1221 | 1221 | |
| 1222 | 1222 | $order = $order_id; |
| 1223 | 1223 | |
| 1224 | - }else{ |
|
| 1224 | + } else { |
|
| 1225 | 1225 | |
| 1226 | - $order = new WC_Order( $order_id ); |
|
| 1226 | + $order = new WC_Order($order_id); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | - if ( ! in_array( $order->get_status(), array( 'cancelled', 'refunded' ) ) ) { |
|
| 1229 | + if ( ! in_array($order->get_status(), array('cancelled', 'refunded'))) { |
|
| 1230 | 1230 | |
| 1231 | 1231 | return; |
| 1232 | 1232 | |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | // Run through each product ordered |
| 1236 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 1236 | + if (0 < sizeof($order->get_items())) { |
|
| 1237 | 1237 | |
| 1238 | 1238 | // Get order user |
| 1239 | - $user_id = $order->__get( 'user_id' ); |
|
| 1239 | + $user_id = $order->__get('user_id'); |
|
| 1240 | 1240 | |
| 1241 | - foreach( $order->get_items() as $item ) { |
|
| 1241 | + foreach ($order->get_items() as $item) { |
|
| 1242 | 1242 | |
| 1243 | 1243 | $product_type = ''; |
| 1244 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1244 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1245 | 1245 | |
| 1246 | 1246 | $item_id = $item['variation_id']; |
| 1247 | 1247 | $product_type = 'variation'; |
@@ -1252,20 +1252,20 @@ discard block |
||
| 1252 | 1252 | |
| 1253 | 1253 | } // End If Statement |
| 1254 | 1254 | |
| 1255 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
| 1255 | + $_product = Sensei_WC::get_product_object($item_id, $product_type); |
|
| 1256 | 1256 | |
| 1257 | 1257 | // Get courses that use the WC product |
| 1258 | 1258 | $courses = array(); |
| 1259 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
| 1259 | + $courses = Sensei()->course->get_product_courses($item_id); |
|
| 1260 | 1260 | |
| 1261 | 1261 | // Loop and update those courses |
| 1262 | - foreach ($courses as $course_item){ |
|
| 1262 | + foreach ($courses as $course_item) { |
|
| 1263 | 1263 | |
| 1264 | - if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){ |
|
| 1264 | + if (self::has_customer_bought_product($user_id, $course_item->ID)) { |
|
| 1265 | 1265 | continue; |
| 1266 | 1266 | } |
| 1267 | 1267 | // Check and Remove course from courses user meta |
| 1268 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 1268 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id); |
|
| 1269 | 1269 | |
| 1270 | 1270 | } // End For Loop |
| 1271 | 1271 | |
@@ -1286,30 +1286,30 @@ discard block |
||
| 1286 | 1286 | * @param string $product_type '' or 'variation' |
| 1287 | 1287 | * @return WC_Product $wc_product_object |
| 1288 | 1288 | */ |
| 1289 | - public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1289 | + public static function get_product_object($wc_product_id = 0, $product_type = '') { |
|
| 1290 | 1290 | |
| 1291 | 1291 | $wc_product_object = false; |
| 1292 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1292 | + if (0 < intval($wc_product_id)) { |
|
| 1293 | 1293 | |
| 1294 | 1294 | // Get the product |
| 1295 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1295 | + if (function_exists('wc_get_product')) { |
|
| 1296 | 1296 | |
| 1297 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1297 | + $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3 |
|
| 1298 | 1298 | |
| 1299 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1299 | + } elseif (function_exists('get_product')) { |
|
| 1300 | 1300 | |
| 1301 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1301 | + $wc_product_object = get_product($wc_product_id); // Post WC 2.0 |
|
| 1302 | 1302 | |
| 1303 | 1303 | } else { |
| 1304 | 1304 | |
| 1305 | 1305 | // Pre WC 2.0 |
| 1306 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1306 | + if ('variation' == $product_type || 'subscription_variation' == $product_type) { |
|
| 1307 | 1307 | |
| 1308 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1308 | + $wc_product_object = new WC_Product_Variation($wc_product_id); |
|
| 1309 | 1309 | |
| 1310 | 1310 | } else { |
| 1311 | 1311 | |
| 1312 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1312 | + $wc_product_object = new WC_Product($wc_product_id); |
|
| 1313 | 1313 | |
| 1314 | 1314 | } // End If Statement |
| 1315 | 1315 | |
@@ -1332,19 +1332,19 @@ discard block |
||
| 1332 | 1332 | * |
| 1333 | 1333 | * @return bool|int |
| 1334 | 1334 | */ |
| 1335 | - public static function course_update ( $course_id = 0, $order_user = array() ) { |
|
| 1335 | + public static function course_update($course_id = 0, $order_user = array()) { |
|
| 1336 | 1336 | |
| 1337 | 1337 | global $current_user; |
| 1338 | 1338 | |
| 1339 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 1339 | + if ( ! isset($current_user) || ! $current_user->ID > 0) return false; |
|
| 1340 | 1340 | |
| 1341 | 1341 | $data_update = false; |
| 1342 | 1342 | |
| 1343 | 1343 | // Get the product ID |
| 1344 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 1344 | + $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true); |
|
| 1345 | 1345 | |
| 1346 | 1346 | // Check if in the admin |
| 1347 | - if ( is_admin() ) { |
|
| 1347 | + if (is_admin()) { |
|
| 1348 | 1348 | |
| 1349 | 1349 | $user_login = $order_user['user_login']; |
| 1350 | 1350 | $user_email = $order_user['user_email']; |
@@ -1361,28 +1361,28 @@ discard block |
||
| 1361 | 1361 | } // End If Statement |
| 1362 | 1362 | |
| 1363 | 1363 | // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
| 1364 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 1365 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 1364 | + $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true); |
|
| 1365 | + if (0 < absint($course_prerequisite_id)) { |
|
| 1366 | 1366 | |
| 1367 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 1368 | - if ( ! $prereq_course_complete ) { |
|
| 1367 | + $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id)); |
|
| 1368 | + if ( ! $prereq_course_complete) { |
|
| 1369 | 1369 | |
| 1370 | 1370 | // Remove all course user meta |
| 1371 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 1371 | + return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
| 1372 | 1372 | |
| 1373 | 1373 | } |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 1376 | + $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id)); |
|
| 1377 | 1377 | |
| 1378 | 1378 | if ( ! $is_user_taking_course |
| 1379 | 1379 | && Sensei_WC::is_woocommerce_active() |
| 1380 | 1380 | && 0 < $wc_post_id |
| 1381 | - && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) { |
|
| 1381 | + && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id)) { |
|
| 1382 | 1382 | |
| 1383 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) ); |
|
| 1383 | + $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id)); |
|
| 1384 | 1384 | |
| 1385 | - if ( true == $activity_logged ) { |
|
| 1385 | + if (true == $activity_logged) { |
|
| 1386 | 1386 | |
| 1387 | 1387 | $is_user_taking_course = true; |
| 1388 | 1388 | |
@@ -1404,14 +1404,14 @@ discard block |
||
| 1404 | 1404 | * |
| 1405 | 1405 | * @return boolean Modified guest checkout setting |
| 1406 | 1406 | */ |
| 1407 | - public static function disable_guest_checkout( $guest_checkout ) { |
|
| 1407 | + public static function disable_guest_checkout($guest_checkout) { |
|
| 1408 | 1408 | |
| 1409 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 1409 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 1410 | 1410 | |
| 1411 | - if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) { |
|
| 1411 | + if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) { |
|
| 1412 | 1412 | |
| 1413 | - foreach( WC()->cart->cart_contents as $cart_key => $product ) { |
|
| 1414 | - if( isset( $product['product_id'] ) ) { |
|
| 1413 | + foreach (WC()->cart->cart_contents as $cart_key => $product) { |
|
| 1414 | + if (isset($product['product_id'])) { |
|
| 1415 | 1415 | |
| 1416 | 1416 | $args = array( |
| 1417 | 1417 | 'posts_per_page' => -1, |
@@ -1424,11 +1424,11 @@ discard block |
||
| 1424 | 1424 | ) |
| 1425 | 1425 | ); |
| 1426 | 1426 | |
| 1427 | - $posts = get_posts( $args ); |
|
| 1427 | + $posts = get_posts($args); |
|
| 1428 | 1428 | |
| 1429 | - if( $posts && count( $posts ) > 0 ) { |
|
| 1429 | + if ($posts && count($posts) > 0) { |
|
| 1430 | 1430 | |
| 1431 | - foreach( $posts as $course ) { |
|
| 1431 | + foreach ($posts as $course) { |
|
| 1432 | 1432 | $guest_checkout = ''; |
| 1433 | 1433 | break; |
| 1434 | 1434 | |
@@ -1457,23 +1457,23 @@ discard block |
||
| 1457 | 1457 | * |
| 1458 | 1458 | * @return string |
| 1459 | 1459 | **/ |
| 1460 | - public static function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 1460 | + public static function virtual_order_payment_complete($order_status, $order_id) { |
|
| 1461 | 1461 | |
| 1462 | - $order = new WC_Order( $order_id ); |
|
| 1462 | + $order = new WC_Order($order_id); |
|
| 1463 | 1463 | |
| 1464 | - if ( ! isset ( $order ) ) return ''; |
|
| 1464 | + if ( ! isset ($order)) return ''; |
|
| 1465 | 1465 | |
| 1466 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 1466 | + if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) { |
|
| 1467 | 1467 | |
| 1468 | 1468 | $virtual_order = true; |
| 1469 | 1469 | |
| 1470 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 1470 | + if (count($order->get_items()) > 0) { |
|
| 1471 | 1471 | |
| 1472 | - foreach( $order->get_items() as $item ) { |
|
| 1472 | + foreach ($order->get_items() as $item) { |
|
| 1473 | 1473 | |
| 1474 | - if ( $item['product_id'] > 0 ) { |
|
| 1475 | - $_product = $order->get_product_from_item( $item ); |
|
| 1476 | - if ( ! $_product->is_virtual() ) { |
|
| 1474 | + if ($item['product_id'] > 0) { |
|
| 1475 | + $_product = $order->get_product_from_item($item); |
|
| 1476 | + if ( ! $_product->is_virtual()) { |
|
| 1477 | 1477 | |
| 1478 | 1478 | $virtual_order = false; |
| 1479 | 1479 | break; |
@@ -1487,7 +1487,7 @@ discard block |
||
| 1487 | 1487 | } // End If Statement |
| 1488 | 1488 | |
| 1489 | 1489 | // virtual order, mark as completed |
| 1490 | - if ( $virtual_order ) { |
|
| 1490 | + if ($virtual_order) { |
|
| 1491 | 1491 | |
| 1492 | 1492 | return 'completed'; |
| 1493 | 1493 | |
@@ -1510,14 +1510,14 @@ discard block |
||
| 1510 | 1510 | * @param integer $user_id |
| 1511 | 1511 | * @return boolean $user_access_permission |
| 1512 | 1512 | */ |
| 1513 | - public static function get_subscription_permission( $user_access_permission , $user_id ){ |
|
| 1513 | + public static function get_subscription_permission($user_access_permission, $user_id) { |
|
| 1514 | 1514 | |
| 1515 | 1515 | global $post; |
| 1516 | 1516 | |
| 1517 | 1517 | // ignore the current case if the following conditions are met |
| 1518 | - if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id ) |
|
| 1519 | - || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) ) |
|
| 1520 | - || ! wcs_user_has_subscription( $user_id) ){ |
|
| 1518 | + if ( ! class_exists('WC_Subscriptions') || empty($user_id) |
|
| 1519 | + || ! in_array($post->post_type, array('course', 'lesson', 'quiz')) |
|
| 1520 | + || ! wcs_user_has_subscription($user_id)) { |
|
| 1521 | 1521 | |
| 1522 | 1522 | return $user_access_permission; |
| 1523 | 1523 | |
@@ -1527,25 +1527,25 @@ discard block |
||
| 1527 | 1527 | // is the subscription on the the current course? |
| 1528 | 1528 | |
| 1529 | 1529 | $course_id = 0; |
| 1530 | - if ( 'course' == $post->post_type ){ |
|
| 1530 | + if ('course' == $post->post_type) { |
|
| 1531 | 1531 | |
| 1532 | 1532 | $course_id = $post->ID; |
| 1533 | 1533 | |
| 1534 | - } elseif ( 'lesson' == $post->post_type ) { |
|
| 1534 | + } elseif ('lesson' == $post->post_type) { |
|
| 1535 | 1535 | |
| 1536 | - $course_id = Sensei()->lesson->get_course_id( $post->ID ); |
|
| 1536 | + $course_id = Sensei()->lesson->get_course_id($post->ID); |
|
| 1537 | 1537 | |
| 1538 | 1538 | } else { |
| 1539 | 1539 | |
| 1540 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 1541 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1540 | + $lesson_id = Sensei()->quiz->get_lesson_id($post->ID); |
|
| 1541 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1542 | 1542 | |
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | // if the course has no subscription WooCommerce product attached to return the permissions as is |
| 1546 | - $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
| 1547 | - $product = wc_get_product( $product_id ); |
|
| 1548 | - if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
| 1546 | + $product_id = Sensei_WC::get_course_product_id($course_id); |
|
| 1547 | + $product = wc_get_product($product_id); |
|
| 1548 | + if ( ! in_array($product->get_type(), self::get_subscription_types())) { |
|
| 1549 | 1549 | |
| 1550 | 1550 | return $user_access_permission; |
| 1551 | 1551 | |
@@ -1553,19 +1553,19 @@ discard block |
||
| 1553 | 1553 | |
| 1554 | 1554 | // give access if user has active subscription on the product otherwise restrict it. |
| 1555 | 1555 | // also check if the user was added to the course directly after the subscription started. |
| 1556 | - if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
| 1557 | - || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
| 1558 | - || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
| 1556 | + if (wcs_user_has_subscription($user_id, $product_id, 'active') |
|
| 1557 | + || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel') |
|
| 1558 | + || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) { |
|
| 1559 | 1559 | |
| 1560 | 1560 | $user_access_permission = true; |
| 1561 | 1561 | |
| 1562 | - }else{ |
|
| 1562 | + } else { |
|
| 1563 | 1563 | |
| 1564 | 1564 | $user_access_permission = false; |
| 1565 | 1565 | // do not show the WC permissions message |
| 1566 | - remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
| 1567 | - Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' ); |
|
| 1568 | - Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' ); |
|
| 1566 | + remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2); |
|
| 1567 | + Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei'); |
|
| 1568 | + Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei'); |
|
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | 1571 | return $user_access_permission; |
@@ -1581,9 +1581,9 @@ discard block |
||
| 1581 | 1581 | * |
| 1582 | 1582 | * @return bool $has_user_started_course |
| 1583 | 1583 | */ |
| 1584 | - public static function get_subscription_user_started_course( $has_user_started_course, $course_id, $user_id ){ |
|
| 1584 | + public static function get_subscription_user_started_course($has_user_started_course, $course_id, $user_id) { |
|
| 1585 | 1585 | |
| 1586 | - if ( ! is_user_logged_in( ) ) { |
|
| 1586 | + if ( ! is_user_logged_in( )) { |
|
| 1587 | 1587 | |
| 1588 | 1588 | return $has_user_started_course; |
| 1589 | 1589 | |
@@ -1591,26 +1591,26 @@ discard block |
||
| 1591 | 1591 | |
| 1592 | 1592 | // cached user course access for this process instance |
| 1593 | 1593 | global $sensei_wc_subscription_access_store; |
| 1594 | - if ( ! is_array( $sensei_wc_subscription_access_store ) ) { |
|
| 1594 | + if ( ! is_array($sensei_wc_subscription_access_store)) { |
|
| 1595 | 1595 | $sensei_wc_subscription_access_store = array(); |
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | 1598 | // user temp cached data so we don't output the mesage again |
| 1599 | - $user_data_index_key = $course_id .'_' . $user_id; |
|
| 1600 | - if ( isset( $sensei_wc_subscription_access_store[ $user_data_index_key ] ) ) { |
|
| 1599 | + $user_data_index_key = $course_id.'_'.$user_id; |
|
| 1600 | + if (isset($sensei_wc_subscription_access_store[$user_data_index_key])) { |
|
| 1601 | 1601 | |
| 1602 | - return $sensei_wc_subscription_access_store[ $user_data_index_key ]; |
|
| 1602 | + return $sensei_wc_subscription_access_store[$user_data_index_key]; |
|
| 1603 | 1603 | |
| 1604 | 1604 | } else { |
| 1605 | 1605 | |
| 1606 | - if( empty( $course_id ) || empty( $user_id ) ){ |
|
| 1606 | + if (empty($course_id) || empty($user_id)) { |
|
| 1607 | 1607 | return $has_user_started_course; |
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | // if the course has no subscription WooCommerce product attached to return the permissions as is |
| 1611 | - $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
| 1612 | - $product = wc_get_product( $product_id ); |
|
| 1613 | - if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
| 1611 | + $product_id = Sensei_WC::get_course_product_id($course_id); |
|
| 1612 | + $product = wc_get_product($product_id); |
|
| 1613 | + if ( ! in_array($product->get_type(), self::get_subscription_types())) { |
|
| 1614 | 1614 | |
| 1615 | 1615 | return $has_user_started_course; |
| 1616 | 1616 | |
@@ -1618,9 +1618,9 @@ discard block |
||
| 1618 | 1618 | |
| 1619 | 1619 | // give access if user has active subscription on the product otherwise restrict it. |
| 1620 | 1620 | // also check if the user was added to the course directly after the subscription started. |
| 1621 | - if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
| 1622 | - || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
| 1623 | - || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
| 1621 | + if (wcs_user_has_subscription($user_id, $product_id, 'active') |
|
| 1622 | + || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel') |
|
| 1623 | + || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) { |
|
| 1624 | 1624 | |
| 1625 | 1625 | $has_user_started_course = true; |
| 1626 | 1626 | |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | $has_user_started_course = false; |
| 1630 | 1630 | |
| 1631 | 1631 | } |
| 1632 | - $sensei_wc_subscription_access_store[ $user_data_index_key ] = $has_user_started_course; |
|
| 1632 | + $sensei_wc_subscription_access_store[$user_data_index_key] = $has_user_started_course; |
|
| 1633 | 1633 | return $has_user_started_course; |
| 1634 | 1634 | } |
| 1635 | 1635 | |
@@ -1641,9 +1641,9 @@ discard block |
||
| 1641 | 1641 | * @since 1.9.0 |
| 1642 | 1642 | * @return array |
| 1643 | 1643 | */ |
| 1644 | - public static function get_subscription_types(){ |
|
| 1644 | + public static function get_subscription_types() { |
|
| 1645 | 1645 | |
| 1646 | - return array( 'subscription','subscription_variation','variable-subscription' ); |
|
| 1646 | + return array('subscription', 'subscription_variation', 'variable-subscription'); |
|
| 1647 | 1647 | |
| 1648 | 1648 | } |
| 1649 | 1649 | |
@@ -1663,16 +1663,16 @@ discard block |
||
| 1663 | 1663 | * |
| 1664 | 1664 | * @return bool |
| 1665 | 1665 | */ |
| 1666 | - public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){ |
|
| 1666 | + public static function was_user_added_without_subscription($user_id, $product_id, $course_id) { |
|
| 1667 | 1667 | |
| 1668 | 1668 | $course_start_date = ''; |
| 1669 | 1669 | $subscription_start_date = ''; |
| 1670 | - $is_a_subscription =''; |
|
| 1670 | + $is_a_subscription = ''; |
|
| 1671 | 1671 | $was_user_added_without_subscription = false; |
| 1672 | 1672 | |
| 1673 | 1673 | // if user is not on the course they were not added |
| 1674 | - remove_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 1675 | - if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1674 | + remove_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3); |
|
| 1675 | + if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) { |
|
| 1676 | 1676 | |
| 1677 | 1677 | return false; |
| 1678 | 1678 | |
@@ -1681,36 +1681,36 @@ discard block |
||
| 1681 | 1681 | // if user doesn't have a subscription and is taking the course |
| 1682 | 1682 | // they were added manually |
| 1683 | 1683 | if ( ! wcs_user_has_subscription($user_id, $product_id) |
| 1684 | - && Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){ |
|
| 1684 | + && Sensei_Utils::user_started_course($course_id, get_current_user_id())) { |
|
| 1685 | 1685 | |
| 1686 | 1686 | return true; |
| 1687 | 1687 | |
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | - add_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 1690 | + add_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3); |
|
| 1691 | 1691 | |
| 1692 | - $course_status = Sensei_Utils::user_course_status( $course_id, $user_id ); |
|
| 1692 | + $course_status = Sensei_Utils::user_course_status($course_id, $user_id); |
|
| 1693 | 1693 | |
| 1694 | 1694 | // comparing dates setup data |
| 1695 | - $course_start_date = date_create( $course_status->comment_date ); |
|
| 1696 | - $subscriptions = wcs_get_users_subscriptions( $user_id ); |
|
| 1695 | + $course_start_date = date_create($course_status->comment_date); |
|
| 1696 | + $subscriptions = wcs_get_users_subscriptions($user_id); |
|
| 1697 | 1697 | |
| 1698 | 1698 | // comparing every subscription |
| 1699 | - foreach( $subscriptions as $subscription ){ |
|
| 1699 | + foreach ($subscriptions as $subscription) { |
|
| 1700 | 1700 | |
| 1701 | 1701 | // for the following statuses we know the user was not added |
| 1702 | 1702 | // manually |
| 1703 | 1703 | $status = $subscription->get_status(); |
| 1704 | - if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) { |
|
| 1704 | + if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) { |
|
| 1705 | 1705 | |
| 1706 | 1706 | continue; |
| 1707 | 1707 | |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | - $current_subscription_start_date = date_create( $subscription->modified_date ); |
|
| 1710 | + $current_subscription_start_date = date_create($subscription->modified_date); |
|
| 1711 | 1711 | |
| 1712 | 1712 | // is the last updated subscription date newer than course start date |
| 1713 | - if ( $current_subscription_start_date > $course_start_date ) { |
|
| 1713 | + if ($current_subscription_start_date > $course_start_date) { |
|
| 1714 | 1714 | |
| 1715 | 1715 | return false; |
| 1716 | 1716 | |
@@ -1729,20 +1729,20 @@ discard block |
||
| 1729 | 1729 | * |
| 1730 | 1730 | * @return array $orders |
| 1731 | 1731 | */ |
| 1732 | - public static function get_user_product_orders( $user_id = 0, $product_id ) { |
|
| 1732 | + public static function get_user_product_orders($user_id = 0, $product_id) { |
|
| 1733 | 1733 | |
| 1734 | 1734 | $args = array( |
| 1735 | 1735 | 'numberposts' => -1, |
| 1736 | 1736 | 'post_type' => 'shop_order', |
| 1737 | 1737 | 'meta_key' => '_customer_user', |
| 1738 | - 'meta_value' => intval( $user_id ), |
|
| 1738 | + 'meta_value' => intval($user_id), |
|
| 1739 | 1739 | ); |
| 1740 | 1740 | |
| 1741 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 1742 | - $args['post_type'] = array( 'shop_order', 'shop_subscription' ); |
|
| 1741 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
| 1742 | + $args['post_type'] = array('shop_order', 'shop_subscription'); |
|
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | - return get_posts( $args ); |
|
| 1745 | + return get_posts($args); |
|
| 1746 | 1746 | |
| 1747 | 1747 | } |
| 1748 | 1748 | |
@@ -1758,12 +1758,12 @@ discard block |
||
| 1758 | 1758 | * |
| 1759 | 1759 | * @return bool |
| 1760 | 1760 | */ |
| 1761 | - public static function is_course_purchasable( $course_id = 0 ){ |
|
| 1761 | + public static function is_course_purchasable($course_id = 0) { |
|
| 1762 | 1762 | |
| 1763 | - if( ! self::is_woocommerce_active() ){ |
|
| 1763 | + if ( ! self::is_woocommerce_active()) { |
|
| 1764 | 1764 | return false; |
| 1765 | 1765 | } |
| 1766 | - $course_product = wc_get_product( self::get_course_product_id( $course_id ) ); |
|
| 1766 | + $course_product = wc_get_product(self::get_course_product_id($course_id)); |
|
| 1767 | 1767 | |
| 1768 | 1768 | return $course_product->is_purchasable(); |
| 1769 | 1769 | |
@@ -7,20 +7,20 @@ discard block |
||
| 7 | 7 | * show the WooCommerce course filter links above the courses |
| 8 | 8 | * @since 1.9.0 |
| 9 | 9 | */ |
| 10 | -add_filter( 'sensei_archive_course_filter_by_options', array( 'Sensei_WC', 'add_course_archive_wc_filter_links' ) ); |
|
| 10 | +add_filter('sensei_archive_course_filter_by_options', array('Sensei_WC', 'add_course_archive_wc_filter_links')); |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * filter the queries for paid and free course based on the users selection. |
| 14 | 14 | * @since 1.9.0 |
| 15 | 15 | */ |
| 16 | -add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_free')); |
|
| 17 | -add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_paid')); |
|
| 16 | +add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_free')); |
|
| 17 | +add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_paid')); |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Add woocommerce action above single course the action |
| 21 | 21 | * @since 1.9.0 |
| 22 | 22 | */ |
| 23 | -add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action') ,50) ; |
|
| 23 | +add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action'), 50); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /****************************** |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * Single Lesson Hooks |
| 29 | 29 | * |
| 30 | 30 | ******************************/ |
| 31 | -add_filter( 'sensei_can_user_view_lesson', array( 'Sensei_WC','alter_can_user_view_lesson' ), 20, 3 ); |
|
| 31 | +add_filter('sensei_can_user_view_lesson', array('Sensei_WC', 'alter_can_user_view_lesson'), 20, 3); |
|
| 32 | 32 | |
| 33 | 33 | /****************************** |
| 34 | 34 | * |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | ******************************/ |
| 38 | 38 | // add a notice on the checkout page to tell users about the course they've purchase |
| 39 | -add_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) ); |
|
| 39 | +add_action('template_redirect', array('Sensei_WC', 'course_link_from_order')); |
|
| 40 | 40 | |
| 41 | 41 | /****************************** |
| 42 | 42 | * |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | ******************************/ |
| 46 | 46 | //@since 1.9.0 |
| 47 | 47 | //show a notice if the user has already added the current course to their cart |
| 48 | -add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_WC', 'course_in_cart_message' ), 20 ); |
|
| 48 | +add_action('sensei_single_course_content_inside_before', array('Sensei_WC', 'course_in_cart_message'), 20); |
|
| 49 | 49 | |
| 50 | 50 | /****************************** |
| 51 | 51 | * |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | ******************************/ |
| 55 | 55 | //@since 1.9.0 |
| 56 | 56 | // alter the no permissions message to show the woocommerce message instead |
| 57 | -add_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
| 57 | +add_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2); |
|
| 58 | 58 | |
| 59 | 59 | // @since 1.9.0 |
| 60 | 60 | // add woocommerce class to the the no permission body class to ensure WooCommerce elements are styled |
| 61 | -add_filter( 'body_class', array( 'Sensei_WC', 'add_woocommerce_body_class' ), 20, 1); |
|
| 61 | +add_filter('body_class', array('Sensei_WC', 'add_woocommerce_body_class'), 20, 1); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | /************************************ |
@@ -67,28 +67,28 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | ************************************/ |
| 69 | 69 | // Add Email link to course orders |
| 70 | -add_action( 'woocommerce_email_after_order_table', array( 'Sensei_WC', 'email_course_details' ), 10, 1 ); |
|
| 70 | +add_action('woocommerce_email_after_order_table', array('Sensei_WC', 'email_course_details'), 10, 1); |
|
| 71 | 71 | |
| 72 | 72 | /************************************ |
| 73 | 73 | * |
| 74 | 74 | * Checkout |
| 75 | 75 | * |
| 76 | 76 | ************************************/ |
| 77 | -add_action( 'woocommerce_delete_shop_order_transients', array( 'Sensei_WC', 'complete_order' ) ); |
|
| 78 | -add_action( 'woocommerce_delete_shop_order_transients', array( 'Sensei_WC', 'cancel_order' ) ); |
|
| 77 | +add_action('woocommerce_delete_shop_order_transients', array('Sensei_WC', 'complete_order')); |
|
| 78 | +add_action('woocommerce_delete_shop_order_transients', array('Sensei_WC', 'cancel_order')); |
|
| 79 | 79 | // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
| 80 | -add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( 'Sensei_WC', 'disable_guest_checkout' ) ); |
|
| 80 | +add_filter('pre_option_woocommerce_enable_guest_checkout', array('Sensei_WC', 'disable_guest_checkout')); |
|
| 81 | 81 | // Mark orders with virtual products as complete rather then stay processing |
| 82 | -add_filter( 'woocommerce_payment_complete_order_status', array( 'Sensei_WC', 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 82 | +add_filter('woocommerce_payment_complete_order_status', array('Sensei_WC', 'virtual_order_payment_complete'), 10, 2); |
|
| 83 | 83 | |
| 84 | 84 | /************************************ |
| 85 | 85 | * |
| 86 | 86 | * WooCommerce Subscriptions |
| 87 | 87 | * |
| 88 | 88 | ************************************/ |
| 89 | -add_action( 'woocommerce_subscription_status_pending_to_active', array( 'Sensei_WC', 'activate_subscription' ), 50, 3 ); |
|
| 89 | +add_action('woocommerce_subscription_status_pending_to_active', array('Sensei_WC', 'activate_subscription'), 50, 3); |
|
| 90 | 90 | // filter the user permission of the subscription is not valid |
| 91 | -add_filter( 'sensei_access_permissions', array( 'Sensei_WC', 'get_subscription_permission' ), 10, 2 ); |
|
| 91 | +add_filter('sensei_access_permissions', array('Sensei_WC', 'get_subscription_permission'), 10, 2); |
|
| 92 | 92 | |
| 93 | 93 | //block user from accessing course when subscription |
| 94 | -add_filter( 'sensei_user_started_course', array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 ); |
|
| 94 | +add_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3); |
|