@@ -13,21 +13,21 @@ discard block |
||
| 13 | 13 | * @since 1.0.0 |
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course { |
| 16 | - /** |
|
| 17 | - * @var $token |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var $token |
|
| 18 | + */ |
|
| 19 | 19 | public $token; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array $meta_fields |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var array $meta_fields |
|
| 23 | + */ |
|
| 24 | 24 | public $meta_fields; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string|bool $my_courses_page reference to the sites |
|
| 28 | - * my courses page, false if none was set |
|
| 29 | - */ |
|
| 30 | - public $my_courses_page; |
|
| 26 | + /** |
|
| 27 | + * @var string|bool $my_courses_page reference to the sites |
|
| 28 | + * my courses page, false if none was set |
|
| 29 | + */ |
|
| 30 | + public $my_courses_page; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Constructor. |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | // Admin actions |
| 40 | 40 | if ( is_admin() ) { |
| 41 | 41 | // Metabox functions |
| 42 | - add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 42 | + add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 43 | 43 | add_action( 'save_post', array( $this, 'meta_box_save' ) ); |
| 44 | 44 | // Custom Write Panel Columns |
| 45 | 45 | add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
@@ -55,47 +55,47 @@ discard block |
||
| 55 | 55 | // Update course completion upon grading of a quiz |
| 56 | 56 | add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 ); |
| 57 | 57 | |
| 58 | - // show the progress bar ont he single course page |
|
| 59 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 60 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 58 | + // show the progress bar ont he single course page |
|
| 59 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 60 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 61 | 61 | |
| 62 | - // provide an option to block all emails related to a selected course |
|
| 63 | - add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 64 | - add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 62 | + // provide an option to block all emails related to a selected course |
|
| 63 | + add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 64 | + add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 65 | 65 | |
| 66 | - // preview lessons on the course content |
|
| 67 | - add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 66 | + // preview lessons on the course content |
|
| 67 | + add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 68 | 68 | |
| 69 | - // the course meta |
|
| 70 | - add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 69 | + // the course meta |
|
| 70 | + add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 71 | 71 | |
| 72 | - // backwards compatible template hooks |
|
| 73 | - add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 74 | - add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 72 | + // backwards compatible template hooks |
|
| 73 | + add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 74 | + add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 75 | 75 | |
| 76 | - // add the user status on the course to the markup as a class |
|
| 77 | - add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 76 | + // add the user status on the course to the markup as a class |
|
| 77 | + add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 78 | 78 | |
| 79 | - //filter the course query in Sensei specific instances |
|
| 80 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 79 | + //filter the course query in Sensei specific instances |
|
| 80 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 81 | 81 | |
| 82 | - //attache the sorting to the course archive |
|
| 83 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 82 | + //attache the sorting to the course archive |
|
| 83 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 84 | 84 | |
| 85 | - //attach the filter links to the course archive |
|
| 86 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 85 | + //attach the filter links to the course archive |
|
| 86 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 87 | 87 | |
| 88 | - //filter the course query when featured filter is applied |
|
| 89 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 88 | + //filter the course query when featured filter is applied |
|
| 89 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 90 | 90 | |
| 91 | - // handle the order by title post submission |
|
| 92 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 91 | + // handle the order by title post submission |
|
| 92 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 93 | 93 | |
| 94 | - // ensure the course category page respects the manual order set for courses |
|
| 95 | - add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 94 | + // ensure the course category page respects the manual order set for courses |
|
| 95 | + add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 96 | 96 | |
| 97 | - // flush rewrite rules when saving a course |
|
| 98 | - add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 97 | + // flush rewrite rules when saving a course |
|
| 98 | + add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 99 | 99 | |
| 100 | 100 | } // End __construct() |
| 101 | 101 | |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 149 | 149 | // Add Meta Box for Course Lessons |
| 150 | 150 | add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 151 | - // Add Meta Box to link to Manage Learners |
|
| 152 | - add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 153 | - // Remove "Custom Settings" meta box. |
|
| 151 | + // Add Meta Box to link to Manage Learners |
|
| 152 | + add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 153 | + // Remove "Custom Settings" meta box. |
|
| 154 | 154 | remove_meta_box( 'woothemes-settings', $this->token, 'normal' ); |
| 155 | 155 | |
| 156 | - // add Disable email notification box |
|
| 157 | - add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 156 | + // add Disable email notification box |
|
| 157 | + add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 158 | 158 | |
| 159 | 159 | } // End meta_box_setup() |
| 160 | 160 | |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | $post_args = array( 'post_type' => array( 'product', 'product_variation' ), |
| 173 | 173 | 'posts_per_page' => -1, |
| 174 | 174 | 'orderby' => 'title', |
| 175 | - 'order' => 'DESC', |
|
| 176 | - 'exclude' => $post->ID, |
|
| 177 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 178 | - 'tax_query' => array( |
|
| 175 | + 'order' => 'DESC', |
|
| 176 | + 'exclude' => $post->ID, |
|
| 177 | + 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 178 | + 'tax_query' => array( |
|
| 179 | 179 | array( |
| 180 | 180 | 'taxonomy' => 'product_type', |
| 181 | 181 | 'field' => 'slug', |
@@ -203,21 +203,21 @@ discard block |
||
| 203 | 203 | $product_object = get_product( $post_item->ID ); |
| 204 | 204 | $parent_id = wp_get_post_parent_id( $post_item->ID ); |
| 205 | 205 | |
| 206 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 206 | + if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 207 | 207 | $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
| 208 | 208 | |
| 209 | 209 | } else { |
| 210 | - // fall back to pre wc 2.1 |
|
| 210 | + // fall back to pre wc 2.1 |
|
| 211 | 211 | $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
| 212 | 212 | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - $product_name = ucwords( $formatted_variation ); |
|
| 216 | - if( empty( $product_name ) ){ |
|
| 215 | + $product_name = ucwords( $formatted_variation ); |
|
| 216 | + if( empty( $product_name ) ){ |
|
| 217 | 217 | |
| 218 | - $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 218 | + $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 219 | 219 | |
| 220 | - } |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | } else { |
| 223 | 223 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | } else { |
| 269 | 269 | |
| 270 | - $html .= '<p>' . "\n"; |
|
| 270 | + $html .= '<p>' . "\n"; |
|
| 271 | 271 | $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n"; |
| 272 | 272 | $html .= '</p>'."\n"; |
| 273 | 273 | |
@@ -293,8 +293,8 @@ discard block |
||
| 293 | 293 | $post_args = array( 'post_type' => 'course', |
| 294 | 294 | 'posts_per_page' => -1, |
| 295 | 295 | 'orderby' => 'title', |
| 296 | - 'order' => 'DESC', |
|
| 297 | - 'exclude' => $post->ID, |
|
| 296 | + 'order' => 'DESC', |
|
| 297 | + 'exclude' => $post->ID, |
|
| 298 | 298 | 'suppress_filters' => 0 |
| 299 | 299 | ); |
| 300 | 300 | $posts_array = get_posts( $post_args ); |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | $checked = ''; |
| 337 | 337 | if ( isset( $course_featured ) && ( '' != $course_featured ) ) { |
| 338 | - $checked = checked( 'featured', $course_featured, false ); |
|
| 338 | + $checked = checked( 'featured', $course_featured, false ); |
|
| 339 | 339 | } // End If Statement |
| 340 | 340 | |
| 341 | 341 | $html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '> ' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>'; |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
| 431 | 431 | } // End If Statement |
| 432 | 432 | |
| 433 | - // update field with the new value |
|
| 434 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 433 | + // update field with the new value |
|
| 434 | + return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 435 | 435 | |
| 436 | 436 | } // End save_post_meta() |
| 437 | 437 | |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | |
| 456 | 456 | $html = ''; |
| 457 | 457 | $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' |
| 458 | - . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 459 | - . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 458 | + . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 459 | + . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 460 | 460 | |
| 461 | 461 | if ( count( $posts_array ) > 0 ) { |
| 462 | 462 | |
@@ -477,8 +477,8 @@ discard block |
||
| 477 | 477 | $html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n"; |
| 478 | 478 | |
| 479 | 479 | $html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id ) |
| 480 | - . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 481 | - . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 480 | + . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 481 | + . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 482 | 482 | |
| 483 | 483 | $html .= '</p>'."\n"; |
| 484 | 484 | } // End If Statement |
@@ -487,29 +487,29 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | } // End course_lessons_meta_box_content() |
| 489 | 489 | |
| 490 | - /** |
|
| 491 | - * course_manage_meta_box_content function. |
|
| 492 | - * |
|
| 493 | - * @since 1.9.0 |
|
| 494 | - * @access public |
|
| 495 | - * @return void |
|
| 496 | - */ |
|
| 490 | + /** |
|
| 491 | + * course_manage_meta_box_content function. |
|
| 492 | + * |
|
| 493 | + * @since 1.9.0 |
|
| 494 | + * @access public |
|
| 495 | + * @return void |
|
| 496 | + */ |
|
| 497 | 497 | |
| 498 | - public function course_manage_meta_box_content () { |
|
| 499 | - global $post; |
|
| 498 | + public function course_manage_meta_box_content () { |
|
| 499 | + global $post; |
|
| 500 | 500 | |
| 501 | - $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 501 | + $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 502 | 502 | |
| 503 | - $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 503 | + $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 504 | 504 | |
| 505 | 505 | |
| 506 | - echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 506 | + echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 507 | 507 | |
| 508 | - echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 508 | + echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 509 | 509 | |
| 510 | 510 | |
| 511 | 511 | |
| 512 | - } // End course_manage_meta_box_content() |
|
| 512 | + } // End course_manage_meta_box_content() |
|
| 513 | 513 | |
| 514 | 514 | /** |
| 515 | 515 | * Add column headings to the "lesson" post list screen. |
@@ -650,92 +650,92 @@ discard block |
||
| 650 | 650 | } // End If Statement |
| 651 | 651 | } // End If Statement |
| 652 | 652 | |
| 653 | - $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 654 | - $order = 'ASC'; |
|
| 655 | - $orderby = 'menu_order'; |
|
| 656 | - if( empty( $stored_order ) ){ |
|
| 653 | + $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 654 | + $order = 'ASC'; |
|
| 655 | + $orderby = 'menu_order'; |
|
| 656 | + if( empty( $stored_order ) ){ |
|
| 657 | 657 | |
| 658 | - $order = 'DESC'; |
|
| 659 | - $orderby = 'date'; |
|
| 658 | + $order = 'DESC'; |
|
| 659 | + $orderby = 'date'; |
|
| 660 | 660 | |
| 661 | - } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | 663 | switch ($type) { |
| 664 | 664 | |
| 665 | 665 | case 'usercourses': |
| 666 | 666 | $post_args = array( 'post_type' => 'course', |
| 667 | 667 | 'orderby' => $orderby, |
| 668 | - 'order' => $order, |
|
| 669 | - 'post_status' => 'publish', |
|
| 670 | - 'include' => $includes, |
|
| 671 | - 'exclude' => $excludes, |
|
| 672 | - 'suppress_filters' => 0 |
|
| 668 | + 'order' => $order, |
|
| 669 | + 'post_status' => 'publish', |
|
| 670 | + 'include' => $includes, |
|
| 671 | + 'exclude' => $excludes, |
|
| 672 | + 'suppress_filters' => 0 |
|
| 673 | 673 | ); |
| 674 | 674 | break; |
| 675 | 675 | case 'freecourses': |
| 676 | 676 | |
| 677 | - $post_args = array( |
|
| 678 | - 'post_type' => 'course', |
|
| 679 | - 'orderby' => $orderby, |
|
| 680 | - 'order' => $order, |
|
| 681 | - 'post_status' => 'publish', |
|
| 682 | - 'exclude' => $excludes, |
|
| 683 | - 'suppress_filters' => 0 |
|
| 684 | - ); |
|
| 685 | - // Sub Query to get all WooCommerce Products that have Zero price |
|
| 686 | - $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 677 | + $post_args = array( |
|
| 678 | + 'post_type' => 'course', |
|
| 679 | + 'orderby' => $orderby, |
|
| 680 | + 'order' => $order, |
|
| 681 | + 'post_status' => 'publish', |
|
| 682 | + 'exclude' => $excludes, |
|
| 683 | + 'suppress_filters' => 0 |
|
| 684 | + ); |
|
| 685 | + // Sub Query to get all WooCommerce Products that have Zero price |
|
| 686 | + $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 687 | 687 | |
| 688 | - break; |
|
| 688 | + break; |
|
| 689 | 689 | |
| 690 | 690 | case 'paidcourses': |
| 691 | 691 | |
| 692 | - $post_args = array( |
|
| 693 | - 'post_type' => 'course', |
|
| 694 | - 'orderby' => $orderby, |
|
| 695 | - 'order' => $order, |
|
| 696 | - 'post_status' => 'publish', |
|
| 697 | - 'exclude' => $excludes, |
|
| 698 | - 'suppress_filters' => 0 |
|
| 699 | - ); |
|
| 692 | + $post_args = array( |
|
| 693 | + 'post_type' => 'course', |
|
| 694 | + 'orderby' => $orderby, |
|
| 695 | + 'order' => $order, |
|
| 696 | + 'post_status' => 'publish', |
|
| 697 | + 'exclude' => $excludes, |
|
| 698 | + 'suppress_filters' => 0 |
|
| 699 | + ); |
|
| 700 | 700 | |
| 701 | - // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 702 | - $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 701 | + // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 702 | + $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 703 | 703 | |
| 704 | 704 | break; |
| 705 | 705 | |
| 706 | 706 | case 'featuredcourses': |
| 707 | - $post_args = array( 'post_type' => 'course', |
|
| 708 | - 'orderby' => $orderby, |
|
| 709 | - 'order' => $order, |
|
| 710 | - 'post_status' => 'publish', |
|
| 711 | - 'meta_value' => 'featured', |
|
| 712 | - 'meta_key' => '_course_featured', |
|
| 713 | - 'meta_compare' => '=', |
|
| 714 | - 'exclude' => $excludes, |
|
| 715 | - 'suppress_filters' => 0 |
|
| 707 | + $post_args = array( 'post_type' => 'course', |
|
| 708 | + 'orderby' => $orderby, |
|
| 709 | + 'order' => $order, |
|
| 710 | + 'post_status' => 'publish', |
|
| 711 | + 'meta_value' => 'featured', |
|
| 712 | + 'meta_key' => '_course_featured', |
|
| 713 | + 'meta_compare' => '=', |
|
| 714 | + 'exclude' => $excludes, |
|
| 715 | + 'suppress_filters' => 0 |
|
| 716 | 716 | ); |
| 717 | 717 | break; |
| 718 | 718 | default: |
| 719 | 719 | $post_args = array( 'post_type' => 'course', |
| 720 | - 'orderby' => $orderby, |
|
| 721 | - 'order' => $order, |
|
| 722 | - 'post_status' => 'publish', |
|
| 723 | - 'exclude' => $excludes, |
|
| 724 | - 'suppress_filters' => 0 |
|
| 720 | + 'orderby' => $orderby, |
|
| 721 | + 'order' => $order, |
|
| 722 | + 'post_status' => 'publish', |
|
| 723 | + 'exclude' => $excludes, |
|
| 724 | + 'suppress_filters' => 0 |
|
| 725 | 725 | ); |
| 726 | 726 | break; |
| 727 | 727 | |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - $post_args['posts_per_page'] = $amount; |
|
| 731 | - $paged = $wp_query->get( 'paged' ); |
|
| 732 | - $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 730 | + $post_args['posts_per_page'] = $amount; |
|
| 731 | + $paged = $wp_query->get( 'paged' ); |
|
| 732 | + $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 733 | 733 | |
| 734 | - if( 'newcourses' == $type ){ |
|
| 734 | + if( 'newcourses' == $type ){ |
|
| 735 | 735 | |
| 736 | - $post_args[ 'orderby' ] = 'date'; |
|
| 737 | - $post_args[ 'order' ] = 'DESC'; |
|
| 738 | - } |
|
| 736 | + $post_args[ 'orderby' ] = 'date'; |
|
| 737 | + $post_args[ 'order' ] = 'DESC'; |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | return $post_args; |
| 741 | 741 | } |
@@ -745,22 +745,22 @@ discard block |
||
| 745 | 745 | * course_image function. |
| 746 | 746 | * |
| 747 | 747 | * Outputs the courses image, or first image from a lesson within a course |
| 748 | - * |
|
| 749 | - * Will echo the image unless return true is specified. |
|
| 748 | + * |
|
| 749 | + * Will echo the image unless return true is specified. |
|
| 750 | 750 | * |
| 751 | 751 | * @access public |
| 752 | 752 | * @param int | WP_Post $course_id (default: 0) |
| 753 | 753 | * @param string $width (default: '100') |
| 754 | 754 | * @param string $height (default: '100') |
| 755 | - * @param bool $return default false |
|
| 756 | - * |
|
| 755 | + * @param bool $return default false |
|
| 756 | + * |
|
| 757 | 757 | * @return string | void |
| 758 | 758 | */ |
| 759 | 759 | public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) { |
| 760 | 760 | |
| 761 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 762 | - $course_id = $course_id->ID; |
|
| 763 | - } |
|
| 761 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 762 | + $course_id = $course_id->ID; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | $html = ''; |
| 766 | 766 | |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | // Display Image Placeholder if none |
| 818 | 818 | if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) { |
| 819 | 819 | |
| 820 | - $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 820 | + $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 821 | 821 | |
| 822 | 822 | } // End If Statement |
| 823 | 823 | |
@@ -831,15 +831,15 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | } // End If Statement |
| 833 | 833 | |
| 834 | - if( $return ){ |
|
| 834 | + if( $return ){ |
|
| 835 | 835 | |
| 836 | - return $html; |
|
| 836 | + return $html; |
|
| 837 | 837 | |
| 838 | - }else{ |
|
| 838 | + }else{ |
|
| 839 | 839 | |
| 840 | - echo $html; |
|
| 840 | + echo $html; |
|
| 841 | 841 | |
| 842 | - } |
|
| 842 | + } |
|
| 843 | 843 | |
| 844 | 844 | } // End course_image() |
| 845 | 845 | |
@@ -883,9 +883,9 @@ discard block |
||
| 883 | 883 | */ |
| 884 | 884 | public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) { |
| 885 | 885 | |
| 886 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 887 | - $course_id = $course_id->ID; |
|
| 888 | - } |
|
| 886 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 887 | + $course_id = $course_id->ID; |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | 890 | $post_args = array( 'post_type' => 'lesson', |
| 891 | 891 | 'posts_per_page' => -1, |
@@ -901,67 +901,67 @@ discard block |
||
| 901 | 901 | 'suppress_filters' => 0, |
| 902 | 902 | ); |
| 903 | 903 | $query_results = new WP_Query( $post_args ); |
| 904 | - $lessons = $query_results->posts; |
|
| 905 | - |
|
| 906 | - // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 907 | - // with the course order for a different course and this should not be included. It could also not |
|
| 908 | - // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 909 | - // that have been added to the course. |
|
| 910 | - if( count( $lessons) > 1 ){ |
|
| 911 | - |
|
| 912 | - foreach( $lessons as $lesson ){ |
|
| 913 | - |
|
| 914 | - $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 915 | - // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 916 | - $lesson->course_order = $order ? $order : 100000; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - /** |
|
| 923 | - * Filter runs inside Sensei_Course::course_lessons function |
|
| 924 | - * |
|
| 925 | - * Returns all lessons for a given course |
|
| 926 | - * |
|
| 927 | - * @param array $lessons |
|
| 928 | - * @param int $course_id |
|
| 929 | - */ |
|
| 930 | - $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 931 | - |
|
| 932 | - //return the requested fields |
|
| 933 | - // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 934 | - // objects |
|
| 935 | - if( 'ids' == $fields ) { |
|
| 936 | - $lesson_objects = $lessons; |
|
| 937 | - $lessons = array(); |
|
| 938 | - |
|
| 939 | - foreach ($lesson_objects as $lesson) { |
|
| 940 | - $lessons[] = $lesson->ID; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - return $lessons; |
|
| 904 | + $lessons = $query_results->posts; |
|
| 905 | + |
|
| 906 | + // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 907 | + // with the course order for a different course and this should not be included. It could also not |
|
| 908 | + // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 909 | + // that have been added to the course. |
|
| 910 | + if( count( $lessons) > 1 ){ |
|
| 911 | + |
|
| 912 | + foreach( $lessons as $lesson ){ |
|
| 913 | + |
|
| 914 | + $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 915 | + // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 916 | + $lesson->course_order = $order ? $order : 100000; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + /** |
|
| 923 | + * Filter runs inside Sensei_Course::course_lessons function |
|
| 924 | + * |
|
| 925 | + * Returns all lessons for a given course |
|
| 926 | + * |
|
| 927 | + * @param array $lessons |
|
| 928 | + * @param int $course_id |
|
| 929 | + */ |
|
| 930 | + $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 931 | + |
|
| 932 | + //return the requested fields |
|
| 933 | + // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 934 | + // objects |
|
| 935 | + if( 'ids' == $fields ) { |
|
| 936 | + $lesson_objects = $lessons; |
|
| 937 | + $lessons = array(); |
|
| 938 | + |
|
| 939 | + foreach ($lesson_objects as $lesson) { |
|
| 940 | + $lessons[] = $lesson->ID; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + return $lessons; |
|
| 945 | 945 | |
| 946 | 946 | } // End course_lessons() |
| 947 | 947 | |
| 948 | - /** |
|
| 949 | - * Used for the uasort in $this->course_lessons() |
|
| 950 | - * @since 1.8.0 |
|
| 951 | - * @access protected |
|
| 952 | - * |
|
| 953 | - * @param array $lesson_1 |
|
| 954 | - * @param array $lesson_2 |
|
| 955 | - * @return int |
|
| 956 | - */ |
|
| 957 | - protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 948 | + /** |
|
| 949 | + * Used for the uasort in $this->course_lessons() |
|
| 950 | + * @since 1.8.0 |
|
| 951 | + * @access protected |
|
| 952 | + * |
|
| 953 | + * @param array $lesson_1 |
|
| 954 | + * @param array $lesson_2 |
|
| 955 | + * @return int |
|
| 956 | + */ |
|
| 957 | + protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 958 | 958 | |
| 959 | - if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 960 | - return 0; |
|
| 961 | - } |
|
| 959 | + if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 960 | + return 0; |
|
| 961 | + } |
|
| 962 | 962 | |
| 963 | - return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 964 | - } |
|
| 963 | + return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | 966 | /** |
| 967 | 967 | * Fetch all quiz ids in a course |
@@ -1024,15 +1024,15 @@ discard block |
||
| 1024 | 1024 | */ |
| 1025 | 1025 | public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) { |
| 1026 | 1026 | |
| 1027 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1027 | + $lesson_args = array( 'post_type' => 'lesson', |
|
| 1028 | 1028 | 'posts_per_page' => -1, |
| 1029 | - 'author' => $author_id, |
|
| 1030 | - 'meta_key' => '_lesson_course', |
|
| 1031 | - 'meta_value' => $course_id, |
|
| 1032 | - 'post_status' => 'publish', |
|
| 1033 | - 'suppress_filters' => 0, |
|
| 1029 | + 'author' => $author_id, |
|
| 1030 | + 'meta_key' => '_lesson_course', |
|
| 1031 | + 'meta_value' => $course_id, |
|
| 1032 | + 'post_status' => 'publish', |
|
| 1033 | + 'suppress_filters' => 0, |
|
| 1034 | 1034 | 'fields' => 'ids', // less data to retrieve |
| 1035 | - ); |
|
| 1035 | + ); |
|
| 1036 | 1036 | $lessons_array = get_posts( $lesson_args ); |
| 1037 | 1037 | $count = count( $lessons_array ); |
| 1038 | 1038 | return $count; |
@@ -1050,17 +1050,17 @@ discard block |
||
| 1050 | 1050 | |
| 1051 | 1051 | $lesson_args = array( 'post_type' => 'lesson', |
| 1052 | 1052 | 'posts_per_page' => -1, |
| 1053 | - 'meta_key' => '_lesson_course', |
|
| 1054 | - 'meta_value' => $course_id, |
|
| 1055 | - 'post_status' => 'publish', |
|
| 1056 | - 'suppress_filters' => 0, |
|
| 1053 | + 'meta_key' => '_lesson_course', |
|
| 1054 | + 'meta_value' => $course_id, |
|
| 1055 | + 'post_status' => 'publish', |
|
| 1056 | + 'suppress_filters' => 0, |
|
| 1057 | 1057 | 'fields' => 'ids', // less data to retrieve |
| 1058 | - ); |
|
| 1058 | + ); |
|
| 1059 | 1059 | $lessons_array = get_posts( $lesson_args ); |
| 1060 | 1060 | |
| 1061 | - $count = count( $lessons_array ); |
|
| 1061 | + $count = count( $lessons_array ); |
|
| 1062 | 1062 | |
| 1063 | - return $count; |
|
| 1063 | + return $count; |
|
| 1064 | 1064 | |
| 1065 | 1065 | } // End course_lesson_count() |
| 1066 | 1066 | |
@@ -1075,9 +1075,9 @@ discard block |
||
| 1075 | 1075 | |
| 1076 | 1076 | $lesson_args = array( 'post_type' => 'lesson', |
| 1077 | 1077 | 'posts_per_page' => -1, |
| 1078 | - 'post_status' => 'publish', |
|
| 1079 | - 'suppress_filters' => 0, |
|
| 1080 | - 'meta_query' => array( |
|
| 1078 | + 'post_status' => 'publish', |
|
| 1079 | + 'suppress_filters' => 0, |
|
| 1080 | + 'meta_query' => array( |
|
| 1081 | 1081 | array( |
| 1082 | 1082 | 'key' => '_lesson_course', |
| 1083 | 1083 | 'value' => $course_id |
@@ -1088,12 +1088,12 @@ discard block |
||
| 1088 | 1088 | ) |
| 1089 | 1089 | ), |
| 1090 | 1090 | 'fields' => 'ids', // less data to retrieve |
| 1091 | - ); |
|
| 1091 | + ); |
|
| 1092 | 1092 | $lessons_array = get_posts( $lesson_args ); |
| 1093 | 1093 | |
| 1094 | 1094 | $count = count( $lessons_array ); |
| 1095 | 1095 | |
| 1096 | - return $count; |
|
| 1096 | + return $count; |
|
| 1097 | 1097 | |
| 1098 | 1098 | } // End course_lesson_count() |
| 1099 | 1099 | |
@@ -1112,8 +1112,8 @@ discard block |
||
| 1112 | 1112 | $post_args = array( 'post_type' => 'course', |
| 1113 | 1113 | 'posts_per_page' => -1, |
| 1114 | 1114 | 'meta_key' => '_course_woocommerce_product', |
| 1115 | - 'meta_value' => $product_id, |
|
| 1116 | - 'post_status' => 'publish', |
|
| 1115 | + 'meta_value' => $product_id, |
|
| 1116 | + 'post_status' => 'publish', |
|
| 1117 | 1117 | 'suppress_filters' => 0, |
| 1118 | 1118 | 'orderby' => 'menu_order date', |
| 1119 | 1119 | 'order' => 'ASC', |
@@ -1154,9 +1154,9 @@ discard block |
||
| 1154 | 1154 | |
| 1155 | 1155 | /** |
| 1156 | 1156 | * load_user_courses_content generates HTML for user's active & completed courses |
| 1157 | - * |
|
| 1158 | - * This function also ouputs the html so no need to echo the content. |
|
| 1159 | - * |
|
| 1157 | + * |
|
| 1158 | + * This function also ouputs the html so no need to echo the content. |
|
| 1159 | + * |
|
| 1160 | 1160 | * @since 1.4.0 |
| 1161 | 1161 | * @param object $user Queried user object |
| 1162 | 1162 | * @param boolean $manage Whether the user has permission to manage the courses |
@@ -1165,17 +1165,17 @@ discard block |
||
| 1165 | 1165 | public function load_user_courses_content( $user = false ) { |
| 1166 | 1166 | global $course, $my_courses_page, $my_courses_section; |
| 1167 | 1167 | |
| 1168 | - if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1169 | - || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1168 | + if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1169 | + || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1170 | 1170 | |
| 1171 | - // do not show the content if the settings doesn't allow for it |
|
| 1172 | - return; |
|
| 1171 | + // do not show the content if the settings doesn't allow for it |
|
| 1172 | + return; |
|
| 1173 | 1173 | |
| 1174 | - } |
|
| 1174 | + } |
|
| 1175 | 1175 | |
| 1176 | - $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1176 | + $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1177 | 1177 | |
| 1178 | - do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1178 | + do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1179 | 1179 | |
| 1180 | 1180 | // Build Output HTML |
| 1181 | 1181 | $complete_html = $active_html = ''; |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | // Logic for Active and Completed Courses |
| 1191 | 1191 | $per_page = 20; |
| 1192 | 1192 | if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) |
| 1193 | - && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1193 | + && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1194 | 1194 | |
| 1195 | 1195 | $per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
| 1196 | 1196 | |
@@ -1236,111 +1236,111 @@ discard block |
||
| 1236 | 1236 | } |
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | - // Get Course Categories |
|
| 1240 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1239 | + // Get Course Categories |
|
| 1240 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1241 | 1241 | |
| 1242 | - $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1242 | + $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1243 | 1243 | |
| 1244 | - // Image |
|
| 1245 | - $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1244 | + // Image |
|
| 1245 | + $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1246 | 1246 | |
| 1247 | - // Title |
|
| 1248 | - $active_html .= '<header>'; |
|
| 1247 | + // Title |
|
| 1248 | + $active_html .= '<header>'; |
|
| 1249 | 1249 | |
| 1250 | - $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1250 | + $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1251 | 1251 | |
| 1252 | - $active_html .= '</header>'; |
|
| 1252 | + $active_html .= '</header>'; |
|
| 1253 | 1253 | |
| 1254 | - $active_html .= '<section class="entry">'; |
|
| 1254 | + $active_html .= '<section class="entry">'; |
|
| 1255 | 1255 | |
| 1256 | - $active_html .= '<p class="sensei-course-meta">'; |
|
| 1256 | + $active_html .= '<p class="sensei-course-meta">'; |
|
| 1257 | 1257 | |
| 1258 | - // Author |
|
| 1259 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1260 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1261 | - && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1258 | + // Author |
|
| 1259 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1260 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1261 | + && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1262 | 1262 | |
| 1263 | - $active_html .= '<span class="course-author">' |
|
| 1264 | - . __( 'by ', 'woothemes-sensei' ) |
|
| 1265 | - . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1266 | - . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1267 | - . esc_html( $user_info->display_name ) |
|
| 1268 | - . '</a></span>'; |
|
| 1263 | + $active_html .= '<span class="course-author">' |
|
| 1264 | + . __( 'by ', 'woothemes-sensei' ) |
|
| 1265 | + . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1266 | + . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1267 | + . esc_html( $user_info->display_name ) |
|
| 1268 | + . '</a></span>'; |
|
| 1269 | 1269 | |
| 1270 | - } // End If Statement |
|
| 1270 | + } // End If Statement |
|
| 1271 | 1271 | |
| 1272 | - // Lesson count for this author |
|
| 1273 | - $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1274 | - // Handle Division by Zero |
|
| 1275 | - if ( 0 == $lesson_count ) { |
|
| 1272 | + // Lesson count for this author |
|
| 1273 | + $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1274 | + // Handle Division by Zero |
|
| 1275 | + if ( 0 == $lesson_count ) { |
|
| 1276 | 1276 | |
| 1277 | - $lesson_count = 1; |
|
| 1277 | + $lesson_count = 1; |
|
| 1278 | 1278 | |
| 1279 | - } // End If Statement |
|
| 1280 | - $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1281 | - // Course Categories |
|
| 1282 | - if ( '' != $category_output ) { |
|
| 1279 | + } // End If Statement |
|
| 1280 | + $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1281 | + // Course Categories |
|
| 1282 | + if ( '' != $category_output ) { |
|
| 1283 | 1283 | |
| 1284 | - $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1284 | + $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1285 | 1285 | |
| 1286 | - } // End If Statement |
|
| 1287 | - $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1286 | + } // End If Statement |
|
| 1287 | + $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1288 | 1288 | |
| 1289 | - $active_html .= '</p>'; |
|
| 1289 | + $active_html .= '</p>'; |
|
| 1290 | 1290 | |
| 1291 | - $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1291 | + $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1292 | 1292 | |
| 1293 | 1293 | |
| 1294 | 1294 | |
| 1295 | - $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1295 | + $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1296 | 1296 | |
| 1297 | - $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1297 | + $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1298 | 1298 | |
| 1299 | - $active_html .= '</section>'; |
|
| 1299 | + $active_html .= '</section>'; |
|
| 1300 | 1300 | |
| 1301 | - if( is_user_logged_in() ) { |
|
| 1301 | + if( is_user_logged_in() ) { |
|
| 1302 | 1302 | |
| 1303 | - $active_html .= '<section class="entry-actions">'; |
|
| 1303 | + $active_html .= '<section class="entry-actions">'; |
|
| 1304 | 1304 | |
| 1305 | - $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1305 | + $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1306 | 1306 | |
| 1307 | - $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1307 | + $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1308 | 1308 | |
| 1309 | - $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1309 | + $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1310 | 1310 | |
| 1311 | - if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1311 | + if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1312 | 1312 | |
| 1313 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1314 | - . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1313 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1314 | + . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1315 | 1315 | |
| 1316 | - } // End If Statement |
|
| 1316 | + } // End If Statement |
|
| 1317 | 1317 | |
| 1318 | - $course_purchased = false; |
|
| 1319 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1318 | + $course_purchased = false; |
|
| 1319 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1320 | 1320 | |
| 1321 | - // Get the product ID |
|
| 1322 | - $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1323 | - if ( 0 < $wc_post_id ) { |
|
| 1321 | + // Get the product ID |
|
| 1322 | + $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1323 | + if ( 0 < $wc_post_id ) { |
|
| 1324 | 1324 | |
| 1325 | - $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1325 | + $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1326 | 1326 | |
| 1327 | - } // End If Statement |
|
| 1327 | + } // End If Statement |
|
| 1328 | 1328 | |
| 1329 | - } // End If Statement |
|
| 1329 | + } // End If Statement |
|
| 1330 | 1330 | |
| 1331 | - if ( false == $course_purchased ) { |
|
| 1331 | + if ( false == $course_purchased ) { |
|
| 1332 | 1332 | |
| 1333 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1334 | - . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1333 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1334 | + . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1335 | 1335 | |
| 1336 | - } // End If Statement |
|
| 1336 | + } // End If Statement |
|
| 1337 | 1337 | |
| 1338 | - $active_html .= '</form>'; |
|
| 1338 | + $active_html .= '</form>'; |
|
| 1339 | 1339 | |
| 1340 | - $active_html .= '</section>'; |
|
| 1341 | - } |
|
| 1340 | + $active_html .= '</section>'; |
|
| 1341 | + } |
|
| 1342 | 1342 | |
| 1343 | - $active_html .= '</article>'; |
|
| 1343 | + $active_html .= '</article>'; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | // Active pagination |
@@ -1380,49 +1380,49 @@ discard block |
||
| 1380 | 1380 | foreach ( $completed_courses as $course_item ) { |
| 1381 | 1381 | $course = $course_item; |
| 1382 | 1382 | |
| 1383 | - // Get Course Categories |
|
| 1384 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1383 | + // Get Course Categories |
|
| 1384 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1385 | 1385 | |
| 1386 | - $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1386 | + $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1387 | 1387 | |
| 1388 | - // Image |
|
| 1389 | - $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1388 | + // Image |
|
| 1389 | + $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1390 | 1390 | |
| 1391 | - // Title |
|
| 1392 | - $complete_html .= '<header>'; |
|
| 1391 | + // Title |
|
| 1392 | + $complete_html .= '<header>'; |
|
| 1393 | 1393 | |
| 1394 | - $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1394 | + $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1395 | 1395 | |
| 1396 | - $complete_html .= '</header>'; |
|
| 1396 | + $complete_html .= '</header>'; |
|
| 1397 | 1397 | |
| 1398 | - $complete_html .= '<section class="entry">'; |
|
| 1398 | + $complete_html .= '<section class="entry">'; |
|
| 1399 | 1399 | |
| 1400 | - $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1400 | + $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1401 | 1401 | |
| 1402 | - // Author |
|
| 1403 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1404 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1405 | - $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1406 | - } // End If Statement |
|
| 1402 | + // Author |
|
| 1403 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1404 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1405 | + $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1406 | + } // End If Statement |
|
| 1407 | 1407 | |
| 1408 | - // Lesson count for this author |
|
| 1409 | - $complete_html .= '<span class="course-lesson-count">' |
|
| 1410 | - . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1411 | - . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1412 | - . '</span>'; |
|
| 1408 | + // Lesson count for this author |
|
| 1409 | + $complete_html .= '<span class="course-lesson-count">' |
|
| 1410 | + . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1411 | + . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1412 | + . '</span>'; |
|
| 1413 | 1413 | |
| 1414 | - // Course Categories |
|
| 1415 | - if ( '' != $category_output ) { |
|
| 1414 | + // Course Categories |
|
| 1415 | + if ( '' != $category_output ) { |
|
| 1416 | 1416 | |
| 1417 | - $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1417 | + $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1418 | 1418 | |
| 1419 | - } // End If Statement |
|
| 1419 | + } // End If Statement |
|
| 1420 | 1420 | |
| 1421 | 1421 | $complete_html .= '</p>'; |
| 1422 | 1422 | |
| 1423 | 1423 | $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
| 1424 | 1424 | |
| 1425 | - $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1425 | + $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1426 | 1426 | |
| 1427 | 1427 | if( $manage ) { |
| 1428 | 1428 | $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true ); |
@@ -1435,9 +1435,9 @@ discard block |
||
| 1435 | 1435 | if( $has_quizzes ) { |
| 1436 | 1436 | |
| 1437 | 1437 | $results_link = '<a class="button view-results" href="' |
| 1438 | - . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1439 | - . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1440 | - . '</a>'; |
|
| 1438 | + . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1439 | + . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1440 | + . '</a>'; |
|
| 1441 | 1441 | } |
| 1442 | 1442 | $complete_html .= apply_filters( 'sensei_results_links', $results_link ); |
| 1443 | 1443 | $complete_html .= '</p>'; |
@@ -1445,9 +1445,9 @@ discard block |
||
| 1445 | 1445 | } |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | - $complete_html .= '</section>'; |
|
| 1448 | + $complete_html .= '</section>'; |
|
| 1449 | 1449 | |
| 1450 | - $complete_html .= '</article>'; |
|
| 1450 | + $complete_html .= '</article>'; |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | // Active pagination |
@@ -1522,16 +1522,16 @@ discard block |
||
| 1522 | 1522 | <?php do_action( 'sensei_before_active_user_courses' ); ?> |
| 1523 | 1523 | |
| 1524 | 1524 | <?php |
| 1525 | - $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1526 | - ?> |
|
| 1525 | + $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1526 | + ?> |
|
| 1527 | 1527 | |
| 1528 | 1528 | <div id="active-courses"> |
| 1529 | 1529 | |
| 1530 | 1530 | <?php if ( '' != $active_html ) { |
| 1531 | 1531 | |
| 1532 | - echo $active_html; |
|
| 1532 | + echo $active_html; |
|
| 1533 | 1533 | |
| 1534 | - } else { ?> |
|
| 1534 | + } else { ?> |
|
| 1535 | 1535 | |
| 1536 | 1536 | <div class="sensei-message info"> |
| 1537 | 1537 | |
@@ -1557,9 +1557,9 @@ discard block |
||
| 1557 | 1557 | |
| 1558 | 1558 | <?php if ( '' != $complete_html ) { |
| 1559 | 1559 | |
| 1560 | - echo $complete_html; |
|
| 1560 | + echo $complete_html; |
|
| 1561 | 1561 | |
| 1562 | - } else { ?> |
|
| 1562 | + } else { ?> |
|
| 1563 | 1563 | |
| 1564 | 1564 | <div class="sensei-message info"> |
| 1565 | 1565 | |
@@ -1578,366 +1578,366 @@ discard block |
||
| 1578 | 1578 | <?php do_action( 'sensei_after_user_courses' ); ?> |
| 1579 | 1579 | |
| 1580 | 1580 | <?php |
| 1581 | - echo ob_get_clean(); |
|
| 1581 | + echo ob_get_clean(); |
|
| 1582 | 1582 | |
| 1583 | - do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1583 | + do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1584 | 1584 | |
| 1585 | 1585 | } // end load_user_courses_content |
| 1586 | 1586 | |
| 1587 | - /** |
|
| 1588 | - * Returns a list of all courses |
|
| 1589 | - * |
|
| 1590 | - * @since 1.8.0 |
|
| 1591 | - * @return array $courses{ |
|
| 1592 | - * @type $course WP_Post |
|
| 1593 | - * } |
|
| 1594 | - */ |
|
| 1595 | - public static function get_all_courses(){ |
|
| 1596 | - |
|
| 1597 | - $args = array( |
|
| 1598 | - 'post_type' => 'course', |
|
| 1599 | - 'posts_per_page' => -1, |
|
| 1600 | - 'orderby' => 'title', |
|
| 1601 | - 'order' => 'ASC', |
|
| 1602 | - 'post_status' => 'any', |
|
| 1603 | - 'suppress_filters' => 0, |
|
| 1604 | - ); |
|
| 1605 | - |
|
| 1606 | - $wp_query_obj = new WP_Query( $args ); |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * sensei_get_all_courses filter |
|
| 1610 | - * |
|
| 1611 | - * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1612 | - * |
|
| 1613 | - * @param array $courses{ |
|
| 1614 | - * @type WP_Post |
|
| 1615 | - * } |
|
| 1616 | - * @param array $attributes |
|
| 1617 | - */ |
|
| 1618 | - return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1619 | - |
|
| 1620 | - }// end get_all_courses |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * Generate the course meter component |
|
| 1624 | - * |
|
| 1625 | - * @since 1.8.0 |
|
| 1626 | - * @param int $progress_percentage 0 - 100 |
|
| 1627 | - * @return string $progress_bar_html |
|
| 1628 | - */ |
|
| 1629 | - public function get_progress_meter( $progress_percentage ){ |
|
| 1630 | - |
|
| 1631 | - if ( 50 < $progress_percentage ) { |
|
| 1632 | - $class = ' green'; |
|
| 1633 | - } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1634 | - $class = ' orange'; |
|
| 1635 | - } else { |
|
| 1636 | - $class = ' red'; |
|
| 1637 | - } |
|
| 1638 | - $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1639 | - |
|
| 1640 | - return $progress_bar_html; |
|
| 1641 | - |
|
| 1642 | - }// end get_progress_meter |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * Generate a statement that tells users |
|
| 1646 | - * how far they are in the course. |
|
| 1647 | - * |
|
| 1648 | - * @param int $course_id |
|
| 1649 | - * @param int $user_id |
|
| 1650 | - * |
|
| 1651 | - * @return string $statement_html |
|
| 1652 | - */ |
|
| 1653 | - public function get_progress_statement( $course_id, $user_id ){ |
|
| 1654 | - |
|
| 1655 | - if( empty( $course_id ) || empty( $user_id ) |
|
| 1656 | - || ! WooThemes_Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1657 | - return ''; |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1661 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1662 | - |
|
| 1663 | - $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * Filter the course completion statement. |
|
| 1667 | - * Default Currently completed $var lesson($plural) of $var in total |
|
| 1668 | - * |
|
| 1669 | - * @param string $statement |
|
| 1670 | - */ |
|
| 1671 | - return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1672 | - |
|
| 1673 | - }// end generate_progress_statement |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * Output the course progress statement |
|
| 1677 | - * |
|
| 1678 | - * @param $course_id |
|
| 1679 | - * @return void |
|
| 1680 | - */ |
|
| 1681 | - public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1682 | - if( empty( $course_id ) ){ |
|
| 1683 | - global $post; |
|
| 1684 | - $course_id = $post->ID; |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - if( empty( $user_id ) ){ |
|
| 1688 | - $user_id = get_current_user_id(); |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - /** |
|
| 1695 | - * Output the course progress bar |
|
| 1696 | - * |
|
| 1697 | - * @param $course_id |
|
| 1698 | - * @return void |
|
| 1699 | - */ |
|
| 1700 | - public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1701 | - |
|
| 1702 | - if( empty( $course_id ) ){ |
|
| 1703 | - global $post; |
|
| 1704 | - $course_id = $post->ID; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - if( empty( $user_id ) ){ |
|
| 1708 | - $user_id = get_current_user_id(); |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1712 | - || ! WooThemes_Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1713 | - return; |
|
| 1714 | - } |
|
| 1715 | - $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1716 | - |
|
| 1717 | - echo $this->get_progress_meter( $percentage_completed ); |
|
| 1718 | - |
|
| 1719 | - }// end the_progress_meter |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * Checks how many lessons are completed |
|
| 1723 | - * |
|
| 1724 | - * @since 1.8.0 |
|
| 1725 | - * |
|
| 1726 | - * @param int $course_id |
|
| 1727 | - * @param int $user_id |
|
| 1728 | - * @return array $completed_lesson_ids |
|
| 1729 | - */ |
|
| 1730 | - public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1731 | - |
|
| 1732 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1733 | - $user_id = get_current_user_id(); |
|
| 1734 | - } |
|
| 1587 | + /** |
|
| 1588 | + * Returns a list of all courses |
|
| 1589 | + * |
|
| 1590 | + * @since 1.8.0 |
|
| 1591 | + * @return array $courses{ |
|
| 1592 | + * @type $course WP_Post |
|
| 1593 | + * } |
|
| 1594 | + */ |
|
| 1595 | + public static function get_all_courses(){ |
|
| 1596 | + |
|
| 1597 | + $args = array( |
|
| 1598 | + 'post_type' => 'course', |
|
| 1599 | + 'posts_per_page' => -1, |
|
| 1600 | + 'orderby' => 'title', |
|
| 1601 | + 'order' => 'ASC', |
|
| 1602 | + 'post_status' => 'any', |
|
| 1603 | + 'suppress_filters' => 0, |
|
| 1604 | + ); |
|
| 1605 | + |
|
| 1606 | + $wp_query_obj = new WP_Query( $args ); |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * sensei_get_all_courses filter |
|
| 1610 | + * |
|
| 1611 | + * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1612 | + * |
|
| 1613 | + * @param array $courses{ |
|
| 1614 | + * @type WP_Post |
|
| 1615 | + * } |
|
| 1616 | + * @param array $attributes |
|
| 1617 | + */ |
|
| 1618 | + return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1619 | + |
|
| 1620 | + }// end get_all_courses |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * Generate the course meter component |
|
| 1624 | + * |
|
| 1625 | + * @since 1.8.0 |
|
| 1626 | + * @param int $progress_percentage 0 - 100 |
|
| 1627 | + * @return string $progress_bar_html |
|
| 1628 | + */ |
|
| 1629 | + public function get_progress_meter( $progress_percentage ){ |
|
| 1630 | + |
|
| 1631 | + if ( 50 < $progress_percentage ) { |
|
| 1632 | + $class = ' green'; |
|
| 1633 | + } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1634 | + $class = ' orange'; |
|
| 1635 | + } else { |
|
| 1636 | + $class = ' red'; |
|
| 1637 | + } |
|
| 1638 | + $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1639 | + |
|
| 1640 | + return $progress_bar_html; |
|
| 1641 | + |
|
| 1642 | + }// end get_progress_meter |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * Generate a statement that tells users |
|
| 1646 | + * how far they are in the course. |
|
| 1647 | + * |
|
| 1648 | + * @param int $course_id |
|
| 1649 | + * @param int $user_id |
|
| 1650 | + * |
|
| 1651 | + * @return string $statement_html |
|
| 1652 | + */ |
|
| 1653 | + public function get_progress_statement( $course_id, $user_id ){ |
|
| 1654 | + |
|
| 1655 | + if( empty( $course_id ) || empty( $user_id ) |
|
| 1656 | + || ! WooThemes_Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1657 | + return ''; |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1661 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1662 | + |
|
| 1663 | + $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * Filter the course completion statement. |
|
| 1667 | + * Default Currently completed $var lesson($plural) of $var in total |
|
| 1668 | + * |
|
| 1669 | + * @param string $statement |
|
| 1670 | + */ |
|
| 1671 | + return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1672 | + |
|
| 1673 | + }// end generate_progress_statement |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * Output the course progress statement |
|
| 1677 | + * |
|
| 1678 | + * @param $course_id |
|
| 1679 | + * @return void |
|
| 1680 | + */ |
|
| 1681 | + public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1682 | + if( empty( $course_id ) ){ |
|
| 1683 | + global $post; |
|
| 1684 | + $course_id = $post->ID; |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + if( empty( $user_id ) ){ |
|
| 1688 | + $user_id = get_current_user_id(); |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + /** |
|
| 1695 | + * Output the course progress bar |
|
| 1696 | + * |
|
| 1697 | + * @param $course_id |
|
| 1698 | + * @return void |
|
| 1699 | + */ |
|
| 1700 | + public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1701 | + |
|
| 1702 | + if( empty( $course_id ) ){ |
|
| 1703 | + global $post; |
|
| 1704 | + $course_id = $post->ID; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + if( empty( $user_id ) ){ |
|
| 1708 | + $user_id = get_current_user_id(); |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1712 | + || ! WooThemes_Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1713 | + return; |
|
| 1714 | + } |
|
| 1715 | + $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1716 | + |
|
| 1717 | + echo $this->get_progress_meter( $percentage_completed ); |
|
| 1718 | + |
|
| 1719 | + }// end the_progress_meter |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * Checks how many lessons are completed |
|
| 1723 | + * |
|
| 1724 | + * @since 1.8.0 |
|
| 1725 | + * |
|
| 1726 | + * @param int $course_id |
|
| 1727 | + * @param int $user_id |
|
| 1728 | + * @return array $completed_lesson_ids |
|
| 1729 | + */ |
|
| 1730 | + public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1731 | + |
|
| 1732 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1733 | + $user_id = get_current_user_id(); |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + $completed_lesson_ids = array(); |
|
| 1737 | + |
|
| 1738 | + $course_lessons = $this->course_lessons( $course_id ); |
|
| 1739 | + |
|
| 1740 | + foreach( $course_lessons as $lesson ){ |
|
| 1741 | + |
|
| 1742 | + $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1743 | + if( $is_lesson_completed ){ |
|
| 1744 | + $completed_lesson_ids[] = $lesson->ID; |
|
| 1745 | + } |
|
| 1746 | + |
|
| 1747 | + } |
|
| 1748 | + |
|
| 1749 | + return $completed_lesson_ids; |
|
| 1750 | + |
|
| 1751 | + }// end get_completed_lesson_ids |
|
| 1752 | + |
|
| 1753 | + /** |
|
| 1754 | + * Calculate the perceantage completed in the course |
|
| 1755 | + * |
|
| 1756 | + * @since 1.8.0 |
|
| 1757 | + * |
|
| 1758 | + * @param int $course_id |
|
| 1759 | + * @param int $user_id |
|
| 1760 | + * @return int $percentage |
|
| 1761 | + */ |
|
| 1762 | + public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1763 | + |
|
| 1764 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1765 | + $user_id = get_current_user_id(); |
|
| 1766 | + } |
|
| 1735 | 1767 | |
| 1736 | - $completed_lesson_ids = array(); |
|
| 1768 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1737 | 1769 | |
| 1738 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 1770 | + if( ! ( $completed > 0 ) ){ |
|
| 1771 | + return 0; |
|
| 1772 | + } |
|
| 1739 | 1773 | |
| 1740 | - foreach( $course_lessons as $lesson ){ |
|
| 1774 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1775 | + $percentage = $completed / $total_lessons * 100; |
|
| 1741 | 1776 | |
| 1742 | - $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1743 | - if( $is_lesson_completed ){ |
|
| 1744 | - $completed_lesson_ids[] = $lesson->ID; |
|
| 1745 | - } |
|
| 1746 | - |
|
| 1747 | - } |
|
| 1748 | - |
|
| 1749 | - return $completed_lesson_ids; |
|
| 1777 | + /** |
|
| 1778 | + * |
|
| 1779 | + * Filter the percentage returned for a users course. |
|
| 1780 | + * |
|
| 1781 | + * @param $percentage |
|
| 1782 | + * @param $course_id |
|
| 1783 | + * @param $user_id |
|
| 1784 | + * @since 1.8.0 |
|
| 1785 | + */ |
|
| 1786 | + return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1750 | 1787 | |
| 1751 | - }// end get_completed_lesson_ids |
|
| 1788 | + }// end get_completed_lesson_ids |
|
| 1752 | 1789 | |
| 1753 | - /** |
|
| 1754 | - * Calculate the perceantage completed in the course |
|
| 1755 | - * |
|
| 1756 | - * @since 1.8.0 |
|
| 1757 | - * |
|
| 1758 | - * @param int $course_id |
|
| 1759 | - * @param int $user_id |
|
| 1760 | - * @return int $percentage |
|
| 1761 | - */ |
|
| 1762 | - public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1763 | - |
|
| 1764 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1765 | - $user_id = get_current_user_id(); |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1769 | - |
|
| 1770 | - if( ! ( $completed > 0 ) ){ |
|
| 1771 | - return 0; |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1775 | - $percentage = $completed / $total_lessons * 100; |
|
| 1776 | - |
|
| 1777 | - /** |
|
| 1778 | - * |
|
| 1779 | - * Filter the percentage returned for a users course. |
|
| 1780 | - * |
|
| 1781 | - * @param $percentage |
|
| 1782 | - * @param $course_id |
|
| 1783 | - * @param $user_id |
|
| 1784 | - * @since 1.8.0 |
|
| 1785 | - */ |
|
| 1786 | - return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1790 | + /** |
|
| 1791 | + * Block email notifications for the specific courses |
|
| 1792 | + * that the user disabled the notifications. |
|
| 1793 | + * |
|
| 1794 | + * @since 1.8.0 |
|
| 1795 | + * @param $should_send |
|
| 1796 | + * @return bool |
|
| 1797 | + */ |
|
| 1798 | + public function block_notification_emails( $should_send ){ |
|
| 1799 | + global $sensei_email_data; |
|
| 1800 | + $email = $sensei_email_data; |
|
| 1787 | 1801 | |
| 1788 | - }// end get_completed_lesson_ids |
|
| 1802 | + $course_id = ''; |
|
| 1789 | 1803 | |
| 1790 | - /** |
|
| 1791 | - * Block email notifications for the specific courses |
|
| 1792 | - * that the user disabled the notifications. |
|
| 1793 | - * |
|
| 1794 | - * @since 1.8.0 |
|
| 1795 | - * @param $should_send |
|
| 1796 | - * @return bool |
|
| 1797 | - */ |
|
| 1798 | - public function block_notification_emails( $should_send ){ |
|
| 1799 | - global $sensei_email_data; |
|
| 1800 | - $email = $sensei_email_data; |
|
| 1804 | + if( isset( $email['course_id'] ) ){ |
|
| 1801 | 1805 | |
| 1802 | - $course_id = ''; |
|
| 1806 | + $course_id = $email['course_id']; |
|
| 1803 | 1807 | |
| 1804 | - if( isset( $email['course_id'] ) ){ |
|
| 1808 | + }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1805 | 1809 | |
| 1806 | - $course_id = $email['course_id']; |
|
| 1810 | + $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1807 | 1811 | |
| 1808 | - }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1812 | + }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1809 | 1813 | |
| 1810 | - $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1814 | + $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1815 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1811 | 1816 | |
| 1812 | - }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1817 | + } |
|
| 1813 | 1818 | |
| 1814 | - $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1815 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1819 | + if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1816 | 1820 | |
| 1817 | - } |
|
| 1821 | + $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1818 | 1822 | |
| 1819 | - if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | + if ($course_emails_disabled) { |
|
| 1820 | 1824 | |
| 1821 | - $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | + return false; |
|
| 1822 | 1826 | |
| 1823 | - if ($course_emails_disabled) { |
|
| 1827 | + } |
|
| 1824 | 1828 | |
| 1825 | - return false; |
|
| 1829 | + }// end if |
|
| 1826 | 1830 | |
| 1827 | - } |
|
| 1831 | + return $should_send; |
|
| 1832 | + }// end block_notification_emails |
|
| 1828 | 1833 | |
| 1829 | - }// end if |
|
| 1834 | + /** |
|
| 1835 | + * Render the course notification setting meta box |
|
| 1836 | + * |
|
| 1837 | + * @since 1.8.0 |
|
| 1838 | + * @param $course |
|
| 1839 | + */ |
|
| 1840 | + public function course_notification_meta_box_content( $course ){ |
|
| 1830 | 1841 | |
| 1831 | - return $should_send; |
|
| 1832 | - }// end block_notification_emails |
|
| 1842 | + $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1833 | 1843 | |
| 1834 | - /** |
|
| 1835 | - * Render the course notification setting meta box |
|
| 1836 | - * |
|
| 1837 | - * @since 1.8.0 |
|
| 1838 | - * @param $course |
|
| 1839 | - */ |
|
| 1840 | - public function course_notification_meta_box_content( $course ){ |
|
| 1844 | + // generate checked html |
|
| 1845 | + $checked_html = ''; |
|
| 1846 | + if( $checked ){ |
|
| 1847 | + $checked_html = 'checked="checked"'; |
|
| 1848 | + } |
|
| 1849 | + wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1841 | 1850 | |
| 1842 | - $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1851 | + echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1852 | + echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1843 | 1853 | |
| 1844 | - // generate checked html |
|
| 1845 | - $checked_html = ''; |
|
| 1846 | - if( $checked ){ |
|
| 1847 | - $checked_html = 'checked="checked"'; |
|
| 1848 | - } |
|
| 1849 | - wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1854 | + }// end course_notification_meta_box_content |
|
| 1850 | 1855 | |
| 1851 | - echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1852 | - echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1853 | - |
|
| 1854 | - }// end course_notification_meta_box_content |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * Store the setting for the course notification setting. |
|
| 1858 | - * |
|
| 1859 | - * @hooked int save_post |
|
| 1860 | - * @since 1.8.0 |
|
| 1861 | - * |
|
| 1862 | - * @param $course_id |
|
| 1863 | - */ |
|
| 1864 | - public function save_course_notification_meta_box( $course_id ){ |
|
| 1856 | + /** |
|
| 1857 | + * Store the setting for the course notification setting. |
|
| 1858 | + * |
|
| 1859 | + * @hooked int save_post |
|
| 1860 | + * @since 1.8.0 |
|
| 1861 | + * |
|
| 1862 | + * @param $course_id |
|
| 1863 | + */ |
|
| 1864 | + public function save_course_notification_meta_box( $course_id ){ |
|
| 1865 | 1865 | |
| 1866 | - if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1867 | - || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1868 | - return; |
|
| 1869 | - } |
|
| 1866 | + if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1867 | + || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1868 | + return; |
|
| 1869 | + } |
|
| 1870 | 1870 | |
| 1871 | - if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1872 | - $new_val = true; |
|
| 1873 | - }else{ |
|
| 1874 | - $new_val = false; |
|
| 1875 | - } |
|
| 1871 | + if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1872 | + $new_val = true; |
|
| 1873 | + }else{ |
|
| 1874 | + $new_val = false; |
|
| 1875 | + } |
|
| 1876 | 1876 | |
| 1877 | - update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1877 | + update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1878 | 1878 | |
| 1879 | - }// end save notification meta box |
|
| 1879 | + }// end save notification meta box |
|
| 1880 | 1880 | |
| 1881 | - /** |
|
| 1882 | - * Backwards compatibility hooks added to ensure that |
|
| 1883 | - * plugins and other parts of sensei still works. |
|
| 1884 | - * |
|
| 1885 | - * This function hooks into `sensei_course_content_inside_before` |
|
| 1886 | - * |
|
| 1887 | - * @since 1.9 |
|
| 1888 | - * |
|
| 1889 | - * @param WP_Post $post |
|
| 1890 | - */ |
|
| 1891 | - public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1881 | + /** |
|
| 1882 | + * Backwards compatibility hooks added to ensure that |
|
| 1883 | + * plugins and other parts of sensei still works. |
|
| 1884 | + * |
|
| 1885 | + * This function hooks into `sensei_course_content_inside_before` |
|
| 1886 | + * |
|
| 1887 | + * @since 1.9 |
|
| 1888 | + * |
|
| 1889 | + * @param WP_Post $post |
|
| 1890 | + */ |
|
| 1891 | + public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1892 | 1892 | |
| 1893 | - if( has_action( 'sensei_course_image' ) ){ |
|
| 1893 | + if( has_action( 'sensei_course_image' ) ){ |
|
| 1894 | 1894 | |
| 1895 | - _doing_it_wrong('sensei_course_image','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1896 | - do_action('sensei_course_image', $post->ID ); |
|
| 1895 | + _doing_it_wrong('sensei_course_image','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1896 | + do_action('sensei_course_image', $post->ID ); |
|
| 1897 | 1897 | |
| 1898 | - } |
|
| 1898 | + } |
|
| 1899 | 1899 | |
| 1900 | - if( has_action( 'sensei_course_archive_course_title' ) ){ |
|
| 1900 | + if( has_action( 'sensei_course_archive_course_title' ) ){ |
|
| 1901 | 1901 | |
| 1902 | - _doing_it_wrong('sensei_course_archive_course_title','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1903 | - do_action('sensei_course_archive_course_title', $post ); |
|
| 1902 | + _doing_it_wrong('sensei_course_archive_course_title','This action has been retired: . Please use sensei_course_content_inside_before instead.', '1.9' ); |
|
| 1903 | + do_action('sensei_course_archive_course_title', $post ); |
|
| 1904 | 1904 | |
| 1905 | - } |
|
| 1905 | + } |
|
| 1906 | 1906 | |
| 1907 | - } |
|
| 1907 | + } |
|
| 1908 | 1908 | |
| 1909 | - /** |
|
| 1910 | - * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1911 | - * |
|
| 1912 | - * hooked into 'sensei_loop_course_before' |
|
| 1913 | - * |
|
| 1914 | - * @since 1.9 |
|
| 1915 | - * |
|
| 1916 | - * @global WP_Post $post |
|
| 1917 | - */ |
|
| 1918 | - public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1919 | - |
|
| 1920 | - global $post; |
|
| 1921 | - sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1922 | - |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1927 | - * |
|
| 1928 | - * hooked into 'sensei_course_content_inside_after' |
|
| 1929 | - * |
|
| 1930 | - * @since 1.9.0 |
|
| 1931 | - * |
|
| 1932 | - * @param WP_Post $course |
|
| 1933 | - */ |
|
| 1934 | - public function the_course_free_lesson_preview( $course ){ |
|
| 1935 | - // Meta data |
|
| 1936 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1937 | - $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1938 | - |
|
| 1939 | - if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1940 | - ?> |
|
| 1909 | + /** |
|
| 1910 | + * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1911 | + * |
|
| 1912 | + * hooked into 'sensei_loop_course_before' |
|
| 1913 | + * |
|
| 1914 | + * @since 1.9 |
|
| 1915 | + * |
|
| 1916 | + * @global WP_Post $post |
|
| 1917 | + */ |
|
| 1918 | + public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1919 | + |
|
| 1920 | + global $post; |
|
| 1921 | + sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1922 | + |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1927 | + * |
|
| 1928 | + * hooked into 'sensei_course_content_inside_after' |
|
| 1929 | + * |
|
| 1930 | + * @since 1.9.0 |
|
| 1931 | + * |
|
| 1932 | + * @param WP_Post $course |
|
| 1933 | + */ |
|
| 1934 | + public function the_course_free_lesson_preview( $course ){ |
|
| 1935 | + // Meta data |
|
| 1936 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1937 | + $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1938 | + |
|
| 1939 | + if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1940 | + ?> |
|
| 1941 | 1941 | <p class="sensei-free-lessons"> |
| 1942 | 1942 | <a href="<?php echo get_permalink(); ?>"> |
| 1943 | 1943 | <?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
@@ -1946,22 +1946,22 @@ discard block |
||
| 1946 | 1946 | </p> |
| 1947 | 1947 | |
| 1948 | 1948 | <?php |
| 1949 | - } |
|
| 1950 | - } |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | 1951 | |
| 1952 | - /** |
|
| 1953 | - * Add course mata to the course meta hook |
|
| 1954 | - * |
|
| 1955 | - * @since 1.9.0 |
|
| 1956 | - * @param WP_Post $course |
|
| 1957 | - */ |
|
| 1958 | - public function the_course_meta( $course ){ |
|
| 1959 | - echo '<p class="sensei-course-meta">'; |
|
| 1952 | + /** |
|
| 1953 | + * Add course mata to the course meta hook |
|
| 1954 | + * |
|
| 1955 | + * @since 1.9.0 |
|
| 1956 | + * @param WP_Post $course |
|
| 1957 | + */ |
|
| 1958 | + public function the_course_meta( $course ){ |
|
| 1959 | + echo '<p class="sensei-course-meta">'; |
|
| 1960 | 1960 | |
| 1961 | - $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1962 | - $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1961 | + $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1962 | + $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1963 | 1963 | |
| 1964 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1964 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1965 | 1965 | |
| 1966 | 1966 | <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?> |
| 1967 | 1967 | |
@@ -1979,59 +1979,59 @@ discard block |
||
| 1979 | 1979 | |
| 1980 | 1980 | <?php } // End If Statement |
| 1981 | 1981 | |
| 1982 | - // number of completed lessons |
|
| 1983 | - if( is_user_logged_in() ){ |
|
| 1984 | - $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1985 | - $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1986 | - echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1987 | - } |
|
| 1982 | + // number of completed lessons |
|
| 1983 | + if( is_user_logged_in() ){ |
|
| 1984 | + $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1985 | + $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1986 | + echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1987 | + } |
|
| 1988 | 1988 | |
| 1989 | - sensei_simple_course_price( $course->ID ); |
|
| 1989 | + sensei_simple_course_price( $course->ID ); |
|
| 1990 | 1990 | |
| 1991 | - echo '</p>'; |
|
| 1992 | - } // end the course meta |
|
| 1991 | + echo '</p>'; |
|
| 1992 | + } // end the course meta |
|
| 1993 | 1993 | |
| 1994 | - /** |
|
| 1995 | - * Filter the classes attached to a post types for courses |
|
| 1996 | - * and add a status class for when the user is logged in. |
|
| 1997 | - * |
|
| 1998 | - * @param $classes |
|
| 1999 | - * @param $class |
|
| 2000 | - * @param $post_id |
|
| 2001 | - * |
|
| 2002 | - * @return array $classes |
|
| 2003 | - */ |
|
| 2004 | - public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1994 | + /** |
|
| 1995 | + * Filter the classes attached to a post types for courses |
|
| 1996 | + * and add a status class for when the user is logged in. |
|
| 1997 | + * |
|
| 1998 | + * @param $classes |
|
| 1999 | + * @param $class |
|
| 2000 | + * @param $post_id |
|
| 2001 | + * |
|
| 2002 | + * @return array $classes |
|
| 2003 | + */ |
|
| 2004 | + public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 2005 | 2005 | |
| 2006 | - if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 2006 | + if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 2007 | 2007 | |
| 2008 | - if( WooThemes_Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2008 | + if( WooThemes_Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2009 | 2009 | |
| 2010 | - $classes[] = 'user-status-completed'; |
|
| 2010 | + $classes[] = 'user-status-completed'; |
|
| 2011 | 2011 | |
| 2012 | - }else{ |
|
| 2012 | + }else{ |
|
| 2013 | 2013 | |
| 2014 | - $classes[] = 'user-status-active'; |
|
| 2014 | + $classes[] = 'user-status-active'; |
|
| 2015 | 2015 | |
| 2016 | - } |
|
| 2016 | + } |
|
| 2017 | 2017 | |
| 2018 | - } |
|
| 2018 | + } |
|
| 2019 | 2019 | |
| 2020 | - return $classes; |
|
| 2020 | + return $classes; |
|
| 2021 | 2021 | |
| 2022 | - }// end add_course_user_status_class |
|
| 2022 | + }// end add_course_user_status_class |
|
| 2023 | 2023 | |
| 2024 | - /** |
|
| 2025 | - * Prints out the course action buttons links |
|
| 2026 | - * |
|
| 2027 | - * - complete course |
|
| 2028 | - * - delete course |
|
| 2029 | - * |
|
| 2030 | - * @param WP_Post $course |
|
| 2031 | - */ |
|
| 2032 | - public static function the_course_action_buttons( $course ){ |
|
| 2024 | + /** |
|
| 2025 | + * Prints out the course action buttons links |
|
| 2026 | + * |
|
| 2027 | + * - complete course |
|
| 2028 | + * - delete course |
|
| 2029 | + * |
|
| 2030 | + * @param WP_Post $course |
|
| 2031 | + */ |
|
| 2032 | + public static function the_course_action_buttons( $course ){ |
|
| 2033 | 2033 | |
| 2034 | - if( is_user_logged_in() ) { ?> |
|
| 2034 | + if( is_user_logged_in() ) { ?> |
|
| 2035 | 2035 | |
| 2036 | 2036 | <section class="entry-actions"> |
| 2037 | 2037 | <form method="POST" action="<?php echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>"> |
@@ -2050,32 +2050,32 @@ discard block |
||
| 2050 | 2050 | |
| 2051 | 2051 | <?php } // End If Statement |
| 2052 | 2052 | |
| 2053 | - $course_purchased = false; |
|
| 2054 | - if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() ) { |
|
| 2055 | - // Get the product ID |
|
| 2056 | - $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2057 | - if ( 0 < $wc_post_id ) { |
|
| 2053 | + $course_purchased = false; |
|
| 2054 | + if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() ) { |
|
| 2055 | + // Get the product ID |
|
| 2056 | + $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2057 | + if ( 0 < $wc_post_id ) { |
|
| 2058 | 2058 | |
| 2059 | - $user = wp_get_current_user(); |
|
| 2060 | - $course_purchased = WooThemes_Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2059 | + $user = wp_get_current_user(); |
|
| 2060 | + $course_purchased = WooThemes_Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2061 | 2061 | |
| 2062 | - } // End If Statement |
|
| 2063 | - } // End If Statement |
|
| 2062 | + } // End If Statement |
|
| 2063 | + } // End If Statement |
|
| 2064 | 2064 | |
| 2065 | - if ( ! $course_purchased && ! WooThemes_Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2065 | + if ( ! $course_purchased && ! WooThemes_Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2066 | 2066 | |
| 2067 | 2067 | <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span> |
| 2068 | 2068 | |
| 2069 | 2069 | <?php } // End If Statement |
| 2070 | 2070 | |
| 2071 | - $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2072 | - $results_link = ''; |
|
| 2073 | - if( $has_quizzes ){ |
|
| 2074 | - $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2075 | - } |
|
| 2071 | + $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2072 | + $results_link = ''; |
|
| 2073 | + if( $has_quizzes ){ |
|
| 2074 | + $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2075 | + } |
|
| 2076 | 2076 | |
| 2077 | - // Output only if there is content to display |
|
| 2078 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2077 | + // Output only if there is content to display |
|
| 2078 | + if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2079 | 2079 | |
| 2080 | 2080 | <p class="sensei-results-links"> |
| 2081 | 2081 | <?php echo apply_filters( 'sensei_results_links', $results_link ); ?> |
@@ -2087,440 +2087,440 @@ discard block |
||
| 2087 | 2087 | |
| 2088 | 2088 | <?php }// end if is user logged in |
| 2089 | 2089 | |
| 2090 | - }// end the_course_action_buttons |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * This function alter the main query on the course archive page. |
|
| 2094 | - * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2095 | - * |
|
| 2096 | - * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2097 | - * query parameters via the arguments. |
|
| 2098 | - * |
|
| 2099 | - * This function is hooked into pre_get_posts filter |
|
| 2100 | - * |
|
| 2101 | - * @since 1.9.0 |
|
| 2102 | - * |
|
| 2103 | - * @param WP_Query $query |
|
| 2104 | - * @return WP_Query $query |
|
| 2105 | - */ |
|
| 2106 | - public static function course_query_filter( $query ){ |
|
| 2107 | - |
|
| 2108 | - // exit early for no course queries and admin queries |
|
| 2109 | - if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2110 | - return $query; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - global $post; // used to get the current page id for my courses |
|
| 2114 | - |
|
| 2115 | - // for the course archive page |
|
| 2116 | - if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2117 | - { |
|
| 2118 | - |
|
| 2119 | - $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2120 | - |
|
| 2121 | - } |
|
| 2122 | - // for the my courses page |
|
| 2123 | - elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2124 | - { |
|
| 2125 | - |
|
| 2126 | - $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2127 | - |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - return $query; |
|
| 2131 | - |
|
| 2132 | - }// end course_query_filter |
|
| 2133 | - |
|
| 2134 | - /** |
|
| 2135 | - * Determine the class of the course loop |
|
| 2136 | - * |
|
| 2137 | - * This will output .first or .last and .course-item-number-x |
|
| 2138 | - * |
|
| 2139 | - * @return array $extra_classes |
|
| 2140 | - * @since 1.9.0 |
|
| 2141 | - */ |
|
| 2142 | - public static function get_course_loop_content_class () |
|
| 2143 | - { |
|
| 2144 | - |
|
| 2145 | - global $sensei_course_loop; |
|
| 2146 | - |
|
| 2147 | - |
|
| 2148 | - if( !isset( $sensei_course_loop ) ){ |
|
| 2149 | - $sensei_course_loop = array(); |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - if (!isset($sensei_course_loop['counter'])) { |
|
| 2153 | - $sensei_course_loop['counter'] = 0; |
|
| 2154 | - } |
|
| 2155 | - |
|
| 2156 | - if (!isset($sensei_course_loop['columns'])) { |
|
| 2157 | - $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2158 | - } |
|
| 2159 | - |
|
| 2160 | - // increment the counter |
|
| 2161 | - $sensei_course_loop['counter']++; |
|
| 2162 | - |
|
| 2163 | - $extra_classes = array(); |
|
| 2164 | - if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2165 | - $extra_classes[] = 'first'; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2169 | - $extra_classes[] = 'last'; |
|
| 2170 | - } |
|
| 2171 | - |
|
| 2172 | - // add the item number to the classes as well. |
|
| 2173 | - $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2174 | - |
|
| 2175 | - /** |
|
| 2176 | - * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2177 | - * which is called from the course loop content-course.php |
|
| 2178 | - * |
|
| 2179 | - * @since 1.9.0 |
|
| 2180 | - * |
|
| 2181 | - * @param array $extra_classes |
|
| 2182 | - * @param WP_Post $loop_current_course |
|
| 2183 | - */ |
|
| 2184 | - return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2185 | - |
|
| 2186 | - }// end get_course_loop_class |
|
| 2187 | - |
|
| 2188 | - /** |
|
| 2189 | - * Get the number of columns set for Sensei courses |
|
| 2190 | - * |
|
| 2191 | - * @since 1.9.0 |
|
| 2192 | - * @return mixed|void |
|
| 2193 | - */ |
|
| 2194 | - public static function get_loop_number_of_columns(){ |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * Filter the number of columns on the course archive page. |
|
| 2198 | - * |
|
| 2199 | - * @since 1.9.0 |
|
| 2200 | - * @param int $number_of_columns default 1 |
|
| 2201 | - */ |
|
| 2202 | - return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2203 | - |
|
| 2204 | - } |
|
| 2205 | - |
|
| 2206 | - /** |
|
| 2207 | - * Output the course archive filter markup |
|
| 2208 | - * |
|
| 2209 | - * hooked into sensei_loop_course_before |
|
| 2210 | - * |
|
| 2211 | - * @since 1.9.0 |
|
| 2212 | - * @param |
|
| 2213 | - */ |
|
| 2214 | - public static function course_archive_sorting( $query ){ |
|
| 2215 | - |
|
| 2216 | - // don't show on category pages and other pages |
|
| 2217 | - if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2218 | - return; |
|
| 2219 | - } |
|
| 2220 | - |
|
| 2221 | - /** |
|
| 2222 | - * Filter the sensei archive course order by values |
|
| 2223 | - * |
|
| 2224 | - * @since 1.9.0 |
|
| 2225 | - * @param array $options { |
|
| 2226 | - * @type string $option_value |
|
| 2227 | - * @type string $option_string |
|
| 2228 | - * } |
|
| 2229 | - */ |
|
| 2230 | - $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2231 | - "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2232 | - "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2233 | - )); |
|
| 2234 | - |
|
| 2235 | - // setup the currently selected item |
|
| 2236 | - $selected = 'newness'; |
|
| 2237 | - if( isset( $_GET['orderby'] ) ){ |
|
| 2238 | - |
|
| 2239 | - $selected = $_GET[ 'orderby' ]; |
|
| 2240 | - |
|
| 2241 | - } |
|
| 2242 | - |
|
| 2243 | - ?> |
|
| 2090 | + }// end the_course_action_buttons |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * This function alter the main query on the course archive page. |
|
| 2094 | + * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2095 | + * |
|
| 2096 | + * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2097 | + * query parameters via the arguments. |
|
| 2098 | + * |
|
| 2099 | + * This function is hooked into pre_get_posts filter |
|
| 2100 | + * |
|
| 2101 | + * @since 1.9.0 |
|
| 2102 | + * |
|
| 2103 | + * @param WP_Query $query |
|
| 2104 | + * @return WP_Query $query |
|
| 2105 | + */ |
|
| 2106 | + public static function course_query_filter( $query ){ |
|
| 2107 | + |
|
| 2108 | + // exit early for no course queries and admin queries |
|
| 2109 | + if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2110 | + return $query; |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + global $post; // used to get the current page id for my courses |
|
| 2114 | + |
|
| 2115 | + // for the course archive page |
|
| 2116 | + if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2117 | + { |
|
| 2118 | + |
|
| 2119 | + $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2120 | + |
|
| 2121 | + } |
|
| 2122 | + // for the my courses page |
|
| 2123 | + elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2124 | + { |
|
| 2125 | + |
|
| 2126 | + $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', get_option( 'posts_per_page' ) ) ); |
|
| 2127 | + |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + return $query; |
|
| 2131 | + |
|
| 2132 | + }// end course_query_filter |
|
| 2133 | + |
|
| 2134 | + /** |
|
| 2135 | + * Determine the class of the course loop |
|
| 2136 | + * |
|
| 2137 | + * This will output .first or .last and .course-item-number-x |
|
| 2138 | + * |
|
| 2139 | + * @return array $extra_classes |
|
| 2140 | + * @since 1.9.0 |
|
| 2141 | + */ |
|
| 2142 | + public static function get_course_loop_content_class () |
|
| 2143 | + { |
|
| 2144 | + |
|
| 2145 | + global $sensei_course_loop; |
|
| 2146 | + |
|
| 2147 | + |
|
| 2148 | + if( !isset( $sensei_course_loop ) ){ |
|
| 2149 | + $sensei_course_loop = array(); |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + if (!isset($sensei_course_loop['counter'])) { |
|
| 2153 | + $sensei_course_loop['counter'] = 0; |
|
| 2154 | + } |
|
| 2155 | + |
|
| 2156 | + if (!isset($sensei_course_loop['columns'])) { |
|
| 2157 | + $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2158 | + } |
|
| 2159 | + |
|
| 2160 | + // increment the counter |
|
| 2161 | + $sensei_course_loop['counter']++; |
|
| 2162 | + |
|
| 2163 | + $extra_classes = array(); |
|
| 2164 | + if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2165 | + $extra_classes[] = 'first'; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2169 | + $extra_classes[] = 'last'; |
|
| 2170 | + } |
|
| 2171 | + |
|
| 2172 | + // add the item number to the classes as well. |
|
| 2173 | + $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2174 | + |
|
| 2175 | + /** |
|
| 2176 | + * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2177 | + * which is called from the course loop content-course.php |
|
| 2178 | + * |
|
| 2179 | + * @since 1.9.0 |
|
| 2180 | + * |
|
| 2181 | + * @param array $extra_classes |
|
| 2182 | + * @param WP_Post $loop_current_course |
|
| 2183 | + */ |
|
| 2184 | + return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2185 | + |
|
| 2186 | + }// end get_course_loop_class |
|
| 2187 | + |
|
| 2188 | + /** |
|
| 2189 | + * Get the number of columns set for Sensei courses |
|
| 2190 | + * |
|
| 2191 | + * @since 1.9.0 |
|
| 2192 | + * @return mixed|void |
|
| 2193 | + */ |
|
| 2194 | + public static function get_loop_number_of_columns(){ |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * Filter the number of columns on the course archive page. |
|
| 2198 | + * |
|
| 2199 | + * @since 1.9.0 |
|
| 2200 | + * @param int $number_of_columns default 1 |
|
| 2201 | + */ |
|
| 2202 | + return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2203 | + |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + /** |
|
| 2207 | + * Output the course archive filter markup |
|
| 2208 | + * |
|
| 2209 | + * hooked into sensei_loop_course_before |
|
| 2210 | + * |
|
| 2211 | + * @since 1.9.0 |
|
| 2212 | + * @param |
|
| 2213 | + */ |
|
| 2214 | + public static function course_archive_sorting( $query ){ |
|
| 2215 | + |
|
| 2216 | + // don't show on category pages and other pages |
|
| 2217 | + if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2218 | + return; |
|
| 2219 | + } |
|
| 2220 | + |
|
| 2221 | + /** |
|
| 2222 | + * Filter the sensei archive course order by values |
|
| 2223 | + * |
|
| 2224 | + * @since 1.9.0 |
|
| 2225 | + * @param array $options { |
|
| 2226 | + * @type string $option_value |
|
| 2227 | + * @type string $option_string |
|
| 2228 | + * } |
|
| 2229 | + */ |
|
| 2230 | + $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2231 | + "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2232 | + "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2233 | + )); |
|
| 2234 | + |
|
| 2235 | + // setup the currently selected item |
|
| 2236 | + $selected = 'newness'; |
|
| 2237 | + if( isset( $_GET['orderby'] ) ){ |
|
| 2238 | + |
|
| 2239 | + $selected = $_GET[ 'orderby' ]; |
|
| 2240 | + |
|
| 2241 | + } |
|
| 2242 | + |
|
| 2243 | + ?> |
|
| 2244 | 2244 | |
| 2245 | 2245 | <form class="sensei-ordering" name="sensei-course-order" action="<?php echo WooThemes_Sensei_Utils::get_current_url(); ?>" method="POST"> |
| 2246 | 2246 | <select name="course-orderby" class="orderby"> |
| 2247 | 2247 | <?php |
| 2248 | - foreach( $course_order_by_options as $value => $text ){ |
|
| 2248 | + foreach( $course_order_by_options as $value => $text ){ |
|
| 2249 | 2249 | |
| 2250 | - echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2250 | + echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2251 | 2251 | |
| 2252 | - } |
|
| 2253 | - ?> |
|
| 2252 | + } |
|
| 2253 | + ?> |
|
| 2254 | 2254 | </select> |
| 2255 | 2255 | </form> |
| 2256 | 2256 | |
| 2257 | 2257 | <?php |
| 2258 | - }// end course archive filters |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * Output the course archive filter markup |
|
| 2262 | - * |
|
| 2263 | - * hooked into sensei_loop_course_before |
|
| 2264 | - * |
|
| 2265 | - * @since 1.9.0 |
|
| 2266 | - * @param |
|
| 2267 | - */ |
|
| 2268 | - public static function course_archive_filters( $query ){ |
|
| 2269 | - |
|
| 2270 | - // don't show on category pages |
|
| 2271 | - if( is_tax('course-category') ){ |
|
| 2272 | - return; |
|
| 2273 | - } |
|
| 2274 | - |
|
| 2275 | - /** |
|
| 2276 | - * filter the course archive filter buttons |
|
| 2277 | - * |
|
| 2278 | - * @since 1.9.0 |
|
| 2279 | - * @param array $filters{ |
|
| 2280 | - * @type array ( $id, $url , $title ) |
|
| 2281 | - * } |
|
| 2282 | - * |
|
| 2283 | - */ |
|
| 2284 | - $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2285 | - array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2286 | - array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2287 | - )); |
|
| 2288 | - |
|
| 2289 | - |
|
| 2290 | - ?> |
|
| 2258 | + }// end course archive filters |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * Output the course archive filter markup |
|
| 2262 | + * |
|
| 2263 | + * hooked into sensei_loop_course_before |
|
| 2264 | + * |
|
| 2265 | + * @since 1.9.0 |
|
| 2266 | + * @param |
|
| 2267 | + */ |
|
| 2268 | + public static function course_archive_filters( $query ){ |
|
| 2269 | + |
|
| 2270 | + // don't show on category pages |
|
| 2271 | + if( is_tax('course-category') ){ |
|
| 2272 | + return; |
|
| 2273 | + } |
|
| 2274 | + |
|
| 2275 | + /** |
|
| 2276 | + * filter the course archive filter buttons |
|
| 2277 | + * |
|
| 2278 | + * @since 1.9.0 |
|
| 2279 | + * @param array $filters{ |
|
| 2280 | + * @type array ( $id, $url , $title ) |
|
| 2281 | + * } |
|
| 2282 | + * |
|
| 2283 | + */ |
|
| 2284 | + $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2285 | + array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2286 | + array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2287 | + )); |
|
| 2288 | + |
|
| 2289 | + |
|
| 2290 | + ?> |
|
| 2291 | 2291 | <ul class="sensei-course-filters clearfix" > |
| 2292 | 2292 | <?php |
| 2293 | 2293 | |
| 2294 | - //determine the current active url |
|
| 2295 | - $current_url = WooThemes_Sensei_Utils::get_current_url(); |
|
| 2294 | + //determine the current active url |
|
| 2295 | + $current_url = WooThemes_Sensei_Utils::get_current_url(); |
|
| 2296 | 2296 | |
| 2297 | - foreach( $filters as $filter ) { |
|
| 2297 | + foreach( $filters as $filter ) { |
|
| 2298 | 2298 | |
| 2299 | - $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2299 | + $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2300 | 2300 | |
| 2301 | - echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2301 | + echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2302 | 2302 | |
| 2303 | - } |
|
| 2304 | - ?> |
|
| 2303 | + } |
|
| 2304 | + ?> |
|
| 2305 | 2305 | |
| 2306 | 2306 | </ul> |
| 2307 | 2307 | |
| 2308 | 2308 | <?php |
| 2309 | 2309 | |
| 2310 | - } |
|
| 2310 | + } |
|
| 2311 | 2311 | |
| 2312 | - /** |
|
| 2313 | - * if the featured link is clicked on the course archive page |
|
| 2314 | - * filter the courses returned to only show those featured |
|
| 2315 | - * |
|
| 2316 | - * Hooked into pre_get_posts |
|
| 2317 | - * |
|
| 2318 | - * @since 1.9.0 |
|
| 2319 | - * @param WP_Query $query |
|
| 2320 | - * @return WP_Query $query |
|
| 2321 | - */ |
|
| 2322 | - public static function course_archive_featured_filter( $query ){ |
|
| 2323 | - |
|
| 2324 | - if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2325 | - //setup meta query for featured courses |
|
| 2326 | - $query->set( 'meta_value', 'featured' ); |
|
| 2327 | - $query->set( 'meta_key', '_course_featured' ); |
|
| 2328 | - $query->set( 'meta_compare', '=' ); |
|
| 2329 | - } |
|
| 2330 | - |
|
| 2331 | - return $query; |
|
| 2332 | - } |
|
| 2333 | - |
|
| 2334 | - /** |
|
| 2335 | - * if the course order drop down is changed |
|
| 2336 | - * |
|
| 2337 | - * Hooked into pre_get_posts |
|
| 2338 | - * |
|
| 2339 | - * @since 1.9.0 |
|
| 2340 | - * @param WP_Query $query |
|
| 2341 | - * @return WP_Query $query |
|
| 2342 | - */ |
|
| 2343 | - public static function course_archive_order_by_title( $query ){ |
|
| 2344 | - |
|
| 2345 | - if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2346 | - && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2347 | - // setup the order by title for this query |
|
| 2348 | - $query->set( 'orderby', 'title' ); |
|
| 2349 | - $query->set( 'order', 'ASC' ); |
|
| 2350 | - } |
|
| 2351 | - |
|
| 2352 | - return $query; |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - |
|
| 2356 | - /** |
|
| 2357 | - * Get the link to the courses page. This will be the course post type archive |
|
| 2358 | - * page link or the page the user set in their settings |
|
| 2359 | - * |
|
| 2360 | - * @since 1.9.0 |
|
| 2361 | - * @return string $course_page_url |
|
| 2362 | - */ |
|
| 2363 | - public static function get_courses_page_url(){ |
|
| 2364 | - |
|
| 2365 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2366 | - $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2312 | + /** |
|
| 2313 | + * if the featured link is clicked on the course archive page |
|
| 2314 | + * filter the courses returned to only show those featured |
|
| 2315 | + * |
|
| 2316 | + * Hooked into pre_get_posts |
|
| 2317 | + * |
|
| 2318 | + * @since 1.9.0 |
|
| 2319 | + * @param WP_Query $query |
|
| 2320 | + * @return WP_Query $query |
|
| 2321 | + */ |
|
| 2322 | + public static function course_archive_featured_filter( $query ){ |
|
| 2367 | 2323 | |
| 2368 | - return $course_page_url; |
|
| 2369 | - |
|
| 2370 | - }// get_course_url |
|
| 2324 | + if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2325 | + //setup meta query for featured courses |
|
| 2326 | + $query->set( 'meta_value', 'featured' ); |
|
| 2327 | + $query->set( 'meta_key', '_course_featured' ); |
|
| 2328 | + $query->set( 'meta_compare', '=' ); |
|
| 2329 | + } |
|
| 2371 | 2330 | |
| 2372 | - /** |
|
| 2373 | - * Output the headers on the course archive page |
|
| 2374 | - * |
|
| 2375 | - * Hooked into the sensei_archive_title |
|
| 2376 | - * |
|
| 2377 | - * @since 1.9.0 |
|
| 2378 | - * @param string $query_type |
|
| 2379 | - * @param string $before_html |
|
| 2380 | - * @param string $after_html |
|
| 2381 | - * @return void |
|
| 2382 | - */ |
|
| 2383 | - public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2331 | + return $query; |
|
| 2332 | + } |
|
| 2384 | 2333 | |
| 2385 | - if( ! is_post_type_archive('course') ){ |
|
| 2386 | - return; |
|
| 2387 | - } |
|
| 2334 | + /** |
|
| 2335 | + * if the course order drop down is changed |
|
| 2336 | + * |
|
| 2337 | + * Hooked into pre_get_posts |
|
| 2338 | + * |
|
| 2339 | + * @since 1.9.0 |
|
| 2340 | + * @param WP_Query $query |
|
| 2341 | + * @return WP_Query $query |
|
| 2342 | + */ |
|
| 2343 | + public static function course_archive_order_by_title( $query ){ |
|
| 2388 | 2344 | |
| 2389 | - // deprecated since 1.9.0 |
|
| 2390 | - sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2345 | + if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2346 | + && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2347 | + // setup the order by title for this query |
|
| 2348 | + $query->set( 'orderby', 'title' ); |
|
| 2349 | + $query->set( 'order', 'ASC' ); |
|
| 2350 | + } |
|
| 2391 | 2351 | |
| 2392 | - $html = ''; |
|
| 2352 | + return $query; |
|
| 2353 | + } |
|
| 2393 | 2354 | |
| 2394 | - if( empty( $before_html ) ){ |
|
| 2395 | 2355 | |
| 2396 | - $before_html = '<header class="archive-header"><h1>'; |
|
| 2356 | + /** |
|
| 2357 | + * Get the link to the courses page. This will be the course post type archive |
|
| 2358 | + * page link or the page the user set in their settings |
|
| 2359 | + * |
|
| 2360 | + * @since 1.9.0 |
|
| 2361 | + * @return string $course_page_url |
|
| 2362 | + */ |
|
| 2363 | + public static function get_courses_page_url(){ |
|
| 2397 | 2364 | |
| 2398 | - } |
|
| 2365 | + $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2366 | + $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2399 | 2367 | |
| 2400 | - if( empty( $after_html ) ){ |
|
| 2368 | + return $course_page_url; |
|
| 2401 | 2369 | |
| 2402 | - $after_html = '</h1></header>'; |
|
| 2370 | + }// get_course_url |
|
| 2403 | 2371 | |
| 2404 | - } |
|
| 2372 | + /** |
|
| 2373 | + * Output the headers on the course archive page |
|
| 2374 | + * |
|
| 2375 | + * Hooked into the sensei_archive_title |
|
| 2376 | + * |
|
| 2377 | + * @since 1.9.0 |
|
| 2378 | + * @param string $query_type |
|
| 2379 | + * @param string $before_html |
|
| 2380 | + * @param string $after_html |
|
| 2381 | + * @return void |
|
| 2382 | + */ |
|
| 2383 | + public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2405 | 2384 | |
| 2406 | - if ( is_tax( 'course-category' ) ) { |
|
| 2385 | + if( ! is_post_type_archive('course') ){ |
|
| 2386 | + return; |
|
| 2387 | + } |
|
| 2407 | 2388 | |
| 2408 | - global $wp_query; |
|
| 2389 | + // deprecated since 1.9.0 |
|
| 2390 | + sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2409 | 2391 | |
| 2410 | - $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2411 | - $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2412 | - $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2413 | - $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2414 | - echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2415 | - return; |
|
| 2392 | + $html = ''; |
|
| 2416 | 2393 | |
| 2417 | - } // End If Statement |
|
| 2394 | + if( empty( $before_html ) ){ |
|
| 2418 | 2395 | |
| 2419 | - switch ( $query_type ) { |
|
| 2420 | - case 'newcourses': |
|
| 2421 | - $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2422 | - break; |
|
| 2423 | - case 'featuredcourses': |
|
| 2424 | - $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2425 | - break; |
|
| 2426 | - case 'freecourses': |
|
| 2427 | - $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2428 | - break; |
|
| 2429 | - case 'paidcourses': |
|
| 2430 | - $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2431 | - break; |
|
| 2432 | - default: |
|
| 2433 | - $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2434 | - break; |
|
| 2435 | - } // End Switch Statement |
|
| 2396 | + $before_html = '<header class="archive-header"><h1>'; |
|
| 2436 | 2397 | |
| 2437 | - echo apply_filters( 'course_archive_title', $html ); |
|
| 2398 | + } |
|
| 2438 | 2399 | |
| 2439 | - }//course_archive_header |
|
| 2400 | + if( empty( $after_html ) ){ |
|
| 2440 | 2401 | |
| 2402 | + $after_html = '</h1></header>'; |
|
| 2441 | 2403 | |
| 2442 | - /** |
|
| 2443 | - * Filter the single course content |
|
| 2444 | - * taking into account if the user has access. |
|
| 2445 | - * |
|
| 2446 | - * @1.9.0 |
|
| 2447 | - * |
|
| 2448 | - * @param string $content |
|
| 2449 | - * @return string $content or $excerpt |
|
| 2450 | - */ |
|
| 2451 | - public static function single_course_content( $content ){ |
|
| 2404 | + } |
|
| 2452 | 2405 | |
| 2453 | - if( ! is_singular('course') ){ |
|
| 2406 | + if ( is_tax( 'course-category' ) ) { |
|
| 2454 | 2407 | |
| 2455 | - return $content; |
|
| 2408 | + global $wp_query; |
|
| 2456 | 2409 | |
| 2457 | - } |
|
| 2410 | + $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2411 | + $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2412 | + $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2413 | + $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2414 | + echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2415 | + return; |
|
| 2458 | 2416 | |
| 2459 | - // Content Access Permissions |
|
| 2460 | - $access_permission = false; |
|
| 2417 | + } // End If Statement |
|
| 2461 | 2418 | |
| 2462 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2419 | + switch ( $query_type ) { |
|
| 2420 | + case 'newcourses': |
|
| 2421 | + $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2422 | + break; |
|
| 2423 | + case 'featuredcourses': |
|
| 2424 | + $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2425 | + break; |
|
| 2426 | + case 'freecourses': |
|
| 2427 | + $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2428 | + break; |
|
| 2429 | + case 'paidcourses': |
|
| 2430 | + $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2431 | + break; |
|
| 2432 | + default: |
|
| 2433 | + $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2434 | + break; |
|
| 2435 | + } // End Switch Statement |
|
| 2463 | 2436 | |
| 2464 | - $access_permission = true; |
|
| 2437 | + echo apply_filters( 'course_archive_title', $html ); |
|
| 2465 | 2438 | |
| 2466 | - } // End If Statement |
|
| 2439 | + }//course_archive_header |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * Filter the single course content |
|
| 2444 | + * taking into account if the user has access. |
|
| 2445 | + * |
|
| 2446 | + * @1.9.0 |
|
| 2447 | + * |
|
| 2448 | + * @param string $content |
|
| 2449 | + * @return string $content or $excerpt |
|
| 2450 | + */ |
|
| 2451 | + public static function single_course_content( $content ){ |
|
| 2467 | 2452 | |
| 2468 | - // Check if the user is taking the course |
|
| 2469 | - $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2453 | + if( ! is_singular('course') ){ |
|
| 2470 | 2454 | |
| 2471 | - if(WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { |
|
| 2455 | + return $content; |
|
| 2472 | 2456 | |
| 2473 | - $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2474 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2457 | + } |
|
| 2475 | 2458 | |
| 2476 | - $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2459 | + // Content Access Permissions |
|
| 2460 | + $access_permission = false; |
|
| 2477 | 2461 | |
| 2478 | - } else { |
|
| 2462 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2479 | 2463 | |
| 2480 | - $has_product_attached = false; |
|
| 2464 | + $access_permission = true; |
|
| 2481 | 2465 | |
| 2482 | - } |
|
| 2466 | + } // End If Statement |
|
| 2483 | 2467 | |
| 2484 | - if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2485 | - || ( $access_permission && !$has_product_attached) |
|
| 2486 | - || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2468 | + // Check if the user is taking the course |
|
| 2469 | + $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2487 | 2470 | |
| 2488 | - return $content; |
|
| 2471 | + if(WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { |
|
| 2489 | 2472 | |
| 2490 | - } else { |
|
| 2473 | + $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2474 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2491 | 2475 | |
| 2492 | - return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2476 | + $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2493 | 2477 | |
| 2494 | - } |
|
| 2478 | + } else { |
|
| 2495 | 2479 | |
| 2496 | - }// end single_course_content |
|
| 2480 | + $has_product_attached = false; |
|
| 2497 | 2481 | |
| 2498 | - /** |
|
| 2499 | - * Output the the single course lessons title with markup. |
|
| 2500 | - * |
|
| 2501 | - * @since 1.9.0 |
|
| 2502 | - */ |
|
| 2503 | - public static function the_course_lessons_title(){ |
|
| 2504 | - global $post; |
|
| 2505 | - $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2506 | - $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2482 | + } |
|
| 2507 | 2483 | |
| 2508 | - // title should be Other Lessons if there are lessons belonging to models. |
|
| 2509 | - $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2510 | - if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2484 | + if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2485 | + || ( $access_permission && !$has_product_attached) |
|
| 2486 | + || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2511 | 2487 | |
| 2512 | - $title = __('Lessons', 'woothemes-sensei'); |
|
| 2488 | + return $content; |
|
| 2513 | 2489 | |
| 2514 | - } |
|
| 2490 | + } else { |
|
| 2515 | 2491 | |
| 2516 | - /** |
|
| 2517 | - * hook document in class-woothemes-sensei-message.php |
|
| 2518 | - */ |
|
| 2519 | - $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2492 | + return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2520 | 2493 | |
| 2521 | - ob_start(); // start capturing the following output. |
|
| 2494 | + } |
|
| 2522 | 2495 | |
| 2523 | - ?> |
|
| 2496 | + }// end single_course_content |
|
| 2497 | + |
|
| 2498 | + /** |
|
| 2499 | + * Output the the single course lessons title with markup. |
|
| 2500 | + * |
|
| 2501 | + * @since 1.9.0 |
|
| 2502 | + */ |
|
| 2503 | + public static function the_course_lessons_title(){ |
|
| 2504 | + global $post; |
|
| 2505 | + $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2506 | + $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2507 | + |
|
| 2508 | + // title should be Other Lessons if there are lessons belonging to models. |
|
| 2509 | + $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2510 | + if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2511 | + |
|
| 2512 | + $title = __('Lessons', 'woothemes-sensei'); |
|
| 2513 | + |
|
| 2514 | + } |
|
| 2515 | + |
|
| 2516 | + /** |
|
| 2517 | + * hook document in class-woothemes-sensei-message.php |
|
| 2518 | + */ |
|
| 2519 | + $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2520 | + |
|
| 2521 | + ob_start(); // start capturing the following output. |
|
| 2522 | + |
|
| 2523 | + ?> |
|
| 2524 | 2524 | |
| 2525 | 2525 | <header> |
| 2526 | 2526 | <h2> <?php echo $title; ?> </h2> |
@@ -2528,277 +2528,277 @@ discard block |
||
| 2528 | 2528 | |
| 2529 | 2529 | <?php |
| 2530 | 2530 | |
| 2531 | - /** |
|
| 2532 | - * Filter the title and markup that appears above the lessons on a single course |
|
| 2533 | - * page. |
|
| 2534 | - * |
|
| 2535 | - * @since 1.9.0 |
|
| 2536 | - * @param string $lessons_title_html |
|
| 2537 | - */ |
|
| 2538 | - echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2539 | - |
|
| 2540 | - }// end the_course_lessons_title |
|
| 2541 | - |
|
| 2542 | - /** |
|
| 2543 | - * This function loads the global wp_query object with with lessons |
|
| 2544 | - * of the current course. It is designed to be used on the single-course template |
|
| 2545 | - * and expects the global post to be a singular course. |
|
| 2546 | - * |
|
| 2547 | - * This function excludes lessons belonging to modules as they are |
|
| 2548 | - * queried separately. |
|
| 2549 | - * |
|
| 2550 | - * @since 1.9.0 |
|
| 2551 | - * @global $wp_query |
|
| 2552 | - */ |
|
| 2553 | - public static function load_single_course_lessons_query(){ |
|
| 2531 | + /** |
|
| 2532 | + * Filter the title and markup that appears above the lessons on a single course |
|
| 2533 | + * page. |
|
| 2534 | + * |
|
| 2535 | + * @since 1.9.0 |
|
| 2536 | + * @param string $lessons_title_html |
|
| 2537 | + */ |
|
| 2538 | + echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2554 | 2539 | |
| 2555 | - global $post, $wp_query; |
|
| 2540 | + }// end the_course_lessons_title |
|
| 2556 | 2541 | |
| 2557 | - $course_id = $post->ID; |
|
| 2558 | - |
|
| 2559 | - if( 'course' != get_post_type( $course_id ) ){ |
|
| 2560 | - return; |
|
| 2561 | - } |
|
| 2542 | + /** |
|
| 2543 | + * This function loads the global wp_query object with with lessons |
|
| 2544 | + * of the current course. It is designed to be used on the single-course template |
|
| 2545 | + * and expects the global post to be a singular course. |
|
| 2546 | + * |
|
| 2547 | + * This function excludes lessons belonging to modules as they are |
|
| 2548 | + * queried separately. |
|
| 2549 | + * |
|
| 2550 | + * @since 1.9.0 |
|
| 2551 | + * @global $wp_query |
|
| 2552 | + */ |
|
| 2553 | + public static function load_single_course_lessons_query(){ |
|
| 2562 | 2554 | |
| 2563 | - $course_lesson_query_args = array( |
|
| 2564 | - 'post_type' => 'lesson', |
|
| 2565 | - 'posts_per_page' => 500, |
|
| 2566 | - 'orderby' => 'date', |
|
| 2567 | - 'order' => 'ASC', |
|
| 2568 | - 'meta_query' => array( |
|
| 2569 | - array( |
|
| 2570 | - 'key' => '_lesson_course', |
|
| 2571 | - 'value' => intval( $course_id ), |
|
| 2572 | - ), |
|
| 2573 | - ), |
|
| 2574 | - 'post_status' => 'public', |
|
| 2575 | - 'suppress_filters' => 0, |
|
| 2576 | - ); |
|
| 2555 | + global $post, $wp_query; |
|
| 2577 | 2556 | |
| 2578 | - // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2579 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2580 | - if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2557 | + $course_id = $post->ID; |
|
| 2581 | 2558 | |
| 2582 | - $terms_ids = array(); |
|
| 2583 | - foreach( $modules as $term ){ |
|
| 2559 | + if( 'course' != get_post_type( $course_id ) ){ |
|
| 2560 | + return; |
|
| 2561 | + } |
|
| 2584 | 2562 | |
| 2585 | - $terms_ids[] = $term->term_id; |
|
| 2563 | + $course_lesson_query_args = array( |
|
| 2564 | + 'post_type' => 'lesson', |
|
| 2565 | + 'posts_per_page' => 500, |
|
| 2566 | + 'orderby' => 'date', |
|
| 2567 | + 'order' => 'ASC', |
|
| 2568 | + 'meta_query' => array( |
|
| 2569 | + array( |
|
| 2570 | + 'key' => '_lesson_course', |
|
| 2571 | + 'value' => intval( $course_id ), |
|
| 2572 | + ), |
|
| 2573 | + ), |
|
| 2574 | + 'post_status' => 'public', |
|
| 2575 | + 'suppress_filters' => 0, |
|
| 2576 | + ); |
|
| 2577 | + |
|
| 2578 | + // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2579 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2580 | + if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2581 | + |
|
| 2582 | + $terms_ids = array(); |
|
| 2583 | + foreach( $modules as $term ){ |
|
| 2584 | + |
|
| 2585 | + $terms_ids[] = $term->term_id; |
|
| 2586 | 2586 | |
| 2587 | - } |
|
| 2587 | + } |
|
| 2588 | 2588 | |
| 2589 | - $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2590 | - array( |
|
| 2591 | - 'taxonomy' => 'module', |
|
| 2592 | - 'field' => 'id', |
|
| 2593 | - 'terms' => $terms_ids, |
|
| 2594 | - 'operator' => 'NOT IN', |
|
| 2595 | - ), |
|
| 2596 | - ); |
|
| 2597 | - } |
|
| 2589 | + $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2590 | + array( |
|
| 2591 | + 'taxonomy' => 'module', |
|
| 2592 | + 'field' => 'id', |
|
| 2593 | + 'terms' => $terms_ids, |
|
| 2594 | + 'operator' => 'NOT IN', |
|
| 2595 | + ), |
|
| 2596 | + ); |
|
| 2597 | + } |
|
| 2598 | 2598 | |
| 2599 | - $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2599 | + $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2600 | 2600 | |
| 2601 | - }// load_single_course_lessons |
|
| 2601 | + }// load_single_course_lessons |
|
| 2602 | 2602 | |
| 2603 | - /** |
|
| 2604 | - * Flush the rewrite rules for a course post type |
|
| 2605 | - * |
|
| 2606 | - * @since 1.9.0 |
|
| 2607 | - * |
|
| 2608 | - * @param $post_id |
|
| 2609 | - */ |
|
| 2610 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 2603 | + /** |
|
| 2604 | + * Flush the rewrite rules for a course post type |
|
| 2605 | + * |
|
| 2606 | + * @since 1.9.0 |
|
| 2607 | + * |
|
| 2608 | + * @param $post_id |
|
| 2609 | + */ |
|
| 2610 | + public static function flush_rewrite_rules( $post_id ){ |
|
| 2611 | 2611 | |
| 2612 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2612 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2613 | 2613 | |
| 2614 | - return; |
|
| 2614 | + return; |
|
| 2615 | 2615 | |
| 2616 | - } |
|
| 2616 | + } |
|
| 2617 | 2617 | |
| 2618 | 2618 | |
| 2619 | - if( 'course' == get_post_type( $post_id ) ){ |
|
| 2619 | + if( 'course' == get_post_type( $post_id ) ){ |
|
| 2620 | 2620 | |
| 2621 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 2621 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 2622 | 2622 | |
| 2623 | - } |
|
| 2623 | + } |
|
| 2624 | 2624 | |
| 2625 | - } |
|
| 2625 | + } |
|
| 2626 | 2626 | |
| 2627 | - /** |
|
| 2628 | - * Optionally return the full content on the single course pages |
|
| 2629 | - * depending on the users course_single_content_display setting |
|
| 2630 | - * |
|
| 2631 | - * @since 1.9.0 |
|
| 2632 | - * @param $excerpt |
|
| 2633 | - * @return string |
|
| 2634 | - */ |
|
| 2635 | - public static function full_content_excerpt_override( $excerpt ){ |
|
| 2627 | + /** |
|
| 2628 | + * Optionally return the full content on the single course pages |
|
| 2629 | + * depending on the users course_single_content_display setting |
|
| 2630 | + * |
|
| 2631 | + * @since 1.9.0 |
|
| 2632 | + * @param $excerpt |
|
| 2633 | + * @return string |
|
| 2634 | + */ |
|
| 2635 | + public static function full_content_excerpt_override( $excerpt ){ |
|
| 2636 | 2636 | |
| 2637 | - if ( is_singular('course') && |
|
| 2638 | - 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2637 | + if ( is_singular('course') && |
|
| 2638 | + 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2639 | 2639 | |
| 2640 | - return get_the_content(); |
|
| 2640 | + return get_the_content(); |
|
| 2641 | 2641 | |
| 2642 | - } else { |
|
| 2642 | + } else { |
|
| 2643 | 2643 | |
| 2644 | - return $excerpt; |
|
| 2644 | + return $excerpt; |
|
| 2645 | 2645 | |
| 2646 | - } |
|
| 2646 | + } |
|
| 2647 | 2647 | |
| 2648 | - } |
|
| 2648 | + } |
|
| 2649 | 2649 | |
| 2650 | - /** |
|
| 2651 | - * Output the course actions like start taking course, register, add to cart etc. |
|
| 2652 | - * |
|
| 2653 | - * @since 1.9.0 |
|
| 2654 | - */ |
|
| 2655 | - public static function the_course_enrolment_actions(){ |
|
| 2656 | - ?> |
|
| 2650 | + /** |
|
| 2651 | + * Output the course actions like start taking course, register, add to cart etc. |
|
| 2652 | + * |
|
| 2653 | + * @since 1.9.0 |
|
| 2654 | + */ |
|
| 2655 | + public static function the_course_enrolment_actions(){ |
|
| 2656 | + ?> |
|
| 2657 | 2657 | <section class="course-meta course-enrolment"> |
| 2658 | 2658 | <?php |
| 2659 | - global $post, $current_user; |
|
| 2660 | - $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2661 | - if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2662 | - |
|
| 2663 | - // Get the product ID |
|
| 2664 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2665 | - |
|
| 2666 | - // Check for woocommerce |
|
| 2667 | - if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2668 | - sensei_wc_add_to_cart($post->ID); |
|
| 2669 | - } else { |
|
| 2670 | - sensei_start_course_form($post->ID); |
|
| 2671 | - } // End If Statement |
|
| 2672 | - |
|
| 2673 | - } elseif ( is_user_logged_in() ) { |
|
| 2674 | - |
|
| 2675 | - // Check if course is completed |
|
| 2676 | - $user_course_status = WooThemes_Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2677 | - $completed_course = WooThemes_Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2678 | - // Success message |
|
| 2679 | - if ( $completed_course ) { ?> |
|
| 2659 | + global $post, $current_user; |
|
| 2660 | + $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2661 | + if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2662 | + |
|
| 2663 | + // Get the product ID |
|
| 2664 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2665 | + |
|
| 2666 | + // Check for woocommerce |
|
| 2667 | + if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2668 | + sensei_wc_add_to_cart($post->ID); |
|
| 2669 | + } else { |
|
| 2670 | + sensei_start_course_form($post->ID); |
|
| 2671 | + } // End If Statement |
|
| 2672 | + |
|
| 2673 | + } elseif ( is_user_logged_in() ) { |
|
| 2674 | + |
|
| 2675 | + // Check if course is completed |
|
| 2676 | + $user_course_status = WooThemes_Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2677 | + $completed_course = WooThemes_Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2678 | + // Success message |
|
| 2679 | + if ( $completed_course ) { ?> |
|
| 2680 | 2680 | <div class="status completed"><?php _e( 'Completed', 'woothemes-sensei' ); ?></div> |
| 2681 | 2681 | <?php |
| 2682 | - $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2683 | - if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2682 | + $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2683 | + if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2684 | 2684 | <p class="sensei-results-links"> |
| 2685 | 2685 | <?php |
| 2686 | - $results_link = ''; |
|
| 2687 | - if( $has_quizzes ) { |
|
| 2688 | - $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2689 | - } |
|
| 2690 | - $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2691 | - echo $results_link; |
|
| 2692 | - ?></p> |
|
| 2686 | + $results_link = ''; |
|
| 2687 | + if( $has_quizzes ) { |
|
| 2688 | + $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2689 | + } |
|
| 2690 | + $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2691 | + echo $results_link; |
|
| 2692 | + ?></p> |
|
| 2693 | 2693 | <?php } ?> |
| 2694 | 2694 | <?php } else { ?> |
| 2695 | 2695 | <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div> |
| 2696 | 2696 | <?php } |
| 2697 | 2697 | |
| 2698 | - } else { |
|
| 2699 | - // Get the product ID |
|
| 2700 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2701 | - // Check for woocommerce |
|
| 2702 | - if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2698 | + } else { |
|
| 2699 | + // Get the product ID |
|
| 2700 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2701 | + // Check for woocommerce |
|
| 2702 | + if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2703 | 2703 | |
| 2704 | - sensei_wc_add_to_cart($post->ID); |
|
| 2704 | + sensei_wc_add_to_cart($post->ID); |
|
| 2705 | 2705 | |
| 2706 | - } else { |
|
| 2706 | + } else { |
|
| 2707 | 2707 | |
| 2708 | - if( get_option( 'users_can_register') ) { |
|
| 2708 | + if( get_option( 'users_can_register') ) { |
|
| 2709 | 2709 | |
| 2710 | 2710 | |
| 2711 | - $my_courses_page_id = ''; |
|
| 2711 | + $my_courses_page_id = ''; |
|
| 2712 | 2712 | |
| 2713 | - /** |
|
| 2714 | - * Filter to force Sensei to output the default WordPress user |
|
| 2715 | - * registration link. |
|
| 2716 | - * |
|
| 2717 | - * @since 1.9.0 |
|
| 2718 | - * @param bool $wp_register_link default false |
|
| 2719 | - */ |
|
| 2713 | + /** |
|
| 2714 | + * Filter to force Sensei to output the default WordPress user |
|
| 2715 | + * registration link. |
|
| 2716 | + * |
|
| 2717 | + * @since 1.9.0 |
|
| 2718 | + * @param bool $wp_register_link default false |
|
| 2719 | + */ |
|
| 2720 | 2720 | |
| 2721 | - $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2721 | + $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2722 | 2722 | |
| 2723 | - $settings = Sensei()->settings->get_settings(); |
|
| 2724 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 2725 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2723 | + $settings = Sensei()->settings->get_settings(); |
|
| 2724 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 2725 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2726 | 2726 | |
| 2727 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2727 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2728 | 2728 | |
| 2729 | - } |
|
| 2729 | + } |
|
| 2730 | 2730 | |
| 2731 | - // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2732 | - // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2733 | - if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2731 | + // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2732 | + // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2733 | + if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2734 | 2734 | |
| 2735 | - $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2736 | - $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2737 | - echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2735 | + $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2736 | + $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2737 | + echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2738 | 2738 | |
| 2739 | - } else{ |
|
| 2739 | + } else{ |
|
| 2740 | 2740 | |
| 2741 | - wp_register( '<div class="status register">', '</div>' ); |
|
| 2741 | + wp_register( '<div class="status register">', '</div>' ); |
|
| 2742 | 2742 | |
| 2743 | - } |
|
| 2743 | + } |
|
| 2744 | 2744 | |
| 2745 | - } // end if user can register |
|
| 2745 | + } // end if user can register |
|
| 2746 | 2746 | |
| 2747 | - } // End If Statement |
|
| 2747 | + } // End If Statement |
|
| 2748 | 2748 | |
| 2749 | - } // End If Statement ?> |
|
| 2749 | + } // End If Statement ?> |
|
| 2750 | 2750 | |
| 2751 | 2751 | </section><?php |
| 2752 | 2752 | |
| 2753 | - }// end the_course_enrolment_actions |
|
| 2753 | + }// end the_course_enrolment_actions |
|
| 2754 | 2754 | |
| 2755 | - /** |
|
| 2756 | - * Output the course video inside the loop. |
|
| 2757 | - * |
|
| 2758 | - * @since 1.9.0 |
|
| 2759 | - */ |
|
| 2760 | - public static function the_course_video(){ |
|
| 2755 | + /** |
|
| 2756 | + * Output the course video inside the loop. |
|
| 2757 | + * |
|
| 2758 | + * @since 1.9.0 |
|
| 2759 | + */ |
|
| 2760 | + public static function the_course_video(){ |
|
| 2761 | 2761 | |
| 2762 | - global $post; |
|
| 2763 | - // Get the meta info |
|
| 2764 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2762 | + global $post; |
|
| 2763 | + // Get the meta info |
|
| 2764 | + $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2765 | 2765 | |
| 2766 | - if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2766 | + if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2767 | 2767 | |
| 2768 | - $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2768 | + $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2769 | 2769 | |
| 2770 | - } // End If Statement |
|
| 2770 | + } // End If Statement |
|
| 2771 | 2771 | |
| 2772 | - if ( '' != $course_video_embed ) { ?> |
|
| 2772 | + if ( '' != $course_video_embed ) { ?> |
|
| 2773 | 2773 | |
| 2774 | 2774 | <div class="course-video"> |
| 2775 | 2775 | <?php echo html_entity_decode($course_video_embed); ?> |
| 2776 | 2776 | </div> |
| 2777 | 2777 | |
| 2778 | 2778 | <?php } // End If Statement |
| 2779 | - } |
|
| 2779 | + } |
|
| 2780 | 2780 | |
| 2781 | - /** |
|
| 2782 | - * Output the title for the single lesson page |
|
| 2783 | - * |
|
| 2784 | - * @global $post |
|
| 2785 | - * @since 1.9.0 |
|
| 2786 | - */ |
|
| 2787 | - public static function the_title(){ |
|
| 2781 | + /** |
|
| 2782 | + * Output the title for the single lesson page |
|
| 2783 | + * |
|
| 2784 | + * @global $post |
|
| 2785 | + * @since 1.9.0 |
|
| 2786 | + */ |
|
| 2787 | + public static function the_title(){ |
|
| 2788 | 2788 | |
| 2789 | - global $post; |
|
| 2789 | + global $post; |
|
| 2790 | 2790 | |
| 2791 | - ?> |
|
| 2791 | + ?> |
|
| 2792 | 2792 | <header> |
| 2793 | 2793 | |
| 2794 | 2794 | <h1> |
| 2795 | 2795 | |
| 2796 | 2796 | <?php |
| 2797 | - /** |
|
| 2798 | - * Filter documented in class-sensei-messages.php the_title |
|
| 2799 | - */ |
|
| 2800 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2801 | - ?> |
|
| 2797 | + /** |
|
| 2798 | + * Filter documented in class-sensei-messages.php the_title |
|
| 2799 | + */ |
|
| 2800 | + echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2801 | + ?> |
|
| 2802 | 2802 | |
| 2803 | 2803 | </h1> |
| 2804 | 2804 | |
@@ -2806,111 +2806,111 @@ discard block |
||
| 2806 | 2806 | |
| 2807 | 2807 | <?php |
| 2808 | 2808 | |
| 2809 | - }//the_title |
|
| 2810 | - |
|
| 2811 | - /** |
|
| 2812 | - * Show the title on the course category pages |
|
| 2813 | - * |
|
| 2814 | - * @since 1.9.0 |
|
| 2815 | - */ |
|
| 2816 | - public static function course_category_title(){ |
|
| 2817 | - |
|
| 2818 | - if( ! is_tax( 'course-category' ) ){ |
|
| 2819 | - return; |
|
| 2820 | - } |
|
| 2821 | - |
|
| 2822 | - $category_slug = get_query_var('course-category'); |
|
| 2823 | - $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2824 | - |
|
| 2825 | - if( ! empty($term) ){ |
|
| 2826 | - |
|
| 2827 | - $title = $term->name; |
|
| 2828 | - |
|
| 2829 | - }else{ |
|
| 2830 | - |
|
| 2831 | - $title = 'Course Category'; |
|
| 2832 | - |
|
| 2833 | - } |
|
| 2834 | - |
|
| 2835 | - $html = '<h2 class="sensei-category-title">'; |
|
| 2836 | - $html .= __('Category') . ' ' . $title; |
|
| 2837 | - $html .= '</h2>'; |
|
| 2838 | - |
|
| 2839 | - echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2840 | - |
|
| 2841 | - }// course_category_title |
|
| 2842 | - |
|
| 2843 | - /** |
|
| 2844 | - * Alter the course query to respect the order set for courses and apply |
|
| 2845 | - * this on the course-category pages. |
|
| 2846 | - * |
|
| 2847 | - * @since 1.9.0 |
|
| 2848 | - * |
|
| 2849 | - * @param WP_Query $query |
|
| 2850 | - * @return WP_Query |
|
| 2851 | - */ |
|
| 2852 | - public static function alter_course_category_order( $query ){ |
|
| 2853 | - |
|
| 2854 | - if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2855 | - return $query; |
|
| 2856 | - } |
|
| 2857 | - |
|
| 2858 | - $order = get_option( 'sensei_course_order', '' ); |
|
| 2859 | - if( !empty( $order ) ){ |
|
| 2860 | - $query->set('orderby', 'menu_order' ); |
|
| 2861 | - $query->set('order', 'ASC' ); |
|
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - return $query; |
|
| 2865 | - |
|
| 2866 | - } |
|
| 2867 | - |
|
| 2868 | - /** |
|
| 2869 | - * The very basic course query arguments |
|
| 2870 | - * so we don't have to repeat this througout |
|
| 2871 | - * the code base. |
|
| 2872 | - * |
|
| 2873 | - * Usage: |
|
| 2874 | - * $args = Sensei_Course::get_default_query_args(); |
|
| 2875 | - * $args['custom_arg'] ='custom value'; |
|
| 2876 | - * $courses = get_posts( $args ) |
|
| 2877 | - * |
|
| 2878 | - * @since 1.9.0 |
|
| 2879 | - * |
|
| 2880 | - * @return array |
|
| 2881 | - */ |
|
| 2882 | - public static function get_default_query_args(){ |
|
| 2883 | - return array( |
|
| 2884 | - 'post_type' => 'course', |
|
| 2885 | - 'posts_per_page' => 1000, |
|
| 2886 | - 'orderby' => 'date', |
|
| 2887 | - 'order' => 'DESC', |
|
| 2888 | - 'suppress_filters' => 0 |
|
| 2889 | - ); |
|
| 2890 | - } |
|
| 2891 | - |
|
| 2892 | - /** |
|
| 2893 | - * Check if the prerequisite course is completed |
|
| 2894 | - * Courses with no pre-requisite should always return true |
|
| 2895 | - * |
|
| 2896 | - * @since 1.9.0 |
|
| 2897 | - * @param $course_id |
|
| 2898 | - * @return bool |
|
| 2899 | - */ |
|
| 2900 | - public static function is_prerequisite_complete( $course_id ){ |
|
| 2901 | - |
|
| 2902 | - $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2903 | - |
|
| 2904 | - // if it has a pre requisite course check it |
|
| 2905 | - if( ! empty( $course_prerequisite_id ) ){ |
|
| 2906 | - |
|
| 2907 | - return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2908 | - |
|
| 2909 | - } |
|
| 2910 | - |
|
| 2911 | - return true; |
|
| 2912 | - |
|
| 2913 | - }// end is_prerequisite_complete |
|
| 2809 | + }//the_title |
|
| 2810 | + |
|
| 2811 | + /** |
|
| 2812 | + * Show the title on the course category pages |
|
| 2813 | + * |
|
| 2814 | + * @since 1.9.0 |
|
| 2815 | + */ |
|
| 2816 | + public static function course_category_title(){ |
|
| 2817 | + |
|
| 2818 | + if( ! is_tax( 'course-category' ) ){ |
|
| 2819 | + return; |
|
| 2820 | + } |
|
| 2821 | + |
|
| 2822 | + $category_slug = get_query_var('course-category'); |
|
| 2823 | + $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2824 | + |
|
| 2825 | + if( ! empty($term) ){ |
|
| 2826 | + |
|
| 2827 | + $title = $term->name; |
|
| 2828 | + |
|
| 2829 | + }else{ |
|
| 2830 | + |
|
| 2831 | + $title = 'Course Category'; |
|
| 2832 | + |
|
| 2833 | + } |
|
| 2834 | + |
|
| 2835 | + $html = '<h2 class="sensei-category-title">'; |
|
| 2836 | + $html .= __('Category') . ' ' . $title; |
|
| 2837 | + $html .= '</h2>'; |
|
| 2838 | + |
|
| 2839 | + echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2840 | + |
|
| 2841 | + }// course_category_title |
|
| 2842 | + |
|
| 2843 | + /** |
|
| 2844 | + * Alter the course query to respect the order set for courses and apply |
|
| 2845 | + * this on the course-category pages. |
|
| 2846 | + * |
|
| 2847 | + * @since 1.9.0 |
|
| 2848 | + * |
|
| 2849 | + * @param WP_Query $query |
|
| 2850 | + * @return WP_Query |
|
| 2851 | + */ |
|
| 2852 | + public static function alter_course_category_order( $query ){ |
|
| 2853 | + |
|
| 2854 | + if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2855 | + return $query; |
|
| 2856 | + } |
|
| 2857 | + |
|
| 2858 | + $order = get_option( 'sensei_course_order', '' ); |
|
| 2859 | + if( !empty( $order ) ){ |
|
| 2860 | + $query->set('orderby', 'menu_order' ); |
|
| 2861 | + $query->set('order', 'ASC' ); |
|
| 2862 | + } |
|
| 2863 | + |
|
| 2864 | + return $query; |
|
| 2865 | + |
|
| 2866 | + } |
|
| 2867 | + |
|
| 2868 | + /** |
|
| 2869 | + * The very basic course query arguments |
|
| 2870 | + * so we don't have to repeat this througout |
|
| 2871 | + * the code base. |
|
| 2872 | + * |
|
| 2873 | + * Usage: |
|
| 2874 | + * $args = Sensei_Course::get_default_query_args(); |
|
| 2875 | + * $args['custom_arg'] ='custom value'; |
|
| 2876 | + * $courses = get_posts( $args ) |
|
| 2877 | + * |
|
| 2878 | + * @since 1.9.0 |
|
| 2879 | + * |
|
| 2880 | + * @return array |
|
| 2881 | + */ |
|
| 2882 | + public static function get_default_query_args(){ |
|
| 2883 | + return array( |
|
| 2884 | + 'post_type' => 'course', |
|
| 2885 | + 'posts_per_page' => 1000, |
|
| 2886 | + 'orderby' => 'date', |
|
| 2887 | + 'order' => 'DESC', |
|
| 2888 | + 'suppress_filters' => 0 |
|
| 2889 | + ); |
|
| 2890 | + } |
|
| 2891 | + |
|
| 2892 | + /** |
|
| 2893 | + * Check if the prerequisite course is completed |
|
| 2894 | + * Courses with no pre-requisite should always return true |
|
| 2895 | + * |
|
| 2896 | + * @since 1.9.0 |
|
| 2897 | + * @param $course_id |
|
| 2898 | + * @return bool |
|
| 2899 | + */ |
|
| 2900 | + public static function is_prerequisite_complete( $course_id ){ |
|
| 2901 | + |
|
| 2902 | + $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2903 | + |
|
| 2904 | + // if it has a pre requisite course check it |
|
| 2905 | + if( ! empty( $course_prerequisite_id ) ){ |
|
| 2906 | + |
|
| 2907 | + return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2908 | + |
|
| 2909 | + } |
|
| 2910 | + |
|
| 2911 | + return true; |
|
| 2912 | + |
|
| 2913 | + }// end is_prerequisite_complete |
|
| 2914 | 2914 | |
| 2915 | 2915 | |
| 2916 | 2916 | }// End Class |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Check if WooCommerce is active. |
| 49 | - * |
|
| 49 | + * |
|
| 50 | 50 | * @access public |
| 51 | 51 | * @since 1.0.2 |
| 52 | 52 | * @static |
@@ -191,15 +191,15 @@ discard block |
||
| 191 | 191 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - //Get the comments |
|
| 195 | - /** |
|
| 196 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 197 | - * |
|
| 198 | - * It runs while getting the comments for the given request. |
|
| 199 | - * |
|
| 200 | - * @param int|array $comments |
|
| 201 | - */ |
|
| 202 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 194 | + //Get the comments |
|
| 195 | + /** |
|
| 196 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 197 | + * |
|
| 198 | + * It runs while getting the comments for the given request. |
|
| 199 | + * |
|
| 200 | + * @param int|array $comments |
|
| 201 | + */ |
|
| 202 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 203 | 203 | |
| 204 | 204 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
| 205 | 205 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -284,18 +284,18 @@ discard block |
||
| 284 | 284 | return $dataset_changes; |
| 285 | 285 | } // End sensei_delete_activities() |
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Delete all activity for specified user |
|
| 289 | - * @access public |
|
| 287 | + /** |
|
| 288 | + * Delete all activity for specified user |
|
| 289 | + * @access public |
|
| 290 | 290 | * @since 1.5.0 |
| 291 | - * @param integer $user_id User ID |
|
| 292 | - * @return boolean |
|
| 293 | - */ |
|
| 294 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 291 | + * @param integer $user_id User ID |
|
| 292 | + * @return boolean |
|
| 293 | + */ |
|
| 294 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 295 | 295 | |
| 296 | - $dataset_changes = false; |
|
| 296 | + $dataset_changes = false; |
|
| 297 | 297 | |
| 298 | - if( $user_id ) { |
|
| 298 | + if( $user_id ) { |
|
| 299 | 299 | |
| 300 | 300 | $activities = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
| 301 | 301 | |
@@ -340,35 +340,35 @@ discard block |
||
| 340 | 340 | return $activity_value; |
| 341 | 341 | } // End sensei_get_activity_value() |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * Checks if a user (by email) has bought an item. |
|
| 345 | - * |
|
| 346 | - * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 347 | - * @access public |
|
| 348 | - * @since 1.0.0 |
|
| 349 | - * @param string $customer_email |
|
| 350 | - * @param int $user_id |
|
| 351 | - * @param int $product_id |
|
| 352 | - * @return bool |
|
| 353 | - */ |
|
| 354 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 343 | + /** |
|
| 344 | + * Checks if a user (by email) has bought an item. |
|
| 345 | + * |
|
| 346 | + * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 347 | + * @access public |
|
| 348 | + * @since 1.0.0 |
|
| 349 | + * @param string $customer_email |
|
| 350 | + * @param int $user_id |
|
| 351 | + * @param int $product_id |
|
| 352 | + * @return bool |
|
| 353 | + */ |
|
| 354 | + public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 355 | 355 | |
| 356 | - $emails = array(); |
|
| 356 | + $emails = array(); |
|
| 357 | 357 | |
| 358 | - if ( $user_id ) { |
|
| 359 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 360 | - $emails[] = $user->user_email; |
|
| 361 | - } |
|
| 358 | + if ( $user_id ) { |
|
| 359 | + $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 360 | + $emails[] = $user->user_email; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - if ( is_email( $customer_email ) ) |
|
| 364 | - $emails[] = $customer_email; |
|
| 363 | + if ( is_email( $customer_email ) ) |
|
| 364 | + $emails[] = $customer_email; |
|
| 365 | 365 | |
| 366 | - if ( sizeof( $emails ) == 0 ) |
|
| 367 | - return false; |
|
| 366 | + if ( sizeof( $emails ) == 0 ) |
|
| 367 | + return false; |
|
| 368 | 368 | |
| 369 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 369 | + return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 370 | 370 | |
| 371 | - } // End sensei_customer_bought_product() |
|
| 371 | + } // End sensei_customer_bought_product() |
|
| 372 | 372 | |
| 373 | 373 | /** |
| 374 | 374 | * Load the WordPress rich text editor |
@@ -471,72 +471,72 @@ discard block |
||
| 471 | 471 | |
| 472 | 472 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
| 476 | - * |
|
| 477 | - * This filter was mainly added for Unit Testing purposes. |
|
| 478 | - * |
|
| 479 | - * @since 1.7.4 |
|
| 480 | - * |
|
| 481 | - * @param array $file_upload_args { |
|
| 482 | - * array of current values |
|
| 483 | - * |
|
| 484 | - * @type string test_form set to false by default |
|
| 485 | - * } |
|
| 486 | - */ |
|
| 487 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 488 | - |
|
| 489 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 490 | - |
|
| 491 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 492 | - return false; |
|
| 493 | - } else { |
|
| 474 | + /** |
|
| 475 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
| 476 | + * |
|
| 477 | + * This filter was mainly added for Unit Testing purposes. |
|
| 478 | + * |
|
| 479 | + * @since 1.7.4 |
|
| 480 | + * |
|
| 481 | + * @param array $file_upload_args { |
|
| 482 | + * array of current values |
|
| 483 | + * |
|
| 484 | + * @type string test_form set to false by default |
|
| 485 | + * } |
|
| 486 | + */ |
|
| 487 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 488 | + |
|
| 489 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 490 | + |
|
| 491 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 492 | + return false; |
|
| 493 | + } else { |
|
| 494 | 494 | |
| 495 | - $filename = $file_return['file']; |
|
| 495 | + $filename = $file_return['file']; |
|
| 496 | 496 | |
| 497 | - $attachment = array( |
|
| 498 | - 'post_mime_type' => $file_return['type'], |
|
| 499 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 500 | - 'post_content' => '', |
|
| 501 | - 'post_status' => 'inherit', |
|
| 502 | - 'guid' => $file_return['url'] |
|
| 503 | - ); |
|
| 497 | + $attachment = array( |
|
| 498 | + 'post_mime_type' => $file_return['type'], |
|
| 499 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 500 | + 'post_content' => '', |
|
| 501 | + 'post_status' => 'inherit', |
|
| 502 | + 'guid' => $file_return['url'] |
|
| 503 | + ); |
|
| 504 | 504 | |
| 505 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 505 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 506 | 506 | |
| 507 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 508 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 509 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 507 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 508 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 509 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 510 | 510 | |
| 511 | - if( 0 < intval( $attachment_id ) ) { |
|
| 512 | - return $attachment_id; |
|
| 513 | - } |
|
| 514 | - } |
|
| 511 | + if( 0 < intval( $attachment_id ) ) { |
|
| 512 | + return $attachment_id; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | 515 | |
| 516 | - return false; |
|
| 516 | + return false; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
| 520 | 520 | * Grade quiz automatically |
| 521 | - * |
|
| 522 | - * This function grades each question automatically if the are auto gradable. |
|
| 523 | - * It store all question grades. |
|
| 524 | - * |
|
| 525 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 526 | - * |
|
| 521 | + * |
|
| 522 | + * This function grades each question automatically if the are auto gradable. |
|
| 523 | + * It store all question grades. |
|
| 524 | + * |
|
| 525 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 526 | + * |
|
| 527 | 527 | * @param integer $quiz_id ID of quiz |
| 528 | 528 | * @param array $submitted questions id ans answers { |
| 529 | - * @type int $question_id |
|
| 530 | - * @type mixed $answer |
|
| 531 | - * } |
|
| 529 | + * @type int $question_id |
|
| 530 | + * @type mixed $answer |
|
| 531 | + * } |
|
| 532 | 532 | * @param integer $total_questions Total questions in quiz (not used) |
| 533 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 534 | - * |
|
| 533 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 534 | + * |
|
| 535 | 535 | * @return int $quiz_grade total sum of all question grades |
| 536 | 536 | */ |
| 537 | 537 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
| 538 | 538 | |
| 539 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 539 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 540 | 540 | |
| 541 | 541 | } // End sensei_grade_quiz_auto() |
| 542 | 542 | |
@@ -568,21 +568,21 @@ discard block |
||
| 568 | 568 | |
| 569 | 569 | /** |
| 570 | 570 | * Grade question automatically |
| 571 | - * |
|
| 572 | - * This function checks the question typ and then grades it accordingly. |
|
| 573 | - * |
|
| 574 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 575 | - * |
|
| 571 | + * |
|
| 572 | + * This function checks the question typ and then grades it accordingly. |
|
| 573 | + * |
|
| 574 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 575 | + * |
|
| 576 | 576 | * @param integer $question_id |
| 577 | - * @param string $question_type of the standard Sensei question types |
|
| 577 | + * @param string $question_type of the standard Sensei question types |
|
| 578 | 578 | * @param string $answer |
| 579 | - * @param int $user_id |
|
| 580 | - * |
|
| 579 | + * @param int $user_id |
|
| 580 | + * |
|
| 581 | 581 | * @return int $question_grade |
| 582 | 582 | */ |
| 583 | 583 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
| 584 | 584 | |
| 585 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 585 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 586 | 586 | |
| 587 | 587 | } // end sensei_grade_question_auto |
| 588 | 588 | |
@@ -628,35 +628,35 @@ discard block |
||
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | |
| 631 | - /** |
|
| 632 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 633 | - * |
|
| 634 | - * @since 1.7.4 |
|
| 635 | - * |
|
| 636 | - * @param integer $user_id |
|
| 637 | - * @param integer $lesson_id |
|
| 638 | - * @param bool $complete |
|
| 639 | - * |
|
| 640 | - * @return mixed boolean or comment_ID |
|
| 641 | - */ |
|
| 642 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 631 | + /** |
|
| 632 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 633 | + * |
|
| 634 | + * @since 1.7.4 |
|
| 635 | + * |
|
| 636 | + * @param integer $user_id |
|
| 637 | + * @param integer $lesson_id |
|
| 638 | + * @param bool $complete |
|
| 639 | + * |
|
| 640 | + * @return mixed boolean or comment_ID |
|
| 641 | + */ |
|
| 642 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 643 | 643 | |
| 644 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 644 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 645 | 645 | |
| 646 | - }// end user_start_lesson() |
|
| 646 | + }// end user_start_lesson() |
|
| 647 | 647 | |
| 648 | 648 | /** |
| 649 | 649 | * Mark a lesson as started for user |
| 650 | - * |
|
| 651 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 652 | - * |
|
| 653 | - * @since 1.6.0 |
|
| 654 | - * |
|
| 650 | + * |
|
| 651 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 652 | + * |
|
| 653 | + * @since 1.6.0 |
|
| 654 | + * |
|
| 655 | 655 | * @param integer $lesson_id ID of lesson |
| 656 | 656 | * @param int| string $user_id default 0 |
| 657 | - * @param bool $complete default false |
|
| 658 | - * |
|
| 659 | - * @return mixed boolean or comment_ID |
|
| 657 | + * @param bool $complete default false |
|
| 658 | + * |
|
| 659 | + * @return mixed boolean or comment_ID |
|
| 660 | 660 | */ |
| 661 | 661 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
| 662 | 662 | |
@@ -702,21 +702,21 @@ discard block |
||
| 702 | 702 | $metadata['start'] = current_time('mysql'); |
| 703 | 703 | $activity_logged = WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
| 704 | 704 | |
| 705 | - } else { |
|
| 705 | + } else { |
|
| 706 | 706 | |
| 707 | - // if users is already taking the lesson and the status changes to complete update it |
|
| 708 | - $current_user_activity = get_comment($activity_logged); |
|
| 709 | - if( $status=='complete' && |
|
| 710 | - $status != $current_user_activity->comment_approved ){ |
|
| 707 | + // if users is already taking the lesson and the status changes to complete update it |
|
| 708 | + $current_user_activity = get_comment($activity_logged); |
|
| 709 | + if( $status=='complete' && |
|
| 710 | + $status != $current_user_activity->comment_approved ){ |
|
| 711 | 711 | |
| 712 | - $comment = array(); |
|
| 713 | - $comment['comment_ID'] = $activity_logged; |
|
| 714 | - $comment['comment_approved'] = $status; |
|
| 715 | - wp_update_comment( $comment ); |
|
| 712 | + $comment = array(); |
|
| 713 | + $comment['comment_ID'] = $activity_logged; |
|
| 714 | + $comment['comment_approved'] = $status; |
|
| 715 | + wp_update_comment( $comment ); |
|
| 716 | 716 | |
| 717 | - } |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - } |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | 721 | if ( $complete ) { |
| 722 | 722 | // Run this *after* the lesson status has been created/updated |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | /** |
| 863 | 863 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 864 | 864 | * |
| 865 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 865 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 866 | 866 | * @param mixed $question |
| 867 | 867 | * @param int $user_id |
| 868 | 868 | * @return string |
@@ -979,17 +979,17 @@ discard block |
||
| 979 | 979 | * @return void |
| 980 | 980 | */ |
| 981 | 981 | public static function sort_array_by_key( $array, $key ) { |
| 982 | - $sorter = array(); |
|
| 983 | - $ret = array(); |
|
| 984 | - reset( $array ); |
|
| 985 | - foreach ( $array as $ii => $va ) { |
|
| 986 | - $sorter[$ii] = $va[$key]; |
|
| 987 | - } // End For Loop |
|
| 988 | - asort( $sorter ); |
|
| 989 | - foreach ( $sorter as $ii => $va ) { |
|
| 990 | - $ret[$ii] = $array[$ii]; |
|
| 991 | - } // End For Loop |
|
| 992 | - $array = $ret; |
|
| 982 | + $sorter = array(); |
|
| 983 | + $ret = array(); |
|
| 984 | + reset( $array ); |
|
| 985 | + foreach ( $array as $ii => $va ) { |
|
| 986 | + $sorter[$ii] = $va[$key]; |
|
| 987 | + } // End For Loop |
|
| 988 | + asort( $sorter ); |
|
| 989 | + foreach ( $sorter as $ii => $va ) { |
|
| 990 | + $ret[$ii] = $array[$ii]; |
|
| 991 | + } // End For Loop |
|
| 992 | + $array = $ret; |
|
| 993 | 993 | } // End sort_array_by_key() |
| 994 | 994 | |
| 995 | 995 | /** |
@@ -1002,21 +1002,21 @@ discard block |
||
| 1002 | 1002 | $questions_array = array(); |
| 1003 | 1003 | if ( 0 < $quiz_id ) { |
| 1004 | 1004 | $question_args = array( 'post_type' => 'question', |
| 1005 | - 'posts_per_page' => -1, |
|
| 1006 | - 'orderby' => 'ID', |
|
| 1007 | - 'order' => 'ASC', |
|
| 1008 | - 'meta_query' => array( |
|
| 1005 | + 'posts_per_page' => -1, |
|
| 1006 | + 'orderby' => 'ID', |
|
| 1007 | + 'order' => 'ASC', |
|
| 1008 | + 'meta_query' => array( |
|
| 1009 | 1009 | array( |
| 1010 | 1010 | 'key' => '_quiz_id', |
| 1011 | 1011 | 'value' => $quiz_id, |
| 1012 | 1012 | ) |
| 1013 | 1013 | ), |
| 1014 | - 'post_status' => 'any', |
|
| 1015 | - 'suppress_filters' => 0 |
|
| 1016 | - ); |
|
| 1017 | - $questions_array = get_posts( $question_args ); |
|
| 1018 | - } // End If Statement |
|
| 1019 | - return $questions_array; |
|
| 1014 | + 'post_status' => 'any', |
|
| 1015 | + 'suppress_filters' => 0 |
|
| 1016 | + ); |
|
| 1017 | + $questions_array = get_posts( $question_args ); |
|
| 1018 | + } // End If Statement |
|
| 1019 | + return $questions_array; |
|
| 1020 | 1020 | } // End lesson_quiz_questions() |
| 1021 | 1021 | |
| 1022 | 1022 | /** |
@@ -1256,20 +1256,20 @@ discard block |
||
| 1256 | 1256 | } |
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | - // add next lesson button |
|
| 1260 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1261 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1259 | + // add next lesson button |
|
| 1260 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1261 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1262 | 1262 | |
| 1263 | - // Output HTML |
|
| 1264 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1265 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1266 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1267 | - .'</a>'; |
|
| 1263 | + // Output HTML |
|
| 1264 | + if ( ( 0 < $next_lesson_id ) ) { |
|
| 1265 | + $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1266 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1267 | + .'</a>'; |
|
| 1268 | 1268 | |
| 1269 | - } |
|
| 1269 | + } |
|
| 1270 | 1270 | |
| 1271 | 1271 | } |
| 1272 | - // Lesson/Quiz not complete |
|
| 1272 | + // Lesson/Quiz not complete |
|
| 1273 | 1273 | else { |
| 1274 | 1274 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1275 | 1275 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1366,9 +1366,9 @@ discard block |
||
| 1366 | 1366 | $user_id = get_current_user_id(); |
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | - if( ! $user_id > 0 ){ |
|
| 1370 | - return false; |
|
| 1371 | - } |
|
| 1369 | + if( ! $user_id > 0 ){ |
|
| 1370 | + return false; |
|
| 1371 | + } |
|
| 1372 | 1372 | |
| 1373 | 1373 | $user_course_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
| 1374 | 1374 | if( $user_course_status_id ) { |
@@ -1509,14 +1509,14 @@ discard block |
||
| 1509 | 1509 | $user_id = get_current_user_id(); |
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1513 | - $course = $course->ID; |
|
| 1514 | - } |
|
| 1512 | + if( is_a( $course, 'WP_Post' ) ){ |
|
| 1513 | + $course = $course->ID; |
|
| 1514 | + } |
|
| 1515 | 1515 | |
| 1516 | 1516 | $user_course_status = WooThemes_Sensei_Utils::user_course_status( $course , $user_id ); |
| 1517 | 1517 | if( isset( $user_course_status->comment_approved ) ){ |
| 1518 | - $user_course_status = $user_course_status->comment_approved; |
|
| 1519 | - } |
|
| 1518 | + $user_course_status = $user_course_status->comment_approved; |
|
| 1519 | + } |
|
| 1520 | 1520 | |
| 1521 | 1521 | } |
| 1522 | 1522 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1552,7 +1552,7 @@ discard block |
||
| 1552 | 1552 | /** |
| 1553 | 1553 | * Check if a user has completed a lesson or not |
| 1554 | 1554 | * |
| 1555 | - * @uses Sensei() |
|
| 1555 | + * @uses Sensei() |
|
| 1556 | 1556 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
| 1557 | 1557 | * @param int $user_id |
| 1558 | 1558 | * @return boolean |
@@ -1573,10 +1573,10 @@ discard block |
||
| 1573 | 1573 | $user_id = get_current_user_id(); |
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | - // the user is not logged in |
|
| 1577 | - if( ! $user_id > 0 ){ |
|
| 1578 | - return false; |
|
| 1579 | - } |
|
| 1576 | + // the user is not logged in |
|
| 1577 | + if( ! $user_id > 0 ){ |
|
| 1578 | + return false; |
|
| 1579 | + } |
|
| 1580 | 1580 | $_user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
| 1581 | 1581 | |
| 1582 | 1582 | if ( $_user_lesson_status ) { |
@@ -1655,9 +1655,9 @@ discard block |
||
| 1655 | 1655 | */ |
| 1656 | 1656 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1657 | 1657 | |
| 1658 | - if( ! $user_id ) { |
|
| 1659 | - $user_id = get_current_user_id(); |
|
| 1660 | - } |
|
| 1658 | + if( ! $user_id ) { |
|
| 1659 | + $user_id = get_current_user_id(); |
|
| 1660 | + } |
|
| 1661 | 1661 | |
| 1662 | 1662 | if( $lesson_id > 0 && $user_id > 0 ) { |
| 1663 | 1663 | |
@@ -1708,12 +1708,12 @@ discard block |
||
| 1708 | 1708 | * Sets the status for the lesson |
| 1709 | 1709 | * |
| 1710 | 1710 | * @since 1.7.0 |
| 1711 | - * |
|
| 1711 | + * |
|
| 1712 | 1712 | * @param int|string $user_id |
| 1713 | 1713 | * @param int|string $lesson_id |
| 1714 | 1714 | * @param string $status |
| 1715 | 1715 | * @param array $metadata |
| 1716 | - * |
|
| 1716 | + * |
|
| 1717 | 1717 | * @return mixed false or comment_ID |
| 1718 | 1718 | */ |
| 1719 | 1719 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1863,360 +1863,360 @@ discard block |
||
| 1863 | 1863 | return $pieces; |
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | - /** |
|
| 1867 | - * |
|
| 1868 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1869 | - * @since 1.7.4 |
|
| 1870 | - * |
|
| 1871 | - * @param string $data_key maximum 39 characters allowed |
|
| 1872 | - * @param int $post_id |
|
| 1873 | - * @param mixed $value |
|
| 1874 | - * @param int $user_id |
|
| 1875 | - * |
|
| 1876 | - * @return bool $success |
|
| 1877 | - */ |
|
| 1878 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1879 | - |
|
| 1880 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1881 | - |
|
| 1882 | - }// end add_user_data |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * add user specific data to the passed in sensei post type id |
|
| 1886 | - * |
|
| 1887 | - * This function saves comment meta on the users current status. If no status is available |
|
| 1888 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1889 | - * |
|
| 1890 | - * @since 1.7.4 |
|
| 1891 | - * |
|
| 1892 | - * @param string $data_key maximum 39 characters allowed |
|
| 1893 | - * @param int $post_id |
|
| 1894 | - * @param mixed $value |
|
| 1895 | - * @param int $user_id |
|
| 1896 | - * |
|
| 1897 | - * @return bool $success |
|
| 1898 | - */ |
|
| 1899 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1900 | - |
|
| 1901 | - if( ! ( $user_id > 0 ) ){ |
|
| 1902 | - $user_id = get_current_user_id(); |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1906 | - $post_type = get_post_type( $post_id ); |
|
| 1907 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1908 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1909 | - || !get_userdata( $user_id ) |
|
| 1910 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1911 | - |
|
| 1912 | - return false; |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1916 | - // and get the activity ID |
|
| 1917 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1918 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1919 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1920 | - |
|
| 1921 | - $start_function = 'user_start_'.$post_type; |
|
| 1922 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1923 | - |
|
| 1924 | - }else{ |
|
| 1925 | - |
|
| 1926 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1927 | - |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - // store the data |
|
| 1931 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1932 | - |
|
| 1933 | - return $success; |
|
| 1934 | - |
|
| 1935 | - }//update_user_data |
|
| 1936 | - |
|
| 1937 | - /** |
|
| 1938 | - * Get the user data stored on the passed in post type |
|
| 1939 | - * |
|
| 1940 | - * This function gets the comment meta on the lesson or course status |
|
| 1941 | - * |
|
| 1942 | - * @since 1.7.4 |
|
| 1943 | - * |
|
| 1944 | - * @param $data_key |
|
| 1945 | - * @param $post_id |
|
| 1946 | - * @param int $user_id |
|
| 1947 | - * |
|
| 1948 | - * @return mixed $user_data_value |
|
| 1949 | - */ |
|
| 1950 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1951 | - |
|
| 1952 | - $user_data_value = true; |
|
| 1953 | - |
|
| 1954 | - if( ! ( $user_id > 0 ) ){ |
|
| 1955 | - $user_id = get_current_user_id(); |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1959 | - $post_type = get_post_type( $post_id ); |
|
| 1960 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1961 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1962 | - || ! get_userdata( $user_id ) |
|
| 1963 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1964 | - |
|
| 1965 | - return false; |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1969 | - // and get the activity ID |
|
| 1970 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1971 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1972 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1973 | - return false; |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1977 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 1978 | - |
|
| 1979 | - return $user_data_value; |
|
| 1980 | - |
|
| 1981 | - }// end get_user_data |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 1985 | - * |
|
| 1986 | - * @param int $data_key |
|
| 1987 | - * @param int $post_id |
|
| 1988 | - * @param int $user_id |
|
| 1989 | - * |
|
| 1990 | - * @return bool $deleted |
|
| 1991 | - */ |
|
| 1992 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 1993 | - $deleted = true; |
|
| 1866 | + /** |
|
| 1867 | + * |
|
| 1868 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1869 | + * @since 1.7.4 |
|
| 1870 | + * |
|
| 1871 | + * @param string $data_key maximum 39 characters allowed |
|
| 1872 | + * @param int $post_id |
|
| 1873 | + * @param mixed $value |
|
| 1874 | + * @param int $user_id |
|
| 1875 | + * |
|
| 1876 | + * @return bool $success |
|
| 1877 | + */ |
|
| 1878 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1879 | + |
|
| 1880 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1881 | + |
|
| 1882 | + }// end add_user_data |
|
| 1883 | + |
|
| 1884 | + /** |
|
| 1885 | + * add user specific data to the passed in sensei post type id |
|
| 1886 | + * |
|
| 1887 | + * This function saves comment meta on the users current status. If no status is available |
|
| 1888 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1889 | + * |
|
| 1890 | + * @since 1.7.4 |
|
| 1891 | + * |
|
| 1892 | + * @param string $data_key maximum 39 characters allowed |
|
| 1893 | + * @param int $post_id |
|
| 1894 | + * @param mixed $value |
|
| 1895 | + * @param int $user_id |
|
| 1896 | + * |
|
| 1897 | + * @return bool $success |
|
| 1898 | + */ |
|
| 1899 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1900 | + |
|
| 1901 | + if( ! ( $user_id > 0 ) ){ |
|
| 1902 | + $user_id = get_current_user_id(); |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1906 | + $post_type = get_post_type( $post_id ); |
|
| 1907 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1908 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1909 | + || !get_userdata( $user_id ) |
|
| 1910 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1911 | + |
|
| 1912 | + return false; |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1916 | + // and get the activity ID |
|
| 1917 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1918 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1919 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1994 | 1920 | |
| 1995 | - if( ! ( $user_id > 0 ) ){ |
|
| 1996 | - $user_id = get_current_user_id(); |
|
| 1997 | - } |
|
| 1921 | + $start_function = 'user_start_'.$post_type; |
|
| 1922 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1998 | 1923 | |
| 1999 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2000 | - $post_type = get_post_type( $post_id ); |
|
| 2001 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2002 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2003 | - || ! get_userdata( $user_id ) |
|
| 2004 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1924 | + }else{ |
|
| 2005 | 1925 | |
| 2006 | - return false; |
|
| 2007 | - } |
|
| 1926 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2008 | 1927 | |
| 2009 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2010 | - // and get the activity ID |
|
| 2011 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2012 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2013 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2014 | - return false; |
|
| 2015 | - } |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + // store the data |
|
| 1931 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1932 | + |
|
| 1933 | + return $success; |
|
| 1934 | + |
|
| 1935 | + }//update_user_data |
|
| 1936 | + |
|
| 1937 | + /** |
|
| 1938 | + * Get the user data stored on the passed in post type |
|
| 1939 | + * |
|
| 1940 | + * This function gets the comment meta on the lesson or course status |
|
| 1941 | + * |
|
| 1942 | + * @since 1.7.4 |
|
| 1943 | + * |
|
| 1944 | + * @param $data_key |
|
| 1945 | + * @param $post_id |
|
| 1946 | + * @param int $user_id |
|
| 1947 | + * |
|
| 1948 | + * @return mixed $user_data_value |
|
| 1949 | + */ |
|
| 1950 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1951 | + |
|
| 1952 | + $user_data_value = true; |
|
| 1953 | + |
|
| 1954 | + if( ! ( $user_id > 0 ) ){ |
|
| 1955 | + $user_id = get_current_user_id(); |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1959 | + $post_type = get_post_type( $post_id ); |
|
| 1960 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1961 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1962 | + || ! get_userdata( $user_id ) |
|
| 1963 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1964 | + |
|
| 1965 | + return false; |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1969 | + // and get the activity ID |
|
| 1970 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1971 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1972 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1973 | + return false; |
|
| 1974 | + } |
|
| 1975 | + |
|
| 1976 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1977 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 1978 | + |
|
| 1979 | + return $user_data_value; |
|
| 1980 | + |
|
| 1981 | + }// end get_user_data |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 1985 | + * |
|
| 1986 | + * @param int $data_key |
|
| 1987 | + * @param int $post_id |
|
| 1988 | + * @param int $user_id |
|
| 1989 | + * |
|
| 1990 | + * @return bool $deleted |
|
| 1991 | + */ |
|
| 1992 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 1993 | + $deleted = true; |
|
| 1994 | + |
|
| 1995 | + if( ! ( $user_id > 0 ) ){ |
|
| 1996 | + $user_id = get_current_user_id(); |
|
| 1997 | + } |
|
| 1998 | + |
|
| 1999 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 2000 | + $post_type = get_post_type( $post_id ); |
|
| 2001 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2002 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2003 | + || ! get_userdata( $user_id ) |
|
| 2004 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2005 | + |
|
| 2006 | + return false; |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2010 | + // and get the activity ID |
|
| 2011 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2012 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2013 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2014 | + return false; |
|
| 2015 | + } |
|
| 2016 | 2016 | |
| 2017 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2018 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2017 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2018 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2019 | 2019 | |
| 2020 | - return $deleted; |
|
| 2020 | + return $deleted; |
|
| 2021 | 2021 | |
| 2022 | - }// end delete_user_data |
|
| 2022 | + }// end delete_user_data |
|
| 2023 | 2023 | |
| 2024 | 2024 | |
| 2025 | - /** |
|
| 2026 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2027 | - * |
|
| 2028 | - * @since 1.8.0 |
|
| 2029 | - * |
|
| 2030 | - * @param string $selected_value |
|
| 2031 | - * @param $options{ |
|
| 2032 | - * @type string $value the value saved in the database |
|
| 2033 | - * @type string $option what the user will see in the list of items |
|
| 2034 | - * } |
|
| 2035 | - * @param array $attributes{ |
|
| 2036 | - * @type string $attribute type such name or id etc. |
|
| 2037 | - * @type string $value |
|
| 2038 | - * } |
|
| 2039 | - * @param bool $enable_none_option |
|
| 2040 | - * |
|
| 2041 | - * @return string $drop_down_element |
|
| 2042 | - */ |
|
| 2043 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2025 | + /** |
|
| 2026 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2027 | + * |
|
| 2028 | + * @since 1.8.0 |
|
| 2029 | + * |
|
| 2030 | + * @param string $selected_value |
|
| 2031 | + * @param $options{ |
|
| 2032 | + * @type string $value the value saved in the database |
|
| 2033 | + * @type string $option what the user will see in the list of items |
|
| 2034 | + * } |
|
| 2035 | + * @param array $attributes{ |
|
| 2036 | + * @type string $attribute type such name or id etc. |
|
| 2037 | + * @type string $value |
|
| 2038 | + * } |
|
| 2039 | + * @param bool $enable_none_option |
|
| 2040 | + * |
|
| 2041 | + * @return string $drop_down_element |
|
| 2042 | + */ |
|
| 2043 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2044 | 2044 | |
| 2045 | - $drop_down_element = ''; |
|
| 2045 | + $drop_down_element = ''; |
|
| 2046 | 2046 | |
| 2047 | - // setup the basic attributes |
|
| 2048 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2047 | + // setup the basic attributes |
|
| 2048 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2049 | 2049 | |
| 2050 | - $attributes['name'] = 'sensei-options'; |
|
| 2050 | + $attributes['name'] = 'sensei-options'; |
|
| 2051 | 2051 | |
| 2052 | - } |
|
| 2052 | + } |
|
| 2053 | 2053 | |
| 2054 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2054 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2055 | 2055 | |
| 2056 | - $attributes['id'] = 'sensei-options'; |
|
| 2056 | + $attributes['id'] = 'sensei-options'; |
|
| 2057 | 2057 | |
| 2058 | - } |
|
| 2058 | + } |
|
| 2059 | 2059 | |
| 2060 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2060 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2061 | 2061 | |
| 2062 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2062 | + $attributes['class'] ='chosen_select widefat'; |
|
| 2063 | 2063 | |
| 2064 | - } |
|
| 2064 | + } |
|
| 2065 | 2065 | |
| 2066 | - // create element attributes |
|
| 2067 | - $combined_attributes = ''; |
|
| 2068 | - foreach( $attributes as $attribute => $value ){ |
|
| 2066 | + // create element attributes |
|
| 2067 | + $combined_attributes = ''; |
|
| 2068 | + foreach( $attributes as $attribute => $value ){ |
|
| 2069 | 2069 | |
| 2070 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2070 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2071 | 2071 | |
| 2072 | - }// end for each |
|
| 2072 | + }// end for each |
|
| 2073 | 2073 | |
| 2074 | 2074 | |
| 2075 | - // create the select element |
|
| 2076 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2075 | + // create the select element |
|
| 2076 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2077 | 2077 | |
| 2078 | - // show the none option if the client requested |
|
| 2079 | - if( $enable_none_option ) { |
|
| 2080 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2081 | - } |
|
| 2078 | + // show the none option if the client requested |
|
| 2079 | + if( $enable_none_option ) { |
|
| 2080 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2081 | + } |
|
| 2082 | 2082 | |
| 2083 | - if ( count( $options ) > 0 ) { |
|
| 2083 | + if ( count( $options ) > 0 ) { |
|
| 2084 | 2084 | |
| 2085 | - foreach ($options as $value => $option ){ |
|
| 2085 | + foreach ($options as $value => $option ){ |
|
| 2086 | 2086 | |
| 2087 | - $element = ''; |
|
| 2088 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2089 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2090 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2087 | + $element = ''; |
|
| 2088 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2089 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2090 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2091 | 2091 | |
| 2092 | - // add the element to the select html |
|
| 2093 | - $drop_down_element.= $element; |
|
| 2094 | - } // End For Loop |
|
| 2092 | + // add the element to the select html |
|
| 2093 | + $drop_down_element.= $element; |
|
| 2094 | + } // End For Loop |
|
| 2095 | 2095 | |
| 2096 | - } // End If Statement |
|
| 2096 | + } // End If Statement |
|
| 2097 | 2097 | |
| 2098 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2098 | + $drop_down_element .= '</select>' . "\n"; |
|
| 2099 | 2099 | |
| 2100 | - return $drop_down_element; |
|
| 2100 | + return $drop_down_element; |
|
| 2101 | 2101 | |
| 2102 | - }// generate_drop_down |
|
| 2102 | + }// generate_drop_down |
|
| 2103 | 2103 | |
| 2104 | - /** |
|
| 2105 | - * Wrapper for the default php round() function. |
|
| 2106 | - * This allows us to give more control to a user on how they can round Sensei |
|
| 2107 | - * decimals passed through this function. |
|
| 2108 | - * |
|
| 2109 | - * @since 1.8.5 |
|
| 2110 | - * |
|
| 2111 | - * @param double $val |
|
| 2112 | - * @param int $precision |
|
| 2113 | - * @param $mode |
|
| 2114 | - * @param string $context |
|
| 2115 | - * |
|
| 2116 | - * @return double $val |
|
| 2117 | - */ |
|
| 2118 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2104 | + /** |
|
| 2105 | + * Wrapper for the default php round() function. |
|
| 2106 | + * This allows us to give more control to a user on how they can round Sensei |
|
| 2107 | + * decimals passed through this function. |
|
| 2108 | + * |
|
| 2109 | + * @since 1.8.5 |
|
| 2110 | + * |
|
| 2111 | + * @param double $val |
|
| 2112 | + * @param int $precision |
|
| 2113 | + * @param $mode |
|
| 2114 | + * @param string $context |
|
| 2115 | + * |
|
| 2116 | + * @return double $val |
|
| 2117 | + */ |
|
| 2118 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2119 | 2119 | |
| 2120 | - /**å |
|
| 2120 | + /**å |
|
| 2121 | 2121 | * Change the precision for the Sensei_Utils::round function. |
| 2122 | 2122 | * the precision given will be passed into the php round function |
| 2123 | 2123 | * @since 1.8.5 |
| 2124 | 2124 | */ |
| 2125 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2126 | - |
|
| 2127 | - /** |
|
| 2128 | - * Change the mode for the Sensei_Utils::round function. |
|
| 2129 | - * the mode given will be passed into the php round function |
|
| 2130 | - * |
|
| 2131 | - * This applies only to PHP version 5.3.0 and greater |
|
| 2132 | - * |
|
| 2133 | - * @since 1.8.5 |
|
| 2134 | - */ |
|
| 2135 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2125 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2136 | 2126 | |
| 2137 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2127 | + /** |
|
| 2128 | + * Change the mode for the Sensei_Utils::round function. |
|
| 2129 | + * the mode given will be passed into the php round function |
|
| 2130 | + * |
|
| 2131 | + * This applies only to PHP version 5.3.0 and greater |
|
| 2132 | + * |
|
| 2133 | + * @since 1.8.5 |
|
| 2134 | + */ |
|
| 2135 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2138 | 2136 | |
| 2139 | - return round( $val, $precision, $mode ); |
|
| 2137 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2140 | 2138 | |
| 2141 | - }else{ |
|
| 2139 | + return round( $val, $precision, $mode ); |
|
| 2142 | 2140 | |
| 2143 | - return round( $val, $precision ); |
|
| 2141 | + }else{ |
|
| 2144 | 2142 | |
| 2145 | - } |
|
| 2143 | + return round( $val, $precision ); |
|
| 2146 | 2144 | |
| 2147 | - } |
|
| 2145 | + } |
|
| 2148 | 2146 | |
| 2149 | - /** |
|
| 2150 | - * Returns the current url with all the query vars |
|
| 2151 | - * |
|
| 2152 | - * @since 1.9.0 |
|
| 2153 | - * @return string $url |
|
| 2154 | - */ |
|
| 2155 | - public static function get_current_url(){ |
|
| 2147 | + } |
|
| 2156 | 2148 | |
| 2157 | - global $wp; |
|
| 2158 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2159 | - if ( isset( $_GET ) ) { |
|
| 2149 | + /** |
|
| 2150 | + * Returns the current url with all the query vars |
|
| 2151 | + * |
|
| 2152 | + * @since 1.9.0 |
|
| 2153 | + * @return string $url |
|
| 2154 | + */ |
|
| 2155 | + public static function get_current_url(){ |
|
| 2160 | 2156 | |
| 2161 | - foreach ($_GET as $param => $val ) { |
|
| 2157 | + global $wp; |
|
| 2158 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2159 | + if ( isset( $_GET ) ) { |
|
| 2162 | 2160 | |
| 2163 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2161 | + foreach ($_GET as $param => $val ) { |
|
| 2164 | 2162 | |
| 2165 | - } |
|
| 2166 | - } |
|
| 2163 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2164 | + |
|
| 2165 | + } |
|
| 2166 | + } |
|
| 2167 | 2167 | |
| 2168 | - return $current_url; |
|
| 2169 | - } |
|
| 2168 | + return $current_url; |
|
| 2169 | + } |
|
| 2170 | 2170 | |
| 2171 | - /** |
|
| 2172 | - * Restore the global WP_Query |
|
| 2173 | - * |
|
| 2174 | - * @since 1.9.0 |
|
| 2175 | - */ |
|
| 2176 | - public static function restore_wp_query() { |
|
| 2171 | + /** |
|
| 2172 | + * Restore the global WP_Query |
|
| 2173 | + * |
|
| 2174 | + * @since 1.9.0 |
|
| 2175 | + */ |
|
| 2176 | + public static function restore_wp_query() { |
|
| 2177 | 2177 | |
| 2178 | - wp_reset_query(); |
|
| 2178 | + wp_reset_query(); |
|
| 2179 | 2179 | |
| 2180 | - } |
|
| 2180 | + } |
|
| 2181 | 2181 | |
| 2182 | - /** |
|
| 2183 | - * Merge two arrays in a zip like fashion. |
|
| 2184 | - * If one array is longer than the other the elements will be apended |
|
| 2185 | - * to the end of the resulting array. |
|
| 2186 | - * |
|
| 2187 | - * @since 1.9.0 |
|
| 2188 | - * |
|
| 2189 | - * @param array $array_a |
|
| 2190 | - * @param array $array_b |
|
| 2191 | - * @return array $merged_array |
|
| 2192 | - */ |
|
| 2193 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2182 | + /** |
|
| 2183 | + * Merge two arrays in a zip like fashion. |
|
| 2184 | + * If one array is longer than the other the elements will be apended |
|
| 2185 | + * to the end of the resulting array. |
|
| 2186 | + * |
|
| 2187 | + * @since 1.9.0 |
|
| 2188 | + * |
|
| 2189 | + * @param array $array_a |
|
| 2190 | + * @param array $array_b |
|
| 2191 | + * @return array $merged_array |
|
| 2192 | + */ |
|
| 2193 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2194 | 2194 | |
| 2195 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2196 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2197 | - } |
|
| 2195 | + if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2196 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2197 | + } |
|
| 2198 | 2198 | |
| 2199 | - $merged_array = array(); |
|
| 2200 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2199 | + $merged_array = array(); |
|
| 2200 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2201 | 2201 | |
| 2202 | - // Zip arrays |
|
| 2203 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2202 | + // Zip arrays |
|
| 2203 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2204 | 2204 | |
| 2205 | - // if has an element at current index push a on top |
|
| 2206 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2207 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2208 | - } |
|
| 2205 | + // if has an element at current index push a on top |
|
| 2206 | + if( isset( $array_a[ $i ] ) ){ |
|
| 2207 | + $merged_array[] = $array_a[ $i ] ; |
|
| 2208 | + } |
|
| 2209 | 2209 | |
| 2210 | - // next if $array_b has an element at current index push a on top of the element |
|
| 2211 | - // from a if there was one, if not the element before that. |
|
| 2212 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2213 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2214 | - } |
|
| 2210 | + // next if $array_b has an element at current index push a on top of the element |
|
| 2211 | + // from a if there was one, if not the element before that. |
|
| 2212 | + if( isset( $array_b[ $i ] ) ){ |
|
| 2213 | + $merged_array[] = $array_b[ $i ] ; |
|
| 2214 | + } |
|
| 2215 | 2215 | |
| 2216 | - } |
|
| 2216 | + } |
|
| 2217 | 2217 | |
| 2218 | - return $merged_array; |
|
| 2219 | - } |
|
| 2218 | + return $merged_array; |
|
| 2219 | + } |
|
| 2220 | 2220 | |
| 2221 | 2221 | } // End Class |
| 2222 | 2222 | |
@@ -12,716 +12,716 @@ 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 |
|
| 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 |
|
| 27 | + * |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public static function is_woocommerce_active(){ |
|
| 32 | 32 | |
| 33 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 33 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 34 | 34 | |
| 35 | - if ( is_multisite() ){ |
|
| 35 | + if ( is_multisite() ){ |
|
| 36 | 36 | |
| 37 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 37 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 38 | 38 | |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 41 | + return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 42 | 42 | |
| 43 | - } // end is_woocommerce_active |
|
| 43 | + } // end is_woocommerce_active |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 47 | - * |
|
| 48 | - * If multiple exist we will return the latest order. |
|
| 49 | - * |
|
| 50 | - * @param $user_id |
|
| 51 | - * @param $course_id |
|
| 52 | - * @return array $user_course_orders |
|
| 53 | - */ |
|
| 54 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 45 | + /** |
|
| 46 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 47 | + * |
|
| 48 | + * If multiple exist we will return the latest order. |
|
| 49 | + * |
|
| 50 | + * @param $user_id |
|
| 51 | + * @param $course_id |
|
| 52 | + * @return array $user_course_orders |
|
| 53 | + */ |
|
| 54 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 55 | 55 | |
| 56 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 56 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 57 | 57 | |
| 58 | - $orders_query = new WP_Query( array( |
|
| 59 | - 'post_type' => 'shop_order', |
|
| 60 | - 'posts_per_page' => -1, |
|
| 61 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 62 | - 'meta_key'=> '_customer_user', |
|
| 63 | - 'meta_value'=> $user_id, |
|
| 64 | - ) ); |
|
| 58 | + $orders_query = new WP_Query( array( |
|
| 59 | + 'post_type' => 'shop_order', |
|
| 60 | + 'posts_per_page' => -1, |
|
| 61 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 62 | + 'meta_key'=> '_customer_user', |
|
| 63 | + 'meta_value'=> $user_id, |
|
| 64 | + ) ); |
|
| 65 | 65 | |
| 66 | - if( $orders_query->post_count == 0 ){ |
|
| 66 | + if( $orders_query->post_count == 0 ){ |
|
| 67 | 67 | |
| 68 | - return false; |
|
| 68 | + return false; |
|
| 69 | 69 | |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 72 | + foreach( $orders_query->get_posts() as $order ){ |
|
| 73 | 73 | |
| 74 | - $order = new WC_Order( $order->ID ); |
|
| 75 | - $items = $order->get_items(); |
|
| 74 | + $order = new WC_Order( $order->ID ); |
|
| 75 | + $items = $order->get_items(); |
|
| 76 | 76 | |
| 77 | - $user_orders = array(); |
|
| 77 | + $user_orders = array(); |
|
| 78 | 78 | |
| 79 | - foreach( $items as $item ){ |
|
| 79 | + foreach( $items as $item ){ |
|
| 80 | 80 | |
| 81 | - // if the product id on the order and the one given to this function |
|
| 82 | - // this order has been placed by the given user on the given course. |
|
| 83 | - $product = wc_get_product( $item['product_id'] ); |
|
| 81 | + // if the product id on the order and the one given to this function |
|
| 82 | + // this order has been placed by the given user on the given course. |
|
| 83 | + $product = wc_get_product( $item['product_id'] ); |
|
| 84 | 84 | |
| 85 | - if ( $product->is_type( 'variable' )) { |
|
| 85 | + if ( $product->is_type( 'variable' )) { |
|
| 86 | 86 | |
| 87 | - $item_product_id = $item['variation_id']; |
|
| 87 | + $item_product_id = $item['variation_id']; |
|
| 88 | 88 | |
| 89 | - } else { |
|
| 89 | + } else { |
|
| 90 | 90 | |
| 91 | - $item_product_id = $item['product_id']; |
|
| 91 | + $item_product_id = $item['product_id']; |
|
| 92 | 92 | |
| 93 | - } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - if( $course_product_id == $item_product_id ){ |
|
| 95 | + if( $course_product_id == $item_product_id ){ |
|
| 96 | 96 | |
| 97 | - return $order->id; |
|
| 97 | + return $order->id; |
|
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | - }//end for each order item |
|
| 102 | + }//end for each order item |
|
| 103 | 103 | |
| 104 | - } // end for each order |
|
| 104 | + } // end for each order |
|
| 105 | 105 | |
| 106 | - // if we reach this place we found no order |
|
| 107 | - return false; |
|
| 106 | + // if we reach this place we found no order |
|
| 107 | + return false; |
|
| 108 | 108 | |
| 109 | - } // end get_learner_course_active_order_ids |
|
| 109 | + } // end get_learner_course_active_order_ids |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Output WooCommerce specific course filters |
|
| 113 | - * Removing the paged argument |
|
| 114 | - * |
|
| 115 | - * @since 1.9.0 |
|
| 116 | - * @param $filter_links |
|
| 117 | - * @return mixed |
|
| 118 | - */ |
|
| 119 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 111 | + /** |
|
| 112 | + * Output WooCommerce specific course filters |
|
| 113 | + * Removing the paged argument |
|
| 114 | + * |
|
| 115 | + * @since 1.9.0 |
|
| 116 | + * @param $filter_links |
|
| 117 | + * @return mixed |
|
| 118 | + */ |
|
| 119 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 120 | 120 | |
| 121 | - $course_url = remove_query_arg('paged', WooThemes_Sensei_Utils::get_current_url() ); |
|
| 121 | + $course_url = remove_query_arg('paged', WooThemes_Sensei_Utils::get_current_url() ); |
|
| 122 | 122 | |
| 123 | - $free_courses = self::get_free_courses(); |
|
| 124 | - $paid_courses = self::get_paid_courses(); |
|
| 123 | + $free_courses = self::get_free_courses(); |
|
| 124 | + $paid_courses = self::get_paid_courses(); |
|
| 125 | 125 | |
| 126 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 127 | - // do not show any WooCommerce filters if all courses are |
|
| 128 | - // free or if all courses are paid |
|
| 129 | - return $filter_links; |
|
| 126 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 127 | + // do not show any WooCommerce filters if all courses are |
|
| 128 | + // free or if all courses are paid |
|
| 129 | + return $filter_links; |
|
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - $filter_links[] = array( 'id'=>'paid' , |
|
| 134 | - 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
|
| 135 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 136 | - ); |
|
| 133 | + $filter_links[] = array( 'id'=>'paid' , |
|
| 134 | + 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
|
| 135 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 136 | + ); |
|
| 137 | 137 | |
| 138 | - $filter_links[] = array( 'id'=>'free', |
|
| 139 | - 'url'=>add_query_arg('course_filter', 'free', $course_url), |
|
| 140 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 141 | - ); |
|
| 138 | + $filter_links[] = array( 'id'=>'free', |
|
| 139 | + 'url'=>add_query_arg('course_filter', 'free', $course_url), |
|
| 140 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 141 | + ); |
|
| 142 | 142 | |
| 143 | - return $filter_links; |
|
| 143 | + return $filter_links; |
|
| 144 | 144 | |
| 145 | - }// end add_course_archive_wc_filter_links |
|
| 145 | + }// end add_course_archive_wc_filter_links |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Apply the free filter the the course query |
|
| 149 | - * getting all course with no products or products with zero price |
|
| 150 | - * |
|
| 151 | - * hooked into pre_get_posts |
|
| 152 | - * |
|
| 153 | - * @since 1.9.0 |
|
| 154 | - * @param WP_Query $query |
|
| 155 | - * @return WP_Query $query |
|
| 156 | - */ |
|
| 157 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 147 | + /** |
|
| 148 | + * Apply the free filter the the course query |
|
| 149 | + * getting all course with no products or products with zero price |
|
| 150 | + * |
|
| 151 | + * hooked into pre_get_posts |
|
| 152 | + * |
|
| 153 | + * @since 1.9.0 |
|
| 154 | + * @param WP_Query $query |
|
| 155 | + * @return WP_Query $query |
|
| 156 | + */ |
|
| 157 | + public static function course_archive_wc_filter_free( $query ){ |
|
| 158 | 158 | |
| 159 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 160 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 159 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 160 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 161 | 161 | |
| 162 | - // setup the course meta query |
|
| 163 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
| 162 | + // setup the course meta query |
|
| 163 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
| 164 | 164 | |
| 165 | - // manipulate the query to return free courses |
|
| 166 | - $query->set('meta_query', $meta_query ); |
|
| 165 | + // manipulate the query to return free courses |
|
| 166 | + $query->set('meta_query', $meta_query ); |
|
| 167 | 167 | |
| 168 | - // don't show any paid courses |
|
| 169 | - $courses = self::get_paid_courses(); |
|
| 170 | - $ids = array(); |
|
| 171 | - foreach( $courses as $course ){ |
|
| 172 | - $ids[] = $course->ID; |
|
| 173 | - } |
|
| 174 | - $query->set( 'post__not_in', $ids ); |
|
| 168 | + // don't show any paid courses |
|
| 169 | + $courses = self::get_paid_courses(); |
|
| 170 | + $ids = array(); |
|
| 171 | + foreach( $courses as $course ){ |
|
| 172 | + $ids[] = $course->ID; |
|
| 173 | + } |
|
| 174 | + $query->set( 'post__not_in', $ids ); |
|
| 175 | 175 | |
| 176 | - }// end if course_filter |
|
| 176 | + }// end if course_filter |
|
| 177 | 177 | |
| 178 | - return $query; |
|
| 178 | + return $query; |
|
| 179 | 179 | |
| 180 | - }// course_archive_wc_filter_free |
|
| 180 | + }// course_archive_wc_filter_free |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Apply the paid filter to the course query on the courses page |
|
| 184 | - * will include all course with a product attached with a price |
|
| 185 | - * more than 0 |
|
| 186 | - * |
|
| 187 | - * hooked into pre_get_posts |
|
| 188 | - * |
|
| 189 | - * @since 1.9.0 |
|
| 190 | - * @param WP_Query $query |
|
| 191 | - * @return WP_Query $query |
|
| 192 | - */ |
|
| 193 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 182 | + /** |
|
| 183 | + * Apply the paid filter to the course query on the courses page |
|
| 184 | + * will include all course with a product attached with a price |
|
| 185 | + * more than 0 |
|
| 186 | + * |
|
| 187 | + * hooked into pre_get_posts |
|
| 188 | + * |
|
| 189 | + * @since 1.9.0 |
|
| 190 | + * @param WP_Query $query |
|
| 191 | + * @return WP_Query $query |
|
| 192 | + */ |
|
| 193 | + public static function course_archive_wc_filter_paid( $query ){ |
|
| 194 | 194 | |
| 195 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 196 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 195 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 196 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 197 | 197 | |
| 198 | - // setup the course meta query |
|
| 199 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 198 | + // setup the course meta query |
|
| 199 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 200 | 200 | |
| 201 | - // manipulate the query to return free courses |
|
| 202 | - $query->set('meta_query', $meta_query ); |
|
| 203 | - |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $query; |
|
| 207 | - |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Load the WooCommerce single product actions above |
|
| 212 | - * single courses if woocommerce is active allowing purchase |
|
| 213 | - * information and actions to be hooked from WooCommerce. |
|
| 214 | - */ |
|
| 215 | - public static function do_single_course_wc_single_product_action(){ |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * this hooks is documented within the WooCommerce plugin. |
|
| 219 | - */ |
|
| 220 | - if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() ) { |
|
| 221 | - |
|
| 222 | - do_action( 'woocommerce_before_single_product' ); |
|
| 223 | - |
|
| 224 | - } // End If Statement |
|
| 225 | - |
|
| 226 | - }// end do_single_course_wc_single_product_action |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Hooking into the single lesson page to alter the |
|
| 230 | - * user access permissions based on if they have purchased the |
|
| 231 | - * course the lesson belongs to. |
|
| 232 | - * |
|
| 233 | - * This function will only return false or the passed in user_access value. |
|
| 234 | - * It doesn't return true in order to avoid altering other options. |
|
| 235 | - * |
|
| 236 | - * @since 1.9.0 |
|
| 237 | - * |
|
| 238 | - * @param $can_user_view_lesson |
|
| 239 | - * @param $lesson_id |
|
| 240 | - * @param $user_id |
|
| 241 | - * @return bool |
|
| 242 | - */ |
|
| 243 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 244 | - |
|
| 245 | - // check if the course has a valid product attached to it |
|
| 246 | - // which the user should have purchased if they want to access |
|
| 247 | - // the current lesson |
|
| 248 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 249 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 250 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 251 | - if( isset ($product) && is_object($product) ){ |
|
| 252 | - |
|
| 253 | - // valid product found |
|
| 254 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 255 | - |
|
| 256 | - // product has a successful order so this user may access the content |
|
| 257 | - // this function may only return false or the default |
|
| 258 | - // returning true may override other negatives which we don't want |
|
| 259 | - if( ! $order_id ){ |
|
| 260 | - |
|
| 261 | - return false; |
|
| 262 | - |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // return the passed in value |
|
| 268 | - return $can_user_view_lesson; |
|
| 269 | - |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Add course link to order thank you and details pages. |
|
| 274 | - * |
|
| 275 | - * @since 1.4.5 |
|
| 276 | - * @access public |
|
| 277 | - * |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - public static function course_link_from_order( ) { |
|
| 281 | - |
|
| 282 | - if( ! is_order_received_page() ){ |
|
| 283 | - return; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $order_id = get_query_var( 'order-received' ); |
|
| 201 | + // manipulate the query to return free courses |
|
| 202 | + $query->set('meta_query', $meta_query ); |
|
| 203 | + |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $query; |
|
| 207 | + |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Load the WooCommerce single product actions above |
|
| 212 | + * single courses if woocommerce is active allowing purchase |
|
| 213 | + * information and actions to be hooked from WooCommerce. |
|
| 214 | + */ |
|
| 215 | + public static function do_single_course_wc_single_product_action(){ |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * this hooks is documented within the WooCommerce plugin. |
|
| 219 | + */ |
|
| 220 | + if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() ) { |
|
| 221 | + |
|
| 222 | + do_action( 'woocommerce_before_single_product' ); |
|
| 223 | + |
|
| 224 | + } // End If Statement |
|
| 225 | + |
|
| 226 | + }// end do_single_course_wc_single_product_action |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Hooking into the single lesson page to alter the |
|
| 230 | + * user access permissions based on if they have purchased the |
|
| 231 | + * course the lesson belongs to. |
|
| 232 | + * |
|
| 233 | + * This function will only return false or the passed in user_access value. |
|
| 234 | + * It doesn't return true in order to avoid altering other options. |
|
| 235 | + * |
|
| 236 | + * @since 1.9.0 |
|
| 237 | + * |
|
| 238 | + * @param $can_user_view_lesson |
|
| 239 | + * @param $lesson_id |
|
| 240 | + * @param $user_id |
|
| 241 | + * @return bool |
|
| 242 | + */ |
|
| 243 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 244 | + |
|
| 245 | + // check if the course has a valid product attached to it |
|
| 246 | + // which the user should have purchased if they want to access |
|
| 247 | + // the current lesson |
|
| 248 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 249 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 250 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 251 | + if( isset ($product) && is_object($product) ){ |
|
| 252 | + |
|
| 253 | + // valid product found |
|
| 254 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 255 | + |
|
| 256 | + // product has a successful order so this user may access the content |
|
| 257 | + // this function may only return false or the default |
|
| 258 | + // returning true may override other negatives which we don't want |
|
| 259 | + if( ! $order_id ){ |
|
| 260 | + |
|
| 261 | + return false; |
|
| 262 | + |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // return the passed in value |
|
| 268 | + return $can_user_view_lesson; |
|
| 269 | + |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Add course link to order thank you and details pages. |
|
| 274 | + * |
|
| 275 | + * @since 1.4.5 |
|
| 276 | + * @access public |
|
| 277 | + * |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + public static function course_link_from_order( ) { |
|
| 281 | + |
|
| 282 | + if( ! is_order_received_page() ){ |
|
| 283 | + return; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $order_id = get_query_var( 'order-received' ); |
|
| 287 | 287 | $order = new WC_Order( $order_id ); |
| 288 | 288 | |
| 289 | 289 | // exit early if not wc-completed or wc-processing |
| 290 | 290 | if( 'wc-completed' != $order->post_status |
| 291 | - && 'wc-processing' != $order->post_status ) { |
|
| 292 | - return; |
|
| 293 | - } |
|
| 291 | + && 'wc-processing' != $order->post_status ) { |
|
| 292 | + return; |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - $course_links = array(); // store the for links for courses purchased |
|
| 295 | + $course_links = array(); // store the for links for courses purchased |
|
| 296 | 296 | foreach ( $order->get_items() as $item ) { |
| 297 | 297 | |
| 298 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 298 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 299 | 299 | |
| 300 | - // If item has variation_id then its a variation of the product |
|
| 301 | - $item_id = $item['variation_id']; |
|
| 300 | + // If item has variation_id then its a variation of the product |
|
| 301 | + $item_id = $item['variation_id']; |
|
| 302 | 302 | |
| 303 | - } else { |
|
| 303 | + } else { |
|
| 304 | 304 | |
| 305 | - //If not its real product set its id to item_id |
|
| 306 | - $item_id = $item['product_id']; |
|
| 305 | + //If not its real product set its id to item_id |
|
| 306 | + $item_id = $item['product_id']; |
|
| 307 | 307 | |
| 308 | - } // End If Statement |
|
| 308 | + } // End If Statement |
|
| 309 | 309 | |
| 310 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 310 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 311 | 311 | |
| 312 | - if( $user_id ) { |
|
| 312 | + if( $user_id ) { |
|
| 313 | 313 | |
| 314 | - // Get all courses for product |
|
| 315 | - $args = Sensei_Course::get_default_query_args(); |
|
| 316 | - $args['meta_query'] = array( array( |
|
| 317 | - 'key' => '_course_woocommerce_product', |
|
| 318 | - 'value' => $item_id |
|
| 319 | - ) ); |
|
| 320 | - $args['orderby'] = 'menu_order date'; |
|
| 321 | - $args['order'] = 'ASC'; |
|
| 314 | + // Get all courses for product |
|
| 315 | + $args = Sensei_Course::get_default_query_args(); |
|
| 316 | + $args['meta_query'] = array( array( |
|
| 317 | + 'key' => '_course_woocommerce_product', |
|
| 318 | + 'value' => $item_id |
|
| 319 | + ) ); |
|
| 320 | + $args['orderby'] = 'menu_order date'; |
|
| 321 | + $args['order'] = 'ASC'; |
|
| 322 | 322 | |
| 323 | - // loop through courses |
|
| 324 | - $courses = get_posts( $args ); |
|
| 325 | - if( $courses && count( $courses ) > 0 ) { |
|
| 323 | + // loop through courses |
|
| 324 | + $courses = get_posts( $args ); |
|
| 325 | + if( $courses && count( $courses ) > 0 ) { |
|
| 326 | 326 | |
| 327 | - foreach( $courses as $course ) { |
|
| 327 | + foreach( $courses as $course ) { |
|
| 328 | 328 | |
| 329 | - $title = $course->post_title; |
|
| 330 | - $permalink = get_permalink( $course->ID ); |
|
| 331 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 329 | + $title = $course->post_title; |
|
| 330 | + $permalink = get_permalink( $course->ID ); |
|
| 331 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 332 | 332 | |
| 333 | - } // end for each |
|
| 333 | + } // end for each |
|
| 334 | 334 | |
| 335 | - // close the message div |
|
| 335 | + // close the message div |
|
| 336 | 336 | |
| 337 | - }// end if $courses check |
|
| 338 | - } |
|
| 339 | - }// end loop through orders |
|
| 337 | + }// end if $courses check |
|
| 338 | + } |
|
| 339 | + }// end loop through orders |
|
| 340 | 340 | |
| 341 | - // add the courses to the WooCommerce notice |
|
| 342 | - if( ! empty( $course_links) ){ |
|
| 341 | + // add the courses to the WooCommerce notice |
|
| 342 | + if( ! empty( $course_links) ){ |
|
| 343 | 343 | |
| 344 | - $courses_html = _nx( |
|
| 345 | - 'You have purchased the following course:', |
|
| 346 | - 'You have purchased the following courses:', |
|
| 347 | - count( $course_links ), |
|
| 348 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 349 | - ); |
|
| 344 | + $courses_html = _nx( |
|
| 345 | + 'You have purchased the following course:', |
|
| 346 | + 'You have purchased the following courses:', |
|
| 347 | + count( $course_links ), |
|
| 348 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 349 | + ); |
|
| 350 | 350 | |
| 351 | - foreach( $course_links as $link ){ |
|
| 351 | + foreach( $course_links as $link ){ |
|
| 352 | 352 | |
| 353 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 353 | + $courses_html .= '<li>' . $link . '</li>'; |
|
| 354 | 354 | |
| 355 | - } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - $courses_html .= ' </ul>'; |
|
| 357 | + $courses_html .= ' </ul>'; |
|
| 358 | 358 | |
| 359 | - wc_add_notice( $courses_html, 'success' ); |
|
| 360 | - } |
|
| 359 | + wc_add_notice( $courses_html, 'success' ); |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | 362 | } // end course_link_order_form |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * Show the message that a user should complete |
|
| 366 | - * their purchase if the course is in the cart |
|
| 367 | - * |
|
| 368 | - * This should be used within the course loop or single course page |
|
| 369 | - * |
|
| 370 | - * @since 1.9.0 |
|
| 371 | - */ |
|
| 372 | - public static function course_in_cart_message(){ |
|
| 364 | + /** |
|
| 365 | + * Show the message that a user should complete |
|
| 366 | + * their purchase if the course is in the cart |
|
| 367 | + * |
|
| 368 | + * This should be used within the course loop or single course page |
|
| 369 | + * |
|
| 370 | + * @since 1.9.0 |
|
| 371 | + */ |
|
| 372 | + public static function course_in_cart_message(){ |
|
| 373 | 373 | |
| 374 | - global $post; |
|
| 374 | + global $post; |
|
| 375 | 375 | |
| 376 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 376 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 377 | 377 | |
| 378 | 378 | <div class="sensei-message info">' |
| 379 | 379 | <?php |
| 380 | 380 | |
| 381 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 382 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 383 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 381 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 382 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 383 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 384 | 384 | |
| 385 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 385 | + sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 386 | 386 | |
| 387 | - ?> |
|
| 387 | + ?> |
|
| 388 | 388 | </div> |
| 389 | 389 | <?php } |
| 390 | 390 | |
| 391 | - } // End sensei_woocommerce_in_cart_message() |
|
| 391 | + } // End sensei_woocommerce_in_cart_message() |
|
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * Checks the cart to see if a course is in the cart. |
|
| 395 | - * |
|
| 396 | - * @param $course_id |
|
| 397 | - * @return bool |
|
| 398 | - */ |
|
| 399 | - public static function is_course_in_cart( $course_id ){ |
|
| 400 | - |
|
| 401 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 402 | - $user_course_status_id = WooThemes_Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 403 | - |
|
| 404 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 405 | - |
|
| 406 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 407 | - |
|
| 408 | - return true; |
|
| 409 | - |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - return false; |
|
| 415 | - |
|
| 416 | - }// is_course_in_cart |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Check the cart to see if the product is in the cart |
|
| 420 | - * |
|
| 421 | - * @param $product_id |
|
| 422 | - * @return bool |
|
| 423 | - */ |
|
| 424 | - public static function is_product_in_cart( $product_id ){ |
|
| 425 | - |
|
| 426 | - if ( 0 < $product_id ) { |
|
| 427 | - |
|
| 428 | - $product = wc_get_product( $product_id ); |
|
| 429 | - |
|
| 430 | - $parent_id = ''; |
|
| 431 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 432 | - $wc_product_id = $product->parent->id; |
|
| 433 | - } |
|
| 434 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 435 | - |
|
| 436 | - $cart_product = $values['data']; |
|
| 437 | - if( $product_id == $cart_product->id ) { |
|
| 438 | - |
|
| 439 | - return true; |
|
| 440 | - |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - } |
|
| 444 | - } // End If Statement |
|
| 445 | - |
|
| 446 | - return false; |
|
| 447 | - |
|
| 448 | - } // end is_product_in_car |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Get all free WooCommerce products |
|
| 452 | - * |
|
| 453 | - * @since 1.9.0 |
|
| 454 | - * |
|
| 455 | - * @return array $free_products{ |
|
| 456 | - * @type int $wp_post_id |
|
| 457 | - * } |
|
| 458 | - */ |
|
| 459 | - public static function get_free_product_ids(){ |
|
| 460 | - |
|
| 461 | - return get_posts( array( |
|
| 462 | - 'post_type' => 'product', |
|
| 463 | - 'posts_per_page' => '1000', |
|
| 464 | - 'fields' => 'ids', |
|
| 465 | - 'meta_query'=> array( |
|
| 466 | - 'relation' => 'OR', |
|
| 467 | - array( |
|
| 468 | - 'key'=> '_regular_price', |
|
| 469 | - 'value' => 0, |
|
| 470 | - ), |
|
| 471 | - array( |
|
| 472 | - 'key'=> '_sale_price', |
|
| 473 | - 'value' => 0, |
|
| 474 | - ), |
|
| 475 | - ), |
|
| 476 | - )); |
|
| 477 | - |
|
| 478 | - }// end get free product query |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * The metat query for courses that are free |
|
| 482 | - * |
|
| 483 | - * @since 1.9.0 |
|
| 484 | - * @return array $wp_meta_query_param |
|
| 485 | - */ |
|
| 486 | - public static function get_free_courses_meta_query_args(){ |
|
| 487 | - |
|
| 488 | - return array( |
|
| 489 | - 'relation' => 'OR', |
|
| 490 | - array( |
|
| 491 | - 'key' => '_course_woocommerce_product', |
|
| 492 | - 'value' => '-', |
|
| 493 | - 'compare' => '=', |
|
| 494 | - ), |
|
| 495 | - array( |
|
| 496 | - 'key' => '_course_woocommerce_product', |
|
| 497 | - 'value' => self::get_free_product_ids(), |
|
| 498 | - 'compare' => 'IN', |
|
| 499 | - ), |
|
| 500 | - ); |
|
| 501 | - |
|
| 502 | - }// get_free_courses_meta_query |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * The metat query for courses that are free |
|
| 506 | - * |
|
| 507 | - * @since 1.9.0 |
|
| 508 | - * @return array $wp_query_meta_query_args_param |
|
| 509 | - */ |
|
| 510 | - public static function get_paid_courses_meta_query_args(){ |
|
| 511 | - |
|
| 512 | - $paid_product_ids = self::get_paid_product_ids(); |
|
| 513 | - |
|
| 514 | - return array( |
|
| 515 | - array( |
|
| 516 | - 'key' => '_course_woocommerce_product', |
|
| 517 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 518 | - // query |
|
| 519 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 520 | - 'compare' => 'IN', |
|
| 521 | - ), |
|
| 522 | - ); |
|
| 523 | - |
|
| 524 | - }// get_free_courses_meta_query |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * The WordPress Query args |
|
| 528 | - * for paid products on sale |
|
| 529 | - * |
|
| 530 | - * @since 1.9.0 |
|
| 531 | - * @return array $product_query_args |
|
| 532 | - */ |
|
| 533 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 534 | - |
|
| 535 | - $args = array( |
|
| 536 | - 'post_type' => 'product', |
|
| 537 | - 'posts_per_page' => 1000, |
|
| 538 | - 'orderby' => 'date', |
|
| 539 | - 'order' => 'DESC', |
|
| 540 | - 'suppress_filters' => 0 |
|
| 541 | - ); |
|
| 542 | - |
|
| 543 | - $args[ 'fields' ] = 'ids'; |
|
| 544 | - |
|
| 545 | - $args[ 'meta_query' ] = array( |
|
| 546 | - 'relation' => 'AND', |
|
| 547 | - array( |
|
| 548 | - 'key'=> '_regular_price', |
|
| 549 | - 'compare' => '>', |
|
| 550 | - 'value' => 0, |
|
| 551 | - ), |
|
| 552 | - array( |
|
| 553 | - 'key'=> '_sale_price', |
|
| 554 | - 'compare' => '>', |
|
| 555 | - 'value' => 0, |
|
| 556 | - ), |
|
| 557 | - ); |
|
| 558 | - |
|
| 559 | - return $args; |
|
| 560 | - |
|
| 561 | - } // get_paid_products_on_sale_query_args |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Return the WordPress query args for |
|
| 566 | - * products not on sale but that is not a free |
|
| 567 | - * |
|
| 568 | - * @since 1.9.0 |
|
| 569 | - * |
|
| 570 | - * @return array |
|
| 571 | - */ |
|
| 572 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 573 | - |
|
| 574 | - $args = array( |
|
| 575 | - 'post_type' => 'product', |
|
| 576 | - 'posts_per_page' => 1000, |
|
| 577 | - 'orderby' => 'date', |
|
| 578 | - 'order' => 'DESC', |
|
| 579 | - 'suppress_filters' => 0 |
|
| 580 | - ); |
|
| 581 | - |
|
| 582 | - $args[ 'fields' ] = 'ids'; |
|
| 583 | - $args[ 'meta_query' ] = array( |
|
| 584 | - 'relation' => 'AND', |
|
| 585 | - array( |
|
| 586 | - 'key'=> '_regular_price', |
|
| 587 | - 'compare' => '>', |
|
| 588 | - 'value' => 0, |
|
| 589 | - ), |
|
| 590 | - array( |
|
| 591 | - 'key'=> '_sale_price', |
|
| 592 | - 'compare' => '=', |
|
| 593 | - 'value' => '', |
|
| 594 | - ), |
|
| 595 | - ); |
|
| 596 | - |
|
| 597 | - return $args; |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - } // get_paid_courses_meta_query |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Get all WooCommerce non-free product id's |
|
| 604 | - * |
|
| 605 | - * @since 1.9.0 |
|
| 606 | - * |
|
| 607 | - * @return array $woocommerce_paid_product_ids |
|
| 608 | - */ |
|
| 609 | - public static function get_paid_product_ids(){ |
|
| 610 | - |
|
| 611 | - // get all the paid WooCommerce products that has regular |
|
| 612 | - // and sale price greater than 0 |
|
| 613 | - // will be used later to check for course with the id as meta |
|
| 614 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 615 | - |
|
| 616 | - // get all the paid WooCommerce products that has regular price |
|
| 617 | - // greater than 0 without a sale price |
|
| 618 | - // will be used later to check for course with the id as meta |
|
| 619 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 620 | - |
|
| 621 | - // combine products ID's with regular and sale price grater than zero and those without |
|
| 622 | - // sale but regular price greater than zero |
|
| 623 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 624 | - |
|
| 625 | - // if |
|
| 626 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 627 | - return array( ); |
|
| 628 | - } |
|
| 629 | - return $woocommerce_paid_product_ids; |
|
| 630 | - |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Get all free courses. |
|
| 635 | - * |
|
| 636 | - * This course that have a WC product attached |
|
| 637 | - * that has a price or sale price of zero and |
|
| 638 | - * other courses with no WooCommerce products |
|
| 639 | - * attached. |
|
| 640 | - * |
|
| 641 | - * @since 1.9.0 |
|
| 642 | - * |
|
| 643 | - * @return array |
|
| 644 | - */ |
|
| 645 | - public static function get_free_courses(){ |
|
| 646 | - |
|
| 647 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 648 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 649 | - |
|
| 650 | - // don't show any paid courses |
|
| 651 | - $courses = self::get_paid_courses(); |
|
| 652 | - $ids = array(); |
|
| 653 | - foreach( $courses as $course ){ |
|
| 654 | - $ids[] = $course->ID; |
|
| 655 | - } |
|
| 656 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 657 | - |
|
| 658 | - return get_posts( $free_course_query_args ); |
|
| 659 | - |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * Return all products that are not free |
|
| 664 | - * |
|
| 665 | - * @since 1.9.0 |
|
| 666 | - * @return array |
|
| 667 | - */ |
|
| 668 | - public static function get_paid_courses(){ |
|
| 669 | - |
|
| 670 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 671 | - |
|
| 672 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 673 | - |
|
| 674 | - return get_posts( $paid_course_query_args ); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - /** |
|
| 678 | - * Show the WooCommerce add to cart button for the current course |
|
| 679 | - * |
|
| 680 | - * The function will only show the button if |
|
| 681 | - * 1- the user can buy the course |
|
| 682 | - * 2- if they have completed their pre-requisite |
|
| 683 | - * 3- if the course has a valid product attached |
|
| 684 | - * |
|
| 685 | - * @since 1.9.0 |
|
| 686 | - * @param int $course_id |
|
| 687 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 688 | - */ |
|
| 689 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 690 | - |
|
| 691 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 692 | - return ''; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 696 | - |
|
| 697 | - // Check if customer purchased the product |
|
| 698 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 699 | - || empty( $wc_post_id ) ) { |
|
| 700 | - |
|
| 701 | - return ''; |
|
| 702 | - |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 706 | - // Get the product |
|
| 707 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 708 | - |
|
| 709 | - // do not show the button for invalid products, non purchasable products, out |
|
| 710 | - // of stock product or if course is already in cart |
|
| 711 | - if ( ! isset ( $product ) |
|
| 712 | - || ! is_object( $product ) |
|
| 713 | - || ! $product->is_purchasable() |
|
| 714 | - || ! $product->is_in_stock() |
|
| 715 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 716 | - |
|
| 717 | - return ''; |
|
| 718 | - |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - // |
|
| 722 | - // button output: |
|
| 723 | - // |
|
| 724 | - ?> |
|
| 393 | + /** |
|
| 394 | + * Checks the cart to see if a course is in the cart. |
|
| 395 | + * |
|
| 396 | + * @param $course_id |
|
| 397 | + * @return bool |
|
| 398 | + */ |
|
| 399 | + public static function is_course_in_cart( $course_id ){ |
|
| 400 | + |
|
| 401 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 402 | + $user_course_status_id = WooThemes_Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 403 | + |
|
| 404 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 405 | + |
|
| 406 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 407 | + |
|
| 408 | + return true; |
|
| 409 | + |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + return false; |
|
| 415 | + |
|
| 416 | + }// is_course_in_cart |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Check the cart to see if the product is in the cart |
|
| 420 | + * |
|
| 421 | + * @param $product_id |
|
| 422 | + * @return bool |
|
| 423 | + */ |
|
| 424 | + public static function is_product_in_cart( $product_id ){ |
|
| 425 | + |
|
| 426 | + if ( 0 < $product_id ) { |
|
| 427 | + |
|
| 428 | + $product = wc_get_product( $product_id ); |
|
| 429 | + |
|
| 430 | + $parent_id = ''; |
|
| 431 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 432 | + $wc_product_id = $product->parent->id; |
|
| 433 | + } |
|
| 434 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 435 | + |
|
| 436 | + $cart_product = $values['data']; |
|
| 437 | + if( $product_id == $cart_product->id ) { |
|
| 438 | + |
|
| 439 | + return true; |
|
| 440 | + |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + } |
|
| 444 | + } // End If Statement |
|
| 445 | + |
|
| 446 | + return false; |
|
| 447 | + |
|
| 448 | + } // end is_product_in_car |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Get all free WooCommerce products |
|
| 452 | + * |
|
| 453 | + * @since 1.9.0 |
|
| 454 | + * |
|
| 455 | + * @return array $free_products{ |
|
| 456 | + * @type int $wp_post_id |
|
| 457 | + * } |
|
| 458 | + */ |
|
| 459 | + public static function get_free_product_ids(){ |
|
| 460 | + |
|
| 461 | + return get_posts( array( |
|
| 462 | + 'post_type' => 'product', |
|
| 463 | + 'posts_per_page' => '1000', |
|
| 464 | + 'fields' => 'ids', |
|
| 465 | + 'meta_query'=> array( |
|
| 466 | + 'relation' => 'OR', |
|
| 467 | + array( |
|
| 468 | + 'key'=> '_regular_price', |
|
| 469 | + 'value' => 0, |
|
| 470 | + ), |
|
| 471 | + array( |
|
| 472 | + 'key'=> '_sale_price', |
|
| 473 | + 'value' => 0, |
|
| 474 | + ), |
|
| 475 | + ), |
|
| 476 | + )); |
|
| 477 | + |
|
| 478 | + }// end get free product query |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * The metat query for courses that are free |
|
| 482 | + * |
|
| 483 | + * @since 1.9.0 |
|
| 484 | + * @return array $wp_meta_query_param |
|
| 485 | + */ |
|
| 486 | + public static function get_free_courses_meta_query_args(){ |
|
| 487 | + |
|
| 488 | + return array( |
|
| 489 | + 'relation' => 'OR', |
|
| 490 | + array( |
|
| 491 | + 'key' => '_course_woocommerce_product', |
|
| 492 | + 'value' => '-', |
|
| 493 | + 'compare' => '=', |
|
| 494 | + ), |
|
| 495 | + array( |
|
| 496 | + 'key' => '_course_woocommerce_product', |
|
| 497 | + 'value' => self::get_free_product_ids(), |
|
| 498 | + 'compare' => 'IN', |
|
| 499 | + ), |
|
| 500 | + ); |
|
| 501 | + |
|
| 502 | + }// get_free_courses_meta_query |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * The metat query for courses that are free |
|
| 506 | + * |
|
| 507 | + * @since 1.9.0 |
|
| 508 | + * @return array $wp_query_meta_query_args_param |
|
| 509 | + */ |
|
| 510 | + public static function get_paid_courses_meta_query_args(){ |
|
| 511 | + |
|
| 512 | + $paid_product_ids = self::get_paid_product_ids(); |
|
| 513 | + |
|
| 514 | + return array( |
|
| 515 | + array( |
|
| 516 | + 'key' => '_course_woocommerce_product', |
|
| 517 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 518 | + // query |
|
| 519 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 520 | + 'compare' => 'IN', |
|
| 521 | + ), |
|
| 522 | + ); |
|
| 523 | + |
|
| 524 | + }// get_free_courses_meta_query |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * The WordPress Query args |
|
| 528 | + * for paid products on sale |
|
| 529 | + * |
|
| 530 | + * @since 1.9.0 |
|
| 531 | + * @return array $product_query_args |
|
| 532 | + */ |
|
| 533 | + public static function get_paid_products_on_sale_query_args(){ |
|
| 534 | + |
|
| 535 | + $args = array( |
|
| 536 | + 'post_type' => 'product', |
|
| 537 | + 'posts_per_page' => 1000, |
|
| 538 | + 'orderby' => 'date', |
|
| 539 | + 'order' => 'DESC', |
|
| 540 | + 'suppress_filters' => 0 |
|
| 541 | + ); |
|
| 542 | + |
|
| 543 | + $args[ 'fields' ] = 'ids'; |
|
| 544 | + |
|
| 545 | + $args[ 'meta_query' ] = array( |
|
| 546 | + 'relation' => 'AND', |
|
| 547 | + array( |
|
| 548 | + 'key'=> '_regular_price', |
|
| 549 | + 'compare' => '>', |
|
| 550 | + 'value' => 0, |
|
| 551 | + ), |
|
| 552 | + array( |
|
| 553 | + 'key'=> '_sale_price', |
|
| 554 | + 'compare' => '>', |
|
| 555 | + 'value' => 0, |
|
| 556 | + ), |
|
| 557 | + ); |
|
| 558 | + |
|
| 559 | + return $args; |
|
| 560 | + |
|
| 561 | + } // get_paid_products_on_sale_query_args |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Return the WordPress query args for |
|
| 566 | + * products not on sale but that is not a free |
|
| 567 | + * |
|
| 568 | + * @since 1.9.0 |
|
| 569 | + * |
|
| 570 | + * @return array |
|
| 571 | + */ |
|
| 572 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
| 573 | + |
|
| 574 | + $args = array( |
|
| 575 | + 'post_type' => 'product', |
|
| 576 | + 'posts_per_page' => 1000, |
|
| 577 | + 'orderby' => 'date', |
|
| 578 | + 'order' => 'DESC', |
|
| 579 | + 'suppress_filters' => 0 |
|
| 580 | + ); |
|
| 581 | + |
|
| 582 | + $args[ 'fields' ] = 'ids'; |
|
| 583 | + $args[ 'meta_query' ] = array( |
|
| 584 | + 'relation' => 'AND', |
|
| 585 | + array( |
|
| 586 | + 'key'=> '_regular_price', |
|
| 587 | + 'compare' => '>', |
|
| 588 | + 'value' => 0, |
|
| 589 | + ), |
|
| 590 | + array( |
|
| 591 | + 'key'=> '_sale_price', |
|
| 592 | + 'compare' => '=', |
|
| 593 | + 'value' => '', |
|
| 594 | + ), |
|
| 595 | + ); |
|
| 596 | + |
|
| 597 | + return $args; |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + } // get_paid_courses_meta_query |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Get all WooCommerce non-free product id's |
|
| 604 | + * |
|
| 605 | + * @since 1.9.0 |
|
| 606 | + * |
|
| 607 | + * @return array $woocommerce_paid_product_ids |
|
| 608 | + */ |
|
| 609 | + public static function get_paid_product_ids(){ |
|
| 610 | + |
|
| 611 | + // get all the paid WooCommerce products that has regular |
|
| 612 | + // and sale price greater than 0 |
|
| 613 | + // will be used later to check for course with the id as meta |
|
| 614 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 615 | + |
|
| 616 | + // get all the paid WooCommerce products that has regular price |
|
| 617 | + // greater than 0 without a sale price |
|
| 618 | + // will be used later to check for course with the id as meta |
|
| 619 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 620 | + |
|
| 621 | + // combine products ID's with regular and sale price grater than zero and those without |
|
| 622 | + // sale but regular price greater than zero |
|
| 623 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 624 | + |
|
| 625 | + // if |
|
| 626 | + if( empty($woocommerce_paid_product_ids) ){ |
|
| 627 | + return array( ); |
|
| 628 | + } |
|
| 629 | + return $woocommerce_paid_product_ids; |
|
| 630 | + |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Get all free courses. |
|
| 635 | + * |
|
| 636 | + * This course that have a WC product attached |
|
| 637 | + * that has a price or sale price of zero and |
|
| 638 | + * other courses with no WooCommerce products |
|
| 639 | + * attached. |
|
| 640 | + * |
|
| 641 | + * @since 1.9.0 |
|
| 642 | + * |
|
| 643 | + * @return array |
|
| 644 | + */ |
|
| 645 | + public static function get_free_courses(){ |
|
| 646 | + |
|
| 647 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 648 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 649 | + |
|
| 650 | + // don't show any paid courses |
|
| 651 | + $courses = self::get_paid_courses(); |
|
| 652 | + $ids = array(); |
|
| 653 | + foreach( $courses as $course ){ |
|
| 654 | + $ids[] = $course->ID; |
|
| 655 | + } |
|
| 656 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 657 | + |
|
| 658 | + return get_posts( $free_course_query_args ); |
|
| 659 | + |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * Return all products that are not free |
|
| 664 | + * |
|
| 665 | + * @since 1.9.0 |
|
| 666 | + * @return array |
|
| 667 | + */ |
|
| 668 | + public static function get_paid_courses(){ |
|
| 669 | + |
|
| 670 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 671 | + |
|
| 672 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 673 | + |
|
| 674 | + return get_posts( $paid_course_query_args ); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + /** |
|
| 678 | + * Show the WooCommerce add to cart button for the current course |
|
| 679 | + * |
|
| 680 | + * The function will only show the button if |
|
| 681 | + * 1- the user can buy the course |
|
| 682 | + * 2- if they have completed their pre-requisite |
|
| 683 | + * 3- if the course has a valid product attached |
|
| 684 | + * |
|
| 685 | + * @since 1.9.0 |
|
| 686 | + * @param int $course_id |
|
| 687 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 688 | + */ |
|
| 689 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
| 690 | + |
|
| 691 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 692 | + return ''; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 696 | + |
|
| 697 | + // Check if customer purchased the product |
|
| 698 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 699 | + || empty( $wc_post_id ) ) { |
|
| 700 | + |
|
| 701 | + return ''; |
|
| 702 | + |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 706 | + // Get the product |
|
| 707 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 708 | + |
|
| 709 | + // do not show the button for invalid products, non purchasable products, out |
|
| 710 | + // of stock product or if course is already in cart |
|
| 711 | + if ( ! isset ( $product ) |
|
| 712 | + || ! is_object( $product ) |
|
| 713 | + || ! $product->is_purchasable() |
|
| 714 | + || ! $product->is_in_stock() |
|
| 715 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 716 | + |
|
| 717 | + return ''; |
|
| 718 | + |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + // |
|
| 722 | + // button output: |
|
| 723 | + // |
|
| 724 | + ?> |
|
| 725 | 725 | |
| 726 | 726 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
| 727 | 727 | class="cart" |
@@ -754,54 +754,54 @@ discard block |
||
| 754 | 754 | </form> |
| 755 | 755 | |
| 756 | 756 | <?php |
| 757 | - } // end the_add_to_cart_button_html |
|
| 757 | + } // end the_add_to_cart_button_html |
|
| 758 | 758 | |
| 759 | - /** |
|
| 760 | - * Alter the no permissions message on the single course page |
|
| 761 | - * Changes the message to a WooCommerce specific message. |
|
| 762 | - * |
|
| 763 | - * @since 1.9.0 |
|
| 764 | - * |
|
| 765 | - * @param $message |
|
| 766 | - * @param $post_id |
|
| 767 | - * |
|
| 768 | - * @return string $message |
|
| 769 | - */ |
|
| 770 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 759 | + /** |
|
| 760 | + * Alter the no permissions message on the single course page |
|
| 761 | + * Changes the message to a WooCommerce specific message. |
|
| 762 | + * |
|
| 763 | + * @since 1.9.0 |
|
| 764 | + * |
|
| 765 | + * @param $message |
|
| 766 | + * @param $post_id |
|
| 767 | + * |
|
| 768 | + * @return string $message |
|
| 769 | + */ |
|
| 770 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 771 | 771 | |
| 772 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 773 | - return $message; |
|
| 774 | - } |
|
| 772 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 773 | + return $message; |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 776 | + $product_id = self::get_course_product_id( $post_id ); |
|
| 777 | 777 | |
| 778 | - if( ! $product_id |
|
| 779 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 778 | + if( ! $product_id |
|
| 779 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 780 | 780 | |
| 781 | - return $message; |
|
| 781 | + return $message; |
|
| 782 | 782 | |
| 783 | - } |
|
| 783 | + } |
|
| 784 | 784 | |
| 785 | - ob_start(); |
|
| 786 | - self::the_course_no_permissions_message( $post_id ); |
|
| 787 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 785 | + ob_start(); |
|
| 786 | + self::the_course_no_permissions_message( $post_id ); |
|
| 787 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 788 | 788 | |
| 789 | - return $woocommerce_course_no_permissions_message ; |
|
| 789 | + return $woocommerce_course_no_permissions_message ; |
|
| 790 | 790 | |
| 791 | - } |
|
| 792 | - /** |
|
| 793 | - * Show the no permissions message when a user is logged in |
|
| 794 | - * and have not yet purchased the current course |
|
| 795 | - * |
|
| 796 | - * @since 1.9.0 |
|
| 797 | - */ |
|
| 798 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 791 | + } |
|
| 792 | + /** |
|
| 793 | + * Show the no permissions message when a user is logged in |
|
| 794 | + * and have not yet purchased the current course |
|
| 795 | + * |
|
| 796 | + * @since 1.9.0 |
|
| 797 | + */ |
|
| 798 | + public static function the_course_no_permissions_message( $course_id ){ |
|
| 799 | 799 | |
| 800 | - // login link |
|
| 801 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 802 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 800 | + // login link |
|
| 801 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 802 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 803 | 803 | |
| 804 | - ?> |
|
| 804 | + ?> |
|
| 805 | 805 | |
| 806 | 806 | <span class="add-to-cart-login"> |
| 807 | 807 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -809,110 +809,110 @@ discard block |
||
| 809 | 809 | |
| 810 | 810 | <?php } |
| 811 | 811 | |
| 812 | - /** |
|
| 813 | - * Checks if a user has bought a product item. |
|
| 814 | - * |
|
| 815 | - * @since 1.9.0 |
|
| 816 | - * |
|
| 817 | - * @param int $user_id |
|
| 818 | - * @param int $product_id |
|
| 819 | - * |
|
| 820 | - * @return bool |
|
| 821 | - */ |
|
| 822 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 812 | + /** |
|
| 813 | + * Checks if a user has bought a product item. |
|
| 814 | + * |
|
| 815 | + * @since 1.9.0 |
|
| 816 | + * |
|
| 817 | + * @param int $user_id |
|
| 818 | + * @param int $product_id |
|
| 819 | + * |
|
| 820 | + * @return bool |
|
| 821 | + */ |
|
| 822 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 823 | 823 | |
| 824 | - $orders = get_posts( array( |
|
| 825 | - 'posts_per_page' => -1, |
|
| 826 | - 'meta_key' => '_customer_user', |
|
| 827 | - 'meta_value' => intval( $user_id ), |
|
| 828 | - 'post_type' => 'shop_order', |
|
| 829 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 830 | - ) ); |
|
| 824 | + $orders = get_posts( array( |
|
| 825 | + 'posts_per_page' => -1, |
|
| 826 | + 'meta_key' => '_customer_user', |
|
| 827 | + 'meta_value' => intval( $user_id ), |
|
| 828 | + 'post_type' => 'shop_order', |
|
| 829 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 830 | + ) ); |
|
| 831 | 831 | |
| 832 | - foreach ( $orders as $order_id ) { |
|
| 832 | + foreach ( $orders as $order_id ) { |
|
| 833 | 833 | |
| 834 | - $order = new WC_Order( $order_id->ID ); |
|
| 834 | + $order = new WC_Order( $order_id->ID ); |
|
| 835 | 835 | |
| 836 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 836 | + if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 837 | 837 | |
| 838 | - continue; |
|
| 839 | - } |
|
| 838 | + continue; |
|
| 839 | + } |
|
| 840 | 840 | |
| 841 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 841 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 842 | 842 | |
| 843 | - continue; |
|
| 843 | + continue; |
|
| 844 | 844 | |
| 845 | - } |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - foreach( $order->get_items() as $item ) { |
|
| 847 | + foreach( $order->get_items() as $item ) { |
|
| 848 | 848 | |
| 849 | - // Check if user has bought product |
|
| 850 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 849 | + // Check if user has bought product |
|
| 850 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 851 | 851 | |
| 852 | - // Check if user has an active subscription for product |
|
| 853 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 854 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 855 | - if( $sub_key ) { |
|
| 856 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 857 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 858 | - if( 'active' == $sub['status'] ) { |
|
| 859 | - return true; |
|
| 860 | - } else { |
|
| 861 | - return false; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - } |
|
| 852 | + // Check if user has an active subscription for product |
|
| 853 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 854 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 855 | + if( $sub_key ) { |
|
| 856 | + $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 857 | + if( $sub && isset( $sub['status'] ) ) { |
|
| 858 | + if( 'active' == $sub['status'] ) { |
|
| 859 | + return true; |
|
| 860 | + } else { |
|
| 861 | + return false; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + } |
|
| 866 | 866 | |
| 867 | - // Customer has bought product |
|
| 868 | - return true; |
|
| 869 | - } // End If Statement |
|
| 867 | + // Customer has bought product |
|
| 868 | + return true; |
|
| 869 | + } // End If Statement |
|
| 870 | 870 | |
| 871 | - } // End For each item |
|
| 871 | + } // End For each item |
|
| 872 | 872 | |
| 873 | - } // End For each order |
|
| 873 | + } // End For each order |
|
| 874 | 874 | |
| 875 | - } // end has customer bought product |
|
| 875 | + } // end has customer bought product |
|
| 876 | 876 | |
| 877 | - /** |
|
| 878 | - * Return the product id for the given course |
|
| 879 | - * |
|
| 880 | - * @since 1.9.0 |
|
| 881 | - * |
|
| 882 | - * @param int $course_id |
|
| 883 | - * |
|
| 884 | - * @return string $woocommerce_product_id or false if none exist |
|
| 885 | - * |
|
| 886 | - */ |
|
| 887 | - public static function get_course_product_id( $course_id ){ |
|
| 877 | + /** |
|
| 878 | + * Return the product id for the given course |
|
| 879 | + * |
|
| 880 | + * @since 1.9.0 |
|
| 881 | + * |
|
| 882 | + * @param int $course_id |
|
| 883 | + * |
|
| 884 | + * @return string $woocommerce_product_id or false if none exist |
|
| 885 | + * |
|
| 886 | + */ |
|
| 887 | + public static function get_course_product_id( $course_id ){ |
|
| 888 | 888 | |
| 889 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 889 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 890 | 890 | |
| 891 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 891 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - return $product_id; |
|
| 895 | + return $product_id; |
|
| 896 | 896 | |
| 897 | - } |
|
| 897 | + } |
|
| 898 | 898 | |
| 899 | - /** |
|
| 900 | - * Alter the body classes adding WooCommerce to the body |
|
| 901 | - * |
|
| 902 | - * @param array $classes |
|
| 903 | - * @return array |
|
| 904 | - */ |
|
| 905 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 899 | + /** |
|
| 900 | + * Alter the body classes adding WooCommerce to the body |
|
| 901 | + * |
|
| 902 | + * @param array $classes |
|
| 903 | + * @return array |
|
| 904 | + */ |
|
| 905 | + public static function add_woocommerce_body_class( $classes ){ |
|
| 906 | 906 | |
| 907 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 907 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 908 | 908 | |
| 909 | - $classes[] ='woocommerce'; |
|
| 909 | + $classes[] ='woocommerce'; |
|
| 910 | 910 | |
| 911 | - } |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | 913 | |
| 914 | - return $classes; |
|
| 914 | + return $classes; |
|
| 915 | 915 | |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | 918 | }// end Sensei_WC |
@@ -23,165 +23,165 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class Sensei_Shortcode_User_Courses implements Sensei_Shortcode_Interface { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 28 | - */ |
|
| 29 | - protected $query; |
|
| 26 | + /** |
|
| 27 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 28 | + */ |
|
| 29 | + protected $query; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string number of items to show on the current page |
|
| 33 | - * Default: -1. |
|
| 34 | - */ |
|
| 35 | - protected $number; |
|
| 31 | + /** |
|
| 32 | + * @var string number of items to show on the current page |
|
| 33 | + * Default: -1. |
|
| 34 | + */ |
|
| 35 | + protected $number; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string ordery by course field |
|
| 39 | - * Default: date |
|
| 40 | - */ |
|
| 41 | - protected $orderby; |
|
| 37 | + /** |
|
| 38 | + * @var string ordery by course field |
|
| 39 | + * Default: date |
|
| 40 | + */ |
|
| 41 | + protected $orderby; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string ASC or DESC |
|
| 45 | - * Default: 'DESC' |
|
| 46 | - */ |
|
| 47 | - protected $order; |
|
| 43 | + /** |
|
| 44 | + * @var string ASC or DESC |
|
| 45 | + * Default: 'DESC' |
|
| 46 | + */ |
|
| 47 | + protected $order; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var status can be completed or active. If none is specified all will be shown |
|
| 51 | - */ |
|
| 52 | - protected $status; |
|
| 49 | + /** |
|
| 50 | + * @var status can be completed or active. If none is specified all will be shown |
|
| 51 | + */ |
|
| 52 | + protected $status; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Setup the shortcode object |
|
| 56 | - * |
|
| 57 | - * @since 1.9.0 |
|
| 58 | - * @param array $attributes |
|
| 59 | - * @param string $content |
|
| 60 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 61 | - */ |
|
| 62 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 54 | + /** |
|
| 55 | + * Setup the shortcode object |
|
| 56 | + * |
|
| 57 | + * @since 1.9.0 |
|
| 58 | + * @param array $attributes |
|
| 59 | + * @param string $content |
|
| 60 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 61 | + */ |
|
| 62 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 63 | 63 | |
| 64 | - if(! is_user_logged_in() ) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 64 | + if(! is_user_logged_in() ) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // set up all argument need for constructing the course query |
|
| 69 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 70 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 71 | - $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 68 | + // set up all argument need for constructing the course query |
|
| 69 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 70 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 71 | + $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 72 | 72 | |
| 73 | - // set the default for menu_order to be ASC |
|
| 74 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 73 | + // set the default for menu_order to be ASC |
|
| 74 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 75 | 75 | |
| 76 | - $this->order = 'ASC'; |
|
| 76 | + $this->order = 'ASC'; |
|
| 77 | 77 | |
| 78 | - }else{ |
|
| 78 | + }else{ |
|
| 79 | 79 | |
| 80 | - // for everything else use the value passed or the default DESC |
|
| 81 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 80 | + // for everything else use the value passed or the default DESC |
|
| 81 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 82 | 82 | |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // setup the course query that will be used when rendering |
|
| 86 | - $this->setup_course_query(); |
|
| 87 | - } |
|
| 85 | + // setup the course query that will be used when rendering |
|
| 86 | + $this->setup_course_query(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Sets up the object course query |
|
| 91 | - * that will be used in the render method. |
|
| 92 | - * |
|
| 93 | - * @since 1.9.0 |
|
| 94 | - */ |
|
| 95 | - protected function setup_course_query(){ |
|
| 89 | + /** |
|
| 90 | + * Sets up the object course query |
|
| 91 | + * that will be used in the render method. |
|
| 92 | + * |
|
| 93 | + * @since 1.9.0 |
|
| 94 | + */ |
|
| 95 | + protected function setup_course_query(){ |
|
| 96 | 96 | |
| 97 | - $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 98 | - $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 99 | - if ( !is_array($user_courses_logs) ) { |
|
| 97 | + $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 98 | + $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 99 | + if ( !is_array($user_courses_logs) ) { |
|
| 100 | 100 | |
| 101 | - $user_courses_logs = array( $user_courses_logs ); |
|
| 101 | + $user_courses_logs = array( $user_courses_logs ); |
|
| 102 | 102 | |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $completed_ids = $active_ids = array(); |
|
| 106 | - foreach( $user_courses_logs as $course_status ) { |
|
| 105 | + $completed_ids = $active_ids = array(); |
|
| 106 | + foreach( $user_courses_logs as $course_status ) { |
|
| 107 | 107 | |
| 108 | - if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 108 | + if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 109 | 109 | |
| 110 | - $completed_ids[] = $course_status->comment_post_ID; |
|
| 110 | + $completed_ids[] = $course_status->comment_post_ID; |
|
| 111 | 111 | |
| 112 | - } else { |
|
| 112 | + } else { |
|
| 113 | 113 | |
| 114 | - $active_ids[] = $course_status->comment_post_ID; |
|
| 114 | + $active_ids[] = $course_status->comment_post_ID; |
|
| 115 | 115 | |
| 116 | - } |
|
| 117 | - } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - if( 'completed' == $this->status ){ |
|
| 119 | + if( 'completed' == $this->status ){ |
|
| 120 | 120 | |
| 121 | - $included_courses = $completed_ids; |
|
| 121 | + $included_courses = $completed_ids; |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - }elseif( 'active'==$this->status ){ |
|
| 124 | + }elseif( 'active'==$this->status ){ |
|
| 125 | 125 | |
| 126 | - $included_courses = $active_ids; |
|
| 126 | + $included_courses = $active_ids; |
|
| 127 | 127 | |
| 128 | - }else{ // all courses |
|
| 128 | + }else{ // all courses |
|
| 129 | 129 | |
| 130 | - if( empty( $completed_ids ) ){ |
|
| 130 | + if( empty( $completed_ids ) ){ |
|
| 131 | 131 | |
| 132 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 133 | - } |
|
| 132 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if( empty( $active_ids ) ){ |
|
| 135 | + if( empty( $active_ids ) ){ |
|
| 136 | 136 | |
| 137 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 137 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 138 | 138 | |
| 139 | - } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 141 | + if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 142 | 142 | |
| 143 | - $included_courses = array('-1000'); // don't show any courses |
|
| 143 | + $included_courses = array('-1000'); // don't show any courses |
|
| 144 | 144 | |
| 145 | - }else{ |
|
| 146 | - $included_courses = Sensei_Utils::array_zip_merge( $active_ids, $completed_ids ); |
|
| 147 | - } |
|
| 145 | + }else{ |
|
| 146 | + $included_courses = Sensei_Utils::array_zip_merge( $active_ids, $completed_ids ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // temporary work around to hide pagination on the courses page |
|
| 153 | + // this is in place until we can load the course for each tab via ajax |
|
| 154 | + // if the shortcode is not active or in active and the active and completed |
|
| 155 | + // tabs show up. |
|
| 156 | + $number_of_posts = $this->number; |
|
| 157 | + if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 158 | + $number_of_posts = 1000; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // course query parameters |
|
| 162 | + $query_var_paged = get_query_var('paged'); |
|
| 163 | + $query_args = array( |
|
| 164 | + 'post_type' => 'course', |
|
| 165 | + 'post_status' => 'publish', |
|
| 166 | + 'orderby' => $this->orderby, |
|
| 167 | + 'order' => $this->order, |
|
| 168 | + 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 169 | + 'posts_per_page' => $number_of_posts, |
|
| 170 | + 'post__in' => $included_courses, |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + $this->query = new WP_Query( $query_args ); |
|
| 148 | 174 | |
| 175 | + }// end setup _course_query |
|
| 149 | 176 | |
| 150 | - } |
|
| 151 | - |
|
| 152 | - // temporary work around to hide pagination on the courses page |
|
| 153 | - // this is in place until we can load the course for each tab via ajax |
|
| 154 | - // if the shortcode is not active or in active and the active and completed |
|
| 155 | - // tabs show up. |
|
| 156 | - $number_of_posts = $this->number; |
|
| 157 | - if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 158 | - $number_of_posts = 1000; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // course query parameters |
|
| 162 | - $query_var_paged = get_query_var('paged'); |
|
| 163 | - $query_args = array( |
|
| 164 | - 'post_type' => 'course', |
|
| 165 | - 'post_status' => 'publish', |
|
| 166 | - 'orderby' => $this->orderby, |
|
| 167 | - 'order' => $this->order, |
|
| 168 | - 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 169 | - 'posts_per_page' => $number_of_posts, |
|
| 170 | - 'post__in' => $included_courses, |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - $this->query = new WP_Query( $query_args ); |
|
| 174 | - |
|
| 175 | - }// end setup _course_query |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Output the message that tells the user they have |
|
| 179 | - * no completed courses. |
|
| 180 | - * |
|
| 181 | - * @since 1.9.0 |
|
| 182 | - */ |
|
| 183 | - public function completed_no_course_message_output(){ |
|
| 184 | - ?> |
|
| 177 | + /** |
|
| 178 | + * Output the message that tells the user they have |
|
| 179 | + * no completed courses. |
|
| 180 | + * |
|
| 181 | + * @since 1.9.0 |
|
| 182 | + */ |
|
| 183 | + public function completed_no_course_message_output(){ |
|
| 184 | + ?> |
|
| 185 | 185 | <li class="user-completed"> |
| 186 | 186 | <div class="sensei-message info"> |
| 187 | 187 | |
@@ -190,16 +190,16 @@ discard block |
||
| 190 | 190 | </div> |
| 191 | 191 | </li> |
| 192 | 192 | <?php |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Output the message that tells the user they have |
|
| 197 | - * no active courses. |
|
| 198 | - * |
|
| 199 | - * @since 1.9.0 |
|
| 200 | - */ |
|
| 201 | - public function active_no_course_message_output(){ |
|
| 202 | - ?> |
|
| 195 | + /** |
|
| 196 | + * Output the message that tells the user they have |
|
| 197 | + * no active courses. |
|
| 198 | + * |
|
| 199 | + * @since 1.9.0 |
|
| 200 | + */ |
|
| 201 | + public function active_no_course_message_output(){ |
|
| 202 | + ?> |
|
| 203 | 203 | |
| 204 | 204 | <li class="user-active"> |
| 205 | 205 | <div class="sensei-message info"> |
@@ -215,141 +215,141 @@ discard block |
||
| 215 | 215 | </div> |
| 216 | 216 | </li> |
| 217 | 217 | <?php |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Rendering the shortcode this class is responsible for. |
|
| 222 | - * |
|
| 223 | - * @return string $content |
|
| 224 | - */ |
|
| 225 | - public function render(){ |
|
| 220 | + /** |
|
| 221 | + * Rendering the shortcode this class is responsible for. |
|
| 222 | + * |
|
| 223 | + * @return string $content |
|
| 224 | + */ |
|
| 225 | + public function render(){ |
|
| 226 | 226 | |
| 227 | - global $wp_query; |
|
| 227 | + global $wp_query; |
|
| 228 | 228 | |
| 229 | - if(! is_user_logged_in() ) { |
|
| 230 | - return ''; |
|
| 231 | - } |
|
| 229 | + if(! is_user_logged_in() ) { |
|
| 230 | + return ''; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // keep a reference to old query |
|
| 234 | - $current_global_query = $wp_query; |
|
| 233 | + // keep a reference to old query |
|
| 234 | + $current_global_query = $wp_query; |
|
| 235 | 235 | |
| 236 | - // assign the query setup in $this-> setup_course_query |
|
| 237 | - $wp_query = $this->query; |
|
| 236 | + // assign the query setup in $this-> setup_course_query |
|
| 237 | + $wp_query = $this->query; |
|
| 238 | 238 | |
| 239 | - $this->attach_shortcode_hooks(); |
|
| 239 | + $this->attach_shortcode_hooks(); |
|
| 240 | 240 | |
| 241 | - ob_start(); |
|
| 242 | - echo '<section id="sensei-user-courses">'; |
|
| 243 | - Sensei_Messages::the_my_messages_link(); |
|
| 244 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 245 | - Sensei_Templates::get_template('globals/pagination.php'); |
|
| 246 | - echo '</section>'; |
|
| 241 | + ob_start(); |
|
| 242 | + echo '<section id="sensei-user-courses">'; |
|
| 243 | + Sensei_Messages::the_my_messages_link(); |
|
| 244 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 245 | + Sensei_Templates::get_template('globals/pagination.php'); |
|
| 246 | + echo '</section>'; |
|
| 247 | 247 | |
| 248 | - $shortcode_output = ob_get_clean(); |
|
| 248 | + $shortcode_output = ob_get_clean(); |
|
| 249 | 249 | |
| 250 | - $this->detach_shortcode_hooks(); |
|
| 250 | + $this->detach_shortcode_hooks(); |
|
| 251 | 251 | |
| 252 | - //restore old query |
|
| 253 | - $wp_query = $current_global_query; |
|
| 252 | + //restore old query |
|
| 253 | + $wp_query = $current_global_query; |
|
| 254 | 254 | |
| 255 | - return $shortcode_output; |
|
| 255 | + return $shortcode_output; |
|
| 256 | 256 | |
| 257 | - }// end render |
|
| 257 | + }// end render |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Add hooks for the shortcode |
|
| 261 | - * |
|
| 262 | - * @since 1.9.0 |
|
| 263 | - */ |
|
| 264 | - public function attach_shortcode_hooks(){ |
|
| 259 | + /** |
|
| 260 | + * Add hooks for the shortcode |
|
| 261 | + * |
|
| 262 | + * @since 1.9.0 |
|
| 263 | + */ |
|
| 264 | + public function attach_shortcode_hooks(){ |
|
| 265 | 265 | |
| 266 | - // attach the toggle functionality |
|
| 267 | - // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 268 | - if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 266 | + // attach the toggle functionality |
|
| 267 | + // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 268 | + if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 269 | 269 | |
| 270 | - add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 271 | - add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 270 | + add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 271 | + add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 272 | 272 | |
| 273 | - } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - // add extra classes to distinguish the course based on user completed or active |
|
| 276 | - add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 275 | + // add extra classes to distinguish the course based on user completed or active |
|
| 276 | + add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 277 | 277 | |
| 278 | - // attach progress meter below course |
|
| 279 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 280 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 278 | + // attach progress meter below course |
|
| 279 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 280 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 281 | 281 | |
| 282 | - } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Remove hooks for the shortcode |
|
| 286 | - * |
|
| 287 | - * @since 1.9.0 |
|
| 288 | - */ |
|
| 289 | - public function detach_shortcode_hooks(){ |
|
| 284 | + /** |
|
| 285 | + * Remove hooks for the shortcode |
|
| 286 | + * |
|
| 287 | + * @since 1.9.0 |
|
| 288 | + */ |
|
| 289 | + public function detach_shortcode_hooks(){ |
|
| 290 | 290 | |
| 291 | - //remove all hooks after the output is generated |
|
| 292 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 293 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 294 | - remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 295 | - remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 296 | - } |
|
| 291 | + //remove all hooks after the output is generated |
|
| 292 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 293 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 294 | + remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 295 | + remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Hooks into sensei_course_content_inside_after |
|
| 300 | - * |
|
| 301 | - * @param $course |
|
| 302 | - */ |
|
| 303 | - public function attach_course_progress( $course ){ |
|
| 298 | + /** |
|
| 299 | + * Hooks into sensei_course_content_inside_after |
|
| 300 | + * |
|
| 301 | + * @param $course |
|
| 302 | + */ |
|
| 303 | + public function attach_course_progress( $course ){ |
|
| 304 | 304 | |
| 305 | - $percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() ); |
|
| 306 | - echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 305 | + $percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() ); |
|
| 306 | + echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 307 | 307 | |
| 308 | - }// attach_course_progress |
|
| 308 | + }// attach_course_progress |
|
| 309 | 309 | |
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * Hooked into sensei_course_content_inside_after |
|
| 313 | - * |
|
| 314 | - * Prints out the course action buttons |
|
| 315 | - * |
|
| 316 | - * @param $course |
|
| 317 | - */ |
|
| 318 | - public function attach_course_buttons( $course ){ |
|
| 311 | + /** |
|
| 312 | + * Hooked into sensei_course_content_inside_after |
|
| 313 | + * |
|
| 314 | + * Prints out the course action buttons |
|
| 315 | + * |
|
| 316 | + * @param $course |
|
| 317 | + */ |
|
| 318 | + public function attach_course_buttons( $course ){ |
|
| 319 | 319 | |
| 320 | - Sensei()->course->the_course_action_buttons( $course ); |
|
| 320 | + Sensei()->course->the_course_action_buttons( $course ); |
|
| 321 | 321 | |
| 322 | - }// attach_course_buttons |
|
| 322 | + }// attach_course_buttons |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Add a the user status class for the given course. |
|
| 326 | - * |
|
| 327 | - * @since 1.9 |
|
| 328 | - * |
|
| 329 | - * @param array $classes |
|
| 330 | - * @param WP_Post $course |
|
| 331 | - * @return array $classes |
|
| 332 | - */ |
|
| 333 | - public function course_status_class_tagging($classes, $course){ |
|
| 324 | + /** |
|
| 325 | + * Add a the user status class for the given course. |
|
| 326 | + * |
|
| 327 | + * @since 1.9 |
|
| 328 | + * |
|
| 329 | + * @param array $classes |
|
| 330 | + * @param WP_Post $course |
|
| 331 | + * @return array $classes |
|
| 332 | + */ |
|
| 333 | + public function course_status_class_tagging($classes, $course){ |
|
| 334 | 334 | |
| 335 | - if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 335 | + if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 336 | 336 | |
| 337 | - $classes[] = 'user-completed'; |
|
| 337 | + $classes[] = 'user-completed'; |
|
| 338 | 338 | |
| 339 | - } else { |
|
| 339 | + } else { |
|
| 340 | 340 | |
| 341 | - $classes[] = 'user-active'; |
|
| 341 | + $classes[] = 'user-active'; |
|
| 342 | 342 | |
| 343 | - } |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - return $classes; |
|
| 345 | + return $classes; |
|
| 346 | 346 | |
| 347 | - }// end course_status_class_tagging |
|
| 347 | + }// end course_status_class_tagging |
|
| 348 | 348 | |
| 349 | - /** |
|
| 350 | - * Output the course toggle functionality |
|
| 351 | - */ |
|
| 352 | - public function course_toggle_actions(){ ?> |
|
| 349 | + /** |
|
| 350 | + * Output the course toggle functionality |
|
| 351 | + */ |
|
| 352 | + public function course_toggle_actions(){ ?> |
|
| 353 | 353 | |
| 354 | 354 | <section id="user-course-status-toggle"> |
| 355 | 355 | <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a> |
@@ -359,12 +359,12 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | <?php } |
| 361 | 361 | |
| 362 | - /** |
|
| 363 | - * Load the javascript for the toggle functionality |
|
| 364 | - * |
|
| 365 | - * @since 1.9.0 |
|
| 366 | - */ |
|
| 367 | - function print_course_toggle_actions_inline_script() { ?> |
|
| 362 | + /** |
|
| 363 | + * Load the javascript for the toggle functionality |
|
| 364 | + * |
|
| 365 | + * @since 1.9.0 |
|
| 366 | + */ |
|
| 367 | + function print_course_toggle_actions_inline_script() { ?> |
|
| 368 | 368 | |
| 369 | 369 | <script type="text/javascript"> |
| 370 | 370 | var buttonContainer = jQuery('#user-course-status-toggle'); |
@@ -5,18 +5,18 @@ discard block |
||
| 5 | 5 | * Output tags. |
| 6 | 6 | ***************************************************************************************************/ |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * sensei_course_archive_next_link function. |
|
| 10 | - * |
|
| 11 | - * @access public |
|
| 12 | - * @param string $type (default: 'newcourses') |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
| 8 | + /** |
|
| 9 | + * sensei_course_archive_next_link function. |
|
| 10 | + * |
|
| 11 | + * @access public |
|
| 12 | + * @param string $type (default: 'newcourses') |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
| 16 | 16 | |
| 17 | - _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
| 17 | + _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
| 18 | 18 | |
| 19 | - } // End sensei_course_archive_next_link() |
|
| 19 | + } // End sensei_course_archive_next_link() |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * course_single_lessons function. |
@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function course_single_lessons() { |
| 28 | 28 | |
| 29 | - // load backwards compatible template name if it exists in the users theme |
|
| 30 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
| 31 | - if( $located_template ){ |
|
| 29 | + // load backwards compatible template name if it exists in the users theme |
|
| 30 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
| 31 | + if( $located_template ){ |
|
| 32 | 32 | |
| 33 | - Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
| 34 | - return; |
|
| 33 | + Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
| 34 | + return; |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | Sensei_Templates::get_template( 'single-course/lessons.php' ); |
| 39 | 39 | |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function lesson_single_meta() { |
| 50 | 50 | |
| 51 | - _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
| 52 | - sensei_the_single_lesson_meta(); |
|
| 51 | + _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
| 52 | + sensei_the_single_lesson_meta(); |
|
| 53 | 53 | |
| 54 | 54 | } // End lesson_single_meta() |
| 55 | 55 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @access public |
| 61 | 61 | * @param bool $return (default: false) |
| 62 | 62 | * @return void |
| 63 | - * @deprecated since 1.9.0 |
|
| 63 | + * @deprecated since 1.9.0 |
|
| 64 | 64 | */ |
| 65 | 65 | function quiz_questions( $return = false ) { |
| 66 | 66 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | * @access public |
| 75 | 75 | * @since 1.3.0 |
| 76 | 76 | * @return void |
| 77 | - * @deprecated |
|
| 77 | + * @deprecated |
|
| 78 | 78 | */ |
| 79 | 79 | function quiz_question_type( $question_type = 'multiple-choice' ) { |
| 80 | 80 | |
| 81 | - Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 81 | + Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 82 | 82 | |
| 83 | 83 | } // End lesson_single_meta() |
| 84 | 84 | |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | /** |
| 90 | 90 | * sensei_check_prerequisite_course function. |
| 91 | 91 | * |
| 92 | - * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 92 | + * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 93 | 93 | * @access public |
| 94 | 94 | * @param mixed $course_id |
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | 97 | function sensei_check_prerequisite_course( $course_id ) { |
| 98 | 98 | |
| 99 | - return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 99 | + return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 100 | 100 | |
| 101 | 101 | } // End sensei_check_prerequisite_course() |
| 102 | 102 | |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | <span><input name="course_start" type="submit" class="course-start" value="<?php _e( 'Start taking this Course', 'woothemes-sensei' ); ?>"/></span> |
| 121 | 121 | |
| 122 | 122 | </form><?php |
| 123 | - } // End If Statement |
|
| 123 | + } // End If Statement |
|
| 124 | 124 | } // End sensei_start_course_form() |
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * sensei_wc_add_to_cart function. |
| 129 | 129 | * |
| 130 | - * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
| 130 | + * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
| 131 | 131 | * @access public |
| 132 | 132 | * @param mixed $course_id |
| 133 | 133 | * @return void |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | 149 | function sensei_check_if_product_is_in_cart( $wc_product_id = 0 ) { |
| 150 | - return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
| 150 | + return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
| 151 | 151 | } // End sensei_check_if_product_is_in_cart() |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | function sensei_simple_course_price( $post_id ) { |
| 161 | 161 | |
| 162 | 162 | //WooCommerce Pricing |
| 163 | - if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() ) { |
|
| 164 | - $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
| 165 | - if ( 0 < $wc_post_id ) { |
|
| 166 | - // Get the product |
|
| 167 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 163 | + if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() ) { |
|
| 164 | + $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
| 165 | + if ( 0 < $wc_post_id ) { |
|
| 166 | + // Get the product |
|
| 167 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 168 | 168 | |
| 169 | - if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
| 169 | + if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
| 170 | 170 | <span class="course-price"><?php echo $product->get_price_html(); ?></span> |
| 171 | 171 | <?php } // End If Statement |
| 172 | - } // End If Statement |
|
| 173 | - } // End If Statement |
|
| 172 | + } // End If Statement |
|
| 173 | + } // End If Statement |
|
| 174 | 174 | } // End sensei_simple_course_price() |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | |
| 199 | 199 | if ( ! $query->is_main_query() ) |
| 200 | - return; |
|
| 200 | + return; |
|
| 201 | 201 | |
| 202 | 202 | // Apply Filter only if on frontend and when course archive is running |
| 203 | 203 | $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | if ( ! is_admin() && 0 < $course_page_id && 0 < intval( $query->get( 'page_id' ) ) && $query->get( 'page_id' ) == $course_page_id ) { |
| 206 | 206 | // Check for pagination settings |
| 207 | 207 | if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
| 208 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 209 | - } else { |
|
| 210 | - $amount = $query->get( 'posts_per_page' ); |
|
| 211 | - } // End If Statement |
|
| 212 | - $query->set( 'posts_per_page', $amount ); |
|
| 208 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 209 | + } else { |
|
| 210 | + $amount = $query->get( 'posts_per_page' ); |
|
| 211 | + } // End If Statement |
|
| 212 | + $query->set( 'posts_per_page', $amount ); |
|
| 213 | 213 | } // End If Statement |
| 214 | 214 | } // End sensei_course_archive_filter() |
| 215 | 215 | add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 ); |
@@ -248,66 +248,66 @@ discard block |
||
| 248 | 248 | $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
| 249 | 249 | $all_lessons = array(); |
| 250 | 250 | |
| 251 | - $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
| 252 | - |
|
| 253 | - foreach( (array) $modules as $module ) { |
|
| 254 | - |
|
| 255 | - $args = array( |
|
| 256 | - 'post_type' => 'lesson', |
|
| 257 | - 'post_status' => 'publish', |
|
| 258 | - 'posts_per_page' => -1, |
|
| 259 | - 'meta_query' => array( |
|
| 260 | - array( |
|
| 261 | - 'key' => '_lesson_course', |
|
| 262 | - 'value' => intval( $lesson_course_id ), |
|
| 263 | - 'compare' => '=' |
|
| 264 | - ) |
|
| 265 | - ), |
|
| 266 | - 'tax_query' => array( |
|
| 267 | - array( |
|
| 268 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 269 | - 'field' => 'id', |
|
| 270 | - 'terms' => intval( $module->term_id ) |
|
| 271 | - ) |
|
| 272 | - ), |
|
| 273 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
| 274 | - 'orderby' => 'meta_value_num date', |
|
| 275 | - 'order' => 'ASC', |
|
| 276 | - 'suppress_filters' => 0 |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - $lessons = get_posts( $args ); |
|
| 280 | - if ( 0 < count( $lessons ) ) { |
|
| 281 | - foreach ($lessons as $lesson_item){ |
|
| 282 | - $all_lessons[] = $lesson_item->ID; |
|
| 283 | - } // End For Loop |
|
| 284 | - } // End If Statement |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $args = array( |
|
| 288 | - 'post_type' => 'lesson', |
|
| 289 | - 'posts_per_page' => -1, |
|
| 290 | - 'suppress_filters' => 0, |
|
| 291 | - 'meta_key' => '_order_' . $lesson_course_id, |
|
| 292 | - 'orderby' => 'meta_value_num date', |
|
| 293 | - 'order' => 'ASC', |
|
| 294 | - 'meta_query' => array( |
|
| 295 | - array( |
|
| 296 | - 'key' => '_lesson_course', |
|
| 297 | - 'value' => intval( $lesson_course_id ), |
|
| 298 | - ), |
|
| 299 | - ), |
|
| 300 | - 'post__not_in' => $all_lessons, |
|
| 301 | - ); |
|
| 302 | - |
|
| 303 | - $other_lessons = get_posts( $args ); |
|
| 304 | - if ( 0 < count( $other_lessons ) ) { |
|
| 251 | + $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
| 252 | + |
|
| 253 | + foreach( (array) $modules as $module ) { |
|
| 254 | + |
|
| 255 | + $args = array( |
|
| 256 | + 'post_type' => 'lesson', |
|
| 257 | + 'post_status' => 'publish', |
|
| 258 | + 'posts_per_page' => -1, |
|
| 259 | + 'meta_query' => array( |
|
| 260 | + array( |
|
| 261 | + 'key' => '_lesson_course', |
|
| 262 | + 'value' => intval( $lesson_course_id ), |
|
| 263 | + 'compare' => '=' |
|
| 264 | + ) |
|
| 265 | + ), |
|
| 266 | + 'tax_query' => array( |
|
| 267 | + array( |
|
| 268 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 269 | + 'field' => 'id', |
|
| 270 | + 'terms' => intval( $module->term_id ) |
|
| 271 | + ) |
|
| 272 | + ), |
|
| 273 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
| 274 | + 'orderby' => 'meta_value_num date', |
|
| 275 | + 'order' => 'ASC', |
|
| 276 | + 'suppress_filters' => 0 |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + $lessons = get_posts( $args ); |
|
| 280 | + if ( 0 < count( $lessons ) ) { |
|
| 281 | + foreach ($lessons as $lesson_item){ |
|
| 282 | + $all_lessons[] = $lesson_item->ID; |
|
| 283 | + } // End For Loop |
|
| 284 | + } // End If Statement |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $args = array( |
|
| 288 | + 'post_type' => 'lesson', |
|
| 289 | + 'posts_per_page' => -1, |
|
| 290 | + 'suppress_filters' => 0, |
|
| 291 | + 'meta_key' => '_order_' . $lesson_course_id, |
|
| 292 | + 'orderby' => 'meta_value_num date', |
|
| 293 | + 'order' => 'ASC', |
|
| 294 | + 'meta_query' => array( |
|
| 295 | + array( |
|
| 296 | + 'key' => '_lesson_course', |
|
| 297 | + 'value' => intval( $lesson_course_id ), |
|
| 298 | + ), |
|
| 299 | + ), |
|
| 300 | + 'post__not_in' => $all_lessons, |
|
| 301 | + ); |
|
| 302 | + |
|
| 303 | + $other_lessons = get_posts( $args ); |
|
| 304 | + if ( 0 < count( $other_lessons ) ) { |
|
| 305 | 305 | foreach ($other_lessons as $lesson_item){ |
| 306 | 306 | $all_lessons[] = $lesson_item->ID; |
| 307 | 307 | } // End For Loop |
| 308 | 308 | } // End If Statement |
| 309 | 309 | |
| 310 | - if ( 0 < count( $all_lessons ) ) { |
|
| 310 | + if ( 0 < count( $all_lessons ) ) { |
|
| 311 | 311 | $found_index = false; |
| 312 | 312 | foreach ( $all_lessons as $lesson ){ |
| 313 | 313 | if ( $found_index && $return_values['next_lesson'] == 0 ) { |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | function sensei_get_excerpt( $post_id = '' ) { |
| 340 | 340 | |
| 341 | - global $post; |
|
| 342 | - _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
| 343 | - return get_the_excerpt(); |
|
| 341 | + global $post; |
|
| 342 | + _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
| 343 | + return get_the_excerpt(); |
|
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | function sensei_has_user_completed_prerequisite_lesson( $current_lesson_id, $user_id ) { |
| 367 | 367 | |
| 368 | - return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
| 368 | + return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
| 369 | 369 | |
| 370 | 370 | } // End sensei_has_user_completed_prerequisite_lesson() |
| 371 | 371 | |
@@ -480,27 +480,27 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | }else{ |
| 482 | 482 | |
| 483 | - // if the loop has not been initiated check the first module has lessons |
|
| 484 | - if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
| 483 | + // if the loop has not been initiated check the first module has lessons |
|
| 484 | + if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
| 485 | 485 | |
| 486 | - $index = 0; |
|
| 486 | + $index = 0; |
|
| 487 | 487 | |
| 488 | - if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
| 489 | - // setup the query for the module lessons |
|
| 490 | - $course_id = $sensei_modules_loop['course_id']; |
|
| 488 | + if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
| 489 | + // setup the query for the module lessons |
|
| 490 | + $course_id = $sensei_modules_loop['course_id']; |
|
| 491 | 491 | |
| 492 | - $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
| 493 | - $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
| 492 | + $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
| 493 | + $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
| 494 | 494 | |
| 495 | - // setup the global wp-query only if the lessons |
|
| 496 | - if( $modules_query->have_posts() ){ |
|
| 495 | + // setup the global wp-query only if the lessons |
|
| 496 | + if( $modules_query->have_posts() ){ |
|
| 497 | 497 | |
| 498 | - return true; |
|
| 498 | + return true; |
|
| 499 | 499 | |
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - // default to false if the first module doesn't have posts |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + // default to false if the first module doesn't have posts |
|
| 504 | 504 | return false; |
| 505 | 505 | |
| 506 | 506 | } |
@@ -612,21 +612,21 @@ discard block |
||
| 612 | 612 | */ |
| 613 | 613 | function sensei_quiz_has_questions(){ |
| 614 | 614 | |
| 615 | - global $sensei_question_loop; |
|
| 615 | + global $sensei_question_loop; |
|
| 616 | 616 | |
| 617 | - if( !isset( $sensei_question_loop['total'] ) ){ |
|
| 618 | - return false; |
|
| 619 | - } |
|
| 617 | + if( !isset( $sensei_question_loop['total'] ) ){ |
|
| 618 | + return false; |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | - if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
| 621 | + if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
| 622 | 622 | |
| 623 | - return true; |
|
| 623 | + return true; |
|
| 624 | 624 | |
| 625 | - }else{ |
|
| 625 | + }else{ |
|
| 626 | 626 | |
| 627 | - return false; |
|
| 627 | + return false; |
|
| 628 | 628 | |
| 629 | - } |
|
| 629 | + } |
|
| 630 | 630 | |
| 631 | 631 | }// end sensei_quiz_has_questions |
| 632 | 632 | |
@@ -637,15 +637,14 @@ discard block |
||
| 637 | 637 | * execution. |
| 638 | 638 | * |
| 639 | 639 | * @since 1.9.0 |
| 640 | - |
|
| 641 | 640 | */ |
| 642 | 641 | function sensei_setup_the_question(){ |
| 643 | 642 | |
| 644 | - global $sensei_question_loop; |
|
| 643 | + global $sensei_question_loop; |
|
| 645 | 644 | |
| 646 | - $sensei_question_loop['current']++; |
|
| 647 | - $index = $sensei_question_loop['current']; |
|
| 648 | - $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
| 645 | + $sensei_question_loop['current']++; |
|
| 646 | + $index = $sensei_question_loop['current']; |
|
| 647 | + $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
| 649 | 648 | |
| 650 | 649 | |
| 651 | 650 | }// end sensei_setup_the_question |
@@ -658,12 +657,12 @@ discard block |
||
| 658 | 657 | */ |
| 659 | 658 | function sensei_the_question_content(){ |
| 660 | 659 | |
| 661 | - global $sensei_question_loop; |
|
| 660 | + global $sensei_question_loop; |
|
| 662 | 661 | |
| 663 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 662 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 664 | 663 | |
| 665 | - // load the template that displays the question information. |
|
| 666 | - WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
| 664 | + // load the template that displays the question information. |
|
| 665 | + WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
| 667 | 666 | |
| 668 | 667 | }// end sensei_the_question_content |
| 669 | 668 | |
@@ -674,26 +673,26 @@ discard block |
||
| 674 | 673 | */ |
| 675 | 674 | function sensei_the_question_class(){ |
| 676 | 675 | |
| 677 | - global $sensei_question_loop; |
|
| 676 | + global $sensei_question_loop; |
|
| 678 | 677 | |
| 679 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 678 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 680 | 679 | |
| 681 | - /** |
|
| 682 | - * filter the sensei question class within |
|
| 683 | - * the quiz question loop. |
|
| 684 | - * |
|
| 685 | - * @since 1.9.0 |
|
| 686 | - */ |
|
| 687 | - $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
| 680 | + /** |
|
| 681 | + * filter the sensei question class within |
|
| 682 | + * the quiz question loop. |
|
| 683 | + * |
|
| 684 | + * @since 1.9.0 |
|
| 685 | + */ |
|
| 686 | + $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
| 688 | 687 | |
| 689 | - $html_classes = ''; |
|
| 690 | - foreach( $classes as $class ){ |
|
| 688 | + $html_classes = ''; |
|
| 689 | + foreach( $classes as $class ){ |
|
| 691 | 690 | |
| 692 | - $html_classes .= $class . ' '; |
|
| 691 | + $html_classes .= $class . ' '; |
|
| 693 | 692 | |
| 694 | - }// end foreach |
|
| 693 | + }// end foreach |
|
| 695 | 694 | |
| 696 | - esc_attr_e( trim( $html_classes ) ); |
|
| 695 | + esc_attr_e( trim( $html_classes ) ); |
|
| 697 | 696 | |
| 698 | 697 | } |
| 699 | 698 | |
@@ -704,12 +703,12 @@ discard block |
||
| 704 | 703 | */ |
| 705 | 704 | function sensei_get_the_question_id( ){ |
| 706 | 705 | |
| 707 | - global $sensei_question_loop; |
|
| 708 | - if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
| 706 | + global $sensei_question_loop; |
|
| 707 | + if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
| 709 | 708 | |
| 710 | - return $sensei_question_loop['current_question']->ID; |
|
| 709 | + return $sensei_question_loop['current_question']->ID; |
|
| 711 | 710 | |
| 712 | - } |
|
| 711 | + } |
|
| 713 | 712 | |
| 714 | 713 | }// end sensei_the_question_id |
| 715 | 714 | |
@@ -736,63 +735,63 @@ discard block |
||
| 736 | 735 | */ |
| 737 | 736 | function sensei_can_user_view_lesson( $lesson_id = '', $user_id = '' ){ |
| 738 | 737 | |
| 739 | - if( empty( $lesson_id ) ){ |
|
| 738 | + if( empty( $lesson_id ) ){ |
|
| 740 | 739 | |
| 741 | - $lesson_id = get_the_ID(); |
|
| 740 | + $lesson_id = get_the_ID(); |
|
| 742 | 741 | |
| 743 | - } |
|
| 742 | + } |
|
| 744 | 743 | |
| 745 | - if( empty( $user_id ) ){ |
|
| 744 | + if( empty( $user_id ) ){ |
|
| 746 | 745 | |
| 747 | - $user_id = get_current_user_id(); |
|
| 746 | + $user_id = get_current_user_id(); |
|
| 748 | 747 | |
| 749 | - } |
|
| 748 | + } |
|
| 750 | 749 | |
| 751 | - // Check for prerequisite lesson completions |
|
| 752 | - $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
| 753 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 754 | - $user_taking_course = WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
| 750 | + // Check for prerequisite lesson completions |
|
| 751 | + $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
| 752 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 753 | + $user_taking_course = WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
| 755 | 754 | |
| 756 | - $is_preview = false; |
|
| 757 | - if( WooThemes_Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
| 755 | + $is_preview = false; |
|
| 756 | + if( WooThemes_Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
| 758 | 757 | |
| 759 | - $is_preview = true; |
|
| 760 | - $pre_requisite_complete = true; |
|
| 758 | + $is_preview = true; |
|
| 759 | + $pre_requisite_complete = true; |
|
| 761 | 760 | |
| 762 | - }; |
|
| 761 | + }; |
|
| 763 | 762 | |
| 764 | 763 | |
| 765 | - $user_can_access_lesson = false; |
|
| 764 | + $user_can_access_lesson = false; |
|
| 766 | 765 | |
| 767 | - if( is_user_logged_in() && $user_taking_course ){ |
|
| 766 | + if( is_user_logged_in() && $user_taking_course ){ |
|
| 768 | 767 | |
| 769 | - $user_can_access_lesson = true; |
|
| 768 | + $user_can_access_lesson = true; |
|
| 770 | 769 | |
| 771 | - } |
|
| 770 | + } |
|
| 772 | 771 | |
| 773 | 772 | |
| 774 | - $access_permission = false; |
|
| 773 | + $access_permission = false; |
|
| 775 | 774 | |
| 776 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 775 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 777 | 776 | |
| 778 | - $access_permission = true; |
|
| 777 | + $access_permission = true; |
|
| 779 | 778 | |
| 780 | - } |
|
| 779 | + } |
|
| 781 | 780 | |
| 782 | - $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
| 781 | + $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
| 783 | 782 | |
| 784 | - /** |
|
| 785 | - * Filter the can user view lesson function |
|
| 786 | - * |
|
| 787 | - * @since 1.9.0 |
|
| 788 | - * |
|
| 789 | - * @hooked Sensei_WC::alter_can_user_view_lesson |
|
| 790 | - * |
|
| 791 | - * @param bool $can_user_view_lesson |
|
| 792 | - * @param string $lesson_id |
|
| 793 | - * @param string $user_id |
|
| 794 | - */ |
|
| 795 | - return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
| 783 | + /** |
|
| 784 | + * Filter the can user view lesson function |
|
| 785 | + * |
|
| 786 | + * @since 1.9.0 |
|
| 787 | + * |
|
| 788 | + * @hooked Sensei_WC::alter_can_user_view_lesson |
|
| 789 | + * |
|
| 790 | + * @param bool $can_user_view_lesson |
|
| 791 | + * @param string $lesson_id |
|
| 792 | + * @param string $user_id |
|
| 793 | + */ |
|
| 794 | + return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
| 796 | 795 | |
| 797 | 796 | } // end sensei_can_current_user_view_lesson |
| 798 | 797 | |
@@ -804,52 +803,52 @@ discard block |
||
| 804 | 803 | */ |
| 805 | 804 | function sensei_the_single_lesson_meta(){ |
| 806 | 805 | |
| 807 | - // if the lesson meta is included within theme load that instead of the function content |
|
| 808 | - $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
| 809 | - if( ! empty( $template ) ){ |
|
| 806 | + // if the lesson meta is included within theme load that instead of the function content |
|
| 807 | + $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
| 808 | + if( ! empty( $template ) ){ |
|
| 810 | 809 | |
| 811 | - Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
| 812 | - return; |
|
| 810 | + Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
| 811 | + return; |
|
| 813 | 812 | |
| 814 | - } |
|
| 813 | + } |
|
| 815 | 814 | |
| 816 | - // Get the meta info |
|
| 817 | - $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
| 818 | - $is_preview = WooThemes_Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
| 815 | + // Get the meta info |
|
| 816 | + $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
| 817 | + $is_preview = WooThemes_Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
| 819 | 818 | |
| 820 | - // Get User Meta |
|
| 821 | - get_currentuserinfo(); |
|
| 819 | + // Get User Meta |
|
| 820 | + get_currentuserinfo(); |
|
| 822 | 821 | |
| 823 | - // Complete Lesson Logic |
|
| 824 | - do_action( 'sensei_complete_lesson' ); |
|
| 825 | - // Check that the course has been started |
|
| 826 | - if ( Sensei()->access_settings() |
|
| 827 | - || WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
| 828 | - || $is_preview ) { |
|
| 829 | - ?> |
|
| 822 | + // Complete Lesson Logic |
|
| 823 | + do_action( 'sensei_complete_lesson' ); |
|
| 824 | + // Check that the course has been started |
|
| 825 | + if ( Sensei()->access_settings() |
|
| 826 | + || WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
| 827 | + || $is_preview ) { |
|
| 828 | + ?> |
|
| 830 | 829 | <section class="lesson-meta"> |
| 831 | 830 | <?php |
| 832 | - if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
| 831 | + if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
| 833 | 832 | |
| 834 | - do_action( 'sensei_lesson_video', get_the_ID() ); |
|
| 833 | + do_action( 'sensei_lesson_video', get_the_ID() ); |
|
| 835 | 834 | |
| 836 | - } |
|
| 837 | - ?> |
|
| 835 | + } |
|
| 836 | + ?> |
|
| 838 | 837 | <?php do_action( 'sensei_frontend_messages' ); ?> |
| 839 | 838 | |
| 840 | 839 | <?php if ( ! $is_preview |
| 841 | - || WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
| 840 | + || WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
| 842 | 841 | |
| 843 | - sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
| 842 | + sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
| 844 | 843 | |
| 845 | - } ?> |
|
| 844 | + } ?> |
|
| 846 | 845 | </section> |
| 847 | 846 | |
| 848 | 847 | <?php do_action( 'sensei_lesson_back_link', $lesson_course_id ); ?> |
| 849 | 848 | |
| 850 | 849 | <?php } |
| 851 | 850 | |
| 852 | - do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
| 851 | + do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
| 853 | 852 | |
| 854 | 853 | } // end the_single_lesson_meta |
| 855 | 854 | |
@@ -865,16 +864,16 @@ discard block |
||
| 865 | 864 | */ |
| 866 | 865 | function get_sensei_header(){ |
| 867 | 866 | |
| 868 | - if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 867 | + if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 869 | 868 | |
| 870 | - get_header(); |
|
| 869 | + get_header(); |
|
| 871 | 870 | |
| 872 | - /** |
|
| 873 | - * sensei_before_main_content hook |
|
| 874 | - * |
|
| 875 | - * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
| 876 | - */ |
|
| 877 | - do_action( 'sensei_before_main_content' ); |
|
| 871 | + /** |
|
| 872 | + * sensei_before_main_content hook |
|
| 873 | + * |
|
| 874 | + * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
| 875 | + */ |
|
| 876 | + do_action( 'sensei_before_main_content' ); |
|
| 878 | 877 | |
| 879 | 878 | }// end get_sensei_header |
| 880 | 879 | |
@@ -890,28 +889,28 @@ discard block |
||
| 890 | 889 | */ |
| 891 | 890 | function get_sensei_footer(){ |
| 892 | 891 | |
| 893 | - /** |
|
| 894 | - * sensei_pagination hook |
|
| 895 | - * |
|
| 896 | - * @hooked sensei_pagination - 10 (outputs pagination) |
|
| 897 | - */ |
|
| 898 | - do_action( 'sensei_pagination' ); |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * sensei_after_main_content hook |
|
| 902 | - * |
|
| 903 | - * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
| 904 | - */ |
|
| 905 | - do_action( 'sensei_after_main_content' ); |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * sensei_sidebar hook |
|
| 909 | - * |
|
| 910 | - * @hooked sensei_get_sidebar - 10 |
|
| 911 | - */ |
|
| 912 | - do_action( 'sensei_sidebar' ); |
|
| 913 | - |
|
| 914 | - get_footer(); |
|
| 892 | + /** |
|
| 893 | + * sensei_pagination hook |
|
| 894 | + * |
|
| 895 | + * @hooked sensei_pagination - 10 (outputs pagination) |
|
| 896 | + */ |
|
| 897 | + do_action( 'sensei_pagination' ); |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * sensei_after_main_content hook |
|
| 901 | + * |
|
| 902 | + * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
| 903 | + */ |
|
| 904 | + do_action( 'sensei_after_main_content' ); |
|
| 905 | + |
|
| 906 | + /** |
|
| 907 | + * sensei_sidebar hook |
|
| 908 | + * |
|
| 909 | + * @hooked sensei_get_sidebar - 10 |
|
| 910 | + */ |
|
| 911 | + do_action( 'sensei_sidebar' ); |
|
| 912 | + |
|
| 913 | + get_footer(); |
|
| 915 | 914 | |
| 916 | 915 | }// end get_sensei_header |
| 917 | 916 | |
@@ -923,14 +922,14 @@ discard block |
||
| 923 | 922 | */ |
| 924 | 923 | function the_no_permissions_title(){ |
| 925 | 924 | |
| 926 | - /** |
|
| 927 | - * Filter the no permissions title just before it is echo'd on the |
|
| 928 | - * no-permissions.php file. |
|
| 929 | - * |
|
| 930 | - * @since 1.9.0 |
|
| 931 | - * @param $no_permissions_title |
|
| 932 | - */ |
|
| 933 | - echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
| 925 | + /** |
|
| 926 | + * Filter the no permissions title just before it is echo'd on the |
|
| 927 | + * no-permissions.php file. |
|
| 928 | + * |
|
| 929 | + * @since 1.9.0 |
|
| 930 | + * @param $no_permissions_title |
|
| 931 | + */ |
|
| 932 | + echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
| 934 | 933 | |
| 935 | 934 | } |
| 936 | 935 | |
@@ -941,14 +940,14 @@ discard block |
||
| 941 | 940 | */ |
| 942 | 941 | function the_no_permissions_message( $post_id ){ |
| 943 | 942 | |
| 944 | - /** |
|
| 945 | - * Filter the no permissions message just before it is echo'd on the |
|
| 946 | - * no-permissions.php file. |
|
| 947 | - * |
|
| 948 | - * @since 1.9.0 |
|
| 949 | - * @param $no_permissions_message |
|
| 950 | - */ |
|
| 951 | - echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
| 943 | + /** |
|
| 944 | + * Filter the no permissions message just before it is echo'd on the |
|
| 945 | + * no-permissions.php file. |
|
| 946 | + * |
|
| 947 | + * @since 1.9.0 |
|
| 948 | + * @param $no_permissions_message |
|
| 949 | + */ |
|
| 950 | + echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
| 952 | 951 | |
| 953 | 952 | } |
| 954 | 953 | |
@@ -959,8 +958,8 @@ discard block |
||
| 959 | 958 | */ |
| 960 | 959 | function sensei_the_excerpt( $post_id ){ |
| 961 | 960 | |
| 962 | - global $post; |
|
| 963 | - the_excerpt( $post ); |
|
| 961 | + global $post; |
|
| 962 | + the_excerpt( $post ); |
|
| 964 | 963 | |
| 965 | 964 | } |
| 966 | 965 | |
@@ -974,9 +973,9 @@ discard block |
||
| 974 | 973 | */ |
| 975 | 974 | function sensei_get_current_page_url(){ |
| 976 | 975 | |
| 977 | - global $wp; |
|
| 978 | - $current_page_url = home_url( $wp->request ); |
|
| 979 | - return $current_page_url; |
|
| 976 | + global $wp; |
|
| 977 | + $current_page_url = home_url( $wp->request ); |
|
| 978 | + return $current_page_url; |
|
| 980 | 979 | |
| 981 | 980 | } |
| 982 | 981 | |
@@ -988,7 +987,7 @@ discard block |
||
| 988 | 987 | */ |
| 989 | 988 | function sensei_the_my_courses_content(){ |
| 990 | 989 | |
| 991 | - echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
| 990 | + echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
| 992 | 991 | |
| 993 | 992 | } // sensei_the_my_courses_content |
| 994 | 993 | |
@@ -1003,7 +1002,7 @@ discard block |
||
| 1003 | 1002 | */ |
| 1004 | 1003 | function sensei_load_template( $template_name ){ |
| 1005 | 1004 | |
| 1006 | - Sensei_Templates::get_template( $template_name ); |
|
| 1005 | + Sensei_Templates::get_template( $template_name ); |
|
| 1007 | 1006 | |
| 1008 | 1007 | } |
| 1009 | 1008 | |
@@ -1017,7 +1016,7 @@ discard block |
||
| 1017 | 1016 | */ |
| 1018 | 1017 | function sensei_load_template_part( $slug, $name ){ |
| 1019 | 1018 | |
| 1020 | - Sensei_Templates::get_part( $slug, $name ); |
|
| 1019 | + Sensei_Templates::get_part( $slug, $name ); |
|
| 1021 | 1020 | |
| 1022 | 1021 | } |
| 1023 | 1022 | |
@@ -1036,17 +1035,17 @@ discard block |
||
| 1036 | 1035 | */ |
| 1037 | 1036 | function sensei_the_lesson_excerpt( $lesson_id = '' ) { |
| 1038 | 1037 | |
| 1039 | - if( empty( $lesson_id )){ |
|
| 1038 | + if( empty( $lesson_id )){ |
|
| 1040 | 1039 | |
| 1041 | - $lesson_id = get_the_ID(); |
|
| 1040 | + $lesson_id = get_the_ID(); |
|
| 1042 | 1041 | |
| 1043 | - } |
|
| 1042 | + } |
|
| 1044 | 1043 | |
| 1045 | - if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 1046 | - return; |
|
| 1047 | - } |
|
| 1044 | + if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 1045 | + return; |
|
| 1046 | + } |
|
| 1048 | 1047 | |
| 1049 | - echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
| 1048 | + echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
| 1050 | 1049 | |
| 1051 | 1050 | }// End lesson_excerpt() |
| 1052 | 1051 | |
@@ -1056,16 +1055,16 @@ discard block |
||
| 1056 | 1055 | * @since 1.9.0 |
| 1057 | 1056 | */ |
| 1058 | 1057 | function sensei_the_course_results_lessons(){ |
| 1059 | - // load backwards compatible template name if it exists in the users theme |
|
| 1060 | - $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
| 1061 | - if( $located_template ){ |
|
| 1058 | + // load backwards compatible template name if it exists in the users theme |
|
| 1059 | + $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
| 1060 | + if( $located_template ){ |
|
| 1062 | 1061 | |
| 1063 | - Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
| 1064 | - return; |
|
| 1062 | + Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
| 1063 | + return; |
|
| 1065 | 1064 | |
| 1066 | - } |
|
| 1065 | + } |
|
| 1067 | 1066 | |
| 1068 | - Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
| 1067 | + Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
| 1069 | 1068 | } |
| 1070 | 1069 | |
| 1071 | 1070 | /** |
@@ -1077,6 +1076,6 @@ discard block |
||
| 1077 | 1076 | */ |
| 1078 | 1077 | function sensei_courses_per_row(){ |
| 1079 | 1078 | |
| 1080 | - echo Sensei_Course::get_loop_number_of_columns(); |
|
| 1079 | + echo Sensei_Course::get_loop_number_of_columns(); |
|
| 1081 | 1080 | |
| 1082 | 1081 | } |
@@ -1,26 +1,26 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The Template for displaying all access restriction error messages. |
|
| 4 | - * |
|
| 5 | - * Override this template by copying it to yourtheme/sensei/no-permissions.php |
|
| 6 | - * |
|
| 7 | - * @author Automattic |
|
| 8 | - * @package Sensei |
|
| 9 | - * @category Templates |
|
| 10 | - * @version 1.9.0 |
|
| 11 | - */ |
|
| 3 | + * The Template for displaying all access restriction error messages. |
|
| 4 | + * |
|
| 5 | + * Override this template by copying it to yourtheme/sensei/no-permissions.php |
|
| 6 | + * |
|
| 7 | + * @author Automattic |
|
| 8 | + * @package Sensei |
|
| 9 | + * @category Templates |
|
| 10 | + * @version 1.9.0 |
|
| 11 | + */ |
|
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <?php get_sensei_header(); ?> |
| 15 | 15 | |
| 16 | 16 | <?php |
| 17 | 17 | /** |
| 18 | - * This action fires inside the no-permissions.php file. It |
|
| 19 | - * is place above before all the content. |
|
| 20 | - * |
|
| 21 | - * @since 1.9.0 |
|
| 22 | - * @param $post_id |
|
| 23 | - */ |
|
| 18 | + * This action fires inside the no-permissions.php file. It |
|
| 19 | + * is place above before all the content. |
|
| 20 | + * |
|
| 21 | + * @since 1.9.0 |
|
| 22 | + * @param $post_id |
|
| 23 | + */ |
|
| 24 | 24 | do_action('sensei_no_permissions_before_content', get_the_ID() ); |
| 25 | 25 | ?> |
| 26 | 26 | |
@@ -33,15 +33,15 @@ discard block |
||
| 33 | 33 | </header> |
| 34 | 34 | |
| 35 | 35 | <?php |
| 36 | - /** |
|
| 37 | - * This action fires inside the no-permissions.php file. It |
|
| 38 | - * is place just before the content. |
|
| 39 | - * |
|
| 40 | - * @since 1.9.0 |
|
| 41 | - * @param $post_id |
|
| 42 | - */ |
|
| 43 | - do_action('sensei_no_permissions_inside_before_content', get_the_ID() ); |
|
| 44 | - ?> |
|
| 36 | + /** |
|
| 37 | + * This action fires inside the no-permissions.php file. It |
|
| 38 | + * is place just before the content. |
|
| 39 | + * |
|
| 40 | + * @since 1.9.0 |
|
| 41 | + * @param $post_id |
|
| 42 | + */ |
|
| 43 | + do_action('sensei_no_permissions_inside_before_content', get_the_ID() ); |
|
| 44 | + ?> |
|
| 45 | 45 | |
| 46 | 46 | <section class="entry fix"> |
| 47 | 47 | |
@@ -60,26 +60,26 @@ discard block |
||
| 60 | 60 | </section> |
| 61 | 61 | |
| 62 | 62 | <?php |
| 63 | - /** |
|
| 64 | - * This action fires inside the no-permissions.php file. It |
|
| 65 | - * is place just after the content. |
|
| 66 | - * |
|
| 67 | - * @since 1.9.0 |
|
| 68 | - * @param $post_id |
|
| 69 | - */ |
|
| 70 | - do_action('sensei_no_permissions_inside_after_content', get_the_ID() ); |
|
| 71 | - ?> |
|
| 63 | + /** |
|
| 64 | + * This action fires inside the no-permissions.php file. It |
|
| 65 | + * is place just after the content. |
|
| 66 | + * |
|
| 67 | + * @since 1.9.0 |
|
| 68 | + * @param $post_id |
|
| 69 | + */ |
|
| 70 | + do_action('sensei_no_permissions_inside_after_content', get_the_ID() ); |
|
| 71 | + ?> |
|
| 72 | 72 | |
| 73 | 73 | </article><!-- .no-permissions --> |
| 74 | 74 | |
| 75 | 75 | <?php |
| 76 | 76 | /** |
| 77 | - * This action fires inside the no-permissions.php file. It |
|
| 78 | - * is placed outside after the content. |
|
| 79 | - * |
|
| 80 | - * @since 1.9.0 |
|
| 81 | - * @param $post_id |
|
| 82 | - */ |
|
| 77 | + * This action fires inside the no-permissions.php file. It |
|
| 78 | + * is placed outside after the content. |
|
| 79 | + * |
|
| 80 | + * @since 1.9.0 |
|
| 81 | + * @param $post_id |
|
| 82 | + */ |
|
| 83 | 83 | do_action('sensei_no_permissions_after_content', get_the_ID() ); |
| 84 | 84 | ?> |
| 85 | 85 | |