@@ -13,21 +13,21 @@ discard block |
||
| 13 | 13 | * @since 1.0.0 |
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course { |
| 16 | - /** |
|
| 17 | - * @var $token |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var $token |
|
| 18 | + */ |
|
| 19 | 19 | public $token; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array $meta_fields |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var array $meta_fields |
|
| 23 | + */ |
|
| 24 | 24 | public $meta_fields; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string|bool $my_courses_page reference to the sites |
|
| 28 | - * my courses page, false if none was set |
|
| 29 | - */ |
|
| 30 | - public $my_courses_page; |
|
| 26 | + /** |
|
| 27 | + * @var string|bool $my_courses_page reference to the sites |
|
| 28 | + * my courses page, false if none was set |
|
| 29 | + */ |
|
| 30 | + public $my_courses_page; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Constructor. |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct () { |
| 37 | 37 | |
| 38 | - $this->token = 'course'; |
|
| 38 | + $this->token = 'course'; |
|
| 39 | 39 | |
| 40 | 40 | // Setup meta fields for this post type |
| 41 | 41 | $this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' ); |
| 42 | 42 | // Admin actions |
| 43 | 43 | if ( is_admin() ) { |
| 44 | 44 | // Metabox functions |
| 45 | - add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 45 | + add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 46 | 46 | add_action( 'save_post', array( $this, 'meta_box_save' ) ); |
| 47 | 47 | // Custom Write Panel Columns |
| 48 | 48 | add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
@@ -58,47 +58,47 @@ discard block |
||
| 58 | 58 | // Update course completion upon grading of a quiz |
| 59 | 59 | add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 ); |
| 60 | 60 | |
| 61 | - // show the progress bar ont he single course page |
|
| 62 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 61 | + // show the progress bar ont he single course page |
|
| 62 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 64 | 64 | |
| 65 | - // provide an option to block all emails related to a selected course |
|
| 66 | - add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | - add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 65 | + // provide an option to block all emails related to a selected course |
|
| 66 | + add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | + add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 68 | 68 | |
| 69 | - // preview lessons on the course content |
|
| 70 | - add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 69 | + // preview lessons on the course content |
|
| 70 | + add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 71 | 71 | |
| 72 | - // the course meta |
|
| 73 | - add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 72 | + // the course meta |
|
| 73 | + add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 74 | 74 | |
| 75 | - // backwards compatible template hooks |
|
| 76 | - add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | - add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 75 | + // backwards compatible template hooks |
|
| 76 | + add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | + add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 78 | 78 | |
| 79 | - // add the user status on the course to the markup as a class |
|
| 80 | - add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 79 | + // add the user status on the course to the markup as a class |
|
| 80 | + add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 81 | 81 | |
| 82 | - //filter the course query in Sensei specific instances |
|
| 83 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 82 | + //filter the course query in Sensei specific instances |
|
| 83 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 84 | 84 | |
| 85 | - //attache the sorting to the course archive |
|
| 86 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 85 | + //attache the sorting to the course archive |
|
| 86 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 87 | 87 | |
| 88 | - //attach the filter links to the course archive |
|
| 89 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 88 | + //attach the filter links to the course archive |
|
| 89 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 90 | 90 | |
| 91 | - //filter the course query when featured filter is applied |
|
| 92 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 91 | + //filter the course query when featured filter is applied |
|
| 92 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 93 | 93 | |
| 94 | - // handle the order by title post submission |
|
| 95 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 94 | + // handle the order by title post submission |
|
| 95 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 96 | 96 | |
| 97 | - // ensure the course category page respects the manual order set for courses |
|
| 98 | - add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 97 | + // ensure the course category page respects the manual order set for courses |
|
| 98 | + add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 99 | 99 | |
| 100 | - // flush rewrite rules when saving a course |
|
| 101 | - add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 100 | + // flush rewrite rules when saving a course |
|
| 101 | + add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 102 | 102 | |
| 103 | 103 | } // End __construct() |
| 104 | 104 | |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 152 | 152 | // Add Meta Box for Course Lessons |
| 153 | 153 | add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 154 | - // Add Meta Box to link to Manage Learners |
|
| 155 | - add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 156 | - // Remove "Custom Settings" meta box. |
|
| 154 | + // Add Meta Box to link to Manage Learners |
|
| 155 | + add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 156 | + // Remove "Custom Settings" meta box. |
|
| 157 | 157 | remove_meta_box( 'woothemes-settings', $this->token, 'normal' ); |
| 158 | 158 | |
| 159 | - // add Disable email notification box |
|
| 160 | - add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 159 | + // add Disable email notification box |
|
| 160 | + add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 161 | 161 | |
| 162 | 162 | } // End meta_box_setup() |
| 163 | 163 | |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | $post_args = array( 'post_type' => array( 'product', 'product_variation' ), |
| 176 | 176 | 'posts_per_page' => -1, |
| 177 | 177 | 'orderby' => 'title', |
| 178 | - 'order' => 'DESC', |
|
| 179 | - 'exclude' => $post->ID, |
|
| 180 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 181 | - 'tax_query' => array( |
|
| 178 | + 'order' => 'DESC', |
|
| 179 | + 'exclude' => $post->ID, |
|
| 180 | + 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 181 | + 'tax_query' => array( |
|
| 182 | 182 | array( |
| 183 | 183 | 'taxonomy' => 'product_type', |
| 184 | 184 | 'field' => 'slug', |
@@ -206,21 +206,21 @@ discard block |
||
| 206 | 206 | $product_object = get_product( $post_item->ID ); |
| 207 | 207 | $parent_id = wp_get_post_parent_id( $post_item->ID ); |
| 208 | 208 | |
| 209 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 209 | + if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 210 | 210 | $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
| 211 | 211 | |
| 212 | 212 | } else { |
| 213 | - // fall back to pre wc 2.1 |
|
| 213 | + // fall back to pre wc 2.1 |
|
| 214 | 214 | $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
| 215 | 215 | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $product_name = ucwords( $formatted_variation ); |
|
| 219 | - if( empty( $product_name ) ){ |
|
| 218 | + $product_name = ucwords( $formatted_variation ); |
|
| 219 | + if( empty( $product_name ) ){ |
|
| 220 | 220 | |
| 221 | - $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 221 | + $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | } else { |
| 226 | 226 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | } else { |
| 272 | 272 | |
| 273 | - $html .= '<p>' . "\n"; |
|
| 273 | + $html .= '<p>' . "\n"; |
|
| 274 | 274 | $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n"; |
| 275 | 275 | $html .= '</p>'."\n"; |
| 276 | 276 | |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | $post_args = array( 'post_type' => 'course', |
| 297 | 297 | 'posts_per_page' => -1, |
| 298 | 298 | 'orderby' => 'title', |
| 299 | - 'order' => 'DESC', |
|
| 300 | - 'exclude' => $post->ID, |
|
| 299 | + 'order' => 'DESC', |
|
| 300 | + 'exclude' => $post->ID, |
|
| 301 | 301 | 'suppress_filters' => 0 |
| 302 | 302 | ); |
| 303 | 303 | $posts_array = get_posts( $post_args ); |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | $checked = ''; |
| 340 | 340 | if ( isset( $course_featured ) && ( '' != $course_featured ) ) { |
| 341 | - $checked = checked( 'featured', $course_featured, false ); |
|
| 341 | + $checked = checked( 'featured', $course_featured, false ); |
|
| 342 | 342 | } // End If Statement |
| 343 | 343 | |
| 344 | 344 | $html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '> ' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>'; |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
| 434 | 434 | } // End If Statement |
| 435 | 435 | |
| 436 | - // update field with the new value |
|
| 437 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 436 | + // update field with the new value |
|
| 437 | + return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 438 | 438 | |
| 439 | 439 | } // End save_post_meta() |
| 440 | 440 | |
@@ -458,8 +458,8 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | $html = ''; |
| 460 | 460 | $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' |
| 461 | - . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | - . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 461 | + . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | + . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 463 | 463 | |
| 464 | 464 | if ( count( $posts_array ) > 0 ) { |
| 465 | 465 | |
@@ -480,8 +480,8 @@ discard block |
||
| 480 | 480 | $html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n"; |
| 481 | 481 | |
| 482 | 482 | $html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id ) |
| 483 | - . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | - . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 483 | + . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | + . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 485 | 485 | |
| 486 | 486 | $html .= '</p>'."\n"; |
| 487 | 487 | } // End If Statement |
@@ -490,29 +490,29 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | } // End course_lessons_meta_box_content() |
| 492 | 492 | |
| 493 | - /** |
|
| 494 | - * course_manage_meta_box_content function. |
|
| 495 | - * |
|
| 496 | - * @since 1.9.0 |
|
| 497 | - * @access public |
|
| 498 | - * @return void |
|
| 499 | - */ |
|
| 493 | + /** |
|
| 494 | + * course_manage_meta_box_content function. |
|
| 495 | + * |
|
| 496 | + * @since 1.9.0 |
|
| 497 | + * @access public |
|
| 498 | + * @return void |
|
| 499 | + */ |
|
| 500 | 500 | |
| 501 | - public function course_manage_meta_box_content () { |
|
| 502 | - global $post; |
|
| 501 | + public function course_manage_meta_box_content () { |
|
| 502 | + global $post; |
|
| 503 | 503 | |
| 504 | - $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 504 | + $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 505 | 505 | |
| 506 | - $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 506 | + $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 507 | 507 | |
| 508 | 508 | |
| 509 | - echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 509 | + echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 510 | 510 | |
| 511 | - echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 511 | + echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 512 | 512 | |
| 513 | 513 | |
| 514 | 514 | |
| 515 | - } // End course_manage_meta_box_content() |
|
| 515 | + } // End course_manage_meta_box_content() |
|
| 516 | 516 | |
| 517 | 517 | /** |
| 518 | 518 | * Add column headings to the "lesson" post list screen. |
@@ -653,92 +653,92 @@ discard block |
||
| 653 | 653 | } // End If Statement |
| 654 | 654 | } // End If Statement |
| 655 | 655 | |
| 656 | - $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 657 | - $order = 'ASC'; |
|
| 658 | - $orderby = 'menu_order'; |
|
| 659 | - if( empty( $stored_order ) ){ |
|
| 656 | + $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 657 | + $order = 'ASC'; |
|
| 658 | + $orderby = 'menu_order'; |
|
| 659 | + if( empty( $stored_order ) ){ |
|
| 660 | 660 | |
| 661 | - $order = 'DESC'; |
|
| 662 | - $orderby = 'date'; |
|
| 661 | + $order = 'DESC'; |
|
| 662 | + $orderby = 'date'; |
|
| 663 | 663 | |
| 664 | - } |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | switch ($type) { |
| 667 | 667 | |
| 668 | 668 | case 'usercourses': |
| 669 | 669 | $post_args = array( 'post_type' => 'course', |
| 670 | 670 | 'orderby' => $orderby, |
| 671 | - 'order' => $order, |
|
| 672 | - 'post_status' => 'publish', |
|
| 673 | - 'include' => $includes, |
|
| 674 | - 'exclude' => $excludes, |
|
| 675 | - 'suppress_filters' => 0 |
|
| 671 | + 'order' => $order, |
|
| 672 | + 'post_status' => 'publish', |
|
| 673 | + 'include' => $includes, |
|
| 674 | + 'exclude' => $excludes, |
|
| 675 | + 'suppress_filters' => 0 |
|
| 676 | 676 | ); |
| 677 | 677 | break; |
| 678 | 678 | case 'freecourses': |
| 679 | 679 | |
| 680 | - $post_args = array( |
|
| 681 | - 'post_type' => 'course', |
|
| 682 | - 'orderby' => $orderby, |
|
| 683 | - 'order' => $order, |
|
| 684 | - 'post_status' => 'publish', |
|
| 685 | - 'exclude' => $excludes, |
|
| 686 | - 'suppress_filters' => 0 |
|
| 687 | - ); |
|
| 688 | - // Sub Query to get all WooCommerce Products that have Zero price |
|
| 689 | - $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 680 | + $post_args = array( |
|
| 681 | + 'post_type' => 'course', |
|
| 682 | + 'orderby' => $orderby, |
|
| 683 | + 'order' => $order, |
|
| 684 | + 'post_status' => 'publish', |
|
| 685 | + 'exclude' => $excludes, |
|
| 686 | + 'suppress_filters' => 0 |
|
| 687 | + ); |
|
| 688 | + // Sub Query to get all WooCommerce Products that have Zero price |
|
| 689 | + $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 690 | 690 | |
| 691 | - break; |
|
| 691 | + break; |
|
| 692 | 692 | |
| 693 | 693 | case 'paidcourses': |
| 694 | 694 | |
| 695 | - $post_args = array( |
|
| 696 | - 'post_type' => 'course', |
|
| 697 | - 'orderby' => $orderby, |
|
| 698 | - 'order' => $order, |
|
| 699 | - 'post_status' => 'publish', |
|
| 700 | - 'exclude' => $excludes, |
|
| 701 | - 'suppress_filters' => 0 |
|
| 702 | - ); |
|
| 695 | + $post_args = array( |
|
| 696 | + 'post_type' => 'course', |
|
| 697 | + 'orderby' => $orderby, |
|
| 698 | + 'order' => $order, |
|
| 699 | + 'post_status' => 'publish', |
|
| 700 | + 'exclude' => $excludes, |
|
| 701 | + 'suppress_filters' => 0 |
|
| 702 | + ); |
|
| 703 | 703 | |
| 704 | - // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 705 | - $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 704 | + // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 705 | + $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 706 | 706 | |
| 707 | 707 | break; |
| 708 | 708 | |
| 709 | 709 | case 'featuredcourses': |
| 710 | - $post_args = array( 'post_type' => 'course', |
|
| 711 | - 'orderby' => $orderby, |
|
| 712 | - 'order' => $order, |
|
| 713 | - 'post_status' => 'publish', |
|
| 714 | - 'meta_value' => 'featured', |
|
| 715 | - 'meta_key' => '_course_featured', |
|
| 716 | - 'meta_compare' => '=', |
|
| 717 | - 'exclude' => $excludes, |
|
| 718 | - 'suppress_filters' => 0 |
|
| 710 | + $post_args = array( 'post_type' => 'course', |
|
| 711 | + 'orderby' => $orderby, |
|
| 712 | + 'order' => $order, |
|
| 713 | + 'post_status' => 'publish', |
|
| 714 | + 'meta_value' => 'featured', |
|
| 715 | + 'meta_key' => '_course_featured', |
|
| 716 | + 'meta_compare' => '=', |
|
| 717 | + 'exclude' => $excludes, |
|
| 718 | + 'suppress_filters' => 0 |
|
| 719 | 719 | ); |
| 720 | 720 | break; |
| 721 | 721 | default: |
| 722 | 722 | $post_args = array( 'post_type' => 'course', |
| 723 | - 'orderby' => $orderby, |
|
| 724 | - 'order' => $order, |
|
| 725 | - 'post_status' => 'publish', |
|
| 726 | - 'exclude' => $excludes, |
|
| 727 | - 'suppress_filters' => 0 |
|
| 723 | + 'orderby' => $orderby, |
|
| 724 | + 'order' => $order, |
|
| 725 | + 'post_status' => 'publish', |
|
| 726 | + 'exclude' => $excludes, |
|
| 727 | + 'suppress_filters' => 0 |
|
| 728 | 728 | ); |
| 729 | 729 | break; |
| 730 | 730 | |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | - $post_args['posts_per_page'] = $amount; |
|
| 734 | - $paged = $wp_query->get( 'paged' ); |
|
| 735 | - $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 733 | + $post_args['posts_per_page'] = $amount; |
|
| 734 | + $paged = $wp_query->get( 'paged' ); |
|
| 735 | + $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 736 | 736 | |
| 737 | - if( 'newcourses' == $type ){ |
|
| 737 | + if( 'newcourses' == $type ){ |
|
| 738 | 738 | |
| 739 | - $post_args[ 'orderby' ] = 'date'; |
|
| 740 | - $post_args[ 'order' ] = 'DESC'; |
|
| 741 | - } |
|
| 739 | + $post_args[ 'orderby' ] = 'date'; |
|
| 740 | + $post_args[ 'order' ] = 'DESC'; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | 743 | return $post_args; |
| 744 | 744 | } |
@@ -748,22 +748,22 @@ discard block |
||
| 748 | 748 | * course_image function. |
| 749 | 749 | * |
| 750 | 750 | * Outputs the courses image, or first image from a lesson within a course |
| 751 | - * |
|
| 752 | - * Will echo the image unless return true is specified. |
|
| 751 | + * |
|
| 752 | + * Will echo the image unless return true is specified. |
|
| 753 | 753 | * |
| 754 | 754 | * @access public |
| 755 | 755 | * @param int | WP_Post $course_id (default: 0) |
| 756 | 756 | * @param string $width (default: '100') |
| 757 | 757 | * @param string $height (default: '100') |
| 758 | - * @param bool $return default false |
|
| 759 | - * |
|
| 758 | + * @param bool $return default false |
|
| 759 | + * |
|
| 760 | 760 | * @return string | void |
| 761 | 761 | */ |
| 762 | 762 | public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) { |
| 763 | 763 | |
| 764 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 765 | - $course_id = $course_id->ID; |
|
| 766 | - } |
|
| 764 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 765 | + $course_id = $course_id->ID; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | $html = ''; |
| 769 | 769 | |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | // Display Image Placeholder if none |
| 821 | 821 | if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) { |
| 822 | 822 | |
| 823 | - $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 823 | + $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 824 | 824 | |
| 825 | 825 | } // End If Statement |
| 826 | 826 | |
@@ -834,15 +834,15 @@ discard block |
||
| 834 | 834 | |
| 835 | 835 | } // End If Statement |
| 836 | 836 | |
| 837 | - if( $return ){ |
|
| 837 | + if( $return ){ |
|
| 838 | 838 | |
| 839 | - return $html; |
|
| 839 | + return $html; |
|
| 840 | 840 | |
| 841 | - }else{ |
|
| 841 | + }else{ |
|
| 842 | 842 | |
| 843 | - echo $html; |
|
| 843 | + echo $html; |
|
| 844 | 844 | |
| 845 | - } |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | 847 | } // End course_image() |
| 848 | 848 | |
@@ -886,9 +886,9 @@ discard block |
||
| 886 | 886 | */ |
| 887 | 887 | public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) { |
| 888 | 888 | |
| 889 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 890 | - $course_id = $course_id->ID; |
|
| 891 | - } |
|
| 889 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 890 | + $course_id = $course_id->ID; |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | 893 | $post_args = array( 'post_type' => 'lesson', |
| 894 | 894 | 'posts_per_page' => -1, |
@@ -904,67 +904,67 @@ discard block |
||
| 904 | 904 | 'suppress_filters' => 0, |
| 905 | 905 | ); |
| 906 | 906 | $query_results = new WP_Query( $post_args ); |
| 907 | - $lessons = $query_results->posts; |
|
| 908 | - |
|
| 909 | - // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 910 | - // with the course order for a different course and this should not be included. It could also not |
|
| 911 | - // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 912 | - // that have been added to the course. |
|
| 913 | - if( count( $lessons) > 1 ){ |
|
| 914 | - |
|
| 915 | - foreach( $lessons as $lesson ){ |
|
| 916 | - |
|
| 917 | - $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 918 | - // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 919 | - $lesson->course_order = $order ? $order : 100000; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * Filter runs inside Sensei_Course::course_lessons function |
|
| 927 | - * |
|
| 928 | - * Returns all lessons for a given course |
|
| 929 | - * |
|
| 930 | - * @param array $lessons |
|
| 931 | - * @param int $course_id |
|
| 932 | - */ |
|
| 933 | - $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 934 | - |
|
| 935 | - //return the requested fields |
|
| 936 | - // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 937 | - // objects |
|
| 938 | - if( 'ids' == $fields ) { |
|
| 939 | - $lesson_objects = $lessons; |
|
| 940 | - $lessons = array(); |
|
| 941 | - |
|
| 942 | - foreach ($lesson_objects as $lesson) { |
|
| 943 | - $lessons[] = $lesson->ID; |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - return $lessons; |
|
| 907 | + $lessons = $query_results->posts; |
|
| 908 | + |
|
| 909 | + // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 910 | + // with the course order for a different course and this should not be included. It could also not |
|
| 911 | + // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 912 | + // that have been added to the course. |
|
| 913 | + if( count( $lessons) > 1 ){ |
|
| 914 | + |
|
| 915 | + foreach( $lessons as $lesson ){ |
|
| 916 | + |
|
| 917 | + $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 918 | + // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 919 | + $lesson->course_order = $order ? $order : 100000; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * Filter runs inside Sensei_Course::course_lessons function |
|
| 927 | + * |
|
| 928 | + * Returns all lessons for a given course |
|
| 929 | + * |
|
| 930 | + * @param array $lessons |
|
| 931 | + * @param int $course_id |
|
| 932 | + */ |
|
| 933 | + $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 934 | + |
|
| 935 | + //return the requested fields |
|
| 936 | + // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 937 | + // objects |
|
| 938 | + if( 'ids' == $fields ) { |
|
| 939 | + $lesson_objects = $lessons; |
|
| 940 | + $lessons = array(); |
|
| 941 | + |
|
| 942 | + foreach ($lesson_objects as $lesson) { |
|
| 943 | + $lessons[] = $lesson->ID; |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + return $lessons; |
|
| 948 | 948 | |
| 949 | 949 | } // End course_lessons() |
| 950 | 950 | |
| 951 | - /** |
|
| 952 | - * Used for the uasort in $this->course_lessons() |
|
| 953 | - * @since 1.8.0 |
|
| 954 | - * @access protected |
|
| 955 | - * |
|
| 956 | - * @param array $lesson_1 |
|
| 957 | - * @param array $lesson_2 |
|
| 958 | - * @return int |
|
| 959 | - */ |
|
| 960 | - protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 951 | + /** |
|
| 952 | + * Used for the uasort in $this->course_lessons() |
|
| 953 | + * @since 1.8.0 |
|
| 954 | + * @access protected |
|
| 955 | + * |
|
| 956 | + * @param array $lesson_1 |
|
| 957 | + * @param array $lesson_2 |
|
| 958 | + * @return int |
|
| 959 | + */ |
|
| 960 | + protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 961 | 961 | |
| 962 | - if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 963 | - return 0; |
|
| 964 | - } |
|
| 962 | + if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 963 | + return 0; |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | - return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 967 | - } |
|
| 966 | + return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | 969 | /** |
| 970 | 970 | * Fetch all quiz ids in a course |
@@ -1027,15 +1027,15 @@ discard block |
||
| 1027 | 1027 | */ |
| 1028 | 1028 | public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) { |
| 1029 | 1029 | |
| 1030 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1030 | + $lesson_args = array( 'post_type' => 'lesson', |
|
| 1031 | 1031 | 'posts_per_page' => -1, |
| 1032 | - 'author' => $author_id, |
|
| 1033 | - 'meta_key' => '_lesson_course', |
|
| 1034 | - 'meta_value' => $course_id, |
|
| 1035 | - 'post_status' => 'publish', |
|
| 1036 | - 'suppress_filters' => 0, |
|
| 1032 | + 'author' => $author_id, |
|
| 1033 | + 'meta_key' => '_lesson_course', |
|
| 1034 | + 'meta_value' => $course_id, |
|
| 1035 | + 'post_status' => 'publish', |
|
| 1036 | + 'suppress_filters' => 0, |
|
| 1037 | 1037 | 'fields' => 'ids', // less data to retrieve |
| 1038 | - ); |
|
| 1038 | + ); |
|
| 1039 | 1039 | $lessons_array = get_posts( $lesson_args ); |
| 1040 | 1040 | $count = count( $lessons_array ); |
| 1041 | 1041 | return $count; |
@@ -1053,17 +1053,17 @@ discard block |
||
| 1053 | 1053 | |
| 1054 | 1054 | $lesson_args = array( 'post_type' => 'lesson', |
| 1055 | 1055 | 'posts_per_page' => -1, |
| 1056 | - 'meta_key' => '_lesson_course', |
|
| 1057 | - 'meta_value' => $course_id, |
|
| 1058 | - 'post_status' => 'publish', |
|
| 1059 | - 'suppress_filters' => 0, |
|
| 1056 | + 'meta_key' => '_lesson_course', |
|
| 1057 | + 'meta_value' => $course_id, |
|
| 1058 | + 'post_status' => 'publish', |
|
| 1059 | + 'suppress_filters' => 0, |
|
| 1060 | 1060 | 'fields' => 'ids', // less data to retrieve |
| 1061 | - ); |
|
| 1061 | + ); |
|
| 1062 | 1062 | $lessons_array = get_posts( $lesson_args ); |
| 1063 | 1063 | |
| 1064 | - $count = count( $lessons_array ); |
|
| 1064 | + $count = count( $lessons_array ); |
|
| 1065 | 1065 | |
| 1066 | - return $count; |
|
| 1066 | + return $count; |
|
| 1067 | 1067 | |
| 1068 | 1068 | } // End course_lesson_count() |
| 1069 | 1069 | |
@@ -1078,9 +1078,9 @@ discard block |
||
| 1078 | 1078 | |
| 1079 | 1079 | $lesson_args = array( 'post_type' => 'lesson', |
| 1080 | 1080 | 'posts_per_page' => -1, |
| 1081 | - 'post_status' => 'publish', |
|
| 1082 | - 'suppress_filters' => 0, |
|
| 1083 | - 'meta_query' => array( |
|
| 1081 | + 'post_status' => 'publish', |
|
| 1082 | + 'suppress_filters' => 0, |
|
| 1083 | + 'meta_query' => array( |
|
| 1084 | 1084 | array( |
| 1085 | 1085 | 'key' => '_lesson_course', |
| 1086 | 1086 | 'value' => $course_id |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | ) |
| 1092 | 1092 | ), |
| 1093 | 1093 | 'fields' => 'ids', // less data to retrieve |
| 1094 | - ); |
|
| 1094 | + ); |
|
| 1095 | 1095 | $lessons_array = get_posts( $lesson_args ); |
| 1096 | 1096 | |
| 1097 | 1097 | $count = count( $lessons_array ); |
| 1098 | 1098 | |
| 1099 | - return $count; |
|
| 1099 | + return $count; |
|
| 1100 | 1100 | |
| 1101 | 1101 | } // End course_lesson_count() |
| 1102 | 1102 | |
@@ -1115,8 +1115,8 @@ discard block |
||
| 1115 | 1115 | $post_args = array( 'post_type' => 'course', |
| 1116 | 1116 | 'posts_per_page' => -1, |
| 1117 | 1117 | 'meta_key' => '_course_woocommerce_product', |
| 1118 | - 'meta_value' => $product_id, |
|
| 1119 | - 'post_status' => 'publish', |
|
| 1118 | + 'meta_value' => $product_id, |
|
| 1119 | + 'post_status' => 'publish', |
|
| 1120 | 1120 | 'suppress_filters' => 0, |
| 1121 | 1121 | 'orderby' => 'menu_order date', |
| 1122 | 1122 | 'order' => 'ASC', |
@@ -1157,9 +1157,9 @@ discard block |
||
| 1157 | 1157 | |
| 1158 | 1158 | /** |
| 1159 | 1159 | * load_user_courses_content generates HTML for user's active & completed courses |
| 1160 | - * |
|
| 1161 | - * This function also ouputs the html so no need to echo the content. |
|
| 1162 | - * |
|
| 1160 | + * |
|
| 1161 | + * This function also ouputs the html so no need to echo the content. |
|
| 1162 | + * |
|
| 1163 | 1163 | * @since 1.4.0 |
| 1164 | 1164 | * @param object $user Queried user object |
| 1165 | 1165 | * @param boolean $manage Whether the user has permission to manage the courses |
@@ -1168,17 +1168,17 @@ discard block |
||
| 1168 | 1168 | public function load_user_courses_content( $user = false ) { |
| 1169 | 1169 | global $course, $my_courses_page, $my_courses_section; |
| 1170 | 1170 | |
| 1171 | - if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | - || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1171 | + if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | + || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1173 | 1173 | |
| 1174 | - // do not show the content if the settings doesn't allow for it |
|
| 1175 | - return; |
|
| 1174 | + // do not show the content if the settings doesn't allow for it |
|
| 1175 | + return; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1179 | + $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1180 | 1180 | |
| 1181 | - do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1181 | + do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1182 | 1182 | |
| 1183 | 1183 | // Build Output HTML |
| 1184 | 1184 | $complete_html = $active_html = ''; |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | // Logic for Active and Completed Courses |
| 1194 | 1194 | $per_page = 20; |
| 1195 | 1195 | if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) |
| 1196 | - && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1196 | + && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1197 | 1197 | |
| 1198 | 1198 | $per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
| 1199 | 1199 | |
@@ -1239,111 +1239,111 @@ discard block |
||
| 1239 | 1239 | } |
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | - // Get Course Categories |
|
| 1243 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1242 | + // Get Course Categories |
|
| 1243 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1244 | 1244 | |
| 1245 | - $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1245 | + $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1246 | 1246 | |
| 1247 | - // Image |
|
| 1248 | - $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1247 | + // Image |
|
| 1248 | + $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1249 | 1249 | |
| 1250 | - // Title |
|
| 1251 | - $active_html .= '<header>'; |
|
| 1250 | + // Title |
|
| 1251 | + $active_html .= '<header>'; |
|
| 1252 | 1252 | |
| 1253 | - $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1253 | + $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1254 | 1254 | |
| 1255 | - $active_html .= '</header>'; |
|
| 1255 | + $active_html .= '</header>'; |
|
| 1256 | 1256 | |
| 1257 | - $active_html .= '<section class="entry">'; |
|
| 1257 | + $active_html .= '<section class="entry">'; |
|
| 1258 | 1258 | |
| 1259 | - $active_html .= '<p class="sensei-course-meta">'; |
|
| 1259 | + $active_html .= '<p class="sensei-course-meta">'; |
|
| 1260 | 1260 | |
| 1261 | - // Author |
|
| 1262 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | - && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1261 | + // Author |
|
| 1262 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | + && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1265 | 1265 | |
| 1266 | - $active_html .= '<span class="course-author">' |
|
| 1267 | - . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | - . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | - . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | - . esc_html( $user_info->display_name ) |
|
| 1271 | - . '</a></span>'; |
|
| 1266 | + $active_html .= '<span class="course-author">' |
|
| 1267 | + . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | + . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | + . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | + . esc_html( $user_info->display_name ) |
|
| 1271 | + . '</a></span>'; |
|
| 1272 | 1272 | |
| 1273 | - } // End If Statement |
|
| 1273 | + } // End If Statement |
|
| 1274 | 1274 | |
| 1275 | - // Lesson count for this author |
|
| 1276 | - $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1277 | - // Handle Division by Zero |
|
| 1278 | - if ( 0 == $lesson_count ) { |
|
| 1275 | + // Lesson count for this author |
|
| 1276 | + $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1277 | + // Handle Division by Zero |
|
| 1278 | + if ( 0 == $lesson_count ) { |
|
| 1279 | 1279 | |
| 1280 | - $lesson_count = 1; |
|
| 1280 | + $lesson_count = 1; |
|
| 1281 | 1281 | |
| 1282 | - } // End If Statement |
|
| 1283 | - $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1284 | - // Course Categories |
|
| 1285 | - if ( '' != $category_output ) { |
|
| 1282 | + } // End If Statement |
|
| 1283 | + $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1284 | + // Course Categories |
|
| 1285 | + if ( '' != $category_output ) { |
|
| 1286 | 1286 | |
| 1287 | - $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1287 | + $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1288 | 1288 | |
| 1289 | - } // End If Statement |
|
| 1290 | - $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1289 | + } // End If Statement |
|
| 1290 | + $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1291 | 1291 | |
| 1292 | - $active_html .= '</p>'; |
|
| 1292 | + $active_html .= '</p>'; |
|
| 1293 | 1293 | |
| 1294 | - $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1294 | + $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | 1297 | |
| 1298 | - $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1298 | + $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1299 | 1299 | |
| 1300 | - $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1300 | + $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1301 | 1301 | |
| 1302 | - $active_html .= '</section>'; |
|
| 1302 | + $active_html .= '</section>'; |
|
| 1303 | 1303 | |
| 1304 | - if( is_user_logged_in() ) { |
|
| 1304 | + if( is_user_logged_in() ) { |
|
| 1305 | 1305 | |
| 1306 | - $active_html .= '<section class="entry-actions">'; |
|
| 1306 | + $active_html .= '<section class="entry-actions">'; |
|
| 1307 | 1307 | |
| 1308 | - $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1308 | + $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1309 | 1309 | |
| 1310 | - $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1310 | + $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1311 | 1311 | |
| 1312 | - $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1312 | + $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1313 | 1313 | |
| 1314 | - if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1314 | + if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1315 | 1315 | |
| 1316 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1317 | - . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1316 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1317 | + . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1318 | 1318 | |
| 1319 | - } // End If Statement |
|
| 1319 | + } // End If Statement |
|
| 1320 | 1320 | |
| 1321 | - $course_purchased = false; |
|
| 1322 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1321 | + $course_purchased = false; |
|
| 1322 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1323 | 1323 | |
| 1324 | - // Get the product ID |
|
| 1325 | - $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | - if ( 0 < $wc_post_id ) { |
|
| 1324 | + // Get the product ID |
|
| 1325 | + $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | + if ( 0 < $wc_post_id ) { |
|
| 1327 | 1327 | |
| 1328 | - $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1328 | + $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1329 | 1329 | |
| 1330 | - } // End If Statement |
|
| 1330 | + } // End If Statement |
|
| 1331 | 1331 | |
| 1332 | - } // End If Statement |
|
| 1332 | + } // End If Statement |
|
| 1333 | 1333 | |
| 1334 | - if ( false == $course_purchased ) { |
|
| 1334 | + if ( false == $course_purchased ) { |
|
| 1335 | 1335 | |
| 1336 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1337 | - . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1336 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1337 | + . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1338 | 1338 | |
| 1339 | - } // End If Statement |
|
| 1339 | + } // End If Statement |
|
| 1340 | 1340 | |
| 1341 | - $active_html .= '</form>'; |
|
| 1341 | + $active_html .= '</form>'; |
|
| 1342 | 1342 | |
| 1343 | - $active_html .= '</section>'; |
|
| 1344 | - } |
|
| 1343 | + $active_html .= '</section>'; |
|
| 1344 | + } |
|
| 1345 | 1345 | |
| 1346 | - $active_html .= '</article>'; |
|
| 1346 | + $active_html .= '</article>'; |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | // Active pagination |
@@ -1383,49 +1383,49 @@ discard block |
||
| 1383 | 1383 | foreach ( $completed_courses as $course_item ) { |
| 1384 | 1384 | $course = $course_item; |
| 1385 | 1385 | |
| 1386 | - // Get Course Categories |
|
| 1387 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1386 | + // Get Course Categories |
|
| 1387 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1388 | 1388 | |
| 1389 | - $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1389 | + $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1390 | 1390 | |
| 1391 | - // Image |
|
| 1392 | - $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1391 | + // Image |
|
| 1392 | + $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1393 | 1393 | |
| 1394 | - // Title |
|
| 1395 | - $complete_html .= '<header>'; |
|
| 1394 | + // Title |
|
| 1395 | + $complete_html .= '<header>'; |
|
| 1396 | 1396 | |
| 1397 | - $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1397 | + $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1398 | 1398 | |
| 1399 | - $complete_html .= '</header>'; |
|
| 1399 | + $complete_html .= '</header>'; |
|
| 1400 | 1400 | |
| 1401 | - $complete_html .= '<section class="entry">'; |
|
| 1401 | + $complete_html .= '<section class="entry">'; |
|
| 1402 | 1402 | |
| 1403 | - $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1403 | + $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1404 | 1404 | |
| 1405 | - // Author |
|
| 1406 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | - $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1409 | - } // End If Statement |
|
| 1405 | + // Author |
|
| 1406 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | + $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1409 | + } // End If Statement |
|
| 1410 | 1410 | |
| 1411 | - // Lesson count for this author |
|
| 1412 | - $complete_html .= '<span class="course-lesson-count">' |
|
| 1413 | - . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | - . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1415 | - . '</span>'; |
|
| 1411 | + // Lesson count for this author |
|
| 1412 | + $complete_html .= '<span class="course-lesson-count">' |
|
| 1413 | + . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | + . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1415 | + . '</span>'; |
|
| 1416 | 1416 | |
| 1417 | - // Course Categories |
|
| 1418 | - if ( '' != $category_output ) { |
|
| 1417 | + // Course Categories |
|
| 1418 | + if ( '' != $category_output ) { |
|
| 1419 | 1419 | |
| 1420 | - $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1420 | + $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1421 | 1421 | |
| 1422 | - } // End If Statement |
|
| 1422 | + } // End If Statement |
|
| 1423 | 1423 | |
| 1424 | 1424 | $complete_html .= '</p>'; |
| 1425 | 1425 | |
| 1426 | 1426 | $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
| 1427 | 1427 | |
| 1428 | - $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1428 | + $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1429 | 1429 | |
| 1430 | 1430 | if( $manage ) { |
| 1431 | 1431 | $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true ); |
@@ -1438,9 +1438,9 @@ discard block |
||
| 1438 | 1438 | if( $has_quizzes ) { |
| 1439 | 1439 | |
| 1440 | 1440 | $results_link = '<a class="button view-results" href="' |
| 1441 | - . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | - . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1443 | - . '</a>'; |
|
| 1441 | + . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | + . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1443 | + . '</a>'; |
|
| 1444 | 1444 | } |
| 1445 | 1445 | $complete_html .= apply_filters( 'sensei_results_links', $results_link ); |
| 1446 | 1446 | $complete_html .= '</p>'; |
@@ -1448,9 +1448,9 @@ discard block |
||
| 1448 | 1448 | } |
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | - $complete_html .= '</section>'; |
|
| 1451 | + $complete_html .= '</section>'; |
|
| 1452 | 1452 | |
| 1453 | - $complete_html .= '</article>'; |
|
| 1453 | + $complete_html .= '</article>'; |
|
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | // Active pagination |
@@ -1525,16 +1525,16 @@ discard block |
||
| 1525 | 1525 | <?php do_action( 'sensei_before_active_user_courses' ); ?> |
| 1526 | 1526 | |
| 1527 | 1527 | <?php |
| 1528 | - $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1529 | - ?> |
|
| 1528 | + $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1529 | + ?> |
|
| 1530 | 1530 | |
| 1531 | 1531 | <div id="active-courses"> |
| 1532 | 1532 | |
| 1533 | 1533 | <?php if ( '' != $active_html ) { |
| 1534 | 1534 | |
| 1535 | - echo $active_html; |
|
| 1535 | + echo $active_html; |
|
| 1536 | 1536 | |
| 1537 | - } else { ?> |
|
| 1537 | + } else { ?> |
|
| 1538 | 1538 | |
| 1539 | 1539 | <div class="sensei-message info"> |
| 1540 | 1540 | |
@@ -1560,9 +1560,9 @@ discard block |
||
| 1560 | 1560 | |
| 1561 | 1561 | <?php if ( '' != $complete_html ) { |
| 1562 | 1562 | |
| 1563 | - echo $complete_html; |
|
| 1563 | + echo $complete_html; |
|
| 1564 | 1564 | |
| 1565 | - } else { ?> |
|
| 1565 | + } else { ?> |
|
| 1566 | 1566 | |
| 1567 | 1567 | <div class="sensei-message info"> |
| 1568 | 1568 | |
@@ -1581,355 +1581,355 @@ discard block |
||
| 1581 | 1581 | <?php do_action( 'sensei_after_user_courses' ); ?> |
| 1582 | 1582 | |
| 1583 | 1583 | <?php |
| 1584 | - echo ob_get_clean(); |
|
| 1584 | + echo ob_get_clean(); |
|
| 1585 | 1585 | |
| 1586 | - do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1586 | + do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1587 | 1587 | |
| 1588 | 1588 | } // end load_user_courses_content |
| 1589 | 1589 | |
| 1590 | - /** |
|
| 1591 | - * Returns a list of all courses |
|
| 1592 | - * |
|
| 1593 | - * @since 1.8.0 |
|
| 1594 | - * @return array $courses{ |
|
| 1595 | - * @type $course WP_Post |
|
| 1596 | - * } |
|
| 1597 | - */ |
|
| 1598 | - public static function get_all_courses(){ |
|
| 1599 | - |
|
| 1600 | - $args = array( |
|
| 1601 | - 'post_type' => 'course', |
|
| 1602 | - 'posts_per_page' => -1, |
|
| 1603 | - 'orderby' => 'title', |
|
| 1604 | - 'order' => 'ASC', |
|
| 1605 | - 'post_status' => 'any', |
|
| 1606 | - 'suppress_filters' => 0, |
|
| 1607 | - ); |
|
| 1608 | - |
|
| 1609 | - $wp_query_obj = new WP_Query( $args ); |
|
| 1610 | - |
|
| 1611 | - /** |
|
| 1612 | - * sensei_get_all_courses filter |
|
| 1613 | - * |
|
| 1614 | - * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1615 | - * |
|
| 1616 | - * @param array $courses{ |
|
| 1617 | - * @type WP_Post |
|
| 1618 | - * } |
|
| 1619 | - * @param array $attributes |
|
| 1620 | - */ |
|
| 1621 | - return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1622 | - |
|
| 1623 | - }// end get_all_courses |
|
| 1624 | - |
|
| 1625 | - /** |
|
| 1626 | - * Generate the course meter component |
|
| 1627 | - * |
|
| 1628 | - * @since 1.8.0 |
|
| 1629 | - * @param int $progress_percentage 0 - 100 |
|
| 1630 | - * @return string $progress_bar_html |
|
| 1631 | - */ |
|
| 1632 | - public function get_progress_meter( $progress_percentage ){ |
|
| 1633 | - |
|
| 1634 | - if ( 50 < $progress_percentage ) { |
|
| 1635 | - $class = ' green'; |
|
| 1636 | - } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1637 | - $class = ' orange'; |
|
| 1638 | - } else { |
|
| 1639 | - $class = ' red'; |
|
| 1640 | - } |
|
| 1641 | - $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1642 | - |
|
| 1643 | - return $progress_bar_html; |
|
| 1644 | - |
|
| 1645 | - }// end get_progress_meter |
|
| 1646 | - |
|
| 1647 | - /** |
|
| 1648 | - * Generate a statement that tells users |
|
| 1649 | - * how far they are in the course. |
|
| 1650 | - * |
|
| 1651 | - * @param int $course_id |
|
| 1652 | - * @param int $user_id |
|
| 1653 | - * |
|
| 1654 | - * @return string $statement_html |
|
| 1655 | - */ |
|
| 1656 | - public function get_progress_statement( $course_id, $user_id ){ |
|
| 1657 | - |
|
| 1658 | - if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | - || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1660 | - return ''; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1665 | - |
|
| 1666 | - $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1667 | - |
|
| 1668 | - /** |
|
| 1669 | - * Filter the course completion statement. |
|
| 1670 | - * Default Currently completed $var lesson($plural) of $var in total |
|
| 1671 | - * |
|
| 1672 | - * @param string $statement |
|
| 1673 | - */ |
|
| 1674 | - return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1675 | - |
|
| 1676 | - }// end generate_progress_statement |
|
| 1677 | - |
|
| 1678 | - /** |
|
| 1679 | - * Output the course progress statement |
|
| 1680 | - * |
|
| 1681 | - * @param $course_id |
|
| 1682 | - * @return void |
|
| 1683 | - */ |
|
| 1684 | - public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | - if( empty( $course_id ) ){ |
|
| 1686 | - global $post; |
|
| 1687 | - $course_id = $post->ID; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - if( empty( $user_id ) ){ |
|
| 1691 | - $user_id = get_current_user_id(); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Output the course progress bar |
|
| 1699 | - * |
|
| 1700 | - * @param $course_id |
|
| 1701 | - * @return void |
|
| 1702 | - */ |
|
| 1703 | - public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1704 | - |
|
| 1705 | - if( empty( $course_id ) ){ |
|
| 1706 | - global $post; |
|
| 1707 | - $course_id = $post->ID; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - if( empty( $user_id ) ){ |
|
| 1711 | - $user_id = get_current_user_id(); |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | - || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1716 | - return; |
|
| 1717 | - } |
|
| 1718 | - $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1719 | - |
|
| 1720 | - echo $this->get_progress_meter( $percentage_completed ); |
|
| 1721 | - |
|
| 1722 | - }// end the_progress_meter |
|
| 1723 | - |
|
| 1724 | - /** |
|
| 1725 | - * Checks how many lessons are completed |
|
| 1726 | - * |
|
| 1727 | - * @since 1.8.0 |
|
| 1728 | - * |
|
| 1729 | - * @param int $course_id |
|
| 1730 | - * @param int $user_id |
|
| 1731 | - * @return array $completed_lesson_ids |
|
| 1732 | - */ |
|
| 1733 | - public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1734 | - |
|
| 1735 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1736 | - $user_id = get_current_user_id(); |
|
| 1737 | - } |
|
| 1590 | + /** |
|
| 1591 | + * Returns a list of all courses |
|
| 1592 | + * |
|
| 1593 | + * @since 1.8.0 |
|
| 1594 | + * @return array $courses{ |
|
| 1595 | + * @type $course WP_Post |
|
| 1596 | + * } |
|
| 1597 | + */ |
|
| 1598 | + public static function get_all_courses(){ |
|
| 1599 | + |
|
| 1600 | + $args = array( |
|
| 1601 | + 'post_type' => 'course', |
|
| 1602 | + 'posts_per_page' => -1, |
|
| 1603 | + 'orderby' => 'title', |
|
| 1604 | + 'order' => 'ASC', |
|
| 1605 | + 'post_status' => 'any', |
|
| 1606 | + 'suppress_filters' => 0, |
|
| 1607 | + ); |
|
| 1608 | + |
|
| 1609 | + $wp_query_obj = new WP_Query( $args ); |
|
| 1610 | + |
|
| 1611 | + /** |
|
| 1612 | + * sensei_get_all_courses filter |
|
| 1613 | + * |
|
| 1614 | + * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1615 | + * |
|
| 1616 | + * @param array $courses{ |
|
| 1617 | + * @type WP_Post |
|
| 1618 | + * } |
|
| 1619 | + * @param array $attributes |
|
| 1620 | + */ |
|
| 1621 | + return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1622 | + |
|
| 1623 | + }// end get_all_courses |
|
| 1624 | + |
|
| 1625 | + /** |
|
| 1626 | + * Generate the course meter component |
|
| 1627 | + * |
|
| 1628 | + * @since 1.8.0 |
|
| 1629 | + * @param int $progress_percentage 0 - 100 |
|
| 1630 | + * @return string $progress_bar_html |
|
| 1631 | + */ |
|
| 1632 | + public function get_progress_meter( $progress_percentage ){ |
|
| 1633 | + |
|
| 1634 | + if ( 50 < $progress_percentage ) { |
|
| 1635 | + $class = ' green'; |
|
| 1636 | + } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1637 | + $class = ' orange'; |
|
| 1638 | + } else { |
|
| 1639 | + $class = ' red'; |
|
| 1640 | + } |
|
| 1641 | + $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1642 | + |
|
| 1643 | + return $progress_bar_html; |
|
| 1644 | + |
|
| 1645 | + }// end get_progress_meter |
|
| 1646 | + |
|
| 1647 | + /** |
|
| 1648 | + * Generate a statement that tells users |
|
| 1649 | + * how far they are in the course. |
|
| 1650 | + * |
|
| 1651 | + * @param int $course_id |
|
| 1652 | + * @param int $user_id |
|
| 1653 | + * |
|
| 1654 | + * @return string $statement_html |
|
| 1655 | + */ |
|
| 1656 | + public function get_progress_statement( $course_id, $user_id ){ |
|
| 1657 | + |
|
| 1658 | + if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | + || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1660 | + return ''; |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1665 | + |
|
| 1666 | + $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1667 | + |
|
| 1668 | + /** |
|
| 1669 | + * Filter the course completion statement. |
|
| 1670 | + * Default Currently completed $var lesson($plural) of $var in total |
|
| 1671 | + * |
|
| 1672 | + * @param string $statement |
|
| 1673 | + */ |
|
| 1674 | + return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1675 | + |
|
| 1676 | + }// end generate_progress_statement |
|
| 1677 | + |
|
| 1678 | + /** |
|
| 1679 | + * Output the course progress statement |
|
| 1680 | + * |
|
| 1681 | + * @param $course_id |
|
| 1682 | + * @return void |
|
| 1683 | + */ |
|
| 1684 | + public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | + if( empty( $course_id ) ){ |
|
| 1686 | + global $post; |
|
| 1687 | + $course_id = $post->ID; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + if( empty( $user_id ) ){ |
|
| 1691 | + $user_id = get_current_user_id(); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * Output the course progress bar |
|
| 1699 | + * |
|
| 1700 | + * @param $course_id |
|
| 1701 | + * @return void |
|
| 1702 | + */ |
|
| 1703 | + public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1704 | + |
|
| 1705 | + if( empty( $course_id ) ){ |
|
| 1706 | + global $post; |
|
| 1707 | + $course_id = $post->ID; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + if( empty( $user_id ) ){ |
|
| 1711 | + $user_id = get_current_user_id(); |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | + || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1716 | + return; |
|
| 1717 | + } |
|
| 1718 | + $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1719 | + |
|
| 1720 | + echo $this->get_progress_meter( $percentage_completed ); |
|
| 1738 | 1721 | |
| 1739 | - $completed_lesson_ids = array(); |
|
| 1722 | + }// end the_progress_meter |
|
| 1740 | 1723 | |
| 1741 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 1724 | + /** |
|
| 1725 | + * Checks how many lessons are completed |
|
| 1726 | + * |
|
| 1727 | + * @since 1.8.0 |
|
| 1728 | + * |
|
| 1729 | + * @param int $course_id |
|
| 1730 | + * @param int $user_id |
|
| 1731 | + * @return array $completed_lesson_ids |
|
| 1732 | + */ |
|
| 1733 | + public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1734 | + |
|
| 1735 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1736 | + $user_id = get_current_user_id(); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + $completed_lesson_ids = array(); |
|
| 1740 | + |
|
| 1741 | + $course_lessons = $this->course_lessons( $course_id ); |
|
| 1742 | + |
|
| 1743 | + foreach( $course_lessons as $lesson ){ |
|
| 1744 | + |
|
| 1745 | + $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | + if( $is_lesson_completed ){ |
|
| 1747 | + $completed_lesson_ids[] = $lesson->ID; |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + } |
|
| 1751 | + |
|
| 1752 | + return $completed_lesson_ids; |
|
| 1753 | + |
|
| 1754 | + }// end get_completed_lesson_ids |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * Calculate the perceantage completed in the course |
|
| 1758 | + * |
|
| 1759 | + * @since 1.8.0 |
|
| 1760 | + * |
|
| 1761 | + * @param int $course_id |
|
| 1762 | + * @param int $user_id |
|
| 1763 | + * @return int $percentage |
|
| 1764 | + */ |
|
| 1765 | + public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1766 | + |
|
| 1767 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1768 | + $user_id = get_current_user_id(); |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1772 | + |
|
| 1773 | + if( ! ( $completed > 0 ) ){ |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1778 | + $percentage = $completed / $total_lessons * 100; |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * |
|
| 1782 | + * Filter the percentage returned for a users course. |
|
| 1783 | + * |
|
| 1784 | + * @param $percentage |
|
| 1785 | + * @param $course_id |
|
| 1786 | + * @param $user_id |
|
| 1787 | + * @since 1.8.0 |
|
| 1788 | + */ |
|
| 1789 | + return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1790 | + |
|
| 1791 | + }// end get_completed_lesson_ids |
|
| 1792 | + |
|
| 1793 | + /** |
|
| 1794 | + * Block email notifications for the specific courses |
|
| 1795 | + * that the user disabled the notifications. |
|
| 1796 | + * |
|
| 1797 | + * @since 1.8.0 |
|
| 1798 | + * @param $should_send |
|
| 1799 | + * @return bool |
|
| 1800 | + */ |
|
| 1801 | + public function block_notification_emails( $should_send ){ |
|
| 1802 | + global $sensei_email_data; |
|
| 1803 | + $email = $sensei_email_data; |
|
| 1804 | + |
|
| 1805 | + $course_id = ''; |
|
| 1806 | + |
|
| 1807 | + if( isset( $email['course_id'] ) ){ |
|
| 1808 | + |
|
| 1809 | + $course_id = $email['course_id']; |
|
| 1810 | + |
|
| 1811 | + }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1812 | + |
|
| 1813 | + $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1814 | + |
|
| 1815 | + }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1816 | + |
|
| 1817 | + $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1819 | + |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | + |
|
| 1824 | + $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | + |
|
| 1826 | + if ($course_emails_disabled) { |
|
| 1827 | + |
|
| 1828 | + return false; |
|
| 1829 | + |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + }// end if |
|
| 1833 | + |
|
| 1834 | + return $should_send; |
|
| 1835 | + }// end block_notification_emails |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * Render the course notification setting meta box |
|
| 1839 | + * |
|
| 1840 | + * @since 1.8.0 |
|
| 1841 | + * @param $course |
|
| 1842 | + */ |
|
| 1843 | + public function course_notification_meta_box_content( $course ){ |
|
| 1742 | 1844 | |
| 1743 | - foreach( $course_lessons as $lesson ){ |
|
| 1845 | + $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1744 | 1846 | |
| 1745 | - $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | - if( $is_lesson_completed ){ |
|
| 1747 | - $completed_lesson_ids[] = $lesson->ID; |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - } |
|
| 1751 | - |
|
| 1752 | - return $completed_lesson_ids; |
|
| 1847 | + // generate checked html |
|
| 1848 | + $checked_html = ''; |
|
| 1849 | + if( $checked ){ |
|
| 1850 | + $checked_html = 'checked="checked"'; |
|
| 1851 | + } |
|
| 1852 | + wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1753 | 1853 | |
| 1754 | - }// end get_completed_lesson_ids |
|
| 1854 | + echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | + echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1755 | 1856 | |
| 1756 | - /** |
|
| 1757 | - * Calculate the perceantage completed in the course |
|
| 1758 | - * |
|
| 1759 | - * @since 1.8.0 |
|
| 1760 | - * |
|
| 1761 | - * @param int $course_id |
|
| 1762 | - * @param int $user_id |
|
| 1763 | - * @return int $percentage |
|
| 1764 | - */ |
|
| 1765 | - public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1766 | - |
|
| 1767 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1768 | - $user_id = get_current_user_id(); |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1772 | - |
|
| 1773 | - if( ! ( $completed > 0 ) ){ |
|
| 1774 | - return 0; |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1778 | - $percentage = $completed / $total_lessons * 100; |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * |
|
| 1782 | - * Filter the percentage returned for a users course. |
|
| 1783 | - * |
|
| 1784 | - * @param $percentage |
|
| 1785 | - * @param $course_id |
|
| 1786 | - * @param $user_id |
|
| 1787 | - * @since 1.8.0 |
|
| 1788 | - */ |
|
| 1789 | - return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1857 | + }// end course_notification_meta_box_content |
|
| 1790 | 1858 | |
| 1791 | - }// end get_completed_lesson_ids |
|
| 1859 | + /** |
|
| 1860 | + * Store the setting for the course notification setting. |
|
| 1861 | + * |
|
| 1862 | + * @hooked int save_post |
|
| 1863 | + * @since 1.8.0 |
|
| 1864 | + * |
|
| 1865 | + * @param $course_id |
|
| 1866 | + */ |
|
| 1867 | + public function save_course_notification_meta_box( $course_id ){ |
|
| 1868 | + |
|
| 1869 | + if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | + || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1871 | + return; |
|
| 1872 | + } |
|
| 1792 | 1873 | |
| 1793 | - /** |
|
| 1794 | - * Block email notifications for the specific courses |
|
| 1795 | - * that the user disabled the notifications. |
|
| 1796 | - * |
|
| 1797 | - * @since 1.8.0 |
|
| 1798 | - * @param $should_send |
|
| 1799 | - * @return bool |
|
| 1800 | - */ |
|
| 1801 | - public function block_notification_emails( $should_send ){ |
|
| 1802 | - global $sensei_email_data; |
|
| 1803 | - $email = $sensei_email_data; |
|
| 1874 | + if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1875 | + $new_val = true; |
|
| 1876 | + }else{ |
|
| 1877 | + $new_val = false; |
|
| 1878 | + } |
|
| 1804 | 1879 | |
| 1805 | - $course_id = ''; |
|
| 1880 | + update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1806 | 1881 | |
| 1807 | - if( isset( $email['course_id'] ) ){ |
|
| 1882 | + }// end save notification meta box |
|
| 1808 | 1883 | |
| 1809 | - $course_id = $email['course_id']; |
|
| 1810 | - |
|
| 1811 | - }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1884 | + /** |
|
| 1885 | + * Backwards compatibility hooks added to ensure that |
|
| 1886 | + * plugins and other parts of sensei still works. |
|
| 1887 | + * |
|
| 1888 | + * This function hooks into `sensei_course_content_inside_before` |
|
| 1889 | + * |
|
| 1890 | + * @since 1.9 |
|
| 1891 | + * |
|
| 1892 | + * @param WP_Post $post |
|
| 1893 | + */ |
|
| 1894 | + public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1812 | 1895 | |
| 1813 | - $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1896 | + sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | + sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1814 | 1898 | |
| 1815 | - }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1899 | + } |
|
| 1816 | 1900 | |
| 1817 | - $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1901 | + /** |
|
| 1902 | + * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1903 | + * |
|
| 1904 | + * hooked into 'sensei_loop_course_before' |
|
| 1905 | + * |
|
| 1906 | + * @since 1.9 |
|
| 1907 | + * |
|
| 1908 | + * @global WP_Post $post |
|
| 1909 | + */ |
|
| 1910 | + public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1819 | 1911 | |
| 1820 | - } |
|
| 1912 | + global $post; |
|
| 1913 | + sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1821 | 1914 | |
| 1822 | - if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | - |
|
| 1824 | - $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | - |
|
| 1826 | - if ($course_emails_disabled) { |
|
| 1827 | - |
|
| 1828 | - return false; |
|
| 1829 | - |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - }// end if |
|
| 1833 | - |
|
| 1834 | - return $should_send; |
|
| 1835 | - }// end block_notification_emails |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * Render the course notification setting meta box |
|
| 1839 | - * |
|
| 1840 | - * @since 1.8.0 |
|
| 1841 | - * @param $course |
|
| 1842 | - */ |
|
| 1843 | - public function course_notification_meta_box_content( $course ){ |
|
| 1844 | - |
|
| 1845 | - $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1846 | - |
|
| 1847 | - // generate checked html |
|
| 1848 | - $checked_html = ''; |
|
| 1849 | - if( $checked ){ |
|
| 1850 | - $checked_html = 'checked="checked"'; |
|
| 1851 | - } |
|
| 1852 | - wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1853 | - |
|
| 1854 | - echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | - echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1856 | - |
|
| 1857 | - }// end course_notification_meta_box_content |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * Store the setting for the course notification setting. |
|
| 1861 | - * |
|
| 1862 | - * @hooked int save_post |
|
| 1863 | - * @since 1.8.0 |
|
| 1864 | - * |
|
| 1865 | - * @param $course_id |
|
| 1866 | - */ |
|
| 1867 | - public function save_course_notification_meta_box( $course_id ){ |
|
| 1868 | - |
|
| 1869 | - if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | - || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1871 | - return; |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1875 | - $new_val = true; |
|
| 1876 | - }else{ |
|
| 1877 | - $new_val = false; |
|
| 1878 | - } |
|
| 1879 | - |
|
| 1880 | - update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1881 | - |
|
| 1882 | - }// end save notification meta box |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * Backwards compatibility hooks added to ensure that |
|
| 1886 | - * plugins and other parts of sensei still works. |
|
| 1887 | - * |
|
| 1888 | - * This function hooks into `sensei_course_content_inside_before` |
|
| 1889 | - * |
|
| 1890 | - * @since 1.9 |
|
| 1891 | - * |
|
| 1892 | - * @param WP_Post $post |
|
| 1893 | - */ |
|
| 1894 | - public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1895 | - |
|
| 1896 | - sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | - sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1915 | + } |
|
| 1898 | 1916 | |
| 1899 | - } |
|
| 1917 | + /** |
|
| 1918 | + * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1919 | + * |
|
| 1920 | + * hooked into 'sensei_course_content_inside_after' |
|
| 1921 | + * |
|
| 1922 | + * @since 1.9.0 |
|
| 1923 | + * |
|
| 1924 | + * @param WP_Post $course |
|
| 1925 | + */ |
|
| 1926 | + public function the_course_free_lesson_preview( $course ){ |
|
| 1927 | + // Meta data |
|
| 1928 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1929 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1900 | 1930 | |
| 1901 | - /** |
|
| 1902 | - * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1903 | - * |
|
| 1904 | - * hooked into 'sensei_loop_course_before' |
|
| 1905 | - * |
|
| 1906 | - * @since 1.9 |
|
| 1907 | - * |
|
| 1908 | - * @global WP_Post $post |
|
| 1909 | - */ |
|
| 1910 | - public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1911 | - |
|
| 1912 | - global $post; |
|
| 1913 | - sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1914 | - |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - /** |
|
| 1918 | - * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1919 | - * |
|
| 1920 | - * hooked into 'sensei_course_content_inside_after' |
|
| 1921 | - * |
|
| 1922 | - * @since 1.9.0 |
|
| 1923 | - * |
|
| 1924 | - * @param WP_Post $course |
|
| 1925 | - */ |
|
| 1926 | - public function the_course_free_lesson_preview( $course ){ |
|
| 1927 | - // Meta data |
|
| 1928 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1929 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1930 | - |
|
| 1931 | - if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1932 | - ?> |
|
| 1931 | + if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1932 | + ?> |
|
| 1933 | 1933 | <p class="sensei-free-lessons"> |
| 1934 | 1934 | <a href="<?php echo get_permalink(); ?>"> |
| 1935 | 1935 | <?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
@@ -1938,22 +1938,22 @@ discard block |
||
| 1938 | 1938 | </p> |
| 1939 | 1939 | |
| 1940 | 1940 | <?php |
| 1941 | - } |
|
| 1942 | - } |
|
| 1941 | + } |
|
| 1942 | + } |
|
| 1943 | 1943 | |
| 1944 | - /** |
|
| 1945 | - * Add course mata to the course meta hook |
|
| 1946 | - * |
|
| 1947 | - * @since 1.9.0 |
|
| 1948 | - * @param WP_Post $course |
|
| 1949 | - */ |
|
| 1950 | - public function the_course_meta( $course ){ |
|
| 1951 | - echo '<p class="sensei-course-meta">'; |
|
| 1944 | + /** |
|
| 1945 | + * Add course mata to the course meta hook |
|
| 1946 | + * |
|
| 1947 | + * @since 1.9.0 |
|
| 1948 | + * @param WP_Post $course |
|
| 1949 | + */ |
|
| 1950 | + public function the_course_meta( $course ){ |
|
| 1951 | + echo '<p class="sensei-course-meta">'; |
|
| 1952 | 1952 | |
| 1953 | - $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1954 | - $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1953 | + $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1954 | + $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1955 | 1955 | |
| 1956 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1956 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1957 | 1957 | |
| 1958 | 1958 | <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?> |
| 1959 | 1959 | |
@@ -1971,59 +1971,59 @@ discard block |
||
| 1971 | 1971 | |
| 1972 | 1972 | <?php } // End If Statement |
| 1973 | 1973 | |
| 1974 | - // number of completed lessons |
|
| 1975 | - if( is_user_logged_in() ){ |
|
| 1976 | - $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1977 | - $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1978 | - echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1979 | - } |
|
| 1974 | + // number of completed lessons |
|
| 1975 | + if( is_user_logged_in() ){ |
|
| 1976 | + $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1977 | + $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1978 | + echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1979 | + } |
|
| 1980 | 1980 | |
| 1981 | - sensei_simple_course_price( $course->ID ); |
|
| 1981 | + sensei_simple_course_price( $course->ID ); |
|
| 1982 | 1982 | |
| 1983 | - echo '</p>'; |
|
| 1984 | - } // end the course meta |
|
| 1983 | + echo '</p>'; |
|
| 1984 | + } // end the course meta |
|
| 1985 | 1985 | |
| 1986 | - /** |
|
| 1987 | - * Filter the classes attached to a post types for courses |
|
| 1988 | - * and add a status class for when the user is logged in. |
|
| 1989 | - * |
|
| 1990 | - * @param $classes |
|
| 1991 | - * @param $class |
|
| 1992 | - * @param $post_id |
|
| 1993 | - * |
|
| 1994 | - * @return array $classes |
|
| 1995 | - */ |
|
| 1996 | - public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1986 | + /** |
|
| 1987 | + * Filter the classes attached to a post types for courses |
|
| 1988 | + * and add a status class for when the user is logged in. |
|
| 1989 | + * |
|
| 1990 | + * @param $classes |
|
| 1991 | + * @param $class |
|
| 1992 | + * @param $post_id |
|
| 1993 | + * |
|
| 1994 | + * @return array $classes |
|
| 1995 | + */ |
|
| 1996 | + public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1997 | 1997 | |
| 1998 | - if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 1998 | + if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 1999 | 1999 | |
| 2000 | - if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2000 | + if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2001 | 2001 | |
| 2002 | - $classes[] = 'user-status-completed'; |
|
| 2002 | + $classes[] = 'user-status-completed'; |
|
| 2003 | 2003 | |
| 2004 | - }else{ |
|
| 2004 | + }else{ |
|
| 2005 | 2005 | |
| 2006 | - $classes[] = 'user-status-active'; |
|
| 2006 | + $classes[] = 'user-status-active'; |
|
| 2007 | 2007 | |
| 2008 | - } |
|
| 2008 | + } |
|
| 2009 | 2009 | |
| 2010 | - } |
|
| 2010 | + } |
|
| 2011 | 2011 | |
| 2012 | - return $classes; |
|
| 2012 | + return $classes; |
|
| 2013 | 2013 | |
| 2014 | - }// end add_course_user_status_class |
|
| 2014 | + }// end add_course_user_status_class |
|
| 2015 | 2015 | |
| 2016 | - /** |
|
| 2017 | - * Prints out the course action buttons links |
|
| 2018 | - * |
|
| 2019 | - * - complete course |
|
| 2020 | - * - delete course |
|
| 2021 | - * |
|
| 2022 | - * @param WP_Post $course |
|
| 2023 | - */ |
|
| 2024 | - public static function the_course_action_buttons( $course ){ |
|
| 2016 | + /** |
|
| 2017 | + * Prints out the course action buttons links |
|
| 2018 | + * |
|
| 2019 | + * - complete course |
|
| 2020 | + * - delete course |
|
| 2021 | + * |
|
| 2022 | + * @param WP_Post $course |
|
| 2023 | + */ |
|
| 2024 | + public static function the_course_action_buttons( $course ){ |
|
| 2025 | 2025 | |
| 2026 | - if( is_user_logged_in() ) { ?> |
|
| 2026 | + if( is_user_logged_in() ) { ?> |
|
| 2027 | 2027 | |
| 2028 | 2028 | <section class="entry-actions"> |
| 2029 | 2029 | <form method="POST" action="<?php echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>"> |
@@ -2042,32 +2042,32 @@ discard block |
||
| 2042 | 2042 | |
| 2043 | 2043 | <?php } // End If Statement |
| 2044 | 2044 | |
| 2045 | - $course_purchased = false; |
|
| 2046 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2047 | - // Get the product ID |
|
| 2048 | - $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2049 | - if ( 0 < $wc_post_id ) { |
|
| 2045 | + $course_purchased = false; |
|
| 2046 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2047 | + // Get the product ID |
|
| 2048 | + $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2049 | + if ( 0 < $wc_post_id ) { |
|
| 2050 | 2050 | |
| 2051 | - $user = wp_get_current_user(); |
|
| 2052 | - $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2051 | + $user = wp_get_current_user(); |
|
| 2052 | + $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2053 | 2053 | |
| 2054 | - } // End If Statement |
|
| 2055 | - } // End If Statement |
|
| 2054 | + } // End If Statement |
|
| 2055 | + } // End If Statement |
|
| 2056 | 2056 | |
| 2057 | - if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2057 | + if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2058 | 2058 | |
| 2059 | 2059 | <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span> |
| 2060 | 2060 | |
| 2061 | 2061 | <?php } // End If Statement |
| 2062 | 2062 | |
| 2063 | - $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2064 | - $results_link = ''; |
|
| 2065 | - if( $has_quizzes ){ |
|
| 2066 | - $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2067 | - } |
|
| 2063 | + $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2064 | + $results_link = ''; |
|
| 2065 | + if( $has_quizzes ){ |
|
| 2066 | + $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2067 | + } |
|
| 2068 | 2068 | |
| 2069 | - // Output only if there is content to display |
|
| 2070 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2069 | + // Output only if there is content to display |
|
| 2070 | + if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2071 | 2071 | |
| 2072 | 2072 | <p class="sensei-results-links"> |
| 2073 | 2073 | <?php echo apply_filters( 'sensei_results_links', $results_link ); ?> |
@@ -2079,456 +2079,456 @@ discard block |
||
| 2079 | 2079 | |
| 2080 | 2080 | <?php }// end if is user logged in |
| 2081 | 2081 | |
| 2082 | - }// end the_course_action_buttons |
|
| 2083 | - |
|
| 2084 | - /** |
|
| 2085 | - * This function alter the main query on the course archive page. |
|
| 2086 | - * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2087 | - * |
|
| 2088 | - * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2089 | - * query parameters via the arguments. |
|
| 2090 | - * |
|
| 2091 | - * This function is hooked into pre_get_posts filter |
|
| 2092 | - * |
|
| 2093 | - * @since 1.9.0 |
|
| 2094 | - * |
|
| 2095 | - * @param WP_Query $query |
|
| 2096 | - * @return WP_Query $query |
|
| 2097 | - */ |
|
| 2098 | - public static function course_query_filter( $query ){ |
|
| 2099 | - |
|
| 2100 | - // exit early for no course queries and admin queries |
|
| 2101 | - if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2102 | - return $query; |
|
| 2103 | - } |
|
| 2104 | - |
|
| 2105 | - global $post; // used to get the current page id for my courses |
|
| 2106 | - |
|
| 2107 | - // for the course archive page |
|
| 2108 | - if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2109 | - { |
|
| 2110 | - /** |
|
| 2111 | - * sensei_archive_courses_per_page |
|
| 2112 | - * |
|
| 2113 | - * Sensei courses per page on the course |
|
| 2114 | - * archive |
|
| 2115 | - * |
|
| 2116 | - * @since 1.9.0 |
|
| 2117 | - * @param integer $posts_per_page default 10 |
|
| 2118 | - */ |
|
| 2119 | - $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) ); |
|
| 2120 | - |
|
| 2121 | - } |
|
| 2122 | - // for the my courses page |
|
| 2123 | - elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2124 | - { |
|
| 2125 | - /** |
|
| 2126 | - * sensei_my_courses_per_page |
|
| 2127 | - * |
|
| 2128 | - * Sensei courses per page on the my courses page |
|
| 2129 | - * as set in the settings |
|
| 2130 | - * |
|
| 2131 | - * @since 1.9.0 |
|
| 2132 | - * @param integer $posts_per_page default 10 |
|
| 2133 | - */ |
|
| 2134 | - $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) ); |
|
| 2135 | - |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - return $query; |
|
| 2139 | - |
|
| 2140 | - }// end course_query_filter |
|
| 2141 | - |
|
| 2142 | - /** |
|
| 2143 | - * Determine the class of the course loop |
|
| 2144 | - * |
|
| 2145 | - * This will output .first or .last and .course-item-number-x |
|
| 2146 | - * |
|
| 2147 | - * @return array $extra_classes |
|
| 2148 | - * @since 1.9.0 |
|
| 2149 | - */ |
|
| 2150 | - public static function get_course_loop_content_class () |
|
| 2151 | - { |
|
| 2152 | - |
|
| 2153 | - global $sensei_course_loop; |
|
| 2154 | - |
|
| 2155 | - |
|
| 2156 | - if( !isset( $sensei_course_loop ) ){ |
|
| 2157 | - $sensei_course_loop = array(); |
|
| 2158 | - } |
|
| 2159 | - |
|
| 2160 | - if (!isset($sensei_course_loop['counter'])) { |
|
| 2161 | - $sensei_course_loop['counter'] = 0; |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - if (!isset($sensei_course_loop['columns'])) { |
|
| 2165 | - $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - // increment the counter |
|
| 2169 | - $sensei_course_loop['counter']++; |
|
| 2170 | - |
|
| 2171 | - $extra_classes = array(); |
|
| 2172 | - if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2173 | - $extra_classes[] = 'first'; |
|
| 2174 | - } |
|
| 2175 | - |
|
| 2176 | - if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2177 | - $extra_classes[] = 'last'; |
|
| 2178 | - } |
|
| 2179 | - |
|
| 2180 | - // add the item number to the classes as well. |
|
| 2181 | - $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2182 | - |
|
| 2183 | - /** |
|
| 2184 | - * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2185 | - * which is called from the course loop content-course.php |
|
| 2186 | - * |
|
| 2187 | - * @since 1.9.0 |
|
| 2188 | - * |
|
| 2189 | - * @param array $extra_classes |
|
| 2190 | - * @param WP_Post $loop_current_course |
|
| 2191 | - */ |
|
| 2192 | - return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2193 | - |
|
| 2194 | - }// end get_course_loop_class |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * Get the number of columns set for Sensei courses |
|
| 2198 | - * |
|
| 2199 | - * @since 1.9.0 |
|
| 2200 | - * @return mixed|void |
|
| 2201 | - */ |
|
| 2202 | - public static function get_loop_number_of_columns(){ |
|
| 2203 | - |
|
| 2204 | - /** |
|
| 2205 | - * Filter the number of columns on the course archive page. |
|
| 2206 | - * |
|
| 2207 | - * @since 1.9.0 |
|
| 2208 | - * @param int $number_of_columns default 1 |
|
| 2209 | - */ |
|
| 2210 | - return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2211 | - |
|
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - /** |
|
| 2215 | - * Output the course archive filter markup |
|
| 2216 | - * |
|
| 2217 | - * hooked into sensei_loop_course_before |
|
| 2218 | - * |
|
| 2219 | - * @since 1.9.0 |
|
| 2220 | - * @param |
|
| 2221 | - */ |
|
| 2222 | - public static function course_archive_sorting( $query ){ |
|
| 2223 | - |
|
| 2224 | - // don't show on category pages and other pages |
|
| 2225 | - if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2226 | - return; |
|
| 2227 | - } |
|
| 2228 | - |
|
| 2229 | - /** |
|
| 2230 | - * Filter the sensei archive course order by values |
|
| 2231 | - * |
|
| 2232 | - * @since 1.9.0 |
|
| 2233 | - * @param array $options { |
|
| 2234 | - * @type string $option_value |
|
| 2235 | - * @type string $option_string |
|
| 2236 | - * } |
|
| 2237 | - */ |
|
| 2238 | - $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2239 | - "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2240 | - "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2241 | - )); |
|
| 2242 | - |
|
| 2243 | - // setup the currently selected item |
|
| 2244 | - $selected = 'newness'; |
|
| 2245 | - if( isset( $_GET['orderby'] ) ){ |
|
| 2246 | - |
|
| 2247 | - $selected = $_GET[ 'orderby' ]; |
|
| 2248 | - |
|
| 2249 | - } |
|
| 2250 | - |
|
| 2251 | - ?> |
|
| 2082 | + }// end the_course_action_buttons |
|
| 2083 | + |
|
| 2084 | + /** |
|
| 2085 | + * This function alter the main query on the course archive page. |
|
| 2086 | + * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2087 | + * |
|
| 2088 | + * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2089 | + * query parameters via the arguments. |
|
| 2090 | + * |
|
| 2091 | + * This function is hooked into pre_get_posts filter |
|
| 2092 | + * |
|
| 2093 | + * @since 1.9.0 |
|
| 2094 | + * |
|
| 2095 | + * @param WP_Query $query |
|
| 2096 | + * @return WP_Query $query |
|
| 2097 | + */ |
|
| 2098 | + public static function course_query_filter( $query ){ |
|
| 2099 | + |
|
| 2100 | + // exit early for no course queries and admin queries |
|
| 2101 | + if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2102 | + return $query; |
|
| 2103 | + } |
|
| 2104 | + |
|
| 2105 | + global $post; // used to get the current page id for my courses |
|
| 2106 | + |
|
| 2107 | + // for the course archive page |
|
| 2108 | + if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2109 | + { |
|
| 2110 | + /** |
|
| 2111 | + * sensei_archive_courses_per_page |
|
| 2112 | + * |
|
| 2113 | + * Sensei courses per page on the course |
|
| 2114 | + * archive |
|
| 2115 | + * |
|
| 2116 | + * @since 1.9.0 |
|
| 2117 | + * @param integer $posts_per_page default 10 |
|
| 2118 | + */ |
|
| 2119 | + $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) ); |
|
| 2120 | + |
|
| 2121 | + } |
|
| 2122 | + // for the my courses page |
|
| 2123 | + elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2124 | + { |
|
| 2125 | + /** |
|
| 2126 | + * sensei_my_courses_per_page |
|
| 2127 | + * |
|
| 2128 | + * Sensei courses per page on the my courses page |
|
| 2129 | + * as set in the settings |
|
| 2130 | + * |
|
| 2131 | + * @since 1.9.0 |
|
| 2132 | + * @param integer $posts_per_page default 10 |
|
| 2133 | + */ |
|
| 2134 | + $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) ); |
|
| 2135 | + |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + return $query; |
|
| 2139 | + |
|
| 2140 | + }// end course_query_filter |
|
| 2141 | + |
|
| 2142 | + /** |
|
| 2143 | + * Determine the class of the course loop |
|
| 2144 | + * |
|
| 2145 | + * This will output .first or .last and .course-item-number-x |
|
| 2146 | + * |
|
| 2147 | + * @return array $extra_classes |
|
| 2148 | + * @since 1.9.0 |
|
| 2149 | + */ |
|
| 2150 | + public static function get_course_loop_content_class () |
|
| 2151 | + { |
|
| 2152 | + |
|
| 2153 | + global $sensei_course_loop; |
|
| 2154 | + |
|
| 2155 | + |
|
| 2156 | + if( !isset( $sensei_course_loop ) ){ |
|
| 2157 | + $sensei_course_loop = array(); |
|
| 2158 | + } |
|
| 2159 | + |
|
| 2160 | + if (!isset($sensei_course_loop['counter'])) { |
|
| 2161 | + $sensei_course_loop['counter'] = 0; |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + if (!isset($sensei_course_loop['columns'])) { |
|
| 2165 | + $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + // increment the counter |
|
| 2169 | + $sensei_course_loop['counter']++; |
|
| 2170 | + |
|
| 2171 | + $extra_classes = array(); |
|
| 2172 | + if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2173 | + $extra_classes[] = 'first'; |
|
| 2174 | + } |
|
| 2175 | + |
|
| 2176 | + if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2177 | + $extra_classes[] = 'last'; |
|
| 2178 | + } |
|
| 2179 | + |
|
| 2180 | + // add the item number to the classes as well. |
|
| 2181 | + $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2182 | + |
|
| 2183 | + /** |
|
| 2184 | + * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2185 | + * which is called from the course loop content-course.php |
|
| 2186 | + * |
|
| 2187 | + * @since 1.9.0 |
|
| 2188 | + * |
|
| 2189 | + * @param array $extra_classes |
|
| 2190 | + * @param WP_Post $loop_current_course |
|
| 2191 | + */ |
|
| 2192 | + return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2193 | + |
|
| 2194 | + }// end get_course_loop_class |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * Get the number of columns set for Sensei courses |
|
| 2198 | + * |
|
| 2199 | + * @since 1.9.0 |
|
| 2200 | + * @return mixed|void |
|
| 2201 | + */ |
|
| 2202 | + public static function get_loop_number_of_columns(){ |
|
| 2203 | + |
|
| 2204 | + /** |
|
| 2205 | + * Filter the number of columns on the course archive page. |
|
| 2206 | + * |
|
| 2207 | + * @since 1.9.0 |
|
| 2208 | + * @param int $number_of_columns default 1 |
|
| 2209 | + */ |
|
| 2210 | + return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2211 | + |
|
| 2212 | + } |
|
| 2213 | + |
|
| 2214 | + /** |
|
| 2215 | + * Output the course archive filter markup |
|
| 2216 | + * |
|
| 2217 | + * hooked into sensei_loop_course_before |
|
| 2218 | + * |
|
| 2219 | + * @since 1.9.0 |
|
| 2220 | + * @param |
|
| 2221 | + */ |
|
| 2222 | + public static function course_archive_sorting( $query ){ |
|
| 2223 | + |
|
| 2224 | + // don't show on category pages and other pages |
|
| 2225 | + if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2226 | + return; |
|
| 2227 | + } |
|
| 2228 | + |
|
| 2229 | + /** |
|
| 2230 | + * Filter the sensei archive course order by values |
|
| 2231 | + * |
|
| 2232 | + * @since 1.9.0 |
|
| 2233 | + * @param array $options { |
|
| 2234 | + * @type string $option_value |
|
| 2235 | + * @type string $option_string |
|
| 2236 | + * } |
|
| 2237 | + */ |
|
| 2238 | + $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2239 | + "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2240 | + "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2241 | + )); |
|
| 2242 | + |
|
| 2243 | + // setup the currently selected item |
|
| 2244 | + $selected = 'newness'; |
|
| 2245 | + if( isset( $_GET['orderby'] ) ){ |
|
| 2246 | + |
|
| 2247 | + $selected = $_GET[ 'orderby' ]; |
|
| 2248 | + |
|
| 2249 | + } |
|
| 2250 | + |
|
| 2251 | + ?> |
|
| 2252 | 2252 | |
| 2253 | 2253 | <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST"> |
| 2254 | 2254 | <select name="course-orderby" class="orderby"> |
| 2255 | 2255 | <?php |
| 2256 | - foreach( $course_order_by_options as $value => $text ){ |
|
| 2256 | + foreach( $course_order_by_options as $value => $text ){ |
|
| 2257 | 2257 | |
| 2258 | - echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2258 | + echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2259 | 2259 | |
| 2260 | - } |
|
| 2261 | - ?> |
|
| 2260 | + } |
|
| 2261 | + ?> |
|
| 2262 | 2262 | </select> |
| 2263 | 2263 | </form> |
| 2264 | 2264 | |
| 2265 | 2265 | <?php |
| 2266 | - }// end course archive filters |
|
| 2267 | - |
|
| 2268 | - /** |
|
| 2269 | - * Output the course archive filter markup |
|
| 2270 | - * |
|
| 2271 | - * hooked into sensei_loop_course_before |
|
| 2272 | - * |
|
| 2273 | - * @since 1.9.0 |
|
| 2274 | - * @param |
|
| 2275 | - */ |
|
| 2276 | - public static function course_archive_filters( $query ){ |
|
| 2277 | - |
|
| 2278 | - // don't show on category pages |
|
| 2279 | - if( is_tax('course-category') ){ |
|
| 2280 | - return; |
|
| 2281 | - } |
|
| 2282 | - |
|
| 2283 | - /** |
|
| 2284 | - * filter the course archive filter buttons |
|
| 2285 | - * |
|
| 2286 | - * @since 1.9.0 |
|
| 2287 | - * @param array $filters{ |
|
| 2288 | - * @type array ( $id, $url , $title ) |
|
| 2289 | - * } |
|
| 2290 | - * |
|
| 2291 | - */ |
|
| 2292 | - $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2293 | - array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2294 | - array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2295 | - )); |
|
| 2296 | - |
|
| 2297 | - |
|
| 2298 | - ?> |
|
| 2266 | + }// end course archive filters |
|
| 2267 | + |
|
| 2268 | + /** |
|
| 2269 | + * Output the course archive filter markup |
|
| 2270 | + * |
|
| 2271 | + * hooked into sensei_loop_course_before |
|
| 2272 | + * |
|
| 2273 | + * @since 1.9.0 |
|
| 2274 | + * @param |
|
| 2275 | + */ |
|
| 2276 | + public static function course_archive_filters( $query ){ |
|
| 2277 | + |
|
| 2278 | + // don't show on category pages |
|
| 2279 | + if( is_tax('course-category') ){ |
|
| 2280 | + return; |
|
| 2281 | + } |
|
| 2282 | + |
|
| 2283 | + /** |
|
| 2284 | + * filter the course archive filter buttons |
|
| 2285 | + * |
|
| 2286 | + * @since 1.9.0 |
|
| 2287 | + * @param array $filters{ |
|
| 2288 | + * @type array ( $id, $url , $title ) |
|
| 2289 | + * } |
|
| 2290 | + * |
|
| 2291 | + */ |
|
| 2292 | + $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2293 | + array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2294 | + array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2295 | + )); |
|
| 2296 | + |
|
| 2297 | + |
|
| 2298 | + ?> |
|
| 2299 | 2299 | <ul class="sensei-course-filters clearfix" > |
| 2300 | 2300 | <?php |
| 2301 | 2301 | |
| 2302 | - //determine the current active url |
|
| 2303 | - $current_url = Sensei_Utils::get_current_url(); |
|
| 2302 | + //determine the current active url |
|
| 2303 | + $current_url = Sensei_Utils::get_current_url(); |
|
| 2304 | 2304 | |
| 2305 | - foreach( $filters as $filter ) { |
|
| 2305 | + foreach( $filters as $filter ) { |
|
| 2306 | 2306 | |
| 2307 | - $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2307 | + $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2308 | 2308 | |
| 2309 | - echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2309 | + echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2310 | 2310 | |
| 2311 | - } |
|
| 2312 | - ?> |
|
| 2311 | + } |
|
| 2312 | + ?> |
|
| 2313 | 2313 | |
| 2314 | 2314 | </ul> |
| 2315 | 2315 | |
| 2316 | 2316 | <?php |
| 2317 | 2317 | |
| 2318 | - } |
|
| 2318 | + } |
|
| 2319 | 2319 | |
| 2320 | - /** |
|
| 2321 | - * if the featured link is clicked on the course archive page |
|
| 2322 | - * filter the courses returned to only show those featured |
|
| 2323 | - * |
|
| 2324 | - * Hooked into pre_get_posts |
|
| 2325 | - * |
|
| 2326 | - * @since 1.9.0 |
|
| 2327 | - * @param WP_Query $query |
|
| 2328 | - * @return WP_Query $query |
|
| 2329 | - */ |
|
| 2330 | - public static function course_archive_featured_filter( $query ){ |
|
| 2331 | - |
|
| 2332 | - if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2333 | - //setup meta query for featured courses |
|
| 2334 | - $query->set( 'meta_value', 'featured' ); |
|
| 2335 | - $query->set( 'meta_key', '_course_featured' ); |
|
| 2336 | - $query->set( 'meta_compare', '=' ); |
|
| 2337 | - } |
|
| 2338 | - |
|
| 2339 | - return $query; |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - /** |
|
| 2343 | - * if the course order drop down is changed |
|
| 2344 | - * |
|
| 2345 | - * Hooked into pre_get_posts |
|
| 2346 | - * |
|
| 2347 | - * @since 1.9.0 |
|
| 2348 | - * @param WP_Query $query |
|
| 2349 | - * @return WP_Query $query |
|
| 2350 | - */ |
|
| 2351 | - public static function course_archive_order_by_title( $query ){ |
|
| 2352 | - |
|
| 2353 | - if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2354 | - && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2355 | - // setup the order by title for this query |
|
| 2356 | - $query->set( 'orderby', 'title' ); |
|
| 2357 | - $query->set( 'order', 'ASC' ); |
|
| 2358 | - } |
|
| 2359 | - |
|
| 2360 | - return $query; |
|
| 2361 | - } |
|
| 2362 | - |
|
| 2363 | - |
|
| 2364 | - /** |
|
| 2365 | - * Get the link to the courses page. This will be the course post type archive |
|
| 2366 | - * page link or the page the user set in their settings |
|
| 2367 | - * |
|
| 2368 | - * @since 1.9.0 |
|
| 2369 | - * @return string $course_page_url |
|
| 2370 | - */ |
|
| 2371 | - public static function get_courses_page_url(){ |
|
| 2372 | - |
|
| 2373 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2374 | - $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2320 | + /** |
|
| 2321 | + * if the featured link is clicked on the course archive page |
|
| 2322 | + * filter the courses returned to only show those featured |
|
| 2323 | + * |
|
| 2324 | + * Hooked into pre_get_posts |
|
| 2325 | + * |
|
| 2326 | + * @since 1.9.0 |
|
| 2327 | + * @param WP_Query $query |
|
| 2328 | + * @return WP_Query $query |
|
| 2329 | + */ |
|
| 2330 | + public static function course_archive_featured_filter( $query ){ |
|
| 2375 | 2331 | |
| 2376 | - return $course_page_url; |
|
| 2377 | - |
|
| 2378 | - }// get_course_url |
|
| 2332 | + if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2333 | + //setup meta query for featured courses |
|
| 2334 | + $query->set( 'meta_value', 'featured' ); |
|
| 2335 | + $query->set( 'meta_key', '_course_featured' ); |
|
| 2336 | + $query->set( 'meta_compare', '=' ); |
|
| 2337 | + } |
|
| 2379 | 2338 | |
| 2380 | - /** |
|
| 2381 | - * Output the headers on the course archive page |
|
| 2382 | - * |
|
| 2383 | - * Hooked into the sensei_archive_title |
|
| 2384 | - * |
|
| 2385 | - * @since 1.9.0 |
|
| 2386 | - * @param string $query_type |
|
| 2387 | - * @param string $before_html |
|
| 2388 | - * @param string $after_html |
|
| 2389 | - * @return void |
|
| 2390 | - */ |
|
| 2391 | - public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2339 | + return $query; |
|
| 2340 | + } |
|
| 2392 | 2341 | |
| 2393 | - if( ! is_post_type_archive('course') ){ |
|
| 2394 | - return; |
|
| 2395 | - } |
|
| 2342 | + /** |
|
| 2343 | + * if the course order drop down is changed |
|
| 2344 | + * |
|
| 2345 | + * Hooked into pre_get_posts |
|
| 2346 | + * |
|
| 2347 | + * @since 1.9.0 |
|
| 2348 | + * @param WP_Query $query |
|
| 2349 | + * @return WP_Query $query |
|
| 2350 | + */ |
|
| 2351 | + public static function course_archive_order_by_title( $query ){ |
|
| 2396 | 2352 | |
| 2397 | - // deprecated since 1.9.0 |
|
| 2398 | - sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2353 | + if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2354 | + && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2355 | + // setup the order by title for this query |
|
| 2356 | + $query->set( 'orderby', 'title' ); |
|
| 2357 | + $query->set( 'order', 'ASC' ); |
|
| 2358 | + } |
|
| 2399 | 2359 | |
| 2400 | - $html = ''; |
|
| 2360 | + return $query; |
|
| 2361 | + } |
|
| 2401 | 2362 | |
| 2402 | - if( empty( $before_html ) ){ |
|
| 2403 | 2363 | |
| 2404 | - $before_html = '<header class="archive-header"><h1>'; |
|
| 2364 | + /** |
|
| 2365 | + * Get the link to the courses page. This will be the course post type archive |
|
| 2366 | + * page link or the page the user set in their settings |
|
| 2367 | + * |
|
| 2368 | + * @since 1.9.0 |
|
| 2369 | + * @return string $course_page_url |
|
| 2370 | + */ |
|
| 2371 | + public static function get_courses_page_url(){ |
|
| 2405 | 2372 | |
| 2406 | - } |
|
| 2373 | + $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2374 | + $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2407 | 2375 | |
| 2408 | - if( empty( $after_html ) ){ |
|
| 2376 | + return $course_page_url; |
|
| 2409 | 2377 | |
| 2410 | - $after_html = '</h1></header>'; |
|
| 2378 | + }// get_course_url |
|
| 2411 | 2379 | |
| 2412 | - } |
|
| 2380 | + /** |
|
| 2381 | + * Output the headers on the course archive page |
|
| 2382 | + * |
|
| 2383 | + * Hooked into the sensei_archive_title |
|
| 2384 | + * |
|
| 2385 | + * @since 1.9.0 |
|
| 2386 | + * @param string $query_type |
|
| 2387 | + * @param string $before_html |
|
| 2388 | + * @param string $after_html |
|
| 2389 | + * @return void |
|
| 2390 | + */ |
|
| 2391 | + public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2413 | 2392 | |
| 2414 | - if ( is_tax( 'course-category' ) ) { |
|
| 2393 | + if( ! is_post_type_archive('course') ){ |
|
| 2394 | + return; |
|
| 2395 | + } |
|
| 2415 | 2396 | |
| 2416 | - global $wp_query; |
|
| 2397 | + // deprecated since 1.9.0 |
|
| 2398 | + sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2417 | 2399 | |
| 2418 | - $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2419 | - $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2420 | - $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2421 | - $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2422 | - echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2423 | - return; |
|
| 2400 | + $html = ''; |
|
| 2424 | 2401 | |
| 2425 | - } // End If Statement |
|
| 2402 | + if( empty( $before_html ) ){ |
|
| 2426 | 2403 | |
| 2427 | - switch ( $query_type ) { |
|
| 2428 | - case 'newcourses': |
|
| 2429 | - $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2430 | - break; |
|
| 2431 | - case 'featuredcourses': |
|
| 2432 | - $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2433 | - break; |
|
| 2434 | - case 'freecourses': |
|
| 2435 | - $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2436 | - break; |
|
| 2437 | - case 'paidcourses': |
|
| 2438 | - $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2439 | - break; |
|
| 2440 | - default: |
|
| 2441 | - $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2442 | - break; |
|
| 2443 | - } // End Switch Statement |
|
| 2404 | + $before_html = '<header class="archive-header"><h1>'; |
|
| 2444 | 2405 | |
| 2445 | - echo apply_filters( 'course_archive_title', $html ); |
|
| 2406 | + } |
|
| 2446 | 2407 | |
| 2447 | - }//course_archive_header |
|
| 2408 | + if( empty( $after_html ) ){ |
|
| 2448 | 2409 | |
| 2410 | + $after_html = '</h1></header>'; |
|
| 2449 | 2411 | |
| 2450 | - /** |
|
| 2451 | - * Filter the single course content |
|
| 2452 | - * taking into account if the user has access. |
|
| 2453 | - * |
|
| 2454 | - * @1.9.0 |
|
| 2455 | - * |
|
| 2456 | - * @param string $content |
|
| 2457 | - * @return string $content or $excerpt |
|
| 2458 | - */ |
|
| 2459 | - public static function single_course_content( $content ){ |
|
| 2412 | + } |
|
| 2460 | 2413 | |
| 2461 | - if( ! is_singular('course') ){ |
|
| 2414 | + if ( is_tax( 'course-category' ) ) { |
|
| 2462 | 2415 | |
| 2463 | - return $content; |
|
| 2416 | + global $wp_query; |
|
| 2464 | 2417 | |
| 2465 | - } |
|
| 2418 | + $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2419 | + $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2420 | + $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2421 | + $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2422 | + echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2423 | + return; |
|
| 2466 | 2424 | |
| 2467 | - // Content Access Permissions |
|
| 2468 | - $access_permission = false; |
|
| 2425 | + } // End If Statement |
|
| 2469 | 2426 | |
| 2470 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2427 | + switch ( $query_type ) { |
|
| 2428 | + case 'newcourses': |
|
| 2429 | + $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2430 | + break; |
|
| 2431 | + case 'featuredcourses': |
|
| 2432 | + $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2433 | + break; |
|
| 2434 | + case 'freecourses': |
|
| 2435 | + $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2436 | + break; |
|
| 2437 | + case 'paidcourses': |
|
| 2438 | + $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2439 | + break; |
|
| 2440 | + default: |
|
| 2441 | + $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2442 | + break; |
|
| 2443 | + } // End Switch Statement |
|
| 2471 | 2444 | |
| 2472 | - $access_permission = true; |
|
| 2445 | + echo apply_filters( 'course_archive_title', $html ); |
|
| 2473 | 2446 | |
| 2474 | - } // End If Statement |
|
| 2447 | + }//course_archive_header |
|
| 2475 | 2448 | |
| 2476 | - // Check if the user is taking the course |
|
| 2477 | - $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2478 | 2449 | |
| 2479 | - if(Sensei_WC::is_woocommerce_active()) { |
|
| 2450 | + /** |
|
| 2451 | + * Filter the single course content |
|
| 2452 | + * taking into account if the user has access. |
|
| 2453 | + * |
|
| 2454 | + * @1.9.0 |
|
| 2455 | + * |
|
| 2456 | + * @param string $content |
|
| 2457 | + * @return string $content or $excerpt |
|
| 2458 | + */ |
|
| 2459 | + public static function single_course_content( $content ){ |
|
| 2480 | 2460 | |
| 2481 | - $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2482 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2461 | + if( ! is_singular('course') ){ |
|
| 2483 | 2462 | |
| 2484 | - $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2463 | + return $content; |
|
| 2485 | 2464 | |
| 2486 | - } else { |
|
| 2465 | + } |
|
| 2487 | 2466 | |
| 2488 | - $has_product_attached = false; |
|
| 2467 | + // Content Access Permissions |
|
| 2468 | + $access_permission = false; |
|
| 2489 | 2469 | |
| 2490 | - } |
|
| 2470 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2491 | 2471 | |
| 2492 | - if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2493 | - || ( $access_permission && !$has_product_attached) |
|
| 2494 | - || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2472 | + $access_permission = true; |
|
| 2495 | 2473 | |
| 2496 | - return $content; |
|
| 2474 | + } // End If Statement |
|
| 2497 | 2475 | |
| 2498 | - } else { |
|
| 2476 | + // Check if the user is taking the course |
|
| 2477 | + $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2499 | 2478 | |
| 2500 | - return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2479 | + if(Sensei_WC::is_woocommerce_active()) { |
|
| 2501 | 2480 | |
| 2502 | - } |
|
| 2481 | + $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2482 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2503 | 2483 | |
| 2504 | - }// end single_course_content |
|
| 2484 | + $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2505 | 2485 | |
| 2506 | - /** |
|
| 2507 | - * Output the the single course lessons title with markup. |
|
| 2508 | - * |
|
| 2509 | - * @since 1.9.0 |
|
| 2510 | - */ |
|
| 2511 | - public static function the_course_lessons_title(){ |
|
| 2512 | - global $post; |
|
| 2513 | - $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2514 | - $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2486 | + } else { |
|
| 2515 | 2487 | |
| 2516 | - // title should be Other Lessons if there are lessons belonging to models. |
|
| 2517 | - $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2518 | - if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2488 | + $has_product_attached = false; |
|
| 2519 | 2489 | |
| 2520 | - $title = __('Lessons', 'woothemes-sensei'); |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2493 | + || ( $access_permission && !$has_product_attached) |
|
| 2494 | + || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2495 | + |
|
| 2496 | + return $content; |
|
| 2521 | 2497 | |
| 2522 | - } |
|
| 2498 | + } else { |
|
| 2523 | 2499 | |
| 2524 | - /** |
|
| 2525 | - * hook document in class-woothemes-sensei-message.php |
|
| 2526 | - */ |
|
| 2527 | - $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2500 | + return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2528 | 2501 | |
| 2529 | - ob_start(); // start capturing the following output. |
|
| 2502 | + } |
|
| 2530 | 2503 | |
| 2531 | - ?> |
|
| 2504 | + }// end single_course_content |
|
| 2505 | + |
|
| 2506 | + /** |
|
| 2507 | + * Output the the single course lessons title with markup. |
|
| 2508 | + * |
|
| 2509 | + * @since 1.9.0 |
|
| 2510 | + */ |
|
| 2511 | + public static function the_course_lessons_title(){ |
|
| 2512 | + global $post; |
|
| 2513 | + $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2514 | + $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2515 | + |
|
| 2516 | + // title should be Other Lessons if there are lessons belonging to models. |
|
| 2517 | + $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2518 | + if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2519 | + |
|
| 2520 | + $title = __('Lessons', 'woothemes-sensei'); |
|
| 2521 | + |
|
| 2522 | + } |
|
| 2523 | + |
|
| 2524 | + /** |
|
| 2525 | + * hook document in class-woothemes-sensei-message.php |
|
| 2526 | + */ |
|
| 2527 | + $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2528 | + |
|
| 2529 | + ob_start(); // start capturing the following output. |
|
| 2530 | + |
|
| 2531 | + ?> |
|
| 2532 | 2532 | |
| 2533 | 2533 | <header> |
| 2534 | 2534 | <h2> <?php echo $title; ?> </h2> |
@@ -2536,277 +2536,277 @@ discard block |
||
| 2536 | 2536 | |
| 2537 | 2537 | <?php |
| 2538 | 2538 | |
| 2539 | - /** |
|
| 2540 | - * Filter the title and markup that appears above the lessons on a single course |
|
| 2541 | - * page. |
|
| 2542 | - * |
|
| 2543 | - * @since 1.9.0 |
|
| 2544 | - * @param string $lessons_title_html |
|
| 2545 | - */ |
|
| 2546 | - echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2547 | - |
|
| 2548 | - }// end the_course_lessons_title |
|
| 2549 | - |
|
| 2550 | - /** |
|
| 2551 | - * This function loads the global wp_query object with with lessons |
|
| 2552 | - * of the current course. It is designed to be used on the single-course template |
|
| 2553 | - * and expects the global post to be a singular course. |
|
| 2554 | - * |
|
| 2555 | - * This function excludes lessons belonging to modules as they are |
|
| 2556 | - * queried separately. |
|
| 2557 | - * |
|
| 2558 | - * @since 1.9.0 |
|
| 2559 | - * @global $wp_query |
|
| 2560 | - */ |
|
| 2561 | - public static function load_single_course_lessons_query(){ |
|
| 2562 | - |
|
| 2563 | - global $post, $wp_query; |
|
| 2539 | + /** |
|
| 2540 | + * Filter the title and markup that appears above the lessons on a single course |
|
| 2541 | + * page. |
|
| 2542 | + * |
|
| 2543 | + * @since 1.9.0 |
|
| 2544 | + * @param string $lessons_title_html |
|
| 2545 | + */ |
|
| 2546 | + echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2564 | 2547 | |
| 2565 | - $course_id = $post->ID; |
|
| 2548 | + }// end the_course_lessons_title |
|
| 2566 | 2549 | |
| 2567 | - if( 'course' != get_post_type( $course_id ) ){ |
|
| 2568 | - return; |
|
| 2569 | - } |
|
| 2550 | + /** |
|
| 2551 | + * This function loads the global wp_query object with with lessons |
|
| 2552 | + * of the current course. It is designed to be used on the single-course template |
|
| 2553 | + * and expects the global post to be a singular course. |
|
| 2554 | + * |
|
| 2555 | + * This function excludes lessons belonging to modules as they are |
|
| 2556 | + * queried separately. |
|
| 2557 | + * |
|
| 2558 | + * @since 1.9.0 |
|
| 2559 | + * @global $wp_query |
|
| 2560 | + */ |
|
| 2561 | + public static function load_single_course_lessons_query(){ |
|
| 2570 | 2562 | |
| 2571 | - $course_lesson_query_args = array( |
|
| 2572 | - 'post_type' => 'lesson', |
|
| 2573 | - 'posts_per_page' => 500, |
|
| 2574 | - 'orderby' => 'date', |
|
| 2575 | - 'order' => 'ASC', |
|
| 2576 | - 'meta_query' => array( |
|
| 2577 | - array( |
|
| 2578 | - 'key' => '_lesson_course', |
|
| 2579 | - 'value' => intval( $course_id ), |
|
| 2580 | - ), |
|
| 2581 | - ), |
|
| 2582 | - 'post_status' => 'public', |
|
| 2583 | - 'suppress_filters' => 0, |
|
| 2584 | - ); |
|
| 2563 | + global $post, $wp_query; |
|
| 2585 | 2564 | |
| 2586 | - // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2587 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2588 | - if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2565 | + $course_id = $post->ID; |
|
| 2589 | 2566 | |
| 2590 | - $terms_ids = array(); |
|
| 2591 | - foreach( $modules as $term ){ |
|
| 2567 | + if( 'course' != get_post_type( $course_id ) ){ |
|
| 2568 | + return; |
|
| 2569 | + } |
|
| 2592 | 2570 | |
| 2593 | - $terms_ids[] = $term->term_id; |
|
| 2571 | + $course_lesson_query_args = array( |
|
| 2572 | + 'post_type' => 'lesson', |
|
| 2573 | + 'posts_per_page' => 500, |
|
| 2574 | + 'orderby' => 'date', |
|
| 2575 | + 'order' => 'ASC', |
|
| 2576 | + 'meta_query' => array( |
|
| 2577 | + array( |
|
| 2578 | + 'key' => '_lesson_course', |
|
| 2579 | + 'value' => intval( $course_id ), |
|
| 2580 | + ), |
|
| 2581 | + ), |
|
| 2582 | + 'post_status' => 'public', |
|
| 2583 | + 'suppress_filters' => 0, |
|
| 2584 | + ); |
|
| 2585 | + |
|
| 2586 | + // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2587 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2588 | + if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2589 | + |
|
| 2590 | + $terms_ids = array(); |
|
| 2591 | + foreach( $modules as $term ){ |
|
| 2592 | + |
|
| 2593 | + $terms_ids[] = $term->term_id; |
|
| 2594 | 2594 | |
| 2595 | - } |
|
| 2595 | + } |
|
| 2596 | 2596 | |
| 2597 | - $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2598 | - array( |
|
| 2599 | - 'taxonomy' => 'module', |
|
| 2600 | - 'field' => 'id', |
|
| 2601 | - 'terms' => $terms_ids, |
|
| 2602 | - 'operator' => 'NOT IN', |
|
| 2603 | - ), |
|
| 2604 | - ); |
|
| 2605 | - } |
|
| 2597 | + $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2598 | + array( |
|
| 2599 | + 'taxonomy' => 'module', |
|
| 2600 | + 'field' => 'id', |
|
| 2601 | + 'terms' => $terms_ids, |
|
| 2602 | + 'operator' => 'NOT IN', |
|
| 2603 | + ), |
|
| 2604 | + ); |
|
| 2605 | + } |
|
| 2606 | 2606 | |
| 2607 | - $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2607 | + $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2608 | 2608 | |
| 2609 | - }// load_single_course_lessons |
|
| 2609 | + }// load_single_course_lessons |
|
| 2610 | 2610 | |
| 2611 | - /** |
|
| 2612 | - * Flush the rewrite rules for a course post type |
|
| 2613 | - * |
|
| 2614 | - * @since 1.9.0 |
|
| 2615 | - * |
|
| 2616 | - * @param $post_id |
|
| 2617 | - */ |
|
| 2618 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 2611 | + /** |
|
| 2612 | + * Flush the rewrite rules for a course post type |
|
| 2613 | + * |
|
| 2614 | + * @since 1.9.0 |
|
| 2615 | + * |
|
| 2616 | + * @param $post_id |
|
| 2617 | + */ |
|
| 2618 | + public static function flush_rewrite_rules( $post_id ){ |
|
| 2619 | 2619 | |
| 2620 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2620 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2621 | 2621 | |
| 2622 | - return; |
|
| 2622 | + return; |
|
| 2623 | 2623 | |
| 2624 | - } |
|
| 2624 | + } |
|
| 2625 | 2625 | |
| 2626 | 2626 | |
| 2627 | - if( 'course' == get_post_type( $post_id ) ){ |
|
| 2627 | + if( 'course' == get_post_type( $post_id ) ){ |
|
| 2628 | 2628 | |
| 2629 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 2629 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 2630 | 2630 | |
| 2631 | - } |
|
| 2631 | + } |
|
| 2632 | 2632 | |
| 2633 | - } |
|
| 2633 | + } |
|
| 2634 | 2634 | |
| 2635 | - /** |
|
| 2636 | - * Optionally return the full content on the single course pages |
|
| 2637 | - * depending on the users course_single_content_display setting |
|
| 2638 | - * |
|
| 2639 | - * @since 1.9.0 |
|
| 2640 | - * @param $excerpt |
|
| 2641 | - * @return string |
|
| 2642 | - */ |
|
| 2643 | - public static function full_content_excerpt_override( $excerpt ){ |
|
| 2635 | + /** |
|
| 2636 | + * Optionally return the full content on the single course pages |
|
| 2637 | + * depending on the users course_single_content_display setting |
|
| 2638 | + * |
|
| 2639 | + * @since 1.9.0 |
|
| 2640 | + * @param $excerpt |
|
| 2641 | + * @return string |
|
| 2642 | + */ |
|
| 2643 | + public static function full_content_excerpt_override( $excerpt ){ |
|
| 2644 | 2644 | |
| 2645 | - if ( is_singular('course') && |
|
| 2646 | - 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2645 | + if ( is_singular('course') && |
|
| 2646 | + 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2647 | 2647 | |
| 2648 | - return get_the_content(); |
|
| 2648 | + return get_the_content(); |
|
| 2649 | 2649 | |
| 2650 | - } else { |
|
| 2650 | + } else { |
|
| 2651 | 2651 | |
| 2652 | - return $excerpt; |
|
| 2652 | + return $excerpt; |
|
| 2653 | 2653 | |
| 2654 | - } |
|
| 2654 | + } |
|
| 2655 | 2655 | |
| 2656 | - } |
|
| 2656 | + } |
|
| 2657 | 2657 | |
| 2658 | - /** |
|
| 2659 | - * Output the course actions like start taking course, register, add to cart etc. |
|
| 2660 | - * |
|
| 2661 | - * @since 1.9.0 |
|
| 2662 | - */ |
|
| 2663 | - public static function the_course_enrolment_actions(){ |
|
| 2664 | - ?> |
|
| 2658 | + /** |
|
| 2659 | + * Output the course actions like start taking course, register, add to cart etc. |
|
| 2660 | + * |
|
| 2661 | + * @since 1.9.0 |
|
| 2662 | + */ |
|
| 2663 | + public static function the_course_enrolment_actions(){ |
|
| 2664 | + ?> |
|
| 2665 | 2665 | <section class="course-meta course-enrolment"> |
| 2666 | 2666 | <?php |
| 2667 | - global $post, $current_user; |
|
| 2668 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2669 | - if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2670 | - |
|
| 2671 | - // Get the product ID |
|
| 2672 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2673 | - |
|
| 2674 | - // Check for woocommerce |
|
| 2675 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2676 | - sensei_wc_add_to_cart($post->ID); |
|
| 2677 | - } else { |
|
| 2678 | - sensei_start_course_form($post->ID); |
|
| 2679 | - } // End If Statement |
|
| 2680 | - |
|
| 2681 | - } elseif ( is_user_logged_in() ) { |
|
| 2682 | - |
|
| 2683 | - // Check if course is completed |
|
| 2684 | - $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2685 | - $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2686 | - // Success message |
|
| 2687 | - if ( $completed_course ) { ?> |
|
| 2667 | + global $post, $current_user; |
|
| 2668 | + $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2669 | + if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2670 | + |
|
| 2671 | + // Get the product ID |
|
| 2672 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2673 | + |
|
| 2674 | + // Check for woocommerce |
|
| 2675 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2676 | + sensei_wc_add_to_cart($post->ID); |
|
| 2677 | + } else { |
|
| 2678 | + sensei_start_course_form($post->ID); |
|
| 2679 | + } // End If Statement |
|
| 2680 | + |
|
| 2681 | + } elseif ( is_user_logged_in() ) { |
|
| 2682 | + |
|
| 2683 | + // Check if course is completed |
|
| 2684 | + $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2685 | + $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2686 | + // Success message |
|
| 2687 | + if ( $completed_course ) { ?> |
|
| 2688 | 2688 | <div class="status completed"><?php _e( 'Completed', 'woothemes-sensei' ); ?></div> |
| 2689 | 2689 | <?php |
| 2690 | - $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2691 | - if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2690 | + $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2691 | + if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2692 | 2692 | <p class="sensei-results-links"> |
| 2693 | 2693 | <?php |
| 2694 | - $results_link = ''; |
|
| 2695 | - if( $has_quizzes ) { |
|
| 2696 | - $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2697 | - } |
|
| 2698 | - $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2699 | - echo $results_link; |
|
| 2700 | - ?></p> |
|
| 2694 | + $results_link = ''; |
|
| 2695 | + if( $has_quizzes ) { |
|
| 2696 | + $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2697 | + } |
|
| 2698 | + $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2699 | + echo $results_link; |
|
| 2700 | + ?></p> |
|
| 2701 | 2701 | <?php } ?> |
| 2702 | 2702 | <?php } else { ?> |
| 2703 | 2703 | <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div> |
| 2704 | 2704 | <?php } |
| 2705 | 2705 | |
| 2706 | - } else { |
|
| 2707 | - // Get the product ID |
|
| 2708 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2709 | - // Check for woocommerce |
|
| 2710 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2706 | + } else { |
|
| 2707 | + // Get the product ID |
|
| 2708 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2709 | + // Check for woocommerce |
|
| 2710 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2711 | 2711 | |
| 2712 | - sensei_wc_add_to_cart($post->ID); |
|
| 2712 | + sensei_wc_add_to_cart($post->ID); |
|
| 2713 | 2713 | |
| 2714 | - } else { |
|
| 2714 | + } else { |
|
| 2715 | 2715 | |
| 2716 | - if( get_option( 'users_can_register') ) { |
|
| 2716 | + if( get_option( 'users_can_register') ) { |
|
| 2717 | 2717 | |
| 2718 | 2718 | |
| 2719 | - $my_courses_page_id = ''; |
|
| 2719 | + $my_courses_page_id = ''; |
|
| 2720 | 2720 | |
| 2721 | - /** |
|
| 2722 | - * Filter to force Sensei to output the default WordPress user |
|
| 2723 | - * registration link. |
|
| 2724 | - * |
|
| 2725 | - * @since 1.9.0 |
|
| 2726 | - * @param bool $wp_register_link default false |
|
| 2727 | - */ |
|
| 2721 | + /** |
|
| 2722 | + * Filter to force Sensei to output the default WordPress user |
|
| 2723 | + * registration link. |
|
| 2724 | + * |
|
| 2725 | + * @since 1.9.0 |
|
| 2726 | + * @param bool $wp_register_link default false |
|
| 2727 | + */ |
|
| 2728 | 2728 | |
| 2729 | - $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2729 | + $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2730 | 2730 | |
| 2731 | - $settings = Sensei()->settings->get_settings(); |
|
| 2732 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 2733 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2731 | + $settings = Sensei()->settings->get_settings(); |
|
| 2732 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 2733 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2734 | 2734 | |
| 2735 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2735 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2736 | 2736 | |
| 2737 | - } |
|
| 2737 | + } |
|
| 2738 | 2738 | |
| 2739 | - // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2740 | - // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2741 | - if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2739 | + // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2740 | + // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2741 | + if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2742 | 2742 | |
| 2743 | - $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2744 | - $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2745 | - echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2743 | + $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2744 | + $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2745 | + echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2746 | 2746 | |
| 2747 | - } else{ |
|
| 2747 | + } else{ |
|
| 2748 | 2748 | |
| 2749 | - wp_register( '<div class="status register">', '</div>' ); |
|
| 2749 | + wp_register( '<div class="status register">', '</div>' ); |
|
| 2750 | 2750 | |
| 2751 | - } |
|
| 2751 | + } |
|
| 2752 | 2752 | |
| 2753 | - } // end if user can register |
|
| 2753 | + } // end if user can register |
|
| 2754 | 2754 | |
| 2755 | - } // End If Statement |
|
| 2755 | + } // End If Statement |
|
| 2756 | 2756 | |
| 2757 | - } // End If Statement ?> |
|
| 2757 | + } // End If Statement ?> |
|
| 2758 | 2758 | |
| 2759 | 2759 | </section><?php |
| 2760 | 2760 | |
| 2761 | - }// end the_course_enrolment_actions |
|
| 2761 | + }// end the_course_enrolment_actions |
|
| 2762 | 2762 | |
| 2763 | - /** |
|
| 2764 | - * Output the course video inside the loop. |
|
| 2765 | - * |
|
| 2766 | - * @since 1.9.0 |
|
| 2767 | - */ |
|
| 2768 | - public static function the_course_video(){ |
|
| 2763 | + /** |
|
| 2764 | + * Output the course video inside the loop. |
|
| 2765 | + * |
|
| 2766 | + * @since 1.9.0 |
|
| 2767 | + */ |
|
| 2768 | + public static function the_course_video(){ |
|
| 2769 | 2769 | |
| 2770 | - global $post; |
|
| 2771 | - // Get the meta info |
|
| 2772 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2770 | + global $post; |
|
| 2771 | + // Get the meta info |
|
| 2772 | + $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2773 | 2773 | |
| 2774 | - if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2774 | + if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2775 | 2775 | |
| 2776 | - $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2776 | + $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2777 | 2777 | |
| 2778 | - } // End If Statement |
|
| 2778 | + } // End If Statement |
|
| 2779 | 2779 | |
| 2780 | - if ( '' != $course_video_embed ) { ?> |
|
| 2780 | + if ( '' != $course_video_embed ) { ?> |
|
| 2781 | 2781 | |
| 2782 | 2782 | <div class="course-video"> |
| 2783 | 2783 | <?php echo html_entity_decode($course_video_embed); ?> |
| 2784 | 2784 | </div> |
| 2785 | 2785 | |
| 2786 | 2786 | <?php } // End If Statement |
| 2787 | - } |
|
| 2787 | + } |
|
| 2788 | 2788 | |
| 2789 | - /** |
|
| 2790 | - * Output the title for the single lesson page |
|
| 2791 | - * |
|
| 2792 | - * @global $post |
|
| 2793 | - * @since 1.9.0 |
|
| 2794 | - */ |
|
| 2795 | - public static function the_title(){ |
|
| 2789 | + /** |
|
| 2790 | + * Output the title for the single lesson page |
|
| 2791 | + * |
|
| 2792 | + * @global $post |
|
| 2793 | + * @since 1.9.0 |
|
| 2794 | + */ |
|
| 2795 | + public static function the_title(){ |
|
| 2796 | 2796 | |
| 2797 | - global $post; |
|
| 2797 | + global $post; |
|
| 2798 | 2798 | |
| 2799 | - ?> |
|
| 2799 | + ?> |
|
| 2800 | 2800 | <header> |
| 2801 | 2801 | |
| 2802 | 2802 | <h1> |
| 2803 | 2803 | |
| 2804 | 2804 | <?php |
| 2805 | - /** |
|
| 2806 | - * Filter documented in class-sensei-messages.php the_title |
|
| 2807 | - */ |
|
| 2808 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2809 | - ?> |
|
| 2805 | + /** |
|
| 2806 | + * Filter documented in class-sensei-messages.php the_title |
|
| 2807 | + */ |
|
| 2808 | + echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2809 | + ?> |
|
| 2810 | 2810 | |
| 2811 | 2811 | </h1> |
| 2812 | 2812 | |
@@ -2814,111 +2814,111 @@ discard block |
||
| 2814 | 2814 | |
| 2815 | 2815 | <?php |
| 2816 | 2816 | |
| 2817 | - }//the_title |
|
| 2818 | - |
|
| 2819 | - /** |
|
| 2820 | - * Show the title on the course category pages |
|
| 2821 | - * |
|
| 2822 | - * @since 1.9.0 |
|
| 2823 | - */ |
|
| 2824 | - public static function course_category_title(){ |
|
| 2825 | - |
|
| 2826 | - if( ! is_tax( 'course-category' ) ){ |
|
| 2827 | - return; |
|
| 2828 | - } |
|
| 2829 | - |
|
| 2830 | - $category_slug = get_query_var('course-category'); |
|
| 2831 | - $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2832 | - |
|
| 2833 | - if( ! empty($term) ){ |
|
| 2834 | - |
|
| 2835 | - $title = $term->name; |
|
| 2836 | - |
|
| 2837 | - }else{ |
|
| 2838 | - |
|
| 2839 | - $title = 'Course Category'; |
|
| 2840 | - |
|
| 2841 | - } |
|
| 2842 | - |
|
| 2843 | - $html = '<h2 class="sensei-category-title">'; |
|
| 2844 | - $html .= __('Category') . ' ' . $title; |
|
| 2845 | - $html .= '</h2>'; |
|
| 2846 | - |
|
| 2847 | - echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2848 | - |
|
| 2849 | - }// course_category_title |
|
| 2850 | - |
|
| 2851 | - /** |
|
| 2852 | - * Alter the course query to respect the order set for courses and apply |
|
| 2853 | - * this on the course-category pages. |
|
| 2854 | - * |
|
| 2855 | - * @since 1.9.0 |
|
| 2856 | - * |
|
| 2857 | - * @param WP_Query $query |
|
| 2858 | - * @return WP_Query |
|
| 2859 | - */ |
|
| 2860 | - public static function alter_course_category_order( $query ){ |
|
| 2861 | - |
|
| 2862 | - if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2863 | - return $query; |
|
| 2864 | - } |
|
| 2865 | - |
|
| 2866 | - $order = get_option( 'sensei_course_order', '' ); |
|
| 2867 | - if( !empty( $order ) ){ |
|
| 2868 | - $query->set('orderby', 'menu_order' ); |
|
| 2869 | - $query->set('order', 'ASC' ); |
|
| 2870 | - } |
|
| 2871 | - |
|
| 2872 | - return $query; |
|
| 2873 | - |
|
| 2874 | - } |
|
| 2875 | - |
|
| 2876 | - /** |
|
| 2877 | - * The very basic course query arguments |
|
| 2878 | - * so we don't have to repeat this througout |
|
| 2879 | - * the code base. |
|
| 2880 | - * |
|
| 2881 | - * Usage: |
|
| 2882 | - * $args = Sensei_Course::get_default_query_args(); |
|
| 2883 | - * $args['custom_arg'] ='custom value'; |
|
| 2884 | - * $courses = get_posts( $args ) |
|
| 2885 | - * |
|
| 2886 | - * @since 1.9.0 |
|
| 2887 | - * |
|
| 2888 | - * @return array |
|
| 2889 | - */ |
|
| 2890 | - public static function get_default_query_args(){ |
|
| 2891 | - return array( |
|
| 2892 | - 'post_type' => 'course', |
|
| 2893 | - 'posts_per_page' => 1000, |
|
| 2894 | - 'orderby' => 'date', |
|
| 2895 | - 'order' => 'DESC', |
|
| 2896 | - 'suppress_filters' => 0 |
|
| 2897 | - ); |
|
| 2898 | - } |
|
| 2899 | - |
|
| 2900 | - /** |
|
| 2901 | - * Check if the prerequisite course is completed |
|
| 2902 | - * Courses with no pre-requisite should always return true |
|
| 2903 | - * |
|
| 2904 | - * @since 1.9.0 |
|
| 2905 | - * @param $course_id |
|
| 2906 | - * @return bool |
|
| 2907 | - */ |
|
| 2908 | - public static function is_prerequisite_complete( $course_id ){ |
|
| 2909 | - |
|
| 2910 | - $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2911 | - |
|
| 2912 | - // if it has a pre requisite course check it |
|
| 2913 | - if( ! empty( $course_prerequisite_id ) ){ |
|
| 2914 | - |
|
| 2915 | - return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2916 | - |
|
| 2917 | - } |
|
| 2918 | - |
|
| 2919 | - return true; |
|
| 2920 | - |
|
| 2921 | - }// end is_prerequisite_complete |
|
| 2817 | + }//the_title |
|
| 2818 | + |
|
| 2819 | + /** |
|
| 2820 | + * Show the title on the course category pages |
|
| 2821 | + * |
|
| 2822 | + * @since 1.9.0 |
|
| 2823 | + */ |
|
| 2824 | + public static function course_category_title(){ |
|
| 2825 | + |
|
| 2826 | + if( ! is_tax( 'course-category' ) ){ |
|
| 2827 | + return; |
|
| 2828 | + } |
|
| 2829 | + |
|
| 2830 | + $category_slug = get_query_var('course-category'); |
|
| 2831 | + $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2832 | + |
|
| 2833 | + if( ! empty($term) ){ |
|
| 2834 | + |
|
| 2835 | + $title = $term->name; |
|
| 2836 | + |
|
| 2837 | + }else{ |
|
| 2838 | + |
|
| 2839 | + $title = 'Course Category'; |
|
| 2840 | + |
|
| 2841 | + } |
|
| 2842 | + |
|
| 2843 | + $html = '<h2 class="sensei-category-title">'; |
|
| 2844 | + $html .= __('Category') . ' ' . $title; |
|
| 2845 | + $html .= '</h2>'; |
|
| 2846 | + |
|
| 2847 | + echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2848 | + |
|
| 2849 | + }// course_category_title |
|
| 2850 | + |
|
| 2851 | + /** |
|
| 2852 | + * Alter the course query to respect the order set for courses and apply |
|
| 2853 | + * this on the course-category pages. |
|
| 2854 | + * |
|
| 2855 | + * @since 1.9.0 |
|
| 2856 | + * |
|
| 2857 | + * @param WP_Query $query |
|
| 2858 | + * @return WP_Query |
|
| 2859 | + */ |
|
| 2860 | + public static function alter_course_category_order( $query ){ |
|
| 2861 | + |
|
| 2862 | + if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2863 | + return $query; |
|
| 2864 | + } |
|
| 2865 | + |
|
| 2866 | + $order = get_option( 'sensei_course_order', '' ); |
|
| 2867 | + if( !empty( $order ) ){ |
|
| 2868 | + $query->set('orderby', 'menu_order' ); |
|
| 2869 | + $query->set('order', 'ASC' ); |
|
| 2870 | + } |
|
| 2871 | + |
|
| 2872 | + return $query; |
|
| 2873 | + |
|
| 2874 | + } |
|
| 2875 | + |
|
| 2876 | + /** |
|
| 2877 | + * The very basic course query arguments |
|
| 2878 | + * so we don't have to repeat this througout |
|
| 2879 | + * the code base. |
|
| 2880 | + * |
|
| 2881 | + * Usage: |
|
| 2882 | + * $args = Sensei_Course::get_default_query_args(); |
|
| 2883 | + * $args['custom_arg'] ='custom value'; |
|
| 2884 | + * $courses = get_posts( $args ) |
|
| 2885 | + * |
|
| 2886 | + * @since 1.9.0 |
|
| 2887 | + * |
|
| 2888 | + * @return array |
|
| 2889 | + */ |
|
| 2890 | + public static function get_default_query_args(){ |
|
| 2891 | + return array( |
|
| 2892 | + 'post_type' => 'course', |
|
| 2893 | + 'posts_per_page' => 1000, |
|
| 2894 | + 'orderby' => 'date', |
|
| 2895 | + 'order' => 'DESC', |
|
| 2896 | + 'suppress_filters' => 0 |
|
| 2897 | + ); |
|
| 2898 | + } |
|
| 2899 | + |
|
| 2900 | + /** |
|
| 2901 | + * Check if the prerequisite course is completed |
|
| 2902 | + * Courses with no pre-requisite should always return true |
|
| 2903 | + * |
|
| 2904 | + * @since 1.9.0 |
|
| 2905 | + * @param $course_id |
|
| 2906 | + * @return bool |
|
| 2907 | + */ |
|
| 2908 | + public static function is_prerequisite_complete( $course_id ){ |
|
| 2909 | + |
|
| 2910 | + $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2911 | + |
|
| 2912 | + // if it has a pre requisite course check it |
|
| 2913 | + if( ! empty( $course_prerequisite_id ) ){ |
|
| 2914 | + |
|
| 2915 | + return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2916 | + |
|
| 2917 | + } |
|
| 2918 | + |
|
| 2919 | + return true; |
|
| 2920 | + |
|
| 2921 | + }// end is_prerequisite_complete |
|
| 2922 | 2922 | |
| 2923 | 2923 | |
| 2924 | 2924 | }// End Class |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Course Class |
@@ -33,72 +33,72 @@ discard block |
||
| 33 | 33 | * Constructor. |
| 34 | 34 | * @since 1.0.0 |
| 35 | 35 | */ |
| 36 | - public function __construct () { |
|
| 36 | + public function __construct() { |
|
| 37 | 37 | |
| 38 | 38 | $this->token = 'course'; |
| 39 | 39 | |
| 40 | 40 | // Setup meta fields for this post type |
| 41 | - $this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' ); |
|
| 41 | + $this->meta_fields = array('course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product'); |
|
| 42 | 42 | // Admin actions |
| 43 | - if ( is_admin() ) { |
|
| 43 | + if (is_admin()) { |
|
| 44 | 44 | // Metabox functions |
| 45 | - add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 46 | - add_action( 'save_post', array( $this, 'meta_box_save' ) ); |
|
| 45 | + add_action('add_meta_boxes', array($this, 'meta_box_setup'), 20); |
|
| 46 | + add_action('save_post', array($this, 'meta_box_save')); |
|
| 47 | 47 | // Custom Write Panel Columns |
| 48 | - add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
|
| 49 | - add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 ); |
|
| 48 | + add_filter('manage_edit-course_columns', array($this, 'add_column_headings'), 10, 1); |
|
| 49 | + add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2); |
|
| 50 | 50 | } else { |
| 51 | 51 | $this->my_courses_page = false; |
| 52 | 52 | } // End If Statement |
| 53 | 53 | |
| 54 | 54 | // Update course completion upon completion of a lesson |
| 55 | - add_action( 'sensei_user_lesson_end', array( $this, 'update_status_after_lesson_change' ), 10, 2 ); |
|
| 55 | + add_action('sensei_user_lesson_end', array($this, 'update_status_after_lesson_change'), 10, 2); |
|
| 56 | 56 | // Update course completion upon reset of a lesson |
| 57 | - add_action( 'sensei_user_lesson_reset', array( $this, 'update_status_after_lesson_change' ), 10, 2 ); |
|
| 57 | + add_action('sensei_user_lesson_reset', array($this, 'update_status_after_lesson_change'), 10, 2); |
|
| 58 | 58 | // Update course completion upon grading of a quiz |
| 59 | - add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 ); |
|
| 59 | + add_action('sensei_user_quiz_grade', array($this, 'update_status_after_quiz_submission'), 10, 2); |
|
| 60 | 60 | |
| 61 | 61 | // show the progress bar ont he single course page |
| 62 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 62 | + add_action('sensei_single_course_content_inside_before', array($this, 'the_progress_statement'), 15); |
|
| 63 | + add_action('sensei_single_course_content_inside_before', array($this, 'the_progress_meter'), 16); |
|
| 64 | 64 | |
| 65 | 65 | // provide an option to block all emails related to a selected course |
| 66 | - add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | - add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 66 | + add_filter('sensei_send_emails', array($this, 'block_notification_emails')); |
|
| 67 | + add_action('save_post', array($this, 'save_course_notification_meta_box')); |
|
| 68 | 68 | |
| 69 | 69 | // preview lessons on the course content |
| 70 | - add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 70 | + add_action('sensei_course_content_inside_after', array($this, 'the_course_free_lesson_preview')); |
|
| 71 | 71 | |
| 72 | 72 | // the course meta |
| 73 | - add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 73 | + add_action('sensei_course_content_inside_before', array($this, 'the_course_meta')); |
|
| 74 | 74 | |
| 75 | 75 | // backwards compatible template hooks |
| 76 | - add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | - add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 76 | + add_action('sensei_course_content_inside_before', array($this, 'content_before_backwards_compatibility_hooks')); |
|
| 77 | + add_action('sensei_loop_course_before', array($this, 'loop_before_backwards_compatibility_hooks')); |
|
| 78 | 78 | |
| 79 | 79 | // add the user status on the course to the markup as a class |
| 80 | - add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 80 | + add_filter('post_class', array(__CLASS__, 'add_course_user_status_class'), 20, 3); |
|
| 81 | 81 | |
| 82 | 82 | //filter the course query in Sensei specific instances |
| 83 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 83 | + add_filter('pre_get_posts', array(__CLASS__, 'course_query_filter')); |
|
| 84 | 84 | |
| 85 | 85 | //attache the sorting to the course archive |
| 86 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 86 | + add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'course_archive_sorting')); |
|
| 87 | 87 | |
| 88 | 88 | //attach the filter links to the course archive |
| 89 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 89 | + add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'course_archive_filters')); |
|
| 90 | 90 | |
| 91 | 91 | //filter the course query when featured filter is applied |
| 92 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 92 | + add_filter('pre_get_posts', array(__CLASS__, 'course_archive_featured_filter')); |
|
| 93 | 93 | |
| 94 | 94 | // handle the order by title post submission |
| 95 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 95 | + add_filter('pre_get_posts', array(__CLASS__, 'course_archive_order_by_title')); |
|
| 96 | 96 | |
| 97 | 97 | // ensure the course category page respects the manual order set for courses |
| 98 | - add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 98 | + add_filter('pre_get_posts', array(__CLASS__, 'alter_course_category_order')); |
|
| 99 | 99 | |
| 100 | 100 | // flush rewrite rules when saving a course |
| 101 | - add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 101 | + add_action('save_post', array('Sensei_Course', 'flush_rewrite_rules')); |
|
| 102 | 102 | |
| 103 | 103 | } // End __construct() |
| 104 | 104 | |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | * @param type $user_id |
| 109 | 109 | * @param type $quiz_id |
| 110 | 110 | */ |
| 111 | - public function update_status_after_quiz_submission( $user_id, $quiz_id ) { |
|
| 112 | - if ( intval( $user_id ) > 0 && intval( $quiz_id ) > 0 ) { |
|
| 113 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 114 | - $this->update_status_after_lesson_change( $user_id, $lesson_id ); |
|
| 111 | + public function update_status_after_quiz_submission($user_id, $quiz_id) { |
|
| 112 | + if (intval($user_id) > 0 && intval($quiz_id) > 0) { |
|
| 113 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 114 | + $this->update_status_after_lesson_change($user_id, $lesson_id); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,12 +121,12 @@ discard block |
||
| 121 | 121 | * @param int $user_id |
| 122 | 122 | * @param int $lesson_id |
| 123 | 123 | */ |
| 124 | - public function update_status_after_lesson_change( $user_id, $lesson_id ) { |
|
| 125 | - if ( intval( $user_id ) > 0 && intval( $lesson_id ) > 0 ) { |
|
| 126 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 127 | - if ( intval( $course_id ) > 0 ) { |
|
| 124 | + public function update_status_after_lesson_change($user_id, $lesson_id) { |
|
| 125 | + if (intval($user_id) > 0 && intval($lesson_id) > 0) { |
|
| 126 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 127 | + if (intval($course_id) > 0) { |
|
| 128 | 128 | // Updates the Course status and it's meta data |
| 129 | - Sensei_Utils::user_complete_course( $course_id, $user_id ); |
|
| 129 | + Sensei_Utils::user_complete_course($course_id, $user_id); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -137,27 +137,27 @@ discard block |
||
| 137 | 137 | * @access public |
| 138 | 138 | * @return void |
| 139 | 139 | */ |
| 140 | - public function meta_box_setup () { |
|
| 140 | + public function meta_box_setup() { |
|
| 141 | 141 | |
| 142 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 142 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 143 | 143 | // Add Meta Box for WooCommerce Course |
| 144 | - add_meta_box( 'course-wc-product', __( 'WooCommerce Product', 'woothemes-sensei' ), array( $this, 'course_woocommerce_product_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 144 | + add_meta_box('course-wc-product', __('WooCommerce Product', 'woothemes-sensei'), array($this, 'course_woocommerce_product_meta_box_content'), $this->token, 'side', 'default'); |
|
| 145 | 145 | } // End If Statement |
| 146 | 146 | // Add Meta Box for Prerequisite Course |
| 147 | - add_meta_box( 'course-prerequisite', __( 'Course Prerequisite', 'woothemes-sensei' ), array( $this, 'course_prerequisite_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 147 | + add_meta_box('course-prerequisite', __('Course Prerequisite', 'woothemes-sensei'), array($this, 'course_prerequisite_meta_box_content'), $this->token, 'side', 'default'); |
|
| 148 | 148 | // Add Meta Box for Featured Course |
| 149 | - add_meta_box( 'course-featured', __( 'Featured Course', 'woothemes-sensei' ), array( $this, 'course_featured_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 149 | + add_meta_box('course-featured', __('Featured Course', 'woothemes-sensei'), array($this, 'course_featured_meta_box_content'), $this->token, 'side', 'default'); |
|
| 150 | 150 | // Add Meta Box for Course Meta |
| 151 | - add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' ); |
|
| 151 | + add_meta_box('course-video', __('Course Video', 'woothemes-sensei'), array($this, 'course_video_meta_box_content'), $this->token, 'normal', 'default'); |
|
| 152 | 152 | // Add Meta Box for Course Lessons |
| 153 | - add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' ); |
|
| 153 | + add_meta_box('course-lessons', __('Course Lessons', 'woothemes-sensei'), array($this, 'course_lessons_meta_box_content'), $this->token, 'normal', 'default'); |
|
| 154 | 154 | // Add Meta Box to link to Manage Learners |
| 155 | - add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 155 | + add_meta_box('course-manage', __('Course Management', 'woothemes-sensei'), array($this, 'course_manage_meta_box_content'), $this->token, 'side', 'default'); |
|
| 156 | 156 | // Remove "Custom Settings" meta box. |
| 157 | - remove_meta_box( 'woothemes-settings', $this->token, 'normal' ); |
|
| 157 | + remove_meta_box('woothemes-settings', $this->token, 'normal'); |
|
| 158 | 158 | |
| 159 | 159 | // add Disable email notification box |
| 160 | - add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 160 | + add_meta_box('course-notifications', __('Course Notifications', 'woothemes-sensei'), array($this, 'course_notification_meta_box_content'), 'course', 'normal', 'default'); |
|
| 161 | 161 | |
| 162 | 162 | } // End meta_box_setup() |
| 163 | 163 | |
@@ -167,58 +167,58 @@ discard block |
||
| 167 | 167 | * @access public |
| 168 | 168 | * @return void |
| 169 | 169 | */ |
| 170 | - public function course_woocommerce_product_meta_box_content () { |
|
| 170 | + public function course_woocommerce_product_meta_box_content() { |
|
| 171 | 171 | global $post; |
| 172 | 172 | |
| 173 | - $select_course_woocommerce_product = get_post_meta( $post->ID, '_course_woocommerce_product', true ); |
|
| 173 | + $select_course_woocommerce_product = get_post_meta($post->ID, '_course_woocommerce_product', true); |
|
| 174 | 174 | |
| 175 | - $post_args = array( 'post_type' => array( 'product', 'product_variation' ), |
|
| 175 | + $post_args = array('post_type' => array('product', 'product_variation'), |
|
| 176 | 176 | 'posts_per_page' => -1, |
| 177 | 177 | 'orderby' => 'title', |
| 178 | 178 | 'order' => 'DESC', |
| 179 | 179 | 'exclude' => $post->ID, |
| 180 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 180 | + 'post_status' => array('publish', 'private', 'draft'), |
|
| 181 | 181 | 'tax_query' => array( |
| 182 | 182 | array( |
| 183 | 183 | 'taxonomy' => 'product_type', |
| 184 | 184 | 'field' => 'slug', |
| 185 | - 'terms' => array( 'variable', 'grouped' ), |
|
| 185 | + 'terms' => array('variable', 'grouped'), |
|
| 186 | 186 | 'operator' => 'NOT IN' |
| 187 | 187 | ) |
| 188 | 188 | ), |
| 189 | 189 | 'suppress_filters' => 0 |
| 190 | 190 | ); |
| 191 | - $posts_array = get_posts( $post_args ); |
|
| 191 | + $posts_array = get_posts($post_args); |
|
| 192 | 192 | |
| 193 | 193 | $html = ''; |
| 194 | 194 | |
| 195 | - $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 195 | + $html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />'; |
|
| 196 | 196 | |
| 197 | - if ( count( $posts_array ) > 0 ) { |
|
| 197 | + if (count($posts_array) > 0) { |
|
| 198 | 198 | |
| 199 | - $html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">' . "\n"; |
|
| 200 | - $html .= '<option value="-">' . __( 'None', 'woothemes-sensei' ) . '</option>'; |
|
| 199 | + $html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">'."\n"; |
|
| 200 | + $html .= '<option value="-">'.__('None', 'woothemes-sensei').'</option>'; |
|
| 201 | 201 | $prev_parent_id = 0; |
| 202 | - foreach ( $posts_array as $post_item ) { |
|
| 202 | + foreach ($posts_array as $post_item) { |
|
| 203 | 203 | |
| 204 | - if ( 'product_variation' == $post_item->post_type ) { |
|
| 204 | + if ('product_variation' == $post_item->post_type) { |
|
| 205 | 205 | |
| 206 | - $product_object = get_product( $post_item->ID ); |
|
| 207 | - $parent_id = wp_get_post_parent_id( $post_item->ID ); |
|
| 206 | + $product_object = get_product($post_item->ID); |
|
| 207 | + $parent_id = wp_get_post_parent_id($post_item->ID); |
|
| 208 | 208 | |
| 209 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 210 | - $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
|
| 209 | + if (sensei_check_woocommerce_version('2.1')) { |
|
| 210 | + $formatted_variation = wc_get_formatted_variation($product_object->variation_data, true); |
|
| 211 | 211 | |
| 212 | 212 | } else { |
| 213 | 213 | // fall back to pre wc 2.1 |
| 214 | - $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
|
| 214 | + $formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true); |
|
| 215 | 215 | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $product_name = ucwords( $formatted_variation ); |
|
| 219 | - if( empty( $product_name ) ){ |
|
| 218 | + $product_name = ucwords($formatted_variation); |
|
| 219 | + if (empty($product_name)) { |
|
| 220 | 220 | |
| 221 | - $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 221 | + $product_name = __('Variation #', 'woothemes-sensei').$product_object->variation_id; |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -231,47 +231,47 @@ discard block |
||
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Show variations in groups |
| 234 | - if( $parent_id && $parent_id != $prev_parent_id ) { |
|
| 234 | + if ($parent_id && $parent_id != $prev_parent_id) { |
|
| 235 | 235 | |
| 236 | - if( 0 != $prev_parent_id ) { |
|
| 236 | + if (0 != $prev_parent_id) { |
|
| 237 | 237 | |
| 238 | 238 | $html .= '</optgroup>'; |
| 239 | 239 | |
| 240 | 240 | } |
| 241 | - $html .= '<optgroup label="' . get_the_title( $parent_id ) . '">'; |
|
| 241 | + $html .= '<optgroup label="'.get_the_title($parent_id).'">'; |
|
| 242 | 242 | $prev_parent_id = $parent_id; |
| 243 | 243 | |
| 244 | - } elseif( ! $parent_id && 0 == $prev_parent_id ) { |
|
| 244 | + } elseif ( ! $parent_id && 0 == $prev_parent_id) { |
|
| 245 | 245 | |
| 246 | 246 | $html .= '</optgroup>'; |
| 247 | 247 | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_course_woocommerce_product, false ) . '>' . esc_html( $product_name ) . '</option>' . "\n"; |
|
| 250 | + $html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_course_woocommerce_product, false).'>'.esc_html($product_name).'</option>'."\n"; |
|
| 251 | 251 | |
| 252 | 252 | } // End For Loop |
| 253 | 253 | |
| 254 | - $html .= '</select>' . "\n"; |
|
| 255 | - if ( current_user_can( 'publish_product' )) { |
|
| 254 | + $html .= '</select>'."\n"; |
|
| 255 | + if (current_user_can('publish_product')) { |
|
| 256 | 256 | |
| 257 | - $html .= '<p>' . "\n"; |
|
| 258 | - $html .= '<a href="' . admin_url( 'post-new.php?post_type=product' ) . '" title="' . esc_attr( __( 'Add a Product', 'woothemes-sensei' ) ) . '">' . __( 'Add a Product', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 257 | + $html .= '<p>'."\n"; |
|
| 258 | + $html .= '<a href="'.admin_url('post-new.php?post_type=product').'" title="'.esc_attr(__('Add a Product', 'woothemes-sensei')).'">'.__('Add a Product', 'woothemes-sensei').'</a>'."\n"; |
|
| 259 | 259 | $html .= '</p>'."\n"; |
| 260 | 260 | |
| 261 | 261 | } // End If Statement |
| 262 | 262 | |
| 263 | 263 | } else { |
| 264 | 264 | |
| 265 | - if ( current_user_can( 'publish_product' )) { |
|
| 265 | + if (current_user_can('publish_product')) { |
|
| 266 | 266 | |
| 267 | - $html .= '<p>' . "\n"; |
|
| 268 | - $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . ' <a href="' . admin_url( 'post-new.php?post_type=product' ) . '" title="' . esc_attr( __( 'Add a Product', 'woothemes-sensei' ) ) . '">' . __( 'Please add some first', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 267 | + $html .= '<p>'."\n"; |
|
| 268 | + $html .= esc_html(__('No products exist yet.', 'woothemes-sensei')).' <a href="'.admin_url('post-new.php?post_type=product').'" title="'.esc_attr(__('Add a Product', 'woothemes-sensei')).'">'.__('Please add some first', 'woothemes-sensei').'</a>'."\n"; |
|
| 269 | 269 | $html .= '</p>'."\n"; |
| 270 | 270 | |
| 271 | 271 | } else { |
| 272 | 272 | |
| 273 | - $html .= '<p>' . "\n"; |
|
| 274 | - $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n"; |
|
| 273 | + $html .= '<p>'."\n"; |
|
| 274 | + $html .= esc_html(__('No products exist yet.', 'woothemes-sensei'))."\n"; |
|
| 275 | 275 | $html .= '</p>'."\n"; |
| 276 | 276 | |
| 277 | 277 | } // End If Statement |
@@ -288,33 +288,33 @@ discard block |
||
| 288 | 288 | * @access public |
| 289 | 289 | * @return void |
| 290 | 290 | */ |
| 291 | - public function course_prerequisite_meta_box_content () { |
|
| 291 | + public function course_prerequisite_meta_box_content() { |
|
| 292 | 292 | global $post; |
| 293 | 293 | |
| 294 | - $select_course_prerequisite = get_post_meta( $post->ID, '_course_prerequisite', true ); |
|
| 294 | + $select_course_prerequisite = get_post_meta($post->ID, '_course_prerequisite', true); |
|
| 295 | 295 | |
| 296 | - $post_args = array( 'post_type' => 'course', |
|
| 296 | + $post_args = array('post_type' => 'course', |
|
| 297 | 297 | 'posts_per_page' => -1, |
| 298 | 298 | 'orderby' => 'title', |
| 299 | 299 | 'order' => 'DESC', |
| 300 | 300 | 'exclude' => $post->ID, |
| 301 | 301 | 'suppress_filters' => 0 |
| 302 | 302 | ); |
| 303 | - $posts_array = get_posts( $post_args ); |
|
| 303 | + $posts_array = get_posts($post_args); |
|
| 304 | 304 | |
| 305 | 305 | $html = ''; |
| 306 | 306 | |
| 307 | - $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 307 | + $html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />'; |
|
| 308 | 308 | |
| 309 | - if ( count( $posts_array ) > 0 ) { |
|
| 310 | - $html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">' . "\n"; |
|
| 311 | - $html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>'; |
|
| 312 | - foreach ($posts_array as $post_item){ |
|
| 313 | - $html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_course_prerequisite, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n"; |
|
| 309 | + if (count($posts_array) > 0) { |
|
| 310 | + $html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">'."\n"; |
|
| 311 | + $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
| 312 | + foreach ($posts_array as $post_item) { |
|
| 313 | + $html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_course_prerequisite, false).'>'.esc_html($post_item->post_title).'</option>'."\n"; |
|
| 314 | 314 | } // End For Loop |
| 315 | - $html .= '</select>' . "\n"; |
|
| 315 | + $html .= '</select>'."\n"; |
|
| 316 | 316 | } else { |
| 317 | - $html .= '<p>' . esc_html( __( 'No courses exist yet. Please add some first.', 'woothemes-sensei' ) ) . '</p>'; |
|
| 317 | + $html .= '<p>'.esc_html(__('No courses exist yet. Please add some first.', 'woothemes-sensei')).'</p>'; |
|
| 318 | 318 | } // End If Statement |
| 319 | 319 | |
| 320 | 320 | echo $html; |
@@ -327,21 +327,21 @@ discard block |
||
| 327 | 327 | * @access public |
| 328 | 328 | * @return void |
| 329 | 329 | */ |
| 330 | - public function course_featured_meta_box_content () { |
|
| 330 | + public function course_featured_meta_box_content() { |
|
| 331 | 331 | global $post; |
| 332 | 332 | |
| 333 | - $course_featured = get_post_meta( $post->ID, '_course_featured', true ); |
|
| 333 | + $course_featured = get_post_meta($post->ID, '_course_featured', true); |
|
| 334 | 334 | |
| 335 | 335 | $html = ''; |
| 336 | 336 | |
| 337 | - $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 337 | + $html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />'; |
|
| 338 | 338 | |
| 339 | 339 | $checked = ''; |
| 340 | - if ( isset( $course_featured ) && ( '' != $course_featured ) ) { |
|
| 341 | - $checked = checked( 'featured', $course_featured, false ); |
|
| 340 | + if (isset($course_featured) && ('' != $course_featured)) { |
|
| 341 | + $checked = checked('featured', $course_featured, false); |
|
| 342 | 342 | } // End If Statement |
| 343 | 343 | |
| 344 | - $html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '> ' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>'; |
|
| 344 | + $html .= '<input type="checkbox" name="course_featured" value="featured" '.$checked.'> '.__('Feature this course', 'woothemes-sensei').'<br>'; |
|
| 345 | 345 | |
| 346 | 346 | echo $html; |
| 347 | 347 | |
@@ -353,16 +353,16 @@ discard block |
||
| 353 | 353 | * @access public |
| 354 | 354 | * @return void |
| 355 | 355 | */ |
| 356 | - public function course_video_meta_box_content () { |
|
| 356 | + public function course_video_meta_box_content() { |
|
| 357 | 357 | global $post; |
| 358 | 358 | |
| 359 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 359 | + $course_video_embed = get_post_meta($post->ID, '_course_video_embed', true); |
|
| 360 | 360 | |
| 361 | 361 | $html = ''; |
| 362 | 362 | |
| 363 | - $html .= '<label class="screen-reader-text" for="course_video_embed">' . __( 'Video Embed Code', 'woothemes-sensei' ) . '</label>'; |
|
| 364 | - $html .= '<textarea rows="5" cols="50" name="course_video_embed" tabindex="6" id="course-video-embed">' . $course_video_embed . '</textarea>'; |
|
| 365 | - $html .= '<p>' . __( 'Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei' ) . '</p>'; |
|
| 363 | + $html .= '<label class="screen-reader-text" for="course_video_embed">'.__('Video Embed Code', 'woothemes-sensei').'</label>'; |
|
| 364 | + $html .= '<textarea rows="5" cols="50" name="course_video_embed" tabindex="6" id="course-video-embed">'.$course_video_embed.'</textarea>'; |
|
| 365 | + $html .= '<p>'.__('Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei').'</p>'; |
|
| 366 | 366 | |
| 367 | 367 | echo $html; |
| 368 | 368 | |
@@ -377,36 +377,36 @@ discard block |
||
| 377 | 377 | * @param int $post_id |
| 378 | 378 | * @return int |
| 379 | 379 | */ |
| 380 | - public function meta_box_save ( $post_id ) { |
|
| 380 | + public function meta_box_save($post_id) { |
|
| 381 | 381 | global $post; |
| 382 | 382 | |
| 383 | 383 | /* Verify the nonce before proceeding. */ |
| 384 | - if ( ( get_post_type() != $this->token ) || ! wp_verify_nonce( $_POST['woo_' . $this->token . '_noonce'], plugin_basename(__FILE__) ) ) { |
|
| 384 | + if ((get_post_type() != $this->token) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_noonce'], plugin_basename(__FILE__))) { |
|
| 385 | 385 | return $post_id; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /* Get the post type object. */ |
| 389 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 389 | + $post_type = get_post_type_object($post->post_type); |
|
| 390 | 390 | |
| 391 | 391 | /* Check if the current user has permission to edit the post. */ |
| 392 | - if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) { |
|
| 392 | + if ( ! current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 393 | 393 | return $post_id; |
| 394 | 394 | } // End If Statement |
| 395 | 395 | |
| 396 | - if ( 'page' == $_POST['post_type'] ) { |
|
| 397 | - if ( ! current_user_can( 'edit_page', $post_id ) ) { |
|
| 396 | + if ('page' == $_POST['post_type']) { |
|
| 397 | + if ( ! current_user_can('edit_page', $post_id)) { |
|
| 398 | 398 | return $post_id; |
| 399 | 399 | } // End If Statement |
| 400 | 400 | } else { |
| 401 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 401 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
| 402 | 402 | return $post_id; |
| 403 | 403 | } // End If Statement |
| 404 | 404 | } // End If Statement |
| 405 | 405 | |
| 406 | 406 | // Save the post meta data fields |
| 407 | - if ( isset($this->meta_fields) && is_array($this->meta_fields) ) { |
|
| 408 | - foreach ( $this->meta_fields as $meta_key ) { |
|
| 409 | - $this->save_post_meta( $meta_key, $post_id ); |
|
| 407 | + if (isset($this->meta_fields) && is_array($this->meta_fields)) { |
|
| 408 | + foreach ($this->meta_fields as $meta_key) { |
|
| 409 | + $this->save_post_meta($meta_key, $post_id); |
|
| 410 | 410 | } // End For Loop |
| 411 | 411 | } // End If Statement |
| 412 | 412 | |
@@ -423,18 +423,18 @@ discard block |
||
| 423 | 423 | * @param int $post_id (default: 0) |
| 424 | 424 | * @return int new meta id | bool meta value saved status |
| 425 | 425 | */ |
| 426 | - private function save_post_meta( $post_key = '', $post_id = 0 ) { |
|
| 426 | + private function save_post_meta($post_key = '', $post_id = 0) { |
|
| 427 | 427 | // Get the meta key. |
| 428 | - $meta_key = '_' . $post_key; |
|
| 428 | + $meta_key = '_'.$post_key; |
|
| 429 | 429 | // Get the posted data and sanitize it for use as an HTML class. |
| 430 | - if ( 'course_video_embed' == $post_key) { |
|
| 431 | - $new_meta_value = esc_html( $_POST[$post_key] ); |
|
| 430 | + if ('course_video_embed' == $post_key) { |
|
| 431 | + $new_meta_value = esc_html($_POST[$post_key]); |
|
| 432 | 432 | } else { |
| 433 | - $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
|
| 433 | + $new_meta_value = (isset($_POST[$post_key]) ? sanitize_html_class($_POST[$post_key]) : ''); |
|
| 434 | 434 | } // End If Statement |
| 435 | 435 | |
| 436 | 436 | // update field with the new value |
| 437 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 437 | + return update_post_meta($post_id, $meta_key, $new_meta_value); |
|
| 438 | 438 | |
| 439 | 439 | } // End save_post_meta() |
| 440 | 440 | |
@@ -444,31 +444,31 @@ discard block |
||
| 444 | 444 | * @access public |
| 445 | 445 | * @return void |
| 446 | 446 | */ |
| 447 | - public function course_lessons_meta_box_content () { |
|
| 447 | + public function course_lessons_meta_box_content() { |
|
| 448 | 448 | |
| 449 | 449 | global $post; |
| 450 | 450 | |
| 451 | 451 | // Setup Lesson Query |
| 452 | 452 | $posts_array = array(); |
| 453 | - if ( 0 < $post->ID ) { |
|
| 453 | + if (0 < $post->ID) { |
|
| 454 | 454 | |
| 455 | - $posts_array = $this->course_lessons( $post->ID, 'any' ); |
|
| 455 | + $posts_array = $this->course_lessons($post->ID, 'any'); |
|
| 456 | 456 | |
| 457 | 457 | } // End If Statement |
| 458 | 458 | |
| 459 | 459 | $html = ''; |
| 460 | - $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' |
|
| 461 | - . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | - . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 460 | + $html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="' |
|
| 461 | + . esc_attr('woo_'.$this->token.'_noonce') |
|
| 462 | + . '" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />'; |
|
| 463 | 463 | |
| 464 | - if ( count( $posts_array ) > 0 ) { |
|
| 464 | + if (count($posts_array) > 0) { |
|
| 465 | 465 | |
| 466 | - foreach ($posts_array as $post_item){ |
|
| 466 | + foreach ($posts_array as $post_item) { |
|
| 467 | 467 | |
| 468 | 468 | $html .= '<p>'."\n"; |
| 469 | 469 | |
| 470 | 470 | $html .= $post_item->post_title."\n"; |
| 471 | - $html .= '<a href="' . esc_url( get_edit_post_link( $post_item->ID ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), $post_item->post_title ) ) . '" class="edit-lesson-action">' . __( 'Edit this lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 471 | + $html .= '<a href="'.esc_url(get_edit_post_link($post_item->ID)).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $post_item->post_title)).'" class="edit-lesson-action">'.__('Edit this lesson', 'woothemes-sensei').'</a>'; |
|
| 472 | 472 | |
| 473 | 473 | $html .= '</p>'."\n"; |
| 474 | 474 | |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | |
| 477 | 477 | } else { |
| 478 | 478 | $course_id = ''; |
| 479 | - if ( 0 < $post->ID ) { $course_id = '&course_id=' . $post->ID; } |
|
| 480 | - $html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n"; |
|
| 479 | + if (0 < $post->ID) { $course_id = '&course_id='.$post->ID; } |
|
| 480 | + $html .= '<p>'.esc_html(__('No lessons exist yet for this course.', 'woothemes-sensei'))."\n"; |
|
| 481 | 481 | |
| 482 | - $html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id ) |
|
| 483 | - . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | - . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 482 | + $html .= '<a href="'.admin_url('post-new.php?post_type=lesson'.$course_id) |
|
| 483 | + . '" title="'.esc_attr(__('Add a Lesson', 'woothemes-sensei')).'">' |
|
| 484 | + . __('Please add some.', 'woothemes-sensei').'</a>'."\n"; |
|
| 485 | 485 | |
| 486 | 486 | $html .= '</p>'."\n"; |
| 487 | 487 | } // End If Statement |
@@ -498,12 +498,12 @@ discard block |
||
| 498 | 498 | * @return void |
| 499 | 499 | */ |
| 500 | 500 | |
| 501 | - public function course_manage_meta_box_content () { |
|
| 501 | + public function course_manage_meta_box_content() { |
|
| 502 | 502 | global $post; |
| 503 | 503 | |
| 504 | - $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 504 | + $manage_url = esc_url(add_query_arg(array('page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners'), admin_url('admin.php'))); |
|
| 505 | 505 | |
| 506 | - $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 506 | + $grading_url = esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners'), admin_url('admin.php'))); |
|
| 507 | 507 | |
| 508 | 508 | |
| 509 | 509 | echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
@@ -521,16 +521,16 @@ discard block |
||
| 521 | 521 | * @param array $defaults |
| 522 | 522 | * @return array $new_columns |
| 523 | 523 | */ |
| 524 | - public function add_column_headings ( $defaults ) { |
|
| 524 | + public function add_column_headings($defaults) { |
|
| 525 | 525 | $new_columns['cb'] = '<input type="checkbox" />'; |
| 526 | 526 | // $new_columns['id'] = __( 'ID' ); |
| 527 | - $new_columns['title'] = _x( 'Course Title', 'column name', 'woothemes-sensei' ); |
|
| 528 | - $new_columns['course-prerequisite'] = _x( 'Pre-requisite Course', 'column name', 'woothemes-sensei' ); |
|
| 529 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 530 | - $new_columns['course-woocommerce-product'] = _x( 'WooCommerce Product', 'column name', 'woothemes-sensei' ); |
|
| 527 | + $new_columns['title'] = _x('Course Title', 'column name', 'woothemes-sensei'); |
|
| 528 | + $new_columns['course-prerequisite'] = _x('Pre-requisite Course', 'column name', 'woothemes-sensei'); |
|
| 529 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 530 | + $new_columns['course-woocommerce-product'] = _x('WooCommerce Product', 'column name', 'woothemes-sensei'); |
|
| 531 | 531 | } // End If Statement |
| 532 | - $new_columns['course-category'] = _x( 'Category', 'column name', 'woothemes-sensei' ); |
|
| 533 | - if ( isset( $defaults['date'] ) ) { |
|
| 532 | + $new_columns['course-category'] = _x('Category', 'column name', 'woothemes-sensei'); |
|
| 533 | + if (isset($defaults['date'])) { |
|
| 534 | 534 | $new_columns['date'] = $defaults['date']; |
| 535 | 535 | } |
| 536 | 536 | |
@@ -545,45 +545,45 @@ discard block |
||
| 545 | 545 | * @param int $id |
| 546 | 546 | * @return void |
| 547 | 547 | */ |
| 548 | - public function add_column_data ( $column_name, $id ) { |
|
| 548 | + public function add_column_data($column_name, $id) { |
|
| 549 | 549 | global $wpdb, $post; |
| 550 | 550 | |
| 551 | - switch ( $column_name ) { |
|
| 551 | + switch ($column_name) { |
|
| 552 | 552 | case 'id': |
| 553 | 553 | echo $id; |
| 554 | 554 | break; |
| 555 | 555 | |
| 556 | 556 | case 'course-prerequisite': |
| 557 | - $course_prerequisite_id = get_post_meta( $id, '_course_prerequisite', true); |
|
| 558 | - if ( 0 < absint( $course_prerequisite_id ) ) { echo '<a href="' . esc_url( get_edit_post_link( absint( $course_prerequisite_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $course_prerequisite_id ) ) ) ) . '">' . get_the_title( absint( $course_prerequisite_id ) ) . '</a>'; } |
|
| 557 | + $course_prerequisite_id = get_post_meta($id, '_course_prerequisite', true); |
|
| 558 | + if (0 < absint($course_prerequisite_id)) { echo '<a href="'.esc_url(get_edit_post_link(absint($course_prerequisite_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($course_prerequisite_id)))).'">'.get_the_title(absint($course_prerequisite_id)).'</a>'; } |
|
| 559 | 559 | |
| 560 | 560 | break; |
| 561 | 561 | |
| 562 | 562 | case 'course-woocommerce-product': |
| 563 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 564 | - $course_woocommerce_product_id = get_post_meta( $id, '_course_woocommerce_product', true); |
|
| 565 | - if ( 0 < absint( $course_woocommerce_product_id ) ) { |
|
| 566 | - if ( 'product_variation' == get_post_type( $course_woocommerce_product_id ) ) { |
|
| 567 | - $product_object = get_product( $course_woocommerce_product_id ); |
|
| 568 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 569 | - $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
|
| 563 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 564 | + $course_woocommerce_product_id = get_post_meta($id, '_course_woocommerce_product', true); |
|
| 565 | + if (0 < absint($course_woocommerce_product_id)) { |
|
| 566 | + if ('product_variation' == get_post_type($course_woocommerce_product_id)) { |
|
| 567 | + $product_object = get_product($course_woocommerce_product_id); |
|
| 568 | + if (sensei_check_woocommerce_version('2.1')) { |
|
| 569 | + $formatted_variation = wc_get_formatted_variation($product_object->variation_data, true); |
|
| 570 | 570 | } else { |
| 571 | - $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
|
| 571 | + $formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true); |
|
| 572 | 572 | } |
| 573 | 573 | $course_woocommerce_product_id = $product_object->parent->post->ID; |
| 574 | - $product_name = $product_object->parent->post->post_title . '<br/> ' . ucwords( $formatted_variation ); |
|
| 574 | + $product_name = $product_object->parent->post->post_title.'<br/> '.ucwords($formatted_variation); |
|
| 575 | 575 | } else { |
| 576 | - $product_name = get_the_title( absint( $course_woocommerce_product_id ) ); |
|
| 576 | + $product_name = get_the_title(absint($course_woocommerce_product_id)); |
|
| 577 | 577 | } // End If Statement |
| 578 | - echo '<a href="' . esc_url( get_edit_post_link( absint( $course_woocommerce_product_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), $product_name ) ) . '">' . $product_name . '</a>'; |
|
| 578 | + echo '<a href="'.esc_url(get_edit_post_link(absint($course_woocommerce_product_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $product_name)).'">'.$product_name.'</a>'; |
|
| 579 | 579 | } // End If Statement |
| 580 | 580 | } // End If Statement |
| 581 | 581 | break; |
| 582 | 582 | |
| 583 | 583 | case 'course-category': |
| 584 | - $output = get_the_term_list( $id, 'course-category', '', ', ', '' ); |
|
| 585 | - if ( '' == $output ) { |
|
| 586 | - $output = __( 'None', 'woothemes-sensei' ); |
|
| 584 | + $output = get_the_term_list($id, 'course-category', '', ', ', ''); |
|
| 585 | + if ('' == $output) { |
|
| 586 | + $output = __('None', 'woothemes-sensei'); |
|
| 587 | 587 | } // End If Statement |
| 588 | 588 | echo $output; |
| 589 | 589 | break; |
@@ -603,29 +603,29 @@ discard block |
||
| 603 | 603 | * @param array $includes (default: array()) |
| 604 | 604 | * @return array |
| 605 | 605 | */ |
| 606 | - public function course_query( $amount = 0, $type = 'default', $includes = array(), $excludes = array() ) { |
|
| 607 | - global $my_courses_page ; |
|
| 606 | + public function course_query($amount = 0, $type = 'default', $includes = array(), $excludes = array()) { |
|
| 607 | + global $my_courses_page; |
|
| 608 | 608 | |
| 609 | 609 | $results_array = array(); |
| 610 | 610 | |
| 611 | - if( $my_courses_page ) { add_action( 'pre_get_posts', array( $this, 'filter_my_courses' ) ); } |
|
| 611 | + if ($my_courses_page) { add_action('pre_get_posts', array($this, 'filter_my_courses')); } |
|
| 612 | 612 | |
| 613 | - $post_args = $this->get_archive_query_args( $type, $amount, $includes, $excludes ); |
|
| 613 | + $post_args = $this->get_archive_query_args($type, $amount, $includes, $excludes); |
|
| 614 | 614 | |
| 615 | 615 | // get the posts |
| 616 | - if( empty( $post_args ) ) { |
|
| 616 | + if (empty($post_args)) { |
|
| 617 | 617 | |
| 618 | 618 | return $results_array; |
| 619 | 619 | |
| 620 | - }else{ |
|
| 620 | + } else { |
|
| 621 | 621 | |
| 622 | 622 | //reset the pagination as this widgets do not need it |
| 623 | 623 | $post_args['paged'] = 1; |
| 624 | - $results_array = get_posts( $post_args ); |
|
| 624 | + $results_array = get_posts($post_args); |
|
| 625 | 625 | |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - if( $my_courses_page ) { remove_action( 'pre_get_posts', array( $this, 'filter_my_courses' ) ); } |
|
| 628 | + if ($my_courses_page) { remove_action('pre_get_posts', array($this, 'filter_my_courses')); } |
|
| 629 | 629 | |
| 630 | 630 | return $results_array; |
| 631 | 631 | |
@@ -641,22 +641,22 @@ discard block |
||
| 641 | 641 | * @param array $includes (default: array()) |
| 642 | 642 | * @return array |
| 643 | 643 | */ |
| 644 | - public function get_archive_query_args( $type = '', $amount = 0 , $includes = array(), $excludes = array() ) { |
|
| 644 | + public function get_archive_query_args($type = '', $amount = 0, $includes = array(), $excludes = array()) { |
|
| 645 | 645 | |
| 646 | 646 | global $wp_query; |
| 647 | 647 | |
| 648 | - if ( 0 == $amount && ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && 'usercourses' != $type && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) ) { |
|
| 649 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 648 | + if (0 == $amount && (isset(Sensei()->settings->settings['course_archive_amount']) && 'usercourses' != $type && (0 < absint(Sensei()->settings->settings['course_archive_amount'])))) { |
|
| 649 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); |
|
| 650 | 650 | } else { |
| 651 | - if ( 0 == $amount) { |
|
| 652 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 651 | + if (0 == $amount) { |
|
| 652 | + $amount = $wp_query->get('posts_per_page'); |
|
| 653 | 653 | } // End If Statement |
| 654 | 654 | } // End If Statement |
| 655 | 655 | |
| 656 | - $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 656 | + $stored_order = get_option('sensei_course_order', ''); |
|
| 657 | 657 | $order = 'ASC'; |
| 658 | 658 | $orderby = 'menu_order'; |
| 659 | - if( empty( $stored_order ) ){ |
|
| 659 | + if (empty($stored_order)) { |
|
| 660 | 660 | |
| 661 | 661 | $order = 'DESC'; |
| 662 | 662 | $orderby = 'date'; |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | switch ($type) { |
| 667 | 667 | |
| 668 | 668 | case 'usercourses': |
| 669 | - $post_args = array( 'post_type' => 'course', |
|
| 669 | + $post_args = array('post_type' => 'course', |
|
| 670 | 670 | 'orderby' => $orderby, |
| 671 | 671 | 'order' => $order, |
| 672 | 672 | 'post_status' => 'publish', |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | break; |
| 708 | 708 | |
| 709 | 709 | case 'featuredcourses': |
| 710 | - $post_args = array( 'post_type' => 'course', |
|
| 710 | + $post_args = array('post_type' => 'course', |
|
| 711 | 711 | 'orderby' => $orderby, |
| 712 | 712 | 'order' => $order, |
| 713 | 713 | 'post_status' => 'publish', |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | ); |
| 720 | 720 | break; |
| 721 | 721 | default: |
| 722 | - $post_args = array( 'post_type' => 'course', |
|
| 722 | + $post_args = array('post_type' => 'course', |
|
| 723 | 723 | 'orderby' => $orderby, |
| 724 | 724 | 'order' => $order, |
| 725 | 725 | 'post_status' => 'publish', |
@@ -731,13 +731,13 @@ discard block |
||
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | $post_args['posts_per_page'] = $amount; |
| 734 | - $paged = $wp_query->get( 'paged' ); |
|
| 735 | - $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 734 | + $paged = $wp_query->get('paged'); |
|
| 735 | + $post_args['paged'] = empty($paged) ? 1 : $paged; |
|
| 736 | 736 | |
| 737 | - if( 'newcourses' == $type ){ |
|
| 737 | + if ('newcourses' == $type) { |
|
| 738 | 738 | |
| 739 | - $post_args[ 'orderby' ] = 'date'; |
|
| 740 | - $post_args[ 'order' ] = 'DESC'; |
|
| 739 | + $post_args['orderby'] = 'date'; |
|
| 740 | + $post_args['order'] = 'DESC'; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | return $post_args; |
@@ -759,35 +759,35 @@ discard block |
||
| 759 | 759 | * |
| 760 | 760 | * @return string | void |
| 761 | 761 | */ |
| 762 | - public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) { |
|
| 762 | + public function course_image($course_id = 0, $width = '100', $height = '100', $return = false) { |
|
| 763 | 763 | |
| 764 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 764 | + if (is_a($course_id, 'WP_Post')) { |
|
| 765 | 765 | $course_id = $course_id->ID; |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | $html = ''; |
| 769 | 769 | |
| 770 | 770 | // Get Width and Height settings |
| 771 | - if ( ( $width == '100' ) && ( $height == '100' ) ) { |
|
| 771 | + if (($width == '100') && ($height == '100')) { |
|
| 772 | 772 | |
| 773 | - if ( is_singular( 'course' ) ) { |
|
| 773 | + if (is_singular('course')) { |
|
| 774 | 774 | |
| 775 | - if ( !Sensei()->settings->settings[ 'course_single_image_enable' ] ) { |
|
| 775 | + if ( ! Sensei()->settings->settings['course_single_image_enable']) { |
|
| 776 | 776 | return ''; |
| 777 | 777 | } // End If Statement |
| 778 | 778 | $image_thumb_size = 'course_single_image'; |
| 779 | - $dimensions = Sensei()->get_image_size( $image_thumb_size ); |
|
| 779 | + $dimensions = Sensei()->get_image_size($image_thumb_size); |
|
| 780 | 780 | $width = $dimensions['width']; |
| 781 | 781 | $height = $dimensions['height']; |
| 782 | 782 | |
| 783 | 783 | } else { |
| 784 | 784 | |
| 785 | - if ( !Sensei()->settings->settings[ 'course_archive_image_enable' ] ) { |
|
| 785 | + if ( ! Sensei()->settings->settings['course_archive_image_enable']) { |
|
| 786 | 786 | return ''; |
| 787 | 787 | } // End If Statement |
| 788 | 788 | |
| 789 | 789 | $image_thumb_size = 'course_archive_image'; |
| 790 | - $dimensions = Sensei()->get_image_size( $image_thumb_size ); |
|
| 790 | + $dimensions = Sensei()->get_image_size($image_thumb_size); |
|
| 791 | 791 | $width = $dimensions['width']; |
| 792 | 792 | $height = $dimensions['height']; |
| 793 | 793 | |
@@ -796,31 +796,31 @@ discard block |
||
| 796 | 796 | } // End If Statement |
| 797 | 797 | |
| 798 | 798 | $img_url = ''; |
| 799 | - if ( has_post_thumbnail( $course_id ) ) { |
|
| 799 | + if (has_post_thumbnail($course_id)) { |
|
| 800 | 800 | // Get Featured Image |
| 801 | - $img_url = get_the_post_thumbnail( $course_id, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') ); |
|
| 801 | + $img_url = get_the_post_thumbnail($course_id, array($width, $height), array('class' => 'woo-image thumbnail alignleft')); |
|
| 802 | 802 | } else { |
| 803 | 803 | |
| 804 | 804 | // Check for a Lesson Image |
| 805 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 805 | + $course_lessons = $this->course_lessons($course_id); |
|
| 806 | 806 | |
| 807 | - foreach ($course_lessons as $lesson_item){ |
|
| 808 | - if ( has_post_thumbnail( $lesson_item->ID ) ) { |
|
| 807 | + foreach ($course_lessons as $lesson_item) { |
|
| 808 | + if (has_post_thumbnail($lesson_item->ID)) { |
|
| 809 | 809 | // Get Featured Image |
| 810 | - $img_url = get_the_post_thumbnail( $lesson_item->ID, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') ); |
|
| 811 | - if ( '' != $img_url ) { |
|
| 810 | + $img_url = get_the_post_thumbnail($lesson_item->ID, array($width, $height), array('class' => 'woo-image thumbnail alignleft')); |
|
| 811 | + if ('' != $img_url) { |
|
| 812 | 812 | break; |
| 813 | 813 | } // End If Statement |
| 814 | 814 | |
| 815 | 815 | } // End If Statement |
| 816 | 816 | } // End For Loop |
| 817 | 817 | |
| 818 | - if ( '' == $img_url ) { |
|
| 818 | + if ('' == $img_url) { |
|
| 819 | 819 | |
| 820 | 820 | // Display Image Placeholder if none |
| 821 | - if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) { |
|
| 821 | + if (Sensei()->settings->get('placeholder_images_enable')) { |
|
| 822 | 822 | |
| 823 | - $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 823 | + $img_url = apply_filters('sensei_course_placeholder_image_url', '<img src="http://placehold.it/'.$width.'x'.$height.'" class="woo-image thumbnail alignleft" />'); |
|
| 824 | 824 | |
| 825 | 825 | } // End If Statement |
| 826 | 826 | |
@@ -828,17 +828,17 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | } // End If Statement |
| 830 | 830 | |
| 831 | - if ( '' != $img_url ) { |
|
| 831 | + if ('' != $img_url) { |
|
| 832 | 832 | |
| 833 | - $html .= '<a href="' . get_permalink( $course_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $course_id ) ) . '">' . $img_url .'</a>'; |
|
| 833 | + $html .= '<a href="'.get_permalink($course_id).'" title="'.esc_attr(get_post_field('post_title', $course_id)).'">'.$img_url.'</a>'; |
|
| 834 | 834 | |
| 835 | 835 | } // End If Statement |
| 836 | 836 | |
| 837 | - if( $return ){ |
|
| 837 | + if ($return) { |
|
| 838 | 838 | |
| 839 | 839 | return $html; |
| 840 | 840 | |
| 841 | - }else{ |
|
| 841 | + } else { |
|
| 842 | 842 | |
| 843 | 843 | echo $html; |
| 844 | 844 | |
@@ -855,9 +855,9 @@ discard block |
||
| 855 | 855 | * @param string $post_status (default: 'publish') |
| 856 | 856 | * @return int |
| 857 | 857 | */ |
| 858 | - public function course_count( $post_status = 'publish' ) { |
|
| 858 | + public function course_count($post_status = 'publish') { |
|
| 859 | 859 | |
| 860 | - $post_args = array( 'post_type' => 'course', |
|
| 860 | + $post_args = array('post_type' => 'course', |
|
| 861 | 861 | 'posts_per_page' => -1, |
| 862 | 862 | // 'orderby' => 'menu_order date', |
| 863 | 863 | // 'order' => 'ASC', |
@@ -868,10 +868,10 @@ discard block |
||
| 868 | 868 | |
| 869 | 869 | // Allow WP to generate the complex final query, just shortcut to only do an overall count |
| 870 | 870 | // add_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) ); |
| 871 | - $courses_query = new WP_Query( apply_filters( 'sensei_course_count', $post_args ) ); |
|
| 871 | + $courses_query = new WP_Query(apply_filters('sensei_course_count', $post_args)); |
|
| 872 | 872 | // remove_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) ); |
| 873 | 873 | |
| 874 | - return count( $courses_query->posts ); |
|
| 874 | + return count($courses_query->posts); |
|
| 875 | 875 | } // End course_count() |
| 876 | 876 | |
| 877 | 877 | |
@@ -884,42 +884,42 @@ discard block |
||
| 884 | 884 | * @param string $fields (default: 'all'). WP only allows 3 types, but we will limit it to only 'ids' or 'all' |
| 885 | 885 | * @return array{ type WP_Post } $posts_array |
| 886 | 886 | */ |
| 887 | - public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) { |
|
| 887 | + public function course_lessons($course_id = 0, $post_status = 'publish', $fields = 'all') { |
|
| 888 | 888 | |
| 889 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 889 | + if (is_a($course_id, 'WP_Post')) { |
|
| 890 | 890 | $course_id = $course_id->ID; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - $post_args = array( 'post_type' => 'lesson', |
|
| 893 | + $post_args = array('post_type' => 'lesson', |
|
| 894 | 894 | 'posts_per_page' => -1, |
| 895 | 895 | 'orderby' => 'date', |
| 896 | 896 | 'order' => 'ASC', |
| 897 | 897 | 'meta_query' => array( |
| 898 | 898 | array( |
| 899 | 899 | 'key' => '_lesson_course', |
| 900 | - 'value' => intval( $course_id ), |
|
| 900 | + 'value' => intval($course_id), |
|
| 901 | 901 | ), |
| 902 | 902 | ), |
| 903 | 903 | 'post_status' => $post_status, |
| 904 | 904 | 'suppress_filters' => 0, |
| 905 | 905 | ); |
| 906 | - $query_results = new WP_Query( $post_args ); |
|
| 906 | + $query_results = new WP_Query($post_args); |
|
| 907 | 907 | $lessons = $query_results->posts; |
| 908 | 908 | |
| 909 | 909 | // re order the lessons. This could not be done via the OR meta query as there may be lessons |
| 910 | 910 | // with the course order for a different course and this should not be included. It could also not |
| 911 | 911 | // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
| 912 | 912 | // that have been added to the course. |
| 913 | - if( count( $lessons) > 1 ){ |
|
| 913 | + if (count($lessons) > 1) { |
|
| 914 | 914 | |
| 915 | - foreach( $lessons as $lesson ){ |
|
| 915 | + foreach ($lessons as $lesson) { |
|
| 916 | 916 | |
| 917 | - $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 917 | + $order = intval(get_post_meta($lesson->ID, '_order_'.$course_id, true)); |
|
| 918 | 918 | // for lessons with no order set it to be 10000 so that it show up at the end |
| 919 | 919 | $lesson->course_order = $order ? $order : 100000; |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | - uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 922 | + uasort($lessons, array($this, '_short_course_lessons_callback')); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -930,12 +930,12 @@ discard block |
||
| 930 | 930 | * @param array $lessons |
| 931 | 931 | * @param int $course_id |
| 932 | 932 | */ |
| 933 | - $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 933 | + $lessons = apply_filters('sensei_course_get_lessons', $lessons, $course_id); |
|
| 934 | 934 | |
| 935 | 935 | //return the requested fields |
| 936 | 936 | // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
| 937 | 937 | // objects |
| 938 | - if( 'ids' == $fields ) { |
|
| 938 | + if ('ids' == $fields) { |
|
| 939 | 939 | $lesson_objects = $lessons; |
| 940 | 940 | $lessons = array(); |
| 941 | 941 | |
@@ -957,9 +957,9 @@ discard block |
||
| 957 | 957 | * @param array $lesson_2 |
| 958 | 958 | * @return int |
| 959 | 959 | */ |
| 960 | - protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 960 | + protected function _short_course_lessons_callback($lesson_1, $lesson_2) { |
|
| 961 | 961 | |
| 962 | - if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 962 | + if ($lesson_1->course_order == $lesson_2->course_order) { |
|
| 963 | 963 | return 0; |
| 964 | 964 | } |
| 965 | 965 | |
@@ -973,21 +973,21 @@ discard block |
||
| 973 | 973 | * @param boolean $boolean_check True if a simple yes/no is required |
| 974 | 974 | * @return array Array of quiz post objects |
| 975 | 975 | */ |
| 976 | - public function course_quizzes( $course_id = 0, $boolean_check = false ) { |
|
| 976 | + public function course_quizzes($course_id = 0, $boolean_check = false) { |
|
| 977 | 977 | |
| 978 | 978 | |
| 979 | 979 | $course_quizzes = array(); |
| 980 | 980 | |
| 981 | - if( $course_id ) { |
|
| 982 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 981 | + if ($course_id) { |
|
| 982 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 983 | 983 | |
| 984 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 985 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 986 | - if ( $has_questions && $boolean_check ) { |
|
| 984 | + foreach ($lesson_ids as $lesson_id) { |
|
| 985 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 986 | + if ($has_questions && $boolean_check) { |
|
| 987 | 987 | return true; |
| 988 | 988 | } |
| 989 | - elseif ( $has_questions ) { |
|
| 990 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 989 | + elseif ($has_questions) { |
|
| 990 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 991 | 991 | // $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
| 992 | 992 | // if( count( $questions ) > 0 ) { |
| 993 | 993 | $course_quizzes[] = $quiz_id; |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | } |
| 998 | - if ( $boolean_check && empty($course_quizzes) ) { |
|
| 998 | + if ($boolean_check && empty($course_quizzes)) { |
|
| 999 | 999 | $course_quizzes = false; |
| 1000 | 1000 | } |
| 1001 | 1001 | return $course_quizzes; |
@@ -1010,9 +1010,9 @@ discard block |
||
| 1010 | 1010 | * @param string $post_status (default: 'publish') |
| 1011 | 1011 | * @return array |
| 1012 | 1012 | */ |
| 1013 | - public function course_lessons_completed( $course_id = 0, $post_status = 'publish' ) { |
|
| 1013 | + public function course_lessons_completed($course_id = 0, $post_status = 'publish') { |
|
| 1014 | 1014 | |
| 1015 | - return $this->course_lessons( $course_id, $post_status ); |
|
| 1015 | + return $this->course_lessons($course_id, $post_status); |
|
| 1016 | 1016 | |
| 1017 | 1017 | } // End course_lessons_completed() |
| 1018 | 1018 | |
@@ -1025,9 +1025,9 @@ discard block |
||
| 1025 | 1025 | * @param int $course_id (default: 0) |
| 1026 | 1026 | * @return int |
| 1027 | 1027 | */ |
| 1028 | - public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) { |
|
| 1028 | + public function course_author_lesson_count($author_id = 0, $course_id = 0) { |
|
| 1029 | 1029 | |
| 1030 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1030 | + $lesson_args = array('post_type' => 'lesson', |
|
| 1031 | 1031 | 'posts_per_page' => -1, |
| 1032 | 1032 | 'author' => $author_id, |
| 1033 | 1033 | 'meta_key' => '_lesson_course', |
@@ -1036,8 +1036,8 @@ discard block |
||
| 1036 | 1036 | 'suppress_filters' => 0, |
| 1037 | 1037 | 'fields' => 'ids', // less data to retrieve |
| 1038 | 1038 | ); |
| 1039 | - $lessons_array = get_posts( $lesson_args ); |
|
| 1040 | - $count = count( $lessons_array ); |
|
| 1039 | + $lessons_array = get_posts($lesson_args); |
|
| 1040 | + $count = count($lessons_array); |
|
| 1041 | 1041 | return $count; |
| 1042 | 1042 | |
| 1043 | 1043 | } // End course_author_lesson_count() |
@@ -1049,9 +1049,9 @@ discard block |
||
| 1049 | 1049 | * @param int $course_id (default: 0) |
| 1050 | 1050 | * @return int |
| 1051 | 1051 | */ |
| 1052 | - public function course_lesson_count( $course_id = 0 ) { |
|
| 1052 | + public function course_lesson_count($course_id = 0) { |
|
| 1053 | 1053 | |
| 1054 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1054 | + $lesson_args = array('post_type' => 'lesson', |
|
| 1055 | 1055 | 'posts_per_page' => -1, |
| 1056 | 1056 | 'meta_key' => '_lesson_course', |
| 1057 | 1057 | 'meta_value' => $course_id, |
@@ -1059,9 +1059,9 @@ discard block |
||
| 1059 | 1059 | 'suppress_filters' => 0, |
| 1060 | 1060 | 'fields' => 'ids', // less data to retrieve |
| 1061 | 1061 | ); |
| 1062 | - $lessons_array = get_posts( $lesson_args ); |
|
| 1062 | + $lessons_array = get_posts($lesson_args); |
|
| 1063 | 1063 | |
| 1064 | - $count = count( $lessons_array ); |
|
| 1064 | + $count = count($lessons_array); |
|
| 1065 | 1065 | |
| 1066 | 1066 | return $count; |
| 1067 | 1067 | |
@@ -1074,9 +1074,9 @@ discard block |
||
| 1074 | 1074 | * @param int $course_id (default: 0) |
| 1075 | 1075 | * @return int |
| 1076 | 1076 | */ |
| 1077 | - public function course_lesson_preview_count( $course_id = 0 ) { |
|
| 1077 | + public function course_lesson_preview_count($course_id = 0) { |
|
| 1078 | 1078 | |
| 1079 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1079 | + $lesson_args = array('post_type' => 'lesson', |
|
| 1080 | 1080 | 'posts_per_page' => -1, |
| 1081 | 1081 | 'post_status' => 'publish', |
| 1082 | 1082 | 'suppress_filters' => 0, |
@@ -1092,9 +1092,9 @@ discard block |
||
| 1092 | 1092 | ), |
| 1093 | 1093 | 'fields' => 'ids', // less data to retrieve |
| 1094 | 1094 | ); |
| 1095 | - $lessons_array = get_posts( $lesson_args ); |
|
| 1095 | + $lessons_array = get_posts($lesson_args); |
|
| 1096 | 1096 | |
| 1097 | - $count = count( $lessons_array ); |
|
| 1097 | + $count = count($lessons_array); |
|
| 1098 | 1098 | |
| 1099 | 1099 | return $count; |
| 1100 | 1100 | |
@@ -1107,12 +1107,12 @@ discard block |
||
| 1107 | 1107 | * @param int $product_id (default: 0) |
| 1108 | 1108 | * @return array |
| 1109 | 1109 | */ |
| 1110 | - public function get_product_courses( $product_id = 0 ) { |
|
| 1110 | + public function get_product_courses($product_id = 0) { |
|
| 1111 | 1111 | |
| 1112 | 1112 | $posts_array = array(); |
| 1113 | 1113 | // Check for WooCommerce |
| 1114 | - if ( Sensei_WC::is_woocommerce_active() && 0 < $product_id ) { |
|
| 1115 | - $post_args = array( 'post_type' => 'course', |
|
| 1114 | + if (Sensei_WC::is_woocommerce_active() && 0 < $product_id) { |
|
| 1115 | + $post_args = array('post_type' => 'course', |
|
| 1116 | 1116 | 'posts_per_page' => -1, |
| 1117 | 1117 | 'meta_key' => '_course_woocommerce_product', |
| 1118 | 1118 | 'meta_value' => $product_id, |
@@ -1121,7 +1121,7 @@ discard block |
||
| 1121 | 1121 | 'orderby' => 'menu_order date', |
| 1122 | 1122 | 'order' => 'ASC', |
| 1123 | 1123 | ); |
| 1124 | - $posts_array = get_posts( $post_args ); |
|
| 1124 | + $posts_array = get_posts($post_args); |
|
| 1125 | 1125 | } // End If Statement |
| 1126 | 1126 | return $posts_array; |
| 1127 | 1127 | |
@@ -1141,17 +1141,17 @@ discard block |
||
| 1141 | 1141 | * @param WP_Query $query |
| 1142 | 1142 | * @return void |
| 1143 | 1143 | */ |
| 1144 | - public function filter_my_courses( $query ) { |
|
| 1144 | + public function filter_my_courses($query) { |
|
| 1145 | 1145 | global $my_courses_section; |
| 1146 | 1146 | |
| 1147 | - if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1148 | - $amount = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
|
| 1149 | - $query->set( 'posts_per_page', $amount ); |
|
| 1147 | + if (isset(Sensei()->settings->settings['my_course_amount']) && (0 < absint(Sensei()->settings->settings['my_course_amount']))) { |
|
| 1148 | + $amount = absint(Sensei()->settings->settings['my_course_amount']); |
|
| 1149 | + $query->set('posts_per_page', $amount); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | - if( isset( $_GET[ $my_courses_section . '_page' ] ) && 0 < intval( $_GET[ $my_courses_section . '_page' ] ) ) { |
|
| 1153 | - $page = intval( $_GET[ $my_courses_section . '_page' ] ); |
|
| 1154 | - $query->set( 'paged', $page ); |
|
| 1152 | + if (isset($_GET[$my_courses_section.'_page']) && 0 < intval($_GET[$my_courses_section.'_page'])) { |
|
| 1153 | + $page = intval($_GET[$my_courses_section.'_page']); |
|
| 1154 | + $query->set('paged', $page); |
|
| 1155 | 1155 | } |
| 1156 | 1156 | } |
| 1157 | 1157 | |
@@ -1165,48 +1165,48 @@ discard block |
||
| 1165 | 1165 | * @param boolean $manage Whether the user has permission to manage the courses |
| 1166 | 1166 | * @return string HTML displayng course data |
| 1167 | 1167 | */ |
| 1168 | - public function load_user_courses_content( $user = false ) { |
|
| 1168 | + public function load_user_courses_content($user = false) { |
|
| 1169 | 1169 | global $course, $my_courses_page, $my_courses_section; |
| 1170 | 1170 | |
| 1171 | - if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | - || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1171 | + if ( ! isset(Sensei()->settings->settings['learner_profile_show_courses']) |
|
| 1172 | + || ! Sensei()->settings->settings['learner_profile_show_courses']) { |
|
| 1173 | 1173 | |
| 1174 | 1174 | // do not show the content if the settings doesn't allow for it |
| 1175 | 1175 | return; |
| 1176 | 1176 | |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | - $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1179 | + $manage = ($user->ID == get_current_user_id()) ? true : false; |
|
| 1180 | 1180 | |
| 1181 | - do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1181 | + do_action('sensei_before_learner_course_content', $user); |
|
| 1182 | 1182 | |
| 1183 | 1183 | // Build Output HTML |
| 1184 | 1184 | $complete_html = $active_html = ''; |
| 1185 | 1185 | |
| 1186 | - if( is_a( $user, 'WP_User' ) ) { |
|
| 1186 | + if (is_a($user, 'WP_User')) { |
|
| 1187 | 1187 | |
| 1188 | 1188 | $my_courses_page = true; |
| 1189 | 1189 | |
| 1190 | 1190 | // Allow action to be run before My Courses content has loaded |
| 1191 | - do_action( 'sensei_before_my_courses', $user->ID ); |
|
| 1191 | + do_action('sensei_before_my_courses', $user->ID); |
|
| 1192 | 1192 | |
| 1193 | 1193 | // Logic for Active and Completed Courses |
| 1194 | 1194 | $per_page = 20; |
| 1195 | - if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) |
|
| 1196 | - && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1195 | + if (isset(Sensei()->settings->settings['my_course_amount']) |
|
| 1196 | + && (0 < absint(Sensei()->settings->settings['my_course_amount']))) { |
|
| 1197 | 1197 | |
| 1198 | - $per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
|
| 1198 | + $per_page = absint(Sensei()->settings->settings['my_course_amount']); |
|
| 1199 | 1199 | |
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | - $course_statuses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user->ID, 'type' => 'sensei_course_status' ), true ); |
|
| 1202 | + $course_statuses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user->ID, 'type' => 'sensei_course_status'), true); |
|
| 1203 | 1203 | // User may only be on 1 Course |
| 1204 | - if ( !is_array($course_statuses) ) { |
|
| 1205 | - $course_statuses = array( $course_statuses ); |
|
| 1204 | + if ( ! is_array($course_statuses)) { |
|
| 1205 | + $course_statuses = array($course_statuses); |
|
| 1206 | 1206 | } |
| 1207 | 1207 | $completed_ids = $active_ids = array(); |
| 1208 | - foreach( $course_statuses as $course_status ) { |
|
| 1209 | - if ( Sensei_Utils::user_completed_course( $course_status, $user->ID ) ) { |
|
| 1208 | + foreach ($course_statuses as $course_status) { |
|
| 1209 | + if (Sensei_Utils::user_completed_course($course_status, $user->ID)) { |
|
| 1210 | 1210 | $completed_ids[] = $course_status->comment_post_ID; |
| 1211 | 1211 | } else { |
| 1212 | 1212 | $active_ids[] = $course_status->comment_post_ID; |
@@ -1216,41 +1216,41 @@ discard block |
||
| 1216 | 1216 | $active_count = $completed_count = 0; |
| 1217 | 1217 | |
| 1218 | 1218 | $active_courses = array(); |
| 1219 | - if ( 0 < intval( count( $active_ids ) ) ) { |
|
| 1219 | + if (0 < intval(count($active_ids))) { |
|
| 1220 | 1220 | $my_courses_section = 'active'; |
| 1221 | - $active_courses = Sensei()->course->course_query( $per_page, 'usercourses', $active_ids ); |
|
| 1222 | - $active_count = count( $active_ids ); |
|
| 1221 | + $active_courses = Sensei()->course->course_query($per_page, 'usercourses', $active_ids); |
|
| 1222 | + $active_count = count($active_ids); |
|
| 1223 | 1223 | } // End If Statement |
| 1224 | 1224 | |
| 1225 | 1225 | $completed_courses = array(); |
| 1226 | - if ( 0 < intval( count( $completed_ids ) ) ) { |
|
| 1226 | + if (0 < intval(count($completed_ids))) { |
|
| 1227 | 1227 | $my_courses_section = 'completed'; |
| 1228 | - $completed_courses = Sensei()->course->course_query( $per_page, 'usercourses', $completed_ids ); |
|
| 1229 | - $completed_count = count( $completed_ids ); |
|
| 1228 | + $completed_courses = Sensei()->course->course_query($per_page, 'usercourses', $completed_ids); |
|
| 1229 | + $completed_count = count($completed_ids); |
|
| 1230 | 1230 | } // End If Statement |
| 1231 | 1231 | |
| 1232 | - foreach ( $active_courses as $course_item ) { |
|
| 1232 | + foreach ($active_courses as $course_item) { |
|
| 1233 | 1233 | |
| 1234 | - $course_lessons = Sensei()->course->course_lessons( $course_item->ID ); |
|
| 1234 | + $course_lessons = Sensei()->course->course_lessons($course_item->ID); |
|
| 1235 | 1235 | $lessons_completed = 0; |
| 1236 | - foreach ( $course_lessons as $lesson ) { |
|
| 1237 | - if ( Sensei_Utils::user_completed_lesson( $lesson->ID, $user->ID ) ) { |
|
| 1236 | + foreach ($course_lessons as $lesson) { |
|
| 1237 | + if (Sensei_Utils::user_completed_lesson($lesson->ID, $user->ID)) { |
|
| 1238 | 1238 | ++$lessons_completed; |
| 1239 | 1239 | } |
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | // Get Course Categories |
| 1243 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1243 | + $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', ''); |
|
| 1244 | 1244 | |
| 1245 | - $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1245 | + $active_html .= '<article class="'.esc_attr(join(' ', get_post_class(array('course', 'post'), $course_item->ID))).'">'; |
|
| 1246 | 1246 | |
| 1247 | 1247 | // Image |
| 1248 | - $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1248 | + $active_html .= Sensei()->course->course_image(absint($course_item->ID), '100', '100', true); |
|
| 1249 | 1249 | |
| 1250 | 1250 | // Title |
| 1251 | 1251 | $active_html .= '<header>'; |
| 1252 | 1252 | |
| 1253 | - $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1253 | + $active_html .= '<h2><a href="'.esc_url(get_permalink(absint($course_item->ID))).'" title="'.esc_attr($course_item->post_title).'">'.esc_html($course_item->post_title).'</a></h2>'; |
|
| 1254 | 1254 | |
| 1255 | 1255 | $active_html .= '</header>'; |
| 1256 | 1256 | |
@@ -1259,82 +1259,82 @@ discard block |
||
| 1259 | 1259 | $active_html .= '<p class="sensei-course-meta">'; |
| 1260 | 1260 | |
| 1261 | 1261 | // Author |
| 1262 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | - && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1262 | + $user_info = get_userdata(absint($course_item->post_author)); |
|
| 1263 | + if (isset(Sensei()->settings->settings['course_author']) |
|
| 1264 | + && (Sensei()->settings->settings['course_author'])) { |
|
| 1265 | 1265 | |
| 1266 | 1266 | $active_html .= '<span class="course-author">' |
| 1267 | - . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | - . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | - . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | - . esc_html( $user_info->display_name ) |
|
| 1267 | + . __('by ', 'woothemes-sensei') |
|
| 1268 | + . '<a href="'.esc_url(get_author_posts_url(absint($course_item->post_author))) |
|
| 1269 | + . '" title="'.esc_attr($user_info->display_name).'">' |
|
| 1270 | + . esc_html($user_info->display_name) |
|
| 1271 | 1271 | . '</a></span>'; |
| 1272 | 1272 | |
| 1273 | 1273 | } // End If Statement |
| 1274 | 1274 | |
| 1275 | 1275 | // Lesson count for this author |
| 1276 | - $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1276 | + $lesson_count = Sensei()->course->course_lesson_count(absint($course_item->ID)); |
|
| 1277 | 1277 | // Handle Division by Zero |
| 1278 | - if ( 0 == $lesson_count ) { |
|
| 1278 | + if (0 == $lesson_count) { |
|
| 1279 | 1279 | |
| 1280 | 1280 | $lesson_count = 1; |
| 1281 | 1281 | |
| 1282 | 1282 | } // End If Statement |
| 1283 | - $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1283 | + $active_html .= '<span class="course-lesson-count">'.$lesson_count.' '.__('Lessons', 'woothemes-sensei').'</span>'; |
|
| 1284 | 1284 | // Course Categories |
| 1285 | - if ( '' != $category_output ) { |
|
| 1285 | + if ('' != $category_output) { |
|
| 1286 | 1286 | |
| 1287 | - $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1287 | + $active_html .= '<span class="course-category">'.sprintf(__('in %s', 'woothemes-sensei'), $category_output).'</span>'; |
|
| 1288 | 1288 | |
| 1289 | 1289 | } // End If Statement |
| 1290 | - $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1290 | + $active_html .= '<span class="course-lesson-progress">'.sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $lessons_completed, $lesson_count).'</span>'; |
|
| 1291 | 1291 | |
| 1292 | 1292 | $active_html .= '</p>'; |
| 1293 | 1293 | |
| 1294 | - $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1294 | + $active_html .= '<p class="course-excerpt">'.$course_item->post_excerpt.'</p>'; |
|
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | 1297 | |
| 1298 | - $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1298 | + $progress_percentage = abs(round((doubleval($lessons_completed) * 100) / ($lesson_count), 0)); |
|
| 1299 | 1299 | |
| 1300 | - $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1300 | + $active_html .= $this->get_progress_meter($progress_percentage); |
|
| 1301 | 1301 | |
| 1302 | 1302 | $active_html .= '</section>'; |
| 1303 | 1303 | |
| 1304 | - if( is_user_logged_in() ) { |
|
| 1304 | + if (is_user_logged_in()) { |
|
| 1305 | 1305 | |
| 1306 | 1306 | $active_html .= '<section class="entry-actions">'; |
| 1307 | 1307 | |
| 1308 | - $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1308 | + $active_html .= '<form method="POST" action="'.esc_url(remove_query_arg(array('active_page', 'completed_page'))).'">'; |
|
| 1309 | 1309 | |
| 1310 | - $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1310 | + $active_html .= '<input type="hidden" name="'.esc_attr('woothemes_sensei_complete_course_noonce').'" id="'.esc_attr('woothemes_sensei_complete_course_noonce').'" value="'.esc_attr(wp_create_nonce('woothemes_sensei_complete_course_noonce')).'" />'; |
|
| 1311 | 1311 | |
| 1312 | - $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1312 | + $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="'.esc_attr(absint($course_item->ID)).'" />'; |
|
| 1313 | 1313 | |
| 1314 | - if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1314 | + if (0 < absint(count($course_lessons)) && Sensei()->settings->settings['course_completion'] == 'complete') { |
|
| 1315 | 1315 | |
| 1316 | 1316 | $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
| 1317 | - . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1317 | + . __('Mark as Complete', 'woothemes-sensei').'"/> </span>'; |
|
| 1318 | 1318 | |
| 1319 | 1319 | } // End If Statement |
| 1320 | 1320 | |
| 1321 | 1321 | $course_purchased = false; |
| 1322 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1322 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1323 | 1323 | |
| 1324 | 1324 | // Get the product ID |
| 1325 | - $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | - if ( 0 < $wc_post_id ) { |
|
| 1325 | + $wc_post_id = get_post_meta(absint($course_item->ID), '_course_woocommerce_product', true); |
|
| 1326 | + if (0 < $wc_post_id) { |
|
| 1327 | 1327 | |
| 1328 | - $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1328 | + $course_purchased = Sensei_WC::has_customer_bought_product($user->ID, $wc_post_id); |
|
| 1329 | 1329 | |
| 1330 | 1330 | } // End If Statement |
| 1331 | 1331 | |
| 1332 | 1332 | } // End If Statement |
| 1333 | 1333 | |
| 1334 | - if ( false == $course_purchased ) { |
|
| 1334 | + if (false == $course_purchased) { |
|
| 1335 | 1335 | |
| 1336 | 1336 | $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
| 1337 | - . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1337 | + . __('Delete Course', 'woothemes-sensei').'"/></span>'; |
|
| 1338 | 1338 | |
| 1339 | 1339 | } // End If Statement |
| 1340 | 1340 | |
@@ -1347,54 +1347,54 @@ discard block |
||
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | // Active pagination |
| 1350 | - if( $active_count > $per_page ) { |
|
| 1350 | + if ($active_count > $per_page) { |
|
| 1351 | 1351 | |
| 1352 | 1352 | $current_page = 1; |
| 1353 | - if( isset( $_GET['active_page'] ) && 0 < intval( $_GET['active_page'] ) ) { |
|
| 1353 | + if (isset($_GET['active_page']) && 0 < intval($_GET['active_page'])) { |
|
| 1354 | 1354 | $current_page = $_GET['active_page']; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | 1357 | $active_html .= '<nav class="pagination woo-pagination">'; |
| 1358 | - $total_pages = ceil( $active_count / $per_page ); |
|
| 1358 | + $total_pages = ceil($active_count / $per_page); |
|
| 1359 | 1359 | |
| 1360 | - if( $current_page > 1 ) { |
|
| 1361 | - $prev_link = add_query_arg( 'active_page', $current_page - 1 ); |
|
| 1362 | - $active_html .= '<a class="prev page-numbers" href="' . esc_url( $prev_link ) . '">' . __( 'Previous' , 'woothemes-sensei' ) . '</a> '; |
|
| 1360 | + if ($current_page > 1) { |
|
| 1361 | + $prev_link = add_query_arg('active_page', $current_page - 1); |
|
| 1362 | + $active_html .= '<a class="prev page-numbers" href="'.esc_url($prev_link).'">'.__('Previous', 'woothemes-sensei').'</a> '; |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | - for ( $i = 1; $i <= $total_pages; $i++ ) { |
|
| 1366 | - $link = add_query_arg( 'active_page', $i ); |
|
| 1365 | + for ($i = 1; $i <= $total_pages; $i++) { |
|
| 1366 | + $link = add_query_arg('active_page', $i); |
|
| 1367 | 1367 | |
| 1368 | - if( $i == $current_page ) { |
|
| 1369 | - $active_html .= '<span class="page-numbers current">' . $i . '</span> '; |
|
| 1368 | + if ($i == $current_page) { |
|
| 1369 | + $active_html .= '<span class="page-numbers current">'.$i.'</span> '; |
|
| 1370 | 1370 | } else { |
| 1371 | - $active_html .= '<a class="page-numbers" href="' . esc_url( $link ). '">' . $i . '</a> '; |
|
| 1371 | + $active_html .= '<a class="page-numbers" href="'.esc_url($link).'">'.$i.'</a> '; |
|
| 1372 | 1372 | } |
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | - if( $current_page < $total_pages ) { |
|
| 1376 | - $next_link = add_query_arg( 'active_page', $current_page + 1 ); |
|
| 1377 | - $active_html .= '<a class="next page-numbers" href="' . esc_url( $next_link ) . '">' . __( 'Next' , 'woothemes-sensei' ) . '</a> '; |
|
| 1375 | + if ($current_page < $total_pages) { |
|
| 1376 | + $next_link = add_query_arg('active_page', $current_page + 1); |
|
| 1377 | + $active_html .= '<a class="next page-numbers" href="'.esc_url($next_link).'">'.__('Next', 'woothemes-sensei').'</a> '; |
|
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | $active_html .= '</nav>'; |
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | - foreach ( $completed_courses as $course_item ) { |
|
| 1383 | + foreach ($completed_courses as $course_item) { |
|
| 1384 | 1384 | $course = $course_item; |
| 1385 | 1385 | |
| 1386 | 1386 | // Get Course Categories |
| 1387 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1387 | + $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', ''); |
|
| 1388 | 1388 | |
| 1389 | - $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1389 | + $complete_html .= '<article class="'.join(' ', get_post_class(array('course', 'post'), $course_item->ID)).'">'; |
|
| 1390 | 1390 | |
| 1391 | 1391 | // Image |
| 1392 | - $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1392 | + $complete_html .= Sensei()->course->course_image(absint($course_item->ID), 100, 100, true); |
|
| 1393 | 1393 | |
| 1394 | 1394 | // Title |
| 1395 | 1395 | $complete_html .= '<header>'; |
| 1396 | 1396 | |
| 1397 | - $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1397 | + $complete_html .= '<h2><a href="'.esc_url(get_permalink(absint($course_item->ID))).'" title="'.esc_attr($course_item->post_title).'">'.esc_html($course_item->post_title).'</a></h2>'; |
|
| 1398 | 1398 | |
| 1399 | 1399 | $complete_html .= '</header>'; |
| 1400 | 1400 | |
@@ -1403,46 +1403,46 @@ discard block |
||
| 1403 | 1403 | $complete_html .= '<p class="sensei-course-meta">'; |
| 1404 | 1404 | |
| 1405 | 1405 | // Author |
| 1406 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | - $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1406 | + $user_info = get_userdata(absint($course_item->post_author)); |
|
| 1407 | + if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { |
|
| 1408 | + $complete_html .= '<span class="course-author">'.__('by ', 'woothemes-sensei').'<a href="'.esc_url(get_author_posts_url(absint($course_item->post_author))).'" title="'.esc_attr($user_info->display_name).'">'.esc_html($user_info->display_name).'</a></span>'; |
|
| 1409 | 1409 | } // End If Statement |
| 1410 | 1410 | |
| 1411 | 1411 | // Lesson count for this author |
| 1412 | 1412 | $complete_html .= '<span class="course-lesson-count">' |
| 1413 | - . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | - . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1413 | + . Sensei()->course->course_lesson_count(absint($course_item->ID)) |
|
| 1414 | + . ' '.__('Lessons', 'woothemes-sensei') |
|
| 1415 | 1415 | . '</span>'; |
| 1416 | 1416 | |
| 1417 | 1417 | // Course Categories |
| 1418 | - if ( '' != $category_output ) { |
|
| 1418 | + if ('' != $category_output) { |
|
| 1419 | 1419 | |
| 1420 | - $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1420 | + $complete_html .= '<span class="course-category">'.sprintf(__('in %s', 'woothemes-sensei'), $category_output).'</span>'; |
|
| 1421 | 1421 | |
| 1422 | 1422 | } // End If Statement |
| 1423 | 1423 | |
| 1424 | 1424 | $complete_html .= '</p>'; |
| 1425 | 1425 | |
| 1426 | - $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1426 | + $complete_html .= '<p class="course-excerpt">'.$course_item->post_excerpt.'</p>'; |
|
| 1427 | 1427 | |
| 1428 | - $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1428 | + $complete_html .= $this->get_progress_meter(100); |
|
| 1429 | 1429 | |
| 1430 | - if( $manage ) { |
|
| 1431 | - $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true ); |
|
| 1430 | + if ($manage) { |
|
| 1431 | + $has_quizzes = Sensei()->course->course_quizzes($course_item->ID, true); |
|
| 1432 | 1432 | // Output only if there is content to display |
| 1433 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { |
|
| 1433 | + if (has_filter('sensei_results_links') || $has_quizzes) { |
|
| 1434 | 1434 | |
| 1435 | 1435 | |
| 1436 | 1436 | $complete_html .= '<p class="sensei-results-links">'; |
| 1437 | 1437 | $results_link = ''; |
| 1438 | - if( $has_quizzes ) { |
|
| 1438 | + if ($has_quizzes) { |
|
| 1439 | 1439 | |
| 1440 | 1440 | $results_link = '<a class="button view-results" href="' |
| 1441 | - . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | - . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1441 | + . Sensei()->course_results->get_permalink($course_item->ID) |
|
| 1442 | + . '">'.__('View results', 'woothemes-sensei') |
|
| 1443 | 1443 | . '</a>'; |
| 1444 | 1444 | } |
| 1445 | - $complete_html .= apply_filters( 'sensei_results_links', $results_link ); |
|
| 1445 | + $complete_html .= apply_filters('sensei_results_links', $results_link); |
|
| 1446 | 1446 | $complete_html .= '</p>'; |
| 1447 | 1447 | |
| 1448 | 1448 | } |
@@ -1454,35 +1454,35 @@ discard block |
||
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | // Active pagination |
| 1457 | - if( $completed_count > $per_page ) { |
|
| 1457 | + if ($completed_count > $per_page) { |
|
| 1458 | 1458 | |
| 1459 | 1459 | $current_page = 1; |
| 1460 | - if( isset( $_GET['completed_page'] ) && 0 < intval( $_GET['completed_page'] ) ) { |
|
| 1460 | + if (isset($_GET['completed_page']) && 0 < intval($_GET['completed_page'])) { |
|
| 1461 | 1461 | $current_page = $_GET['completed_page']; |
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | 1464 | $complete_html .= '<nav class="pagination woo-pagination">'; |
| 1465 | - $total_pages = ceil( $completed_count / $per_page ); |
|
| 1465 | + $total_pages = ceil($completed_count / $per_page); |
|
| 1466 | 1466 | |
| 1467 | 1467 | |
| 1468 | - if( $current_page > 1 ) { |
|
| 1469 | - $prev_link = add_query_arg( 'completed_page', $current_page - 1 ); |
|
| 1470 | - $complete_html .= '<a class="prev page-numbers" href="' . esc_url( $prev_link ) . '">' . __( 'Previous' , 'woothemes-sensei' ) . '</a> '; |
|
| 1468 | + if ($current_page > 1) { |
|
| 1469 | + $prev_link = add_query_arg('completed_page', $current_page - 1); |
|
| 1470 | + $complete_html .= '<a class="prev page-numbers" href="'.esc_url($prev_link).'">'.__('Previous', 'woothemes-sensei').'</a> '; |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | - for ( $i = 1; $i <= $total_pages; $i++ ) { |
|
| 1474 | - $link = add_query_arg( 'completed_page', $i ); |
|
| 1473 | + for ($i = 1; $i <= $total_pages; $i++) { |
|
| 1474 | + $link = add_query_arg('completed_page', $i); |
|
| 1475 | 1475 | |
| 1476 | - if( $i == $current_page ) { |
|
| 1477 | - $complete_html .= '<span class="page-numbers current">' . $i . '</span> '; |
|
| 1476 | + if ($i == $current_page) { |
|
| 1477 | + $complete_html .= '<span class="page-numbers current">'.$i.'</span> '; |
|
| 1478 | 1478 | } else { |
| 1479 | - $complete_html .= '<a class="page-numbers" href="' . esc_url( $link ) . '">' . $i . '</a> '; |
|
| 1479 | + $complete_html .= '<a class="page-numbers" href="'.esc_url($link).'">'.$i.'</a> '; |
|
| 1480 | 1480 | } |
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | - if( $current_page < $total_pages ) { |
|
| 1484 | - $next_link = add_query_arg( 'completed_page', $current_page + 1 ); |
|
| 1485 | - $complete_html .= '<a class="next page-numbers" href="' . esc_url( $next_link ) . '">' . __( 'Next' , 'woothemes-sensei' ) . '</a> '; |
|
| 1483 | + if ($current_page < $total_pages) { |
|
| 1484 | + $next_link = add_query_arg('completed_page', $current_page + 1); |
|
| 1485 | + $complete_html .= '<a class="next page-numbers" href="'.esc_url($next_link).'">'.__('Next', 'woothemes-sensei').'</a> '; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | $complete_html .= '</nav>'; |
@@ -1490,26 +1490,26 @@ discard block |
||
| 1490 | 1490 | |
| 1491 | 1491 | } // End If Statement |
| 1492 | 1492 | |
| 1493 | - if( $manage ) { |
|
| 1494 | - $no_active_message = __( 'You have no active courses.', 'woothemes-sensei' ); |
|
| 1495 | - $no_complete_message = __( 'You have not completed any courses yet.', 'woothemes-sensei' ); |
|
| 1493 | + if ($manage) { |
|
| 1494 | + $no_active_message = __('You have no active courses.', 'woothemes-sensei'); |
|
| 1495 | + $no_complete_message = __('You have not completed any courses yet.', 'woothemes-sensei'); |
|
| 1496 | 1496 | } else { |
| 1497 | - $no_active_message = __( 'This learner has no active courses.', 'woothemes-sensei' ); |
|
| 1498 | - $no_complete_message = __( 'This learner has not completed any courses yet.', 'woothemes-sensei' ); |
|
| 1497 | + $no_active_message = __('This learner has no active courses.', 'woothemes-sensei'); |
|
| 1498 | + $no_complete_message = __('This learner has not completed any courses yet.', 'woothemes-sensei'); |
|
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | ob_start(); |
| 1502 | 1502 | ?> |
| 1503 | 1503 | |
| 1504 | - <?php do_action( 'sensei_before_user_courses' ); ?> |
|
| 1504 | + <?php do_action('sensei_before_user_courses'); ?> |
|
| 1505 | 1505 | |
| 1506 | 1506 | <?php |
| 1507 | - if( $manage && ( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) ) { |
|
| 1507 | + if ($manage && ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable'])) { |
|
| 1508 | 1508 | ?> |
| 1509 | 1509 | <p class="my-messages-link-container"> |
| 1510 | - <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
|
| 1511 | - title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
|
| 1512 | - <?php _e( 'My Messages', 'woothemes-sensei' ); ?> |
|
| 1510 | + <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>" |
|
| 1511 | + title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>"> |
|
| 1512 | + <?php _e('My Messages', 'woothemes-sensei'); ?> |
|
| 1513 | 1513 | </a> |
| 1514 | 1514 | </p> |
| 1515 | 1515 | <?php |
@@ -1518,11 +1518,11 @@ discard block |
||
| 1518 | 1518 | <div id="my-courses"> |
| 1519 | 1519 | |
| 1520 | 1520 | <ul> |
| 1521 | - <li><a href="#active-courses"><?php _e( 'Active Courses', 'woothemes-sensei' ); ?></a></li> |
|
| 1522 | - <li><a href="#completed-courses"><?php _e( 'Completed Courses', 'woothemes-sensei' ); ?></a></li> |
|
| 1521 | + <li><a href="#active-courses"><?php _e('Active Courses', 'woothemes-sensei'); ?></a></li> |
|
| 1522 | + <li><a href="#completed-courses"><?php _e('Completed Courses', 'woothemes-sensei'); ?></a></li> |
|
| 1523 | 1523 | </ul> |
| 1524 | 1524 | |
| 1525 | - <?php do_action( 'sensei_before_active_user_courses' ); ?> |
|
| 1525 | + <?php do_action('sensei_before_active_user_courses'); ?> |
|
| 1526 | 1526 | |
| 1527 | 1527 | <?php |
| 1528 | 1528 | $course_page_url = Sensei_Course::get_courses_page_url(); |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | |
| 1531 | 1531 | <div id="active-courses"> |
| 1532 | 1532 | |
| 1533 | - <?php if ( '' != $active_html ) { |
|
| 1533 | + <?php if ('' != $active_html) { |
|
| 1534 | 1534 | |
| 1535 | 1535 | echo $active_html; |
| 1536 | 1536 | |
@@ -1542,7 +1542,7 @@ discard block |
||
| 1542 | 1542 | |
| 1543 | 1543 | <a href="<?php echo $course_page_url; ?>"> |
| 1544 | 1544 | |
| 1545 | - <?php _e( 'Start a Course!', 'woothemes-sensei' ); ?> |
|
| 1545 | + <?php _e('Start a Course!', 'woothemes-sensei'); ?> |
|
| 1546 | 1546 | |
| 1547 | 1547 | </a> |
| 1548 | 1548 | |
@@ -1552,13 +1552,13 @@ discard block |
||
| 1552 | 1552 | |
| 1553 | 1553 | </div> |
| 1554 | 1554 | |
| 1555 | - <?php do_action( 'sensei_after_active_user_courses' ); ?> |
|
| 1555 | + <?php do_action('sensei_after_active_user_courses'); ?> |
|
| 1556 | 1556 | |
| 1557 | - <?php do_action( 'sensei_before_completed_user_courses' ); ?> |
|
| 1557 | + <?php do_action('sensei_before_completed_user_courses'); ?> |
|
| 1558 | 1558 | |
| 1559 | 1559 | <div id="completed-courses"> |
| 1560 | 1560 | |
| 1561 | - <?php if ( '' != $complete_html ) { |
|
| 1561 | + <?php if ('' != $complete_html) { |
|
| 1562 | 1562 | |
| 1563 | 1563 | echo $complete_html; |
| 1564 | 1564 | |
@@ -1574,16 +1574,16 @@ discard block |
||
| 1574 | 1574 | |
| 1575 | 1575 | </div> |
| 1576 | 1576 | |
| 1577 | - <?php do_action( 'sensei_after_completed_user_courses' ); ?> |
|
| 1577 | + <?php do_action('sensei_after_completed_user_courses'); ?> |
|
| 1578 | 1578 | |
| 1579 | 1579 | </div> |
| 1580 | 1580 | |
| 1581 | - <?php do_action( 'sensei_after_user_courses' ); ?> |
|
| 1581 | + <?php do_action('sensei_after_user_courses'); ?> |
|
| 1582 | 1582 | |
| 1583 | 1583 | <?php |
| 1584 | 1584 | echo ob_get_clean(); |
| 1585 | 1585 | |
| 1586 | - do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1586 | + do_action('sensei_after_learner_course_content', $user); |
|
| 1587 | 1587 | |
| 1588 | 1588 | } // end load_user_courses_content |
| 1589 | 1589 | |
@@ -1595,7 +1595,7 @@ discard block |
||
| 1595 | 1595 | * @type $course WP_Post |
| 1596 | 1596 | * } |
| 1597 | 1597 | */ |
| 1598 | - public static function get_all_courses(){ |
|
| 1598 | + public static function get_all_courses() { |
|
| 1599 | 1599 | |
| 1600 | 1600 | $args = array( |
| 1601 | 1601 | 'post_type' => 'course', |
@@ -1606,7 +1606,7 @@ discard block |
||
| 1606 | 1606 | 'suppress_filters' => 0, |
| 1607 | 1607 | ); |
| 1608 | 1608 | |
| 1609 | - $wp_query_obj = new WP_Query( $args ); |
|
| 1609 | + $wp_query_obj = new WP_Query($args); |
|
| 1610 | 1610 | |
| 1611 | 1611 | /** |
| 1612 | 1612 | * sensei_get_all_courses filter |
@@ -1618,7 +1618,7 @@ discard block |
||
| 1618 | 1618 | * } |
| 1619 | 1619 | * @param array $attributes |
| 1620 | 1620 | */ |
| 1621 | - return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1621 | + return apply_filters('sensei_get_all_courses', $wp_query_obj->posts); |
|
| 1622 | 1622 | |
| 1623 | 1623 | }// end get_all_courses |
| 1624 | 1624 | |
@@ -1629,16 +1629,16 @@ discard block |
||
| 1629 | 1629 | * @param int $progress_percentage 0 - 100 |
| 1630 | 1630 | * @return string $progress_bar_html |
| 1631 | 1631 | */ |
| 1632 | - public function get_progress_meter( $progress_percentage ){ |
|
| 1632 | + public function get_progress_meter($progress_percentage) { |
|
| 1633 | 1633 | |
| 1634 | - if ( 50 < $progress_percentage ) { |
|
| 1634 | + if (50 < $progress_percentage) { |
|
| 1635 | 1635 | $class = ' green'; |
| 1636 | - } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1636 | + } elseif (25 <= $progress_percentage && 50 >= $progress_percentage) { |
|
| 1637 | 1637 | $class = ' orange'; |
| 1638 | 1638 | } else { |
| 1639 | 1639 | $class = ' red'; |
| 1640 | 1640 | } |
| 1641 | - $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1641 | + $progress_bar_html = '<div class="meter'.esc_attr($class).'"><span style="width: '.$progress_percentage.'%">'.round($progress_percentage).'%</span></div>'; |
|
| 1642 | 1642 | |
| 1643 | 1643 | return $progress_bar_html; |
| 1644 | 1644 | |
@@ -1653,17 +1653,17 @@ discard block |
||
| 1653 | 1653 | * |
| 1654 | 1654 | * @return string $statement_html |
| 1655 | 1655 | */ |
| 1656 | - public function get_progress_statement( $course_id, $user_id ){ |
|
| 1656 | + public function get_progress_statement($course_id, $user_id) { |
|
| 1657 | 1657 | |
| 1658 | - if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | - || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1658 | + if (empty($course_id) || empty($user_id) |
|
| 1659 | + || ! Sensei_Utils::user_started_course($course_id, $user_id)) { |
|
| 1660 | 1660 | return ''; |
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1663 | + $completed = count($this->get_completed_lesson_ids($course_id, $user_id)); |
|
| 1664 | + $total_lessons = count($this->course_lessons($course_id)); |
|
| 1665 | 1665 | |
| 1666 | - $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1666 | + $statement = sprintf(_n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons); |
|
| 1667 | 1667 | |
| 1668 | 1668 | /** |
| 1669 | 1669 | * Filter the course completion statement. |
@@ -1671,7 +1671,7 @@ discard block |
||
| 1671 | 1671 | * |
| 1672 | 1672 | * @param string $statement |
| 1673 | 1673 | */ |
| 1674 | - return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1674 | + return apply_filters('sensei_course_completion_statement', $statement); |
|
| 1675 | 1675 | |
| 1676 | 1676 | }// end generate_progress_statement |
| 1677 | 1677 | |
@@ -1681,17 +1681,17 @@ discard block |
||
| 1681 | 1681 | * @param $course_id |
| 1682 | 1682 | * @return void |
| 1683 | 1683 | */ |
| 1684 | - public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | - if( empty( $course_id ) ){ |
|
| 1684 | + public function the_progress_statement($course_id = 0, $user_id = 0) { |
|
| 1685 | + if (empty($course_id)) { |
|
| 1686 | 1686 | global $post; |
| 1687 | 1687 | $course_id = $post->ID; |
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | - if( empty( $user_id ) ){ |
|
| 1690 | + if (empty($user_id)) { |
|
| 1691 | 1691 | $user_id = get_current_user_id(); |
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | - echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1694 | + echo '<span class="progress statement course-completion-rate">'.$this->get_progress_statement($course_id, $user_id).'</span>'; |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | 1697 | /** |
@@ -1700,24 +1700,24 @@ discard block |
||
| 1700 | 1700 | * @param $course_id |
| 1701 | 1701 | * @return void |
| 1702 | 1702 | */ |
| 1703 | - public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1703 | + public function the_progress_meter($course_id = 0, $user_id = 0) { |
|
| 1704 | 1704 | |
| 1705 | - if( empty( $course_id ) ){ |
|
| 1705 | + if (empty($course_id)) { |
|
| 1706 | 1706 | global $post; |
| 1707 | 1707 | $course_id = $post->ID; |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | - if( empty( $user_id ) ){ |
|
| 1710 | + if (empty($user_id)) { |
|
| 1711 | 1711 | $user_id = get_current_user_id(); |
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | - || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1714 | + if ('course' != get_post_type($course_id) || ! get_userdata($user_id) |
|
| 1715 | + || ! Sensei_Utils::user_started_course($course_id, $user_id)) { |
|
| 1716 | 1716 | return; |
| 1717 | 1717 | } |
| 1718 | - $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1718 | + $percentage_completed = $this->get_completion_percentage($course_id, $user_id); |
|
| 1719 | 1719 | |
| 1720 | - echo $this->get_progress_meter( $percentage_completed ); |
|
| 1720 | + echo $this->get_progress_meter($percentage_completed); |
|
| 1721 | 1721 | |
| 1722 | 1722 | }// end the_progress_meter |
| 1723 | 1723 | |
@@ -1730,20 +1730,20 @@ discard block |
||
| 1730 | 1730 | * @param int $user_id |
| 1731 | 1731 | * @return array $completed_lesson_ids |
| 1732 | 1732 | */ |
| 1733 | - public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1733 | + public function get_completed_lesson_ids($course_id, $user_id = 0) { |
|
| 1734 | 1734 | |
| 1735 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1735 | + if ( ! (intval($user_id)) > 0) { |
|
| 1736 | 1736 | $user_id = get_current_user_id(); |
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | 1739 | $completed_lesson_ids = array(); |
| 1740 | 1740 | |
| 1741 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 1741 | + $course_lessons = $this->course_lessons($course_id); |
|
| 1742 | 1742 | |
| 1743 | - foreach( $course_lessons as $lesson ){ |
|
| 1743 | + foreach ($course_lessons as $lesson) { |
|
| 1744 | 1744 | |
| 1745 | - $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | - if( $is_lesson_completed ){ |
|
| 1745 | + $is_lesson_completed = Sensei_Utils::user_completed_lesson($lesson->ID, $user_id); |
|
| 1746 | + if ($is_lesson_completed) { |
|
| 1747 | 1747 | $completed_lesson_ids[] = $lesson->ID; |
| 1748 | 1748 | } |
| 1749 | 1749 | |
@@ -1762,19 +1762,19 @@ discard block |
||
| 1762 | 1762 | * @param int $user_id |
| 1763 | 1763 | * @return int $percentage |
| 1764 | 1764 | */ |
| 1765 | - public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1765 | + public function get_completion_percentage($course_id, $user_id = 0) { |
|
| 1766 | 1766 | |
| 1767 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1767 | + if ( ! (intval($user_id)) > 0) { |
|
| 1768 | 1768 | $user_id = get_current_user_id(); |
| 1769 | 1769 | } |
| 1770 | 1770 | |
| 1771 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1771 | + $completed = count($this->get_completed_lesson_ids($course_id, $user_id)); |
|
| 1772 | 1772 | |
| 1773 | - if( ! ( $completed > 0 ) ){ |
|
| 1773 | + if ( ! ($completed > 0)) { |
|
| 1774 | 1774 | return 0; |
| 1775 | 1775 | } |
| 1776 | 1776 | |
| 1777 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1777 | + $total_lessons = count($this->course_lessons($course_id)); |
|
| 1778 | 1778 | $percentage = $completed / $total_lessons * 100; |
| 1779 | 1779 | |
| 1780 | 1780 | /** |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | * @param $user_id |
| 1787 | 1787 | * @since 1.8.0 |
| 1788 | 1788 | */ |
| 1789 | - return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1789 | + return apply_filters('sensei_course_completion_percentage', $percentage, $course_id, $user_id); |
|
| 1790 | 1790 | |
| 1791 | 1791 | }// end get_completed_lesson_ids |
| 1792 | 1792 | |
@@ -1798,28 +1798,28 @@ discard block |
||
| 1798 | 1798 | * @param $should_send |
| 1799 | 1799 | * @return bool |
| 1800 | 1800 | */ |
| 1801 | - public function block_notification_emails( $should_send ){ |
|
| 1801 | + public function block_notification_emails($should_send) { |
|
| 1802 | 1802 | global $sensei_email_data; |
| 1803 | 1803 | $email = $sensei_email_data; |
| 1804 | 1804 | |
| 1805 | 1805 | $course_id = ''; |
| 1806 | 1806 | |
| 1807 | - if( isset( $email['course_id'] ) ){ |
|
| 1807 | + if (isset($email['course_id'])) { |
|
| 1808 | 1808 | |
| 1809 | 1809 | $course_id = $email['course_id']; |
| 1810 | 1810 | |
| 1811 | - }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1811 | + }elseif (isset($email['lesson_id'])) { |
|
| 1812 | 1812 | |
| 1813 | - $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1813 | + $course_id = Sensei()->lesson->get_course_id($email['lesson_id']); |
|
| 1814 | 1814 | |
| 1815 | - }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1815 | + }elseif (isset($email['quiz_id'])) { |
|
| 1816 | 1816 | |
| 1817 | - $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1817 | + $lesson_id = Sensei()->quiz->get_lesson_id($email['quiz_id']); |
|
| 1818 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1819 | 1819 | |
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | - if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1822 | + if ( ! empty($course_id) && 'course' == get_post_type($course_id)) { |
|
| 1823 | 1823 | |
| 1824 | 1824 | $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
| 1825 | 1825 | |
@@ -1840,19 +1840,19 @@ discard block |
||
| 1840 | 1840 | * @since 1.8.0 |
| 1841 | 1841 | * @param $course |
| 1842 | 1842 | */ |
| 1843 | - public function course_notification_meta_box_content( $course ){ |
|
| 1843 | + public function course_notification_meta_box_content($course) { |
|
| 1844 | 1844 | |
| 1845 | - $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1845 | + $checked = get_post_meta($course->ID, 'disable_notification', true); |
|
| 1846 | 1846 | |
| 1847 | 1847 | // generate checked html |
| 1848 | 1848 | $checked_html = ''; |
| 1849 | - if( $checked ){ |
|
| 1849 | + if ($checked) { |
|
| 1850 | 1850 | $checked_html = 'checked="checked"'; |
| 1851 | 1851 | } |
| 1852 | - wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1852 | + wp_nonce_field('update-course-notification-setting', '_sensei_course_notification'); |
|
| 1853 | 1853 | |
| 1854 | - echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | - echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1854 | + echo '<input id="disable_sensei_course_notification" '.$checked_html.' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | + echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei').'</label>'; |
|
| 1856 | 1856 | |
| 1857 | 1857 | }// end course_notification_meta_box_content |
| 1858 | 1858 | |
@@ -1864,20 +1864,20 @@ discard block |
||
| 1864 | 1864 | * |
| 1865 | 1865 | * @param $course_id |
| 1866 | 1866 | */ |
| 1867 | - public function save_course_notification_meta_box( $course_id ){ |
|
| 1867 | + public function save_course_notification_meta_box($course_id) { |
|
| 1868 | 1868 | |
| 1869 | - if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | - || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1869 | + if ( ! isset($_POST['_sensei_course_notification']) |
|
| 1870 | + || ! wp_verify_nonce($_POST['_sensei_course_notification'], 'update-course-notification-setting')) { |
|
| 1871 | 1871 | return; |
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | - if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1874 | + if (isset($_POST['disable_sensei_course_notification']) && 'on' == $_POST['disable_sensei_course_notification']) { |
|
| 1875 | 1875 | $new_val = true; |
| 1876 | - }else{ |
|
| 1876 | + } else { |
|
| 1877 | 1877 | $new_val = false; |
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | - update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1880 | + update_post_meta($course_id, 'disable_notification', $new_val); |
|
| 1881 | 1881 | |
| 1882 | 1882 | }// end save notification meta box |
| 1883 | 1883 | |
@@ -1891,10 +1891,10 @@ discard block |
||
| 1891 | 1891 | * |
| 1892 | 1892 | * @param WP_Post $post |
| 1893 | 1893 | */ |
| 1894 | - public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1894 | + public function content_before_backwards_compatibility_hooks($post) { |
|
| 1895 | 1895 | |
| 1896 | - sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | - sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1896 | + sensei_do_deprecated_action('sensei_course_image', '1.9.0', 'sensei_course_content_inside_before'); |
|
| 1897 | + sensei_do_deprecated_action('sensei_course_archive_course_title', '1.9.0', 'sensei_course_content_inside_before'); |
|
| 1898 | 1898 | |
| 1899 | 1899 | } |
| 1900 | 1900 | |
@@ -1907,10 +1907,10 @@ discard block |
||
| 1907 | 1907 | * |
| 1908 | 1908 | * @global WP_Post $post |
| 1909 | 1909 | */ |
| 1910 | - public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1910 | + public function loop_before_backwards_compatibility_hooks( ) { |
|
| 1911 | 1911 | |
| 1912 | 1912 | global $post; |
| 1913 | - sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1913 | + sensei_do_deprecated_action('sensei_course_archive_header', '1.9.0', 'sensei_course_content_inside_before', $post->post_type); |
|
| 1914 | 1914 | |
| 1915 | 1915 | } |
| 1916 | 1916 | |
@@ -1923,18 +1923,18 @@ discard block |
||
| 1923 | 1923 | * |
| 1924 | 1924 | * @param WP_Post $course |
| 1925 | 1925 | */ |
| 1926 | - public function the_course_free_lesson_preview( $course ){ |
|
| 1926 | + public function the_course_free_lesson_preview($course) { |
|
| 1927 | 1927 | // Meta data |
| 1928 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1929 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1928 | + $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course->ID)); |
|
| 1929 | + $is_user_taking_course = Sensei_Utils::user_started_course($course->ID, get_current_user_id()); |
|
| 1930 | 1930 | |
| 1931 | - if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1931 | + if (0 < $preview_lesson_count && ! $is_user_taking_course) { |
|
| 1932 | 1932 | ?> |
| 1933 | 1933 | <p class="sensei-free-lessons"> |
| 1934 | 1934 | <a href="<?php echo get_permalink(); ?>"> |
| 1935 | - <?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
|
| 1935 | + <?php _e('Preview this course', 'woothemes-sensei') ?> |
|
| 1936 | 1936 | </a> |
| 1937 | - - <?php echo sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ) ; ?> |
|
| 1937 | + - <?php echo sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?> |
|
| 1938 | 1938 | </p> |
| 1939 | 1939 | |
| 1940 | 1940 | <?php |
@@ -1947,38 +1947,38 @@ discard block |
||
| 1947 | 1947 | * @since 1.9.0 |
| 1948 | 1948 | * @param WP_Post $course |
| 1949 | 1949 | */ |
| 1950 | - public function the_course_meta( $course ){ |
|
| 1950 | + public function the_course_meta($course) { |
|
| 1951 | 1951 | echo '<p class="sensei-course-meta">'; |
| 1952 | 1952 | |
| 1953 | - $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1954 | - $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1953 | + $category_output = get_the_term_list($course->ID, 'course-category', '', ', ', ''); |
|
| 1954 | + $author_display_name = get_the_author_meta('display_name', $course->post_author); |
|
| 1955 | 1955 | |
| 1956 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1956 | + if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) {?> |
|
| 1957 | 1957 | |
| 1958 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?> |
|
| 1958 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?> |
|
| 1959 | 1959 | |
| 1960 | - <a href="<?php esc_attr_e( get_author_posts_url( $course->post_author ) ); ?>" title="<?php esc_attr_e( $author_display_name ); ?>"><?php esc_attr_e( $author_display_name ); ?></a> |
|
| 1960 | + <a href="<?php esc_attr_e(get_author_posts_url($course->post_author)); ?>" title="<?php esc_attr_e($author_display_name); ?>"><?php esc_attr_e($author_display_name); ?></a> |
|
| 1961 | 1961 | |
| 1962 | 1962 | </span> |
| 1963 | 1963 | |
| 1964 | 1964 | <?php } // End If Statement ?> |
| 1965 | 1965 | |
| 1966 | - <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $course->ID ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?></span> |
|
| 1966 | + <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($course->ID).' '.__('Lessons', 'woothemes-sensei'); ?></span> |
|
| 1967 | 1967 | |
| 1968 | - <?php if ( '' != $category_output ) { ?> |
|
| 1968 | + <?php if ('' != $category_output) { ?> |
|
| 1969 | 1969 | |
| 1970 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> |
|
| 1970 | + <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> |
|
| 1971 | 1971 | |
| 1972 | 1972 | <?php } // End If Statement |
| 1973 | 1973 | |
| 1974 | 1974 | // number of completed lessons |
| 1975 | - if( is_user_logged_in() ){ |
|
| 1976 | - $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1977 | - $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1978 | - echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1975 | + if (is_user_logged_in()) { |
|
| 1976 | + $completed = count($this->get_completed_lesson_ids($course->ID, get_current_user_id())); |
|
| 1977 | + $lesson_count = count($this->course_lessons($course->ID)); |
|
| 1978 | + echo '<span class="course-lesson-progress">'.sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $completed, $lesson_count).'</span>'; |
|
| 1979 | 1979 | } |
| 1980 | 1980 | |
| 1981 | - sensei_simple_course_price( $course->ID ); |
|
| 1981 | + sensei_simple_course_price($course->ID); |
|
| 1982 | 1982 | |
| 1983 | 1983 | echo '</p>'; |
| 1984 | 1984 | } // end the course meta |
@@ -1993,15 +1993,15 @@ discard block |
||
| 1993 | 1993 | * |
| 1994 | 1994 | * @return array $classes |
| 1995 | 1995 | */ |
| 1996 | - public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1996 | + public static function add_course_user_status_class($classes, $class, $course_id) { |
|
| 1997 | 1997 | |
| 1998 | - if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 1998 | + if ('course' == get_post_type($course_id) && is_user_logged_in()) { |
|
| 1999 | 1999 | |
| 2000 | - if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2000 | + if (Sensei_Utils::user_completed_course($course_id, get_current_user_id())) { |
|
| 2001 | 2001 | |
| 2002 | 2002 | $classes[] = 'user-status-completed'; |
| 2003 | 2003 | |
| 2004 | - }else{ |
|
| 2004 | + } else { |
|
| 2005 | 2005 | |
| 2006 | 2006 | $classes[] = 'user-status-active'; |
| 2007 | 2007 | |
@@ -2021,56 +2021,56 @@ discard block |
||
| 2021 | 2021 | * |
| 2022 | 2022 | * @param WP_Post $course |
| 2023 | 2023 | */ |
| 2024 | - public static function the_course_action_buttons( $course ){ |
|
| 2024 | + public static function the_course_action_buttons($course) { |
|
| 2025 | 2025 | |
| 2026 | - if( is_user_logged_in() ) { ?> |
|
| 2026 | + if (is_user_logged_in()) { ?> |
|
| 2027 | 2027 | |
| 2028 | 2028 | <section class="entry-actions"> |
| 2029 | - <form method="POST" action="<?php echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>"> |
|
| 2029 | + <form method="POST" action="<?php echo esc_url(remove_query_arg(array('active_page', 'completed_page'))); ?>"> |
|
| 2030 | 2030 | |
| 2031 | 2031 | <input type="hidden" |
| 2032 | - name="<?php esc_attr_e( 'woothemes_sensei_complete_course_noonce' ) ?>" |
|
| 2033 | - id="<?php esc_attr_e( 'woothemes_sensei_complete_course_noonce' ); ?>" |
|
| 2034 | - value="<?php esc_attr_e( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ); ?>" |
|
| 2032 | + name="<?php esc_attr_e('woothemes_sensei_complete_course_noonce') ?>" |
|
| 2033 | + id="<?php esc_attr_e('woothemes_sensei_complete_course_noonce'); ?>" |
|
| 2034 | + value="<?php esc_attr_e(wp_create_nonce('woothemes_sensei_complete_course_noonce')); ?>" |
|
| 2035 | 2035 | /> |
| 2036 | 2036 | |
| 2037 | - <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e( intval( $course->ID ) ); ?>" /> |
|
| 2037 | + <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e(intval($course->ID)); ?>" /> |
|
| 2038 | 2038 | |
| 2039 | - <?php if ( 0 < absint( count( Sensei()->course->course_lessons( $course->ID ) ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { ?> |
|
| 2039 | + <?php if (0 < absint(count(Sensei()->course->course_lessons($course->ID))) && Sensei()->settings->settings['course_completion'] == 'complete') { ?> |
|
| 2040 | 2040 | |
| 2041 | - <span><input name="course_complete" type="submit" class="course-complete" value="<?php _e( 'Mark as Complete', 'woothemes-sensei' ); ?>" /></span> |
|
| 2041 | + <span><input name="course_complete" type="submit" class="course-complete" value="<?php _e('Mark as Complete', 'woothemes-sensei'); ?>" /></span> |
|
| 2042 | 2042 | |
| 2043 | 2043 | <?php } // End If Statement |
| 2044 | 2044 | |
| 2045 | 2045 | $course_purchased = false; |
| 2046 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2046 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 2047 | 2047 | // Get the product ID |
| 2048 | - $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2049 | - if ( 0 < $wc_post_id ) { |
|
| 2048 | + $wc_post_id = get_post_meta(intval($course->ID), '_course_woocommerce_product', true); |
|
| 2049 | + if (0 < $wc_post_id) { |
|
| 2050 | 2050 | |
| 2051 | 2051 | $user = wp_get_current_user(); |
| 2052 | - $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2052 | + $course_purchased = Sensei_Utils::sensei_customer_bought_product($user->user_email, $user->ID, $wc_post_id); |
|
| 2053 | 2053 | |
| 2054 | 2054 | } // End If Statement |
| 2055 | 2055 | } // End If Statement |
| 2056 | 2056 | |
| 2057 | - if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2057 | + if ( ! $course_purchased && ! Sensei_Utils::user_completed_course($course->ID, get_current_user_id())) {?> |
|
| 2058 | 2058 | |
| 2059 | - <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span> |
|
| 2059 | + <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __('Delete Course', 'woothemes-sensei'); ?>"/></span> |
|
| 2060 | 2060 | |
| 2061 | 2061 | <?php } // End If Statement |
| 2062 | 2062 | |
| 2063 | - $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2063 | + $has_quizzes = Sensei()->course->course_quizzes($course->ID, true); |
|
| 2064 | 2064 | $results_link = ''; |
| 2065 | - if( $has_quizzes ){ |
|
| 2066 | - $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2065 | + if ($has_quizzes) { |
|
| 2066 | + $results_link = '<a class="button view-results" href="'.Sensei()->course_results->get_permalink($course->ID).'">'.__('View results', 'woothemes-sensei').'</a>'; |
|
| 2067 | 2067 | } |
| 2068 | 2068 | |
| 2069 | 2069 | // Output only if there is content to display |
| 2070 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2070 | + if (has_filter('sensei_results_links') || $has_quizzes) { ?> |
|
| 2071 | 2071 | |
| 2072 | 2072 | <p class="sensei-results-links"> |
| 2073 | - <?php echo apply_filters( 'sensei_results_links', $results_link ); ?> |
|
| 2073 | + <?php echo apply_filters('sensei_results_links', $results_link); ?> |
|
| 2074 | 2074 | </p> |
| 2075 | 2075 | |
| 2076 | 2076 | <?php } // end if has filter ?> |
@@ -2095,17 +2095,17 @@ discard block |
||
| 2095 | 2095 | * @param WP_Query $query |
| 2096 | 2096 | * @return WP_Query $query |
| 2097 | 2097 | */ |
| 2098 | - public static function course_query_filter( $query ){ |
|
| 2098 | + public static function course_query_filter($query) { |
|
| 2099 | 2099 | |
| 2100 | 2100 | // exit early for no course queries and admin queries |
| 2101 | - if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2101 | + if (is_admin( ) || 'course' != $query->get('post_type')) { |
|
| 2102 | 2102 | return $query; |
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | global $post; // used to get the current page id for my courses |
| 2106 | 2106 | |
| 2107 | 2107 | // for the course archive page |
| 2108 | - if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2108 | + if ($query->is_main_query() && is_post_type_archive('course')) |
|
| 2109 | 2109 | { |
| 2110 | 2110 | /** |
| 2111 | 2111 | * sensei_archive_courses_per_page |
@@ -2116,11 +2116,11 @@ discard block |
||
| 2116 | 2116 | * @since 1.9.0 |
| 2117 | 2117 | * @param integer $posts_per_page default 10 |
| 2118 | 2118 | */ |
| 2119 | - $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) ); |
|
| 2119 | + $query->set('posts_per_page', apply_filters('sensei_archive_courses_per_page', 10)); |
|
| 2120 | 2120 | |
| 2121 | 2121 | } |
| 2122 | 2122 | // for the my courses page |
| 2123 | - elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2123 | + elseif (is_page() && Sensei()->settings->get('my_course_page') == $post->ID) |
|
| 2124 | 2124 | { |
| 2125 | 2125 | /** |
| 2126 | 2126 | * sensei_my_courses_per_page |
@@ -2131,7 +2131,7 @@ discard block |
||
| 2131 | 2131 | * @since 1.9.0 |
| 2132 | 2132 | * @param integer $posts_per_page default 10 |
| 2133 | 2133 | */ |
| 2134 | - $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) ); |
|
| 2134 | + $query->set('posts_per_page', apply_filters('sensei_my_courses_per_page', 10)); |
|
| 2135 | 2135 | |
| 2136 | 2136 | } |
| 2137 | 2137 | |
@@ -2147,21 +2147,21 @@ discard block |
||
| 2147 | 2147 | * @return array $extra_classes |
| 2148 | 2148 | * @since 1.9.0 |
| 2149 | 2149 | */ |
| 2150 | - public static function get_course_loop_content_class () |
|
| 2150 | + public static function get_course_loop_content_class() |
|
| 2151 | 2151 | { |
| 2152 | 2152 | |
| 2153 | 2153 | global $sensei_course_loop; |
| 2154 | 2154 | |
| 2155 | 2155 | |
| 2156 | - if( !isset( $sensei_course_loop ) ){ |
|
| 2156 | + if ( ! isset($sensei_course_loop)) { |
|
| 2157 | 2157 | $sensei_course_loop = array(); |
| 2158 | 2158 | } |
| 2159 | 2159 | |
| 2160 | - if (!isset($sensei_course_loop['counter'])) { |
|
| 2160 | + if ( ! isset($sensei_course_loop['counter'])) { |
|
| 2161 | 2161 | $sensei_course_loop['counter'] = 0; |
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | - if (!isset($sensei_course_loop['columns'])) { |
|
| 2164 | + if ( ! isset($sensei_course_loop['columns'])) { |
|
| 2165 | 2165 | $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
| 2166 | 2166 | } |
| 2167 | 2167 | |
@@ -2169,16 +2169,16 @@ discard block |
||
| 2169 | 2169 | $sensei_course_loop['counter']++; |
| 2170 | 2170 | |
| 2171 | 2171 | $extra_classes = array(); |
| 2172 | - if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2172 | + if (0 == ($sensei_course_loop['counter'] - 1) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']) { |
|
| 2173 | 2173 | $extra_classes[] = 'first'; |
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | - if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2176 | + if (0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']) { |
|
| 2177 | 2177 | $extra_classes[] = 'last'; |
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | // add the item number to the classes as well. |
| 2181 | - $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2181 | + $extra_classes[] = 'loop-item-number-'.$sensei_course_loop['counter']; |
|
| 2182 | 2182 | |
| 2183 | 2183 | /** |
| 2184 | 2184 | * Filter the course loop class the fires in the in get_course_loop_content_class function |
@@ -2189,7 +2189,7 @@ discard block |
||
| 2189 | 2189 | * @param array $extra_classes |
| 2190 | 2190 | * @param WP_Post $loop_current_course |
| 2191 | 2191 | */ |
| 2192 | - return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2192 | + return apply_filters('sensei_course_loop_content_class', $extra_classes, get_post()); |
|
| 2193 | 2193 | |
| 2194 | 2194 | }// end get_course_loop_class |
| 2195 | 2195 | |
@@ -2199,7 +2199,7 @@ discard block |
||
| 2199 | 2199 | * @since 1.9.0 |
| 2200 | 2200 | * @return mixed|void |
| 2201 | 2201 | */ |
| 2202 | - public static function get_loop_number_of_columns(){ |
|
| 2202 | + public static function get_loop_number_of_columns() { |
|
| 2203 | 2203 | |
| 2204 | 2204 | /** |
| 2205 | 2205 | * Filter the number of columns on the course archive page. |
@@ -2219,10 +2219,10 @@ discard block |
||
| 2219 | 2219 | * @since 1.9.0 |
| 2220 | 2220 | * @param |
| 2221 | 2221 | */ |
| 2222 | - public static function course_archive_sorting( $query ){ |
|
| 2222 | + public static function course_archive_sorting($query) { |
|
| 2223 | 2223 | |
| 2224 | 2224 | // don't show on category pages and other pages |
| 2225 | - if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2225 | + if ( ! is_archive('course ') || is_tax('course-category')) { |
|
| 2226 | 2226 | return; |
| 2227 | 2227 | } |
| 2228 | 2228 | |
@@ -2235,27 +2235,27 @@ discard block |
||
| 2235 | 2235 | * @type string $option_string |
| 2236 | 2236 | * } |
| 2237 | 2237 | */ |
| 2238 | - $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2239 | - "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2240 | - "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2238 | + $course_order_by_options = apply_filters('sensei_archive_course_order_by_options', array( |
|
| 2239 | + "newness" => __("Sort by newest first", "woothemes-sensei"), |
|
| 2240 | + "title" => __("Sort by title A-Z", "woothemes-sensei"), |
|
| 2241 | 2241 | )); |
| 2242 | 2242 | |
| 2243 | 2243 | // setup the currently selected item |
| 2244 | 2244 | $selected = 'newness'; |
| 2245 | - if( isset( $_GET['orderby'] ) ){ |
|
| 2245 | + if (isset($_GET['orderby'])) { |
|
| 2246 | 2246 | |
| 2247 | - $selected = $_GET[ 'orderby' ]; |
|
| 2247 | + $selected = $_GET['orderby']; |
|
| 2248 | 2248 | |
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | 2251 | ?> |
| 2252 | 2252 | |
| 2253 | - <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST"> |
|
| 2253 | + <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr(Sensei_Utils::get_current_url()); ?>" method="POST"> |
|
| 2254 | 2254 | <select name="course-orderby" class="orderby"> |
| 2255 | 2255 | <?php |
| 2256 | - foreach( $course_order_by_options as $value => $text ){ |
|
| 2256 | + foreach ($course_order_by_options as $value => $text) { |
|
| 2257 | 2257 | |
| 2258 | - echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2258 | + echo '<option value="'.$value.' "'.selected($selected, $value, false).'>'.$text.'</option>'; |
|
| 2259 | 2259 | |
| 2260 | 2260 | } |
| 2261 | 2261 | ?> |
@@ -2273,10 +2273,10 @@ discard block |
||
| 2273 | 2273 | * @since 1.9.0 |
| 2274 | 2274 | * @param |
| 2275 | 2275 | */ |
| 2276 | - public static function course_archive_filters( $query ){ |
|
| 2276 | + public static function course_archive_filters($query) { |
|
| 2277 | 2277 | |
| 2278 | 2278 | // don't show on category pages |
| 2279 | - if( is_tax('course-category') ){ |
|
| 2279 | + if (is_tax('course-category')) { |
|
| 2280 | 2280 | return; |
| 2281 | 2281 | } |
| 2282 | 2282 | |
@@ -2289,9 +2289,9 @@ discard block |
||
| 2289 | 2289 | * } |
| 2290 | 2290 | * |
| 2291 | 2291 | */ |
| 2292 | - $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2293 | - array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2294 | - array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2292 | + $filters = apply_filters('sensei_archive_course_filter_by_options', array( |
|
| 2293 | + array('id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __('All', 'woothemes-sensei')), |
|
| 2294 | + array('id' => 'featured', 'url' => add_query_arg(array('course_filter'=>'featured'), self::get_courses_page_url()), 'title'=> __('Featured', 'woothemes-sensei')), |
|
| 2295 | 2295 | )); |
| 2296 | 2296 | |
| 2297 | 2297 | |
@@ -2302,11 +2302,11 @@ discard block |
||
| 2302 | 2302 | //determine the current active url |
| 2303 | 2303 | $current_url = Sensei_Utils::get_current_url(); |
| 2304 | 2304 | |
| 2305 | - foreach( $filters as $filter ) { |
|
| 2305 | + foreach ($filters as $filter) { |
|
| 2306 | 2306 | |
| 2307 | - $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2307 | + $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2308 | 2308 | |
| 2309 | - echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2309 | + echo '<li><a '.$active_class.' id="'.$filter['id'].'" href="'.esc_url($filter['url']).'" >'.$filter['title'].'</a></li>'; |
|
| 2310 | 2310 | |
| 2311 | 2311 | } |
| 2312 | 2312 | ?> |
@@ -2327,13 +2327,13 @@ discard block |
||
| 2327 | 2327 | * @param WP_Query $query |
| 2328 | 2328 | * @return WP_Query $query |
| 2329 | 2329 | */ |
| 2330 | - public static function course_archive_featured_filter( $query ){ |
|
| 2330 | + public static function course_archive_featured_filter($query) { |
|
| 2331 | 2331 | |
| 2332 | - if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2332 | + if (isset ($_GET['course_filter']) && 'featured' == $_GET['course_filter'] && $query->is_main_query()) { |
|
| 2333 | 2333 | //setup meta query for featured courses |
| 2334 | - $query->set( 'meta_value', 'featured' ); |
|
| 2335 | - $query->set( 'meta_key', '_course_featured' ); |
|
| 2336 | - $query->set( 'meta_compare', '=' ); |
|
| 2334 | + $query->set('meta_value', 'featured'); |
|
| 2335 | + $query->set('meta_key', '_course_featured'); |
|
| 2336 | + $query->set('meta_compare', '='); |
|
| 2337 | 2337 | } |
| 2338 | 2338 | |
| 2339 | 2339 | return $query; |
@@ -2348,13 +2348,13 @@ discard block |
||
| 2348 | 2348 | * @param WP_Query $query |
| 2349 | 2349 | * @return WP_Query $query |
| 2350 | 2350 | */ |
| 2351 | - public static function course_archive_order_by_title( $query ){ |
|
| 2351 | + public static function course_archive_order_by_title($query) { |
|
| 2352 | 2352 | |
| 2353 | - if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2354 | - && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2353 | + if (isset ($_POST['course-orderby']) && 'title ' == $_POST['course-orderby'] |
|
| 2354 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 2355 | 2355 | // setup the order by title for this query |
| 2356 | - $query->set( 'orderby', 'title' ); |
|
| 2357 | - $query->set( 'order', 'ASC' ); |
|
| 2356 | + $query->set('orderby', 'title'); |
|
| 2357 | + $query->set('order', 'ASC'); |
|
| 2358 | 2358 | } |
| 2359 | 2359 | |
| 2360 | 2360 | return $query; |
@@ -2368,10 +2368,10 @@ discard block |
||
| 2368 | 2368 | * @since 1.9.0 |
| 2369 | 2369 | * @return string $course_page_url |
| 2370 | 2370 | */ |
| 2371 | - public static function get_courses_page_url(){ |
|
| 2371 | + public static function get_courses_page_url() { |
|
| 2372 | 2372 | |
| 2373 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2374 | - $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2373 | + $course_page_id = intval(Sensei()->settings->settings['course_page']); |
|
| 2374 | + $course_page_url = empty($course_page_id) ? get_post_type_archive_link('course') : get_permalink($course_page_id); |
|
| 2375 | 2375 | |
| 2376 | 2376 | return $course_page_url; |
| 2377 | 2377 | |
@@ -2388,61 +2388,61 @@ discard block |
||
| 2388 | 2388 | * @param string $after_html |
| 2389 | 2389 | * @return void |
| 2390 | 2390 | */ |
| 2391 | - public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2391 | + public static function archive_header($query_type = '', $before_html = '', $after_html = '') { |
|
| 2392 | 2392 | |
| 2393 | - if( ! is_post_type_archive('course') ){ |
|
| 2393 | + if ( ! is_post_type_archive('course')) { |
|
| 2394 | 2394 | return; |
| 2395 | 2395 | } |
| 2396 | 2396 | |
| 2397 | 2397 | // deprecated since 1.9.0 |
| 2398 | - sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2398 | + sensei_do_deprecated_action('sensei_archive_title', '1.9.0', 'sensei_archive_before_course_loop'); |
|
| 2399 | 2399 | |
| 2400 | 2400 | $html = ''; |
| 2401 | 2401 | |
| 2402 | - if( empty( $before_html ) ){ |
|
| 2402 | + if (empty($before_html)) { |
|
| 2403 | 2403 | |
| 2404 | 2404 | $before_html = '<header class="archive-header"><h1>'; |
| 2405 | 2405 | |
| 2406 | 2406 | } |
| 2407 | 2407 | |
| 2408 | - if( empty( $after_html ) ){ |
|
| 2408 | + if (empty($after_html)) { |
|
| 2409 | 2409 | |
| 2410 | 2410 | $after_html = '</h1></header>'; |
| 2411 | 2411 | |
| 2412 | 2412 | } |
| 2413 | 2413 | |
| 2414 | - if ( is_tax( 'course-category' ) ) { |
|
| 2414 | + if (is_tax('course-category')) { |
|
| 2415 | 2415 | |
| 2416 | 2416 | global $wp_query; |
| 2417 | 2417 | |
| 2418 | 2418 | $taxonomy_obj = $wp_query->get_queried_object(); |
| 2419 | 2419 | $taxonomy_short_name = $taxonomy_obj->taxonomy; |
| 2420 | - $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2421 | - $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2422 | - echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2420 | + $taxonomy_raw_obj = get_taxonomy($taxonomy_short_name); |
|
| 2421 | + $title = sprintf(__('%1$s Archives: %2$s', 'woothemes-sensei'), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name); |
|
| 2422 | + echo apply_filters('course_category_archive_title', $before_html.$title.$after_html); |
|
| 2423 | 2423 | return; |
| 2424 | 2424 | |
| 2425 | 2425 | } // End If Statement |
| 2426 | 2426 | |
| 2427 | - switch ( $query_type ) { |
|
| 2427 | + switch ($query_type) { |
|
| 2428 | 2428 | case 'newcourses': |
| 2429 | - $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2429 | + $html .= $before_html.__('New Courses', 'woothemes-sensei').$after_html; |
|
| 2430 | 2430 | break; |
| 2431 | 2431 | case 'featuredcourses': |
| 2432 | - $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2432 | + $html .= $before_html.__('Featured Courses', 'woothemes-sensei').$after_html; |
|
| 2433 | 2433 | break; |
| 2434 | 2434 | case 'freecourses': |
| 2435 | - $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2435 | + $html .= $before_html.__('Free Courses', 'woothemes-sensei').$after_html; |
|
| 2436 | 2436 | break; |
| 2437 | 2437 | case 'paidcourses': |
| 2438 | - $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2438 | + $html .= $before_html.__('Paid Courses', 'woothemes-sensei').$after_html; |
|
| 2439 | 2439 | break; |
| 2440 | 2440 | default: |
| 2441 | - $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2441 | + $html .= $before_html.__('Courses', 'woothemes-sensei').$after_html; |
|
| 2442 | 2442 | break; |
| 2443 | 2443 | } // End Switch Statement |
| 2444 | 2444 | |
| 2445 | - echo apply_filters( 'course_archive_title', $html ); |
|
| 2445 | + echo apply_filters('course_archive_title', $html); |
|
| 2446 | 2446 | |
| 2447 | 2447 | }//course_archive_header |
| 2448 | 2448 | |
@@ -2456,9 +2456,9 @@ discard block |
||
| 2456 | 2456 | * @param string $content |
| 2457 | 2457 | * @return string $content or $excerpt |
| 2458 | 2458 | */ |
| 2459 | - public static function single_course_content( $content ){ |
|
| 2459 | + public static function single_course_content($content) { |
|
| 2460 | 2460 | |
| 2461 | - if( ! is_singular('course') ){ |
|
| 2461 | + if ( ! is_singular('course')) { |
|
| 2462 | 2462 | |
| 2463 | 2463 | return $content; |
| 2464 | 2464 | |
@@ -2467,21 +2467,21 @@ discard block |
||
| 2467 | 2467 | // Content Access Permissions |
| 2468 | 2468 | $access_permission = false; |
| 2469 | 2469 | |
| 2470 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2470 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access()) { |
|
| 2471 | 2471 | |
| 2472 | 2472 | $access_permission = true; |
| 2473 | 2473 | |
| 2474 | 2474 | } // End If Statement |
| 2475 | 2475 | |
| 2476 | 2476 | // Check if the user is taking the course |
| 2477 | - $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2477 | + $is_user_taking_course = Sensei_Utils::user_started_course(get_the_ID(), get_current_user_id()); |
|
| 2478 | 2478 | |
| 2479 | - if(Sensei_WC::is_woocommerce_active()) { |
|
| 2479 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 2480 | 2480 | |
| 2481 | - $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2482 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2481 | + $wc_post_id = get_post_meta(get_the_ID(), '_course_woocommerce_product', true); |
|
| 2482 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 2483 | 2483 | |
| 2484 | - $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2484 | + $has_product_attached = isset ($product) && is_object($product); |
|
| 2485 | 2485 | |
| 2486 | 2486 | } else { |
| 2487 | 2487 | |
@@ -2489,15 +2489,15 @@ discard block |
||
| 2489 | 2489 | |
| 2490 | 2490 | } |
| 2491 | 2491 | |
| 2492 | - if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2493 | - || ( $access_permission && !$has_product_attached) |
|
| 2494 | - || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2492 | + if ((is_user_logged_in() && $is_user_taking_course) |
|
| 2493 | + || ($access_permission && ! $has_product_attached) |
|
| 2494 | + || 'full' == Sensei()->settings->get('course_single_content_display')) { |
|
| 2495 | 2495 | |
| 2496 | 2496 | return $content; |
| 2497 | 2497 | |
| 2498 | 2498 | } else { |
| 2499 | 2499 | |
| 2500 | - return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2500 | + return '<p class="course-excerpt">'.get_post(get_the_ID())->post_excerpt.'</p>'; |
|
| 2501 | 2501 | |
| 2502 | 2502 | } |
| 2503 | 2503 | |
@@ -2508,14 +2508,14 @@ discard block |
||
| 2508 | 2508 | * |
| 2509 | 2509 | * @since 1.9.0 |
| 2510 | 2510 | */ |
| 2511 | - public static function the_course_lessons_title(){ |
|
| 2511 | + public static function the_course_lessons_title() { |
|
| 2512 | 2512 | global $post; |
| 2513 | - $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2514 | - $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2513 | + $none_module_lessons = Sensei()->modules->get_none_module_lessons($post->ID); |
|
| 2514 | + $course_lessons = Sensei()->course->course_lessons($post->ID); |
|
| 2515 | 2515 | |
| 2516 | 2516 | // title should be Other Lessons if there are lessons belonging to models. |
| 2517 | 2517 | $title = __('Other Lessons', 'woothemes-sensei'); |
| 2518 | - if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2518 | + if (count($course_lessons) == count($none_module_lessons)) { |
|
| 2519 | 2519 | |
| 2520 | 2520 | $title = __('Lessons', 'woothemes-sensei'); |
| 2521 | 2521 | |
@@ -2524,7 +2524,7 @@ discard block |
||
| 2524 | 2524 | /** |
| 2525 | 2525 | * hook document in class-woothemes-sensei-message.php |
| 2526 | 2526 | */ |
| 2527 | - $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2527 | + $title = apply_filters('sensei_single_title', $title, $post->post_type); |
|
| 2528 | 2528 | |
| 2529 | 2529 | ob_start(); // start capturing the following output. |
| 2530 | 2530 | |
@@ -2543,7 +2543,7 @@ discard block |
||
| 2543 | 2543 | * @since 1.9.0 |
| 2544 | 2544 | * @param string $lessons_title_html |
| 2545 | 2545 | */ |
| 2546 | - echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2546 | + echo apply_filters('the_course_lessons_title', ob_get_clean()); // output and filter the captured output and stop capturing. |
|
| 2547 | 2547 | |
| 2548 | 2548 | }// end the_course_lessons_title |
| 2549 | 2549 | |
@@ -2558,13 +2558,13 @@ discard block |
||
| 2558 | 2558 | * @since 1.9.0 |
| 2559 | 2559 | * @global $wp_query |
| 2560 | 2560 | */ |
| 2561 | - public static function load_single_course_lessons_query(){ |
|
| 2561 | + public static function load_single_course_lessons_query() { |
|
| 2562 | 2562 | |
| 2563 | 2563 | global $post, $wp_query; |
| 2564 | 2564 | |
| 2565 | 2565 | $course_id = $post->ID; |
| 2566 | 2566 | |
| 2567 | - if( 'course' != get_post_type( $course_id ) ){ |
|
| 2567 | + if ('course' != get_post_type($course_id)) { |
|
| 2568 | 2568 | return; |
| 2569 | 2569 | } |
| 2570 | 2570 | |
@@ -2576,7 +2576,7 @@ discard block |
||
| 2576 | 2576 | 'meta_query' => array( |
| 2577 | 2577 | array( |
| 2578 | 2578 | 'key' => '_lesson_course', |
| 2579 | - 'value' => intval( $course_id ), |
|
| 2579 | + 'value' => intval($course_id), |
|
| 2580 | 2580 | ), |
| 2581 | 2581 | ), |
| 2582 | 2582 | 'post_status' => 'public', |
@@ -2584,17 +2584,17 @@ discard block |
||
| 2584 | 2584 | ); |
| 2585 | 2585 | |
| 2586 | 2586 | // Exclude lessons belonging to modules as they are queried along with the modules. |
| 2587 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2588 | - if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2587 | + $modules = Sensei()->modules->get_course_modules($course_id); |
|
| 2588 | + if ( ! is_wp_error($modules) && ! empty($modules) && is_array($modules)) { |
|
| 2589 | 2589 | |
| 2590 | 2590 | $terms_ids = array(); |
| 2591 | - foreach( $modules as $term ){ |
|
| 2591 | + foreach ($modules as $term) { |
|
| 2592 | 2592 | |
| 2593 | 2593 | $terms_ids[] = $term->term_id; |
| 2594 | 2594 | |
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | - $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2597 | + $course_lesson_query_args['tax_query'] = array( |
|
| 2598 | 2598 | array( |
| 2599 | 2599 | 'taxonomy' => 'module', |
| 2600 | 2600 | 'field' => 'id', |
@@ -2604,7 +2604,7 @@ discard block |
||
| 2604 | 2604 | ); |
| 2605 | 2605 | } |
| 2606 | 2606 | |
| 2607 | - $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2607 | + $wp_query = new WP_Query($course_lesson_query_args); |
|
| 2608 | 2608 | |
| 2609 | 2609 | }// load_single_course_lessons |
| 2610 | 2610 | |
@@ -2615,16 +2615,16 @@ discard block |
||
| 2615 | 2615 | * |
| 2616 | 2616 | * @param $post_id |
| 2617 | 2617 | */ |
| 2618 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 2618 | + public static function flush_rewrite_rules($post_id) { |
|
| 2619 | 2619 | |
| 2620 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2620 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 2621 | 2621 | |
| 2622 | 2622 | return; |
| 2623 | 2623 | |
| 2624 | 2624 | } |
| 2625 | 2625 | |
| 2626 | 2626 | |
| 2627 | - if( 'course' == get_post_type( $post_id ) ){ |
|
| 2627 | + if ('course' == get_post_type($post_id)) { |
|
| 2628 | 2628 | |
| 2629 | 2629 | Sensei()->initiate_rewrite_rules_flush(); |
| 2630 | 2630 | |
@@ -2640,10 +2640,10 @@ discard block |
||
| 2640 | 2640 | * @param $excerpt |
| 2641 | 2641 | * @return string |
| 2642 | 2642 | */ |
| 2643 | - public static function full_content_excerpt_override( $excerpt ){ |
|
| 2643 | + public static function full_content_excerpt_override($excerpt) { |
|
| 2644 | 2644 | |
| 2645 | - if ( is_singular('course') && |
|
| 2646 | - 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2645 | + if (is_singular('course') && |
|
| 2646 | + 'full' == Sensei()->settings->get('course_single_content_display')) { |
|
| 2647 | 2647 | |
| 2648 | 2648 | return get_the_content(); |
| 2649 | 2649 | |
@@ -2660,60 +2660,60 @@ discard block |
||
| 2660 | 2660 | * |
| 2661 | 2661 | * @since 1.9.0 |
| 2662 | 2662 | */ |
| 2663 | - public static function the_course_enrolment_actions(){ |
|
| 2663 | + public static function the_course_enrolment_actions() { |
|
| 2664 | 2664 | ?> |
| 2665 | 2665 | <section class="course-meta course-enrolment"> |
| 2666 | 2666 | <?php |
| 2667 | 2667 | global $post, $current_user; |
| 2668 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2669 | - if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2668 | + $is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID); |
|
| 2669 | + if (is_user_logged_in() && ! $is_user_taking_course) { |
|
| 2670 | 2670 | |
| 2671 | 2671 | // Get the product ID |
| 2672 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2672 | + $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true)); |
|
| 2673 | 2673 | |
| 2674 | 2674 | // Check for woocommerce |
| 2675 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2675 | + if (Sensei_WC::is_woocommerce_active() && (0 < intval($wc_post_id))) { |
|
| 2676 | 2676 | sensei_wc_add_to_cart($post->ID); |
| 2677 | 2677 | } else { |
| 2678 | 2678 | sensei_start_course_form($post->ID); |
| 2679 | 2679 | } // End If Statement |
| 2680 | 2680 | |
| 2681 | - } elseif ( is_user_logged_in() ) { |
|
| 2681 | + } elseif (is_user_logged_in()) { |
|
| 2682 | 2682 | |
| 2683 | 2683 | // Check if course is completed |
| 2684 | - $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2685 | - $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2684 | + $user_course_status = Sensei_Utils::user_course_status($post->ID, $current_user->ID); |
|
| 2685 | + $completed_course = Sensei_Utils::user_completed_course($user_course_status); |
|
| 2686 | 2686 | // Success message |
| 2687 | - if ( $completed_course ) { ?> |
|
| 2688 | - <div class="status completed"><?php _e( 'Completed', 'woothemes-sensei' ); ?></div> |
|
| 2687 | + if ($completed_course) { ?> |
|
| 2688 | + <div class="status completed"><?php _e('Completed', 'woothemes-sensei'); ?></div> |
|
| 2689 | 2689 | <?php |
| 2690 | - $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2691 | - if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2690 | + $has_quizzes = Sensei()->course->course_quizzes($post->ID, true); |
|
| 2691 | + if (has_filter('sensei_results_links') || $has_quizzes) { ?> |
|
| 2692 | 2692 | <p class="sensei-results-links"> |
| 2693 | 2693 | <?php |
| 2694 | 2694 | $results_link = ''; |
| 2695 | - if( $has_quizzes ) { |
|
| 2696 | - $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2695 | + if ($has_quizzes) { |
|
| 2696 | + $results_link = '<a class="view-results" href="'.Sensei()->course_results->get_permalink($post->ID).'">'.__('View results', 'woothemes-sensei').'</a>'; |
|
| 2697 | 2697 | } |
| 2698 | - $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2698 | + $results_link = apply_filters('sensei_results_links', $results_link); |
|
| 2699 | 2699 | echo $results_link; |
| 2700 | 2700 | ?></p> |
| 2701 | 2701 | <?php } ?> |
| 2702 | 2702 | <?php } else { ?> |
| 2703 | - <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div> |
|
| 2703 | + <div class="status in-progress"><?php echo __('In Progress', 'woothemes-sensei'); ?></div> |
|
| 2704 | 2704 | <?php } |
| 2705 | 2705 | |
| 2706 | 2706 | } else { |
| 2707 | 2707 | // Get the product ID |
| 2708 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2708 | + $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true)); |
|
| 2709 | 2709 | // Check for woocommerce |
| 2710 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2710 | + if (Sensei_WC::is_woocommerce_active() && (0 < intval($wc_post_id))) { |
|
| 2711 | 2711 | |
| 2712 | 2712 | sensei_wc_add_to_cart($post->ID); |
| 2713 | 2713 | |
| 2714 | 2714 | } else { |
| 2715 | 2715 | |
| 2716 | - if( get_option( 'users_can_register') ) { |
|
| 2716 | + if (get_option('users_can_register')) { |
|
| 2717 | 2717 | |
| 2718 | 2718 | |
| 2719 | 2719 | $my_courses_page_id = ''; |
@@ -2729,24 +2729,24 @@ discard block |
||
| 2729 | 2729 | $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
| 2730 | 2730 | |
| 2731 | 2731 | $settings = Sensei()->settings->get_settings(); |
| 2732 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 2733 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2732 | + if (isset($settings['my_course_page']) |
|
| 2733 | + && 0 < intval($settings['my_course_page'])) { |
|
| 2734 | 2734 | |
| 2735 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2735 | + $my_courses_page_id = $settings['my_course_page']; |
|
| 2736 | 2736 | |
| 2737 | 2737 | } |
| 2738 | 2738 | |
| 2739 | 2739 | // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
| 2740 | 2740 | // is false, link to My Courses. If not, link to default WordPress registration page. |
| 2741 | - if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2741 | + if ( ! empty($my_courses_page_id) && $my_courses_page_id && ! $wp_register_link) { |
|
| 2742 | 2742 | |
| 2743 | - $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2744 | - $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2745 | - echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2743 | + $my_courses_url = get_permalink($my_courses_page_id); |
|
| 2744 | + $register_link = '<a href="'.$my_courses_url.'">'.__('Register', 'woothemes-sensei').'</a>'; |
|
| 2745 | + echo '<div class="status register">'.$register_link.'</div>'; |
|
| 2746 | 2746 | |
| 2747 | - } else{ |
|
| 2747 | + } else { |
|
| 2748 | 2748 | |
| 2749 | - wp_register( '<div class="status register">', '</div>' ); |
|
| 2749 | + wp_register('<div class="status register">', '</div>'); |
|
| 2750 | 2750 | |
| 2751 | 2751 | } |
| 2752 | 2752 | |
@@ -2765,19 +2765,19 @@ discard block |
||
| 2765 | 2765 | * |
| 2766 | 2766 | * @since 1.9.0 |
| 2767 | 2767 | */ |
| 2768 | - public static function the_course_video(){ |
|
| 2768 | + public static function the_course_video() { |
|
| 2769 | 2769 | |
| 2770 | 2770 | global $post; |
| 2771 | 2771 | // Get the meta info |
| 2772 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2772 | + $course_video_embed = get_post_meta($post->ID, '_course_video_embed', true); |
|
| 2773 | 2773 | |
| 2774 | - if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2774 | + if ('http' == substr($course_video_embed, 0, 4)) { |
|
| 2775 | 2775 | |
| 2776 | - $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2776 | + $course_video_embed = wp_oembed_get(esc_url($course_video_embed)); |
|
| 2777 | 2777 | |
| 2778 | 2778 | } // End If Statement |
| 2779 | 2779 | |
| 2780 | - if ( '' != $course_video_embed ) { ?> |
|
| 2780 | + if ('' != $course_video_embed) { ?> |
|
| 2781 | 2781 | |
| 2782 | 2782 | <div class="course-video"> |
| 2783 | 2783 | <?php echo html_entity_decode($course_video_embed); ?> |
@@ -2792,7 +2792,7 @@ discard block |
||
| 2792 | 2792 | * @global $post |
| 2793 | 2793 | * @since 1.9.0 |
| 2794 | 2794 | */ |
| 2795 | - public static function the_title(){ |
|
| 2795 | + public static function the_title() { |
|
| 2796 | 2796 | |
| 2797 | 2797 | global $post; |
| 2798 | 2798 | |
@@ -2805,7 +2805,7 @@ discard block |
||
| 2805 | 2805 | /** |
| 2806 | 2806 | * Filter documented in class-sensei-messages.php the_title |
| 2807 | 2807 | */ |
| 2808 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2808 | + echo apply_filters('sensei_single_title', get_the_title($post), $post->post_type); |
|
| 2809 | 2809 | ?> |
| 2810 | 2810 | |
| 2811 | 2811 | </h1> |
@@ -2821,30 +2821,30 @@ discard block |
||
| 2821 | 2821 | * |
| 2822 | 2822 | * @since 1.9.0 |
| 2823 | 2823 | */ |
| 2824 | - public static function course_category_title(){ |
|
| 2824 | + public static function course_category_title() { |
|
| 2825 | 2825 | |
| 2826 | - if( ! is_tax( 'course-category' ) ){ |
|
| 2826 | + if ( ! is_tax('course-category')) { |
|
| 2827 | 2827 | return; |
| 2828 | 2828 | } |
| 2829 | 2829 | |
| 2830 | 2830 | $category_slug = get_query_var('course-category'); |
| 2831 | - $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2831 | + $term = get_term_by('slug', $category_slug, 'course-category'); |
|
| 2832 | 2832 | |
| 2833 | - if( ! empty($term) ){ |
|
| 2833 | + if ( ! empty($term)) { |
|
| 2834 | 2834 | |
| 2835 | 2835 | $title = $term->name; |
| 2836 | 2836 | |
| 2837 | - }else{ |
|
| 2837 | + } else { |
|
| 2838 | 2838 | |
| 2839 | 2839 | $title = 'Course Category'; |
| 2840 | 2840 | |
| 2841 | 2841 | } |
| 2842 | 2842 | |
| 2843 | 2843 | $html = '<h2 class="sensei-category-title">'; |
| 2844 | - $html .= __('Category') . ' ' . $title; |
|
| 2844 | + $html .= __('Category').' '.$title; |
|
| 2845 | 2845 | $html .= '</h2>'; |
| 2846 | 2846 | |
| 2847 | - echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2847 | + echo apply_filters('course_category_title', $html, $term->term_id); |
|
| 2848 | 2848 | |
| 2849 | 2849 | }// course_category_title |
| 2850 | 2850 | |
@@ -2857,16 +2857,16 @@ discard block |
||
| 2857 | 2857 | * @param WP_Query $query |
| 2858 | 2858 | * @return WP_Query |
| 2859 | 2859 | */ |
| 2860 | - public static function alter_course_category_order( $query ){ |
|
| 2860 | + public static function alter_course_category_order($query) { |
|
| 2861 | 2861 | |
| 2862 | - if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2862 | + if ( ! is_tax('course-category') || ! $query->is_main_query()) { |
|
| 2863 | 2863 | return $query; |
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | - $order = get_option( 'sensei_course_order', '' ); |
|
| 2867 | - if( !empty( $order ) ){ |
|
| 2868 | - $query->set('orderby', 'menu_order' ); |
|
| 2869 | - $query->set('order', 'ASC' ); |
|
| 2866 | + $order = get_option('sensei_course_order', ''); |
|
| 2867 | + if ( ! empty($order)) { |
|
| 2868 | + $query->set('orderby', 'menu_order'); |
|
| 2869 | + $query->set('order', 'ASC'); |
|
| 2870 | 2870 | } |
| 2871 | 2871 | |
| 2872 | 2872 | return $query; |
@@ -2887,7 +2887,7 @@ discard block |
||
| 2887 | 2887 | * |
| 2888 | 2888 | * @return array |
| 2889 | 2889 | */ |
| 2890 | - public static function get_default_query_args(){ |
|
| 2890 | + public static function get_default_query_args() { |
|
| 2891 | 2891 | return array( |
| 2892 | 2892 | 'post_type' => 'course', |
| 2893 | 2893 | 'posts_per_page' => 1000, |
@@ -2905,14 +2905,14 @@ discard block |
||
| 2905 | 2905 | * @param $course_id |
| 2906 | 2906 | * @return bool |
| 2907 | 2907 | */ |
| 2908 | - public static function is_prerequisite_complete( $course_id ){ |
|
| 2908 | + public static function is_prerequisite_complete($course_id) { |
|
| 2909 | 2909 | |
| 2910 | - $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2910 | + $course_prerequisite_id = get_post_meta($course_id, '_course_prerequisite', true); |
|
| 2911 | 2911 | |
| 2912 | 2912 | // if it has a pre requisite course check it |
| 2913 | - if( ! empty( $course_prerequisite_id ) ){ |
|
| 2913 | + if ( ! empty($course_prerequisite_id)) { |
|
| 2914 | 2914 | |
| 2915 | - return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2915 | + return Sensei_Utils::user_completed_course($course_prerequisite_id, get_current_user_id()); |
|
| 2916 | 2916 | |
| 2917 | 2917 | } |
| 2918 | 2918 | |
@@ -2928,4 +2928,4 @@ discard block |
||
| 2928 | 2928 | * for backward compatibility |
| 2929 | 2929 | * @since 1.9.0 |
| 2930 | 2930 | */ |
| 2931 | -class WooThemes_Sensei_Course extends Sensei_Course{} |
|
| 2931 | +class WooThemes_Sensei_Course extends Sensei_Course {} |
|
@@ -12,735 +12,735 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | Class Sensei_WC{ |
| 15 | - /** |
|
| 16 | - * Load the files needed for the woocommerce integration. |
|
| 17 | - * |
|
| 18 | - * @since 1.9.0 |
|
| 19 | - */ |
|
| 20 | - public static function load_woocommerce_integration_hooks(){ |
|
| 15 | + /** |
|
| 16 | + * Load the files needed for the woocommerce integration. |
|
| 17 | + * |
|
| 18 | + * @since 1.9.0 |
|
| 19 | + */ |
|
| 20 | + public static function load_woocommerce_integration_hooks(){ |
|
| 21 | 21 | |
| 22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 22 | + require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 23 | 23 | |
| 24 | - } |
|
| 25 | - /** |
|
| 26 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | - * |
|
| 28 | - * @since 1.9.0 |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public static function is_woocommerce_active(){ |
|
| 24 | + } |
|
| 25 | + /** |
|
| 26 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | + * |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public static function is_woocommerce_active(){ |
|
| 32 | 32 | |
| 33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 33 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 35 | 35 | |
| 36 | - } // end is_woocommerce_active |
|
| 36 | + } // end is_woocommerce_active |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | - * |
|
| 41 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | - * |
|
| 44 | - * @since 1.9.0 |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public static function is_woocommerce_present(){ |
|
| 38 | + /** |
|
| 39 | + * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | + * |
|
| 41 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | + * |
|
| 44 | + * @since 1.9.0 |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public static function is_woocommerce_present(){ |
|
| 49 | 49 | |
| 50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 50 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 51 | 51 | |
| 52 | - if ( is_multisite() ){ |
|
| 52 | + if ( is_multisite() ){ |
|
| 53 | 53 | |
| 54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 54 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 58 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 59 | 59 | |
| 60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 60 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 61 | 61 | |
| 62 | - }// end is_woocommerce_present |
|
| 62 | + }// end is_woocommerce_present |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | - * |
|
| 67 | - * If multiple exist we will return the latest order. |
|
| 68 | - * |
|
| 69 | - * @param $user_id |
|
| 70 | - * @param $course_id |
|
| 71 | - * @return array $user_course_orders |
|
| 72 | - */ |
|
| 73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 64 | + /** |
|
| 65 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | + * |
|
| 67 | + * If multiple exist we will return the latest order. |
|
| 68 | + * |
|
| 69 | + * @param $user_id |
|
| 70 | + * @param $course_id |
|
| 71 | + * @return array $user_course_orders |
|
| 72 | + */ |
|
| 73 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 74 | 74 | |
| 75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 75 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 76 | 76 | |
| 77 | - $orders_query = new WP_Query( array( |
|
| 78 | - 'post_type' => 'shop_order', |
|
| 79 | - 'posts_per_page' => -1, |
|
| 80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | - 'meta_key'=> '_customer_user', |
|
| 82 | - 'meta_value'=> $user_id, |
|
| 83 | - ) ); |
|
| 77 | + $orders_query = new WP_Query( array( |
|
| 78 | + 'post_type' => 'shop_order', |
|
| 79 | + 'posts_per_page' => -1, |
|
| 80 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | + 'meta_key'=> '_customer_user', |
|
| 82 | + 'meta_value'=> $user_id, |
|
| 83 | + ) ); |
|
| 84 | 84 | |
| 85 | - if( $orders_query->post_count == 0 ){ |
|
| 85 | + if( $orders_query->post_count == 0 ){ |
|
| 86 | 86 | |
| 87 | - return false; |
|
| 87 | + return false; |
|
| 88 | 88 | |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 91 | + foreach( $orders_query->get_posts() as $order ){ |
|
| 92 | 92 | |
| 93 | - $order = new WC_Order( $order->ID ); |
|
| 94 | - $items = $order->get_items(); |
|
| 93 | + $order = new WC_Order( $order->ID ); |
|
| 94 | + $items = $order->get_items(); |
|
| 95 | 95 | |
| 96 | - $user_orders = array(); |
|
| 96 | + $user_orders = array(); |
|
| 97 | 97 | |
| 98 | - foreach( $items as $item ){ |
|
| 98 | + foreach( $items as $item ){ |
|
| 99 | 99 | |
| 100 | - // if the product id on the order and the one given to this function |
|
| 101 | - // this order has been placed by the given user on the given course. |
|
| 102 | - $product = wc_get_product( $item['product_id'] ); |
|
| 100 | + // if the product id on the order and the one given to this function |
|
| 101 | + // this order has been placed by the given user on the given course. |
|
| 102 | + $product = wc_get_product( $item['product_id'] ); |
|
| 103 | 103 | |
| 104 | - if ( $product->is_type( 'variable' )) { |
|
| 104 | + if ( $product->is_type( 'variable' )) { |
|
| 105 | 105 | |
| 106 | - $item_product_id = $item['variation_id']; |
|
| 106 | + $item_product_id = $item['variation_id']; |
|
| 107 | 107 | |
| 108 | - } else { |
|
| 108 | + } else { |
|
| 109 | 109 | |
| 110 | - $item_product_id = $item['product_id']; |
|
| 110 | + $item_product_id = $item['product_id']; |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if( $course_product_id == $item_product_id ){ |
|
| 114 | + if( $course_product_id == $item_product_id ){ |
|
| 115 | 115 | |
| 116 | - return $order->id; |
|
| 116 | + return $order->id; |
|
| 117 | 117 | |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - }//end for each order item |
|
| 121 | + }//end for each order item |
|
| 122 | 122 | |
| 123 | - } // end for each order |
|
| 123 | + } // end for each order |
|
| 124 | 124 | |
| 125 | - // if we reach this place we found no order |
|
| 126 | - return false; |
|
| 125 | + // if we reach this place we found no order |
|
| 126 | + return false; |
|
| 127 | 127 | |
| 128 | - } // end get_learner_course_active_order_ids |
|
| 128 | + } // end get_learner_course_active_order_ids |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Output WooCommerce specific course filters |
|
| 132 | - * Removing the paged argument |
|
| 133 | - * |
|
| 134 | - * @since 1.9.0 |
|
| 135 | - * @param $filter_links |
|
| 136 | - * @return mixed |
|
| 137 | - */ |
|
| 138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 130 | + /** |
|
| 131 | + * Output WooCommerce specific course filters |
|
| 132 | + * Removing the paged argument |
|
| 133 | + * |
|
| 134 | + * @since 1.9.0 |
|
| 135 | + * @param $filter_links |
|
| 136 | + * @return mixed |
|
| 137 | + */ |
|
| 138 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 139 | 139 | |
| 140 | - $free_courses = self::get_free_courses(); |
|
| 141 | - $paid_courses = self::get_paid_courses(); |
|
| 140 | + $free_courses = self::get_free_courses(); |
|
| 141 | + $paid_courses = self::get_paid_courses(); |
|
| 142 | 142 | |
| 143 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 144 | - // do not show any WooCommerce filters if all courses are |
|
| 145 | - // free or if all courses are paid |
|
| 146 | - return $filter_links; |
|
| 143 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 144 | + // do not show any WooCommerce filters if all courses are |
|
| 145 | + // free or if all courses are paid |
|
| 146 | + return $filter_links; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - $filter_links[] = array( |
|
| 151 | - 'id'=>'paid' , |
|
| 152 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | - ); |
|
| 150 | + $filter_links[] = array( |
|
| 151 | + 'id'=>'paid' , |
|
| 152 | + 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | - $filter_links[] = array( |
|
| 157 | - 'id'=>'free', |
|
| 158 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | - ); |
|
| 156 | + $filter_links[] = array( |
|
| 157 | + 'id'=>'free', |
|
| 158 | + 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | + ); |
|
| 161 | 161 | |
| 162 | - return $filter_links; |
|
| 162 | + return $filter_links; |
|
| 163 | 163 | |
| 164 | - }// end add_course_archive_wc_filter_links |
|
| 164 | + }// end add_course_archive_wc_filter_links |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Apply the free filter the the course query |
|
| 168 | - * getting all course with no products or products with zero price |
|
| 169 | - * |
|
| 170 | - * hooked into pre_get_posts |
|
| 171 | - * |
|
| 172 | - * @since 1.9.0 |
|
| 173 | - * @param WP_Query $query |
|
| 174 | - * @return WP_Query $query |
|
| 175 | - */ |
|
| 176 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 166 | + /** |
|
| 167 | + * Apply the free filter the the course query |
|
| 168 | + * getting all course with no products or products with zero price |
|
| 169 | + * |
|
| 170 | + * hooked into pre_get_posts |
|
| 171 | + * |
|
| 172 | + * @since 1.9.0 |
|
| 173 | + * @param WP_Query $query |
|
| 174 | + * @return WP_Query $query |
|
| 175 | + */ |
|
| 176 | + public static function course_archive_wc_filter_free( $query ){ |
|
| 177 | 177 | |
| 178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 178 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 180 | 180 | |
| 181 | - // setup the course meta query |
|
| 182 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
| 181 | + // setup the course meta query |
|
| 182 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
| 183 | 183 | |
| 184 | - // manipulate the query to return free courses |
|
| 185 | - $query->set('meta_query', $meta_query ); |
|
| 184 | + // manipulate the query to return free courses |
|
| 185 | + $query->set('meta_query', $meta_query ); |
|
| 186 | 186 | |
| 187 | - // don't show any paid courses |
|
| 188 | - $courses = self::get_paid_courses(); |
|
| 189 | - $ids = array(); |
|
| 190 | - foreach( $courses as $course ){ |
|
| 191 | - $ids[] = $course->ID; |
|
| 192 | - } |
|
| 193 | - $query->set( 'post__not_in', $ids ); |
|
| 187 | + // don't show any paid courses |
|
| 188 | + $courses = self::get_paid_courses(); |
|
| 189 | + $ids = array(); |
|
| 190 | + foreach( $courses as $course ){ |
|
| 191 | + $ids[] = $course->ID; |
|
| 192 | + } |
|
| 193 | + $query->set( 'post__not_in', $ids ); |
|
| 194 | 194 | |
| 195 | - }// end if course_filter |
|
| 195 | + }// end if course_filter |
|
| 196 | 196 | |
| 197 | - return $query; |
|
| 197 | + return $query; |
|
| 198 | 198 | |
| 199 | - }// course_archive_wc_filter_free |
|
| 199 | + }// course_archive_wc_filter_free |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Apply the paid filter to the course query on the courses page |
|
| 203 | - * will include all course with a product attached with a price |
|
| 204 | - * more than 0 |
|
| 205 | - * |
|
| 206 | - * hooked into pre_get_posts |
|
| 207 | - * |
|
| 208 | - * @since 1.9.0 |
|
| 209 | - * @param WP_Query $query |
|
| 210 | - * @return WP_Query $query |
|
| 211 | - */ |
|
| 212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 201 | + /** |
|
| 202 | + * Apply the paid filter to the course query on the courses page |
|
| 203 | + * will include all course with a product attached with a price |
|
| 204 | + * more than 0 |
|
| 205 | + * |
|
| 206 | + * hooked into pre_get_posts |
|
| 207 | + * |
|
| 208 | + * @since 1.9.0 |
|
| 209 | + * @param WP_Query $query |
|
| 210 | + * @return WP_Query $query |
|
| 211 | + */ |
|
| 212 | + public static function course_archive_wc_filter_paid( $query ){ |
|
| 213 | 213 | |
| 214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | - |
|
| 217 | - // setup the course meta query |
|
| 218 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | - |
|
| 220 | - // manipulate the query to return free courses |
|
| 221 | - $query->set('meta_query', $meta_query ); |
|
| 222 | - |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $query; |
|
| 226 | - |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Load the WooCommerce single product actions above |
|
| 231 | - * single courses if woocommerce is active allowing purchase |
|
| 232 | - * information and actions to be hooked from WooCommerce. |
|
| 233 | - */ |
|
| 234 | - public static function do_single_course_wc_single_product_action(){ |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * this hooks is documented within the WooCommerce plugin. |
|
| 238 | - */ |
|
| 239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | - |
|
| 241 | - do_action( 'woocommerce_before_single_product' ); |
|
| 242 | - |
|
| 243 | - } // End If Statement |
|
| 244 | - |
|
| 245 | - }// end do_single_course_wc_single_product_action |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Hooking into the single lesson page to alter the |
|
| 249 | - * user access permissions based on if they have purchased the |
|
| 250 | - * course the lesson belongs to. |
|
| 251 | - * |
|
| 252 | - * This function will only return false or the passed in user_access value. |
|
| 253 | - * It doesn't return true in order to avoid altering other options. |
|
| 254 | - * |
|
| 255 | - * @since 1.9.0 |
|
| 256 | - * |
|
| 257 | - * @param $can_user_view_lesson |
|
| 258 | - * @param $lesson_id |
|
| 259 | - * @param $user_id |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | - |
|
| 264 | - // check if the course has a valid product attached to it |
|
| 265 | - // which the user should have purchased if they want to access |
|
| 266 | - // the current lesson |
|
| 267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | - if( isset ($product) && is_object($product) ){ |
|
| 271 | - |
|
| 272 | - // valid product found |
|
| 273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | - |
|
| 275 | - // product has a successful order so this user may access the content |
|
| 276 | - // this function may only return false or the default |
|
| 277 | - // returning true may override other negatives which we don't want |
|
| 278 | - if( ! $order_id ){ |
|
| 279 | - |
|
| 280 | - return false; |
|
| 281 | - |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // return the passed in value |
|
| 287 | - return $can_user_view_lesson; |
|
| 288 | - |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Add course link to order thank you and details pages. |
|
| 293 | - * |
|
| 294 | - * @since 1.4.5 |
|
| 295 | - * @access public |
|
| 296 | - * |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function course_link_from_order( ) { |
|
| 300 | - |
|
| 301 | - if( ! is_order_received_page() ){ |
|
| 302 | - return; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $order_id = get_query_var( 'order-received' ); |
|
| 214 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | + |
|
| 217 | + // setup the course meta query |
|
| 218 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | + |
|
| 220 | + // manipulate the query to return free courses |
|
| 221 | + $query->set('meta_query', $meta_query ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $query; |
|
| 226 | + |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Load the WooCommerce single product actions above |
|
| 231 | + * single courses if woocommerce is active allowing purchase |
|
| 232 | + * information and actions to be hooked from WooCommerce. |
|
| 233 | + */ |
|
| 234 | + public static function do_single_course_wc_single_product_action(){ |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * this hooks is documented within the WooCommerce plugin. |
|
| 238 | + */ |
|
| 239 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | + |
|
| 241 | + do_action( 'woocommerce_before_single_product' ); |
|
| 242 | + |
|
| 243 | + } // End If Statement |
|
| 244 | + |
|
| 245 | + }// end do_single_course_wc_single_product_action |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Hooking into the single lesson page to alter the |
|
| 249 | + * user access permissions based on if they have purchased the |
|
| 250 | + * course the lesson belongs to. |
|
| 251 | + * |
|
| 252 | + * This function will only return false or the passed in user_access value. |
|
| 253 | + * It doesn't return true in order to avoid altering other options. |
|
| 254 | + * |
|
| 255 | + * @since 1.9.0 |
|
| 256 | + * |
|
| 257 | + * @param $can_user_view_lesson |
|
| 258 | + * @param $lesson_id |
|
| 259 | + * @param $user_id |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | + |
|
| 264 | + // check if the course has a valid product attached to it |
|
| 265 | + // which the user should have purchased if they want to access |
|
| 266 | + // the current lesson |
|
| 267 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | + if( isset ($product) && is_object($product) ){ |
|
| 271 | + |
|
| 272 | + // valid product found |
|
| 273 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | + |
|
| 275 | + // product has a successful order so this user may access the content |
|
| 276 | + // this function may only return false or the default |
|
| 277 | + // returning true may override other negatives which we don't want |
|
| 278 | + if( ! $order_id ){ |
|
| 279 | + |
|
| 280 | + return false; |
|
| 281 | + |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // return the passed in value |
|
| 287 | + return $can_user_view_lesson; |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Add course link to order thank you and details pages. |
|
| 293 | + * |
|
| 294 | + * @since 1.4.5 |
|
| 295 | + * @access public |
|
| 296 | + * |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function course_link_from_order( ) { |
|
| 300 | + |
|
| 301 | + if( ! is_order_received_page() ){ |
|
| 302 | + return; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $order_id = get_query_var( 'order-received' ); |
|
| 306 | 306 | $order = new WC_Order( $order_id ); |
| 307 | 307 | |
| 308 | 308 | // exit early if not wc-completed or wc-processing |
| 309 | 309 | if( 'wc-completed' != $order->post_status |
| 310 | - && 'wc-processing' != $order->post_status ) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 310 | + && 'wc-processing' != $order->post_status ) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $course_links = array(); // store the for links for courses purchased |
|
| 314 | + $course_links = array(); // store the for links for courses purchased |
|
| 315 | 315 | foreach ( $order->get_items() as $item ) { |
| 316 | 316 | |
| 317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 317 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 318 | 318 | |
| 319 | - // If item has variation_id then its a variation of the product |
|
| 320 | - $item_id = $item['variation_id']; |
|
| 319 | + // If item has variation_id then its a variation of the product |
|
| 320 | + $item_id = $item['variation_id']; |
|
| 321 | 321 | |
| 322 | - } else { |
|
| 322 | + } else { |
|
| 323 | 323 | |
| 324 | - //If not its real product set its id to item_id |
|
| 325 | - $item_id = $item['product_id']; |
|
| 324 | + //If not its real product set its id to item_id |
|
| 325 | + $item_id = $item['product_id']; |
|
| 326 | 326 | |
| 327 | - } // End If Statement |
|
| 327 | + } // End If Statement |
|
| 328 | 328 | |
| 329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 329 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 330 | 330 | |
| 331 | - if( $user_id ) { |
|
| 331 | + if( $user_id ) { |
|
| 332 | 332 | |
| 333 | - // Get all courses for product |
|
| 334 | - $args = Sensei_Course::get_default_query_args(); |
|
| 335 | - $args['meta_query'] = array( array( |
|
| 336 | - 'key' => '_course_woocommerce_product', |
|
| 337 | - 'value' => $item_id |
|
| 338 | - ) ); |
|
| 339 | - $args['orderby'] = 'menu_order date'; |
|
| 340 | - $args['order'] = 'ASC'; |
|
| 333 | + // Get all courses for product |
|
| 334 | + $args = Sensei_Course::get_default_query_args(); |
|
| 335 | + $args['meta_query'] = array( array( |
|
| 336 | + 'key' => '_course_woocommerce_product', |
|
| 337 | + 'value' => $item_id |
|
| 338 | + ) ); |
|
| 339 | + $args['orderby'] = 'menu_order date'; |
|
| 340 | + $args['order'] = 'ASC'; |
|
| 341 | 341 | |
| 342 | - // loop through courses |
|
| 343 | - $courses = get_posts( $args ); |
|
| 344 | - if( $courses && count( $courses ) > 0 ) { |
|
| 342 | + // loop through courses |
|
| 343 | + $courses = get_posts( $args ); |
|
| 344 | + if( $courses && count( $courses ) > 0 ) { |
|
| 345 | 345 | |
| 346 | - foreach( $courses as $course ) { |
|
| 346 | + foreach( $courses as $course ) { |
|
| 347 | 347 | |
| 348 | - $title = $course->post_title; |
|
| 349 | - $permalink = get_permalink( $course->ID ); |
|
| 350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 348 | + $title = $course->post_title; |
|
| 349 | + $permalink = get_permalink( $course->ID ); |
|
| 350 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 351 | 351 | |
| 352 | - } // end for each |
|
| 352 | + } // end for each |
|
| 353 | 353 | |
| 354 | - // close the message div |
|
| 354 | + // close the message div |
|
| 355 | 355 | |
| 356 | - }// end if $courses check |
|
| 357 | - } |
|
| 358 | - }// end loop through orders |
|
| 356 | + }// end if $courses check |
|
| 357 | + } |
|
| 358 | + }// end loop through orders |
|
| 359 | 359 | |
| 360 | - // add the courses to the WooCommerce notice |
|
| 361 | - if( ! empty( $course_links) ){ |
|
| 360 | + // add the courses to the WooCommerce notice |
|
| 361 | + if( ! empty( $course_links) ){ |
|
| 362 | 362 | |
| 363 | - $courses_html = _nx( |
|
| 364 | - 'You have purchased the following course:', |
|
| 365 | - 'You have purchased the following courses:', |
|
| 366 | - count( $course_links ), |
|
| 367 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | - ); |
|
| 363 | + $courses_html = _nx( |
|
| 364 | + 'You have purchased the following course:', |
|
| 365 | + 'You have purchased the following courses:', |
|
| 366 | + count( $course_links ), |
|
| 367 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | + ); |
|
| 369 | 369 | |
| 370 | - foreach( $course_links as $link ){ |
|
| 370 | + foreach( $course_links as $link ){ |
|
| 371 | 371 | |
| 372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 372 | + $courses_html .= '<li>' . $link . '</li>'; |
|
| 373 | 373 | |
| 374 | - } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $courses_html .= ' </ul>'; |
|
| 376 | + $courses_html .= ' </ul>'; |
|
| 377 | 377 | |
| 378 | - wc_add_notice( $courses_html, 'success' ); |
|
| 379 | - } |
|
| 378 | + wc_add_notice( $courses_html, 'success' ); |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | } // end course_link_order_form |
| 382 | 382 | |
| 383 | - /** |
|
| 384 | - * Show the message that a user should complete |
|
| 385 | - * their purchase if the course is in the cart |
|
| 386 | - * |
|
| 387 | - * This should be used within the course loop or single course page |
|
| 388 | - * |
|
| 389 | - * @since 1.9.0 |
|
| 390 | - */ |
|
| 391 | - public static function course_in_cart_message(){ |
|
| 383 | + /** |
|
| 384 | + * Show the message that a user should complete |
|
| 385 | + * their purchase if the course is in the cart |
|
| 386 | + * |
|
| 387 | + * This should be used within the course loop or single course page |
|
| 388 | + * |
|
| 389 | + * @since 1.9.0 |
|
| 390 | + */ |
|
| 391 | + public static function course_in_cart_message(){ |
|
| 392 | 392 | |
| 393 | - global $post; |
|
| 393 | + global $post; |
|
| 394 | 394 | |
| 395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 395 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 396 | 396 | |
| 397 | 397 | <div class="sensei-message info">' |
| 398 | 398 | <?php |
| 399 | 399 | |
| 400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 400 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 403 | 403 | |
| 404 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 404 | + sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 405 | 405 | |
| 406 | - ?> |
|
| 406 | + ?> |
|
| 407 | 407 | </div> |
| 408 | 408 | <?php } |
| 409 | 409 | |
| 410 | - } // End sensei_woocommerce_in_cart_message() |
|
| 410 | + } // End sensei_woocommerce_in_cart_message() |
|
| 411 | 411 | |
| 412 | - /** |
|
| 413 | - * Checks the cart to see if a course is in the cart. |
|
| 414 | - * |
|
| 415 | - * @param $course_id |
|
| 416 | - * @return bool |
|
| 417 | - */ |
|
| 418 | - public static function is_course_in_cart( $course_id ){ |
|
| 419 | - |
|
| 420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | - |
|
| 423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | - |
|
| 425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | - |
|
| 427 | - return true; |
|
| 428 | - |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return false; |
|
| 434 | - |
|
| 435 | - }// is_course_in_cart |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Check the cart to see if the product is in the cart |
|
| 439 | - * |
|
| 440 | - * @param $product_id |
|
| 441 | - * @return bool |
|
| 442 | - */ |
|
| 443 | - public static function is_product_in_cart( $product_id ){ |
|
| 444 | - |
|
| 445 | - if ( 0 < $product_id ) { |
|
| 446 | - |
|
| 447 | - $product = wc_get_product( $product_id ); |
|
| 448 | - |
|
| 449 | - $parent_id = ''; |
|
| 450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | - $wc_product_id = $product->parent->id; |
|
| 452 | - } |
|
| 453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | - |
|
| 455 | - $cart_product = $values['data']; |
|
| 456 | - if( $product_id == $cart_product->id ) { |
|
| 457 | - |
|
| 458 | - return true; |
|
| 459 | - |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - } |
|
| 463 | - } // End If Statement |
|
| 464 | - |
|
| 465 | - return false; |
|
| 466 | - |
|
| 467 | - } // end is_product_in_car |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Get all free WooCommerce products |
|
| 471 | - * |
|
| 472 | - * @since 1.9.0 |
|
| 473 | - * |
|
| 474 | - * @return array $free_products{ |
|
| 475 | - * @type int $wp_post_id |
|
| 476 | - * } |
|
| 477 | - */ |
|
| 478 | - public static function get_free_product_ids(){ |
|
| 479 | - |
|
| 480 | - return get_posts( array( |
|
| 481 | - 'post_type' => 'product', |
|
| 482 | - 'posts_per_page' => '1000', |
|
| 483 | - 'fields' => 'ids', |
|
| 484 | - 'meta_query'=> array( |
|
| 485 | - 'relation' => 'OR', |
|
| 486 | - array( |
|
| 487 | - 'key'=> '_regular_price', |
|
| 488 | - 'value' => 0, |
|
| 489 | - ), |
|
| 490 | - array( |
|
| 491 | - 'key'=> '_sale_price', |
|
| 492 | - 'value' => 0, |
|
| 493 | - ), |
|
| 494 | - ), |
|
| 495 | - )); |
|
| 496 | - |
|
| 497 | - }// end get free product query |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * The metat query for courses that are free |
|
| 501 | - * |
|
| 502 | - * @since 1.9.0 |
|
| 503 | - * @return array $wp_meta_query_param |
|
| 504 | - */ |
|
| 505 | - public static function get_free_courses_meta_query_args(){ |
|
| 506 | - |
|
| 507 | - return array( |
|
| 508 | - 'relation' => 'OR', |
|
| 509 | - array( |
|
| 510 | - 'key' => '_course_woocommerce_product', |
|
| 511 | - 'value' => '-', |
|
| 512 | - 'compare' => '=', |
|
| 513 | - ), |
|
| 514 | - array( |
|
| 515 | - 'key' => '_course_woocommerce_product', |
|
| 516 | - 'value' => self::get_free_product_ids(), |
|
| 517 | - 'compare' => 'IN', |
|
| 518 | - ), |
|
| 519 | - ); |
|
| 520 | - |
|
| 521 | - }// get_free_courses_meta_query |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * The metat query for courses that are free |
|
| 525 | - * |
|
| 526 | - * @since 1.9.0 |
|
| 527 | - * @return array $wp_query_meta_query_args_param |
|
| 528 | - */ |
|
| 529 | - public static function get_paid_courses_meta_query_args(){ |
|
| 530 | - |
|
| 531 | - $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | - |
|
| 533 | - return array( |
|
| 534 | - array( |
|
| 535 | - 'key' => '_course_woocommerce_product', |
|
| 536 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | - // query |
|
| 538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | - 'compare' => 'IN', |
|
| 540 | - ), |
|
| 541 | - ); |
|
| 542 | - |
|
| 543 | - }// get_free_courses_meta_query |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * The WordPress Query args |
|
| 547 | - * for paid products on sale |
|
| 548 | - * |
|
| 549 | - * @since 1.9.0 |
|
| 550 | - * @return array $product_query_args |
|
| 551 | - */ |
|
| 552 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | - |
|
| 554 | - $args = array( |
|
| 555 | - 'post_type' => 'product', |
|
| 556 | - 'posts_per_page' => 1000, |
|
| 557 | - 'orderby' => 'date', |
|
| 558 | - 'order' => 'DESC', |
|
| 559 | - 'suppress_filters' => 0 |
|
| 560 | - ); |
|
| 561 | - |
|
| 562 | - $args[ 'fields' ] = 'ids'; |
|
| 563 | - |
|
| 564 | - $args[ 'meta_query' ] = array( |
|
| 565 | - 'relation' => 'AND', |
|
| 566 | - array( |
|
| 567 | - 'key'=> '_regular_price', |
|
| 568 | - 'compare' => '>', |
|
| 569 | - 'value' => 0, |
|
| 570 | - ), |
|
| 571 | - array( |
|
| 572 | - 'key'=> '_sale_price', |
|
| 573 | - 'compare' => '>', |
|
| 574 | - 'value' => 0, |
|
| 575 | - ), |
|
| 576 | - ); |
|
| 577 | - |
|
| 578 | - return $args; |
|
| 579 | - |
|
| 580 | - } // get_paid_products_on_sale_query_args |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Return the WordPress query args for |
|
| 585 | - * products not on sale but that is not a free |
|
| 586 | - * |
|
| 587 | - * @since 1.9.0 |
|
| 588 | - * |
|
| 589 | - * @return array |
|
| 590 | - */ |
|
| 591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | - |
|
| 593 | - $args = array( |
|
| 594 | - 'post_type' => 'product', |
|
| 595 | - 'posts_per_page' => 1000, |
|
| 596 | - 'orderby' => 'date', |
|
| 597 | - 'order' => 'DESC', |
|
| 598 | - 'suppress_filters' => 0 |
|
| 599 | - ); |
|
| 600 | - |
|
| 601 | - $args[ 'fields' ] = 'ids'; |
|
| 602 | - $args[ 'meta_query' ] = array( |
|
| 603 | - 'relation' => 'AND', |
|
| 604 | - array( |
|
| 605 | - 'key'=> '_regular_price', |
|
| 606 | - 'compare' => '>', |
|
| 607 | - 'value' => 0, |
|
| 608 | - ), |
|
| 609 | - array( |
|
| 610 | - 'key'=> '_sale_price', |
|
| 611 | - 'compare' => '=', |
|
| 612 | - 'value' => '', |
|
| 613 | - ), |
|
| 614 | - ); |
|
| 615 | - |
|
| 616 | - return $args; |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - } // get_paid_courses_meta_query |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Get all WooCommerce non-free product id's |
|
| 623 | - * |
|
| 624 | - * @since 1.9.0 |
|
| 625 | - * |
|
| 626 | - * @return array $woocommerce_paid_product_ids |
|
| 627 | - */ |
|
| 628 | - public static function get_paid_product_ids(){ |
|
| 629 | - |
|
| 630 | - // get all the paid WooCommerce products that has regular |
|
| 631 | - // and sale price greater than 0 |
|
| 632 | - // will be used later to check for course with the id as meta |
|
| 633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | - |
|
| 635 | - // get all the paid WooCommerce products that has regular price |
|
| 636 | - // greater than 0 without a sale price |
|
| 637 | - // will be used later to check for course with the id as meta |
|
| 638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | - |
|
| 640 | - // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | - // sale but regular price greater than zero |
|
| 642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | - |
|
| 644 | - // if |
|
| 645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | - return array( ); |
|
| 647 | - } |
|
| 648 | - return $woocommerce_paid_product_ids; |
|
| 649 | - |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Get all free courses. |
|
| 654 | - * |
|
| 655 | - * This course that have a WC product attached |
|
| 656 | - * that has a price or sale price of zero and |
|
| 657 | - * other courses with no WooCommerce products |
|
| 658 | - * attached. |
|
| 659 | - * |
|
| 660 | - * @since 1.9.0 |
|
| 661 | - * |
|
| 662 | - * @return array |
|
| 663 | - */ |
|
| 664 | - public static function get_free_courses(){ |
|
| 665 | - |
|
| 666 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | - |
|
| 669 | - // don't show any paid courses |
|
| 670 | - $courses = self::get_paid_courses(); |
|
| 671 | - $ids = array(); |
|
| 672 | - foreach( $courses as $course ){ |
|
| 673 | - $ids[] = $course->ID; |
|
| 674 | - } |
|
| 675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | - |
|
| 677 | - return get_posts( $free_course_query_args ); |
|
| 678 | - |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Return all products that are not free |
|
| 683 | - * |
|
| 684 | - * @since 1.9.0 |
|
| 685 | - * @return array |
|
| 686 | - */ |
|
| 687 | - public static function get_paid_courses(){ |
|
| 688 | - |
|
| 689 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | - |
|
| 691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | - |
|
| 693 | - return get_posts( $paid_course_query_args ); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Show the WooCommerce add to cart button for the current course |
|
| 698 | - * |
|
| 699 | - * The function will only show the button if |
|
| 700 | - * 1- the user can buy the course |
|
| 701 | - * 2- if they have completed their pre-requisite |
|
| 702 | - * 3- if the course has a valid product attached |
|
| 703 | - * |
|
| 704 | - * @since 1.9.0 |
|
| 705 | - * @param int $course_id |
|
| 706 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | - */ |
|
| 708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | - |
|
| 710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | - return ''; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | - |
|
| 716 | - // Check if customer purchased the product |
|
| 717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | - || empty( $wc_post_id ) ) { |
|
| 719 | - |
|
| 720 | - return ''; |
|
| 721 | - |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | - // Get the product |
|
| 726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | - |
|
| 728 | - // do not show the button for invalid products, non purchasable products, out |
|
| 729 | - // of stock product or if course is already in cart |
|
| 730 | - if ( ! isset ( $product ) |
|
| 731 | - || ! is_object( $product ) |
|
| 732 | - || ! $product->is_purchasable() |
|
| 733 | - || ! $product->is_in_stock() |
|
| 734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | - |
|
| 736 | - return ''; |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - // |
|
| 741 | - // button output: |
|
| 742 | - // |
|
| 743 | - ?> |
|
| 412 | + /** |
|
| 413 | + * Checks the cart to see if a course is in the cart. |
|
| 414 | + * |
|
| 415 | + * @param $course_id |
|
| 416 | + * @return bool |
|
| 417 | + */ |
|
| 418 | + public static function is_course_in_cart( $course_id ){ |
|
| 419 | + |
|
| 420 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | + |
|
| 423 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | + |
|
| 425 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | + |
|
| 427 | + return true; |
|
| 428 | + |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return false; |
|
| 434 | + |
|
| 435 | + }// is_course_in_cart |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Check the cart to see if the product is in the cart |
|
| 439 | + * |
|
| 440 | + * @param $product_id |
|
| 441 | + * @return bool |
|
| 442 | + */ |
|
| 443 | + public static function is_product_in_cart( $product_id ){ |
|
| 444 | + |
|
| 445 | + if ( 0 < $product_id ) { |
|
| 446 | + |
|
| 447 | + $product = wc_get_product( $product_id ); |
|
| 448 | + |
|
| 449 | + $parent_id = ''; |
|
| 450 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | + $wc_product_id = $product->parent->id; |
|
| 452 | + } |
|
| 453 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | + |
|
| 455 | + $cart_product = $values['data']; |
|
| 456 | + if( $product_id == $cart_product->id ) { |
|
| 457 | + |
|
| 458 | + return true; |
|
| 459 | + |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + } |
|
| 463 | + } // End If Statement |
|
| 464 | + |
|
| 465 | + return false; |
|
| 466 | + |
|
| 467 | + } // end is_product_in_car |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Get all free WooCommerce products |
|
| 471 | + * |
|
| 472 | + * @since 1.9.0 |
|
| 473 | + * |
|
| 474 | + * @return array $free_products{ |
|
| 475 | + * @type int $wp_post_id |
|
| 476 | + * } |
|
| 477 | + */ |
|
| 478 | + public static function get_free_product_ids(){ |
|
| 479 | + |
|
| 480 | + return get_posts( array( |
|
| 481 | + 'post_type' => 'product', |
|
| 482 | + 'posts_per_page' => '1000', |
|
| 483 | + 'fields' => 'ids', |
|
| 484 | + 'meta_query'=> array( |
|
| 485 | + 'relation' => 'OR', |
|
| 486 | + array( |
|
| 487 | + 'key'=> '_regular_price', |
|
| 488 | + 'value' => 0, |
|
| 489 | + ), |
|
| 490 | + array( |
|
| 491 | + 'key'=> '_sale_price', |
|
| 492 | + 'value' => 0, |
|
| 493 | + ), |
|
| 494 | + ), |
|
| 495 | + )); |
|
| 496 | + |
|
| 497 | + }// end get free product query |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * The metat query for courses that are free |
|
| 501 | + * |
|
| 502 | + * @since 1.9.0 |
|
| 503 | + * @return array $wp_meta_query_param |
|
| 504 | + */ |
|
| 505 | + public static function get_free_courses_meta_query_args(){ |
|
| 506 | + |
|
| 507 | + return array( |
|
| 508 | + 'relation' => 'OR', |
|
| 509 | + array( |
|
| 510 | + 'key' => '_course_woocommerce_product', |
|
| 511 | + 'value' => '-', |
|
| 512 | + 'compare' => '=', |
|
| 513 | + ), |
|
| 514 | + array( |
|
| 515 | + 'key' => '_course_woocommerce_product', |
|
| 516 | + 'value' => self::get_free_product_ids(), |
|
| 517 | + 'compare' => 'IN', |
|
| 518 | + ), |
|
| 519 | + ); |
|
| 520 | + |
|
| 521 | + }// get_free_courses_meta_query |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * The metat query for courses that are free |
|
| 525 | + * |
|
| 526 | + * @since 1.9.0 |
|
| 527 | + * @return array $wp_query_meta_query_args_param |
|
| 528 | + */ |
|
| 529 | + public static function get_paid_courses_meta_query_args(){ |
|
| 530 | + |
|
| 531 | + $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | + |
|
| 533 | + return array( |
|
| 534 | + array( |
|
| 535 | + 'key' => '_course_woocommerce_product', |
|
| 536 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | + // query |
|
| 538 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | + 'compare' => 'IN', |
|
| 540 | + ), |
|
| 541 | + ); |
|
| 542 | + |
|
| 543 | + }// get_free_courses_meta_query |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * The WordPress Query args |
|
| 547 | + * for paid products on sale |
|
| 548 | + * |
|
| 549 | + * @since 1.9.0 |
|
| 550 | + * @return array $product_query_args |
|
| 551 | + */ |
|
| 552 | + public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | + |
|
| 554 | + $args = array( |
|
| 555 | + 'post_type' => 'product', |
|
| 556 | + 'posts_per_page' => 1000, |
|
| 557 | + 'orderby' => 'date', |
|
| 558 | + 'order' => 'DESC', |
|
| 559 | + 'suppress_filters' => 0 |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + $args[ 'fields' ] = 'ids'; |
|
| 563 | + |
|
| 564 | + $args[ 'meta_query' ] = array( |
|
| 565 | + 'relation' => 'AND', |
|
| 566 | + array( |
|
| 567 | + 'key'=> '_regular_price', |
|
| 568 | + 'compare' => '>', |
|
| 569 | + 'value' => 0, |
|
| 570 | + ), |
|
| 571 | + array( |
|
| 572 | + 'key'=> '_sale_price', |
|
| 573 | + 'compare' => '>', |
|
| 574 | + 'value' => 0, |
|
| 575 | + ), |
|
| 576 | + ); |
|
| 577 | + |
|
| 578 | + return $args; |
|
| 579 | + |
|
| 580 | + } // get_paid_products_on_sale_query_args |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Return the WordPress query args for |
|
| 585 | + * products not on sale but that is not a free |
|
| 586 | + * |
|
| 587 | + * @since 1.9.0 |
|
| 588 | + * |
|
| 589 | + * @return array |
|
| 590 | + */ |
|
| 591 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | + |
|
| 593 | + $args = array( |
|
| 594 | + 'post_type' => 'product', |
|
| 595 | + 'posts_per_page' => 1000, |
|
| 596 | + 'orderby' => 'date', |
|
| 597 | + 'order' => 'DESC', |
|
| 598 | + 'suppress_filters' => 0 |
|
| 599 | + ); |
|
| 600 | + |
|
| 601 | + $args[ 'fields' ] = 'ids'; |
|
| 602 | + $args[ 'meta_query' ] = array( |
|
| 603 | + 'relation' => 'AND', |
|
| 604 | + array( |
|
| 605 | + 'key'=> '_regular_price', |
|
| 606 | + 'compare' => '>', |
|
| 607 | + 'value' => 0, |
|
| 608 | + ), |
|
| 609 | + array( |
|
| 610 | + 'key'=> '_sale_price', |
|
| 611 | + 'compare' => '=', |
|
| 612 | + 'value' => '', |
|
| 613 | + ), |
|
| 614 | + ); |
|
| 615 | + |
|
| 616 | + return $args; |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + } // get_paid_courses_meta_query |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Get all WooCommerce non-free product id's |
|
| 623 | + * |
|
| 624 | + * @since 1.9.0 |
|
| 625 | + * |
|
| 626 | + * @return array $woocommerce_paid_product_ids |
|
| 627 | + */ |
|
| 628 | + public static function get_paid_product_ids(){ |
|
| 629 | + |
|
| 630 | + // get all the paid WooCommerce products that has regular |
|
| 631 | + // and sale price greater than 0 |
|
| 632 | + // will be used later to check for course with the id as meta |
|
| 633 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | + |
|
| 635 | + // get all the paid WooCommerce products that has regular price |
|
| 636 | + // greater than 0 without a sale price |
|
| 637 | + // will be used later to check for course with the id as meta |
|
| 638 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | + |
|
| 640 | + // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | + // sale but regular price greater than zero |
|
| 642 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | + |
|
| 644 | + // if |
|
| 645 | + if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | + return array( ); |
|
| 647 | + } |
|
| 648 | + return $woocommerce_paid_product_ids; |
|
| 649 | + |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Get all free courses. |
|
| 654 | + * |
|
| 655 | + * This course that have a WC product attached |
|
| 656 | + * that has a price or sale price of zero and |
|
| 657 | + * other courses with no WooCommerce products |
|
| 658 | + * attached. |
|
| 659 | + * |
|
| 660 | + * @since 1.9.0 |
|
| 661 | + * |
|
| 662 | + * @return array |
|
| 663 | + */ |
|
| 664 | + public static function get_free_courses(){ |
|
| 665 | + |
|
| 666 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | + |
|
| 669 | + // don't show any paid courses |
|
| 670 | + $courses = self::get_paid_courses(); |
|
| 671 | + $ids = array(); |
|
| 672 | + foreach( $courses as $course ){ |
|
| 673 | + $ids[] = $course->ID; |
|
| 674 | + } |
|
| 675 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | + |
|
| 677 | + return get_posts( $free_course_query_args ); |
|
| 678 | + |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Return all products that are not free |
|
| 683 | + * |
|
| 684 | + * @since 1.9.0 |
|
| 685 | + * @return array |
|
| 686 | + */ |
|
| 687 | + public static function get_paid_courses(){ |
|
| 688 | + |
|
| 689 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | + |
|
| 691 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | + |
|
| 693 | + return get_posts( $paid_course_query_args ); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Show the WooCommerce add to cart button for the current course |
|
| 698 | + * |
|
| 699 | + * The function will only show the button if |
|
| 700 | + * 1- the user can buy the course |
|
| 701 | + * 2- if they have completed their pre-requisite |
|
| 702 | + * 3- if the course has a valid product attached |
|
| 703 | + * |
|
| 704 | + * @since 1.9.0 |
|
| 705 | + * @param int $course_id |
|
| 706 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | + */ |
|
| 708 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | + |
|
| 710 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | + return ''; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | + |
|
| 716 | + // Check if customer purchased the product |
|
| 717 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | + || empty( $wc_post_id ) ) { |
|
| 719 | + |
|
| 720 | + return ''; |
|
| 721 | + |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | + // Get the product |
|
| 726 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | + |
|
| 728 | + // do not show the button for invalid products, non purchasable products, out |
|
| 729 | + // of stock product or if course is already in cart |
|
| 730 | + if ( ! isset ( $product ) |
|
| 731 | + || ! is_object( $product ) |
|
| 732 | + || ! $product->is_purchasable() |
|
| 733 | + || ! $product->is_in_stock() |
|
| 734 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | + |
|
| 736 | + return ''; |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + // |
|
| 741 | + // button output: |
|
| 742 | + // |
|
| 743 | + ?> |
|
| 744 | 744 | |
| 745 | 745 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
| 746 | 746 | class="cart" |
@@ -773,54 +773,54 @@ discard block |
||
| 773 | 773 | </form> |
| 774 | 774 | |
| 775 | 775 | <?php |
| 776 | - } // end the_add_to_cart_button_html |
|
| 776 | + } // end the_add_to_cart_button_html |
|
| 777 | 777 | |
| 778 | - /** |
|
| 779 | - * Alter the no permissions message on the single course page |
|
| 780 | - * Changes the message to a WooCommerce specific message. |
|
| 781 | - * |
|
| 782 | - * @since 1.9.0 |
|
| 783 | - * |
|
| 784 | - * @param $message |
|
| 785 | - * @param $post_id |
|
| 786 | - * |
|
| 787 | - * @return string $message |
|
| 788 | - */ |
|
| 789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 778 | + /** |
|
| 779 | + * Alter the no permissions message on the single course page |
|
| 780 | + * Changes the message to a WooCommerce specific message. |
|
| 781 | + * |
|
| 782 | + * @since 1.9.0 |
|
| 783 | + * |
|
| 784 | + * @param $message |
|
| 785 | + * @param $post_id |
|
| 786 | + * |
|
| 787 | + * @return string $message |
|
| 788 | + */ |
|
| 789 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 790 | 790 | |
| 791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | - return $message; |
|
| 793 | - } |
|
| 791 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | + return $message; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 795 | + $product_id = self::get_course_product_id( $post_id ); |
|
| 796 | 796 | |
| 797 | - if( ! $product_id |
|
| 798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 797 | + if( ! $product_id |
|
| 798 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 799 | 799 | |
| 800 | - return $message; |
|
| 800 | + return $message; |
|
| 801 | 801 | |
| 802 | - } |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - ob_start(); |
|
| 805 | - self::the_course_no_permissions_message( $post_id ); |
|
| 806 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 804 | + ob_start(); |
|
| 805 | + self::the_course_no_permissions_message( $post_id ); |
|
| 806 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 807 | 807 | |
| 808 | - return $woocommerce_course_no_permissions_message ; |
|
| 808 | + return $woocommerce_course_no_permissions_message ; |
|
| 809 | 809 | |
| 810 | - } |
|
| 811 | - /** |
|
| 812 | - * Show the no permissions message when a user is logged in |
|
| 813 | - * and have not yet purchased the current course |
|
| 814 | - * |
|
| 815 | - * @since 1.9.0 |
|
| 816 | - */ |
|
| 817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 810 | + } |
|
| 811 | + /** |
|
| 812 | + * Show the no permissions message when a user is logged in |
|
| 813 | + * and have not yet purchased the current course |
|
| 814 | + * |
|
| 815 | + * @since 1.9.0 |
|
| 816 | + */ |
|
| 817 | + public static function the_course_no_permissions_message( $course_id ){ |
|
| 818 | 818 | |
| 819 | - // login link |
|
| 820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 819 | + // login link |
|
| 820 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 822 | 822 | |
| 823 | - ?> |
|
| 823 | + ?> |
|
| 824 | 824 | |
| 825 | 825 | <span class="add-to-cart-login"> |
| 826 | 826 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -828,110 +828,110 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | <?php } |
| 830 | 830 | |
| 831 | - /** |
|
| 832 | - * Checks if a user has bought a product item. |
|
| 833 | - * |
|
| 834 | - * @since 1.9.0 |
|
| 835 | - * |
|
| 836 | - * @param int $user_id |
|
| 837 | - * @param int $product_id |
|
| 838 | - * |
|
| 839 | - * @return bool |
|
| 840 | - */ |
|
| 841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 831 | + /** |
|
| 832 | + * Checks if a user has bought a product item. |
|
| 833 | + * |
|
| 834 | + * @since 1.9.0 |
|
| 835 | + * |
|
| 836 | + * @param int $user_id |
|
| 837 | + * @param int $product_id |
|
| 838 | + * |
|
| 839 | + * @return bool |
|
| 840 | + */ |
|
| 841 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 842 | 842 | |
| 843 | - $orders = get_posts( array( |
|
| 844 | - 'posts_per_page' => -1, |
|
| 845 | - 'meta_key' => '_customer_user', |
|
| 846 | - 'meta_value' => intval( $user_id ), |
|
| 847 | - 'post_type' => 'shop_order', |
|
| 848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | - ) ); |
|
| 843 | + $orders = get_posts( array( |
|
| 844 | + 'posts_per_page' => -1, |
|
| 845 | + 'meta_key' => '_customer_user', |
|
| 846 | + 'meta_value' => intval( $user_id ), |
|
| 847 | + 'post_type' => 'shop_order', |
|
| 848 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | + ) ); |
|
| 850 | 850 | |
| 851 | - foreach ( $orders as $order_id ) { |
|
| 851 | + foreach ( $orders as $order_id ) { |
|
| 852 | 852 | |
| 853 | - $order = new WC_Order( $order_id->ID ); |
|
| 853 | + $order = new WC_Order( $order_id->ID ); |
|
| 854 | 854 | |
| 855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 855 | + if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 856 | 856 | |
| 857 | - continue; |
|
| 858 | - } |
|
| 857 | + continue; |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 860 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 861 | 861 | |
| 862 | - continue; |
|
| 862 | + continue; |
|
| 863 | 863 | |
| 864 | - } |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - foreach( $order->get_items() as $item ) { |
|
| 866 | + foreach( $order->get_items() as $item ) { |
|
| 867 | 867 | |
| 868 | - // Check if user has bought product |
|
| 869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 868 | + // Check if user has bought product |
|
| 869 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 870 | 870 | |
| 871 | - // Check if user has an active subscription for product |
|
| 872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | - if( $sub_key ) { |
|
| 875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | - if( 'active' == $sub['status'] ) { |
|
| 878 | - return true; |
|
| 879 | - } else { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - } |
|
| 871 | + // Check if user has an active subscription for product |
|
| 872 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | + if( $sub_key ) { |
|
| 875 | + $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | + if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | + if( 'active' == $sub['status'] ) { |
|
| 878 | + return true; |
|
| 879 | + } else { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | 885 | |
| 886 | - // Customer has bought product |
|
| 887 | - return true; |
|
| 888 | - } // End If Statement |
|
| 886 | + // Customer has bought product |
|
| 887 | + return true; |
|
| 888 | + } // End If Statement |
|
| 889 | 889 | |
| 890 | - } // End For each item |
|
| 890 | + } // End For each item |
|
| 891 | 891 | |
| 892 | - } // End For each order |
|
| 892 | + } // End For each order |
|
| 893 | 893 | |
| 894 | - } // end has customer bought product |
|
| 894 | + } // end has customer bought product |
|
| 895 | 895 | |
| 896 | - /** |
|
| 897 | - * Return the product id for the given course |
|
| 898 | - * |
|
| 899 | - * @since 1.9.0 |
|
| 900 | - * |
|
| 901 | - * @param int $course_id |
|
| 902 | - * |
|
| 903 | - * @return string $woocommerce_product_id or false if none exist |
|
| 904 | - * |
|
| 905 | - */ |
|
| 906 | - public static function get_course_product_id( $course_id ){ |
|
| 896 | + /** |
|
| 897 | + * Return the product id for the given course |
|
| 898 | + * |
|
| 899 | + * @since 1.9.0 |
|
| 900 | + * |
|
| 901 | + * @param int $course_id |
|
| 902 | + * |
|
| 903 | + * @return string $woocommerce_product_id or false if none exist |
|
| 904 | + * |
|
| 905 | + */ |
|
| 906 | + public static function get_course_product_id( $course_id ){ |
|
| 907 | 907 | |
| 908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 908 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 909 | 909 | |
| 910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | - return false; |
|
| 912 | - } |
|
| 910 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | + return false; |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | - return $product_id; |
|
| 914 | + return $product_id; |
|
| 915 | 915 | |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - /** |
|
| 919 | - * Alter the body classes adding WooCommerce to the body |
|
| 920 | - * |
|
| 921 | - * @param array $classes |
|
| 922 | - * @return array |
|
| 923 | - */ |
|
| 924 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 918 | + /** |
|
| 919 | + * Alter the body classes adding WooCommerce to the body |
|
| 920 | + * |
|
| 921 | + * @param array $classes |
|
| 922 | + * @return array |
|
| 923 | + */ |
|
| 924 | + public static function add_woocommerce_body_class( $classes ){ |
|
| 925 | 925 | |
| 926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 926 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 927 | 927 | |
| 928 | - $classes[] ='woocommerce'; |
|
| 928 | + $classes[] ='woocommerce'; |
|
| 929 | 929 | |
| 930 | - } |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | 932 | |
| 933 | - return $classes; |
|
| 933 | + return $classes; |
|
| 934 | 934 | |
| 935 | - } |
|
| 935 | + } |
|
| 936 | 936 | |
| 937 | 937 | }// end Sensei_WC |
@@ -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,15 +11,15 @@ discard block |
||
| 11 | 11 | * @since 1.9.0 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -Class Sensei_WC{ |
|
| 14 | +Class Sensei_WC { |
|
| 15 | 15 | /** |
| 16 | 16 | * Load the files needed for the woocommerce integration. |
| 17 | 17 | * |
| 18 | 18 | * @since 1.9.0 |
| 19 | 19 | */ |
| 20 | - public static function load_woocommerce_integration_hooks(){ |
|
| 20 | + public static function load_woocommerce_integration_hooks() { |
|
| 21 | 21 | |
| 22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 22 | + require_once(__DIR__.'/hooks/woocommerce.php'); |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | /** |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | * @since 1.9.0 |
| 29 | 29 | * @return bool |
| 30 | 30 | */ |
| 31 | - public static function is_woocommerce_active(){ |
|
| 31 | + public static function is_woocommerce_active() { |
|
| 32 | 32 | |
| 33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 33 | + $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | 34 | return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
| 35 | 35 | |
| 36 | 36 | } // end is_woocommerce_active |
@@ -45,19 +45,19 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | - public static function is_woocommerce_present(){ |
|
| 48 | + public static function is_woocommerce_present() { |
|
| 49 | 49 | |
| 50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 50 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
| 51 | 51 | |
| 52 | - if ( is_multisite() ){ |
|
| 52 | + if (is_multisite()) { |
|
| 53 | 53 | |
| 54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 54 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 58 | + $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins); |
|
| 59 | 59 | |
| 60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 60 | + return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated; |
|
| 61 | 61 | |
| 62 | 62 | }// end is_woocommerce_present |
| 63 | 63 | |
@@ -70,48 +70,48 @@ discard block |
||
| 70 | 70 | * @param $course_id |
| 71 | 71 | * @return array $user_course_orders |
| 72 | 72 | */ |
| 73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 73 | + public static function get_learner_course_active_order_id($user_id, $course_id) { |
|
| 74 | 74 | |
| 75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 75 | + $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 76 | 76 | |
| 77 | - $orders_query = new WP_Query( array( |
|
| 77 | + $orders_query = new WP_Query(array( |
|
| 78 | 78 | 'post_type' => 'shop_order', |
| 79 | 79 | 'posts_per_page' => -1, |
| 80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 80 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 81 | 81 | 'meta_key'=> '_customer_user', |
| 82 | 82 | 'meta_value'=> $user_id, |
| 83 | - ) ); |
|
| 83 | + )); |
|
| 84 | 84 | |
| 85 | - if( $orders_query->post_count == 0 ){ |
|
| 85 | + if ($orders_query->post_count == 0) { |
|
| 86 | 86 | |
| 87 | 87 | return false; |
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 91 | + foreach ($orders_query->get_posts() as $order) { |
|
| 92 | 92 | |
| 93 | - $order = new WC_Order( $order->ID ); |
|
| 93 | + $order = new WC_Order($order->ID); |
|
| 94 | 94 | $items = $order->get_items(); |
| 95 | 95 | |
| 96 | - $user_orders = array(); |
|
| 96 | + $user_orders = array(); |
|
| 97 | 97 | |
| 98 | - foreach( $items as $item ){ |
|
| 98 | + foreach ($items as $item) { |
|
| 99 | 99 | |
| 100 | 100 | // if the product id on the order and the one given to this function |
| 101 | 101 | // this order has been placed by the given user on the given course. |
| 102 | - $product = wc_get_product( $item['product_id'] ); |
|
| 102 | + $product = wc_get_product($item['product_id']); |
|
| 103 | 103 | |
| 104 | - if ( $product->is_type( 'variable' )) { |
|
| 104 | + if ($product->is_type('variable')) { |
|
| 105 | 105 | |
| 106 | 106 | $item_product_id = $item['variation_id']; |
| 107 | 107 | |
| 108 | 108 | } else { |
| 109 | 109 | |
| 110 | - $item_product_id = $item['product_id']; |
|
| 110 | + $item_product_id = $item['product_id']; |
|
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if( $course_product_id == $item_product_id ){ |
|
| 114 | + if ($course_product_id == $item_product_id) { |
|
| 115 | 115 | |
| 116 | 116 | return $order->id; |
| 117 | 117 | |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | * @param $filter_links |
| 136 | 136 | * @return mixed |
| 137 | 137 | */ |
| 138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 138 | + public static function add_course_archive_wc_filter_links($filter_links) { |
|
| 139 | 139 | |
| 140 | 140 | $free_courses = self::get_free_courses(); |
| 141 | 141 | $paid_courses = self::get_paid_courses(); |
| 142 | 142 | |
| 143 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 143 | + if (empty($free_courses) || empty($paid_courses)) { |
|
| 144 | 144 | // do not show any WooCommerce filters if all courses are |
| 145 | 145 | // free or if all courses are paid |
| 146 | 146 | return $filter_links; |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $filter_links[] = array( |
| 151 | - 'id'=>'paid' , |
|
| 152 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 151 | + 'id'=>'paid', |
|
| 152 | + 'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()), |
|
| 153 | + 'title'=>__('Paid', 'woothemes-sensei') |
|
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | 156 | $filter_links[] = array( |
| 157 | 157 | 'id'=>'free', |
| 158 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 158 | + 'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()), |
|
| 159 | + 'title'=>__('Free', 'woothemes-sensei') |
|
| 160 | 160 | ); |
| 161 | 161 | |
| 162 | 162 | return $filter_links; |
@@ -173,24 +173,24 @@ discard block |
||
| 173 | 173 | * @param WP_Query $query |
| 174 | 174 | * @return WP_Query $query |
| 175 | 175 | */ |
| 176 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 176 | + public static function course_archive_wc_filter_free($query) { |
|
| 177 | 177 | |
| 178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 178 | + if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter'] |
|
| 179 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 180 | 180 | |
| 181 | 181 | // setup the course meta query |
| 182 | 182 | $meta_query = self::get_free_courses_meta_query_args(); |
| 183 | 183 | |
| 184 | 184 | // manipulate the query to return free courses |
| 185 | - $query->set('meta_query', $meta_query ); |
|
| 185 | + $query->set('meta_query', $meta_query); |
|
| 186 | 186 | |
| 187 | 187 | // don't show any paid courses |
| 188 | 188 | $courses = self::get_paid_courses(); |
| 189 | 189 | $ids = array(); |
| 190 | - foreach( $courses as $course ){ |
|
| 190 | + foreach ($courses as $course) { |
|
| 191 | 191 | $ids[] = $course->ID; |
| 192 | 192 | } |
| 193 | - $query->set( 'post__not_in', $ids ); |
|
| 193 | + $query->set('post__not_in', $ids); |
|
| 194 | 194 | |
| 195 | 195 | }// end if course_filter |
| 196 | 196 | |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | * @param WP_Query $query |
| 210 | 210 | * @return WP_Query $query |
| 211 | 211 | */ |
| 212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 212 | + public static function course_archive_wc_filter_paid($query) { |
|
| 213 | 213 | |
| 214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 214 | + if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter'] |
|
| 215 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
| 216 | 216 | |
| 217 | 217 | // setup the course meta query |
| 218 | 218 | $meta_query = self::get_paid_courses_meta_query_args(); |
| 219 | 219 | |
| 220 | 220 | // manipulate the query to return free courses |
| 221 | - $query->set('meta_query', $meta_query ); |
|
| 221 | + $query->set('meta_query', $meta_query); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | * single courses if woocommerce is active allowing purchase |
| 232 | 232 | * information and actions to be hooked from WooCommerce. |
| 233 | 233 | */ |
| 234 | - public static function do_single_course_wc_single_product_action(){ |
|
| 234 | + public static function do_single_course_wc_single_product_action() { |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * this hooks is documented within the WooCommerce plugin. |
| 238 | 238 | */ |
| 239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 239 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 240 | 240 | |
| 241 | - do_action( 'woocommerce_before_single_product' ); |
|
| 241 | + do_action('woocommerce_before_single_product'); |
|
| 242 | 242 | |
| 243 | 243 | } // End If Statement |
| 244 | 244 | |
@@ -259,23 +259,23 @@ discard block |
||
| 259 | 259 | * @param $user_id |
| 260 | 260 | * @return bool |
| 261 | 261 | */ |
| 262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 262 | + public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) { |
|
| 263 | 263 | |
| 264 | 264 | // check if the course has a valid product attached to it |
| 265 | 265 | // which the user should have purchased if they want to access |
| 266 | 266 | // the current lesson |
| 267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 267 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 268 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 269 | 269 | $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
| 270 | - if( isset ($product) && is_object($product) ){ |
|
| 270 | + if (isset ($product) && is_object($product)) { |
|
| 271 | 271 | |
| 272 | 272 | // valid product found |
| 273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 273 | + $order_id = self::get_learner_course_active_order_id($user_id, $course_id); |
|
| 274 | 274 | |
| 275 | 275 | // product has a successful order so this user may access the content |
| 276 | 276 | // this function may only return false or the default |
| 277 | 277 | // returning true may override other negatives which we don't want |
| 278 | - if( ! $order_id ){ |
|
| 278 | + if ( ! $order_id) { |
|
| 279 | 279 | |
| 280 | 280 | return false; |
| 281 | 281 | |
@@ -298,23 +298,23 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public static function course_link_from_order( ) { |
| 300 | 300 | |
| 301 | - if( ! is_order_received_page() ){ |
|
| 301 | + if ( ! is_order_received_page()) { |
|
| 302 | 302 | return; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - $order_id = get_query_var( 'order-received' ); |
|
| 306 | - $order = new WC_Order( $order_id ); |
|
| 305 | + $order_id = get_query_var('order-received'); |
|
| 306 | + $order = new WC_Order($order_id); |
|
| 307 | 307 | |
| 308 | 308 | // exit early if not wc-completed or wc-processing |
| 309 | - if( 'wc-completed' != $order->post_status |
|
| 310 | - && 'wc-processing' != $order->post_status ) { |
|
| 309 | + if ('wc-completed' != $order->post_status |
|
| 310 | + && 'wc-processing' != $order->post_status) { |
|
| 311 | 311 | return; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $course_links = array(); // store the for links for courses purchased |
| 315 | - foreach ( $order->get_items() as $item ) { |
|
| 315 | + foreach ($order->get_items() as $item) { |
|
| 316 | 316 | |
| 317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 317 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 318 | 318 | |
| 319 | 319 | // If item has variation_id then its a variation of the product |
| 320 | 320 | $item_id = $item['variation_id']; |
@@ -326,28 +326,28 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | } // End If Statement |
| 328 | 328 | |
| 329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 329 | + $user_id = get_post_meta($order->id, '_customer_user', true); |
|
| 330 | 330 | |
| 331 | - if( $user_id ) { |
|
| 331 | + if ($user_id) { |
|
| 332 | 332 | |
| 333 | 333 | // Get all courses for product |
| 334 | 334 | $args = Sensei_Course::get_default_query_args(); |
| 335 | - $args['meta_query'] = array( array( |
|
| 335 | + $args['meta_query'] = array(array( |
|
| 336 | 336 | 'key' => '_course_woocommerce_product', |
| 337 | 337 | 'value' => $item_id |
| 338 | - ) ); |
|
| 338 | + )); |
|
| 339 | 339 | $args['orderby'] = 'menu_order date'; |
| 340 | 340 | $args['order'] = 'ASC'; |
| 341 | 341 | |
| 342 | 342 | // loop through courses |
| 343 | - $courses = get_posts( $args ); |
|
| 344 | - if( $courses && count( $courses ) > 0 ) { |
|
| 343 | + $courses = get_posts($args); |
|
| 344 | + if ($courses && count($courses) > 0) { |
|
| 345 | 345 | |
| 346 | - foreach( $courses as $course ) { |
|
| 346 | + foreach ($courses as $course) { |
|
| 347 | 347 | |
| 348 | 348 | $title = $course->post_title; |
| 349 | - $permalink = get_permalink( $course->ID ); |
|
| 350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 349 | + $permalink = get_permalink($course->ID); |
|
| 350 | + $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> '; |
|
| 351 | 351 | |
| 352 | 352 | } // end for each |
| 353 | 353 | |
@@ -358,24 +358,24 @@ discard block |
||
| 358 | 358 | }// end loop through orders |
| 359 | 359 | |
| 360 | 360 | // add the courses to the WooCommerce notice |
| 361 | - if( ! empty( $course_links) ){ |
|
| 361 | + if ( ! empty($course_links)) { |
|
| 362 | 362 | |
| 363 | 363 | $courses_html = _nx( |
| 364 | 364 | 'You have purchased the following course:', |
| 365 | 365 | 'You have purchased the following courses:', |
| 366 | - count( $course_links ), |
|
| 366 | + count($course_links), |
|
| 367 | 367 | 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - foreach( $course_links as $link ){ |
|
| 370 | + foreach ($course_links as $link) { |
|
| 371 | 371 | |
| 372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 372 | + $courses_html .= '<li>'.$link.'</li>'; |
|
| 373 | 373 | |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | $courses_html .= ' </ul>'; |
| 377 | 377 | |
| 378 | - wc_add_notice( $courses_html, 'success' ); |
|
| 378 | + wc_add_notice($courses_html, 'success'); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | } // end course_link_order_form |
@@ -388,20 +388,20 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @since 1.9.0 |
| 390 | 390 | */ |
| 391 | - public static function course_in_cart_message(){ |
|
| 391 | + public static function course_in_cart_message() { |
|
| 392 | 392 | |
| 393 | 393 | global $post; |
| 394 | 394 | |
| 395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 395 | + if (self::is_course_in_cart($post->ID)) { ?> |
|
| 396 | 396 | |
| 397 | 397 | <div class="sensei-message info">' |
| 398 | 398 | <?php |
| 399 | 399 | |
| 400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 400 | + $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url() |
|
| 401 | + . '" title="'.__('complete purchase', 'woothemes-sensei').'">' |
|
| 402 | + . __('complete the purchase', 'woothemes-sensei').'</a>'; |
|
| 403 | 403 | |
| 404 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 404 | + sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link); |
|
| 405 | 405 | |
| 406 | 406 | ?> |
| 407 | 407 | </div> |
@@ -415,14 +415,14 @@ discard block |
||
| 415 | 415 | * @param $course_id |
| 416 | 416 | * @return bool |
| 417 | 417 | */ |
| 418 | - public static function is_course_in_cart( $course_id ){ |
|
| 418 | + public static function is_course_in_cart($course_id) { |
|
| 419 | 419 | |
| 420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 420 | + $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true)); |
|
| 421 | + $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
| 422 | 422 | |
| 423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 423 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
| 424 | 424 | |
| 425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 425 | + if (self::is_product_in_cart($wc_post_id)) { |
|
| 426 | 426 | |
| 427 | 427 | return true; |
| 428 | 428 | |
@@ -440,20 +440,20 @@ discard block |
||
| 440 | 440 | * @param $product_id |
| 441 | 441 | * @return bool |
| 442 | 442 | */ |
| 443 | - public static function is_product_in_cart( $product_id ){ |
|
| 443 | + public static function is_product_in_cart($product_id) { |
|
| 444 | 444 | |
| 445 | - if ( 0 < $product_id ) { |
|
| 445 | + if (0 < $product_id) { |
|
| 446 | 446 | |
| 447 | - $product = wc_get_product( $product_id ); |
|
| 447 | + $product = wc_get_product($product_id); |
|
| 448 | 448 | |
| 449 | 449 | $parent_id = ''; |
| 450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 450 | + if (isset($product->variation_id) && 0 < intval($product->variation_id)) { |
|
| 451 | 451 | $wc_product_id = $product->parent->id; |
| 452 | 452 | } |
| 453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 453 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 454 | 454 | |
| 455 | 455 | $cart_product = $values['data']; |
| 456 | - if( $product_id == $cart_product->id ) { |
|
| 456 | + if ($product_id == $cart_product->id) { |
|
| 457 | 457 | |
| 458 | 458 | return true; |
| 459 | 459 | |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | * @type int $wp_post_id |
| 476 | 476 | * } |
| 477 | 477 | */ |
| 478 | - public static function get_free_product_ids(){ |
|
| 478 | + public static function get_free_product_ids() { |
|
| 479 | 479 | |
| 480 | - return get_posts( array( |
|
| 480 | + return get_posts(array( |
|
| 481 | 481 | 'post_type' => 'product', |
| 482 | 482 | 'posts_per_page' => '1000', |
| 483 | 483 | 'fields' => 'ids', |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @since 1.9.0 |
| 503 | 503 | * @return array $wp_meta_query_param |
| 504 | 504 | */ |
| 505 | - public static function get_free_courses_meta_query_args(){ |
|
| 505 | + public static function get_free_courses_meta_query_args() { |
|
| 506 | 506 | |
| 507 | 507 | return array( |
| 508 | 508 | 'relation' => 'OR', |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | * @since 1.9.0 |
| 527 | 527 | * @return array $wp_query_meta_query_args_param |
| 528 | 528 | */ |
| 529 | - public static function get_paid_courses_meta_query_args(){ |
|
| 529 | + public static function get_paid_courses_meta_query_args() { |
|
| 530 | 530 | |
| 531 | 531 | $paid_product_ids = self::get_paid_product_ids(); |
| 532 | 532 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | 'key' => '_course_woocommerce_product', |
| 536 | 536 | // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
| 537 | 537 | // query |
| 538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 538 | + 'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids, |
|
| 539 | 539 | 'compare' => 'IN', |
| 540 | 540 | ), |
| 541 | 541 | ); |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | * @since 1.9.0 |
| 550 | 550 | * @return array $product_query_args |
| 551 | 551 | */ |
| 552 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 552 | + public static function get_paid_products_on_sale_query_args() { |
|
| 553 | 553 | |
| 554 | 554 | $args = array( |
| 555 | 555 | 'post_type' => 'product', |
@@ -559,9 +559,9 @@ discard block |
||
| 559 | 559 | 'suppress_filters' => 0 |
| 560 | 560 | ); |
| 561 | 561 | |
| 562 | - $args[ 'fields' ] = 'ids'; |
|
| 562 | + $args['fields'] = 'ids'; |
|
| 563 | 563 | |
| 564 | - $args[ 'meta_query' ] = array( |
|
| 564 | + $args['meta_query'] = array( |
|
| 565 | 565 | 'relation' => 'AND', |
| 566 | 566 | array( |
| 567 | 567 | 'key'=> '_regular_price', |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * |
| 589 | 589 | * @return array |
| 590 | 590 | */ |
| 591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 591 | + public static function get_paid_products_not_on_sale_query_args() { |
|
| 592 | 592 | |
| 593 | 593 | $args = array( |
| 594 | 594 | 'post_type' => 'product', |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | 'suppress_filters' => 0 |
| 599 | 599 | ); |
| 600 | 600 | |
| 601 | - $args[ 'fields' ] = 'ids'; |
|
| 602 | - $args[ 'meta_query' ] = array( |
|
| 601 | + $args['fields'] = 'ids'; |
|
| 602 | + $args['meta_query'] = array( |
|
| 603 | 603 | 'relation' => 'AND', |
| 604 | 604 | array( |
| 605 | 605 | 'key'=> '_regular_price', |
@@ -625,24 +625,24 @@ discard block |
||
| 625 | 625 | * |
| 626 | 626 | * @return array $woocommerce_paid_product_ids |
| 627 | 627 | */ |
| 628 | - public static function get_paid_product_ids(){ |
|
| 628 | + public static function get_paid_product_ids() { |
|
| 629 | 629 | |
| 630 | 630 | // get all the paid WooCommerce products that has regular |
| 631 | 631 | // and sale price greater than 0 |
| 632 | 632 | // will be used later to check for course with the id as meta |
| 633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 633 | + $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args()); |
|
| 634 | 634 | |
| 635 | 635 | // get all the paid WooCommerce products that has regular price |
| 636 | 636 | // greater than 0 without a sale price |
| 637 | 637 | // will be used later to check for course with the id as meta |
| 638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 638 | + $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args()); |
|
| 639 | 639 | |
| 640 | 640 | // combine products ID's with regular and sale price grater than zero and those without |
| 641 | 641 | // sale but regular price greater than zero |
| 642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 642 | + $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale); |
|
| 643 | 643 | |
| 644 | 644 | // if |
| 645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 645 | + if (empty($woocommerce_paid_product_ids)) { |
|
| 646 | 646 | return array( ); |
| 647 | 647 | } |
| 648 | 648 | return $woocommerce_paid_product_ids; |
@@ -661,20 +661,20 @@ discard block |
||
| 661 | 661 | * |
| 662 | 662 | * @return array |
| 663 | 663 | */ |
| 664 | - public static function get_free_courses(){ |
|
| 664 | + public static function get_free_courses() { |
|
| 665 | 665 | |
| 666 | 666 | $free_course_query_args = Sensei_Course::get_default_query_args(); |
| 667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 667 | + $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args(); |
|
| 668 | 668 | |
| 669 | 669 | // don't show any paid courses |
| 670 | 670 | $courses = self::get_paid_courses(); |
| 671 | 671 | $ids = array(); |
| 672 | - foreach( $courses as $course ){ |
|
| 672 | + foreach ($courses as $course) { |
|
| 673 | 673 | $ids[] = $course->ID; |
| 674 | 674 | } |
| 675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 675 | + $free_course_query_args['post__not_in'] = $ids; |
|
| 676 | 676 | |
| 677 | - return get_posts( $free_course_query_args ); |
|
| 677 | + return get_posts($free_course_query_args); |
|
| 678 | 678 | |
| 679 | 679 | } |
| 680 | 680 | |
@@ -684,13 +684,13 @@ discard block |
||
| 684 | 684 | * @since 1.9.0 |
| 685 | 685 | * @return array |
| 686 | 686 | */ |
| 687 | - public static function get_paid_courses(){ |
|
| 687 | + public static function get_paid_courses() { |
|
| 688 | 688 | |
| 689 | 689 | $paid_course_query_args = Sensei_Course::get_default_query_args(); |
| 690 | 690 | |
| 691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 691 | + $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args(); |
|
| 692 | 692 | |
| 693 | - return get_posts( $paid_course_query_args ); |
|
| 693 | + return get_posts($paid_course_query_args); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | /** |
@@ -705,17 +705,17 @@ discard block |
||
| 705 | 705 | * @param int $course_id |
| 706 | 706 | * @return string $html markup for the button or nothing if user not allowed to buy |
| 707 | 707 | */ |
| 708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 708 | + public static function the_add_to_cart_button_html($course_id) { |
|
| 709 | 709 | |
| 710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 710 | + if ( ! Sensei_Course::is_prerequisite_complete($course_id)) { |
|
| 711 | 711 | return ''; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 714 | + $wc_post_id = self::get_course_product_id($course_id); |
|
| 715 | 715 | |
| 716 | 716 | // Check if customer purchased the product |
| 717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | - || empty( $wc_post_id ) ) { |
|
| 717 | + if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) |
|
| 718 | + || empty($wc_post_id)) { |
|
| 719 | 719 | |
| 720 | 720 | return ''; |
| 721 | 721 | |
@@ -723,15 +723,15 @@ discard block |
||
| 723 | 723 | |
| 724 | 724 | // based on simple.php in WC templates/single-product/add-to-cart/ |
| 725 | 725 | // Get the product |
| 726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 726 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 727 | 727 | |
| 728 | 728 | // do not show the button for invalid products, non purchasable products, out |
| 729 | 729 | // of stock product or if course is already in cart |
| 730 | - if ( ! isset ( $product ) |
|
| 731 | - || ! is_object( $product ) |
|
| 730 | + if ( ! isset ($product) |
|
| 731 | + || ! is_object($product) |
|
| 732 | 732 | || ! $product->is_purchasable() |
| 733 | 733 | || ! $product->is_in_stock() |
| 734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 734 | + || self::is_course_in_cart($wc_post_id)) { |
|
| 735 | 735 | |
| 736 | 736 | return ''; |
| 737 | 737 | |
@@ -742,23 +742,23 @@ discard block |
||
| 742 | 742 | // |
| 743 | 743 | ?> |
| 744 | 744 | |
| 745 | - <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
|
| 745 | + <form action="<?php echo esc_url($product->add_to_cart_url()); ?>" |
|
| 746 | 746 | class="cart" |
| 747 | 747 | method="post" |
| 748 | 748 | enctype="multipart/form-data"> |
| 749 | 749 | |
| 750 | - <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" /> |
|
| 750 | + <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" /> |
|
| 751 | 751 | |
| 752 | 752 | <input type="hidden" name="quantity" value="1" /> |
| 753 | 753 | |
| 754 | - <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?> |
|
| 754 | + <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> |
|
| 755 | 755 | |
| 756 | 756 | <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" /> |
| 757 | - <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?> |
|
| 757 | + <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> |
|
| 758 | 758 | |
| 759 | - <?php foreach( $product->variation_data as $att => $val ) { ?> |
|
| 759 | + <?php foreach ($product->variation_data as $att => $val) { ?> |
|
| 760 | 760 | |
| 761 | - <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" /> |
|
| 761 | + <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" /> |
|
| 762 | 762 | |
| 763 | 763 | <?php } ?> |
| 764 | 764 | |
@@ -786,26 +786,26 @@ discard block |
||
| 786 | 786 | * |
| 787 | 787 | * @return string $message |
| 788 | 788 | */ |
| 789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 789 | + public static function alter_no_permissions_message($message, $post_id) { |
|
| 790 | 790 | |
| 791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 791 | + if (empty($post_id) || 'course' != get_post_type($post_id)) { |
|
| 792 | 792 | return $message; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 795 | + $product_id = self::get_course_product_id($post_id); |
|
| 796 | 796 | |
| 797 | - if( ! $product_id |
|
| 798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 797 | + if ( ! $product_id |
|
| 798 | + || self::has_customer_bought_product(get_current_user_id(), $product_id)) { |
|
| 799 | 799 | |
| 800 | 800 | return $message; |
| 801 | 801 | |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | ob_start(); |
| 805 | - self::the_course_no_permissions_message( $post_id ); |
|
| 805 | + self::the_course_no_permissions_message($post_id); |
|
| 806 | 806 | $woocommerce_course_no_permissions_message = ob_get_clean(); |
| 807 | 807 | |
| 808 | - return $woocommerce_course_no_permissions_message ; |
|
| 808 | + return $woocommerce_course_no_permissions_message; |
|
| 809 | 809 | |
| 810 | 810 | } |
| 811 | 811 | /** |
@@ -814,16 +814,16 @@ discard block |
||
| 814 | 814 | * |
| 815 | 815 | * @since 1.9.0 |
| 816 | 816 | */ |
| 817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 817 | + public static function the_course_no_permissions_message($course_id) { |
|
| 818 | 818 | |
| 819 | 819 | // login link |
| 820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 820 | + $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
| 821 | + $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>'; |
|
| 822 | 822 | |
| 823 | 823 | ?> |
| 824 | 824 | |
| 825 | 825 | <span class="add-to-cart-login"> |
| 826 | - <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
|
| 826 | + <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?> |
|
| 827 | 827 | </span> |
| 828 | 828 | |
| 829 | 829 | <?php } |
@@ -838,43 +838,43 @@ discard block |
||
| 838 | 838 | * |
| 839 | 839 | * @return bool |
| 840 | 840 | */ |
| 841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 841 | + public static function has_customer_bought_product($user_id, $product_id) { |
|
| 842 | 842 | |
| 843 | - $orders = get_posts( array( |
|
| 843 | + $orders = get_posts(array( |
|
| 844 | 844 | 'posts_per_page' => -1, |
| 845 | 845 | 'meta_key' => '_customer_user', |
| 846 | - 'meta_value' => intval( $user_id ), |
|
| 846 | + 'meta_value' => intval($user_id), |
|
| 847 | 847 | 'post_type' => 'shop_order', |
| 848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | - ) ); |
|
| 848 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 849 | + )); |
|
| 850 | 850 | |
| 851 | - foreach ( $orders as $order_id ) { |
|
| 851 | + foreach ($orders as $order_id) { |
|
| 852 | 852 | |
| 853 | - $order = new WC_Order( $order_id->ID ); |
|
| 853 | + $order = new WC_Order($order_id->ID); |
|
| 854 | 854 | |
| 855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 855 | + if ($order->post_status != 'wc-completed' && $order->post_status != 'wc-processing') { |
|
| 856 | 856 | |
| 857 | 857 | continue; |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 860 | + if ( ! (0 < sizeof($order->get_items()))) { |
|
| 861 | 861 | |
| 862 | 862 | continue; |
| 863 | 863 | |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - foreach( $order->get_items() as $item ) { |
|
| 866 | + foreach ($order->get_items() as $item) { |
|
| 867 | 867 | |
| 868 | 868 | // Check if user has bought product |
| 869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 869 | + if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) { |
|
| 870 | 870 | |
| 871 | 871 | // Check if user has an active subscription for product |
| 872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | - if( $sub_key ) { |
|
| 875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | - if( 'active' == $sub['status'] ) { |
|
| 872 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
| 873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key($order_id->ID, $product_id); |
|
| 874 | + if ($sub_key) { |
|
| 875 | + $sub = WC_Subscriptions_Manager::get_subscription($sub_key); |
|
| 876 | + if ($sub && isset($sub['status'])) { |
|
| 877 | + if ('active' == $sub['status']) { |
|
| 878 | 878 | return true; |
| 879 | 879 | } else { |
| 880 | 880 | return false; |
@@ -903,11 +903,11 @@ discard block |
||
| 903 | 903 | * @return string $woocommerce_product_id or false if none exist |
| 904 | 904 | * |
| 905 | 905 | */ |
| 906 | - public static function get_course_product_id( $course_id ){ |
|
| 906 | + public static function get_course_product_id($course_id) { |
|
| 907 | 907 | |
| 908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 908 | + $product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 909 | 909 | |
| 910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 910 | + if (empty($product_id) || 'product' != get_post_type($product_id)) { |
|
| 911 | 911 | return false; |
| 912 | 912 | } |
| 913 | 913 | |
@@ -921,11 +921,11 @@ discard block |
||
| 921 | 921 | * @param array $classes |
| 922 | 922 | * @return array |
| 923 | 923 | */ |
| 924 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 924 | + public static function add_woocommerce_body_class($classes) { |
|
| 925 | 925 | |
| 926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 926 | + if ( ! in_array('woocommerce', $classes)) { |
|
| 927 | 927 | |
| 928 | - $classes[] ='woocommerce'; |
|
| 928 | + $classes[] = 'woocommerce'; |
|
| 929 | 929 | |
| 930 | 930 | } |
| 931 | 931 | |