@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | 3 | /** |
| 4 | - * The Template for displaying all course lessons on the course results page. |
|
| 5 | - * |
|
| 6 | - * Override this template by copying it to yourtheme/sensei/course-results/course-lessons.php |
|
| 7 | - * |
|
| 8 | - * @author Automattic |
|
| 9 | - * @package Sensei |
|
| 10 | - * @category Templates |
|
| 11 | - * @version 1.9.0 |
|
| 12 | - */ |
|
| 4 | + * The Template for displaying all course lessons on the course results page. |
|
| 5 | + * |
|
| 6 | + * Override this template by copying it to yourtheme/sensei/course-results/course-lessons.php |
|
| 7 | + * |
|
| 8 | + * @author Automattic |
|
| 9 | + * @package Sensei |
|
| 10 | + * @category Templates |
|
| 11 | + * @version 1.9.0 |
|
| 12 | + */ |
|
| 13 | 13 | |
| 14 | 14 | global $course; |
| 15 | 15 | ?> |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | <?php if ( is_user_logged_in() ): ?> |
| 18 | 18 | |
| 19 | 19 | <?php |
| 20 | - /** |
|
| 21 | - * Fires inside course-results/lessons.php after the |
|
| 22 | - * is uer logged check, just above the lessons header. |
|
| 23 | - * @since 1.4.0 |
|
| 24 | - */ |
|
| 25 | - do_action( 'sensei_course_results_before_lessons', $course->ID ); |
|
| 26 | - ?> |
|
| 20 | + /** |
|
| 21 | + * Fires inside course-results/lessons.php after the |
|
| 22 | + * is uer logged check, just above the lessons header. |
|
| 23 | + * @since 1.4.0 |
|
| 24 | + */ |
|
| 25 | + do_action( 'sensei_course_results_before_lessons', $course->ID ); |
|
| 26 | + ?> |
|
| 27 | 27 | |
| 28 | 28 | <header> |
| 29 | 29 | |
@@ -36,33 +36,33 @@ discard block |
||
| 36 | 36 | <?php |
| 37 | 37 | |
| 38 | 38 | $displayed_lessons = array(); |
| 39 | - $modules = Sensei()->modules->get_course_modules( intval( $course->ID ) ); |
|
| 39 | + $modules = Sensei()->modules->get_course_modules( intval( $course->ID ) ); |
|
| 40 | 40 | |
| 41 | - // List modules with lessons |
|
| 42 | - foreach( $modules as $module ) { |
|
| 41 | + // List modules with lessons |
|
| 42 | + foreach( $modules as $module ) { |
|
| 43 | 43 | |
| 44 | - $lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id ); |
|
| 45 | - $lessons = $lessons_query->get_posts(); |
|
| 44 | + $lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id ); |
|
| 45 | + $lessons = $lessons_query->get_posts(); |
|
| 46 | 46 | |
| 47 | - if( count( $lessons ) > 0 ) { ?> |
|
| 47 | + if( count( $lessons ) > 0 ) { ?> |
|
| 48 | 48 | |
| 49 | 49 | <h3> <?php echo $module->name; ?></h3> |
| 50 | 50 | |
| 51 | 51 | <?php |
| 52 | - $count = 0; |
|
| 53 | - foreach( $lessons as $lesson ) { |
|
| 54 | - |
|
| 55 | - $lesson_grade = 'n/a'; |
|
| 56 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 57 | - if ( $has_questions ) { |
|
| 58 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() ); |
|
| 59 | - // Get user quiz grade |
|
| 60 | - $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 61 | - if ( $lesson_grade ) { |
|
| 62 | - $lesson_grade .= '%'; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - ?> |
|
| 52 | + $count = 0; |
|
| 53 | + foreach( $lessons as $lesson ) { |
|
| 54 | + |
|
| 55 | + $lesson_grade = 'n/a'; |
|
| 56 | + $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 57 | + if ( $has_questions ) { |
|
| 58 | + $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() ); |
|
| 59 | + // Get user quiz grade |
|
| 60 | + $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 61 | + if ( $lesson_grade ) { |
|
| 62 | + $lesson_grade .= '%'; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + ?> |
|
| 66 | 66 | <h2> |
| 67 | 67 | |
| 68 | 68 | <a href="<?php esc_url_raw( get_permalink( $lesson->ID ) ); ?>" |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | <?php |
| 82 | 82 | |
| 83 | - }// end for each |
|
| 83 | + }// end for each |
|
| 84 | 84 | |
| 85 | - }// end if count lesson |
|
| 85 | + }// end if count lesson |
|
| 86 | 86 | |
| 87 | - } // end for each module |
|
| 88 | - ?> |
|
| 87 | + } // end for each module |
|
| 88 | + ?> |
|
| 89 | 89 | |
| 90 | 90 | <?php |
| 91 | 91 | |
| 92 | - $lessons = Sensei()->modules->get_none_module_lessons( $course->ID ); |
|
| 93 | - if( 0 < count( $lessons ) ): ?> |
|
| 92 | + $lessons = Sensei()->modules->get_none_module_lessons( $course->ID ); |
|
| 93 | + if( 0 < count( $lessons ) ): ?> |
|
| 94 | 94 | |
| 95 | 95 | <h3> |
| 96 | 96 | |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | <?php foreach ( $lessons as $lesson ): ?> |
| 102 | 102 | |
| 103 | 103 | <?php |
| 104 | - $lesson_grade = 'n/a'; |
|
| 105 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 106 | - if ( $has_questions ) { |
|
| 107 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id()); |
|
| 108 | - // Get user quiz grade |
|
| 109 | - $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 110 | - if ( $lesson_grade ) { |
|
| 111 | - $lesson_grade .= '%'; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - ?> |
|
| 104 | + $lesson_grade = 'n/a'; |
|
| 105 | + $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 106 | + if ( $has_questions ) { |
|
| 107 | + $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id()); |
|
| 108 | + // Get user quiz grade |
|
| 109 | + $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 110 | + if ( $lesson_grade ) { |
|
| 111 | + $lesson_grade .= '%'; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + ?> |
|
| 115 | 115 | |
| 116 | 116 | <h2> |
| 117 | 117 | |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | <?php |
| 139 | 139 | |
| 140 | - $course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() ); |
|
| 141 | - echo $course_user_grade . '%'; |
|
| 140 | + $course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() ); |
|
| 141 | + echo $course_user_grade . '%'; |
|
| 142 | 142 | |
| 143 | - ?> |
|
| 143 | + ?> |
|
| 144 | 144 | |
| 145 | 145 | </span> |
| 146 | 146 | |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | </article> |
| 150 | 150 | |
| 151 | 151 | <?php |
| 152 | - /** |
|
| 153 | - * Fires inside course-results/lessons.php after the |
|
| 154 | - * is uer logged check, at the bottom of all lessons. |
|
| 155 | - * |
|
| 156 | - * @since 1.4.0 |
|
| 157 | - */ |
|
| 152 | + /** |
|
| 153 | + * Fires inside course-results/lessons.php after the |
|
| 154 | + * is uer logged check, at the bottom of all lessons. |
|
| 155 | + * |
|
| 156 | + * @since 1.4.0 |
|
| 157 | + */ |
|
| 158 | 158 | do_action( 'sensei_course_results_after_lessons', $course->ID ); |
| 159 | - ?> |
|
| 159 | + ?> |
|
| 160 | 160 | |
| 161 | 161 | <?php endif; //user logged in ?> |
| 162 | 162 | \ No newline at end of file |
@@ -9,24 +9,24 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | Class Sensei_Twentythirteen { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Output opening wrappers |
|
| 14 | - * @since 1.9.0 |
|
| 15 | - */ |
|
| 16 | - public function wrapper_start(){ |
|
| 17 | - ?> |
|
| 12 | + /** |
|
| 13 | + * Output opening wrappers |
|
| 14 | + * @since 1.9.0 |
|
| 15 | + */ |
|
| 16 | + public function wrapper_start(){ |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div id="primary" class="site-content"> |
| 20 | 20 | <div id="content" role="main" class="entry-content"> |
| 21 | 21 | |
| 22 | 22 | <?php } |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Output closing wrappers |
|
| 26 | - * |
|
| 27 | - * @since 1.9.0 |
|
| 28 | - */ |
|
| 29 | - public function wrapper_end(){ ?> |
|
| 24 | + /** |
|
| 25 | + * Output closing wrappers |
|
| 26 | + * |
|
| 27 | + * @since 1.9.0 |
|
| 28 | + */ |
|
| 29 | + public function wrapper_end(){ ?> |
|
| 30 | 30 | |
| 31 | 31 | </div> |
| 32 | 32 | </div> |
@@ -16,28 +16,28 @@ discard block |
||
| 16 | 16 | class Sensei_Notices{ |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * @var $notices |
|
| 20 | - */ |
|
| 19 | + * @var $notices |
|
| 20 | + */ |
|
| 21 | 21 | protected $notices; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * constructor |
|
| 25 | - */ |
|
| 24 | + * constructor |
|
| 25 | + */ |
|
| 26 | 26 | public function __construct(){ |
| 27 | 27 | //initialize the notices variable |
| 28 | 28 | $this->notices = array(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Add a notice to the array of notices for display at a later stage. |
|
| 33 | - * |
|
| 34 | - * |
|
| 35 | - * |
|
| 36 | - * @param string $message |
|
| 37 | - * @param string $type defaults to alert options( alert, tick , download , info ) |
|
| 38 | - * |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 32 | + * Add a notice to the array of notices for display at a later stage. |
|
| 33 | + * |
|
| 34 | + * |
|
| 35 | + * |
|
| 36 | + * @param string $message |
|
| 37 | + * @param string $type defaults to alert options( alert, tick , download , info ) |
|
| 38 | + * |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | 42 | public function add_notice( $content , $type = 'alert' ){ |
| 43 | 43 | // append the new notice |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | } // end add_notice() |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Output all notices added |
|
| 49 | - * |
|
| 50 | - * @param string $message |
|
| 51 | - * @param string $type |
|
| 52 | - * |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 48 | + * Output all notices added |
|
| 49 | + * |
|
| 50 | + * @param string $message |
|
| 51 | + * @param string $type |
|
| 52 | + * |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | 55 | |
| 56 | 56 | public function print_notices(){ |
| 57 | 57 | if( count( $this->notices ) > 0 ){ |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | } // end print_notice() |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Clear all notices |
|
| 72 | - * |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 71 | + * Clear all notices |
|
| 72 | + * |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | 75 | |
| 76 | 76 | public function clear_notices(){ |
| 77 | 77 | // assign an empty array to clear all existing notices |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | function sensei_all_access() { |
| 47 | 47 | |
| 48 | - $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Filter sensei_all_access function result |
|
| 52 | - * which determinse if the current user |
|
| 53 | - * can access all of Sensei without restrictions |
|
| 54 | - * |
|
| 55 | - * @since 1.4.0 |
|
| 56 | - * @param bool $access |
|
| 57 | - */ |
|
| 48 | + $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Filter sensei_all_access function result |
|
| 52 | + * which determinse if the current user |
|
| 53 | + * can access all of Sensei without restrictions |
|
| 54 | + * |
|
| 55 | + * @since 1.4.0 |
|
| 56 | + * @param bool $access |
|
| 57 | + */ |
|
| 58 | 58 | return apply_filters( 'sensei_all_access', $access ); |
| 59 | 59 | |
| 60 | 60 | } // End sensei_all_access() |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
| 74 | 74 | |
| 75 | - $hex = str_replace( '#', '', $color ); |
|
| 75 | + $hex = str_replace( '#', '', $color ); |
|
| 76 | 76 | |
| 77 | 77 | $c_r = hexdec( substr( $hex, 0, 2 ) ); |
| 78 | 78 | $c_g = hexdec( substr( $hex, 2, 2 ) ); |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | $color = '#'; |
| 120 | 120 | |
| 121 | 121 | foreach ($base as $k => $v) : |
| 122 | - $amount = $v / 100; |
|
| 123 | - $amount = round($amount * $factor); |
|
| 124 | - $new_decimal = $v - $amount; |
|
| 125 | - |
|
| 126 | - $new_hex_component = dechex($new_decimal); |
|
| 127 | - if(strlen($new_hex_component) < 2) : |
|
| 128 | - $new_hex_component = "0".$new_hex_component; |
|
| 129 | - endif; |
|
| 130 | - $color .= $new_hex_component; |
|
| 122 | + $amount = $v / 100; |
|
| 123 | + $amount = round($amount * $factor); |
|
| 124 | + $new_decimal = $v - $amount; |
|
| 125 | + |
|
| 126 | + $new_hex_component = dechex($new_decimal); |
|
| 127 | + if(strlen($new_hex_component) < 2) : |
|
| 128 | + $new_hex_component = "0".$new_hex_component; |
|
| 129 | + endif; |
|
| 130 | + $color .= $new_hex_component; |
|
| 131 | 131 | endforeach; |
| 132 | 132 | |
| 133 | 133 | return $color; |
@@ -148,17 +148,17 @@ discard block |
||
| 148 | 148 | $base = sensei_rgb_from_hex( $color ); |
| 149 | 149 | $color = '#'; |
| 150 | 150 | |
| 151 | - foreach ($base as $k => $v) : |
|
| 152 | - $amount = 255 - $v; |
|
| 153 | - $amount = $amount / 100; |
|
| 154 | - $amount = round($amount * $factor); |
|
| 155 | - $new_decimal = $v + $amount; |
|
| 156 | - |
|
| 157 | - $new_hex_component = dechex($new_decimal); |
|
| 158 | - if(strlen($new_hex_component) < 2) : |
|
| 159 | - $new_hex_component = "0".$new_hex_component; |
|
| 160 | - endif; |
|
| 161 | - $color .= $new_hex_component; |
|
| 151 | + foreach ($base as $k => $v) : |
|
| 152 | + $amount = 255 - $v; |
|
| 153 | + $amount = $amount / 100; |
|
| 154 | + $amount = round($amount * $factor); |
|
| 155 | + $new_decimal = $v + $amount; |
|
| 156 | + |
|
| 157 | + $new_hex_component = dechex($new_decimal); |
|
| 158 | + if(strlen($new_hex_component) < 2) : |
|
| 159 | + $new_hex_component = "0".$new_hex_component; |
|
| 160 | + endif; |
|
| 161 | + $color .= $new_hex_component; |
|
| 162 | 162 | endforeach; |
| 163 | 163 | |
| 164 | 164 | return $color; |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active() |
| 173 | 173 | */ |
| 174 | 174 | if ( ! function_exists( 'is_woocommerce_active' ) ) { |
| 175 | - function is_woocommerce_active() { |
|
| 176 | - // calling is present instead of is active here |
|
| 177 | - // as this function can override other is_woocommerce_active |
|
| 178 | - // function in other woo plugins and Sensei_WC::is_woocommerce_active |
|
| 179 | - // also check the sensei settings for enable WooCommerce support, which |
|
| 180 | - // other plugins should not check against. |
|
| 181 | - return Sensei_WC::is_woocommerce_present(); |
|
| 182 | - } |
|
| 175 | + function is_woocommerce_active() { |
|
| 176 | + // calling is present instead of is active here |
|
| 177 | + // as this function can override other is_woocommerce_active |
|
| 178 | + // function in other woo plugins and Sensei_WC::is_woocommerce_active |
|
| 179 | + // also check the sensei settings for enable WooCommerce support, which |
|
| 180 | + // other plugins should not check against. |
|
| 181 | + return Sensei_WC::is_woocommerce_present(); |
|
| 182 | + } |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,20 +195,20 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array() ){ |
| 197 | 197 | |
| 198 | - if( has_action( $hook_tag ) ){ |
|
| 198 | + if( has_action( $hook_tag ) ){ |
|
| 199 | 199 | |
| 200 | - $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
|
| 200 | + $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
|
| 201 | 201 | |
| 202 | - if( !empty( $alternative ) ){ |
|
| 202 | + if( !empty( $alternative ) ){ |
|
| 203 | 203 | |
| 204 | - $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
|
| 204 | + $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - trigger_error( $error_message ); |
|
| 209 | - do_action( $hook_tag , $args ); |
|
| 208 | + trigger_error( $error_message ); |
|
| 209 | + do_action( $hook_tag , $args ); |
|
| 210 | 210 | |
| 211 | - } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | 213 | }// end sensei_do_deprecated_action |
| 214 | 214 | |
@@ -238,18 +238,18 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | function sensei_user_login_url(){ |
| 240 | 240 | |
| 241 | - $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); |
|
| 242 | - $page = get_post( $my_courses_page_id ); |
|
| 241 | + $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); |
|
| 242 | + $page = get_post( $my_courses_page_id ); |
|
| 243 | 243 | |
| 244 | - if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID ) ){ |
|
| 244 | + if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID ) ){ |
|
| 245 | 245 | |
| 246 | - return get_permalink( $page->ID ); |
|
| 246 | + return get_permalink( $page->ID ); |
|
| 247 | 247 | |
| 248 | - } else { |
|
| 248 | + } else { |
|
| 249 | 249 | |
| 250 | - return wp_login_url(); |
|
| 250 | + return wp_login_url(); |
|
| 251 | 251 | |
| 252 | - } |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | 254 | }// end sensei_user_login_link |
| 255 | 255 | |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | function sensei_is_login_required(){ |
| 264 | 264 | |
| 265 | - $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); |
|
| 265 | + $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); |
|
| 266 | 266 | |
| 267 | - return $login_required; |
|
| 267 | + return $login_required; |
|
| 268 | 268 | |
| 269 | 269 | } |
| 270 | 270 | \ No newline at end of file |
@@ -15,172 +15,172 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Sensei_Shortcode_Loader{ |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var array { |
|
| 20 | - * type string $shortcode |
|
| 21 | - * type Sensei_Shortcode |
|
| 22 | - * } all the shortcodes and which class to instantiate when they are called from |
|
| 23 | - * WordPress's do_shortcode() function. |
|
| 24 | - * |
|
| 25 | - */ |
|
| 26 | - protected $shortcode_classes; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Run all the functions that needs to be hooked into WordPress |
|
| 30 | - * |
|
| 31 | - * @since 1.9.0 |
|
| 32 | - */ |
|
| 33 | - public function __construct(){ |
|
| 34 | - |
|
| 35 | - // create a list of shortcodes and the class that handles them |
|
| 36 | - $this->setup_shortcode_class_map(); |
|
| 37 | - |
|
| 38 | - // setup all the shortcodes and load the listener into WP |
|
| 39 | - $this->initialize_shortcodes(); |
|
| 40 | - |
|
| 41 | - // add sensei body class for shortcodes |
|
| 42 | - add_filter( 'body_class', array( $this, 'possibly_add_body_class' )); |
|
| 43 | - |
|
| 44 | - // array( $this, 'add_body_class') |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Array of shortcode classes that should be instantiated when WordPress loads |
|
| 50 | - * a Sensei specific shortcode. |
|
| 51 | - * This list contains: |
|
| 52 | - * $shortcode => $class_name |
|
| 53 | - * |
|
| 54 | - * $shortcode is the actual shortcode the user will add to the editor |
|
| 55 | - * $class_name is the name of the class that will be instantiated to handle |
|
| 56 | - * the rendering of the shortcode. |
|
| 57 | - * |
|
| 58 | - * NOTE: When adding a new shortcode here be sure to load your shortcodes class |
|
| 59 | - * in class-sensei-autoloader class_file_map function |
|
| 60 | - */ |
|
| 61 | - public function setup_shortcode_class_map(){ |
|
| 62 | - |
|
| 63 | - $this->shortcode_classes = array( |
|
| 64 | - 'sensei_featured_courses' => 'Sensei_Shortcode_Featured_Courses', |
|
| 65 | - 'sensei_user_courses' => 'Sensei_Shortcode_User_Courses', |
|
| 66 | - 'sensei_courses' => 'Sensei_Shortcode_Courses', |
|
| 67 | - 'sensei_teachers' => 'Sensei_Shortcode_Teachers', |
|
| 68 | - 'sensei_user_messages' => 'Sensei_Shortcode_User_Messages', |
|
| 69 | - 'sensei_course_page' => 'Sensei_Shortcode_Course_Page', |
|
| 70 | - 'sensei_lesson_page' => 'Sensei_Shortcode_Lesson_Page', |
|
| 71 | - 'sensei_course_categories' => 'Sensei_Shortcode_Course_Categories', |
|
| 72 | - 'sensei_unpurchased_courses' => 'Sensei_Shortcode_Unpurchased_Courses', |
|
| 73 | - ); |
|
| 74 | - |
|
| 75 | - // legacy shortcode handling: |
|
| 76 | - Sensei_Legacy_Shortcodes::init(); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Add all shortcodes here |
|
| 82 | - * |
|
| 83 | - * This function adds shortcodes to WP that links to other functionality. |
|
| 84 | - * @since 1.9.0 |
|
| 85 | - */ |
|
| 86 | - public function initialize_shortcodes(){ |
|
| 87 | - |
|
| 88 | - // shortcodes should only respond to front end calls |
|
| 89 | - if( is_admin() || defined( 'DOING_AJAX' ) ){ |
|
| 90 | - return; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Tell WP to run this classes load_shortcode function for all the |
|
| 95 | - * shortcodes registered here in. |
|
| 96 | - * |
|
| 97 | - * With this method we only load shortcode classes when we need them. |
|
| 98 | - */ |
|
| 99 | - foreach( $this->shortcode_classes as $shortcode => $class ){ |
|
| 100 | - |
|
| 101 | - // all Sensei shortcodes are rendered by this loader class |
|
| 102 | - // it acts as an interface between wp and the shortcodes registered |
|
| 103 | - // above |
|
| 104 | - add_shortcode( $shortcode, array( $this,'render_shortcode' ) ); |
|
| 105 | - |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Respond to WordPress do_shortcode calls |
|
| 112 | - * for shortcodes registered in the initialize_shortcodes function. |
|
| 113 | - * |
|
| 114 | - * @since 1.9.0 |
|
| 115 | - * |
|
| 116 | - * @param $attributes |
|
| 117 | - * @param $content |
|
| 118 | - * @param $code the shortcode that is being requested |
|
| 119 | - * |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function render_shortcode( $attributes='', $content='', $code ){ |
|
| 123 | - |
|
| 124 | - // only respond if the shortcode that we've added shortcode |
|
| 125 | - // classes for. |
|
| 126 | - if( ! isset( $this->shortcode_classes[ $code ] ) ){ |
|
| 127 | - return ''; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // create an instances of the current requested shortcode |
|
| 131 | - $shortcode_handling_class = $this->shortcode_classes[ $code ]; |
|
| 132 | - $shortcode = new $shortcode_handling_class( $attributes, $content, $code ); |
|
| 133 | - |
|
| 134 | - // we expect the sensei class instantiated to implement the Sensei_Shortcode interface |
|
| 135 | - if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){ |
|
| 136 | - |
|
| 137 | - $message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface"; |
|
| 138 | - _doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' ); |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $shortcode->render(); |
|
| 143 | - |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Add the Sensei body class if |
|
| 148 | - * the current page has a Sensei shortcode. |
|
| 149 | - * |
|
| 150 | - * Note: legacy shortcodes not supported here. |
|
| 151 | - * |
|
| 152 | - * @since 1.9.0 |
|
| 153 | - * |
|
| 154 | - * @param array $classes |
|
| 155 | - * @return array |
|
| 156 | - */ |
|
| 157 | - public function possibly_add_body_class ( $classes ) { |
|
| 158 | - |
|
| 159 | - global $post; |
|
| 160 | - |
|
| 161 | - $has_sensei_shortcode = false; |
|
| 162 | - |
|
| 163 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
| 164 | - |
|
| 165 | - // check all registered Sensei shortcodes (not legacy shortcodes) |
|
| 166 | - foreach ( $this->shortcode_classes as $shortcode => $class ){ |
|
| 167 | - |
|
| 168 | - if ( has_shortcode( $post->post_content, $shortcode ) ) { |
|
| 18 | + /** |
|
| 19 | + * @var array { |
|
| 20 | + * type string $shortcode |
|
| 21 | + * type Sensei_Shortcode |
|
| 22 | + * } all the shortcodes and which class to instantiate when they are called from |
|
| 23 | + * WordPress's do_shortcode() function. |
|
| 24 | + * |
|
| 25 | + */ |
|
| 26 | + protected $shortcode_classes; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Run all the functions that needs to be hooked into WordPress |
|
| 30 | + * |
|
| 31 | + * @since 1.9.0 |
|
| 32 | + */ |
|
| 33 | + public function __construct(){ |
|
| 34 | + |
|
| 35 | + // create a list of shortcodes and the class that handles them |
|
| 36 | + $this->setup_shortcode_class_map(); |
|
| 37 | + |
|
| 38 | + // setup all the shortcodes and load the listener into WP |
|
| 39 | + $this->initialize_shortcodes(); |
|
| 40 | + |
|
| 41 | + // add sensei body class for shortcodes |
|
| 42 | + add_filter( 'body_class', array( $this, 'possibly_add_body_class' )); |
|
| 43 | + |
|
| 44 | + // array( $this, 'add_body_class') |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Array of shortcode classes that should be instantiated when WordPress loads |
|
| 50 | + * a Sensei specific shortcode. |
|
| 51 | + * This list contains: |
|
| 52 | + * $shortcode => $class_name |
|
| 53 | + * |
|
| 54 | + * $shortcode is the actual shortcode the user will add to the editor |
|
| 55 | + * $class_name is the name of the class that will be instantiated to handle |
|
| 56 | + * the rendering of the shortcode. |
|
| 57 | + * |
|
| 58 | + * NOTE: When adding a new shortcode here be sure to load your shortcodes class |
|
| 59 | + * in class-sensei-autoloader class_file_map function |
|
| 60 | + */ |
|
| 61 | + public function setup_shortcode_class_map(){ |
|
| 62 | + |
|
| 63 | + $this->shortcode_classes = array( |
|
| 64 | + 'sensei_featured_courses' => 'Sensei_Shortcode_Featured_Courses', |
|
| 65 | + 'sensei_user_courses' => 'Sensei_Shortcode_User_Courses', |
|
| 66 | + 'sensei_courses' => 'Sensei_Shortcode_Courses', |
|
| 67 | + 'sensei_teachers' => 'Sensei_Shortcode_Teachers', |
|
| 68 | + 'sensei_user_messages' => 'Sensei_Shortcode_User_Messages', |
|
| 69 | + 'sensei_course_page' => 'Sensei_Shortcode_Course_Page', |
|
| 70 | + 'sensei_lesson_page' => 'Sensei_Shortcode_Lesson_Page', |
|
| 71 | + 'sensei_course_categories' => 'Sensei_Shortcode_Course_Categories', |
|
| 72 | + 'sensei_unpurchased_courses' => 'Sensei_Shortcode_Unpurchased_Courses', |
|
| 73 | + ); |
|
| 74 | + |
|
| 75 | + // legacy shortcode handling: |
|
| 76 | + Sensei_Legacy_Shortcodes::init(); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Add all shortcodes here |
|
| 82 | + * |
|
| 83 | + * This function adds shortcodes to WP that links to other functionality. |
|
| 84 | + * @since 1.9.0 |
|
| 85 | + */ |
|
| 86 | + public function initialize_shortcodes(){ |
|
| 87 | + |
|
| 88 | + // shortcodes should only respond to front end calls |
|
| 89 | + if( is_admin() || defined( 'DOING_AJAX' ) ){ |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Tell WP to run this classes load_shortcode function for all the |
|
| 95 | + * shortcodes registered here in. |
|
| 96 | + * |
|
| 97 | + * With this method we only load shortcode classes when we need them. |
|
| 98 | + */ |
|
| 99 | + foreach( $this->shortcode_classes as $shortcode => $class ){ |
|
| 100 | + |
|
| 101 | + // all Sensei shortcodes are rendered by this loader class |
|
| 102 | + // it acts as an interface between wp and the shortcodes registered |
|
| 103 | + // above |
|
| 104 | + add_shortcode( $shortcode, array( $this,'render_shortcode' ) ); |
|
| 105 | + |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Respond to WordPress do_shortcode calls |
|
| 112 | + * for shortcodes registered in the initialize_shortcodes function. |
|
| 113 | + * |
|
| 114 | + * @since 1.9.0 |
|
| 115 | + * |
|
| 116 | + * @param $attributes |
|
| 117 | + * @param $content |
|
| 118 | + * @param $code the shortcode that is being requested |
|
| 119 | + * |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function render_shortcode( $attributes='', $content='', $code ){ |
|
| 123 | + |
|
| 124 | + // only respond if the shortcode that we've added shortcode |
|
| 125 | + // classes for. |
|
| 126 | + if( ! isset( $this->shortcode_classes[ $code ] ) ){ |
|
| 127 | + return ''; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // create an instances of the current requested shortcode |
|
| 131 | + $shortcode_handling_class = $this->shortcode_classes[ $code ]; |
|
| 132 | + $shortcode = new $shortcode_handling_class( $attributes, $content, $code ); |
|
| 133 | + |
|
| 134 | + // we expect the sensei class instantiated to implement the Sensei_Shortcode interface |
|
| 135 | + if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){ |
|
| 136 | + |
|
| 137 | + $message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface"; |
|
| 138 | + _doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' ); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $shortcode->render(); |
|
| 143 | + |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Add the Sensei body class if |
|
| 148 | + * the current page has a Sensei shortcode. |
|
| 149 | + * |
|
| 150 | + * Note: legacy shortcodes not supported here. |
|
| 151 | + * |
|
| 152 | + * @since 1.9.0 |
|
| 153 | + * |
|
| 154 | + * @param array $classes |
|
| 155 | + * @return array |
|
| 156 | + */ |
|
| 157 | + public function possibly_add_body_class ( $classes ) { |
|
| 158 | + |
|
| 159 | + global $post; |
|
| 160 | + |
|
| 161 | + $has_sensei_shortcode = false; |
|
| 162 | + |
|
| 163 | + if ( is_a( $post, 'WP_Post' ) ) { |
|
| 164 | + |
|
| 165 | + // check all registered Sensei shortcodes (not legacy shortcodes) |
|
| 166 | + foreach ( $this->shortcode_classes as $shortcode => $class ){ |
|
| 167 | + |
|
| 168 | + if ( has_shortcode( $post->post_content, $shortcode ) ) { |
|
| 169 | 169 | |
| 170 | - $has_sensei_shortcode = true; |
|
| 171 | - } |
|
| 170 | + $has_sensei_shortcode = true; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - } |
|
| 174 | - } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - if( $has_sensei_shortcode ) { |
|
| 177 | - $classes[] = 'sensei' ; |
|
| 178 | - } |
|
| 176 | + if( $has_sensei_shortcode ) { |
|
| 177 | + $classes[] = 'sensei' ; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | |
| 181 | - return $classes; |
|
| 182 | - |
|
| 183 | - } |
|
| 181 | + return $classes; |
|
| 182 | + |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | 185 | } // end class Sensei_Shortcodes |
| 186 | 186 | new Sensei_Shortcode_Loader(); |
@@ -14,148 +14,148 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 19 | - */ |
|
| 20 | - protected $query; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var string number of items to show on the current page |
|
| 24 | - * Default: all. |
|
| 25 | - */ |
|
| 26 | - protected $number; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string ordery by course field |
|
| 30 | - * Default: date |
|
| 31 | - */ |
|
| 32 | - protected $orderby; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string ASC or DESC |
|
| 36 | - * Default: 'DESC' |
|
| 37 | - */ |
|
| 38 | - protected $order; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Setup the shortcode object |
|
| 42 | - * |
|
| 43 | - * @since 1.9.0 |
|
| 44 | - * @param array $attributes |
|
| 45 | - * @param string $content |
|
| 46 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 47 | - */ |
|
| 48 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 49 | - |
|
| 50 | - // set up all argument need for constructing the course query |
|
| 51 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 52 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 53 | - |
|
| 54 | - // set the default for menu_order to be ASC |
|
| 55 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 56 | - |
|
| 57 | - $this->order = 'ASC'; |
|
| 17 | + /** |
|
| 18 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 19 | + */ |
|
| 20 | + protected $query; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var string number of items to show on the current page |
|
| 24 | + * Default: all. |
|
| 25 | + */ |
|
| 26 | + protected $number; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string ordery by course field |
|
| 30 | + * Default: date |
|
| 31 | + */ |
|
| 32 | + protected $orderby; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string ASC or DESC |
|
| 36 | + * Default: 'DESC' |
|
| 37 | + */ |
|
| 38 | + protected $order; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Setup the shortcode object |
|
| 42 | + * |
|
| 43 | + * @since 1.9.0 |
|
| 44 | + * @param array $attributes |
|
| 45 | + * @param string $content |
|
| 46 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 47 | + */ |
|
| 48 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 49 | + |
|
| 50 | + // set up all argument need for constructing the course query |
|
| 51 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 52 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 53 | + |
|
| 54 | + // set the default for menu_order to be ASC |
|
| 55 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 56 | + |
|
| 57 | + $this->order = 'ASC'; |
|
| 58 | 58 | |
| 59 | - }else{ |
|
| 59 | + }else{ |
|
| 60 | 60 | |
| 61 | - // for everything else use the value passed or the default DESC |
|
| 62 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 61 | + // for everything else use the value passed or the default DESC |
|
| 62 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 63 | 63 | |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - // setup the course query that will be used when rendering |
|
| 67 | - $this->setup_course_query(); |
|
| 68 | - } |
|
| 66 | + // setup the course query that will be used when rendering |
|
| 67 | + $this->setup_course_query(); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Sets up the object course query |
|
| 72 | - * that will be used int he render method. |
|
| 73 | - * |
|
| 74 | - * @since 1.9.0 |
|
| 75 | - */ |
|
| 76 | - protected function setup_course_query(){ |
|
| 70 | + /** |
|
| 71 | + * Sets up the object course query |
|
| 72 | + * that will be used int he render method. |
|
| 73 | + * |
|
| 74 | + * @since 1.9.0 |
|
| 75 | + */ |
|
| 76 | + protected function setup_course_query(){ |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - // course query parameters to be used for all courses |
|
| 80 | - $query_args = array( |
|
| 81 | - 'post_type' => 'course', |
|
| 82 | - 'post_status' => 'publish', |
|
| 83 | - // the number specified by the user will be used later in this function |
|
| 84 | - 'posts_per_page' => 1000, |
|
| 85 | - 'orderby' => $this->orderby, |
|
| 86 | - 'order' => $this->order |
|
| 87 | - ); |
|
| 79 | + // course query parameters to be used for all courses |
|
| 80 | + $query_args = array( |
|
| 81 | + 'post_type' => 'course', |
|
| 82 | + 'post_status' => 'publish', |
|
| 83 | + // the number specified by the user will be used later in this function |
|
| 84 | + 'posts_per_page' => 1000, |
|
| 85 | + 'orderby' => $this->orderby, |
|
| 86 | + 'order' => $this->order |
|
| 87 | + ); |
|
| 88 | 88 | |
| 89 | - // get all the courses that has a product attached |
|
| 90 | - $all_courses_query = new WP_Query( $query_args ); |
|
| 89 | + // get all the courses that has a product attached |
|
| 90 | + $all_courses_query = new WP_Query( $query_args ); |
|
| 91 | 91 | |
| 92 | - $paid_courses_not_taken = array(); |
|
| 93 | - // look through all course and find the purchasable ones that user has not purchased |
|
| 94 | - foreach( $all_courses_query->posts as $course ){ |
|
| 92 | + $paid_courses_not_taken = array(); |
|
| 93 | + // look through all course and find the purchasable ones that user has not purchased |
|
| 94 | + foreach( $all_courses_query->posts as $course ){ |
|
| 95 | 95 | |
| 96 | - // only keep the courses with a product including only courses that the user not taking |
|
| 97 | - $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 98 | - if( is_numeric( $course_product_id ) |
|
| 99 | - && |
|
| 100 | - ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 101 | - ){ |
|
| 96 | + // only keep the courses with a product including only courses that the user not taking |
|
| 97 | + $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 98 | + if( is_numeric( $course_product_id ) |
|
| 99 | + && |
|
| 100 | + ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 101 | + ){ |
|
| 102 | 102 | |
| 103 | - $paid_courses_not_taken[] = $course->ID; |
|
| 103 | + $paid_courses_not_taken[] = $course->ID; |
|
| 104 | 104 | |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - } // end foreach |
|
| 107 | + } // end foreach |
|
| 108 | 108 | |
| 109 | - // setup the course query again and only use the course the user has not purchased. |
|
| 110 | - // this query will be loaded into the global WP_Query in the render function. |
|
| 111 | - $query_args[ 'post__in' ] = $paid_courses_not_taken; |
|
| 112 | - $query_args[ 'posts_per_page' ] = $this->number; |
|
| 109 | + // setup the course query again and only use the course the user has not purchased. |
|
| 110 | + // this query will be loaded into the global WP_Query in the render function. |
|
| 111 | + $query_args[ 'post__in' ] = $paid_courses_not_taken; |
|
| 112 | + $query_args[ 'posts_per_page' ] = $this->number; |
|
| 113 | 113 | |
| 114 | - $this->query = new WP_Query( $query_args ); |
|
| 114 | + $this->query = new WP_Query( $query_args ); |
|
| 115 | 115 | |
| 116 | - }// end setup _course_query |
|
| 116 | + }// end setup _course_query |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Rendering the shortcode this class is responsible for. |
|
| 120 | - * |
|
| 121 | - * @return string $content |
|
| 122 | - */ |
|
| 123 | - public function render(){ |
|
| 118 | + /** |
|
| 119 | + * Rendering the shortcode this class is responsible for. |
|
| 120 | + * |
|
| 121 | + * @return string $content |
|
| 122 | + */ |
|
| 123 | + public function render(){ |
|
| 124 | 124 | |
| 125 | - global $wp_query; |
|
| 125 | + global $wp_query; |
|
| 126 | 126 | |
| 127 | - if ( ! is_user_logged_in() ) { |
|
| 127 | + if ( ! is_user_logged_in() ) { |
|
| 128 | 128 | |
| 129 | - $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >'; |
|
| 130 | - $anchor_after = '</a>'; |
|
| 131 | - $notice = sprintf( |
|
| 132 | - __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'), |
|
| 133 | - $anchor_before, |
|
| 134 | - $anchor_after |
|
| 135 | - ); |
|
| 129 | + $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >'; |
|
| 130 | + $anchor_after = '</a>'; |
|
| 131 | + $notice = sprintf( |
|
| 132 | + __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'), |
|
| 133 | + $anchor_before, |
|
| 134 | + $anchor_after |
|
| 135 | + ); |
|
| 136 | 136 | |
| 137 | - Sensei()->notices->add_notice( $notice, 'info' ); |
|
| 138 | - Sensei()->notices->print_notices(); |
|
| 137 | + Sensei()->notices->add_notice( $notice, 'info' ); |
|
| 138 | + Sensei()->notices->print_notices(); |
|
| 139 | 139 | |
| 140 | - return ''; |
|
| 140 | + return ''; |
|
| 141 | 141 | |
| 142 | - } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - // keep a reference to old query |
|
| 145 | - $current_global_query = $wp_query; |
|
| 146 | - // assign the query setup in $this-> setup_course_query |
|
| 147 | - $wp_query = $this->query; |
|
| 144 | + // keep a reference to old query |
|
| 145 | + $current_global_query = $wp_query; |
|
| 146 | + // assign the query setup in $this-> setup_course_query |
|
| 147 | + $wp_query = $this->query; |
|
| 148 | 148 | |
| 149 | - ob_start(); |
|
| 150 | - Sensei()->notices->print_notices(); |
|
| 151 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 152 | - $shortcode_output = ob_get_clean(); |
|
| 149 | + ob_start(); |
|
| 150 | + Sensei()->notices->print_notices(); |
|
| 151 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 152 | + $shortcode_output = ob_get_clean(); |
|
| 153 | 153 | |
| 154 | - //restore old query |
|
| 155 | - $wp_query = $current_global_query; |
|
| 154 | + //restore old query |
|
| 155 | + $wp_query = $current_global_query; |
|
| 156 | 156 | |
| 157 | - return $shortcode_output; |
|
| 157 | + return $shortcode_output; |
|
| 158 | 158 | |
| 159 | - }// end render |
|
| 159 | + }// end render |
|
| 160 | 160 | |
| 161 | 161 | } |
| 162 | 162 | \ No newline at end of file |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course_Results { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - public $courses_url_base; |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + public $courses_url_base; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Constructor. |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | global $wp_query, $current_user; |
| 99 | 99 | |
| 100 | 100 | if( isset( $wp_query->query_vars['course_results'] ) ) { |
| 101 | - Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 101 | + Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | } |
@@ -117,20 +117,20 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | sensei_do_deprecated_action( 'sensei_course_results_lessons','1.9.','sensei_course_results_content_inside_after', $course ); |
| 119 | 119 | |
| 120 | - sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 120 | + sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Load template for displaying course lessons |
| 126 | - * |
|
| 126 | + * |
|
| 127 | 127 | * @since 1.4.0 |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | 130 | public function course_lessons() { |
| 131 | 131 | |
| 132 | 132 | global $course; |
| 133 | - _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 133 | + _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
@@ -147,62 +147,62 @@ discard block |
||
| 147 | 147 | return $classes; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Deprecate the sensei_course_results_content hook |
|
| 152 | - * |
|
| 153 | - * @deprecated since 1.9.0 |
|
| 154 | - */ |
|
| 155 | - public static function deprecate_sensei_course_results_content_hook(){ |
|
| 150 | + /** |
|
| 151 | + * Deprecate the sensei_course_results_content hook |
|
| 152 | + * |
|
| 153 | + * @deprecated since 1.9.0 |
|
| 154 | + */ |
|
| 155 | + public static function deprecate_sensei_course_results_content_hook(){ |
|
| 156 | 156 | |
| 157 | - sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 157 | + sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 158 | 158 | |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Fire the sensei frontend message hook |
|
| 163 | - * |
|
| 164 | - * @since 1.9.0 |
|
| 165 | - */ |
|
| 166 | - public static function fire_sensei_message_hook(){ |
|
| 161 | + /** |
|
| 162 | + * Fire the sensei frontend message hook |
|
| 163 | + * |
|
| 164 | + * @since 1.9.0 |
|
| 165 | + */ |
|
| 166 | + public static function fire_sensei_message_hook(){ |
|
| 167 | 167 | |
| 168 | - do_action( 'sensei_frontend_messages' ); |
|
| 168 | + do_action( 'sensei_frontend_messages' ); |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Deprecate the course_results info hook |
|
| 174 | - * |
|
| 175 | - * @since 1.9.0 |
|
| 176 | - */ |
|
| 177 | - public static function deprecate_course_result_info_hook(){ |
|
| 172 | + /** |
|
| 173 | + * Deprecate the course_results info hook |
|
| 174 | + * |
|
| 175 | + * @since 1.9.0 |
|
| 176 | + */ |
|
| 177 | + public static function deprecate_course_result_info_hook(){ |
|
| 178 | 178 | |
| 179 | - sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 179 | + sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 180 | 180 | |
| 181 | - } |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Deprecate the sensei_course_results_top hook |
|
| 185 | - * |
|
| 186 | - * @deprecate since 1.9.0 |
|
| 187 | - */ |
|
| 188 | - public static function deprecate_course_results_top_hook(){ |
|
| 183 | + /** |
|
| 184 | + * Deprecate the sensei_course_results_top hook |
|
| 185 | + * |
|
| 186 | + * @deprecate since 1.9.0 |
|
| 187 | + */ |
|
| 188 | + public static function deprecate_course_results_top_hook(){ |
|
| 189 | 189 | |
| 190 | - global $course; |
|
| 191 | - sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 190 | + global $course; |
|
| 191 | + sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Fire the course image hook |
|
| 197 | - * |
|
| 198 | - * @since 1.8.0 |
|
| 199 | - */ |
|
| 200 | - public static function fire_course_image_hook(){ |
|
| 195 | + /** |
|
| 196 | + * Fire the course image hook |
|
| 197 | + * |
|
| 198 | + * @since 1.8.0 |
|
| 199 | + */ |
|
| 200 | + public static function fire_course_image_hook(){ |
|
| 201 | 201 | |
| 202 | - global $course; |
|
| 203 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 202 | + global $course; |
|
| 203 | + sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 204 | 204 | |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | } // End Class |
| 208 | 208 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public static function has_language_pack_available( $locale = null ) { |
| 93 | 93 | |
| 94 | - if ( is_null( $locale ) ) { |
|
| 94 | + if ( is_null( $locale ) ) { |
|
| 95 | 95 | |
| 96 | 96 | $locale = get_locale(); |
| 97 | 97 | |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if( isset( $_GET['translation_updated'] ) && 5 == $_GET['translation_updated'] ){ |
|
| 112 | + if( isset( $_GET['translation_updated'] ) && 5 == $_GET['translation_updated'] ){ |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | $version = get_option( 'woothemes_sensei_language_pack_version', array( '0', $locale ) ); |
| 119 | 119 | |
@@ -12,735 +12,735 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | Class Sensei_WC{ |
| 15 | - /** |
|
| 16 | - * Load the files needed for the woocommerce integration. |
|
| 17 | - * |
|
| 18 | - * @since 1.9.0 |
|
| 19 | - */ |
|
| 20 | - public static function load_woocommerce_integration_hooks(){ |
|
| 15 | + /** |
|
| 16 | + * Load the files needed for the woocommerce integration. |
|
| 17 | + * |
|
| 18 | + * @since 1.9.0 |
|
| 19 | + */ |
|
| 20 | + public static function load_woocommerce_integration_hooks(){ |
|
| 21 | 21 | |
| 22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 22 | + require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 23 | 23 | |
| 24 | - } |
|
| 25 | - /** |
|
| 26 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | - * |
|
| 28 | - * @since 1.9.0 |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public static function is_woocommerce_active(){ |
|
| 24 | + } |
|
| 25 | + /** |
|
| 26 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | + * |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public static function is_woocommerce_active(){ |
|
| 32 | 32 | |
| 33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 33 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 35 | 35 | |
| 36 | - } // end is_woocommerce_active |
|
| 36 | + } // end is_woocommerce_active |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | - * |
|
| 41 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | - * |
|
| 44 | - * @since 1.9.0 |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public static function is_woocommerce_present(){ |
|
| 38 | + /** |
|
| 39 | + * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | + * |
|
| 41 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | + * |
|
| 44 | + * @since 1.9.0 |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public static function is_woocommerce_present(){ |
|
| 49 | 49 | |
| 50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 50 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 51 | 51 | |
| 52 | - if ( is_multisite() ){ |
|
| 52 | + if ( is_multisite() ){ |
|
| 53 | 53 | |
| 54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 54 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 58 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 59 | 59 | |
| 60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 60 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 61 | 61 | |
| 62 | - }// end is_woocommerce_present |
|
| 62 | + }// end is_woocommerce_present |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | - * |
|
| 67 | - * If multiple exist we will return the latest order. |
|
| 68 | - * |
|
| 69 | - * @param $user_id |
|
| 70 | - * @param $course_id |
|
| 71 | - * @return array $user_course_orders |
|
| 72 | - */ |
|
| 73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 64 | + /** |
|
| 65 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | + * |
|
| 67 | + * If multiple exist we will return the latest order. |
|
| 68 | + * |
|
| 69 | + * @param $user_id |
|
| 70 | + * @param $course_id |
|
| 71 | + * @return array $user_course_orders |
|
| 72 | + */ |
|
| 73 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 74 | 74 | |
| 75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 75 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 76 | 76 | |
| 77 | - $orders_query = new WP_Query( array( |
|
| 78 | - 'post_type' => 'shop_order', |
|
| 79 | - 'posts_per_page' => -1, |
|
| 80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | - 'meta_key'=> '_customer_user', |
|
| 82 | - 'meta_value'=> $user_id, |
|
| 83 | - ) ); |
|
| 77 | + $orders_query = new WP_Query( array( |
|
| 78 | + 'post_type' => 'shop_order', |
|
| 79 | + 'posts_per_page' => -1, |
|
| 80 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | + 'meta_key'=> '_customer_user', |
|
| 82 | + 'meta_value'=> $user_id, |
|
| 83 | + ) ); |
|
| 84 | 84 | |
| 85 | - if( $orders_query->post_count == 0 ){ |
|
| 85 | + if( $orders_query->post_count == 0 ){ |
|
| 86 | 86 | |
| 87 | - return false; |
|
| 87 | + return false; |
|
| 88 | 88 | |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 91 | + foreach( $orders_query->get_posts() as $order ){ |
|
| 92 | 92 | |
| 93 | - $order = new WC_Order( $order->ID ); |
|
| 94 | - $items = $order->get_items(); |
|
| 93 | + $order = new WC_Order( $order->ID ); |
|
| 94 | + $items = $order->get_items(); |
|
| 95 | 95 | |
| 96 | - $user_orders = array(); |
|
| 96 | + $user_orders = array(); |
|
| 97 | 97 | |
| 98 | - foreach( $items as $item ){ |
|
| 98 | + foreach( $items as $item ){ |
|
| 99 | 99 | |
| 100 | - // if the product id on the order and the one given to this function |
|
| 101 | - // this order has been placed by the given user on the given course. |
|
| 102 | - $product = wc_get_product( $item['product_id'] ); |
|
| 100 | + // if the product id on the order and the one given to this function |
|
| 101 | + // this order has been placed by the given user on the given course. |
|
| 102 | + $product = wc_get_product( $item['product_id'] ); |
|
| 103 | 103 | |
| 104 | - if ( $product->is_type( 'variable' )) { |
|
| 104 | + if ( $product->is_type( 'variable' )) { |
|
| 105 | 105 | |
| 106 | - $item_product_id = $item['variation_id']; |
|
| 106 | + $item_product_id = $item['variation_id']; |
|
| 107 | 107 | |
| 108 | - } else { |
|
| 108 | + } else { |
|
| 109 | 109 | |
| 110 | - $item_product_id = $item['product_id']; |
|
| 110 | + $item_product_id = $item['product_id']; |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if( $course_product_id == $item_product_id ){ |
|
| 114 | + if( $course_product_id == $item_product_id ){ |
|
| 115 | 115 | |
| 116 | - return $order->id; |
|
| 116 | + return $order->id; |
|
| 117 | 117 | |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - }//end for each order item |
|
| 121 | + }//end for each order item |
|
| 122 | 122 | |
| 123 | - } // end for each order |
|
| 123 | + } // end for each order |
|
| 124 | 124 | |
| 125 | - // if we reach this place we found no order |
|
| 126 | - return false; |
|
| 125 | + // if we reach this place we found no order |
|
| 126 | + return false; |
|
| 127 | 127 | |
| 128 | - } // end get_learner_course_active_order_ids |
|
| 128 | + } // end get_learner_course_active_order_ids |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Output WooCommerce specific course filters |
|
| 132 | - * Removing the paged argument |
|
| 133 | - * |
|
| 134 | - * @since 1.9.0 |
|
| 135 | - * @param $filter_links |
|
| 136 | - * @return mixed |
|
| 137 | - */ |
|
| 138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 130 | + /** |
|
| 131 | + * Output WooCommerce specific course filters |
|
| 132 | + * Removing the paged argument |
|
| 133 | + * |
|
| 134 | + * @since 1.9.0 |
|
| 135 | + * @param $filter_links |
|
| 136 | + * @return mixed |
|
| 137 | + */ |
|
| 138 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 139 | 139 | |
| 140 | - $free_courses = self::get_free_courses(); |
|
| 141 | - $paid_courses = self::get_paid_courses(); |
|
| 140 | + $free_courses = self::get_free_courses(); |
|
| 141 | + $paid_courses = self::get_paid_courses(); |
|
| 142 | 142 | |
| 143 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 144 | - // do not show any WooCommerce filters if all courses are |
|
| 145 | - // free or if all courses are paid |
|
| 146 | - return $filter_links; |
|
| 143 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 144 | + // do not show any WooCommerce filters if all courses are |
|
| 145 | + // free or if all courses are paid |
|
| 146 | + return $filter_links; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - $filter_links[] = array( |
|
| 151 | - 'id'=>'paid' , |
|
| 152 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | - ); |
|
| 150 | + $filter_links[] = array( |
|
| 151 | + 'id'=>'paid' , |
|
| 152 | + 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | - $filter_links[] = array( |
|
| 157 | - 'id'=>'free', |
|
| 158 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | - ); |
|
| 156 | + $filter_links[] = array( |
|
| 157 | + 'id'=>'free', |
|
| 158 | + 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | + ); |
|
| 161 | 161 | |
| 162 | - return $filter_links; |
|
| 162 | + return $filter_links; |
|
| 163 | 163 | |
| 164 | - }// end add_course_archive_wc_filter_links |
|
| 164 | + }// end add_course_archive_wc_filter_links |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Apply the free filter the the course query |
|
| 168 | - * getting all course with no products or products with zero price |
|
| 169 | - * |
|
| 170 | - * hooked into pre_get_posts |
|
| 171 | - * |
|
| 172 | - * @since 1.9.0 |
|
| 173 | - * @param WP_Query $query |
|
| 174 | - * @return WP_Query $query |
|
| 175 | - */ |
|
| 176 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 166 | + /** |
|
| 167 | + * Apply the free filter the the course query |
|
| 168 | + * getting all course with no products or products with zero price |
|
| 169 | + * |
|
| 170 | + * hooked into pre_get_posts |
|
| 171 | + * |
|
| 172 | + * @since 1.9.0 |
|
| 173 | + * @param WP_Query $query |
|
| 174 | + * @return WP_Query $query |
|
| 175 | + */ |
|
| 176 | + public static function course_archive_wc_filter_free( $query ){ |
|
| 177 | 177 | |
| 178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 178 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 180 | 180 | |
| 181 | - // setup the course meta query |
|
| 182 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
| 181 | + // setup the course meta query |
|
| 182 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
| 183 | 183 | |
| 184 | - // manipulate the query to return free courses |
|
| 185 | - $query->set('meta_query', $meta_query ); |
|
| 184 | + // manipulate the query to return free courses |
|
| 185 | + $query->set('meta_query', $meta_query ); |
|
| 186 | 186 | |
| 187 | - // don't show any paid courses |
|
| 188 | - $courses = self::get_paid_courses(); |
|
| 189 | - $ids = array(); |
|
| 190 | - foreach( $courses as $course ){ |
|
| 191 | - $ids[] = $course->ID; |
|
| 192 | - } |
|
| 193 | - $query->set( 'post__not_in', $ids ); |
|
| 187 | + // don't show any paid courses |
|
| 188 | + $courses = self::get_paid_courses(); |
|
| 189 | + $ids = array(); |
|
| 190 | + foreach( $courses as $course ){ |
|
| 191 | + $ids[] = $course->ID; |
|
| 192 | + } |
|
| 193 | + $query->set( 'post__not_in', $ids ); |
|
| 194 | 194 | |
| 195 | - }// end if course_filter |
|
| 195 | + }// end if course_filter |
|
| 196 | 196 | |
| 197 | - return $query; |
|
| 197 | + return $query; |
|
| 198 | 198 | |
| 199 | - }// course_archive_wc_filter_free |
|
| 199 | + }// course_archive_wc_filter_free |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Apply the paid filter to the course query on the courses page |
|
| 203 | - * will include all course with a product attached with a price |
|
| 204 | - * more than 0 |
|
| 205 | - * |
|
| 206 | - * hooked into pre_get_posts |
|
| 207 | - * |
|
| 208 | - * @since 1.9.0 |
|
| 209 | - * @param WP_Query $query |
|
| 210 | - * @return WP_Query $query |
|
| 211 | - */ |
|
| 212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 201 | + /** |
|
| 202 | + * Apply the paid filter to the course query on the courses page |
|
| 203 | + * will include all course with a product attached with a price |
|
| 204 | + * more than 0 |
|
| 205 | + * |
|
| 206 | + * hooked into pre_get_posts |
|
| 207 | + * |
|
| 208 | + * @since 1.9.0 |
|
| 209 | + * @param WP_Query $query |
|
| 210 | + * @return WP_Query $query |
|
| 211 | + */ |
|
| 212 | + public static function course_archive_wc_filter_paid( $query ){ |
|
| 213 | 213 | |
| 214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | - |
|
| 217 | - // setup the course meta query |
|
| 218 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | - |
|
| 220 | - // manipulate the query to return free courses |
|
| 221 | - $query->set('meta_query', $meta_query ); |
|
| 222 | - |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $query; |
|
| 226 | - |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Load the WooCommerce single product actions above |
|
| 231 | - * single courses if woocommerce is active allowing purchase |
|
| 232 | - * information and actions to be hooked from WooCommerce. |
|
| 233 | - */ |
|
| 234 | - public static function do_single_course_wc_single_product_action(){ |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * this hooks is documented within the WooCommerce plugin. |
|
| 238 | - */ |
|
| 239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | - |
|
| 241 | - do_action( 'woocommerce_before_single_product' ); |
|
| 242 | - |
|
| 243 | - } // End If Statement |
|
| 244 | - |
|
| 245 | - }// end do_single_course_wc_single_product_action |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Hooking into the single lesson page to alter the |
|
| 249 | - * user access permissions based on if they have purchased the |
|
| 250 | - * course the lesson belongs to. |
|
| 251 | - * |
|
| 252 | - * This function will only return false or the passed in user_access value. |
|
| 253 | - * It doesn't return true in order to avoid altering other options. |
|
| 254 | - * |
|
| 255 | - * @since 1.9.0 |
|
| 256 | - * |
|
| 257 | - * @param $can_user_view_lesson |
|
| 258 | - * @param $lesson_id |
|
| 259 | - * @param $user_id |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | - |
|
| 264 | - // check if the course has a valid product attached to it |
|
| 265 | - // which the user should have purchased if they want to access |
|
| 266 | - // the current lesson |
|
| 267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | - if( isset ($product) && is_object($product) ){ |
|
| 271 | - |
|
| 272 | - // valid product found |
|
| 273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | - |
|
| 275 | - // product has a successful order so this user may access the content |
|
| 276 | - // this function may only return false or the default |
|
| 277 | - // returning true may override other negatives which we don't want |
|
| 278 | - if( ! $order_id ){ |
|
| 279 | - |
|
| 280 | - return false; |
|
| 281 | - |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // return the passed in value |
|
| 287 | - return $can_user_view_lesson; |
|
| 288 | - |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Add course link to order thank you and details pages. |
|
| 293 | - * |
|
| 294 | - * @since 1.4.5 |
|
| 295 | - * @access public |
|
| 296 | - * |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function course_link_from_order( ) { |
|
| 300 | - |
|
| 301 | - if( ! is_order_received_page() ){ |
|
| 302 | - return; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $order_id = get_query_var( 'order-received' ); |
|
| 214 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | + |
|
| 217 | + // setup the course meta query |
|
| 218 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | + |
|
| 220 | + // manipulate the query to return free courses |
|
| 221 | + $query->set('meta_query', $meta_query ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $query; |
|
| 226 | + |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Load the WooCommerce single product actions above |
|
| 231 | + * single courses if woocommerce is active allowing purchase |
|
| 232 | + * information and actions to be hooked from WooCommerce. |
|
| 233 | + */ |
|
| 234 | + public static function do_single_course_wc_single_product_action(){ |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * this hooks is documented within the WooCommerce plugin. |
|
| 238 | + */ |
|
| 239 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | + |
|
| 241 | + do_action( 'woocommerce_before_single_product' ); |
|
| 242 | + |
|
| 243 | + } // End If Statement |
|
| 244 | + |
|
| 245 | + }// end do_single_course_wc_single_product_action |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Hooking into the single lesson page to alter the |
|
| 249 | + * user access permissions based on if they have purchased the |
|
| 250 | + * course the lesson belongs to. |
|
| 251 | + * |
|
| 252 | + * This function will only return false or the passed in user_access value. |
|
| 253 | + * It doesn't return true in order to avoid altering other options. |
|
| 254 | + * |
|
| 255 | + * @since 1.9.0 |
|
| 256 | + * |
|
| 257 | + * @param $can_user_view_lesson |
|
| 258 | + * @param $lesson_id |
|
| 259 | + * @param $user_id |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | + |
|
| 264 | + // check if the course has a valid product attached to it |
|
| 265 | + // which the user should have purchased if they want to access |
|
| 266 | + // the current lesson |
|
| 267 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | + if( isset ($product) && is_object($product) ){ |
|
| 271 | + |
|
| 272 | + // valid product found |
|
| 273 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | + |
|
| 275 | + // product has a successful order so this user may access the content |
|
| 276 | + // this function may only return false or the default |
|
| 277 | + // returning true may override other negatives which we don't want |
|
| 278 | + if( ! $order_id ){ |
|
| 279 | + |
|
| 280 | + return false; |
|
| 281 | + |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // return the passed in value |
|
| 287 | + return $can_user_view_lesson; |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Add course link to order thank you and details pages. |
|
| 293 | + * |
|
| 294 | + * @since 1.4.5 |
|
| 295 | + * @access public |
|
| 296 | + * |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function course_link_from_order( ) { |
|
| 300 | + |
|
| 301 | + if( ! is_order_received_page() ){ |
|
| 302 | + return; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $order_id = get_query_var( 'order-received' ); |
|
| 306 | 306 | $order = new WC_Order( $order_id ); |
| 307 | 307 | |
| 308 | 308 | // exit early if not wc-completed or wc-processing |
| 309 | 309 | if( 'wc-completed' != $order->post_status |
| 310 | - && 'wc-processing' != $order->post_status ) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 310 | + && 'wc-processing' != $order->post_status ) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $course_links = array(); // store the for links for courses purchased |
|
| 314 | + $course_links = array(); // store the for links for courses purchased |
|
| 315 | 315 | foreach ( $order->get_items() as $item ) { |
| 316 | 316 | |
| 317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 317 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 318 | 318 | |
| 319 | - // If item has variation_id then its a variation of the product |
|
| 320 | - $item_id = $item['variation_id']; |
|
| 319 | + // If item has variation_id then its a variation of the product |
|
| 320 | + $item_id = $item['variation_id']; |
|
| 321 | 321 | |
| 322 | - } else { |
|
| 322 | + } else { |
|
| 323 | 323 | |
| 324 | - //If not its real product set its id to item_id |
|
| 325 | - $item_id = $item['product_id']; |
|
| 324 | + //If not its real product set its id to item_id |
|
| 325 | + $item_id = $item['product_id']; |
|
| 326 | 326 | |
| 327 | - } // End If Statement |
|
| 327 | + } // End If Statement |
|
| 328 | 328 | |
| 329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 329 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 330 | 330 | |
| 331 | - if( $user_id ) { |
|
| 331 | + if( $user_id ) { |
|
| 332 | 332 | |
| 333 | - // Get all courses for product |
|
| 334 | - $args = Sensei_Course::get_default_query_args(); |
|
| 335 | - $args['meta_query'] = array( array( |
|
| 336 | - 'key' => '_course_woocommerce_product', |
|
| 337 | - 'value' => $item_id |
|
| 338 | - ) ); |
|
| 339 | - $args['orderby'] = 'menu_order date'; |
|
| 340 | - $args['order'] = 'ASC'; |
|
| 333 | + // Get all courses for product |
|
| 334 | + $args = Sensei_Course::get_default_query_args(); |
|
| 335 | + $args['meta_query'] = array( array( |
|
| 336 | + 'key' => '_course_woocommerce_product', |
|
| 337 | + 'value' => $item_id |
|
| 338 | + ) ); |
|
| 339 | + $args['orderby'] = 'menu_order date'; |
|
| 340 | + $args['order'] = 'ASC'; |
|
| 341 | 341 | |
| 342 | - // loop through courses |
|
| 343 | - $courses = get_posts( $args ); |
|
| 344 | - if( $courses && count( $courses ) > 0 ) { |
|
| 342 | + // loop through courses |
|
| 343 | + $courses = get_posts( $args ); |
|
| 344 | + if( $courses && count( $courses ) > 0 ) { |
|
| 345 | 345 | |
| 346 | - foreach( $courses as $course ) { |
|
| 346 | + foreach( $courses as $course ) { |
|
| 347 | 347 | |
| 348 | - $title = $course->post_title; |
|
| 349 | - $permalink = get_permalink( $course->ID ); |
|
| 350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 348 | + $title = $course->post_title; |
|
| 349 | + $permalink = get_permalink( $course->ID ); |
|
| 350 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 351 | 351 | |
| 352 | - } // end for each |
|
| 352 | + } // end for each |
|
| 353 | 353 | |
| 354 | - // close the message div |
|
| 354 | + // close the message div |
|
| 355 | 355 | |
| 356 | - }// end if $courses check |
|
| 357 | - } |
|
| 358 | - }// end loop through orders |
|
| 356 | + }// end if $courses check |
|
| 357 | + } |
|
| 358 | + }// end loop through orders |
|
| 359 | 359 | |
| 360 | - // add the courses to the WooCommerce notice |
|
| 361 | - if( ! empty( $course_links) ){ |
|
| 360 | + // add the courses to the WooCommerce notice |
|
| 361 | + if( ! empty( $course_links) ){ |
|
| 362 | 362 | |
| 363 | - $courses_html = _nx( |
|
| 364 | - 'You have purchased the following course:', |
|
| 365 | - 'You have purchased the following courses:', |
|
| 366 | - count( $course_links ), |
|
| 367 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | - ); |
|
| 363 | + $courses_html = _nx( |
|
| 364 | + 'You have purchased the following course:', |
|
| 365 | + 'You have purchased the following courses:', |
|
| 366 | + count( $course_links ), |
|
| 367 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | + ); |
|
| 369 | 369 | |
| 370 | - foreach( $course_links as $link ){ |
|
| 370 | + foreach( $course_links as $link ){ |
|
| 371 | 371 | |
| 372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 372 | + $courses_html .= '<li>' . $link . '</li>'; |
|
| 373 | 373 | |
| 374 | - } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $courses_html .= ' </ul>'; |
|
| 376 | + $courses_html .= ' </ul>'; |
|
| 377 | 377 | |
| 378 | - wc_add_notice( $courses_html, 'success' ); |
|
| 379 | - } |
|
| 378 | + wc_add_notice( $courses_html, 'success' ); |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | } // end course_link_order_form |
| 382 | 382 | |
| 383 | - /** |
|
| 384 | - * Show the message that a user should complete |
|
| 385 | - * their purchase if the course is in the cart |
|
| 386 | - * |
|
| 387 | - * This should be used within the course loop or single course page |
|
| 388 | - * |
|
| 389 | - * @since 1.9.0 |
|
| 390 | - */ |
|
| 391 | - public static function course_in_cart_message(){ |
|
| 383 | + /** |
|
| 384 | + * Show the message that a user should complete |
|
| 385 | + * their purchase if the course is in the cart |
|
| 386 | + * |
|
| 387 | + * This should be used within the course loop or single course page |
|
| 388 | + * |
|
| 389 | + * @since 1.9.0 |
|
| 390 | + */ |
|
| 391 | + public static function course_in_cart_message(){ |
|
| 392 | 392 | |
| 393 | - global $post; |
|
| 393 | + global $post; |
|
| 394 | 394 | |
| 395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 395 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 396 | 396 | |
| 397 | 397 | <div class="sensei-message info"> |
| 398 | 398 | <?php |
| 399 | 399 | |
| 400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 400 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 403 | 403 | |
| 404 | - echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 404 | + echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 405 | 405 | |
| 406 | - ?> |
|
| 406 | + ?> |
|
| 407 | 407 | </div> |
| 408 | 408 | <?php } |
| 409 | 409 | |
| 410 | - } // End sensei_woocommerce_in_cart_message() |
|
| 410 | + } // End sensei_woocommerce_in_cart_message() |
|
| 411 | 411 | |
| 412 | - /** |
|
| 413 | - * Checks the cart to see if a course is in the cart. |
|
| 414 | - * |
|
| 415 | - * @param $course_id |
|
| 416 | - * @return bool |
|
| 417 | - */ |
|
| 418 | - public static function is_course_in_cart( $course_id ){ |
|
| 419 | - |
|
| 420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | - |
|
| 423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | - |
|
| 425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | - |
|
| 427 | - return true; |
|
| 428 | - |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return false; |
|
| 434 | - |
|
| 435 | - }// is_course_in_cart |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Check the cart to see if the product is in the cart |
|
| 439 | - * |
|
| 440 | - * @param $product_id |
|
| 441 | - * @return bool |
|
| 442 | - */ |
|
| 443 | - public static function is_product_in_cart( $product_id ){ |
|
| 444 | - |
|
| 445 | - if ( 0 < $product_id ) { |
|
| 446 | - |
|
| 447 | - $product = wc_get_product( $product_id ); |
|
| 448 | - |
|
| 449 | - $parent_id = ''; |
|
| 450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | - $wc_product_id = $product->parent->id; |
|
| 452 | - } |
|
| 453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | - |
|
| 455 | - $cart_product = $values['data']; |
|
| 456 | - if( $product_id == $cart_product->id ) { |
|
| 457 | - |
|
| 458 | - return true; |
|
| 459 | - |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - } |
|
| 463 | - } // End If Statement |
|
| 464 | - |
|
| 465 | - return false; |
|
| 466 | - |
|
| 467 | - } // end is_product_in_car |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Get all free WooCommerce products |
|
| 471 | - * |
|
| 472 | - * @since 1.9.0 |
|
| 473 | - * |
|
| 474 | - * @return array $free_products{ |
|
| 475 | - * @type int $wp_post_id |
|
| 476 | - * } |
|
| 477 | - */ |
|
| 478 | - public static function get_free_product_ids(){ |
|
| 479 | - |
|
| 480 | - return get_posts( array( |
|
| 481 | - 'post_type' => 'product', |
|
| 482 | - 'posts_per_page' => '1000', |
|
| 483 | - 'fields' => 'ids', |
|
| 484 | - 'meta_query'=> array( |
|
| 485 | - 'relation' => 'OR', |
|
| 486 | - array( |
|
| 487 | - 'key'=> '_regular_price', |
|
| 488 | - 'value' => 0, |
|
| 489 | - ), |
|
| 490 | - array( |
|
| 491 | - 'key'=> '_sale_price', |
|
| 492 | - 'value' => 0, |
|
| 493 | - ), |
|
| 494 | - ), |
|
| 495 | - )); |
|
| 496 | - |
|
| 497 | - }// end get free product query |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * The metat query for courses that are free |
|
| 501 | - * |
|
| 502 | - * @since 1.9.0 |
|
| 503 | - * @return array $wp_meta_query_param |
|
| 504 | - */ |
|
| 505 | - public static function get_free_courses_meta_query_args(){ |
|
| 506 | - |
|
| 507 | - return array( |
|
| 508 | - 'relation' => 'OR', |
|
| 509 | - array( |
|
| 510 | - 'key' => '_course_woocommerce_product', |
|
| 511 | - 'value' => '-', |
|
| 512 | - 'compare' => '=', |
|
| 513 | - ), |
|
| 514 | - array( |
|
| 515 | - 'key' => '_course_woocommerce_product', |
|
| 516 | - 'value' => self::get_free_product_ids(), |
|
| 517 | - 'compare' => 'IN', |
|
| 518 | - ), |
|
| 519 | - ); |
|
| 520 | - |
|
| 521 | - }// get_free_courses_meta_query |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * The metat query for courses that are free |
|
| 525 | - * |
|
| 526 | - * @since 1.9.0 |
|
| 527 | - * @return array $wp_query_meta_query_args_param |
|
| 528 | - */ |
|
| 529 | - public static function get_paid_courses_meta_query_args(){ |
|
| 530 | - |
|
| 531 | - $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | - |
|
| 533 | - return array( |
|
| 534 | - array( |
|
| 535 | - 'key' => '_course_woocommerce_product', |
|
| 536 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | - // query |
|
| 538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | - 'compare' => 'IN', |
|
| 540 | - ), |
|
| 541 | - ); |
|
| 542 | - |
|
| 543 | - }// get_free_courses_meta_query |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * The WordPress Query args |
|
| 547 | - * for paid products on sale |
|
| 548 | - * |
|
| 549 | - * @since 1.9.0 |
|
| 550 | - * @return array $product_query_args |
|
| 551 | - */ |
|
| 552 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | - |
|
| 554 | - $args = array( |
|
| 555 | - 'post_type' => 'product', |
|
| 556 | - 'posts_per_page' => 1000, |
|
| 557 | - 'orderby' => 'date', |
|
| 558 | - 'order' => 'DESC', |
|
| 559 | - 'suppress_filters' => 0 |
|
| 560 | - ); |
|
| 561 | - |
|
| 562 | - $args[ 'fields' ] = 'ids'; |
|
| 563 | - |
|
| 564 | - $args[ 'meta_query' ] = array( |
|
| 565 | - 'relation' => 'AND', |
|
| 566 | - array( |
|
| 567 | - 'key'=> '_regular_price', |
|
| 568 | - 'compare' => '>', |
|
| 569 | - 'value' => 0, |
|
| 570 | - ), |
|
| 571 | - array( |
|
| 572 | - 'key'=> '_sale_price', |
|
| 573 | - 'compare' => '>', |
|
| 574 | - 'value' => 0, |
|
| 575 | - ), |
|
| 576 | - ); |
|
| 577 | - |
|
| 578 | - return $args; |
|
| 579 | - |
|
| 580 | - } // get_paid_products_on_sale_query_args |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Return the WordPress query args for |
|
| 585 | - * products not on sale but that is not a free |
|
| 586 | - * |
|
| 587 | - * @since 1.9.0 |
|
| 588 | - * |
|
| 589 | - * @return array |
|
| 590 | - */ |
|
| 591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | - |
|
| 593 | - $args = array( |
|
| 594 | - 'post_type' => 'product', |
|
| 595 | - 'posts_per_page' => 1000, |
|
| 596 | - 'orderby' => 'date', |
|
| 597 | - 'order' => 'DESC', |
|
| 598 | - 'suppress_filters' => 0 |
|
| 599 | - ); |
|
| 600 | - |
|
| 601 | - $args[ 'fields' ] = 'ids'; |
|
| 602 | - $args[ 'meta_query' ] = array( |
|
| 603 | - 'relation' => 'AND', |
|
| 604 | - array( |
|
| 605 | - 'key'=> '_regular_price', |
|
| 606 | - 'compare' => '>', |
|
| 607 | - 'value' => 0, |
|
| 608 | - ), |
|
| 609 | - array( |
|
| 610 | - 'key'=> '_sale_price', |
|
| 611 | - 'compare' => '=', |
|
| 612 | - 'value' => '', |
|
| 613 | - ), |
|
| 614 | - ); |
|
| 615 | - |
|
| 616 | - return $args; |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - } // get_paid_courses_meta_query |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Get all WooCommerce non-free product id's |
|
| 623 | - * |
|
| 624 | - * @since 1.9.0 |
|
| 625 | - * |
|
| 626 | - * @return array $woocommerce_paid_product_ids |
|
| 627 | - */ |
|
| 628 | - public static function get_paid_product_ids(){ |
|
| 629 | - |
|
| 630 | - // get all the paid WooCommerce products that has regular |
|
| 631 | - // and sale price greater than 0 |
|
| 632 | - // will be used later to check for course with the id as meta |
|
| 633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | - |
|
| 635 | - // get all the paid WooCommerce products that has regular price |
|
| 636 | - // greater than 0 without a sale price |
|
| 637 | - // will be used later to check for course with the id as meta |
|
| 638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | - |
|
| 640 | - // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | - // sale but regular price greater than zero |
|
| 642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | - |
|
| 644 | - // if |
|
| 645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | - return array( ); |
|
| 647 | - } |
|
| 648 | - return $woocommerce_paid_product_ids; |
|
| 649 | - |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Get all free courses. |
|
| 654 | - * |
|
| 655 | - * This course that have a WC product attached |
|
| 656 | - * that has a price or sale price of zero and |
|
| 657 | - * other courses with no WooCommerce products |
|
| 658 | - * attached. |
|
| 659 | - * |
|
| 660 | - * @since 1.9.0 |
|
| 661 | - * |
|
| 662 | - * @return array |
|
| 663 | - */ |
|
| 664 | - public static function get_free_courses(){ |
|
| 665 | - |
|
| 666 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | - |
|
| 669 | - // don't show any paid courses |
|
| 670 | - $courses = self::get_paid_courses(); |
|
| 671 | - $ids = array(); |
|
| 672 | - foreach( $courses as $course ){ |
|
| 673 | - $ids[] = $course->ID; |
|
| 674 | - } |
|
| 675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | - |
|
| 677 | - return get_posts( $free_course_query_args ); |
|
| 678 | - |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Return all products that are not free |
|
| 683 | - * |
|
| 684 | - * @since 1.9.0 |
|
| 685 | - * @return array |
|
| 686 | - */ |
|
| 687 | - public static function get_paid_courses(){ |
|
| 688 | - |
|
| 689 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | - |
|
| 691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | - |
|
| 693 | - return get_posts( $paid_course_query_args ); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Show the WooCommerce add to cart button for the current course |
|
| 698 | - * |
|
| 699 | - * The function will only show the button if |
|
| 700 | - * 1- the user can buy the course |
|
| 701 | - * 2- if they have completed their pre-requisite |
|
| 702 | - * 3- if the course has a valid product attached |
|
| 703 | - * |
|
| 704 | - * @since 1.9.0 |
|
| 705 | - * @param int $course_id |
|
| 706 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | - */ |
|
| 708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | - |
|
| 710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | - return ''; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | - |
|
| 716 | - // Check if customer purchased the product |
|
| 717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | - || empty( $wc_post_id ) ) { |
|
| 719 | - |
|
| 720 | - return ''; |
|
| 721 | - |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | - // Get the product |
|
| 726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | - |
|
| 728 | - // do not show the button for invalid products, non purchasable products, out |
|
| 729 | - // of stock product or if course is already in cart |
|
| 730 | - if ( ! isset ( $product ) |
|
| 731 | - || ! is_object( $product ) |
|
| 732 | - || ! $product->is_purchasable() |
|
| 733 | - || ! $product->is_in_stock() |
|
| 734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | - |
|
| 736 | - return ''; |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - // |
|
| 741 | - // button output: |
|
| 742 | - // |
|
| 743 | - ?> |
|
| 412 | + /** |
|
| 413 | + * Checks the cart to see if a course is in the cart. |
|
| 414 | + * |
|
| 415 | + * @param $course_id |
|
| 416 | + * @return bool |
|
| 417 | + */ |
|
| 418 | + public static function is_course_in_cart( $course_id ){ |
|
| 419 | + |
|
| 420 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | + |
|
| 423 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | + |
|
| 425 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | + |
|
| 427 | + return true; |
|
| 428 | + |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return false; |
|
| 434 | + |
|
| 435 | + }// is_course_in_cart |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Check the cart to see if the product is in the cart |
|
| 439 | + * |
|
| 440 | + * @param $product_id |
|
| 441 | + * @return bool |
|
| 442 | + */ |
|
| 443 | + public static function is_product_in_cart( $product_id ){ |
|
| 444 | + |
|
| 445 | + if ( 0 < $product_id ) { |
|
| 446 | + |
|
| 447 | + $product = wc_get_product( $product_id ); |
|
| 448 | + |
|
| 449 | + $parent_id = ''; |
|
| 450 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | + $wc_product_id = $product->parent->id; |
|
| 452 | + } |
|
| 453 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | + |
|
| 455 | + $cart_product = $values['data']; |
|
| 456 | + if( $product_id == $cart_product->id ) { |
|
| 457 | + |
|
| 458 | + return true; |
|
| 459 | + |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + } |
|
| 463 | + } // End If Statement |
|
| 464 | + |
|
| 465 | + return false; |
|
| 466 | + |
|
| 467 | + } // end is_product_in_car |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Get all free WooCommerce products |
|
| 471 | + * |
|
| 472 | + * @since 1.9.0 |
|
| 473 | + * |
|
| 474 | + * @return array $free_products{ |
|
| 475 | + * @type int $wp_post_id |
|
| 476 | + * } |
|
| 477 | + */ |
|
| 478 | + public static function get_free_product_ids(){ |
|
| 479 | + |
|
| 480 | + return get_posts( array( |
|
| 481 | + 'post_type' => 'product', |
|
| 482 | + 'posts_per_page' => '1000', |
|
| 483 | + 'fields' => 'ids', |
|
| 484 | + 'meta_query'=> array( |
|
| 485 | + 'relation' => 'OR', |
|
| 486 | + array( |
|
| 487 | + 'key'=> '_regular_price', |
|
| 488 | + 'value' => 0, |
|
| 489 | + ), |
|
| 490 | + array( |
|
| 491 | + 'key'=> '_sale_price', |
|
| 492 | + 'value' => 0, |
|
| 493 | + ), |
|
| 494 | + ), |
|
| 495 | + )); |
|
| 496 | + |
|
| 497 | + }// end get free product query |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * The metat query for courses that are free |
|
| 501 | + * |
|
| 502 | + * @since 1.9.0 |
|
| 503 | + * @return array $wp_meta_query_param |
|
| 504 | + */ |
|
| 505 | + public static function get_free_courses_meta_query_args(){ |
|
| 506 | + |
|
| 507 | + return array( |
|
| 508 | + 'relation' => 'OR', |
|
| 509 | + array( |
|
| 510 | + 'key' => '_course_woocommerce_product', |
|
| 511 | + 'value' => '-', |
|
| 512 | + 'compare' => '=', |
|
| 513 | + ), |
|
| 514 | + array( |
|
| 515 | + 'key' => '_course_woocommerce_product', |
|
| 516 | + 'value' => self::get_free_product_ids(), |
|
| 517 | + 'compare' => 'IN', |
|
| 518 | + ), |
|
| 519 | + ); |
|
| 520 | + |
|
| 521 | + }// get_free_courses_meta_query |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * The metat query for courses that are free |
|
| 525 | + * |
|
| 526 | + * @since 1.9.0 |
|
| 527 | + * @return array $wp_query_meta_query_args_param |
|
| 528 | + */ |
|
| 529 | + public static function get_paid_courses_meta_query_args(){ |
|
| 530 | + |
|
| 531 | + $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | + |
|
| 533 | + return array( |
|
| 534 | + array( |
|
| 535 | + 'key' => '_course_woocommerce_product', |
|
| 536 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | + // query |
|
| 538 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | + 'compare' => 'IN', |
|
| 540 | + ), |
|
| 541 | + ); |
|
| 542 | + |
|
| 543 | + }// get_free_courses_meta_query |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * The WordPress Query args |
|
| 547 | + * for paid products on sale |
|
| 548 | + * |
|
| 549 | + * @since 1.9.0 |
|
| 550 | + * @return array $product_query_args |
|
| 551 | + */ |
|
| 552 | + public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | + |
|
| 554 | + $args = array( |
|
| 555 | + 'post_type' => 'product', |
|
| 556 | + 'posts_per_page' => 1000, |
|
| 557 | + 'orderby' => 'date', |
|
| 558 | + 'order' => 'DESC', |
|
| 559 | + 'suppress_filters' => 0 |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + $args[ 'fields' ] = 'ids'; |
|
| 563 | + |
|
| 564 | + $args[ 'meta_query' ] = array( |
|
| 565 | + 'relation' => 'AND', |
|
| 566 | + array( |
|
| 567 | + 'key'=> '_regular_price', |
|
| 568 | + 'compare' => '>', |
|
| 569 | + 'value' => 0, |
|
| 570 | + ), |
|
| 571 | + array( |
|
| 572 | + 'key'=> '_sale_price', |
|
| 573 | + 'compare' => '>', |
|
| 574 | + 'value' => 0, |
|
| 575 | + ), |
|
| 576 | + ); |
|
| 577 | + |
|
| 578 | + return $args; |
|
| 579 | + |
|
| 580 | + } // get_paid_products_on_sale_query_args |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Return the WordPress query args for |
|
| 585 | + * products not on sale but that is not a free |
|
| 586 | + * |
|
| 587 | + * @since 1.9.0 |
|
| 588 | + * |
|
| 589 | + * @return array |
|
| 590 | + */ |
|
| 591 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | + |
|
| 593 | + $args = array( |
|
| 594 | + 'post_type' => 'product', |
|
| 595 | + 'posts_per_page' => 1000, |
|
| 596 | + 'orderby' => 'date', |
|
| 597 | + 'order' => 'DESC', |
|
| 598 | + 'suppress_filters' => 0 |
|
| 599 | + ); |
|
| 600 | + |
|
| 601 | + $args[ 'fields' ] = 'ids'; |
|
| 602 | + $args[ 'meta_query' ] = array( |
|
| 603 | + 'relation' => 'AND', |
|
| 604 | + array( |
|
| 605 | + 'key'=> '_regular_price', |
|
| 606 | + 'compare' => '>', |
|
| 607 | + 'value' => 0, |
|
| 608 | + ), |
|
| 609 | + array( |
|
| 610 | + 'key'=> '_sale_price', |
|
| 611 | + 'compare' => '=', |
|
| 612 | + 'value' => '', |
|
| 613 | + ), |
|
| 614 | + ); |
|
| 615 | + |
|
| 616 | + return $args; |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + } // get_paid_courses_meta_query |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Get all WooCommerce non-free product id's |
|
| 623 | + * |
|
| 624 | + * @since 1.9.0 |
|
| 625 | + * |
|
| 626 | + * @return array $woocommerce_paid_product_ids |
|
| 627 | + */ |
|
| 628 | + public static function get_paid_product_ids(){ |
|
| 629 | + |
|
| 630 | + // get all the paid WooCommerce products that has regular |
|
| 631 | + // and sale price greater than 0 |
|
| 632 | + // will be used later to check for course with the id as meta |
|
| 633 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | + |
|
| 635 | + // get all the paid WooCommerce products that has regular price |
|
| 636 | + // greater than 0 without a sale price |
|
| 637 | + // will be used later to check for course with the id as meta |
|
| 638 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | + |
|
| 640 | + // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | + // sale but regular price greater than zero |
|
| 642 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | + |
|
| 644 | + // if |
|
| 645 | + if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | + return array( ); |
|
| 647 | + } |
|
| 648 | + return $woocommerce_paid_product_ids; |
|
| 649 | + |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Get all free courses. |
|
| 654 | + * |
|
| 655 | + * This course that have a WC product attached |
|
| 656 | + * that has a price or sale price of zero and |
|
| 657 | + * other courses with no WooCommerce products |
|
| 658 | + * attached. |
|
| 659 | + * |
|
| 660 | + * @since 1.9.0 |
|
| 661 | + * |
|
| 662 | + * @return array |
|
| 663 | + */ |
|
| 664 | + public static function get_free_courses(){ |
|
| 665 | + |
|
| 666 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | + |
|
| 669 | + // don't show any paid courses |
|
| 670 | + $courses = self::get_paid_courses(); |
|
| 671 | + $ids = array(); |
|
| 672 | + foreach( $courses as $course ){ |
|
| 673 | + $ids[] = $course->ID; |
|
| 674 | + } |
|
| 675 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | + |
|
| 677 | + return get_posts( $free_course_query_args ); |
|
| 678 | + |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Return all products that are not free |
|
| 683 | + * |
|
| 684 | + * @since 1.9.0 |
|
| 685 | + * @return array |
|
| 686 | + */ |
|
| 687 | + public static function get_paid_courses(){ |
|
| 688 | + |
|
| 689 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | + |
|
| 691 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | + |
|
| 693 | + return get_posts( $paid_course_query_args ); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Show the WooCommerce add to cart button for the current course |
|
| 698 | + * |
|
| 699 | + * The function will only show the button if |
|
| 700 | + * 1- the user can buy the course |
|
| 701 | + * 2- if they have completed their pre-requisite |
|
| 702 | + * 3- if the course has a valid product attached |
|
| 703 | + * |
|
| 704 | + * @since 1.9.0 |
|
| 705 | + * @param int $course_id |
|
| 706 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | + */ |
|
| 708 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | + |
|
| 710 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | + return ''; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | + |
|
| 716 | + // Check if customer purchased the product |
|
| 717 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | + || empty( $wc_post_id ) ) { |
|
| 719 | + |
|
| 720 | + return ''; |
|
| 721 | + |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | + // Get the product |
|
| 726 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | + |
|
| 728 | + // do not show the button for invalid products, non purchasable products, out |
|
| 729 | + // of stock product or if course is already in cart |
|
| 730 | + if ( ! isset ( $product ) |
|
| 731 | + || ! is_object( $product ) |
|
| 732 | + || ! $product->is_purchasable() |
|
| 733 | + || ! $product->is_in_stock() |
|
| 734 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | + |
|
| 736 | + return ''; |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + // |
|
| 741 | + // button output: |
|
| 742 | + // |
|
| 743 | + ?> |
|
| 744 | 744 | |
| 745 | 745 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
| 746 | 746 | class="cart" |
@@ -773,54 +773,54 @@ discard block |
||
| 773 | 773 | </form> |
| 774 | 774 | |
| 775 | 775 | <?php |
| 776 | - } // end the_add_to_cart_button_html |
|
| 776 | + } // end the_add_to_cart_button_html |
|
| 777 | 777 | |
| 778 | - /** |
|
| 779 | - * Alter the no permissions message on the single course page |
|
| 780 | - * Changes the message to a WooCommerce specific message. |
|
| 781 | - * |
|
| 782 | - * @since 1.9.0 |
|
| 783 | - * |
|
| 784 | - * @param $message |
|
| 785 | - * @param $post_id |
|
| 786 | - * |
|
| 787 | - * @return string $message |
|
| 788 | - */ |
|
| 789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 778 | + /** |
|
| 779 | + * Alter the no permissions message on the single course page |
|
| 780 | + * Changes the message to a WooCommerce specific message. |
|
| 781 | + * |
|
| 782 | + * @since 1.9.0 |
|
| 783 | + * |
|
| 784 | + * @param $message |
|
| 785 | + * @param $post_id |
|
| 786 | + * |
|
| 787 | + * @return string $message |
|
| 788 | + */ |
|
| 789 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 790 | 790 | |
| 791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | - return $message; |
|
| 793 | - } |
|
| 791 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | + return $message; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 795 | + $product_id = self::get_course_product_id( $post_id ); |
|
| 796 | 796 | |
| 797 | - if( ! $product_id |
|
| 798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 797 | + if( ! $product_id |
|
| 798 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 799 | 799 | |
| 800 | - return $message; |
|
| 800 | + return $message; |
|
| 801 | 801 | |
| 802 | - } |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - ob_start(); |
|
| 805 | - self::the_course_no_permissions_message( $post_id ); |
|
| 806 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 804 | + ob_start(); |
|
| 805 | + self::the_course_no_permissions_message( $post_id ); |
|
| 806 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 807 | 807 | |
| 808 | - return $woocommerce_course_no_permissions_message ; |
|
| 808 | + return $woocommerce_course_no_permissions_message ; |
|
| 809 | 809 | |
| 810 | - } |
|
| 811 | - /** |
|
| 812 | - * Show the no permissions message when a user is logged in |
|
| 813 | - * and have not yet purchased the current course |
|
| 814 | - * |
|
| 815 | - * @since 1.9.0 |
|
| 816 | - */ |
|
| 817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 810 | + } |
|
| 811 | + /** |
|
| 812 | + * Show the no permissions message when a user is logged in |
|
| 813 | + * and have not yet purchased the current course |
|
| 814 | + * |
|
| 815 | + * @since 1.9.0 |
|
| 816 | + */ |
|
| 817 | + public static function the_course_no_permissions_message( $course_id ){ |
|
| 818 | 818 | |
| 819 | - // login link |
|
| 820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 819 | + // login link |
|
| 820 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 822 | 822 | |
| 823 | - ?> |
|
| 823 | + ?> |
|
| 824 | 824 | |
| 825 | 825 | <span class="add-to-cart-login"> |
| 826 | 826 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -828,110 +828,110 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | <?php } |
| 830 | 830 | |
| 831 | - /** |
|
| 832 | - * Checks if a user has bought a product item. |
|
| 833 | - * |
|
| 834 | - * @since 1.9.0 |
|
| 835 | - * |
|
| 836 | - * @param int $user_id |
|
| 837 | - * @param int $product_id |
|
| 838 | - * |
|
| 839 | - * @return bool |
|
| 840 | - */ |
|
| 841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 831 | + /** |
|
| 832 | + * Checks if a user has bought a product item. |
|
| 833 | + * |
|
| 834 | + * @since 1.9.0 |
|
| 835 | + * |
|
| 836 | + * @param int $user_id |
|
| 837 | + * @param int $product_id |
|
| 838 | + * |
|
| 839 | + * @return bool |
|
| 840 | + */ |
|
| 841 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 842 | 842 | |
| 843 | - $orders = get_posts( array( |
|
| 844 | - 'posts_per_page' => -1, |
|
| 845 | - 'meta_key' => '_customer_user', |
|
| 846 | - 'meta_value' => intval( $user_id ), |
|
| 847 | - 'post_type' => 'shop_order', |
|
| 848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | - ) ); |
|
| 843 | + $orders = get_posts( array( |
|
| 844 | + 'posts_per_page' => -1, |
|
| 845 | + 'meta_key' => '_customer_user', |
|
| 846 | + 'meta_value' => intval( $user_id ), |
|
| 847 | + 'post_type' => 'shop_order', |
|
| 848 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | + ) ); |
|
| 850 | 850 | |
| 851 | - foreach ( $orders as $order_id ) { |
|
| 851 | + foreach ( $orders as $order_id ) { |
|
| 852 | 852 | |
| 853 | - $order = new WC_Order( $order_id->ID ); |
|
| 853 | + $order = new WC_Order( $order_id->ID ); |
|
| 854 | 854 | |
| 855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 855 | + if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 856 | 856 | |
| 857 | - continue; |
|
| 858 | - } |
|
| 857 | + continue; |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 860 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 861 | 861 | |
| 862 | - continue; |
|
| 862 | + continue; |
|
| 863 | 863 | |
| 864 | - } |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - foreach( $order->get_items() as $item ) { |
|
| 866 | + foreach( $order->get_items() as $item ) { |
|
| 867 | 867 | |
| 868 | - // Check if user has bought product |
|
| 869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 868 | + // Check if user has bought product |
|
| 869 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 870 | 870 | |
| 871 | - // Check if user has an active subscription for product |
|
| 872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | - if( $sub_key ) { |
|
| 875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | - if( 'active' == $sub['status'] ) { |
|
| 878 | - return true; |
|
| 879 | - } else { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - } |
|
| 871 | + // Check if user has an active subscription for product |
|
| 872 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | + if( $sub_key ) { |
|
| 875 | + $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | + if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | + if( 'active' == $sub['status'] ) { |
|
| 878 | + return true; |
|
| 879 | + } else { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | 885 | |
| 886 | - // Customer has bought product |
|
| 887 | - return true; |
|
| 888 | - } // End If Statement |
|
| 886 | + // Customer has bought product |
|
| 887 | + return true; |
|
| 888 | + } // End If Statement |
|
| 889 | 889 | |
| 890 | - } // End For each item |
|
| 890 | + } // End For each item |
|
| 891 | 891 | |
| 892 | - } // End For each order |
|
| 892 | + } // End For each order |
|
| 893 | 893 | |
| 894 | - } // end has customer bought product |
|
| 894 | + } // end has customer bought product |
|
| 895 | 895 | |
| 896 | - /** |
|
| 897 | - * Return the product id for the given course |
|
| 898 | - * |
|
| 899 | - * @since 1.9.0 |
|
| 900 | - * |
|
| 901 | - * @param int $course_id |
|
| 902 | - * |
|
| 903 | - * @return string $woocommerce_product_id or false if none exist |
|
| 904 | - * |
|
| 905 | - */ |
|
| 906 | - public static function get_course_product_id( $course_id ){ |
|
| 896 | + /** |
|
| 897 | + * Return the product id for the given course |
|
| 898 | + * |
|
| 899 | + * @since 1.9.0 |
|
| 900 | + * |
|
| 901 | + * @param int $course_id |
|
| 902 | + * |
|
| 903 | + * @return string $woocommerce_product_id or false if none exist |
|
| 904 | + * |
|
| 905 | + */ |
|
| 906 | + public static function get_course_product_id( $course_id ){ |
|
| 907 | 907 | |
| 908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 908 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 909 | 909 | |
| 910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | - return false; |
|
| 912 | - } |
|
| 910 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | + return false; |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | - return $product_id; |
|
| 914 | + return $product_id; |
|
| 915 | 915 | |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - /** |
|
| 919 | - * Alter the body classes adding WooCommerce to the body |
|
| 920 | - * |
|
| 921 | - * @param array $classes |
|
| 922 | - * @return array |
|
| 923 | - */ |
|
| 924 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 918 | + /** |
|
| 919 | + * Alter the body classes adding WooCommerce to the body |
|
| 920 | + * |
|
| 921 | + * @param array $classes |
|
| 922 | + * @return array |
|
| 923 | + */ |
|
| 924 | + public static function add_woocommerce_body_class( $classes ){ |
|
| 925 | 925 | |
| 926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 926 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 927 | 927 | |
| 928 | - $classes[] ='woocommerce'; |
|
| 928 | + $classes[] ='woocommerce'; |
|
| 929 | 929 | |
| 930 | - } |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | 932 | |
| 933 | - return $classes; |
|
| 933 | + return $classes; |
|
| 934 | 934 | |
| 935 | - } |
|
| 935 | + } |
|
| 936 | 936 | |
| 937 | 937 | }// end Sensei_WC |