@@ -5,18 +5,18 @@ discard block |
||
| 5 | 5 | * Output tags. |
| 6 | 6 | ***************************************************************************************************/ |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * sensei_course_archive_next_link function. |
|
| 10 | - * |
|
| 11 | - * @access public |
|
| 12 | - * @param string $type (default: 'newcourses') |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
| 8 | + /** |
|
| 9 | + * sensei_course_archive_next_link function. |
|
| 10 | + * |
|
| 11 | + * @access public |
|
| 12 | + * @param string $type (default: 'newcourses') |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
| 16 | 16 | |
| 17 | - _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
| 17 | + _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
| 18 | 18 | |
| 19 | - } // End sensei_course_archive_next_link() |
|
| 19 | + } // End sensei_course_archive_next_link() |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * course_single_lessons function. |
@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function course_single_lessons() { |
| 28 | 28 | |
| 29 | - // load backwards compatible template name if it exists in the users theme |
|
| 30 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
| 31 | - if( $located_template ){ |
|
| 29 | + // load backwards compatible template name if it exists in the users theme |
|
| 30 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
| 31 | + if( $located_template ){ |
|
| 32 | 32 | |
| 33 | - Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
| 34 | - return; |
|
| 33 | + Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
| 34 | + return; |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | Sensei_Templates::get_template( 'single-course/lessons.php' ); |
| 39 | 39 | |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function lesson_single_meta() { |
| 50 | 50 | |
| 51 | - _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
| 52 | - sensei_the_single_lesson_meta(); |
|
| 51 | + _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
| 52 | + sensei_the_single_lesson_meta(); |
|
| 53 | 53 | |
| 54 | 54 | } // End lesson_single_meta() |
| 55 | 55 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @access public |
| 61 | 61 | * @param bool $return (default: false) |
| 62 | 62 | * @return void |
| 63 | - * @deprecated since 1.9.0 |
|
| 63 | + * @deprecated since 1.9.0 |
|
| 64 | 64 | */ |
| 65 | 65 | function quiz_questions( $return = false ) { |
| 66 | 66 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | * @access public |
| 75 | 75 | * @since 1.3.0 |
| 76 | 76 | * @return void |
| 77 | - * @deprecated |
|
| 77 | + * @deprecated |
|
| 78 | 78 | */ |
| 79 | 79 | function quiz_question_type( $question_type = 'multiple-choice' ) { |
| 80 | 80 | |
| 81 | - Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 81 | + Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 82 | 82 | |
| 83 | 83 | } // End lesson_single_meta() |
| 84 | 84 | |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | /** |
| 90 | 90 | * sensei_check_prerequisite_course function. |
| 91 | 91 | * |
| 92 | - * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 92 | + * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 93 | 93 | * @access public |
| 94 | 94 | * @param mixed $course_id |
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | 97 | function sensei_check_prerequisite_course( $course_id ) { |
| 98 | 98 | |
| 99 | - return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 99 | + return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
| 100 | 100 | |
| 101 | 101 | } // End sensei_check_prerequisite_course() |
| 102 | 102 | |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | <span><input name="course_start" type="submit" class="course-start" value="<?php _e( 'Start taking this Course', 'woothemes-sensei' ); ?>"/></span> |
| 121 | 121 | |
| 122 | 122 | </form><?php |
| 123 | - } // End If Statement |
|
| 123 | + } // End If Statement |
|
| 124 | 124 | } // End sensei_start_course_form() |
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * sensei_wc_add_to_cart function. |
| 129 | 129 | * |
| 130 | - * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
| 130 | + * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
| 131 | 131 | * @access public |
| 132 | 132 | * @param mixed $course_id |
| 133 | 133 | * @return void |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @return bool |
| 148 | 148 | */ |
| 149 | 149 | function sensei_check_if_product_is_in_cart( $wc_product_id = 0 ) { |
| 150 | - return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
| 150 | + return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
| 151 | 151 | } // End sensei_check_if_product_is_in_cart() |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | function sensei_simple_course_price( $post_id ) { |
| 161 | 161 | |
| 162 | 162 | //WooCommerce Pricing |
| 163 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 164 | - $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
| 165 | - if ( 0 < $wc_post_id ) { |
|
| 166 | - // Get the product |
|
| 167 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 163 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 164 | + $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
| 165 | + if ( 0 < $wc_post_id ) { |
|
| 166 | + // Get the product |
|
| 167 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 168 | 168 | |
| 169 | - if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
| 169 | + if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
| 170 | 170 | <span class="course-price"><?php echo $product->get_price_html(); ?></span> |
| 171 | 171 | <?php } // End If Statement |
| 172 | - } // End If Statement |
|
| 173 | - } // End If Statement |
|
| 172 | + } // End If Statement |
|
| 173 | + } // End If Statement |
|
| 174 | 174 | } // End sensei_simple_course_price() |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | |
| 199 | 199 | if ( ! $query->is_main_query() ) |
| 200 | - return; |
|
| 200 | + return; |
|
| 201 | 201 | |
| 202 | 202 | // Apply Filter only if on frontend and when course archive is running |
| 203 | 203 | $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | if ( ! is_admin() && 0 < $course_page_id && 0 < intval( $query->get( 'page_id' ) ) && $query->get( 'page_id' ) == $course_page_id ) { |
| 206 | 206 | // Check for pagination settings |
| 207 | 207 | if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
| 208 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 209 | - } else { |
|
| 210 | - $amount = $query->get( 'posts_per_page' ); |
|
| 211 | - } // End If Statement |
|
| 212 | - $query->set( 'posts_per_page', $amount ); |
|
| 208 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 209 | + } else { |
|
| 210 | + $amount = $query->get( 'posts_per_page' ); |
|
| 211 | + } // End If Statement |
|
| 212 | + $query->set( 'posts_per_page', $amount ); |
|
| 213 | 213 | } // End If Statement |
| 214 | 214 | } // End sensei_course_archive_filter() |
| 215 | 215 | add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 ); |
@@ -248,70 +248,70 @@ discard block |
||
| 248 | 248 | $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
| 249 | 249 | $all_lessons = array(); |
| 250 | 250 | |
| 251 | - $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
| 252 | - |
|
| 253 | - if( !empty( $modules ) ){ |
|
| 254 | - foreach( (array) $modules as $module ) { |
|
| 255 | - |
|
| 256 | - $args = array( |
|
| 257 | - 'post_type' => 'lesson', |
|
| 258 | - 'post_status' => 'publish', |
|
| 259 | - 'posts_per_page' => -1, |
|
| 260 | - 'meta_query' => array( |
|
| 261 | - array( |
|
| 262 | - 'key' => '_lesson_course', |
|
| 263 | - 'value' => intval( $lesson_course_id ), |
|
| 264 | - 'compare' => '=' |
|
| 265 | - ) |
|
| 266 | - ), |
|
| 267 | - 'tax_query' => array( |
|
| 268 | - array( |
|
| 269 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 270 | - 'field' => 'id', |
|
| 271 | - 'terms' => intval( $module->term_id ) |
|
| 272 | - ) |
|
| 273 | - ), |
|
| 274 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
| 275 | - 'orderby' => 'meta_value_num date', |
|
| 276 | - 'order' => 'ASC', |
|
| 277 | - 'suppress_filters' => 0 |
|
| 278 | - ); |
|
| 279 | - |
|
| 280 | - $lessons = get_posts( $args ); |
|
| 281 | - if ( 0 < count( $lessons ) ) { |
|
| 282 | - foreach ($lessons as $lesson_item){ |
|
| 283 | - $all_lessons[] = $lesson_item->ID; |
|
| 284 | - } // End For Loop |
|
| 285 | - } // End If Statement |
|
| 286 | - |
|
| 287 | - }//end for each |
|
| 288 | - |
|
| 289 | - }// end if empty modules |
|
| 290 | - |
|
| 291 | - $args = array( |
|
| 292 | - 'post_type' => 'lesson', |
|
| 293 | - 'posts_per_page' => -1, |
|
| 294 | - 'suppress_filters' => 0, |
|
| 295 | - 'meta_key' => '_order_' . $lesson_course_id, |
|
| 296 | - 'orderby' => 'meta_value_num date', |
|
| 297 | - 'order' => 'ASC', |
|
| 298 | - 'meta_query' => array( |
|
| 299 | - array( |
|
| 300 | - 'key' => '_lesson_course', |
|
| 301 | - 'value' => intval( $lesson_course_id ), |
|
| 302 | - ), |
|
| 303 | - ), |
|
| 304 | - 'post__not_in' => $all_lessons, |
|
| 305 | - ); |
|
| 306 | - |
|
| 307 | - $other_lessons = get_posts( $args ); |
|
| 308 | - if ( 0 < count( $other_lessons ) ) { |
|
| 251 | + $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
| 252 | + |
|
| 253 | + if( !empty( $modules ) ){ |
|
| 254 | + foreach( (array) $modules as $module ) { |
|
| 255 | + |
|
| 256 | + $args = array( |
|
| 257 | + 'post_type' => 'lesson', |
|
| 258 | + 'post_status' => 'publish', |
|
| 259 | + 'posts_per_page' => -1, |
|
| 260 | + 'meta_query' => array( |
|
| 261 | + array( |
|
| 262 | + 'key' => '_lesson_course', |
|
| 263 | + 'value' => intval( $lesson_course_id ), |
|
| 264 | + 'compare' => '=' |
|
| 265 | + ) |
|
| 266 | + ), |
|
| 267 | + 'tax_query' => array( |
|
| 268 | + array( |
|
| 269 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 270 | + 'field' => 'id', |
|
| 271 | + 'terms' => intval( $module->term_id ) |
|
| 272 | + ) |
|
| 273 | + ), |
|
| 274 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
| 275 | + 'orderby' => 'meta_value_num date', |
|
| 276 | + 'order' => 'ASC', |
|
| 277 | + 'suppress_filters' => 0 |
|
| 278 | + ); |
|
| 279 | + |
|
| 280 | + $lessons = get_posts( $args ); |
|
| 281 | + if ( 0 < count( $lessons ) ) { |
|
| 282 | + foreach ($lessons as $lesson_item){ |
|
| 283 | + $all_lessons[] = $lesson_item->ID; |
|
| 284 | + } // End For Loop |
|
| 285 | + } // End If Statement |
|
| 286 | + |
|
| 287 | + }//end for each |
|
| 288 | + |
|
| 289 | + }// end if empty modules |
|
| 290 | + |
|
| 291 | + $args = array( |
|
| 292 | + 'post_type' => 'lesson', |
|
| 293 | + 'posts_per_page' => -1, |
|
| 294 | + 'suppress_filters' => 0, |
|
| 295 | + 'meta_key' => '_order_' . $lesson_course_id, |
|
| 296 | + 'orderby' => 'meta_value_num date', |
|
| 297 | + 'order' => 'ASC', |
|
| 298 | + 'meta_query' => array( |
|
| 299 | + array( |
|
| 300 | + 'key' => '_lesson_course', |
|
| 301 | + 'value' => intval( $lesson_course_id ), |
|
| 302 | + ), |
|
| 303 | + ), |
|
| 304 | + 'post__not_in' => $all_lessons, |
|
| 305 | + ); |
|
| 306 | + |
|
| 307 | + $other_lessons = get_posts( $args ); |
|
| 308 | + if ( 0 < count( $other_lessons ) ) { |
|
| 309 | 309 | foreach ($other_lessons as $lesson_item){ |
| 310 | 310 | $all_lessons[] = $lesson_item->ID; |
| 311 | 311 | } // End For Loop |
| 312 | 312 | } // End If Statement |
| 313 | 313 | |
| 314 | - if ( 0 < count( $all_lessons ) ) { |
|
| 314 | + if ( 0 < count( $all_lessons ) ) { |
|
| 315 | 315 | $found_index = false; |
| 316 | 316 | foreach ( $all_lessons as $lesson ){ |
| 317 | 317 | if ( $found_index && $return_values['next_lesson'] == 0 ) { |
@@ -342,9 +342,9 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | function sensei_get_excerpt( $post_id = '' ) { |
| 344 | 344 | |
| 345 | - global $post; |
|
| 346 | - _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
| 347 | - return get_the_excerpt(); |
|
| 345 | + global $post; |
|
| 346 | + _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
| 347 | + return get_the_excerpt(); |
|
| 348 | 348 | |
| 349 | 349 | } |
| 350 | 350 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | */ |
| 370 | 370 | function sensei_has_user_completed_prerequisite_lesson( $current_lesson_id, $user_id ) { |
| 371 | 371 | |
| 372 | - return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
| 372 | + return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
| 373 | 373 | |
| 374 | 374 | } // End sensei_has_user_completed_prerequisite_lesson() |
| 375 | 375 | |
@@ -484,27 +484,27 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | }else{ |
| 486 | 486 | |
| 487 | - // if the loop has not been initiated check the first module has lessons |
|
| 488 | - if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
| 487 | + // if the loop has not been initiated check the first module has lessons |
|
| 488 | + if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
| 489 | 489 | |
| 490 | - $index = 0; |
|
| 490 | + $index = 0; |
|
| 491 | 491 | |
| 492 | - if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
| 493 | - // setup the query for the module lessons |
|
| 494 | - $course_id = $sensei_modules_loop['course_id']; |
|
| 492 | + if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
| 493 | + // setup the query for the module lessons |
|
| 494 | + $course_id = $sensei_modules_loop['course_id']; |
|
| 495 | 495 | |
| 496 | - $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
| 497 | - $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
| 496 | + $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
| 497 | + $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
| 498 | 498 | |
| 499 | - // setup the global wp-query only if the lessons |
|
| 500 | - if( $modules_query->have_posts() ){ |
|
| 499 | + // setup the global wp-query only if the lessons |
|
| 500 | + if( $modules_query->have_posts() ){ |
|
| 501 | 501 | |
| 502 | - return true; |
|
| 502 | + return true; |
|
| 503 | 503 | |
| 504 | - } |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - // default to false if the first module doesn't have posts |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + // default to false if the first module doesn't have posts |
|
| 508 | 508 | return false; |
| 509 | 509 | |
| 510 | 510 | } |
@@ -612,46 +612,46 @@ discard block |
||
| 612 | 612 | return ''; |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - global $sensei_modules_loop; |
|
| 616 | - $module_title = $sensei_modules_loop['current_module']->name; |
|
| 617 | - $module_term_id = $sensei_modules_loop['current_module']->term_id; |
|
| 618 | - $course_id = $sensei_modules_loop['course_id']; |
|
| 619 | - $module_progress = Sensei()->modules->get_user_module_progress( $module_term_id, $course_id, get_current_user_id() ); |
|
| 615 | + global $sensei_modules_loop; |
|
| 616 | + $module_title = $sensei_modules_loop['current_module']->name; |
|
| 617 | + $module_term_id = $sensei_modules_loop['current_module']->term_id; |
|
| 618 | + $course_id = $sensei_modules_loop['course_id']; |
|
| 619 | + $module_progress = Sensei()->modules->get_user_module_progress( $module_term_id, $course_id, get_current_user_id() ); |
|
| 620 | 620 | |
| 621 | - $module_status = ''; |
|
| 622 | - if ( $module_progress && $module_progress > 0) { |
|
| 621 | + $module_status = ''; |
|
| 622 | + if ( $module_progress && $module_progress > 0) { |
|
| 623 | 623 | |
| 624 | - $module_status = __('Completed', 'woothemes-sensei'); |
|
| 624 | + $module_status = __('Completed', 'woothemes-sensei'); |
|
| 625 | 625 | |
| 626 | - if ($module_progress < 100) { |
|
| 626 | + if ($module_progress < 100) { |
|
| 627 | 627 | |
| 628 | - $module_status = __('In progress', 'woothemes-sensei'); |
|
| 628 | + $module_status = __('In progress', 'woothemes-sensei'); |
|
| 629 | 629 | |
| 630 | - } |
|
| 630 | + } |
|
| 631 | 631 | |
| 632 | - } |
|
| 632 | + } |
|
| 633 | 633 | |
| 634 | 634 | if ( empty( $module_status ) ){ |
| 635 | 635 | return ''; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | $status_class = strtolower( str_replace( ' ', '-', $module_status ) ); |
| 639 | - $module_status_html = '<p class="status module-status ' . $status_class . '">' |
|
| 640 | - . $module_status |
|
| 641 | - . '</p>'; |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * Filter the module status. |
|
| 645 | - * |
|
| 646 | - * This fires within the sensei_get_the_module_status function. |
|
| 647 | - * |
|
| 648 | - * @since 1.9.0 |
|
| 649 | - * |
|
| 650 | - * @param $module_status_html |
|
| 651 | - * @param $module_term_id |
|
| 652 | - * @param $course_id |
|
| 653 | - */ |
|
| 654 | - return apply_filters( 'sensei_the_module_status_html', $module_status_html , $module_term_id, $course_id ); |
|
| 639 | + $module_status_html = '<p class="status module-status ' . $status_class . '">' |
|
| 640 | + . $module_status |
|
| 641 | + . '</p>'; |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * Filter the module status. |
|
| 645 | + * |
|
| 646 | + * This fires within the sensei_get_the_module_status function. |
|
| 647 | + * |
|
| 648 | + * @since 1.9.0 |
|
| 649 | + * |
|
| 650 | + * @param $module_status_html |
|
| 651 | + * @param $module_term_id |
|
| 652 | + * @param $course_id |
|
| 653 | + */ |
|
| 654 | + return apply_filters( 'sensei_the_module_status_html', $module_status_html , $module_term_id, $course_id ); |
|
| 655 | 655 | |
| 656 | 656 | } |
| 657 | 657 | |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | */ |
| 662 | 662 | function sensei_the_module_status(){ |
| 663 | 663 | |
| 664 | - echo sensei_get_the_module_status(); |
|
| 664 | + echo sensei_get_the_module_status(); |
|
| 665 | 665 | |
| 666 | 666 | } |
| 667 | 667 | |
@@ -682,21 +682,21 @@ discard block |
||
| 682 | 682 | */ |
| 683 | 683 | function sensei_quiz_has_questions(){ |
| 684 | 684 | |
| 685 | - global $sensei_question_loop; |
|
| 685 | + global $sensei_question_loop; |
|
| 686 | 686 | |
| 687 | - if( !isset( $sensei_question_loop['total'] ) ){ |
|
| 688 | - return false; |
|
| 689 | - } |
|
| 687 | + if( !isset( $sensei_question_loop['total'] ) ){ |
|
| 688 | + return false; |
|
| 689 | + } |
|
| 690 | 690 | |
| 691 | - if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
| 691 | + if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
| 692 | 692 | |
| 693 | - return true; |
|
| 693 | + return true; |
|
| 694 | 694 | |
| 695 | - }else{ |
|
| 695 | + }else{ |
|
| 696 | 696 | |
| 697 | - return false; |
|
| 697 | + return false; |
|
| 698 | 698 | |
| 699 | - } |
|
| 699 | + } |
|
| 700 | 700 | |
| 701 | 701 | }// end sensei_quiz_has_questions |
| 702 | 702 | |
@@ -707,15 +707,14 @@ discard block |
||
| 707 | 707 | * execution. |
| 708 | 708 | * |
| 709 | 709 | * @since 1.9.0 |
| 710 | - |
|
| 711 | 710 | */ |
| 712 | 711 | function sensei_setup_the_question(){ |
| 713 | 712 | |
| 714 | - global $sensei_question_loop; |
|
| 713 | + global $sensei_question_loop; |
|
| 715 | 714 | |
| 716 | - $sensei_question_loop['current']++; |
|
| 717 | - $index = $sensei_question_loop['current']; |
|
| 718 | - $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
| 715 | + $sensei_question_loop['current']++; |
|
| 716 | + $index = $sensei_question_loop['current']; |
|
| 717 | + $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
| 719 | 718 | |
| 720 | 719 | |
| 721 | 720 | }// end sensei_setup_the_question |
@@ -728,12 +727,12 @@ discard block |
||
| 728 | 727 | */ |
| 729 | 728 | function sensei_the_question_content(){ |
| 730 | 729 | |
| 731 | - global $sensei_question_loop; |
|
| 730 | + global $sensei_question_loop; |
|
| 732 | 731 | |
| 733 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 732 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 734 | 733 | |
| 735 | - // load the template that displays the question information. |
|
| 736 | - WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
| 734 | + // load the template that displays the question information. |
|
| 735 | + WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
| 737 | 736 | |
| 738 | 737 | }// end sensei_the_question_content |
| 739 | 738 | |
@@ -744,26 +743,26 @@ discard block |
||
| 744 | 743 | */ |
| 745 | 744 | function sensei_the_question_class(){ |
| 746 | 745 | |
| 747 | - global $sensei_question_loop; |
|
| 746 | + global $sensei_question_loop; |
|
| 748 | 747 | |
| 749 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 748 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
| 750 | 749 | |
| 751 | - /** |
|
| 752 | - * filter the sensei question class within |
|
| 753 | - * the quiz question loop. |
|
| 754 | - * |
|
| 755 | - * @since 1.9.0 |
|
| 756 | - */ |
|
| 757 | - $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
| 750 | + /** |
|
| 751 | + * filter the sensei question class within |
|
| 752 | + * the quiz question loop. |
|
| 753 | + * |
|
| 754 | + * @since 1.9.0 |
|
| 755 | + */ |
|
| 756 | + $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
| 758 | 757 | |
| 759 | - $html_classes = ''; |
|
| 760 | - foreach( $classes as $class ){ |
|
| 758 | + $html_classes = ''; |
|
| 759 | + foreach( $classes as $class ){ |
|
| 761 | 760 | |
| 762 | - $html_classes .= $class . ' '; |
|
| 761 | + $html_classes .= $class . ' '; |
|
| 763 | 762 | |
| 764 | - }// end foreach |
|
| 763 | + }// end foreach |
|
| 765 | 764 | |
| 766 | - esc_attr_e( trim( $html_classes ) ); |
|
| 765 | + esc_attr_e( trim( $html_classes ) ); |
|
| 767 | 766 | |
| 768 | 767 | } |
| 769 | 768 | |
@@ -774,12 +773,12 @@ discard block |
||
| 774 | 773 | */ |
| 775 | 774 | function sensei_get_the_question_id( ){ |
| 776 | 775 | |
| 777 | - global $sensei_question_loop; |
|
| 778 | - if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
| 776 | + global $sensei_question_loop; |
|
| 777 | + if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
| 779 | 778 | |
| 780 | - return $sensei_question_loop['current_question']->ID; |
|
| 779 | + return $sensei_question_loop['current_question']->ID; |
|
| 781 | 780 | |
| 782 | - } |
|
| 781 | + } |
|
| 783 | 782 | |
| 784 | 783 | }// end sensei_the_question_id |
| 785 | 784 | |
@@ -806,63 +805,63 @@ discard block |
||
| 806 | 805 | */ |
| 807 | 806 | function sensei_can_user_view_lesson( $lesson_id = '', $user_id = '' ){ |
| 808 | 807 | |
| 809 | - if( empty( $lesson_id ) ){ |
|
| 808 | + if( empty( $lesson_id ) ){ |
|
| 810 | 809 | |
| 811 | - $lesson_id = get_the_ID(); |
|
| 810 | + $lesson_id = get_the_ID(); |
|
| 812 | 811 | |
| 813 | - } |
|
| 812 | + } |
|
| 814 | 813 | |
| 815 | - if( empty( $user_id ) ){ |
|
| 814 | + if( empty( $user_id ) ){ |
|
| 816 | 815 | |
| 817 | - $user_id = get_current_user_id(); |
|
| 816 | + $user_id = get_current_user_id(); |
|
| 818 | 817 | |
| 819 | - } |
|
| 818 | + } |
|
| 820 | 819 | |
| 821 | - // Check for prerequisite lesson completions |
|
| 822 | - $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
| 823 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 824 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
| 820 | + // Check for prerequisite lesson completions |
|
| 821 | + $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
| 822 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 823 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
| 825 | 824 | |
| 826 | - $is_preview = false; |
|
| 827 | - if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
| 825 | + $is_preview = false; |
|
| 826 | + if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
| 828 | 827 | |
| 829 | - $is_preview = true; |
|
| 830 | - $pre_requisite_complete = true; |
|
| 828 | + $is_preview = true; |
|
| 829 | + $pre_requisite_complete = true; |
|
| 831 | 830 | |
| 832 | - }; |
|
| 831 | + }; |
|
| 833 | 832 | |
| 834 | 833 | |
| 835 | - $user_can_access_lesson = false; |
|
| 834 | + $user_can_access_lesson = false; |
|
| 836 | 835 | |
| 837 | - if( is_user_logged_in() && $user_taking_course ){ |
|
| 836 | + if( is_user_logged_in() && $user_taking_course ){ |
|
| 838 | 837 | |
| 839 | - $user_can_access_lesson = true; |
|
| 838 | + $user_can_access_lesson = true; |
|
| 840 | 839 | |
| 841 | - } |
|
| 840 | + } |
|
| 842 | 841 | |
| 843 | 842 | |
| 844 | - $access_permission = false; |
|
| 843 | + $access_permission = false; |
|
| 845 | 844 | |
| 846 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 845 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 847 | 846 | |
| 848 | - $access_permission = true; |
|
| 847 | + $access_permission = true; |
|
| 849 | 848 | |
| 850 | - } |
|
| 849 | + } |
|
| 851 | 850 | |
| 852 | - $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
| 851 | + $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
| 853 | 852 | |
| 854 | - /** |
|
| 855 | - * Filter the can user view lesson function |
|
| 856 | - * |
|
| 857 | - * @since 1.9.0 |
|
| 858 | - * |
|
| 859 | - * @hooked Sensei_WC::alter_can_user_view_lesson |
|
| 860 | - * |
|
| 861 | - * @param bool $can_user_view_lesson |
|
| 862 | - * @param string $lesson_id |
|
| 863 | - * @param string $user_id |
|
| 864 | - */ |
|
| 865 | - return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
| 853 | + /** |
|
| 854 | + * Filter the can user view lesson function |
|
| 855 | + * |
|
| 856 | + * @since 1.9.0 |
|
| 857 | + * |
|
| 858 | + * @hooked Sensei_WC::alter_can_user_view_lesson |
|
| 859 | + * |
|
| 860 | + * @param bool $can_user_view_lesson |
|
| 861 | + * @param string $lesson_id |
|
| 862 | + * @param string $user_id |
|
| 863 | + */ |
|
| 864 | + return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
| 866 | 865 | |
| 867 | 866 | } // end sensei_can_current_user_view_lesson |
| 868 | 867 | |
@@ -874,49 +873,49 @@ discard block |
||
| 874 | 873 | */ |
| 875 | 874 | function sensei_the_single_lesson_meta(){ |
| 876 | 875 | |
| 877 | - // if the lesson meta is included within theme load that instead of the function content |
|
| 878 | - $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
| 879 | - if( ! empty( $template ) ){ |
|
| 876 | + // if the lesson meta is included within theme load that instead of the function content |
|
| 877 | + $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
| 878 | + if( ! empty( $template ) ){ |
|
| 880 | 879 | |
| 881 | - Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
| 882 | - return; |
|
| 880 | + Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
| 881 | + return; |
|
| 883 | 882 | |
| 884 | - } |
|
| 885 | - |
|
| 886 | - // Get the meta info |
|
| 887 | - $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
| 888 | - $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
| 883 | + } |
|
| 889 | 884 | |
| 890 | - // Complete Lesson Logic |
|
| 891 | - do_action( 'sensei_complete_lesson' ); |
|
| 892 | - // Check that the course has been started |
|
| 893 | - if ( Sensei()->access_settings() |
|
| 894 | - || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
| 895 | - || $is_preview ) { |
|
| 896 | - ?> |
|
| 885 | + // Get the meta info |
|
| 886 | + $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
| 887 | + $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
| 888 | + |
|
| 889 | + // Complete Lesson Logic |
|
| 890 | + do_action( 'sensei_complete_lesson' ); |
|
| 891 | + // Check that the course has been started |
|
| 892 | + if ( Sensei()->access_settings() |
|
| 893 | + || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
| 894 | + || $is_preview ) { |
|
| 895 | + ?> |
|
| 897 | 896 | <section class="lesson-meta"> |
| 898 | 897 | <?php |
| 899 | - if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
| 898 | + if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
| 900 | 899 | |
| 901 | - do_action( 'sensei_lesson_video', get_the_ID() ); |
|
| 900 | + do_action( 'sensei_lesson_video', get_the_ID() ); |
|
| 902 | 901 | |
| 903 | - } |
|
| 904 | - ?> |
|
| 902 | + } |
|
| 903 | + ?> |
|
| 905 | 904 | <?php do_action( 'sensei_frontend_messages' ); ?> |
| 906 | 905 | |
| 907 | 906 | <?php if ( ! $is_preview |
| 908 | - || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
| 907 | + || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
| 909 | 908 | |
| 910 | - sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
| 909 | + sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
| 911 | 910 | |
| 912 | - } ?> |
|
| 911 | + } ?> |
|
| 913 | 912 | </section> |
| 914 | 913 | |
| 915 | 914 | <?php do_action( 'sensei_lesson_back_link', $lesson_course_id ); ?> |
| 916 | 915 | |
| 917 | 916 | <?php } |
| 918 | 917 | |
| 919 | - do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
| 918 | + do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
| 920 | 919 | |
| 921 | 920 | } // end the_single_lesson_meta |
| 922 | 921 | |
@@ -932,16 +931,16 @@ discard block |
||
| 932 | 931 | */ |
| 933 | 932 | function get_sensei_header(){ |
| 934 | 933 | |
| 935 | - if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 934 | + if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 936 | 935 | |
| 937 | - get_header(); |
|
| 936 | + get_header(); |
|
| 938 | 937 | |
| 939 | - /** |
|
| 940 | - * sensei_before_main_content hook |
|
| 941 | - * |
|
| 942 | - * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
| 943 | - */ |
|
| 944 | - do_action( 'sensei_before_main_content' ); |
|
| 938 | + /** |
|
| 939 | + * sensei_before_main_content hook |
|
| 940 | + * |
|
| 941 | + * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
| 942 | + */ |
|
| 943 | + do_action( 'sensei_before_main_content' ); |
|
| 945 | 944 | |
| 946 | 945 | }// end get_sensei_header |
| 947 | 946 | |
@@ -957,28 +956,28 @@ discard block |
||
| 957 | 956 | */ |
| 958 | 957 | function get_sensei_footer(){ |
| 959 | 958 | |
| 960 | - /** |
|
| 961 | - * sensei_pagination hook |
|
| 962 | - * |
|
| 963 | - * @hooked sensei_pagination - 10 (outputs pagination) |
|
| 964 | - */ |
|
| 965 | - do_action( 'sensei_pagination' ); |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * sensei_after_main_content hook |
|
| 969 | - * |
|
| 970 | - * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
| 971 | - */ |
|
| 972 | - do_action( 'sensei_after_main_content' ); |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * sensei_sidebar hook |
|
| 976 | - * |
|
| 977 | - * @hooked sensei_get_sidebar - 10 |
|
| 978 | - */ |
|
| 979 | - do_action( 'sensei_sidebar' ); |
|
| 980 | - |
|
| 981 | - get_footer(); |
|
| 959 | + /** |
|
| 960 | + * sensei_pagination hook |
|
| 961 | + * |
|
| 962 | + * @hooked sensei_pagination - 10 (outputs pagination) |
|
| 963 | + */ |
|
| 964 | + do_action( 'sensei_pagination' ); |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * sensei_after_main_content hook |
|
| 968 | + * |
|
| 969 | + * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
| 970 | + */ |
|
| 971 | + do_action( 'sensei_after_main_content' ); |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * sensei_sidebar hook |
|
| 975 | + * |
|
| 976 | + * @hooked sensei_get_sidebar - 10 |
|
| 977 | + */ |
|
| 978 | + do_action( 'sensei_sidebar' ); |
|
| 979 | + |
|
| 980 | + get_footer(); |
|
| 982 | 981 | |
| 983 | 982 | }// end get_sensei_header |
| 984 | 983 | |
@@ -990,14 +989,14 @@ discard block |
||
| 990 | 989 | */ |
| 991 | 990 | function the_no_permissions_title(){ |
| 992 | 991 | |
| 993 | - /** |
|
| 994 | - * Filter the no permissions title just before it is echo'd on the |
|
| 995 | - * no-permissions.php file. |
|
| 996 | - * |
|
| 997 | - * @since 1.9.0 |
|
| 998 | - * @param $no_permissions_title |
|
| 999 | - */ |
|
| 1000 | - echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
| 992 | + /** |
|
| 993 | + * Filter the no permissions title just before it is echo'd on the |
|
| 994 | + * no-permissions.php file. |
|
| 995 | + * |
|
| 996 | + * @since 1.9.0 |
|
| 997 | + * @param $no_permissions_title |
|
| 998 | + */ |
|
| 999 | + echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
| 1001 | 1000 | |
| 1002 | 1001 | } |
| 1003 | 1002 | |
@@ -1008,14 +1007,14 @@ discard block |
||
| 1008 | 1007 | */ |
| 1009 | 1008 | function the_no_permissions_message( $post_id ){ |
| 1010 | 1009 | |
| 1011 | - /** |
|
| 1012 | - * Filter the no permissions message just before it is echo'd on the |
|
| 1013 | - * no-permissions.php file. |
|
| 1014 | - * |
|
| 1015 | - * @since 1.9.0 |
|
| 1016 | - * @param $no_permissions_message |
|
| 1017 | - */ |
|
| 1018 | - echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
| 1010 | + /** |
|
| 1011 | + * Filter the no permissions message just before it is echo'd on the |
|
| 1012 | + * no-permissions.php file. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.9.0 |
|
| 1015 | + * @param $no_permissions_message |
|
| 1016 | + */ |
|
| 1017 | + echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
| 1019 | 1018 | |
| 1020 | 1019 | } |
| 1021 | 1020 | |
@@ -1026,8 +1025,8 @@ discard block |
||
| 1026 | 1025 | */ |
| 1027 | 1026 | function sensei_the_excerpt( $post_id ){ |
| 1028 | 1027 | |
| 1029 | - global $post; |
|
| 1030 | - the_excerpt( $post ); |
|
| 1028 | + global $post; |
|
| 1029 | + the_excerpt( $post ); |
|
| 1031 | 1030 | |
| 1032 | 1031 | } |
| 1033 | 1032 | |
@@ -1041,9 +1040,9 @@ discard block |
||
| 1041 | 1040 | */ |
| 1042 | 1041 | function sensei_get_current_page_url(){ |
| 1043 | 1042 | |
| 1044 | - global $wp; |
|
| 1045 | - $current_page_url = home_url( $wp->request ); |
|
| 1046 | - return $current_page_url; |
|
| 1043 | + global $wp; |
|
| 1044 | + $current_page_url = home_url( $wp->request ); |
|
| 1045 | + return $current_page_url; |
|
| 1047 | 1046 | |
| 1048 | 1047 | } |
| 1049 | 1048 | |
@@ -1055,7 +1054,7 @@ discard block |
||
| 1055 | 1054 | */ |
| 1056 | 1055 | function sensei_the_my_courses_content(){ |
| 1057 | 1056 | |
| 1058 | - echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
| 1057 | + echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
| 1059 | 1058 | |
| 1060 | 1059 | } // sensei_the_my_courses_content |
| 1061 | 1060 | |
@@ -1070,7 +1069,7 @@ discard block |
||
| 1070 | 1069 | */ |
| 1071 | 1070 | function sensei_load_template( $template_name ){ |
| 1072 | 1071 | |
| 1073 | - Sensei_Templates::get_template( $template_name ); |
|
| 1072 | + Sensei_Templates::get_template( $template_name ); |
|
| 1074 | 1073 | |
| 1075 | 1074 | } |
| 1076 | 1075 | |
@@ -1084,7 +1083,7 @@ discard block |
||
| 1084 | 1083 | */ |
| 1085 | 1084 | function sensei_load_template_part( $slug, $name ){ |
| 1086 | 1085 | |
| 1087 | - Sensei_Templates::get_part( $slug, $name ); |
|
| 1086 | + Sensei_Templates::get_part( $slug, $name ); |
|
| 1088 | 1087 | |
| 1089 | 1088 | } |
| 1090 | 1089 | |
@@ -1103,17 +1102,17 @@ discard block |
||
| 1103 | 1102 | */ |
| 1104 | 1103 | function sensei_the_lesson_excerpt( $lesson_id = '' ) { |
| 1105 | 1104 | |
| 1106 | - if( empty( $lesson_id )){ |
|
| 1105 | + if( empty( $lesson_id )){ |
|
| 1107 | 1106 | |
| 1108 | - $lesson_id = get_the_ID(); |
|
| 1107 | + $lesson_id = get_the_ID(); |
|
| 1109 | 1108 | |
| 1110 | - } |
|
| 1109 | + } |
|
| 1111 | 1110 | |
| 1112 | - if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 1113 | - return; |
|
| 1114 | - } |
|
| 1111 | + if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
| 1112 | + return; |
|
| 1113 | + } |
|
| 1115 | 1114 | |
| 1116 | - echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
| 1115 | + echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
| 1117 | 1116 | |
| 1118 | 1117 | }// End lesson_excerpt() |
| 1119 | 1118 | |
@@ -1123,16 +1122,16 @@ discard block |
||
| 1123 | 1122 | * @since 1.9.0 |
| 1124 | 1123 | */ |
| 1125 | 1124 | function sensei_the_course_results_lessons(){ |
| 1126 | - // load backwards compatible template name if it exists in the users theme |
|
| 1127 | - $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
| 1128 | - if( $located_template ){ |
|
| 1125 | + // load backwards compatible template name if it exists in the users theme |
|
| 1126 | + $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
| 1127 | + if( $located_template ){ |
|
| 1129 | 1128 | |
| 1130 | - Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
| 1131 | - return; |
|
| 1129 | + Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
| 1130 | + return; |
|
| 1132 | 1131 | |
| 1133 | - } |
|
| 1132 | + } |
|
| 1134 | 1133 | |
| 1135 | - Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
| 1134 | + Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
| 1136 | 1135 | } |
| 1137 | 1136 | |
| 1138 | 1137 | /** |
@@ -1144,7 +1143,7 @@ discard block |
||
| 1144 | 1143 | */ |
| 1145 | 1144 | function sensei_courses_per_row(){ |
| 1146 | 1145 | |
| 1147 | - echo Sensei_Course::get_loop_number_of_columns(); |
|
| 1146 | + echo Sensei_Course::get_loop_number_of_columns(); |
|
| 1148 | 1147 | |
| 1149 | 1148 | } |
| 1150 | 1149 | |
@@ -1158,7 +1157,7 @@ discard block |
||
| 1158 | 1157 | */ |
| 1159 | 1158 | function sensei_get_template( $template_name, $args, $path ){ |
| 1160 | 1159 | |
| 1161 | - Sensei_Templates::get_template( $template_name, $args, $path ); |
|
| 1160 | + Sensei_Templates::get_template( $template_name, $args, $path ); |
|
| 1162 | 1161 | |
| 1163 | 1162 | } |
| 1164 | 1163 | |
@@ -1172,14 +1171,14 @@ discard block |
||
| 1172 | 1171 | */ |
| 1173 | 1172 | function get_the_lesson_status_class(){ |
| 1174 | 1173 | |
| 1175 | - $status_class = ''; |
|
| 1176 | - $lesson_completed = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() ); |
|
| 1174 | + $status_class = ''; |
|
| 1175 | + $lesson_completed = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() ); |
|
| 1177 | 1176 | |
| 1178 | - if ( $lesson_completed ) { |
|
| 1179 | - $status_class = 'completed'; |
|
| 1180 | - } |
|
| 1177 | + if ( $lesson_completed ) { |
|
| 1178 | + $status_class = 'completed'; |
|
| 1179 | + } |
|
| 1181 | 1180 | |
| 1182 | - return $status_class; |
|
| 1181 | + return $status_class; |
|
| 1183 | 1182 | |
| 1184 | 1183 | }// end get_the_lesson_status_class |
| 1185 | 1184 | /** |
@@ -1191,5 +1190,5 @@ discard block |
||
| 1191 | 1190 | */ |
| 1192 | 1191 | function sensei_the_lesson_status_class(){ |
| 1193 | 1192 | |
| 1194 | - echo get_the_lesson_status_class(); |
|
| 1193 | + echo get_the_lesson_status_class(); |
|
| 1195 | 1194 | } |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * Constructor |
| 22 | 22 | * @since 1.3.0 |
| 23 | - * |
|
| 24 | - * @param $file |
|
| 23 | + * |
|
| 24 | + * @param $file |
|
| 25 | 25 | */ |
| 26 | 26 | public function __construct ( $file ) { |
| 27 | 27 | $this->name = __( 'Grading', 'woothemes-sensei' ); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | /** |
| 231 | 231 | * Outputs Grading general headers |
| 232 | 232 | * @since 1.3.0 |
| 233 | - * @param array $args |
|
| 233 | + * @param array $args |
|
| 234 | 234 | * @return void |
| 235 | 235 | */ |
| 236 | 236 | public function grading_headers( $args = array( 'nav' => 'default' ) ) { |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
| 284 | 284 | |
| 285 | - $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] ); |
|
| 285 | + $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] ); |
|
| 286 | 286 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 287 | 287 | |
| 288 | 288 | } // End If Statement |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
| 318 | 318 | |
| 319 | - $user_name = Sensei_Learner::get_full_name( $_GET['user'] ); |
|
| 319 | + $user_name = Sensei_Learner::get_full_name( $_GET['user'] ); |
|
| 320 | 320 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 321 | 321 | |
| 322 | 322 | } // End If Statement |
@@ -365,15 +365,15 @@ discard block |
||
| 365 | 365 | public function count_statuses( $args = array() ) { |
| 366 | 366 | global $wpdb; |
| 367 | 367 | |
| 368 | - /** |
|
| 369 | - * Filter fires inside Sensei_Grading::count_statuses |
|
| 370 | - * |
|
| 371 | - * Alter the the post_in array to determine which posts the |
|
| 372 | - * comment query should be limited to. |
|
| 373 | - * @since 1.8.0 |
|
| 374 | - * @param array $args |
|
| 375 | - */ |
|
| 376 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 368 | + /** |
|
| 369 | + * Filter fires inside Sensei_Grading::count_statuses |
|
| 370 | + * |
|
| 371 | + * Alter the the post_in array to determine which posts the |
|
| 372 | + * comment query should be limited to. |
|
| 373 | + * @since 1.8.0 |
|
| 374 | + * @param array $args |
|
| 375 | + */ |
|
| 376 | + $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 377 | 377 | |
| 378 | 378 | if ( 'course' == $args['type'] ) { |
| 379 | 379 | $type = 'sensei_course_status'; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | |
| 386 | 386 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
| 387 | 387 | |
| 388 | - // Restrict to specific posts |
|
| 388 | + // Restrict to specific posts |
|
| 389 | 389 | if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
| 390 | 390 | $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
| 391 | 391 | } |
@@ -520,148 +520,148 @@ discard block |
||
| 520 | 520 | return $html; |
| 521 | 521 | } // End lessons_drop_down_html() |
| 522 | 522 | |
| 523 | - /** |
|
| 524 | - * The process grading function handles admin grading submissions. |
|
| 525 | - * |
|
| 526 | - * This function is hooked on to admin_init. It simply accepts |
|
| 527 | - * the grades as the Grader selected theme and saves the total grade and |
|
| 528 | - * individual question grades. |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function admin_process_grading_submission() { |
|
| 523 | + /** |
|
| 524 | + * The process grading function handles admin grading submissions. |
|
| 525 | + * |
|
| 526 | + * This function is hooked on to admin_init. It simply accepts |
|
| 527 | + * the grades as the Grader selected theme and saves the total grade and |
|
| 528 | + * individual question grades. |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function admin_process_grading_submission() { |
|
| 533 | 533 | |
| 534 | - // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 535 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 536 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 537 | - || ! isset( $_GET['quiz_id'] ) |
|
| 538 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 534 | + // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 535 | + if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 536 | + || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 537 | + || ! isset( $_GET['quiz_id'] ) |
|
| 538 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 539 | 539 | |
| 540 | - return false; //exit and do not grade |
|
| 540 | + return false; //exit and do not grade |
|
| 541 | 541 | |
| 542 | - } |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - $quiz_id = $_GET['quiz_id']; |
|
| 545 | - $user_id = $_GET['user']; |
|
| 544 | + $quiz_id = $_GET['quiz_id']; |
|
| 545 | + $user_id = $_GET['user']; |
|
| 546 | 546 | |
| 547 | 547 | |
| 548 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 549 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 550 | - $quiz_grade = 0; |
|
| 551 | - $count = 0; |
|
| 552 | - $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 553 | - $all_question_grades = array(); |
|
| 554 | - $all_answers_feedback = array(); |
|
| 548 | + $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 549 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 550 | + $quiz_grade = 0; |
|
| 551 | + $count = 0; |
|
| 552 | + $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 553 | + $all_question_grades = array(); |
|
| 554 | + $all_answers_feedback = array(); |
|
| 555 | 555 | |
| 556 | - foreach( $questions as $question ) { |
|
| 556 | + foreach( $questions as $question ) { |
|
| 557 | 557 | |
| 558 | - ++$count; |
|
| 559 | - $question_id = $question->ID; |
|
| 558 | + ++$count; |
|
| 559 | + $question_id = $question->ID; |
|
| 560 | 560 | |
| 561 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 561 | + if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 562 | 562 | |
| 563 | - $question_grade = 0; |
|
| 564 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 563 | + $question_grade = 0; |
|
| 564 | + if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 565 | 565 | |
| 566 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 566 | + $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 567 | 567 | |
| 568 | - } |
|
| 568 | + } |
|
| 569 | 569 | |
| 570 | - // add data to the array that will, after the loop, be stored on the lesson status |
|
| 571 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 570 | + // add data to the array that will, after the loop, be stored on the lesson status |
|
| 571 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 572 | 572 | |
| 573 | - // tally up the total quiz grade |
|
| 574 | - $quiz_grade += $question_grade; |
|
| 573 | + // tally up the total quiz grade |
|
| 574 | + $quiz_grade += $question_grade; |
|
| 575 | 575 | |
| 576 | - } // endif |
|
| 576 | + } // endif |
|
| 577 | 577 | |
| 578 | - // Question answer feedback / notes |
|
| 579 | - $question_feedback = ''; |
|
| 580 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 578 | + // Question answer feedback / notes |
|
| 579 | + $question_feedback = ''; |
|
| 580 | + if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 581 | 581 | |
| 582 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 582 | + $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 583 | 583 | |
| 584 | - } |
|
| 585 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 584 | + } |
|
| 585 | + $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 586 | 586 | |
| 587 | - } // end for each $questions |
|
| 587 | + } // end for each $questions |
|
| 588 | 588 | |
| 589 | - //store all question grades on the lesson status |
|
| 590 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 589 | + //store all question grades on the lesson status |
|
| 590 | + Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 591 | 591 | |
| 592 | - //store the feedback from grading |
|
| 593 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 592 | + //store the feedback from grading |
|
| 593 | + Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 594 | 594 | |
| 595 | - // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 596 | - // in the class sensei grading user quiz -> display() |
|
| 597 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 595 | + // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 596 | + // in the class sensei grading user quiz -> display() |
|
| 597 | + if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 598 | 598 | |
| 599 | - // set the users total quiz grade |
|
| 599 | + // set the users total quiz grade |
|
| 600 | 600 | if ( 0 < intval( $quiz_grade_total ) ) { |
| 601 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 601 | + $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 602 | 602 | } |
| 603 | 603 | else { |
| 604 | 604 | $grade = 0; |
| 605 | 605 | } |
| 606 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 607 | - |
|
| 608 | - // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 609 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 610 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 611 | - $lesson_metadata = array(); |
|
| 612 | - if ( $pass_required ) { |
|
| 613 | - // Student has reached the pass mark and lesson is complete |
|
| 614 | - if ( $quiz_passmark <= $grade ) { |
|
| 615 | - $lesson_status = 'passed'; |
|
| 616 | - } |
|
| 617 | - else { |
|
| 618 | - $lesson_status = 'failed'; |
|
| 619 | - } // End If Statement |
|
| 620 | - } |
|
| 621 | - // Student only has to partake the quiz |
|
| 622 | - else { |
|
| 623 | - $lesson_status = 'graded'; |
|
| 624 | - } |
|
| 625 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 606 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 607 | + |
|
| 608 | + // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 609 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 610 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 611 | + $lesson_metadata = array(); |
|
| 612 | + if ( $pass_required ) { |
|
| 613 | + // Student has reached the pass mark and lesson is complete |
|
| 614 | + if ( $quiz_passmark <= $grade ) { |
|
| 615 | + $lesson_status = 'passed'; |
|
| 616 | + } |
|
| 617 | + else { |
|
| 618 | + $lesson_status = 'failed'; |
|
| 619 | + } // End If Statement |
|
| 620 | + } |
|
| 621 | + // Student only has to partake the quiz |
|
| 622 | + else { |
|
| 623 | + $lesson_status = 'graded'; |
|
| 624 | + } |
|
| 625 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 626 | 626 | |
| 627 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 627 | + Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 628 | 628 | |
| 629 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 629 | + if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 630 | 630 | |
| 631 | - /** |
|
| 632 | - * Summary. |
|
| 633 | - * |
|
| 634 | - * Description. |
|
| 635 | - * |
|
| 636 | - * @since 1.7.0 |
|
| 637 | - * |
|
| 638 | - * @param int $user_id |
|
| 639 | - * @param int $quiz_lesson_id |
|
| 640 | - */ |
|
| 641 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 631 | + /** |
|
| 632 | + * Summary. |
|
| 633 | + * |
|
| 634 | + * Description. |
|
| 635 | + * |
|
| 636 | + * @since 1.7.0 |
|
| 637 | + * |
|
| 638 | + * @param int $user_id |
|
| 639 | + * @param int $quiz_lesson_id |
|
| 640 | + */ |
|
| 641 | + do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 642 | 642 | |
| 643 | - } // end if in_array |
|
| 643 | + } // end if in_array |
|
| 644 | 644 | |
| 645 | - }// end if $_POST['all_que... |
|
| 645 | + }// end if $_POST['all_que... |
|
| 646 | 646 | |
| 647 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 647 | + if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 648 | 648 | |
| 649 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 649 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 650 | 650 | |
| 651 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 651 | + } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 652 | 652 | |
| 653 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 653 | + $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 654 | 654 | |
| 655 | - } else { |
|
| 655 | + } else { |
|
| 656 | 656 | |
| 657 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 657 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 658 | 658 | |
| 659 | - } |
|
| 659 | + } |
|
| 660 | 660 | |
| 661 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 662 | - exit; |
|
| 661 | + wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 662 | + exit; |
|
| 663 | 663 | |
| 664 | - } // end admin_process_grading_submission |
|
| 664 | + } // end admin_process_grading_submission |
|
| 665 | 665 | |
| 666 | 666 | public function get_redirect_url() { |
| 667 | 667 | // Parse POST data |
@@ -706,398 +706,398 @@ discard block |
||
| 706 | 706 | } // End If Statement |
| 707 | 707 | } // End sensei_grading_notices() |
| 708 | 708 | |
| 709 | - /** |
|
| 710 | - * Grade quiz automatically |
|
| 711 | - * |
|
| 712 | - * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 713 | - * the quiz will not be auto gradable. |
|
| 714 | - * |
|
| 715 | - * @since 1.7.4 |
|
| 716 | - * |
|
| 717 | - * @param integer $quiz_id ID of quiz |
|
| 718 | - * @param array $submitted questions id ans answers { |
|
| 719 | - * @type int $question_id |
|
| 720 | - * @type mixed $answer |
|
| 721 | - * } |
|
| 722 | - * @param integer $total_questions Total questions in quiz (not used) |
|
| 723 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 724 | - * |
|
| 725 | - * @return int $quiz_grade total sum of all question grades |
|
| 726 | - */ |
|
| 727 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 728 | - |
|
| 729 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 730 | - || $quiz_grade_type != 'auto' ) { |
|
| 731 | - return false; // exit early |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - $user_id = get_current_user_id(); |
|
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 737 | - $quiz_autogradable = true; |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * Filter the types of question types that can be automatically graded. |
|
| 741 | - * |
|
| 742 | - * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 743 | - * |
|
| 744 | - * @param array { |
|
| 745 | - * 'multiple-choice', |
|
| 746 | - * 'boolean', |
|
| 747 | - * 'gap-fill'. |
|
| 748 | - * } |
|
| 749 | - */ |
|
| 750 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 751 | - |
|
| 752 | - $grade_total = 0; |
|
| 753 | - $all_question_grades = array(); |
|
| 754 | - foreach( $submitted as $question_id => $answer ) { |
|
| 755 | - |
|
| 756 | - // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 757 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 709 | + /** |
|
| 710 | + * Grade quiz automatically |
|
| 711 | + * |
|
| 712 | + * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 713 | + * the quiz will not be auto gradable. |
|
| 714 | + * |
|
| 715 | + * @since 1.7.4 |
|
| 716 | + * |
|
| 717 | + * @param integer $quiz_id ID of quiz |
|
| 718 | + * @param array $submitted questions id ans answers { |
|
| 719 | + * @type int $question_id |
|
| 720 | + * @type mixed $answer |
|
| 721 | + * } |
|
| 722 | + * @param integer $total_questions Total questions in quiz (not used) |
|
| 723 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 724 | + * |
|
| 725 | + * @return int $quiz_grade total sum of all question grades |
|
| 726 | + */ |
|
| 727 | + public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 728 | + |
|
| 729 | + if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 730 | + || $quiz_grade_type != 'auto' ) { |
|
| 731 | + return false; // exit early |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + $user_id = get_current_user_id(); |
|
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 737 | + $quiz_autogradable = true; |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * Filter the types of question types that can be automatically graded. |
|
| 741 | + * |
|
| 742 | + * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 743 | + * |
|
| 744 | + * @param array { |
|
| 745 | + * 'multiple-choice', |
|
| 746 | + * 'boolean', |
|
| 747 | + * 'gap-fill'. |
|
| 748 | + * } |
|
| 749 | + */ |
|
| 750 | + $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 751 | + |
|
| 752 | + $grade_total = 0; |
|
| 753 | + $all_question_grades = array(); |
|
| 754 | + foreach( $submitted as $question_id => $answer ) { |
|
| 755 | + |
|
| 756 | + // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 757 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | 758 | $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
| 759 | 759 | // Question has a zero grade, so skip grading |
| 760 | 760 | if ( 0 == $achievable_grade ) { |
| 761 | 761 | $all_question_grades[ $question_id ] = $achievable_grade; |
| 762 | 762 | } |
| 763 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 764 | - // Get user question grade |
|
| 765 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 766 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 767 | - $grade_total += $question_grade; |
|
| 763 | + elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 764 | + // Get user question grade |
|
| 765 | + $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 766 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 767 | + $grade_total += $question_grade; |
|
| 768 | 768 | |
| 769 | - } else { |
|
| 769 | + } else { |
|
| 770 | 770 | |
| 771 | - // There is a question that cannot be autograded |
|
| 772 | - $quiz_autogradable = false; |
|
| 771 | + // There is a question that cannot be autograded |
|
| 772 | + $quiz_autogradable = false; |
|
| 773 | 773 | |
| 774 | - } // end if in_array( $question_type... |
|
| 774 | + } // end if in_array( $question_type... |
|
| 775 | 775 | |
| 776 | - }// end for each question |
|
| 776 | + }// end for each question |
|
| 777 | 777 | |
| 778 | - // Only if the whole quiz was autogradable do we set a grade |
|
| 779 | - if ( $quiz_autogradable ) { |
|
| 778 | + // Only if the whole quiz was autogradable do we set a grade |
|
| 779 | + if ( $quiz_autogradable ) { |
|
| 780 | 780 | |
| 781 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 781 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 782 | 782 | // Check for zero total from grades |
| 783 | 783 | if ( 0 < $quiz_total ) { |
| 784 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 784 | + $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 785 | 785 | } |
| 786 | 786 | else { |
| 787 | 787 | $grade = 0; |
| 788 | 788 | } |
| 789 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 789 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 790 | 790 | |
| 791 | - } else { |
|
| 791 | + } else { |
|
| 792 | 792 | |
| 793 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 793 | + $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 794 | 794 | |
| 795 | - } |
|
| 796 | - |
|
| 797 | - // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 798 | - // when doing manual grading. |
|
| 799 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 795 | + } |
|
| 800 | 796 | |
| 801 | - return $grade; |
|
| 797 | + // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 798 | + // when doing manual grading. |
|
| 799 | + Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 802 | 800 | |
| 803 | - } // End grade_quiz_auto() |
|
| 801 | + return $grade; |
|
| 804 | 802 | |
| 805 | - /** |
|
| 806 | - * Grade question automatically |
|
| 807 | - * |
|
| 808 | - * This function checks the question typ and then grades it accordingly. |
|
| 809 | - * |
|
| 810 | - * @since 1.7.4 |
|
| 811 | - * |
|
| 812 | - * @param integer $question_id |
|
| 813 | - * @param string $question_type of the standard Sensei question types |
|
| 814 | - * @param string $answer |
|
| 815 | - * @param int $user_id |
|
| 816 | - * |
|
| 817 | - * @return int $question_grade |
|
| 818 | - */ |
|
| 819 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 820 | - |
|
| 821 | - if( intval( $user_id ) == 0 ) { |
|
| 822 | - |
|
| 823 | - $user_id = get_current_user_id(); |
|
| 824 | - |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 828 | - |
|
| 829 | - return false; |
|
| 830 | - |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - Sensei()->question->get_question_type( $question_id ); |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * Applying a grade before the auto grading takes place. |
|
| 838 | - * |
|
| 839 | - * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 840 | - * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 841 | - * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 842 | - * |
|
| 843 | - * @param int $question_grade default false |
|
| 844 | - * @param int $question_id |
|
| 845 | - * @param string $question_type one of the Sensei question type. |
|
| 846 | - * @param string $answer user supplied question answer |
|
| 847 | - */ |
|
| 848 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 803 | + } // End grade_quiz_auto() |
|
| 849 | 804 | |
| 850 | - if ( false !== $question_grade ) { |
|
| 805 | + /** |
|
| 806 | + * Grade question automatically |
|
| 807 | + * |
|
| 808 | + * This function checks the question typ and then grades it accordingly. |
|
| 809 | + * |
|
| 810 | + * @since 1.7.4 |
|
| 811 | + * |
|
| 812 | + * @param integer $question_id |
|
| 813 | + * @param string $question_type of the standard Sensei question types |
|
| 814 | + * @param string $answer |
|
| 815 | + * @param int $user_id |
|
| 816 | + * |
|
| 817 | + * @return int $question_grade |
|
| 818 | + */ |
|
| 819 | + public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 851 | 820 | |
| 852 | - return $question_grade; |
|
| 821 | + if( intval( $user_id ) == 0 ) { |
|
| 853 | 822 | |
| 854 | - } |
|
| 823 | + $user_id = get_current_user_id(); |
|
| 855 | 824 | |
| 856 | - // auto grading core |
|
| 857 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 825 | + } |
|
| 858 | 826 | |
| 859 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 827 | + if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 860 | 828 | |
| 861 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 862 | - $answer = wp_unslash( $answer ); |
|
| 863 | - } |
|
| 864 | - $answer = (array) $answer; |
|
| 865 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 866 | - // Loop through all answers ensure none are 'missing' |
|
| 867 | - $all_correct = true; |
|
| 868 | - foreach ( $answer as $check_answer ) { |
|
| 869 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 870 | - $all_correct = false; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - // If all correct then grade |
|
| 874 | - if ( $all_correct ) { |
|
| 875 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 876 | - } |
|
| 877 | - } |
|
| 829 | + return false; |
|
| 878 | 830 | |
| 879 | - } elseif( 'gap-fill' == $question_type ){ |
|
| 831 | + } |
|
| 880 | 832 | |
| 881 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 882 | 833 | |
| 883 | - } else{ |
|
| 834 | + Sensei()->question->get_question_type( $question_id ); |
|
| 884 | 835 | |
| 885 | - /** |
|
| 886 | - * Grading questions that are not auto gradable. |
|
| 887 | - * |
|
| 888 | - * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 889 | - * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 890 | - * |
|
| 891 | - * @param int $question_grade default zero |
|
| 892 | - * @param int $question_id |
|
| 893 | - * @param string $question_type one of the Sensei question type. |
|
| 894 | - * @param string $answer user supplied question answer |
|
| 895 | - */ |
|
| 896 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 836 | + /** |
|
| 837 | + * Applying a grade before the auto grading takes place. |
|
| 838 | + * |
|
| 839 | + * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 840 | + * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 841 | + * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 842 | + * |
|
| 843 | + * @param int $question_grade default false |
|
| 844 | + * @param int $question_id |
|
| 845 | + * @param string $question_type one of the Sensei question type. |
|
| 846 | + * @param string $answer user supplied question answer |
|
| 847 | + */ |
|
| 848 | + $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 897 | 849 | |
| 898 | - } // end if $question_type |
|
| 850 | + if ( false !== $question_grade ) { |
|
| 899 | 851 | |
| 900 | - return $question_grade; |
|
| 901 | - } // end grade_question_auto |
|
| 852 | + return $question_grade; |
|
| 902 | 853 | |
| 903 | - /** |
|
| 904 | - * Grading logic specifically for the gap fill questions |
|
| 905 | - * |
|
| 906 | - * @since 1.9.0 |
|
| 907 | - * @param $question_id |
|
| 908 | - * @param $user_answer |
|
| 909 | - * |
|
| 910 | - * @return bool | int false or the grade given to the user answer |
|
| 911 | - */ |
|
| 912 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 854 | + } |
|
| 913 | 855 | |
| 914 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 915 | - $gapfill_array = explode( '||', $right_answer ); |
|
| 856 | + // auto grading core |
|
| 857 | + if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 916 | 858 | |
| 917 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 918 | - $user_answer = wp_unslash( $user_answer ); |
|
| 919 | - } |
|
| 859 | + $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 920 | 860 | |
| 921 | - /** |
|
| 922 | - * case sensitive grading filter |
|
| 923 | - * |
|
| 924 | - * alter the value simply use this code in your plugin or the themes functions.php |
|
| 925 | - * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 926 | - * |
|
| 927 | - * @param bool $do_case_sensitive_comparison default false. |
|
| 928 | - * |
|
| 929 | - * @since 1.9.0 |
|
| 930 | - */ |
|
| 931 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 861 | + if( 0 == get_magic_quotes_gpc() ) { |
|
| 862 | + $answer = wp_unslash( $answer ); |
|
| 863 | + } |
|
| 864 | + $answer = (array) $answer; |
|
| 865 | + if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 866 | + // Loop through all answers ensure none are 'missing' |
|
| 867 | + $all_correct = true; |
|
| 868 | + foreach ( $answer as $check_answer ) { |
|
| 869 | + if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 870 | + $all_correct = false; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + // If all correct then grade |
|
| 874 | + if ( $all_correct ) { |
|
| 875 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 876 | + } |
|
| 877 | + } |
|
| 932 | 878 | |
| 933 | - if( $do_case_sensitive_comparison ){ |
|
| 879 | + } elseif( 'gap-fill' == $question_type ){ |
|
| 934 | 880 | |
| 935 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 936 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 881 | + $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 937 | 882 | |
| 938 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 883 | + } else{ |
|
| 939 | 884 | |
| 940 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 885 | + /** |
|
| 886 | + * Grading questions that are not auto gradable. |
|
| 887 | + * |
|
| 888 | + * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 889 | + * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 890 | + * |
|
| 891 | + * @param int $question_grade default zero |
|
| 892 | + * @param int $question_id |
|
| 893 | + * @param string $question_type one of the Sensei question type. |
|
| 894 | + * @param string $answer user supplied question answer |
|
| 895 | + */ |
|
| 896 | + $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 941 | 897 | |
| 942 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 898 | + } // end if $question_type |
|
| 943 | 899 | |
| 944 | - return Sensei()->question->get_question_grade($question_id); |
|
| 900 | + return $question_grade; |
|
| 901 | + } // end grade_question_auto |
|
| 945 | 902 | |
| 946 | - }else{ |
|
| 903 | + /** |
|
| 904 | + * Grading logic specifically for the gap fill questions |
|
| 905 | + * |
|
| 906 | + * @since 1.9.0 |
|
| 907 | + * @param $question_id |
|
| 908 | + * @param $user_answer |
|
| 909 | + * |
|
| 910 | + * @return bool | int false or the grade given to the user answer |
|
| 911 | + */ |
|
| 912 | + public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 947 | 913 | |
| 948 | - return false; |
|
| 914 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 915 | + $gapfill_array = explode( '||', $right_answer ); |
|
| 949 | 916 | |
| 950 | - } |
|
| 917 | + if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 918 | + $user_answer = wp_unslash( $user_answer ); |
|
| 919 | + } |
|
| 951 | 920 | |
| 952 | - }else{ |
|
| 921 | + /** |
|
| 922 | + * case sensitive grading filter |
|
| 923 | + * |
|
| 924 | + * alter the value simply use this code in your plugin or the themes functions.php |
|
| 925 | + * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 926 | + * |
|
| 927 | + * @param bool $do_case_sensitive_comparison default false. |
|
| 928 | + * |
|
| 929 | + * @since 1.9.0 |
|
| 930 | + */ |
|
| 931 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 953 | 932 | |
| 954 | - return false; |
|
| 933 | + if( $do_case_sensitive_comparison ){ |
|
| 955 | 934 | |
| 956 | - } |
|
| 935 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 936 | + if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 957 | 937 | |
| 958 | - }else{ |
|
| 938 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 959 | 939 | |
| 960 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 961 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 940 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 962 | 941 | |
| 963 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 942 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 964 | 943 | |
| 965 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 944 | + return Sensei()->question->get_question_grade($question_id); |
|
| 966 | 945 | |
| 967 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 946 | + }else{ |
|
| 968 | 947 | |
| 969 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 948 | + return false; |
|
| 970 | 949 | |
| 971 | - }else{ |
|
| 950 | + } |
|
| 972 | 951 | |
| 973 | - return false; |
|
| 952 | + }else{ |
|
| 974 | 953 | |
| 975 | - } |
|
| 954 | + return false; |
|
| 976 | 955 | |
| 977 | - }else{ |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + }else{ |
|
| 959 | + |
|
| 960 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 961 | + if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 962 | + |
|
| 963 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 964 | + |
|
| 965 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 966 | + |
|
| 967 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 968 | + |
|
| 969 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 970 | + |
|
| 971 | + }else{ |
|
| 972 | + |
|
| 973 | + return false; |
|
| 974 | + |
|
| 975 | + } |
|
| 978 | 976 | |
| 979 | - return false; |
|
| 977 | + }else{ |
|
| 978 | + |
|
| 979 | + return false; |
|
| 980 | + |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Counts the lessons that have been graded manually and automatically |
|
| 989 | + * |
|
| 990 | + * @since 1.9.0 |
|
| 991 | + * @return int $number_of_graded_lessons |
|
| 992 | + */ |
|
| 993 | + public static function get_graded_lessons_count(){ |
|
| 980 | 994 | |
| 981 | - } |
|
| 995 | + global $wpdb; |
|
| 982 | 996 | |
| 983 | - } |
|
| 997 | + $comment_query_piece[ 'select'] = "SELECT COUNT(*) AS total"; |
|
| 998 | + $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 999 | + $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade')"; |
|
| 1000 | + $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 984 | 1001 | |
| 985 | - } |
|
| 1002 | + $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1003 | + $number_of_graded_lessons = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 986 | 1004 | |
| 987 | - /** |
|
| 988 | - * Counts the lessons that have been graded manually and automatically |
|
| 989 | - * |
|
| 990 | - * @since 1.9.0 |
|
| 991 | - * @return int $number_of_graded_lessons |
|
| 992 | - */ |
|
| 993 | - public static function get_graded_lessons_count(){ |
|
| 1005 | + return $number_of_graded_lessons; |
|
| 1006 | + } |
|
| 994 | 1007 | |
| 995 | - global $wpdb; |
|
| 1008 | + /** |
|
| 1009 | + * Add together all the graded lesson grades |
|
| 1010 | + * |
|
| 1011 | + * @since 1.9.0 |
|
| 1012 | + * @return double $sum_of_all_grades |
|
| 1013 | + */ |
|
| 1014 | + public static function get_graded_lessons_sum(){ |
|
| 996 | 1015 | |
| 997 | - $comment_query_piece[ 'select'] = "SELECT COUNT(*) AS total"; |
|
| 998 | - $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 999 | - $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade')"; |
|
| 1000 | - $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1016 | + global $wpdb; |
|
| 1001 | 1017 | |
| 1002 | - $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1003 | - $number_of_graded_lessons = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1018 | + $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1019 | + $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1020 | + $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade')"; |
|
| 1021 | + $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1004 | 1022 | |
| 1005 | - return $number_of_graded_lessons; |
|
| 1006 | - } |
|
| 1023 | + $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1024 | + $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1007 | 1025 | |
| 1008 | - /** |
|
| 1009 | - * Add together all the graded lesson grades |
|
| 1010 | - * |
|
| 1011 | - * @since 1.9.0 |
|
| 1012 | - * @return double $sum_of_all_grades |
|
| 1013 | - */ |
|
| 1014 | - public static function get_graded_lessons_sum(){ |
|
| 1026 | + return $sum_of_all_grades; |
|
| 1015 | 1027 | |
| 1016 | - global $wpdb; |
|
| 1028 | + } |
|
| 1017 | 1029 | |
| 1018 | - $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1019 | - $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1020 | - $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade')"; |
|
| 1021 | - $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1030 | + /** |
|
| 1031 | + * Get the sum of all grades for the given user. |
|
| 1032 | + * |
|
| 1033 | + * @since 1.9.0 |
|
| 1034 | + * @param $user_id |
|
| 1035 | + * @return double |
|
| 1036 | + */ |
|
| 1037 | + public static function get_user_graded_lessons_sum( $user_id ){ |
|
| 1038 | + global $wpdb; |
|
| 1022 | 1039 | |
| 1023 | - $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1024 | - $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1040 | + $clean_user_id = esc_sql( $user_id); |
|
| 1041 | + $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1042 | + $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1043 | + $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade') AND {$wpdb->comments}.user_id = {$clean_user_id} "; |
|
| 1044 | + $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1025 | 1045 | |
| 1026 | - return $sum_of_all_grades; |
|
| 1046 | + $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1047 | + $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1027 | 1048 | |
| 1028 | - } |
|
| 1049 | + return $sum_of_all_grades; |
|
| 1050 | + } |
|
| 1029 | 1051 | |
| 1030 | - /** |
|
| 1031 | - * Get the sum of all grades for the given user. |
|
| 1032 | - * |
|
| 1033 | - * @since 1.9.0 |
|
| 1034 | - * @param $user_id |
|
| 1035 | - * @return double |
|
| 1036 | - */ |
|
| 1037 | - public static function get_user_graded_lessons_sum( $user_id ){ |
|
| 1038 | - global $wpdb; |
|
| 1052 | + /** |
|
| 1053 | + * Get the sum of all user grades for the given lesson. |
|
| 1054 | + * |
|
| 1055 | + * @since 1.9.0 |
|
| 1056 | + * |
|
| 1057 | + * @param int lesson_id |
|
| 1058 | + * @return double |
|
| 1059 | + */ |
|
| 1060 | + public static function get_lessons_users_grades_sum( $lesson_id ){ |
|
| 1039 | 1061 | |
| 1040 | - $clean_user_id = esc_sql( $user_id); |
|
| 1041 | - $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1042 | - $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1043 | - $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade') AND {$wpdb->comments}.user_id = {$clean_user_id} "; |
|
| 1044 | - $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1062 | + global $wpdb; |
|
| 1045 | 1063 | |
| 1046 | - $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1047 | - $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1064 | + $clean_lesson_id = esc_sql( $lesson_id); |
|
| 1065 | + $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1066 | + $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1067 | + $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade') AND {$wpdb->comments}.comment_post_ID = {$clean_lesson_id} "; |
|
| 1068 | + $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1048 | 1069 | |
| 1049 | - return $sum_of_all_grades; |
|
| 1050 | - } |
|
| 1070 | + $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1071 | + $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1051 | 1072 | |
| 1052 | - /** |
|
| 1053 | - * Get the sum of all user grades for the given lesson. |
|
| 1054 | - * |
|
| 1055 | - * @since 1.9.0 |
|
| 1056 | - * |
|
| 1057 | - * @param int lesson_id |
|
| 1058 | - * @return double |
|
| 1059 | - */ |
|
| 1060 | - public static function get_lessons_users_grades_sum( $lesson_id ){ |
|
| 1073 | + return $sum_of_all_grades; |
|
| 1061 | 1074 | |
| 1062 | - global $wpdb; |
|
| 1075 | + }//get_lessons_user_grades_sum |
|
| 1063 | 1076 | |
| 1064 | - $clean_lesson_id = esc_sql( $lesson_id); |
|
| 1065 | - $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1066 | - $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1067 | - $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade') AND {$wpdb->comments}.comment_post_ID = {$clean_lesson_id} "; |
|
| 1068 | - $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1077 | + /** |
|
| 1078 | + * Get the sum of all user grades for the given course. |
|
| 1079 | + * |
|
| 1080 | + * @since 1.9.0 |
|
| 1081 | + * |
|
| 1082 | + * @param int $course_id |
|
| 1083 | + * @return double |
|
| 1084 | + */ |
|
| 1085 | + public static function get_course_users_grades_sum( $course_id ){ |
|
| 1069 | 1086 | |
| 1070 | - $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1071 | - $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1087 | + global $wpdb; |
|
| 1072 | 1088 | |
| 1073 | - return $sum_of_all_grades; |
|
| 1089 | + $clean_course_id = esc_sql( $course_id); |
|
| 1090 | + $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1091 | + $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1092 | + $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_course_status') AND ( {$wpdb->commentmeta}.meta_key = 'percent') AND {$wpdb->comments}.comment_post_ID = {$clean_course_id} "; |
|
| 1093 | + $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1074 | 1094 | |
| 1075 | - }//get_lessons_user_grades_sum |
|
| 1095 | + $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1096 | + $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1076 | 1097 | |
| 1077 | - /** |
|
| 1078 | - * Get the sum of all user grades for the given course. |
|
| 1079 | - * |
|
| 1080 | - * @since 1.9.0 |
|
| 1081 | - * |
|
| 1082 | - * @param int $course_id |
|
| 1083 | - * @return double |
|
| 1084 | - */ |
|
| 1085 | - public static function get_course_users_grades_sum( $course_id ){ |
|
| 1086 | - |
|
| 1087 | - global $wpdb; |
|
| 1088 | - |
|
| 1089 | - $clean_course_id = esc_sql( $course_id); |
|
| 1090 | - $comment_query_piece[ 'select'] = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum"; |
|
| 1091 | - $comment_query_piece[ 'from'] = " FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) "; |
|
| 1092 | - $comment_query_piece[ 'where'] = " WHERE {$wpdb->comments}.comment_type IN ('sensei_course_status') AND ( {$wpdb->commentmeta}.meta_key = 'percent') AND {$wpdb->comments}.comment_post_ID = {$clean_course_id} "; |
|
| 1093 | - $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC "; |
|
| 1098 | + return $sum_of_all_grades; |
|
| 1094 | 1099 | |
| 1095 | - $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby']; |
|
| 1096 | - $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) ); |
|
| 1097 | - |
|
| 1098 | - return $sum_of_all_grades; |
|
| 1099 | - |
|
| 1100 | - }//get_lessons_user_grades_sum |
|
| 1100 | + }//get_lessons_user_grades_sum |
|
| 1101 | 1101 | |
| 1102 | 1102 | } // End Class |
| 1103 | 1103 | |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | class Sensei_Notices{ |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @var $notices |
|
| 18 | - */ |
|
| 17 | + * @var $notices |
|
| 18 | + */ |
|
| 19 | 19 | protected $notices; |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | protected $has_printed; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * constructor |
|
| 28 | - */ |
|
| 27 | + * constructor |
|
| 28 | + */ |
|
| 29 | 29 | public function __construct(){ |
| 30 | 30 | //initialize the notices variable |
| 31 | 31 | $this->notices = array(); |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | } // end print_notice() |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | - * Clear all notices |
|
| 83 | - * |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 82 | + * Clear all notices |
|
| 83 | + * |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | 86 | public function clear_notices(){ |
| 87 | 87 | // assign an empty array to clear all existing notices |
| 88 | 88 | $this->notices = array(); |
@@ -12,662 +12,662 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Sensei_Templates { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 17 | - * |
|
| 18 | - * @since 1.9.0 |
|
| 19 | - * @param string $slug |
|
| 20 | - * @param string $name default: '' |
|
| 21 | - * |
|
| 22 | - * @return void |
|
| 23 | - */ |
|
| 24 | - public static function get_part( $slug, $name = '' ){ |
|
| 15 | + /** |
|
| 16 | + * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 17 | + * |
|
| 18 | + * @since 1.9.0 |
|
| 19 | + * @param string $slug |
|
| 20 | + * @param string $name default: '' |
|
| 21 | + * |
|
| 22 | + * @return void |
|
| 23 | + */ |
|
| 24 | + public static function get_part( $slug, $name = '' ){ |
|
| 25 | + |
|
| 26 | + $template = ''; |
|
| 27 | + $plugin_template_url = Sensei()->template_url; |
|
| 28 | + $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 29 | + |
|
| 30 | + // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 31 | + if ( $name ){ |
|
| 32 | + |
|
| 33 | + $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 25 | 34 | |
| 26 | - $template = ''; |
|
| 27 | - $plugin_template_url = Sensei()->template_url; |
|
| 28 | - $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 29 | - |
|
| 30 | - // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 31 | - if ( $name ){ |
|
| 32 | - |
|
| 33 | - $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 34 | - |
|
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // Get default slug-name.php |
|
| 38 | - if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 37 | + // Get default slug-name.php |
|
| 38 | + if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 39 | 39 | |
| 40 | - $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 40 | + $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 41 | 41 | |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 46 | - if ( !$template ){ |
|
| 45 | + // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 46 | + if ( !$template ){ |
|
| 47 | 47 | |
| 48 | - $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 48 | + $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - if ( $template ){ |
|
| 53 | + if ( $template ){ |
|
| 54 | 54 | |
| 55 | - load_template( $template, false ); |
|
| 55 | + load_template( $template, false ); |
|
| 56 | 56 | |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - } // end get part |
|
| 59 | + } // end get part |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the template. |
|
| 63 | - * |
|
| 64 | - * @since 1.9.0 |
|
| 65 | - * |
|
| 66 | - * @param $template_name |
|
| 67 | - * @param array $args |
|
| 68 | - * @param string $template_path |
|
| 69 | - * @param string $default_path |
|
| 70 | - */ |
|
| 71 | - public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 61 | + /** |
|
| 62 | + * Get the template. |
|
| 63 | + * |
|
| 64 | + * @since 1.9.0 |
|
| 65 | + * |
|
| 66 | + * @param $template_name |
|
| 67 | + * @param array $args |
|
| 68 | + * @param string $template_path |
|
| 69 | + * @param string $default_path |
|
| 70 | + */ |
|
| 71 | + public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 72 | 72 | |
| 73 | - if ( $args && is_array($args) ) |
|
| 74 | - extract( $args ); |
|
| 73 | + if ( $args && is_array($args) ) |
|
| 74 | + extract( $args ); |
|
| 75 | 75 | |
| 76 | - $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 76 | + $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 77 | 77 | |
| 78 | - if( ! empty( $located ) ){ |
|
| 78 | + if( ! empty( $located ) ){ |
|
| 79 | 79 | |
| 80 | - do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 80 | + do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 81 | 81 | |
| 82 | - include( $located ); |
|
| 82 | + include( $located ); |
|
| 83 | 83 | |
| 84 | - do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 84 | + do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 85 | 85 | |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - } // end get template |
|
| 88 | + } // end get template |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Check if the template file exists. A wrapper for WP locate_template. |
|
| 92 | + * |
|
| 93 | + * @since 1.9.0 |
|
| 94 | + * |
|
| 95 | + * @param $template_name |
|
| 96 | + * @param string $template_path |
|
| 97 | + * @param string $default_path |
|
| 98 | + * |
|
| 99 | + * @return mixed|void |
|
| 100 | + */ |
|
| 101 | + public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 102 | + |
|
| 103 | + if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 104 | + if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 105 | + |
|
| 106 | + // Look within passed path within the theme - this is priority |
|
| 107 | + $template = locate_template( |
|
| 108 | + array( |
|
| 109 | + $template_path . $template_name, |
|
| 110 | + $template_name |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + |
|
| 114 | + // Get default template |
|
| 115 | + if ( ! $template ){ |
|
| 116 | + |
|
| 117 | + $template = $default_path . $template_name; |
|
| 89 | 118 | |
| 90 | - /** |
|
| 91 | - * Check if the template file exists. A wrapper for WP locate_template. |
|
| 92 | - * |
|
| 93 | - * @since 1.9.0 |
|
| 94 | - * |
|
| 95 | - * @param $template_name |
|
| 96 | - * @param string $template_path |
|
| 97 | - * @param string $default_path |
|
| 98 | - * |
|
| 99 | - * @return mixed|void |
|
| 100 | - */ |
|
| 101 | - public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 119 | + } |
|
| 120 | + // return nothing for file that do not exist |
|
| 121 | + if( !file_exists( $template ) ){ |
|
| 122 | + $template = ''; |
|
| 123 | + } |
|
| 102 | 124 | |
| 103 | - if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 104 | - if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 125 | + // Return what we found |
|
| 126 | + return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 105 | 127 | |
| 106 | - // Look within passed path within the theme - this is priority |
|
| 107 | - $template = locate_template( |
|
| 108 | - array( |
|
| 109 | - $template_path . $template_name, |
|
| 110 | - $template_name |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 128 | + } // end locate |
|
| 113 | 129 | |
| 114 | - // Get default template |
|
| 115 | - if ( ! $template ){ |
|
| 130 | + /** |
|
| 131 | + * Determine which Sensei template to load based on the |
|
| 132 | + * current page context. |
|
| 133 | + * |
|
| 134 | + * @since 1.0 |
|
| 135 | + * |
|
| 136 | + * @param string $template |
|
| 137 | + * @return string $template |
|
| 138 | + */ |
|
| 139 | + public static function template_loader ( $template = '' ) { |
|
| 116 | 140 | |
| 117 | - $template = $default_path . $template_name; |
|
| 141 | + global $wp_query, $email_template; |
|
| 118 | 142 | |
| 119 | - } |
|
| 120 | - // return nothing for file that do not exist |
|
| 121 | - if( !file_exists( $template ) ){ |
|
| 122 | - $template = ''; |
|
| 123 | - } |
|
| 143 | + $find = array( 'woothemes-sensei.php' ); |
|
| 144 | + $file = ''; |
|
| 124 | 145 | |
| 125 | - // Return what we found |
|
| 126 | - return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 146 | + if ( isset( $email_template ) && $email_template ) { |
|
| 127 | 147 | |
| 128 | - } // end locate |
|
| 148 | + $file = 'emails/' . $email_template; |
|
| 149 | + $find[] = $file; |
|
| 150 | + $find[] = Sensei()->template_url . $file; |
|
| 129 | 151 | |
| 130 | - /** |
|
| 131 | - * Determine which Sensei template to load based on the |
|
| 132 | - * current page context. |
|
| 133 | - * |
|
| 134 | - * @since 1.0 |
|
| 135 | - * |
|
| 136 | - * @param string $template |
|
| 137 | - * @return string $template |
|
| 138 | - */ |
|
| 139 | - public static function template_loader ( $template = '' ) { |
|
| 152 | + } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 140 | 153 | |
| 141 | - global $wp_query, $email_template; |
|
| 154 | + // possible backward compatible template include if theme overrides content-single-course.php |
|
| 155 | + // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 156 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 142 | 157 | |
| 143 | - $find = array( 'woothemes-sensei.php' ); |
|
| 144 | - $file = ''; |
|
| 158 | + $file = 'single-course.php'; |
|
| 159 | + $find[] = $file; |
|
| 160 | + $find[] = Sensei()->template_url . $file; |
|
| 145 | 161 | |
| 146 | - if ( isset( $email_template ) && $email_template ) { |
|
| 147 | 162 | |
| 148 | - $file = 'emails/' . $email_template; |
|
| 149 | - $find[] = $file; |
|
| 150 | - $find[] = Sensei()->template_url . $file; |
|
| 163 | + } elseif ( is_single() && get_post_type() == 'lesson' ) { // check |
|
| 151 | 164 | |
| 152 | - } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 165 | + // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 166 | + // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 167 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 153 | 168 | |
| 154 | - // possible backward compatible template include if theme overrides content-single-course.php |
|
| 155 | - // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 156 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 169 | + $file = 'single-lesson.php'; |
|
| 170 | + $find[] = $file; |
|
| 171 | + $find[] = Sensei()->template_url . $file; |
|
| 157 | 172 | |
| 158 | - $file = 'single-course.php'; |
|
| 159 | - $find[] = $file; |
|
| 160 | - $find[] = Sensei()->template_url . $file; |
|
| 173 | + } elseif ( is_single() && get_post_type() == 'quiz' ) { // check |
|
| 161 | 174 | |
| 175 | + // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 176 | + // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 177 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 162 | 178 | |
| 163 | - } elseif ( is_single() && get_post_type() == 'lesson' ) { // check |
|
| 179 | + $file = 'single-quiz.php'; |
|
| 180 | + $find[] = $file; |
|
| 181 | + $find[] = Sensei()->template_url . $file; |
|
| 164 | 182 | |
| 165 | - // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 166 | - // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 167 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 168 | 183 | |
| 169 | - $file = 'single-lesson.php'; |
|
| 170 | - $find[] = $file; |
|
| 171 | - $find[] = Sensei()->template_url . $file; |
|
| 184 | + } elseif ( is_single() && get_post_type() == 'sensei_message' ) { //// check |
|
| 172 | 185 | |
| 173 | - } elseif ( is_single() && get_post_type() == 'quiz' ) { // check |
|
| 186 | + // possible backward compatible template include if theme overrides content-single-message.php |
|
| 187 | + // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 188 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 174 | 189 | |
| 175 | - // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 176 | - // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 177 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 190 | + $file = 'single-message.php'; |
|
| 191 | + $find[] = $file; |
|
| 192 | + $find[] = Sensei()->template_url . $file; |
|
| 178 | 193 | |
| 179 | - $file = 'single-quiz.php'; |
|
| 180 | - $find[] = $file; |
|
| 181 | - $find[] = Sensei()->template_url . $file; |
|
| 194 | + } elseif ( is_post_type_archive( 'course' ) |
|
| 195 | + || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 196 | + || is_tax( 'course-category' )) { |
|
| 182 | 197 | |
| 198 | + // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 199 | + // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 200 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 183 | 201 | |
| 184 | - } elseif ( is_single() && get_post_type() == 'sensei_message' ) { //// check |
|
| 202 | + $file = 'archive-course.php'; |
|
| 203 | + $find[] = $file; |
|
| 204 | + $find[] = Sensei()->template_url . $file; |
|
| 185 | 205 | |
| 186 | - // possible backward compatible template include if theme overrides content-single-message.php |
|
| 187 | - // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 188 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 206 | + } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 189 | 207 | |
| 190 | - $file = 'single-message.php'; |
|
| 191 | - $find[] = $file; |
|
| 192 | - $find[] = Sensei()->template_url . $file; |
|
| 208 | + $file = 'archive-message.php'; |
|
| 209 | + $find[] = $file; |
|
| 210 | + $find[] = Sensei()->template_url . $file; |
|
| 193 | 211 | |
| 194 | - } elseif ( is_post_type_archive( 'course' ) |
|
| 195 | - || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 196 | - || is_tax( 'course-category' )) { |
|
| 212 | + } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 197 | 213 | |
| 198 | - // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 199 | - // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 200 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 214 | + // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 215 | + // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 216 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 201 | 217 | |
| 202 | - $file = 'archive-course.php'; |
|
| 203 | - $find[] = $file; |
|
| 204 | - $find[] = Sensei()->template_url . $file; |
|
| 218 | + $file = 'archive-lesson.php'; |
|
| 219 | + $find[] = $file; |
|
| 220 | + $find[] = Sensei()->template_url . $file; |
|
| 205 | 221 | |
| 206 | - } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 222 | + } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 207 | 223 | |
| 208 | - $file = 'archive-message.php'; |
|
| 209 | - $find[] = $file; |
|
| 210 | - $find[] = Sensei()->template_url . $file; |
|
| 224 | + // Override for sites with static home page |
|
| 225 | + $wp_query->is_home = false; |
|
| 211 | 226 | |
| 212 | - } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 227 | + $file = 'learner-profile.php'; |
|
| 228 | + $find[] = $file; |
|
| 229 | + $find[] = Sensei()->template_url . $file; |
|
| 213 | 230 | |
| 214 | - // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 215 | - // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 216 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 231 | + } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 217 | 232 | |
| 218 | - $file = 'archive-lesson.php'; |
|
| 219 | - $find[] = $file; |
|
| 220 | - $find[] = Sensei()->template_url . $file; |
|
| 233 | + // Override for sites with static home page |
|
| 234 | + $wp_query->is_home = false; |
|
| 221 | 235 | |
| 222 | - } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 236 | + $file = 'course-results.php'; |
|
| 237 | + $find[] = $file; |
|
| 238 | + $find[] = Sensei()->template_url . $file; |
|
| 223 | 239 | |
| 224 | - // Override for sites with static home page |
|
| 225 | - $wp_query->is_home = false; |
|
| 240 | + }elseif( is_author() |
|
| 241 | + && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 242 | + && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 226 | 243 | |
| 227 | - $file = 'learner-profile.php'; |
|
| 228 | - $find[] = $file; |
|
| 229 | - $find[] = Sensei()->template_url . $file; |
|
| 244 | + $file = 'teacher-archive.php'; |
|
| 245 | + $find[] = $file; |
|
| 246 | + $find[] = Sensei()->template_url . $file; |
|
| 230 | 247 | |
| 231 | - } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 248 | + } // Load the template file |
|
| 232 | 249 | |
| 233 | - // Override for sites with static home page |
|
| 234 | - $wp_query->is_home = false; |
|
| 250 | + // if file is present set it to be loaded otherwise continue with the initial template given by WP |
|
| 251 | + if ( $file ) { |
|
| 235 | 252 | |
| 236 | - $file = 'course-results.php'; |
|
| 237 | - $find[] = $file; |
|
| 238 | - $find[] = Sensei()->template_url . $file; |
|
| 253 | + $template = locate_template( $find ); |
|
| 254 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 239 | 255 | |
| 240 | - }elseif( is_author() |
|
| 241 | - && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 242 | - && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 256 | + } // End If Statement |
|
| 243 | 257 | |
| 244 | - $file = 'teacher-archive.php'; |
|
| 245 | - $find[] = $file; |
|
| 246 | - $find[] = Sensei()->template_url . $file; |
|
| 258 | + return $template; |
|
| 247 | 259 | |
| 248 | - } // Load the template file |
|
| 260 | + } // End template_loader() |
|
| 249 | 261 | |
| 250 | - // if file is present set it to be loaded otherwise continue with the initial template given by WP |
|
| 251 | - if ( $file ) { |
|
| 262 | + /** |
|
| 263 | + * This function loads the no-permissions template for users with no access |
|
| 264 | + * if a Sensei template was loaded. |
|
| 265 | + * |
|
| 266 | + * This function doesn't determine the permissions. Permissions must be determined |
|
| 267 | + * before loading this function as it only gets the template. |
|
| 268 | + * |
|
| 269 | + * This function also checks the user theme for overrides to ensure the right template |
|
| 270 | + * file is returned. |
|
| 271 | + * |
|
| 272 | + * @since 1.9.0 |
|
| 273 | + */ |
|
| 274 | + public static function get_no_permission_template( ){ |
|
| 252 | 275 | |
| 253 | - $template = locate_template( $find ); |
|
| 254 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 276 | + // possible backward compatible template loading |
|
| 277 | + // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 278 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 255 | 279 | |
| 256 | - } // End If Statement |
|
| 280 | + $file = 'no-permissions.php'; |
|
| 281 | + $find[] = $file; |
|
| 282 | + $find[] = Sensei()->template_url . $file; |
|
| 257 | 283 | |
| 258 | - return $template; |
|
| 284 | + $template = locate_template( $find ); |
|
| 285 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 259 | 286 | |
| 260 | - } // End template_loader() |
|
| 287 | + // set a global constant so that we know that we're in this template |
|
| 288 | + define('SENSEI_NO_PERMISSION', true ); |
|
| 261 | 289 | |
| 262 | - /** |
|
| 263 | - * This function loads the no-permissions template for users with no access |
|
| 264 | - * if a Sensei template was loaded. |
|
| 265 | - * |
|
| 266 | - * This function doesn't determine the permissions. Permissions must be determined |
|
| 267 | - * before loading this function as it only gets the template. |
|
| 268 | - * |
|
| 269 | - * This function also checks the user theme for overrides to ensure the right template |
|
| 270 | - * file is returned. |
|
| 271 | - * |
|
| 272 | - * @since 1.9.0 |
|
| 273 | - */ |
|
| 274 | - public static function get_no_permission_template( ){ |
|
| 290 | + return $template; |
|
| 275 | 291 | |
| 276 | - // possible backward compatible template loading |
|
| 277 | - // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 278 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 292 | + } |
|
| 279 | 293 | |
| 280 | - $file = 'no-permissions.php'; |
|
| 281 | - $find[] = $file; |
|
| 282 | - $find[] = Sensei()->template_url . $file; |
|
| 294 | + /** |
|
| 295 | + * This function is specifically created for loading template files from the theme. |
|
| 296 | + * |
|
| 297 | + * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 298 | + * around the singular content file from their theme and exit. |
|
| 299 | + * |
|
| 300 | + * If none is found this function will do nothing. If a template is found this funciton |
|
| 301 | + * will exit execution of the script an not continue. |
|
| 302 | + * |
|
| 303 | + * @since 1.9.0 |
|
| 304 | + * @param string $template |
|
| 305 | + * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 306 | + */ |
|
| 307 | + public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 283 | 308 | |
| 284 | - $template = locate_template( $find ); |
|
| 285 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 309 | + $found_template = locate_template( array( $template ) ); |
|
| 310 | + if( $found_template ){ |
|
| 286 | 311 | |
| 287 | - // set a global constant so that we know that we're in this template |
|
| 288 | - define('SENSEI_NO_PERMISSION', true ); |
|
| 312 | + if( $load_header_footer ){ |
|
| 289 | 313 | |
| 290 | - return $template; |
|
| 314 | + get_sensei_header(); |
|
| 315 | + include( $found_template ); |
|
| 316 | + get_sensei_footer(); |
|
| 291 | 317 | |
| 292 | - } |
|
| 318 | + }else{ |
|
| 293 | 319 | |
| 294 | - /** |
|
| 295 | - * This function is specifically created for loading template files from the theme. |
|
| 296 | - * |
|
| 297 | - * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 298 | - * around the singular content file from their theme and exit. |
|
| 299 | - * |
|
| 300 | - * If none is found this function will do nothing. If a template is found this funciton |
|
| 301 | - * will exit execution of the script an not continue. |
|
| 302 | - * |
|
| 303 | - * @since 1.9.0 |
|
| 304 | - * @param string $template |
|
| 305 | - * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 306 | - */ |
|
| 307 | - public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 320 | + include( $found_template ); |
|
| 308 | 321 | |
| 309 | - $found_template = locate_template( array( $template ) ); |
|
| 310 | - if( $found_template ){ |
|
| 322 | + } |
|
| 311 | 323 | |
| 312 | - if( $load_header_footer ){ |
|
| 324 | + exit; |
|
| 313 | 325 | |
| 314 | - get_sensei_header(); |
|
| 315 | - include( $found_template ); |
|
| 316 | - get_sensei_footer(); |
|
| 317 | - |
|
| 318 | - }else{ |
|
| 319 | - |
|
| 320 | - include( $found_template ); |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - exit; |
|
| 325 | - |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - } |
|
| 326 | + } |
|
| 329 | 327 | |
| 328 | + } |
|
| 330 | 329 | |
| 331 | - /** |
|
| 332 | - * Hooks the deprecated archive content hook into the hook again just in |
|
| 333 | - * case other developers have used it. |
|
| 334 | - * |
|
| 335 | - * @deprecated since 1.9.0 |
|
| 336 | - */ |
|
| 337 | - public static function deprecated_archive_course_content_hook(){ |
|
| 338 | - |
|
| 339 | - sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 340 | - |
|
| 341 | - }// end deprecated_archive_hook |
|
| 342 | 330 | |
| 343 | - /** |
|
| 344 | - * A generic function for echoing the post title |
|
| 345 | - * |
|
| 346 | - * @since 1.9.0 |
|
| 347 | - * @param WP_Post $post |
|
| 348 | - */ |
|
| 349 | - public static function the_title( $post ){ |
|
| 350 | - |
|
| 351 | - // ID passed in |
|
| 352 | - if( is_numeric( $post ) ){ |
|
| 353 | - $post = get_post( $post ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Filter the template html tag for the title |
|
| 358 | - * |
|
| 359 | - * @since 1.9.0 |
|
| 360 | - * |
|
| 361 | - * @param $title_html_tag default is 'h3' |
|
| 362 | - */ |
|
| 363 | - $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Filter the title classes |
|
| 367 | - * |
|
| 368 | - * @since 1.9.0 |
|
| 369 | - * @param string $title_classes defaults to $post_type-title |
|
| 370 | - */ |
|
| 371 | - $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 331 | + /** |
|
| 332 | + * Hooks the deprecated archive content hook into the hook again just in |
|
| 333 | + * case other developers have used it. |
|
| 334 | + * |
|
| 335 | + * @deprecated since 1.9.0 |
|
| 336 | + */ |
|
| 337 | + public static function deprecated_archive_course_content_hook(){ |
|
| 372 | 338 | |
| 373 | - $html= ''; |
|
| 374 | - $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 375 | - $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 376 | - $html .= $post->post_title ; |
|
| 377 | - $html .= '</a>'; |
|
| 378 | - $html .= '</'. $title_html_tag. '>'; |
|
| 379 | - echo $html; |
|
| 380 | - |
|
| 381 | - }// end the title |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * This function adds the hooks inside and above the single course content for |
|
| 385 | - * backwards compatibility sake. |
|
| 386 | - * |
|
| 387 | - * @since 1.9.0 |
|
| 388 | - * @deprecated 1.9.0 |
|
| 389 | - */ |
|
| 390 | - public static function deprecated_single_course_inside_before_hooks(){ |
|
| 391 | - |
|
| 392 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 393 | - sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 394 | - sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 395 | - |
|
| 396 | - }// end deprecated_single_course_inside_before_hooks |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * This function adds the hooks to sensei_course_single_lessons for |
|
| 400 | - * backwards compatibility sake. and provides developers with an alternative. |
|
| 401 | - * |
|
| 402 | - * @since 1.9.0 |
|
| 403 | - * @deprecated 1.9.0 |
|
| 404 | - */ |
|
| 405 | - public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 339 | + sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 406 | 340 | |
| 407 | - sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 341 | + }// end deprecated_archive_hook |
|
| 408 | 342 | |
| 409 | - }// deprecate_sensei_course_single_lessons_hook |
|
| 343 | + /** |
|
| 344 | + * A generic function for echoing the post title |
|
| 345 | + * |
|
| 346 | + * @since 1.9.0 |
|
| 347 | + * @param WP_Post $post |
|
| 348 | + */ |
|
| 349 | + public static function the_title( $post ){ |
|
| 410 | 350 | |
| 411 | - /** |
|
| 412 | - * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 413 | - * |
|
| 414 | - * The content must be dealt with inside the respective templates. |
|
| 415 | - * |
|
| 416 | - * @since 1.9.0 |
|
| 417 | - * @deprecated 1.9.0 |
|
| 418 | - */ |
|
| 419 | - public static function deprecated_single_main_content_hook(){ |
|
| 351 | + // ID passed in |
|
| 352 | + if( is_numeric( $post ) ){ |
|
| 353 | + $post = get_post( $post ); |
|
| 354 | + } |
|
| 420 | 355 | |
| 421 | - if( is_singular( 'course' ) ) { |
|
| 356 | + /** |
|
| 357 | + * Filter the template html tag for the title |
|
| 358 | + * |
|
| 359 | + * @since 1.9.0 |
|
| 360 | + * |
|
| 361 | + * @param $title_html_tag default is 'h3' |
|
| 362 | + */ |
|
| 363 | + $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Filter the title classes |
|
| 367 | + * |
|
| 368 | + * @since 1.9.0 |
|
| 369 | + * @param string $title_classes defaults to $post_type-title |
|
| 370 | + */ |
|
| 371 | + $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 372 | + |
|
| 373 | + $html= ''; |
|
| 374 | + $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 375 | + $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 376 | + $html .= $post->post_title ; |
|
| 377 | + $html .= '</a>'; |
|
| 378 | + $html .= '</'. $title_html_tag. '>'; |
|
| 379 | + echo $html; |
|
| 380 | + |
|
| 381 | + }// end the title |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * This function adds the hooks inside and above the single course content for |
|
| 385 | + * backwards compatibility sake. |
|
| 386 | + * |
|
| 387 | + * @since 1.9.0 |
|
| 388 | + * @deprecated 1.9.0 |
|
| 389 | + */ |
|
| 390 | + public static function deprecated_single_course_inside_before_hooks(){ |
|
| 391 | + |
|
| 392 | + sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 393 | + sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 394 | + sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 395 | + |
|
| 396 | + }// end deprecated_single_course_inside_before_hooks |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * This function adds the hooks to sensei_course_single_lessons for |
|
| 400 | + * backwards compatibility sake. and provides developers with an alternative. |
|
| 401 | + * |
|
| 402 | + * @since 1.9.0 |
|
| 403 | + * @deprecated 1.9.0 |
|
| 404 | + */ |
|
| 405 | + public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 406 | + |
|
| 407 | + sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 408 | + |
|
| 409 | + }// deprecate_sensei_course_single_lessons_hook |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 413 | + * |
|
| 414 | + * The content must be dealt with inside the respective templates. |
|
| 415 | + * |
|
| 416 | + * @since 1.9.0 |
|
| 417 | + * @deprecated 1.9.0 |
|
| 418 | + */ |
|
| 419 | + public static function deprecated_single_main_content_hook(){ |
|
| 420 | + |
|
| 421 | + if( is_singular( 'course' ) ) { |
|
| 422 | + |
|
| 423 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 424 | + |
|
| 425 | + } elseif( is_singular( 'message' ) ){ |
|
| 426 | + |
|
| 427 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + }// end deprecated_single_course_single_main_content_hook |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Deprecate the old sensei modules |
|
| 434 | + * @since 1.9.0 |
|
| 435 | + * @deprecated since 1.9.0 |
|
| 436 | + */ |
|
| 437 | + public static function deprecate_module_before_hook(){ |
|
| 438 | + |
|
| 439 | + sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 422 | 440 | |
| 423 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 424 | - |
|
| 425 | - } elseif( is_singular( 'message' ) ){ |
|
| 426 | - |
|
| 427 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - }// end deprecated_single_course_single_main_content_hook |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Deprecate the old sensei modules |
|
| 434 | - * @since 1.9.0 |
|
| 435 | - * @deprecated since 1.9.0 |
|
| 436 | - */ |
|
| 437 | - public static function deprecate_module_before_hook(){ |
|
| 441 | + } |
|
| 438 | 442 | |
| 439 | - sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 443 | + /** |
|
| 444 | + * Deprecate the old sensei modules after hooks |
|
| 445 | + * @since 1.9.0 |
|
| 446 | + * @deprecated since 1.9.0 |
|
| 447 | + */ |
|
| 448 | + public static function deprecate_module_after_hook(){ |
|
| 440 | 449 | |
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Deprecate the old sensei modules after hooks |
|
| 445 | - * @since 1.9.0 |
|
| 446 | - * @deprecated since 1.9.0 |
|
| 447 | - */ |
|
| 448 | - public static function deprecate_module_after_hook(){ |
|
| 450 | + sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 449 | 451 | |
| 450 | - sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 452 | + } |
|
| 451 | 453 | |
| 452 | - } |
|
| 454 | + /** |
|
| 455 | + * Deprecate the single message hooks for post types. |
|
| 456 | + * |
|
| 457 | + * @since 1.9.0 |
|
| 458 | + * @deprecated since 1.9.0 |
|
| 459 | + */ |
|
| 460 | + public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 453 | 461 | |
| 454 | - /** |
|
| 455 | - * Deprecate the single message hooks for post types. |
|
| 456 | - * |
|
| 457 | - * @since 1.9.0 |
|
| 458 | - * @deprecated since 1.9.0 |
|
| 459 | - */ |
|
| 460 | - public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 462 | + if( is_singular( 'sensei_message' ) ){ |
|
| 461 | 463 | |
| 462 | - if( is_singular( 'sensei_message' ) ){ |
|
| 464 | + sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 463 | 465 | |
| 464 | - sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 466 | + } |
|
| 465 | 467 | |
| 466 | - } |
|
| 468 | + } |
|
| 467 | 469 | |
| 468 | - } |
|
| 470 | + /** |
|
| 471 | + * course_single_meta function. |
|
| 472 | + * |
|
| 473 | + * @access public |
|
| 474 | + * @return void |
|
| 475 | + * @deprecated since 1.9.0 |
|
| 476 | + */ |
|
| 477 | + public static function deprecate_course_single_meta_hooks() { |
|
| 469 | 478 | |
| 470 | - /** |
|
| 471 | - * course_single_meta function. |
|
| 472 | - * |
|
| 473 | - * @access public |
|
| 474 | - * @return void |
|
| 475 | - * @deprecated since 1.9.0 |
|
| 476 | - */ |
|
| 477 | - public static function deprecate_course_single_meta_hooks() { |
|
| 479 | + // deprecate all these hooks |
|
| 480 | + sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 481 | + sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 482 | + sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 483 | + sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 478 | 484 | |
| 479 | - // deprecate all these hooks |
|
| 480 | - sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 481 | - sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 482 | - sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 483 | - sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 485 | + } // End deprecate_course_single_meta_hooks |
|
| 484 | 486 | |
| 485 | - } // End deprecate_course_single_meta_hooks |
|
| 487 | + /** |
|
| 488 | + * Run the deprecated hooks on the single lesson page |
|
| 489 | + * @deprecated since 1.9.0 |
|
| 490 | + */ |
|
| 491 | + public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 486 | 492 | |
| 487 | - /** |
|
| 488 | - * Run the deprecated hooks on the single lesson page |
|
| 489 | - * @deprecated since 1.9.0 |
|
| 490 | - */ |
|
| 491 | - public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 493 | + if( is_singular( 'lesson' ) ){ |
|
| 492 | 494 | |
| 493 | - if( is_singular( 'lesson' ) ){ |
|
| 495 | + sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 496 | + sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 494 | 497 | |
| 495 | - sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 496 | - sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 498 | + } |
|
| 497 | 499 | |
| 498 | - } |
|
| 500 | + }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 499 | 501 | |
| 500 | - }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 502 | + /** |
|
| 503 | + * Deprecate the hook sensei_lesson_course_signup. |
|
| 504 | + * |
|
| 505 | + * The hook content will be linked directly on the recommended |
|
| 506 | + * sensei_single_lesson_content_inside_after |
|
| 507 | + * |
|
| 508 | + * @deprecated since 1.9.0 |
|
| 509 | + */ |
|
| 510 | + public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 501 | 511 | |
| 502 | - /** |
|
| 503 | - * Deprecate the hook sensei_lesson_course_signup. |
|
| 504 | - * |
|
| 505 | - * The hook content will be linked directly on the recommended |
|
| 506 | - * sensei_single_lesson_content_inside_after |
|
| 507 | - * |
|
| 508 | - * @deprecated since 1.9.0 |
|
| 509 | - */ |
|
| 510 | - public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 512 | + $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 513 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 511 | 514 | |
| 512 | - $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 513 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 515 | + if( !$user_taking_course ) { |
|
| 514 | 516 | |
| 515 | - if( !$user_taking_course ) { |
|
| 517 | + sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 516 | 518 | |
| 517 | - sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 519 | + } |
|
| 520 | + }// end deprecate_sensei_lesson_course_signup_hook |
|
| 518 | 521 | |
| 519 | - } |
|
| 520 | - }// end deprecate_sensei_lesson_course_signup_hook |
|
| 522 | + /** |
|
| 523 | + * Running the deprecated hook: sensei_lesson_single_meta |
|
| 524 | + * |
|
| 525 | + * @since 1.9.0 |
|
| 526 | + * @deprecated since 1.9.0 |
|
| 527 | + */ |
|
| 528 | + public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 521 | 529 | |
| 522 | - /** |
|
| 523 | - * Running the deprecated hook: sensei_lesson_single_meta |
|
| 524 | - * |
|
| 525 | - * @since 1.9.0 |
|
| 526 | - * @deprecated since 1.9.0 |
|
| 527 | - */ |
|
| 528 | - public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 530 | + if ( sensei_can_user_view_lesson() ) { |
|
| 529 | 531 | |
| 530 | - if ( sensei_can_user_view_lesson() ) { |
|
| 532 | + sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 531 | 533 | |
| 532 | - sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 533 | 534 | |
| 535 | + } |
|
| 534 | 536 | |
| 535 | - } |
|
| 537 | + }// end deprecate_sensei_lesson_single_meta_hook |
|
| 536 | 538 | |
| 537 | - }// end deprecate_sensei_lesson_single_meta_hook |
|
| 539 | + /** |
|
| 540 | + * Deprecate the sensei lesson single title hook |
|
| 541 | + * @deprecated since 1.9.0 |
|
| 542 | + */ |
|
| 543 | + public static function deprecate_sensei_lesson_single_title(){ |
|
| 538 | 544 | |
| 539 | - /** |
|
| 540 | - * Deprecate the sensei lesson single title hook |
|
| 541 | - * @deprecated since 1.9.0 |
|
| 542 | - */ |
|
| 543 | - public static function deprecate_sensei_lesson_single_title(){ |
|
| 545 | + sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 544 | 546 | |
| 545 | - sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 547 | + }// end deprecate_sensei_lesson_single_title |
|
| 546 | 548 | |
| 547 | - }// end deprecate_sensei_lesson_single_title |
|
| 549 | + /** |
|
| 550 | + * hook in the deperecated single main content to the lesson |
|
| 551 | + * @deprecated since 1.9.0 |
|
| 552 | + */ |
|
| 553 | + public static function deprecate_lesson_single_main_content_hook(){ |
|
| 548 | 554 | |
| 549 | - /** |
|
| 550 | - * hook in the deperecated single main content to the lesson |
|
| 551 | - * @deprecated since 1.9.0 |
|
| 552 | - */ |
|
| 553 | - public static function deprecate_lesson_single_main_content_hook(){ |
|
| 555 | + sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 554 | 556 | |
| 555 | - sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 557 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 556 | 558 | |
| 557 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 559 | + /** |
|
| 560 | + * hook in the deperecated single main content to the lesson |
|
| 561 | + * @deprecated since 1.9.0 |
|
| 562 | + */ |
|
| 563 | + public static function deprecate_lesson_image_hook(){ |
|
| 558 | 564 | |
| 559 | - /** |
|
| 560 | - * hook in the deperecated single main content to the lesson |
|
| 561 | - * @deprecated since 1.9.0 |
|
| 562 | - */ |
|
| 563 | - public static function deprecate_lesson_image_hook(){ |
|
| 565 | + sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 564 | 566 | |
| 565 | - sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 567 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 566 | 568 | |
| 567 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 569 | + /** |
|
| 570 | + * hook in the deprecated sensei_login_form hook for backwards |
|
| 571 | + * compatibility |
|
| 572 | + * |
|
| 573 | + * @since 1.9.0 |
|
| 574 | + * @deprecated since 1.9.0 |
|
| 575 | + */ |
|
| 576 | + public static function deprecate_sensei_login_form_hook(){ |
|
| 568 | 577 | |
| 569 | - /** |
|
| 570 | - * hook in the deprecated sensei_login_form hook for backwards |
|
| 571 | - * compatibility |
|
| 572 | - * |
|
| 573 | - * @since 1.9.0 |
|
| 574 | - * @deprecated since 1.9.0 |
|
| 575 | - */ |
|
| 576 | - public static function deprecate_sensei_login_form_hook(){ |
|
| 578 | + sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 577 | 579 | |
| 578 | - sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 580 | + } // end deprecate_sensei_login_form_hook |
|
| 579 | 581 | |
| 580 | - } // end deprecate_sensei_login_form_hook |
|
| 582 | + /** |
|
| 583 | + * Fire the sensei_complete_course action. |
|
| 584 | + * |
|
| 585 | + * This is just a backwards compatible function to add the action |
|
| 586 | + * to a template. This should not be used as the function from this |
|
| 587 | + * hook will be added directly to my-courses page via one of the hooks there. |
|
| 588 | + * |
|
| 589 | + * @since 1.9.0 |
|
| 590 | + */ |
|
| 591 | + public static function fire_sensei_complete_course_hook(){ |
|
| 581 | 592 | |
| 582 | - /** |
|
| 583 | - * Fire the sensei_complete_course action. |
|
| 584 | - * |
|
| 585 | - * This is just a backwards compatible function to add the action |
|
| 586 | - * to a template. This should not be used as the function from this |
|
| 587 | - * hook will be added directly to my-courses page via one of the hooks there. |
|
| 588 | - * |
|
| 589 | - * @since 1.9.0 |
|
| 590 | - */ |
|
| 591 | - public static function fire_sensei_complete_course_hook(){ |
|
| 593 | + do_action( 'sensei_complete_course' ); |
|
| 592 | 594 | |
| 593 | - do_action( 'sensei_complete_course' ); |
|
| 595 | + } //fire_sensei_complete_course_hook |
|
| 594 | 596 | |
| 595 | - } //fire_sensei_complete_course_hook |
|
| 597 | + /** |
|
| 598 | + * Fire the frontend message hook |
|
| 599 | + * |
|
| 600 | + * @since 1.9.0 |
|
| 601 | + */ |
|
| 602 | + public static function fire_frontend_messages_hook(){ |
|
| 596 | 603 | |
| 597 | - /** |
|
| 598 | - * Fire the frontend message hook |
|
| 599 | - * |
|
| 600 | - * @since 1.9.0 |
|
| 601 | - */ |
|
| 602 | - public static function fire_frontend_messages_hook(){ |
|
| 604 | + do_action( 'sensei_frontend_messages' ); |
|
| 603 | 605 | |
| 604 | - do_action( 'sensei_frontend_messages' ); |
|
| 606 | + }// end sensei_complete_course_action |
|
| 605 | 607 | |
| 606 | - }// end sensei_complete_course_action |
|
| 608 | + /** |
|
| 609 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 610 | + * of sensei_my_courses_content_inside_before. |
|
| 611 | + * |
|
| 612 | + * @deprected since 1.9.0 |
|
| 613 | + */ |
|
| 614 | + public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 607 | 615 | |
| 608 | - /** |
|
| 609 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 610 | - * of sensei_my_courses_content_inside_before. |
|
| 611 | - * |
|
| 612 | - * @deprected since 1.9.0 |
|
| 613 | - */ |
|
| 614 | - public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 616 | + sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 615 | 617 | |
| 616 | - sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 618 | + }// deprecate_sensei_before_user_course_content_hook |
|
| 617 | 619 | |
| 618 | - }// deprecate_sensei_before_user_course_content_hook |
|
| 620 | + /** |
|
| 621 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 622 | + * of sensei_my_courses_content_inside_after hook. |
|
| 623 | + * |
|
| 624 | + * @deprected since 1.9.0 |
|
| 625 | + */ |
|
| 626 | + public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 619 | 627 | |
| 620 | - /** |
|
| 621 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 622 | - * of sensei_my_courses_content_inside_after hook. |
|
| 623 | - * |
|
| 624 | - * @deprected since 1.9.0 |
|
| 625 | - */ |
|
| 626 | - public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 628 | + sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 627 | 629 | |
| 628 | - sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 630 | + }// deprecate_sensei_after_user_course_content_hook |
|
| 629 | 631 | |
| 630 | - }// deprecate_sensei_after_user_course_content_hook |
|
| 632 | + /** |
|
| 633 | + * Deprecate the 2 main hooks on the archive message template |
|
| 634 | + * |
|
| 635 | + * @deprecated since 1.9.0 |
|
| 636 | + * @since 1.9.0 |
|
| 637 | + */ |
|
| 638 | + public static function deprecated_archive_message_hooks (){ |
|
| 631 | 639 | |
| 632 | - /** |
|
| 633 | - * Deprecate the 2 main hooks on the archive message template |
|
| 634 | - * |
|
| 635 | - * @deprecated since 1.9.0 |
|
| 636 | - * @since 1.9.0 |
|
| 637 | - */ |
|
| 638 | - public static function deprecated_archive_message_hooks (){ |
|
| 640 | + sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 641 | + sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 639 | 642 | |
| 640 | - sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 641 | - sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 643 | + } |
|
| 642 | 644 | |
| 643 | - } |
|
| 645 | + /** |
|
| 646 | + * Run the sensei_complete_quiz for those still hooking |
|
| 647 | + * into but deprecated it. |
|
| 648 | + * |
|
| 649 | + * @deprecated since 1.9.0 |
|
| 650 | + */ |
|
| 651 | + public static function deprecate_sensei_complete_quiz_action(){ |
|
| 644 | 652 | |
| 645 | - /** |
|
| 646 | - * Run the sensei_complete_quiz for those still hooking |
|
| 647 | - * into but deprecated it. |
|
| 648 | - * |
|
| 649 | - * @deprecated since 1.9.0 |
|
| 650 | - */ |
|
| 651 | - public static function deprecate_sensei_complete_quiz_action(){ |
|
| 653 | + sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 652 | 654 | |
| 653 | - sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 655 | + } |
|
| 654 | 656 | |
| 655 | - } |
|
| 657 | + /** |
|
| 658 | + * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 659 | + * it to provide user with a better alternative. |
|
| 660 | + * |
|
| 661 | + * @deprecated since 1.9.0 |
|
| 662 | + */ |
|
| 663 | + public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 656 | 664 | |
| 657 | - /** |
|
| 658 | - * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 659 | - * it to provide user with a better alternative. |
|
| 660 | - * |
|
| 661 | - * @deprecated since 1.9.0 |
|
| 662 | - */ |
|
| 663 | - public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 665 | + // Question Type |
|
| 666 | + global $sensei_question_loop; |
|
| 667 | + $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 668 | + sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 664 | 669 | |
| 665 | - // Question Type |
|
| 666 | - global $sensei_question_loop; |
|
| 667 | - $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 668 | - sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 669 | - |
|
| 670 | - } |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | 672 | |
| 673 | 673 | public static function the_register_button( $post_id = "" ){ |
@@ -675,9 +675,9 @@ discard block |
||
| 675 | 675 | global $current_user, $post; |
| 676 | 676 | |
| 677 | 677 | if ( ! get_option('users_can_register') |
| 678 | - || 'course' != get_post_type( $post_id ) |
|
| 679 | - || ! empty( $current_user->caps ) |
|
| 680 | - || ! Sensei()->settings->get('access_permission') ) { |
|
| 678 | + || 'course' != get_post_type( $post_id ) |
|
| 679 | + || ! empty( $current_user->caps ) |
|
| 680 | + || ! Sensei()->settings->get('access_permission') ) { |
|
| 681 | 681 | |
| 682 | 682 | return; |
| 683 | 683 | |
@@ -10,910 +10,910 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class Sensei_Main { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var string |
|
| 15 | - * Reference to the main plugin file |
|
| 16 | - */ |
|
| 17 | - private $file; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
| 21 | - * @since 1.8.0 |
|
| 22 | - */ |
|
| 23 | - protected static $_instance = null; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Main reference to the plugins current version |
|
| 27 | - */ |
|
| 28 | - public $version; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Public token, referencing for the text domain. |
|
| 32 | - */ |
|
| 33 | - public $token = 'woothemes-sensei'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Plugin url and path for use when access resources. |
|
| 37 | - */ |
|
| 38 | - public $plugin_url; |
|
| 39 | - public $plugin_path; |
|
| 40 | - public $template_url; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var Sensei_PostTypes |
|
| 44 | - * All Sensei sub classes. Currently used to access functionality contained within |
|
| 45 | - * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 46 | - */ |
|
| 47 | - public $post_types; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var WooThemes_Sensei_Settings |
|
| 51 | - */ |
|
| 52 | - public $settings; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var WooThemes_Sensei_Course_Results |
|
| 56 | - */ |
|
| 57 | - public $course_results; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var Sensei_Updates |
|
| 61 | - */ |
|
| 62 | - public $updates; |
|
| 63 | - /** |
|
| 64 | - * @var WooThemes_Sensei_Course |
|
| 65 | - */ |
|
| 66 | - public $course; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var WooThemes_Sensei_Lesson |
|
| 70 | - */ |
|
| 71 | - public $lesson; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var WooThemes_Sensei_Quiz |
|
| 75 | - */ |
|
| 76 | - public $quiz; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var WooThemes_Sensei_Question |
|
| 80 | - */ |
|
| 81 | - public $question; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var WooThemes_Sensei_Admin |
|
| 85 | - */ |
|
| 86 | - public $admin; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @var WooThemes_Sensei_Frontend |
|
| 90 | - */ |
|
| 91 | - public $frontend; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @var Sensei_Notices |
|
| 95 | - */ |
|
| 96 | - public $notices; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var WooThemes_Sensei_Grading |
|
| 100 | - */ |
|
| 101 | - public $grading; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var WooThemes_Sensei_Emails |
|
| 105 | - */ |
|
| 106 | - public $emails; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @var WooThemes_Sensei_Learner_Profiles |
|
| 110 | - */ |
|
| 111 | - public $learner_profiles; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @var Sensei_Teacher |
|
| 115 | - */ |
|
| 116 | - public $teacher; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @var WooThemes_Sensei_Learners |
|
| 120 | - */ |
|
| 121 | - public $learners; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var array |
|
| 125 | - * Global instance for access to the permissions message shown |
|
| 126 | - * when users do not have the right privileges to access resources. |
|
| 127 | - */ |
|
| 128 | - public $permissions_message; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 132 | - */ |
|
| 133 | - public $modules; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @var Sensei_Analysis |
|
| 137 | - */ |
|
| 138 | - public $analysis; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Constructor method. |
|
| 142 | - * @param string $file The base file of the plugin. |
|
| 143 | - * @since 1.0.0 |
|
| 144 | - */ |
|
| 145 | - public function __construct ( $file ) { |
|
| 146 | - |
|
| 147 | - // Setup object data |
|
| 148 | - $this->file = $file; |
|
| 149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | - |
|
| 153 | - // Initialize the core Sensei functionality |
|
| 154 | - $this->init(); |
|
| 155 | - |
|
| 156 | - // Installation |
|
| 157 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 158 | - |
|
| 159 | - // Run this on activation. |
|
| 160 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 161 | - |
|
| 162 | - // Image Sizes |
|
| 163 | - $this->init_image_sizes(); |
|
| 164 | - |
|
| 165 | - // load all hooks |
|
| 166 | - $this->load_hooks(); |
|
| 167 | - |
|
| 168 | - } // End __construct() |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Load the foundations of Sensei. |
|
| 172 | - * @since 1.9.0 |
|
| 173 | - */ |
|
| 174 | - protected function init(){ |
|
| 175 | - |
|
| 176 | - // Localisation |
|
| 177 | - $this->load_plugin_textdomain(); |
|
| 178 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 179 | - |
|
| 180 | - // Setup settings |
|
| 181 | - $this->settings = new Sensei_Settings(); |
|
| 182 | - |
|
| 183 | - // load the shortcode loader into memory, so as to listen to all for |
|
| 184 | - // all shortcodes on the front end |
|
| 185 | - new Sensei_Shortcode_Loader(); |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Global Sensei Instance |
|
| 191 | - * |
|
| 192 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 193 | - * |
|
| 194 | - * @since 1.8.0 |
|
| 195 | - * @static |
|
| 196 | - * @see WC() |
|
| 197 | - * @return WooThemes_Sensei Instance. |
|
| 198 | - */ |
|
| 199 | - public static function instance() { |
|
| 13 | + /** |
|
| 14 | + * @var string |
|
| 15 | + * Reference to the main plugin file |
|
| 16 | + */ |
|
| 17 | + private $file; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
| 21 | + * @since 1.8.0 |
|
| 22 | + */ |
|
| 23 | + protected static $_instance = null; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Main reference to the plugins current version |
|
| 27 | + */ |
|
| 28 | + public $version; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Public token, referencing for the text domain. |
|
| 32 | + */ |
|
| 33 | + public $token = 'woothemes-sensei'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Plugin url and path for use when access resources. |
|
| 37 | + */ |
|
| 38 | + public $plugin_url; |
|
| 39 | + public $plugin_path; |
|
| 40 | + public $template_url; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var Sensei_PostTypes |
|
| 44 | + * All Sensei sub classes. Currently used to access functionality contained within |
|
| 45 | + * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 46 | + */ |
|
| 47 | + public $post_types; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var WooThemes_Sensei_Settings |
|
| 51 | + */ |
|
| 52 | + public $settings; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var WooThemes_Sensei_Course_Results |
|
| 56 | + */ |
|
| 57 | + public $course_results; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var Sensei_Updates |
|
| 61 | + */ |
|
| 62 | + public $updates; |
|
| 63 | + /** |
|
| 64 | + * @var WooThemes_Sensei_Course |
|
| 65 | + */ |
|
| 66 | + public $course; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var WooThemes_Sensei_Lesson |
|
| 70 | + */ |
|
| 71 | + public $lesson; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var WooThemes_Sensei_Quiz |
|
| 75 | + */ |
|
| 76 | + public $quiz; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var WooThemes_Sensei_Question |
|
| 80 | + */ |
|
| 81 | + public $question; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var WooThemes_Sensei_Admin |
|
| 85 | + */ |
|
| 86 | + public $admin; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @var WooThemes_Sensei_Frontend |
|
| 90 | + */ |
|
| 91 | + public $frontend; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @var Sensei_Notices |
|
| 95 | + */ |
|
| 96 | + public $notices; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var WooThemes_Sensei_Grading |
|
| 100 | + */ |
|
| 101 | + public $grading; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var WooThemes_Sensei_Emails |
|
| 105 | + */ |
|
| 106 | + public $emails; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @var WooThemes_Sensei_Learner_Profiles |
|
| 110 | + */ |
|
| 111 | + public $learner_profiles; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @var Sensei_Teacher |
|
| 115 | + */ |
|
| 116 | + public $teacher; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @var WooThemes_Sensei_Learners |
|
| 120 | + */ |
|
| 121 | + public $learners; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @var array |
|
| 125 | + * Global instance for access to the permissions message shown |
|
| 126 | + * when users do not have the right privileges to access resources. |
|
| 127 | + */ |
|
| 128 | + public $permissions_message; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 132 | + */ |
|
| 133 | + public $modules; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @var Sensei_Analysis |
|
| 137 | + */ |
|
| 138 | + public $analysis; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Constructor method. |
|
| 142 | + * @param string $file The base file of the plugin. |
|
| 143 | + * @since 1.0.0 |
|
| 144 | + */ |
|
| 145 | + public function __construct ( $file ) { |
|
| 146 | + |
|
| 147 | + // Setup object data |
|
| 148 | + $this->file = $file; |
|
| 149 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | + |
|
| 153 | + // Initialize the core Sensei functionality |
|
| 154 | + $this->init(); |
|
| 155 | + |
|
| 156 | + // Installation |
|
| 157 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 158 | + |
|
| 159 | + // Run this on activation. |
|
| 160 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 161 | + |
|
| 162 | + // Image Sizes |
|
| 163 | + $this->init_image_sizes(); |
|
| 164 | + |
|
| 165 | + // load all hooks |
|
| 166 | + $this->load_hooks(); |
|
| 167 | + |
|
| 168 | + } // End __construct() |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Load the foundations of Sensei. |
|
| 172 | + * @since 1.9.0 |
|
| 173 | + */ |
|
| 174 | + protected function init(){ |
|
| 175 | + |
|
| 176 | + // Localisation |
|
| 177 | + $this->load_plugin_textdomain(); |
|
| 178 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 179 | + |
|
| 180 | + // Setup settings |
|
| 181 | + $this->settings = new Sensei_Settings(); |
|
| 182 | + |
|
| 183 | + // load the shortcode loader into memory, so as to listen to all for |
|
| 184 | + // all shortcodes on the front end |
|
| 185 | + new Sensei_Shortcode_Loader(); |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Global Sensei Instance |
|
| 191 | + * |
|
| 192 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 193 | + * |
|
| 194 | + * @since 1.8.0 |
|
| 195 | + * @static |
|
| 196 | + * @see WC() |
|
| 197 | + * @return WooThemes_Sensei Instance. |
|
| 198 | + */ |
|
| 199 | + public static function instance() { |
|
| 200 | 200 | |
| 201 | - if ( is_null( self::$_instance ) ) { |
|
| 201 | + if ( is_null( self::$_instance ) ) { |
|
| 202 | 202 | |
| 203 | - //Sensei requires a reference to the main Sensei plugin file |
|
| 204 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 203 | + //Sensei requires a reference to the main Sensei plugin file |
|
| 204 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 205 | 205 | |
| 206 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 206 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 207 | 207 | |
| 208 | - // load the global class objects needed throughout Sensei |
|
| 209 | - self::$_instance->initialize_global_objects(); |
|
| 208 | + // load the global class objects needed throughout Sensei |
|
| 209 | + self::$_instance->initialize_global_objects(); |
|
| 210 | 210 | |
| 211 | - } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - return self::$_instance; |
|
| 213 | + return self::$_instance; |
|
| 214 | 214 | |
| 215 | - } // end instance() |
|
| 215 | + } // end instance() |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * This function is linked into the activation |
|
| 219 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 220 | - * |
|
| 221 | - * @since 1.9.0 |
|
| 222 | - * |
|
| 223 | - * @param $plugin |
|
| 224 | - */ |
|
| 225 | - public static function activation_flush_rules( $plugin ){ |
|
| 217 | + /** |
|
| 218 | + * This function is linked into the activation |
|
| 219 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 220 | + * |
|
| 221 | + * @since 1.9.0 |
|
| 222 | + * |
|
| 223 | + * @param $plugin |
|
| 224 | + */ |
|
| 225 | + public static function activation_flush_rules( $plugin ){ |
|
| 226 | 226 | |
| 227 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 227 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 228 | 228 | |
| 229 | - flush_rewrite_rules(true); |
|
| 229 | + flush_rewrite_rules(true); |
|
| 230 | 230 | |
| 231 | - } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Cloning is forbidden. |
|
| 237 | - * @since 1.8.0 |
|
| 238 | - */ |
|
| 239 | - public function __clone() { |
|
| 240 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 241 | - } |
|
| 235 | + /** |
|
| 236 | + * Cloning is forbidden. |
|
| 237 | + * @since 1.8.0 |
|
| 238 | + */ |
|
| 239 | + public function __clone() { |
|
| 240 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Unserializing instances of this class is forbidden. |
|
| 245 | - * @since 1.8.0 |
|
| 246 | - */ |
|
| 247 | - public function __wakeup() { |
|
| 248 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 249 | - } |
|
| 243 | + /** |
|
| 244 | + * Unserializing instances of this class is forbidden. |
|
| 245 | + * @since 1.8.0 |
|
| 246 | + */ |
|
| 247 | + public function __wakeup() { |
|
| 248 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * Load the properties for the main Sensei object |
|
| 253 | - * |
|
| 254 | - * @since 1.9.0 |
|
| 255 | - */ |
|
| 256 | - public function initialize_global_objects(){ |
|
| 251 | + /** |
|
| 252 | + * Load the properties for the main Sensei object |
|
| 253 | + * |
|
| 254 | + * @since 1.9.0 |
|
| 255 | + */ |
|
| 256 | + public function initialize_global_objects(){ |
|
| 257 | 257 | |
| 258 | - // Setup post types. |
|
| 259 | - $this->post_types = new Sensei_PostTypes(); |
|
| 258 | + // Setup post types. |
|
| 259 | + $this->post_types = new Sensei_PostTypes(); |
|
| 260 | 260 | |
| 261 | - // Lad the updates class |
|
| 262 | - $this->updates = new Sensei_Updates( $this ); |
|
| 261 | + // Lad the updates class |
|
| 262 | + $this->updates = new Sensei_Updates( $this ); |
|
| 263 | 263 | |
| 264 | - // Load Course Results Class |
|
| 265 | - $this->course_results = new Sensei_Course_Results(); |
|
| 264 | + // Load Course Results Class |
|
| 265 | + $this->course_results = new Sensei_Course_Results(); |
|
| 266 | 266 | |
| 267 | - // Load the teacher role |
|
| 268 | - $this->teacher = new Sensei_Teacher(); |
|
| 267 | + // Load the teacher role |
|
| 268 | + $this->teacher = new Sensei_Teacher(); |
|
| 269 | 269 | |
| 270 | - // Add the Course class |
|
| 271 | - $this->course = $this->post_types->course; |
|
| 270 | + // Add the Course class |
|
| 271 | + $this->course = $this->post_types->course; |
|
| 272 | 272 | |
| 273 | - // Add the lesson class |
|
| 274 | - $this->lesson = $this->post_types->lesson; |
|
| 273 | + // Add the lesson class |
|
| 274 | + $this->lesson = $this->post_types->lesson; |
|
| 275 | 275 | |
| 276 | - // Add the question class |
|
| 277 | - $this->question = $this->post_types->question; |
|
| 276 | + // Add the question class |
|
| 277 | + $this->question = $this->post_types->question; |
|
| 278 | 278 | |
| 279 | - //Add the quiz class |
|
| 280 | - $this->quiz = $this->post_types->quiz; |
|
| 279 | + //Add the quiz class |
|
| 280 | + $this->quiz = $this->post_types->quiz; |
|
| 281 | 281 | |
| 282 | - // load the modules class after all plugsin are loaded |
|
| 283 | - $this->load_modules_class(); |
|
| 282 | + // load the modules class after all plugsin are loaded |
|
| 283 | + $this->load_modules_class(); |
|
| 284 | 284 | |
| 285 | - // Load Learner Management Functionality |
|
| 286 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 285 | + // Load Learner Management Functionality |
|
| 286 | + $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 287 | 287 | |
| 288 | - // Differentiate between administration and frontend logic. |
|
| 289 | - if ( is_admin() ) { |
|
| 288 | + // Differentiate between administration and frontend logic. |
|
| 289 | + if ( is_admin() ) { |
|
| 290 | 290 | |
| 291 | - // Load Admin Welcome class |
|
| 292 | - new Sensei_Welcome(); |
|
| 291 | + // Load Admin Welcome class |
|
| 292 | + new Sensei_Welcome(); |
|
| 293 | 293 | |
| 294 | - // Load Admin Class |
|
| 295 | - $this->admin = new Sensei_Admin( $this->file ); |
|
| 294 | + // Load Admin Class |
|
| 295 | + $this->admin = new Sensei_Admin( $this->file ); |
|
| 296 | 296 | |
| 297 | - // Load Analysis Reports |
|
| 298 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 297 | + // Load Analysis Reports |
|
| 298 | + $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 299 | 299 | |
| 300 | - } else { |
|
| 300 | + } else { |
|
| 301 | 301 | |
| 302 | - // Load Frontend Class |
|
| 303 | - $this->frontend = new Sensei_Frontend(); |
|
| 302 | + // Load Frontend Class |
|
| 303 | + $this->frontend = new Sensei_Frontend(); |
|
| 304 | 304 | |
| 305 | - // Load notice Class |
|
| 306 | - $this->notices = new Sensei_Notices(); |
|
| 305 | + // Load notice Class |
|
| 306 | + $this->notices = new Sensei_Notices(); |
|
| 307 | 307 | |
| 308 | - // Load built in themes support integration |
|
| 309 | - new Sensei_Theme_Integration_Loader(); |
|
| 308 | + // Load built in themes support integration |
|
| 309 | + new Sensei_Theme_Integration_Loader(); |
|
| 310 | 310 | |
| 311 | 311 | |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - // Load Grading Functionality |
|
| 315 | - $this->grading = new Sensei_Grading( $this->file ); |
|
| 314 | + // Load Grading Functionality |
|
| 315 | + $this->grading = new Sensei_Grading( $this->file ); |
|
| 316 | 316 | |
| 317 | - // Load Email Class |
|
| 318 | - $this->emails = new Sensei_Emails( $this->file ); |
|
| 317 | + // Load Email Class |
|
| 318 | + $this->emails = new Sensei_Emails( $this->file ); |
|
| 319 | 319 | |
| 320 | - // Load Learner Profiles Class |
|
| 321 | - $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 320 | + // Load Learner Profiles Class |
|
| 321 | + $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 322 | 322 | |
| 323 | - } |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - /** |
|
| 326 | - * Initialize all Sensei hooks |
|
| 327 | - * |
|
| 328 | - * @since 1.9.0 |
|
| 329 | - */ |
|
| 330 | - public function load_hooks(){ |
|
| 325 | + /** |
|
| 326 | + * Initialize all Sensei hooks |
|
| 327 | + * |
|
| 328 | + * @since 1.9.0 |
|
| 329 | + */ |
|
| 330 | + public function load_hooks(){ |
|
| 331 | 331 | |
| 332 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 333 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 332 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 333 | + add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 334 | 334 | |
| 335 | - // Filter comment counts |
|
| 336 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 335 | + // Filter comment counts |
|
| 336 | + add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 337 | 337 | |
| 338 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 338 | + add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 339 | 339 | |
| 340 | - // Check for and activate JetPack LaTeX support |
|
| 341 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 340 | + // Check for and activate JetPack LaTeX support |
|
| 341 | + add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 342 | 342 | |
| 343 | - // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 344 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 343 | + // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 344 | + add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 345 | 345 | |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - /** |
|
| 349 | - * Run Sensei updates. |
|
| 350 | - * @access public |
|
| 351 | - * @since 1.1.0 |
|
| 352 | - * @return void |
|
| 353 | - */ |
|
| 354 | - public function run_updates() { |
|
| 355 | - // Run updates if administrator |
|
| 356 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 348 | + /** |
|
| 349 | + * Run Sensei updates. |
|
| 350 | + * @access public |
|
| 351 | + * @since 1.1.0 |
|
| 352 | + * @return void |
|
| 353 | + */ |
|
| 354 | + public function run_updates() { |
|
| 355 | + // Run updates if administrator |
|
| 356 | + if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 357 | 357 | |
| 358 | - $this->updates->update(); |
|
| 358 | + $this->updates->update(); |
|
| 359 | 359 | |
| 360 | - } // End If Statement |
|
| 361 | - } // End run_updates() |
|
| 360 | + } // End If Statement |
|
| 361 | + } // End run_updates() |
|
| 362 | 362 | |
| 363 | - /** |
|
| 364 | - * Register the widgets. |
|
| 365 | - * @access public |
|
| 366 | - * @since 1.0.0 |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function register_widgets () { |
|
| 370 | - // Widget List (key => value is filename => widget class). |
|
| 371 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 372 | - 'lesson-component' => 'Lesson_Component', |
|
| 373 | - 'course-categories' => 'Course_Categories', |
|
| 374 | - 'category-courses' => 'Category_Courses' ) |
|
| 375 | - ); |
|
| 376 | - foreach ( $widget_list as $key => $value ) { |
|
| 377 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 378 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 379 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 380 | - } |
|
| 381 | - } // End For Loop |
|
| 363 | + /** |
|
| 364 | + * Register the widgets. |
|
| 365 | + * @access public |
|
| 366 | + * @since 1.0.0 |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function register_widgets () { |
|
| 370 | + // Widget List (key => value is filename => widget class). |
|
| 371 | + $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 372 | + 'lesson-component' => 'Lesson_Component', |
|
| 373 | + 'course-categories' => 'Course_Categories', |
|
| 374 | + 'category-courses' => 'Category_Courses' ) |
|
| 375 | + ); |
|
| 376 | + foreach ( $widget_list as $key => $value ) { |
|
| 377 | + if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 378 | + require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 379 | + register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 380 | + } |
|
| 381 | + } // End For Loop |
|
| 382 | 382 | |
| 383 | - do_action( 'sensei_register_widgets' ); |
|
| 383 | + do_action( 'sensei_register_widgets' ); |
|
| 384 | 384 | |
| 385 | - } // End register_widgets() |
|
| 385 | + } // End register_widgets() |
|
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * Load the plugin's localisation file. |
|
| 389 | - * @access public |
|
| 390 | - * @since 1.0.0 |
|
| 391 | - * @return void |
|
| 392 | - */ |
|
| 393 | - public function load_localisation () { |
|
| 387 | + /** |
|
| 388 | + * Load the plugin's localisation file. |
|
| 389 | + * @access public |
|
| 390 | + * @since 1.0.0 |
|
| 391 | + * @return void |
|
| 392 | + */ |
|
| 393 | + public function load_localisation () { |
|
| 394 | 394 | |
| 395 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 395 | + load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 396 | 396 | |
| 397 | - } // End load_localisation() |
|
| 397 | + } // End load_localisation() |
|
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 401 | - * @access public |
|
| 402 | - * @since 1.0.0 |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - public function load_plugin_textdomain () { |
|
| 406 | - |
|
| 407 | - $domain = 'woothemes-sensei'; |
|
| 408 | - // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 409 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 410 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 411 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 412 | - |
|
| 413 | - } // End load_plugin_textdomain() |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Run on activation. |
|
| 417 | - * @access public |
|
| 418 | - * @since 1.0.0 |
|
| 419 | - * @return void |
|
| 420 | - */ |
|
| 421 | - public function activation () { |
|
| 422 | - |
|
| 423 | - $this->register_plugin_version(); |
|
| 424 | - |
|
| 425 | - } // End activation() |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Register activation hooks. |
|
| 430 | - * @access public |
|
| 431 | - * @since 1.0.0 |
|
| 432 | - * @return void |
|
| 433 | - */ |
|
| 434 | - public function install () { |
|
| 435 | - |
|
| 436 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 437 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 438 | - |
|
| 439 | - } // End install() |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Run on activation of the plugin. |
|
| 444 | - * @access public |
|
| 445 | - * @since 1.0.0 |
|
| 446 | - * @return void |
|
| 447 | - */ |
|
| 448 | - public function activate_sensei () { |
|
| 449 | - |
|
| 450 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 451 | - update_option( 'sensei_installed', 1 ); |
|
| 452 | - |
|
| 453 | - } // End activate_sensei() |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Register the plugin's version. |
|
| 457 | - * @access public |
|
| 458 | - * @since 1.0.0 |
|
| 459 | - * @return void |
|
| 460 | - */ |
|
| 461 | - private function register_plugin_version () { |
|
| 462 | - if ( $this->version != '' ) { |
|
| 463 | - |
|
| 464 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 465 | - |
|
| 466 | - } |
|
| 467 | - } // End register_plugin_version() |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 471 | - * @access public |
|
| 472 | - * @since 1.0.1 |
|
| 473 | - * @return void |
|
| 474 | - */ |
|
| 475 | - public function ensure_post_thumbnails_support () { |
|
| 399 | + /** |
|
| 400 | + * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 401 | + * @access public |
|
| 402 | + * @since 1.0.0 |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + public function load_plugin_textdomain () { |
|
| 406 | + |
|
| 407 | + $domain = 'woothemes-sensei'; |
|
| 408 | + // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 409 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 410 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 411 | + load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 412 | + |
|
| 413 | + } // End load_plugin_textdomain() |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Run on activation. |
|
| 417 | + * @access public |
|
| 418 | + * @since 1.0.0 |
|
| 419 | + * @return void |
|
| 420 | + */ |
|
| 421 | + public function activation () { |
|
| 422 | + |
|
| 423 | + $this->register_plugin_version(); |
|
| 424 | + |
|
| 425 | + } // End activation() |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Register activation hooks. |
|
| 430 | + * @access public |
|
| 431 | + * @since 1.0.0 |
|
| 432 | + * @return void |
|
| 433 | + */ |
|
| 434 | + public function install () { |
|
| 435 | + |
|
| 436 | + register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 437 | + register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 438 | + |
|
| 439 | + } // End install() |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Run on activation of the plugin. |
|
| 444 | + * @access public |
|
| 445 | + * @since 1.0.0 |
|
| 446 | + * @return void |
|
| 447 | + */ |
|
| 448 | + public function activate_sensei () { |
|
| 449 | + |
|
| 450 | + update_option( 'skip_install_sensei_pages', 0 ); |
|
| 451 | + update_option( 'sensei_installed', 1 ); |
|
| 452 | + |
|
| 453 | + } // End activate_sensei() |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Register the plugin's version. |
|
| 457 | + * @access public |
|
| 458 | + * @since 1.0.0 |
|
| 459 | + * @return void |
|
| 460 | + */ |
|
| 461 | + private function register_plugin_version () { |
|
| 462 | + if ( $this->version != '' ) { |
|
| 463 | + |
|
| 464 | + update_option( 'woothemes-sensei-version', $this->version ); |
|
| 465 | + |
|
| 466 | + } |
|
| 467 | + } // End register_plugin_version() |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 471 | + * @access public |
|
| 472 | + * @since 1.0.1 |
|
| 473 | + * @return void |
|
| 474 | + */ |
|
| 475 | + public function ensure_post_thumbnails_support () { |
|
| 476 | 476 | |
| 477 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 477 | + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 478 | 478 | |
| 479 | - } // End ensure_post_thumbnails_support() |
|
| 479 | + } // End ensure_post_thumbnails_support() |
|
| 480 | 480 | |
| 481 | - /** |
|
| 482 | - * template_loader function. |
|
| 483 | - * |
|
| 484 | - * @access public |
|
| 485 | - * @param mixed $template |
|
| 486 | - * @return void |
|
| 487 | - * @deprecated |
|
| 488 | - */ |
|
| 489 | - public function template_loader ( $template = '' ) { |
|
| 481 | + /** |
|
| 482 | + * template_loader function. |
|
| 483 | + * |
|
| 484 | + * @access public |
|
| 485 | + * @param mixed $template |
|
| 486 | + * @return void |
|
| 487 | + * @deprecated |
|
| 488 | + */ |
|
| 489 | + public function template_loader ( $template = '' ) { |
|
| 490 | 490 | |
| 491 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 492 | - Sensei_Templates::template_loader( $template ); |
|
| 491 | + _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 492 | + Sensei_Templates::template_loader( $template ); |
|
| 493 | 493 | |
| 494 | - } // End template_loader() |
|
| 494 | + } // End template_loader() |
|
| 495 | 495 | |
| 496 | - /** |
|
| 497 | - * Determine the relative path to the plugin's directory. |
|
| 498 | - * @access public |
|
| 499 | - * @since 1.0.0 |
|
| 500 | - * @return string $sensei_plugin_path |
|
| 501 | - */ |
|
| 502 | - public function plugin_path () { |
|
| 496 | + /** |
|
| 497 | + * Determine the relative path to the plugin's directory. |
|
| 498 | + * @access public |
|
| 499 | + * @since 1.0.0 |
|
| 500 | + * @return string $sensei_plugin_path |
|
| 501 | + */ |
|
| 502 | + public function plugin_path () { |
|
| 503 | 503 | |
| 504 | - if ( $this->plugin_path ) { |
|
| 504 | + if ( $this->plugin_path ) { |
|
| 505 | 505 | |
| 506 | - $sensei_plugin_path = $this->plugin_path; |
|
| 506 | + $sensei_plugin_path = $this->plugin_path; |
|
| 507 | 507 | |
| 508 | - }else{ |
|
| 508 | + }else{ |
|
| 509 | 509 | |
| 510 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 510 | + $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 511 | 511 | |
| 512 | - } |
|
| 512 | + } |
|
| 513 | 513 | |
| 514 | - return $sensei_plugin_path; |
|
| 514 | + return $sensei_plugin_path; |
|
| 515 | 515 | |
| 516 | - } // End plugin_path() |
|
| 516 | + } // End plugin_path() |
|
| 517 | 517 | |
| 518 | - /** |
|
| 519 | - * Retrieve the ID of a specified page setting. |
|
| 520 | - * @access public |
|
| 521 | - * @since 1.0.0 |
|
| 522 | - * @param string $page |
|
| 523 | - * @return int |
|
| 524 | - */ |
|
| 525 | - public function get_page_id ( $page ) { |
|
| 526 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 527 | - return ( $page ) ? $page : -1; |
|
| 528 | - } // End get_page_id() |
|
| 518 | + /** |
|
| 519 | + * Retrieve the ID of a specified page setting. |
|
| 520 | + * @access public |
|
| 521 | + * @since 1.0.0 |
|
| 522 | + * @param string $page |
|
| 523 | + * @return int |
|
| 524 | + */ |
|
| 525 | + public function get_page_id ( $page ) { |
|
| 526 | + $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 527 | + return ( $page ) ? $page : -1; |
|
| 528 | + } // End get_page_id() |
|
| 529 | 529 | |
| 530 | - /** |
|
| 531 | - * check_user_permissions function. |
|
| 532 | - * |
|
| 533 | - * @access public |
|
| 534 | - * @param string $page (default: '') |
|
| 535 | - * |
|
| 536 | - * @return bool |
|
| 537 | - */ |
|
| 538 | - public function check_user_permissions ( $page = '' ) { |
|
| 530 | + /** |
|
| 531 | + * check_user_permissions function. |
|
| 532 | + * |
|
| 533 | + * @access public |
|
| 534 | + * @param string $page (default: '') |
|
| 535 | + * |
|
| 536 | + * @return bool |
|
| 537 | + */ |
|
| 538 | + public function check_user_permissions ( $page = '' ) { |
|
| 539 | 539 | |
| 540 | - global $current_user, $post; |
|
| 540 | + global $current_user, $post; |
|
| 541 | 541 | |
| 542 | - $user_allowed = false; |
|
| 542 | + $user_allowed = false; |
|
| 543 | 543 | |
| 544 | - switch ( $page ) { |
|
| 545 | - case 'course-single': |
|
| 546 | - // check for prerequisite course or lesson, |
|
| 547 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true ); |
|
| 548 | - $update_course = Sensei_WC::course_update( $post->ID ); |
|
| 544 | + switch ( $page ) { |
|
| 545 | + case 'course-single': |
|
| 546 | + // check for prerequisite course or lesson, |
|
| 547 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true ); |
|
| 548 | + $update_course = Sensei_WC::course_update( $post->ID ); |
|
| 549 | 549 | |
| 550 | - // Count completed lessons |
|
| 551 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 550 | + // Count completed lessons |
|
| 551 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 552 | 552 | |
| 553 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 553 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 554 | 554 | |
| 555 | - } else { |
|
| 556 | - $prerequisite_complete = true; |
|
| 557 | - } // End If Statement |
|
| 555 | + } else { |
|
| 556 | + $prerequisite_complete = true; |
|
| 557 | + } // End If Statement |
|
| 558 | 558 | |
| 559 | - // Handles restrictions on the course |
|
| 560 | - if ( ( ! $prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) ) { |
|
| 559 | + // Handles restrictions on the course |
|
| 560 | + if ( ( ! $prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) ) { |
|
| 561 | 561 | |
| 562 | - $user_allowed = false; |
|
| 563 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 564 | - $this->notices->add_notice( sprintf( __( 'Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ), 'info' ); |
|
| 562 | + $user_allowed = false; |
|
| 563 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 564 | + $this->notices->add_notice( sprintf( __( 'Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ), 'info' ); |
|
| 565 | 565 | |
| 566 | - } elseif( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) && ! Sensei_Utils::user_started_course( $post->ID, $current_user->ID ) ) { |
|
| 566 | + } elseif( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) && ! Sensei_Utils::user_started_course( $post->ID, $current_user->ID ) ) { |
|
| 567 | 567 | |
| 568 | - $message = sprintf( __( 'Or %1$s login %2$s to access your purchased courses', 'woothemes-sensei' ), '<a href="'.sensei_user_login_url().'">', '</a>' ); |
|
| 569 | - $this->notices->add_notice( $message, 'info' ); |
|
| 568 | + $message = sprintf( __( 'Or %1$s login %2$s to access your purchased courses', 'woothemes-sensei' ), '<a href="'.sensei_user_login_url().'">', '</a>' ); |
|
| 569 | + $this->notices->add_notice( $message, 'info' ); |
|
| 570 | 570 | |
| 571 | 571 | |
| 572 | - } elseif ( ! Sensei_Utils::user_started_course( $post->ID, $current_user->ID ) ) { |
|
| 572 | + } elseif ( ! Sensei_Utils::user_started_course( $post->ID, $current_user->ID ) ) { |
|
| 573 | 573 | |
| 574 | 574 | // users who haven't started the course are allowed to view it |
| 575 | - $user_allowed = true; |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - } else { |
|
| 580 | - |
|
| 581 | - $user_allowed = true; |
|
| 582 | - |
|
| 583 | - } // End If Statement |
|
| 584 | - break; |
|
| 585 | - case 'lesson-single': |
|
| 586 | - // Check for WC purchase |
|
| 587 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 588 | - |
|
| 589 | - $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
| 590 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 591 | - |
|
| 592 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 593 | - $user_allowed = true; |
|
| 594 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 595 | - |
|
| 596 | - $user_allowed = true; |
|
| 597 | - |
|
| 598 | - } else { |
|
| 599 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 600 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 601 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 602 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 603 | - if ( $is_preview ) { |
|
| 604 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 605 | - } else { |
|
| 606 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 607 | - } |
|
| 608 | - } else { |
|
| 609 | - if ( $is_preview ) { |
|
| 610 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 611 | - } else { |
|
| 612 | - /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 613 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 614 | - } |
|
| 615 | - } // End If Statement |
|
| 616 | - } // End If Statement |
|
| 617 | - break; |
|
| 618 | - case 'quiz-single': |
|
| 619 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 620 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 621 | - |
|
| 622 | - $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
| 623 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 624 | - |
|
| 625 | - // Check for prerequisite lesson for this quiz |
|
| 626 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 627 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 628 | - |
|
| 629 | - // Handle restrictions |
|
| 630 | - if( sensei_all_access() ) { |
|
| 631 | - |
|
| 632 | - $user_allowed = true; |
|
| 633 | - |
|
| 634 | - } else { |
|
| 635 | - |
|
| 636 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 637 | - |
|
| 638 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 639 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 640 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 641 | - |
|
| 642 | - } else { |
|
| 643 | - |
|
| 644 | - $user_allowed = true; |
|
| 645 | - |
|
| 646 | - } // End If Statement |
|
| 647 | - } // End If Statement |
|
| 648 | - } elseif( $this->access_settings() ) { |
|
| 649 | - // Check if the user has started the course |
|
| 650 | - |
|
| 651 | - if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 652 | - |
|
| 653 | - $user_allowed = false; |
|
| 654 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 655 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 656 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 657 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 658 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 659 | - } else { |
|
| 660 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 661 | - } // End If Statement |
|
| 662 | - } else { |
|
| 663 | - $user_allowed = true; |
|
| 664 | - } // End If Statement |
|
| 665 | - } else { |
|
| 666 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 667 | - $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 668 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 669 | - } // End If Statement |
|
| 670 | - break; |
|
| 671 | - default: |
|
| 672 | - $user_allowed = true; |
|
| 673 | - break; |
|
| 674 | - |
|
| 675 | - } // End Switch Statement |
|
| 676 | - |
|
| 677 | - /** |
|
| 678 | - * filter the permissions message shown on sensei post types. |
|
| 679 | - * |
|
| 680 | - * @since 1.8.7 |
|
| 681 | - * |
|
| 682 | - * @param array $permissions_message{ |
|
| 683 | - * |
|
| 684 | - * @type string $title |
|
| 685 | - * @type string $message |
|
| 686 | - * |
|
| 687 | - * } |
|
| 688 | - * @param string $post_id |
|
| 689 | - */ |
|
| 690 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 575 | + $user_allowed = true; |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + } else { |
|
| 580 | + |
|
| 581 | + $user_allowed = true; |
|
| 582 | + |
|
| 583 | + } // End If Statement |
|
| 584 | + break; |
|
| 585 | + case 'lesson-single': |
|
| 586 | + // Check for WC purchase |
|
| 587 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 588 | + |
|
| 589 | + $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
| 590 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 591 | + |
|
| 592 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 593 | + $user_allowed = true; |
|
| 594 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 595 | + |
|
| 596 | + $user_allowed = true; |
|
| 597 | + |
|
| 598 | + } else { |
|
| 599 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 600 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 601 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 602 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 603 | + if ( $is_preview ) { |
|
| 604 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 605 | + } else { |
|
| 606 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 607 | + } |
|
| 608 | + } else { |
|
| 609 | + if ( $is_preview ) { |
|
| 610 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 611 | + } else { |
|
| 612 | + /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 613 | + $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 614 | + } |
|
| 615 | + } // End If Statement |
|
| 616 | + } // End If Statement |
|
| 617 | + break; |
|
| 618 | + case 'quiz-single': |
|
| 619 | + $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 620 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 621 | + |
|
| 622 | + $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
| 623 | + if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 624 | + |
|
| 625 | + // Check for prerequisite lesson for this quiz |
|
| 626 | + $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 627 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 628 | + |
|
| 629 | + // Handle restrictions |
|
| 630 | + if( sensei_all_access() ) { |
|
| 631 | + |
|
| 632 | + $user_allowed = true; |
|
| 633 | + |
|
| 634 | + } else { |
|
| 635 | + |
|
| 636 | + if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 637 | + |
|
| 638 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 639 | + $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 640 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 641 | + |
|
| 642 | + } else { |
|
| 643 | + |
|
| 644 | + $user_allowed = true; |
|
| 645 | + |
|
| 646 | + } // End If Statement |
|
| 647 | + } // End If Statement |
|
| 648 | + } elseif( $this->access_settings() ) { |
|
| 649 | + // Check if the user has started the course |
|
| 650 | + |
|
| 651 | + if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 652 | + |
|
| 653 | + $user_allowed = false; |
|
| 654 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 655 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 656 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 657 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 658 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 659 | + } else { |
|
| 660 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 661 | + } // End If Statement |
|
| 662 | + } else { |
|
| 663 | + $user_allowed = true; |
|
| 664 | + } // End If Statement |
|
| 665 | + } else { |
|
| 666 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 667 | + $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 668 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 669 | + } // End If Statement |
|
| 670 | + break; |
|
| 671 | + default: |
|
| 672 | + $user_allowed = true; |
|
| 673 | + break; |
|
| 674 | + |
|
| 675 | + } // End Switch Statement |
|
| 676 | + |
|
| 677 | + /** |
|
| 678 | + * filter the permissions message shown on sensei post types. |
|
| 679 | + * |
|
| 680 | + * @since 1.8.7 |
|
| 681 | + * |
|
| 682 | + * @param array $permissions_message{ |
|
| 683 | + * |
|
| 684 | + * @type string $title |
|
| 685 | + * @type string $message |
|
| 686 | + * |
|
| 687 | + * } |
|
| 688 | + * @param string $post_id |
|
| 689 | + */ |
|
| 690 | + $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 691 | 691 | |
| 692 | 692 | // add the permissions message to the stack |
| 693 | 693 | |
| 694 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 695 | - $user_allowed = true; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * Filter the permissions check final result. Which determines if the user has |
|
| 700 | - * access to the given page. |
|
| 701 | - * |
|
| 702 | - * @since 1.0 |
|
| 703 | - * |
|
| 704 | - * @param boolean $user_allowed |
|
| 705 | - * @param integer $user_id |
|
| 706 | - * |
|
| 707 | - */ |
|
| 708 | - return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID ); |
|
| 709 | - |
|
| 710 | - } // End get_placeholder_image() |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 715 | - * @since 1.0.0 |
|
| 716 | - * @access public |
|
| 717 | - * @return bool |
|
| 718 | - */ |
|
| 719 | - public function access_settings () { |
|
| 720 | - |
|
| 721 | - if( sensei_all_access() ) return true; |
|
| 722 | - |
|
| 723 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 724 | - if ( is_user_logged_in() ) { |
|
| 725 | - return true; |
|
| 726 | - } else { |
|
| 727 | - return false; |
|
| 728 | - } // End If Statement |
|
| 729 | - } else { |
|
| 730 | - return true; |
|
| 731 | - } // End If Statement |
|
| 732 | - } // End access_settings() |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * load_class loads in class files |
|
| 736 | - * @since 1.2.0 |
|
| 737 | - * @access public |
|
| 738 | - * @return void |
|
| 739 | - */ |
|
| 740 | - public function load_class ( $class_name = '' ) { |
|
| 741 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 742 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 743 | - } // End If Statement |
|
| 744 | - } // End load_class() |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 748 | - * @since 1.4.0 |
|
| 749 | - * @access public |
|
| 750 | - * @param array $comments |
|
| 751 | - * @param integer $post_id |
|
| 752 | - * @return array |
|
| 753 | - */ |
|
| 754 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 755 | - global $wpdb; |
|
| 756 | - |
|
| 757 | - $post_id = (int) $post_id; |
|
| 758 | - |
|
| 759 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 760 | - |
|
| 761 | - if ( false !== $count ) { |
|
| 762 | - return $count; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 766 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 767 | - foreach ( (array) $stati AS $status ) { |
|
| 768 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 769 | - $statuses[] = $status['comment_type']; |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 773 | - |
|
| 774 | - if ( $post_id > 0 ) |
|
| 775 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 776 | - |
|
| 777 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 778 | - |
|
| 779 | - $total = 0; |
|
| 780 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 781 | - foreach ( (array) $count as $row ) { |
|
| 782 | - // Don't count post-trashed toward totals |
|
| 783 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 784 | - $total += $row['num_comments']; |
|
| 785 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 786 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - $stats['total_comments'] = $total; |
|
| 790 | - foreach ( $approved as $key ) { |
|
| 791 | - if ( empty($stats[$key]) ) |
|
| 792 | - $stats[$key] = 0; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - $stats = (object) $stats; |
|
| 796 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 797 | - |
|
| 798 | - return $stats; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Init images. |
|
| 803 | - * |
|
| 804 | - * @since 1.4.5 |
|
| 805 | - * @access public |
|
| 806 | - * @return void |
|
| 807 | - */ |
|
| 808 | - public function init_image_sizes() { |
|
| 809 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 810 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 811 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 812 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 813 | - |
|
| 814 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 815 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 816 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 817 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Get an image size. |
|
| 822 | - * |
|
| 823 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 824 | - * |
|
| 825 | - * @since 1.4.5 |
|
| 826 | - * @access public |
|
| 827 | - * @param mixed $image_size |
|
| 828 | - * @return string |
|
| 829 | - */ |
|
| 830 | - public function get_image_size( $image_size ) { |
|
| 831 | - |
|
| 832 | - // Only return sizes we define in settings |
|
| 833 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 834 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 835 | - |
|
| 836 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 837 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 838 | - } |
|
| 839 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 840 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 841 | - } |
|
| 842 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 843 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $size = array_filter( array( |
|
| 847 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 848 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 849 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 850 | - ) ); |
|
| 851 | - |
|
| 852 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 853 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 854 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 855 | - |
|
| 856 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - public function body_class( $classes ) { |
|
| 860 | - if( is_sensei() ) { |
|
| 861 | - $classes[] = 'sensei'; |
|
| 862 | - } |
|
| 863 | - return $classes; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 868 | - * |
|
| 869 | - * @return null |
|
| 870 | - * @since 1.7.0 |
|
| 871 | - */ |
|
| 872 | - public function jetpack_latex_support() { |
|
| 873 | - if ( function_exists( 'latex_markup') ) { |
|
| 874 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 875 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Load the module functionality. |
|
| 881 | - * |
|
| 882 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 883 | - * the retired modules extension. |
|
| 884 | - * |
|
| 885 | - * @since 1.8.0 |
|
| 886 | - */ |
|
| 887 | - public function load_modules_class(){ |
|
| 888 | - global $sensei_modules; |
|
| 889 | - |
|
| 890 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 891 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 892 | - |
|
| 893 | - //Load the modules class |
|
| 894 | - require_once( 'class-sensei-modules.php'); |
|
| 895 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 896 | - |
|
| 897 | - }else{ |
|
| 898 | - // fallback for people still using the modules extension. |
|
| 899 | - global $sensei_modules; |
|
| 900 | - Sensei()->modules = $sensei_modules; |
|
| 901 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * Tell the user to that the modules extension is no longer needed. |
|
| 907 | - * |
|
| 908 | - * @since 1.8.0 |
|
| 909 | - */ |
|
| 910 | - public function disable_sensei_modules_extension(){ ?> |
|
| 694 | + if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 695 | + $user_allowed = true; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * Filter the permissions check final result. Which determines if the user has |
|
| 700 | + * access to the given page. |
|
| 701 | + * |
|
| 702 | + * @since 1.0 |
|
| 703 | + * |
|
| 704 | + * @param boolean $user_allowed |
|
| 705 | + * @param integer $user_id |
|
| 706 | + * |
|
| 707 | + */ |
|
| 708 | + return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID ); |
|
| 709 | + |
|
| 710 | + } // End get_placeholder_image() |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 715 | + * @since 1.0.0 |
|
| 716 | + * @access public |
|
| 717 | + * @return bool |
|
| 718 | + */ |
|
| 719 | + public function access_settings () { |
|
| 720 | + |
|
| 721 | + if( sensei_all_access() ) return true; |
|
| 722 | + |
|
| 723 | + if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 724 | + if ( is_user_logged_in() ) { |
|
| 725 | + return true; |
|
| 726 | + } else { |
|
| 727 | + return false; |
|
| 728 | + } // End If Statement |
|
| 729 | + } else { |
|
| 730 | + return true; |
|
| 731 | + } // End If Statement |
|
| 732 | + } // End access_settings() |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * load_class loads in class files |
|
| 736 | + * @since 1.2.0 |
|
| 737 | + * @access public |
|
| 738 | + * @return void |
|
| 739 | + */ |
|
| 740 | + public function load_class ( $class_name = '' ) { |
|
| 741 | + if ( '' != $class_name && '' != $this->token ) { |
|
| 742 | + require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 743 | + } // End If Statement |
|
| 744 | + } // End load_class() |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 748 | + * @since 1.4.0 |
|
| 749 | + * @access public |
|
| 750 | + * @param array $comments |
|
| 751 | + * @param integer $post_id |
|
| 752 | + * @return array |
|
| 753 | + */ |
|
| 754 | + public function sensei_count_comments( $comments, $post_id ) { |
|
| 755 | + global $wpdb; |
|
| 756 | + |
|
| 757 | + $post_id = (int) $post_id; |
|
| 758 | + |
|
| 759 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 760 | + |
|
| 761 | + if ( false !== $count ) { |
|
| 762 | + return $count; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + $statuses = array( '' ); // Default to the WP normal comments |
|
| 766 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 767 | + foreach ( (array) $stati AS $status ) { |
|
| 768 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 769 | + $statuses[] = $status['comment_type']; |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 773 | + |
|
| 774 | + if ( $post_id > 0 ) |
|
| 775 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 776 | + |
|
| 777 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 778 | + |
|
| 779 | + $total = 0; |
|
| 780 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 781 | + foreach ( (array) $count as $row ) { |
|
| 782 | + // Don't count post-trashed toward totals |
|
| 783 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 784 | + $total += $row['num_comments']; |
|
| 785 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 786 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + $stats['total_comments'] = $total; |
|
| 790 | + foreach ( $approved as $key ) { |
|
| 791 | + if ( empty($stats[$key]) ) |
|
| 792 | + $stats[$key] = 0; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + $stats = (object) $stats; |
|
| 796 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 797 | + |
|
| 798 | + return $stats; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Init images. |
|
| 803 | + * |
|
| 804 | + * @since 1.4.5 |
|
| 805 | + * @access public |
|
| 806 | + * @return void |
|
| 807 | + */ |
|
| 808 | + public function init_image_sizes() { |
|
| 809 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 810 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 811 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 812 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 813 | + |
|
| 814 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 815 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 816 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 817 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Get an image size. |
|
| 822 | + * |
|
| 823 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 824 | + * |
|
| 825 | + * @since 1.4.5 |
|
| 826 | + * @access public |
|
| 827 | + * @param mixed $image_size |
|
| 828 | + * @return string |
|
| 829 | + */ |
|
| 830 | + public function get_image_size( $image_size ) { |
|
| 831 | + |
|
| 832 | + // Only return sizes we define in settings |
|
| 833 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 834 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 835 | + |
|
| 836 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 837 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 838 | + } |
|
| 839 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 840 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 841 | + } |
|
| 842 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 843 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $size = array_filter( array( |
|
| 847 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 848 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 849 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 850 | + ) ); |
|
| 851 | + |
|
| 852 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 853 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 854 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 855 | + |
|
| 856 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + public function body_class( $classes ) { |
|
| 860 | + if( is_sensei() ) { |
|
| 861 | + $classes[] = 'sensei'; |
|
| 862 | + } |
|
| 863 | + return $classes; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 868 | + * |
|
| 869 | + * @return null |
|
| 870 | + * @since 1.7.0 |
|
| 871 | + */ |
|
| 872 | + public function jetpack_latex_support() { |
|
| 873 | + if ( function_exists( 'latex_markup') ) { |
|
| 874 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 875 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Load the module functionality. |
|
| 881 | + * |
|
| 882 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 883 | + * the retired modules extension. |
|
| 884 | + * |
|
| 885 | + * @since 1.8.0 |
|
| 886 | + */ |
|
| 887 | + public function load_modules_class(){ |
|
| 888 | + global $sensei_modules; |
|
| 889 | + |
|
| 890 | + if( !class_exists( 'Sensei_Modules' ) |
|
| 891 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 892 | + |
|
| 893 | + //Load the modules class |
|
| 894 | + require_once( 'class-sensei-modules.php'); |
|
| 895 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 896 | + |
|
| 897 | + }else{ |
|
| 898 | + // fallback for people still using the modules extension. |
|
| 899 | + global $sensei_modules; |
|
| 900 | + Sensei()->modules = $sensei_modules; |
|
| 901 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * Tell the user to that the modules extension is no longer needed. |
|
| 907 | + * |
|
| 908 | + * @since 1.8.0 |
|
| 909 | + */ |
|
| 910 | + public function disable_sensei_modules_extension(){ ?> |
|
| 911 | 911 | <div class="notice updated fade"> |
| 912 | 912 | <p> |
| 913 | 913 | <?php |
| 914 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 915 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 916 | - ?> |
|
| 914 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 915 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 916 | + ?> |
|
| 917 | 917 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 918 | 918 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
| 919 | 919 | </p> |
@@ -921,200 +921,200 @@ discard block |
||
| 921 | 921 | |
| 922 | 922 | <?php }// end function |
| 923 | 923 | |
| 924 | - /** |
|
| 925 | - * Sensei wide rewrite flush call. |
|
| 926 | - * |
|
| 927 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 928 | - * |
|
| 929 | - * After the option is one the Rules will be flushed. |
|
| 930 | - * |
|
| 931 | - * @since 1.9.0 |
|
| 932 | - */ |
|
| 933 | - public function flush_rewrite_rules(){ |
|
| 934 | - |
|
| 935 | - // ensures that the rewrite rules are flushed on the second |
|
| 936 | - // attempt. This ensure that the settings for any other process |
|
| 937 | - // have been completed and saved to the database before we refresh the |
|
| 938 | - // rewrite rules. |
|
| 939 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 940 | - if( '1' == $option ) { |
|
| 941 | - |
|
| 942 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
| 943 | - |
|
| 944 | - }elseif( '2' == $option ) { |
|
| 945 | - |
|
| 946 | - flush_rewrite_rules(); |
|
| 947 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
| 948 | - |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - } // end flush_rewrite_rules |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Calling this function will tell Sensei to flush rewrite |
|
| 955 | - * rules on the next load. |
|
| 956 | - * |
|
| 957 | - * @since 1.9.0 |
|
| 958 | - */ |
|
| 959 | - public function initiate_rewrite_rules_flush(){ |
|
| 960 | - |
|
| 961 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
| 962 | - |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * sensei_woocommerce_email_course_details adds detail to email |
|
| 967 | - * |
|
| 968 | - * @deprecated since 1.9.0 use Sensei_WC::email_course_details |
|
| 969 | - * |
|
| 970 | - * @since 1.4.5 |
|
| 971 | - * @access public |
|
| 972 | - * @param WC_Order $order |
|
| 973 | - * |
|
| 974 | - * @return void |
|
| 975 | - */ |
|
| 976 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 977 | - |
|
| 978 | - Sensei_WC::email_course_details( $order ); |
|
| 979 | - |
|
| 980 | - } // end func email course details |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
| 984 | - * @param $user_id |
|
| 985 | - * @param $subscription_key |
|
| 986 | - */ |
|
| 987 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){ |
|
| 988 | - |
|
| 989 | - Sensei_WC::reactivate_subscription( $user_id, $subscription_key ); |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
| 994 | - * @param $user_id |
|
| 995 | - * @param $subscription_key |
|
| 996 | - */ |
|
| 997 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){ |
|
| 998 | - |
|
| 999 | - Sensei_WC::end_subscription( $user_id, $subscription_key ); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * sensei_woocommerce_complete_order description |
|
| 1004 | - * |
|
| 1005 | - * @deprecated since 1.9.0 use Sensei_WC::complete_order( $order_id ); |
|
| 1006 | - * @since 1.0.3 |
|
| 1007 | - * @access public |
|
| 1008 | - * @param int $order_id WC order ID |
|
| 1009 | - * |
|
| 1010 | - * @return void |
|
| 1011 | - */ |
|
| 1012 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 1013 | - |
|
| 1014 | - Sensei_WC::complete_order( $order_id ); |
|
| 1015 | - |
|
| 1016 | - } // End sensei_woocommerce_complete_order() |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * Runs when an order is cancelled. |
|
| 1020 | - * |
|
| 1021 | - * @deprecated since 1.9.0 |
|
| 1022 | - * |
|
| 1023 | - * @since 1.2.0 |
|
| 1024 | - * @param integer $order_id order ID |
|
| 1025 | - * @return void |
|
| 1026 | - */ |
|
| 1027 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 1028 | - |
|
| 1029 | - Sensei_WC::cancel_order( $order_id ); |
|
| 1030 | - |
|
| 1031 | - } // End sensei_woocommerce_cancel_order() |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1035 | - * @deprecated since 1.9.0 |
|
| 1036 | - * @since 1.2.0 |
|
| 1037 | - * @access public |
|
| 1038 | - * @param integer $order_id order ID |
|
| 1039 | - * @return void |
|
| 1040 | - */ |
|
| 1041 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1042 | - |
|
| 1043 | - Sensei_WC::activate_subscription( $order_id ); |
|
| 1044 | - |
|
| 1045 | - } // End sensei_activate_subscription() |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 1049 | - * @deprecated since 1.9.0 |
|
| 1050 | - * @since 1.0.0 |
|
| 1051 | - * @param int $course_id (default: 0) |
|
| 1052 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 1053 | - * @return bool|int |
|
| 1054 | - */ |
|
| 1055 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 1056 | - |
|
| 1057 | - return Sensei_WC::course_update( $course_id, $order_user ); |
|
| 1058 | - |
|
| 1059 | - } // End woocommerce_course_update() |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * Returns the WooCommerce Product Object |
|
| 1063 | - * |
|
| 1064 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 1065 | - * |
|
| 1066 | - * @deprecated since 1.9.0 |
|
| 1067 | - * @since 1.1.1 |
|
| 1068 | - * |
|
| 1069 | - * @param integer $wc_product_id Product ID or Variation ID |
|
| 1070 | - * @param string $product_type '' or 'variation' |
|
| 1071 | - * |
|
| 1072 | - * @return WC_Product $wc_product_object |
|
| 1073 | - */ |
|
| 1074 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1075 | - |
|
| 1076 | - return Sensei_WC::get_product_object( $wc_product_id, $product_type ); |
|
| 1077 | - |
|
| 1078 | - } // End sensei_get_woocommerce_product_object() |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * Setup required WooCommerce settings. |
|
| 1082 | - * @access public |
|
| 1083 | - * @since 1.1.0 |
|
| 1084 | - * @return void |
|
| 1085 | - */ |
|
| 1086 | - public function set_woocommerce_functionality() { |
|
| 1087 | - |
|
| 1088 | - _deprecated_function('Sensei()->set_woocommerce_functionality', 'Sensei 1.9.0'); |
|
| 1089 | - |
|
| 1090 | - } // End set_woocommerce_functionality() |
|
| 1091 | - |
|
| 1092 | - /** |
|
| 1093 | - * Disable guest checkout if a course product is in the cart |
|
| 1094 | - * @deprecated since 1.9.0 |
|
| 1095 | - * @param boolean $guest_checkout Current guest checkout setting |
|
| 1096 | - * @return boolean Modified guest checkout setting |
|
| 1097 | - */ |
|
| 1098 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 1099 | - |
|
| 1100 | - return Sensei_WC::disable_guest_checkout( $guest_checkout ); |
|
| 1101 | - |
|
| 1102 | - }// end disable_guest_checkout |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Change order status with virtual products to completed |
|
| 1106 | - * |
|
| 1107 | - * @deprecated since 1.9.0 use Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ) |
|
| 1108 | - * |
|
| 1109 | - * @since 1.1.0 |
|
| 1110 | - * @param string $order_status |
|
| 1111 | - * @param int $order_id |
|
| 1112 | - * @return string |
|
| 1113 | - **/ |
|
| 1114 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 1115 | - |
|
| 1116 | - return Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ); |
|
| 1117 | - } |
|
| 924 | + /** |
|
| 925 | + * Sensei wide rewrite flush call. |
|
| 926 | + * |
|
| 927 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 928 | + * |
|
| 929 | + * After the option is one the Rules will be flushed. |
|
| 930 | + * |
|
| 931 | + * @since 1.9.0 |
|
| 932 | + */ |
|
| 933 | + public function flush_rewrite_rules(){ |
|
| 934 | + |
|
| 935 | + // ensures that the rewrite rules are flushed on the second |
|
| 936 | + // attempt. This ensure that the settings for any other process |
|
| 937 | + // have been completed and saved to the database before we refresh the |
|
| 938 | + // rewrite rules. |
|
| 939 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 940 | + if( '1' == $option ) { |
|
| 941 | + |
|
| 942 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
| 943 | + |
|
| 944 | + }elseif( '2' == $option ) { |
|
| 945 | + |
|
| 946 | + flush_rewrite_rules(); |
|
| 947 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
| 948 | + |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + } // end flush_rewrite_rules |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Calling this function will tell Sensei to flush rewrite |
|
| 955 | + * rules on the next load. |
|
| 956 | + * |
|
| 957 | + * @since 1.9.0 |
|
| 958 | + */ |
|
| 959 | + public function initiate_rewrite_rules_flush(){ |
|
| 960 | + |
|
| 961 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
| 962 | + |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * sensei_woocommerce_email_course_details adds detail to email |
|
| 967 | + * |
|
| 968 | + * @deprecated since 1.9.0 use Sensei_WC::email_course_details |
|
| 969 | + * |
|
| 970 | + * @since 1.4.5 |
|
| 971 | + * @access public |
|
| 972 | + * @param WC_Order $order |
|
| 973 | + * |
|
| 974 | + * @return void |
|
| 975 | + */ |
|
| 976 | + public function sensei_woocommerce_email_course_details( $order ) { |
|
| 977 | + |
|
| 978 | + Sensei_WC::email_course_details( $order ); |
|
| 979 | + |
|
| 980 | + } // end func email course details |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
| 984 | + * @param $user_id |
|
| 985 | + * @param $subscription_key |
|
| 986 | + */ |
|
| 987 | + public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){ |
|
| 988 | + |
|
| 989 | + Sensei_WC::reactivate_subscription( $user_id, $subscription_key ); |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
| 994 | + * @param $user_id |
|
| 995 | + * @param $subscription_key |
|
| 996 | + */ |
|
| 997 | + public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){ |
|
| 998 | + |
|
| 999 | + Sensei_WC::end_subscription( $user_id, $subscription_key ); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * sensei_woocommerce_complete_order description |
|
| 1004 | + * |
|
| 1005 | + * @deprecated since 1.9.0 use Sensei_WC::complete_order( $order_id ); |
|
| 1006 | + * @since 1.0.3 |
|
| 1007 | + * @access public |
|
| 1008 | + * @param int $order_id WC order ID |
|
| 1009 | + * |
|
| 1010 | + * @return void |
|
| 1011 | + */ |
|
| 1012 | + public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 1013 | + |
|
| 1014 | + Sensei_WC::complete_order( $order_id ); |
|
| 1015 | + |
|
| 1016 | + } // End sensei_woocommerce_complete_order() |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * Runs when an order is cancelled. |
|
| 1020 | + * |
|
| 1021 | + * @deprecated since 1.9.0 |
|
| 1022 | + * |
|
| 1023 | + * @since 1.2.0 |
|
| 1024 | + * @param integer $order_id order ID |
|
| 1025 | + * @return void |
|
| 1026 | + */ |
|
| 1027 | + public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 1028 | + |
|
| 1029 | + Sensei_WC::cancel_order( $order_id ); |
|
| 1030 | + |
|
| 1031 | + } // End sensei_woocommerce_cancel_order() |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1035 | + * @deprecated since 1.9.0 |
|
| 1036 | + * @since 1.2.0 |
|
| 1037 | + * @access public |
|
| 1038 | + * @param integer $order_id order ID |
|
| 1039 | + * @return void |
|
| 1040 | + */ |
|
| 1041 | + public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1042 | + |
|
| 1043 | + Sensei_WC::activate_subscription( $order_id ); |
|
| 1044 | + |
|
| 1045 | + } // End sensei_activate_subscription() |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 1049 | + * @deprecated since 1.9.0 |
|
| 1050 | + * @since 1.0.0 |
|
| 1051 | + * @param int $course_id (default: 0) |
|
| 1052 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 1053 | + * @return bool|int |
|
| 1054 | + */ |
|
| 1055 | + public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 1056 | + |
|
| 1057 | + return Sensei_WC::course_update( $course_id, $order_user ); |
|
| 1058 | + |
|
| 1059 | + } // End woocommerce_course_update() |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * Returns the WooCommerce Product Object |
|
| 1063 | + * |
|
| 1064 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 1065 | + * |
|
| 1066 | + * @deprecated since 1.9.0 |
|
| 1067 | + * @since 1.1.1 |
|
| 1068 | + * |
|
| 1069 | + * @param integer $wc_product_id Product ID or Variation ID |
|
| 1070 | + * @param string $product_type '' or 'variation' |
|
| 1071 | + * |
|
| 1072 | + * @return WC_Product $wc_product_object |
|
| 1073 | + */ |
|
| 1074 | + public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1075 | + |
|
| 1076 | + return Sensei_WC::get_product_object( $wc_product_id, $product_type ); |
|
| 1077 | + |
|
| 1078 | + } // End sensei_get_woocommerce_product_object() |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * Setup required WooCommerce settings. |
|
| 1082 | + * @access public |
|
| 1083 | + * @since 1.1.0 |
|
| 1084 | + * @return void |
|
| 1085 | + */ |
|
| 1086 | + public function set_woocommerce_functionality() { |
|
| 1087 | + |
|
| 1088 | + _deprecated_function('Sensei()->set_woocommerce_functionality', 'Sensei 1.9.0'); |
|
| 1089 | + |
|
| 1090 | + } // End set_woocommerce_functionality() |
|
| 1091 | + |
|
| 1092 | + /** |
|
| 1093 | + * Disable guest checkout if a course product is in the cart |
|
| 1094 | + * @deprecated since 1.9.0 |
|
| 1095 | + * @param boolean $guest_checkout Current guest checkout setting |
|
| 1096 | + * @return boolean Modified guest checkout setting |
|
| 1097 | + */ |
|
| 1098 | + public function disable_guest_checkout( $guest_checkout ) { |
|
| 1099 | + |
|
| 1100 | + return Sensei_WC::disable_guest_checkout( $guest_checkout ); |
|
| 1101 | + |
|
| 1102 | + }// end disable_guest_checkout |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Change order status with virtual products to completed |
|
| 1106 | + * |
|
| 1107 | + * @deprecated since 1.9.0 use Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ) |
|
| 1108 | + * |
|
| 1109 | + * @since 1.1.0 |
|
| 1110 | + * @param string $order_status |
|
| 1111 | + * @param int $order_id |
|
| 1112 | + * @return string |
|
| 1113 | + **/ |
|
| 1114 | + public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 1115 | + |
|
| 1116 | + return Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ); |
|
| 1117 | + } |
|
| 1118 | 1118 | |
| 1119 | 1119 | } // End Class |
| 1120 | 1120 | |
@@ -16,148 +16,148 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 21 | - */ |
|
| 22 | - protected $query; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var string number of items to show on the current page |
|
| 26 | - * Default: all. |
|
| 27 | - */ |
|
| 28 | - protected $number; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string ordery by course field |
|
| 32 | - * Default: date |
|
| 33 | - */ |
|
| 34 | - protected $orderby; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string ASC or DESC |
|
| 38 | - * Default: 'DESC' |
|
| 39 | - */ |
|
| 40 | - protected $order; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Setup the shortcode object |
|
| 44 | - * |
|
| 45 | - * @since 1.9.0 |
|
| 46 | - * @param array $attributes |
|
| 47 | - * @param string $content |
|
| 48 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 49 | - */ |
|
| 50 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 51 | - |
|
| 52 | - // set up all argument need for constructing the course query |
|
| 53 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 54 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 55 | - |
|
| 56 | - // set the default for menu_order to be ASC |
|
| 57 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 58 | - |
|
| 59 | - $this->order = 'ASC'; |
|
| 19 | + /** |
|
| 20 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 21 | + */ |
|
| 22 | + protected $query; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var string number of items to show on the current page |
|
| 26 | + * Default: all. |
|
| 27 | + */ |
|
| 28 | + protected $number; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string ordery by course field |
|
| 32 | + * Default: date |
|
| 33 | + */ |
|
| 34 | + protected $orderby; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string ASC or DESC |
|
| 38 | + * Default: 'DESC' |
|
| 39 | + */ |
|
| 40 | + protected $order; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Setup the shortcode object |
|
| 44 | + * |
|
| 45 | + * @since 1.9.0 |
|
| 46 | + * @param array $attributes |
|
| 47 | + * @param string $content |
|
| 48 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 49 | + */ |
|
| 50 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 51 | + |
|
| 52 | + // set up all argument need for constructing the course query |
|
| 53 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 54 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 55 | + |
|
| 56 | + // set the default for menu_order to be ASC |
|
| 57 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 58 | + |
|
| 59 | + $this->order = 'ASC'; |
|
| 60 | 60 | |
| 61 | - }else{ |
|
| 61 | + }else{ |
|
| 62 | 62 | |
| 63 | - // for everything else use the value passed or the default DESC |
|
| 64 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 63 | + // for everything else use the value passed or the default DESC |
|
| 64 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 65 | 65 | |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // setup the course query that will be used when rendering |
|
| 69 | - $this->setup_course_query(); |
|
| 70 | - } |
|
| 68 | + // setup the course query that will be used when rendering |
|
| 69 | + $this->setup_course_query(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Sets up the object course query |
|
| 74 | - * that will be used int he render method. |
|
| 75 | - * |
|
| 76 | - * @since 1.9.0 |
|
| 77 | - */ |
|
| 78 | - protected function setup_course_query(){ |
|
| 72 | + /** |
|
| 73 | + * Sets up the object course query |
|
| 74 | + * that will be used int he render method. |
|
| 75 | + * |
|
| 76 | + * @since 1.9.0 |
|
| 77 | + */ |
|
| 78 | + protected function setup_course_query(){ |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - // course query parameters to be used for all courses |
|
| 82 | - $query_args = array( |
|
| 83 | - 'post_type' => 'course', |
|
| 84 | - 'post_status' => 'publish', |
|
| 85 | - // the number specified by the user will be used later in this function |
|
| 86 | - 'posts_per_page' => 1000, |
|
| 87 | - 'orderby' => $this->orderby, |
|
| 88 | - 'order' => $this->order |
|
| 89 | - ); |
|
| 81 | + // course query parameters to be used for all courses |
|
| 82 | + $query_args = array( |
|
| 83 | + 'post_type' => 'course', |
|
| 84 | + 'post_status' => 'publish', |
|
| 85 | + // the number specified by the user will be used later in this function |
|
| 86 | + 'posts_per_page' => 1000, |
|
| 87 | + 'orderby' => $this->orderby, |
|
| 88 | + 'order' => $this->order |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - // get all the courses that has a product attached |
|
| 92 | - $all_courses_query = new WP_Query( $query_args ); |
|
| 91 | + // get all the courses that has a product attached |
|
| 92 | + $all_courses_query = new WP_Query( $query_args ); |
|
| 93 | 93 | |
| 94 | - $paid_courses_not_taken = array(); |
|
| 95 | - // look through all course and find the purchasable ones that user has not purchased |
|
| 96 | - foreach( $all_courses_query->posts as $course ){ |
|
| 94 | + $paid_courses_not_taken = array(); |
|
| 95 | + // look through all course and find the purchasable ones that user has not purchased |
|
| 96 | + foreach( $all_courses_query->posts as $course ){ |
|
| 97 | 97 | |
| 98 | - // only keep the courses with a product including only courses that the user not taking |
|
| 99 | - $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 100 | - if( is_numeric( $course_product_id ) |
|
| 101 | - && |
|
| 102 | - ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 103 | - ){ |
|
| 98 | + // only keep the courses with a product including only courses that the user not taking |
|
| 99 | + $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
| 100 | + if( is_numeric( $course_product_id ) |
|
| 101 | + && |
|
| 102 | + ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
| 103 | + ){ |
|
| 104 | 104 | |
| 105 | - $paid_courses_not_taken[] = $course->ID; |
|
| 105 | + $paid_courses_not_taken[] = $course->ID; |
|
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - } // end foreach |
|
| 109 | + } // end foreach |
|
| 110 | 110 | |
| 111 | - // setup the course query again and only use the course the user has not purchased. |
|
| 112 | - // this query will be loaded into the global WP_Query in the render function. |
|
| 113 | - $query_args[ 'post__in' ] = $paid_courses_not_taken; |
|
| 114 | - $query_args[ 'posts_per_page' ] = $this->number; |
|
| 111 | + // setup the course query again and only use the course the user has not purchased. |
|
| 112 | + // this query will be loaded into the global WP_Query in the render function. |
|
| 113 | + $query_args[ 'post__in' ] = $paid_courses_not_taken; |
|
| 114 | + $query_args[ 'posts_per_page' ] = $this->number; |
|
| 115 | 115 | |
| 116 | - $this->query = new WP_Query( $query_args ); |
|
| 116 | + $this->query = new WP_Query( $query_args ); |
|
| 117 | 117 | |
| 118 | - }// end setup _course_query |
|
| 118 | + }// end setup _course_query |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Rendering the shortcode this class is responsible for. |
|
| 122 | - * |
|
| 123 | - * @return string $content |
|
| 124 | - */ |
|
| 125 | - public function render(){ |
|
| 120 | + /** |
|
| 121 | + * Rendering the shortcode this class is responsible for. |
|
| 122 | + * |
|
| 123 | + * @return string $content |
|
| 124 | + */ |
|
| 125 | + public function render(){ |
|
| 126 | 126 | |
| 127 | - global $wp_query; |
|
| 127 | + global $wp_query; |
|
| 128 | 128 | |
| 129 | - if ( ! is_user_logged_in() ) { |
|
| 129 | + if ( ! is_user_logged_in() ) { |
|
| 130 | 130 | |
| 131 | - $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >'; |
|
| 132 | - $anchor_after = '</a>'; |
|
| 133 | - $notice = sprintf( |
|
| 134 | - __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'), |
|
| 135 | - $anchor_before, |
|
| 136 | - $anchor_after |
|
| 137 | - ); |
|
| 131 | + $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >'; |
|
| 132 | + $anchor_after = '</a>'; |
|
| 133 | + $notice = sprintf( |
|
| 134 | + __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'), |
|
| 135 | + $anchor_before, |
|
| 136 | + $anchor_after |
|
| 137 | + ); |
|
| 138 | 138 | |
| 139 | - Sensei()->notices->add_notice( $notice, 'info' ); |
|
| 140 | - Sensei()->notices->maybe_print_notices(); |
|
| 139 | + Sensei()->notices->add_notice( $notice, 'info' ); |
|
| 140 | + Sensei()->notices->maybe_print_notices(); |
|
| 141 | 141 | |
| 142 | - return ''; |
|
| 142 | + return ''; |
|
| 143 | 143 | |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - // keep a reference to old query |
|
| 147 | - $current_global_query = $wp_query; |
|
| 148 | - // assign the query setup in $this-> setup_course_query |
|
| 149 | - $wp_query = $this->query; |
|
| 146 | + // keep a reference to old query |
|
| 147 | + $current_global_query = $wp_query; |
|
| 148 | + // assign the query setup in $this-> setup_course_query |
|
| 149 | + $wp_query = $this->query; |
|
| 150 | 150 | |
| 151 | - ob_start(); |
|
| 152 | - Sensei()->notices->maybe_print_notices(); |
|
| 153 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 154 | - $shortcode_output = ob_get_clean(); |
|
| 151 | + ob_start(); |
|
| 152 | + Sensei()->notices->maybe_print_notices(); |
|
| 153 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 154 | + $shortcode_output = ob_get_clean(); |
|
| 155 | 155 | |
| 156 | - //restore old query |
|
| 157 | - $wp_query = $current_global_query; |
|
| 156 | + //restore old query |
|
| 157 | + $wp_query = $current_global_query; |
|
| 158 | 158 | |
| 159 | - return $shortcode_output; |
|
| 159 | + return $shortcode_output; |
|
| 160 | 160 | |
| 161 | - }// end render |
|
| 161 | + }// end render |
|
| 162 | 162 | |
| 163 | 163 | } |
| 164 | 164 | \ No newline at end of file |
@@ -17,91 +17,91 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Sensei_Shortcode_User_Messages implements Sensei_Shortcode_Interface { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var WP_Query |
|
| 22 | - * messages for the current user |
|
| 23 | - */ |
|
| 24 | - protected $messages_query; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Setup the shortcode object |
|
| 28 | - * |
|
| 29 | - * @since 1.9.0 |
|
| 30 | - * @param array $attributes |
|
| 31 | - * @param string $content |
|
| 32 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 33 | - */ |
|
| 34 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 35 | - |
|
| 36 | - $this->setup_messages_query(); |
|
| 37 | - |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * create the messages query . |
|
| 42 | - * |
|
| 43 | - * @return mixed |
|
| 44 | - */ |
|
| 45 | - public function setup_messages_query(){ |
|
| 46 | - |
|
| 47 | - $user = wp_get_current_user(); |
|
| 48 | - |
|
| 49 | - $args = array( |
|
| 50 | - 'post_type' => 'sensei_message', |
|
| 51 | - 'posts_per_page' => 500, |
|
| 52 | - 'orderby' => 'date', |
|
| 53 | - 'order' => 'DESC', |
|
| 54 | - 'post_status' => 'publish', |
|
| 55 | - 'meta_query' => array( |
|
| 56 | - array( |
|
| 57 | - 'key' => '_sender', |
|
| 58 | - 'value' => $user->user_login, |
|
| 59 | - 'compare' => '=', |
|
| 60 | - ), |
|
| 61 | - ), |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - $this->messages_query = new WP_Query( $args ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Rendering the shortcode this class is responsible for. |
|
| 69 | - * |
|
| 70 | - * @return string $content |
|
| 71 | - */ |
|
| 72 | - public function render(){ |
|
| 73 | - |
|
| 74 | - if( !is_user_logged_in() ){ |
|
| 75 | - |
|
| 76 | - Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert' ); |
|
| 77 | - |
|
| 78 | - } elseif( 0 == $this->messages_query->post_count ){ |
|
| 79 | - |
|
| 80 | - Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert' ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 84 | - || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 85 | - |
|
| 86 | - // don't show anything if messages are disable |
|
| 87 | - if( $messages_disabled_in_settings ){ |
|
| 88 | - return ''; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //set the wp_query to the current messages query |
|
| 92 | - global $wp_query; |
|
| 93 | - $wp_query = $this->messages_query; |
|
| 94 | - |
|
| 95 | - ob_start(); |
|
| 96 | - Sensei()->notices->maybe_print_notices(); |
|
| 97 | - Sensei_Templates::get_part('loop', 'message'); |
|
| 98 | - $messages_html = ob_get_clean(); |
|
| 99 | - |
|
| 100 | - // set back the global query |
|
| 101 | - wp_reset_query(); |
|
| 102 | - |
|
| 103 | - return $messages_html; |
|
| 104 | - |
|
| 105 | - }// end render |
|
| 20 | + /** |
|
| 21 | + * @var WP_Query |
|
| 22 | + * messages for the current user |
|
| 23 | + */ |
|
| 24 | + protected $messages_query; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Setup the shortcode object |
|
| 28 | + * |
|
| 29 | + * @since 1.9.0 |
|
| 30 | + * @param array $attributes |
|
| 31 | + * @param string $content |
|
| 32 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 33 | + */ |
|
| 34 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 35 | + |
|
| 36 | + $this->setup_messages_query(); |
|
| 37 | + |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * create the messages query . |
|
| 42 | + * |
|
| 43 | + * @return mixed |
|
| 44 | + */ |
|
| 45 | + public function setup_messages_query(){ |
|
| 46 | + |
|
| 47 | + $user = wp_get_current_user(); |
|
| 48 | + |
|
| 49 | + $args = array( |
|
| 50 | + 'post_type' => 'sensei_message', |
|
| 51 | + 'posts_per_page' => 500, |
|
| 52 | + 'orderby' => 'date', |
|
| 53 | + 'order' => 'DESC', |
|
| 54 | + 'post_status' => 'publish', |
|
| 55 | + 'meta_query' => array( |
|
| 56 | + array( |
|
| 57 | + 'key' => '_sender', |
|
| 58 | + 'value' => $user->user_login, |
|
| 59 | + 'compare' => '=', |
|
| 60 | + ), |
|
| 61 | + ), |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + $this->messages_query = new WP_Query( $args ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Rendering the shortcode this class is responsible for. |
|
| 69 | + * |
|
| 70 | + * @return string $content |
|
| 71 | + */ |
|
| 72 | + public function render(){ |
|
| 73 | + |
|
| 74 | + if( !is_user_logged_in() ){ |
|
| 75 | + |
|
| 76 | + Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert' ); |
|
| 77 | + |
|
| 78 | + } elseif( 0 == $this->messages_query->post_count ){ |
|
| 79 | + |
|
| 80 | + Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert' ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 84 | + || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 85 | + |
|
| 86 | + // don't show anything if messages are disable |
|
| 87 | + if( $messages_disabled_in_settings ){ |
|
| 88 | + return ''; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //set the wp_query to the current messages query |
|
| 92 | + global $wp_query; |
|
| 93 | + $wp_query = $this->messages_query; |
|
| 94 | + |
|
| 95 | + ob_start(); |
|
| 96 | + Sensei()->notices->maybe_print_notices(); |
|
| 97 | + Sensei_Templates::get_part('loop', 'message'); |
|
| 98 | + $messages_html = ob_get_clean(); |
|
| 99 | + |
|
| 100 | + // set back the global query |
|
| 101 | + wp_reset_query(); |
|
| 102 | + |
|
| 103 | + return $messages_html; |
|
| 104 | + |
|
| 105 | + }// end render |
|
| 106 | 106 | |
| 107 | 107 | }// end class |
| 108 | 108 | \ No newline at end of file |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The Template for displaying all Quiz Questions. |
|
| 4 | - * |
|
| 5 | - * Override this template by copying it to yourtheme/sensei/single-quiz.php |
|
| 6 | - * |
|
| 7 | - * @author Automattic |
|
| 8 | - * @package Sensei |
|
| 9 | - * @category Templates |
|
| 10 | - * @version 1.9.0 |
|
| 11 | - */ |
|
| 3 | + * The Template for displaying all Quiz Questions. |
|
| 4 | + * |
|
| 5 | + * Override this template by copying it to yourtheme/sensei/single-quiz.php |
|
| 6 | + * |
|
| 7 | + * @author Automattic |
|
| 8 | + * @package Sensei |
|
| 9 | + * @category Templates |
|
| 10 | + * @version 1.9.0 |
|
| 11 | + */ |
|
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <?php get_sensei_header(); ?> |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | <?php |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Hook inside the single quiz post above the content |
|
| 22 | - * |
|
| 23 | - * @since 1.9.0 |
|
| 24 | - * |
|
| 25 | - * @hooked Sensei_Quiz::the_title - 20 |
|
| 26 | - * @hooked Sensei_Quiz::the_user_status_message - 40 |
|
| 27 | - * @param integer $quiz_id |
|
| 28 | - * |
|
| 29 | - */ |
|
| 30 | - do_action( 'sensei_single_quiz_content_inside_before', get_the_ID() ); |
|
| 20 | + /** |
|
| 21 | + * Hook inside the single quiz post above the content |
|
| 22 | + * |
|
| 23 | + * @since 1.9.0 |
|
| 24 | + * |
|
| 25 | + * @hooked Sensei_Quiz::the_title - 20 |
|
| 26 | + * @hooked Sensei_Quiz::the_user_status_message - 40 |
|
| 27 | + * @param integer $quiz_id |
|
| 28 | + * |
|
| 29 | + */ |
|
| 30 | + do_action( 'sensei_single_quiz_content_inside_before', get_the_ID() ); |
|
| 31 | 31 | |
| 32 | - ?> |
|
| 32 | + ?> |
|
| 33 | 33 | |
| 34 | 34 | <?php if ( sensei_can_user_view_lesson() ) : ?> |
| 35 | 35 | |
@@ -41,16 +41,16 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | <?php |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Action inside before the question content on single-quiz page |
|
| 46 | - * |
|
| 47 | - * @hooked WooThemes_Sensei_Quiz::the_user_status_message - 10 |
|
| 48 | - * |
|
| 49 | - * @param string $the_quiz_id |
|
| 50 | - */ |
|
| 51 | - do_action( 'sensei_single_quiz_questions_before', get_the_id() ); |
|
| 44 | + /** |
|
| 45 | + * Action inside before the question content on single-quiz page |
|
| 46 | + * |
|
| 47 | + * @hooked WooThemes_Sensei_Quiz::the_user_status_message - 10 |
|
| 48 | + * |
|
| 49 | + * @param string $the_quiz_id |
|
| 50 | + */ |
|
| 51 | + do_action( 'sensei_single_quiz_questions_before', get_the_id() ); |
|
| 52 | 52 | |
| 53 | - ?> |
|
| 53 | + ?> |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | |
@@ -62,35 +62,35 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | <?php |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Action inside before the question content on single-quiz page |
|
| 67 | - * |
|
| 68 | - * @hooked WooThemes_Sensei_Question::the_question_title - 10 |
|
| 69 | - * @hooked WooThemes_Sensei_Question::the_question_description - 20 |
|
| 70 | - * @hooked WooThemes_Sensei_Question::the_question_media - 30 |
|
| 71 | - * @hooked WooThemes_Sensei_Question::the_question_hidden_field - 40 |
|
| 72 | - * |
|
| 73 | - * @since 1.9.0 |
|
| 74 | - * @param string $the_question_id |
|
| 75 | - */ |
|
| 76 | - do_action( 'sensei_quiz_question_inside_before', sensei_get_the_question_id() ); |
|
| 77 | - |
|
| 78 | - ?> |
|
| 65 | + /** |
|
| 66 | + * Action inside before the question content on single-quiz page |
|
| 67 | + * |
|
| 68 | + * @hooked WooThemes_Sensei_Question::the_question_title - 10 |
|
| 69 | + * @hooked WooThemes_Sensei_Question::the_question_description - 20 |
|
| 70 | + * @hooked WooThemes_Sensei_Question::the_question_media - 30 |
|
| 71 | + * @hooked WooThemes_Sensei_Question::the_question_hidden_field - 40 |
|
| 72 | + * |
|
| 73 | + * @since 1.9.0 |
|
| 74 | + * @param string $the_question_id |
|
| 75 | + */ |
|
| 76 | + do_action( 'sensei_quiz_question_inside_before', sensei_get_the_question_id() ); |
|
| 77 | + |
|
| 78 | + ?> |
|
| 79 | 79 | |
| 80 | 80 | <?php sensei_the_question_content(); ?> |
| 81 | 81 | |
| 82 | 82 | <?php |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Action inside before the question content on single-quiz page |
|
| 86 | - * |
|
| 87 | - * @hooked WooThemes_Sensei_Question::answer_feedback_notes |
|
| 88 | - * |
|
| 89 | - * @param string $the_question_id |
|
| 90 | - */ |
|
| 91 | - do_action( 'sensei_quiz_question_inside_after', sensei_get_the_question_id() ); |
|
| 84 | + /** |
|
| 85 | + * Action inside before the question content on single-quiz page |
|
| 86 | + * |
|
| 87 | + * @hooked WooThemes_Sensei_Question::answer_feedback_notes |
|
| 88 | + * |
|
| 89 | + * @param string $the_question_id |
|
| 90 | + */ |
|
| 91 | + do_action( 'sensei_quiz_question_inside_after', sensei_get_the_question_id() ); |
|
| 92 | 92 | |
| 93 | - ?> |
|
| 93 | + ?> |
|
| 94 | 94 | |
| 95 | 95 | </li> |
| 96 | 96 | |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | <?php |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Action inside before the question content on single-quiz page |
|
| 105 | - * |
|
| 106 | - * @param string $the_quiz_id |
|
| 107 | - */ |
|
| 108 | - do_action( 'sensei_single_quiz_questions_after', get_the_id() ); |
|
| 103 | + /** |
|
| 104 | + * Action inside before the question content on single-quiz page |
|
| 105 | + * |
|
| 106 | + * @param string $the_quiz_id |
|
| 107 | + */ |
|
| 108 | + do_action( 'sensei_single_quiz_questions_after', get_the_id() ); |
|
| 109 | 109 | |
| 110 | - ?> |
|
| 110 | + ?> |
|
| 111 | 111 | |
| 112 | 112 | </form> |
| 113 | 113 | <?php else: ?> |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | <?php |
| 121 | - $quiz_lesson = Sensei()->quiz->data->quiz_lesson; |
|
| 122 | - do_action( 'sensei_quiz_back_link', $quiz_lesson ); |
|
| 123 | - ?> |
|
| 121 | + $quiz_lesson = Sensei()->quiz->data->quiz_lesson; |
|
| 122 | + do_action( 'sensei_quiz_back_link', $quiz_lesson ); |
|
| 123 | + ?> |
|
| 124 | 124 | |
| 125 | 125 | </section> |
| 126 | 126 | |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | <?php |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Hook inside the single quiz post above the content |
|
| 133 | - * |
|
| 134 | - * @since 1.9.0 |
|
| 135 | - * |
|
| 136 | - * @param integer $quiz_id |
|
| 137 | - * |
|
| 138 | - */ |
|
| 139 | - do_action( 'sensei_single_quiz_content_inside_after', get_the_ID() ); |
|
| 140 | - |
|
| 141 | - ?> |
|
| 131 | + /** |
|
| 132 | + * Hook inside the single quiz post above the content |
|
| 133 | + * |
|
| 134 | + * @since 1.9.0 |
|
| 135 | + * |
|
| 136 | + * @param integer $quiz_id |
|
| 137 | + * |
|
| 138 | + */ |
|
| 139 | + do_action( 'sensei_single_quiz_content_inside_after', get_the_ID() ); |
|
| 140 | + |
|
| 141 | + ?> |
|
| 142 | 142 | |
| 143 | 143 | </article><!-- .quiz --> |
| 144 | 144 | |
@@ -24,69 +24,69 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct ( $file = __FILE__ ) { |
| 26 | 26 | $this->file = $file; |
| 27 | - $this->token = 'quiz'; |
|
| 27 | + $this->token = 'quiz'; |
|
| 28 | 28 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
| 29 | 29 | add_action( 'save_post', array( $this, 'update_author' )); |
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click |
| 32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
| 33 | 33 | |
| 34 | - // fire the complete quiz button submit for grading action |
|
| 35 | - add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 34 | + // fire the complete quiz button submit for grading action |
|
| 35 | + add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder |
| 38 | 38 | add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_save_quiz_answers_listener' ) ); |
| 39 | 39 | |
| 40 | - // fire the load global data function |
|
| 41 | - add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 40 | + // fire the load global data function |
|
| 41 | + add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - } // End __construct() |
|
| 46 | + } // End __construct() |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Update the quiz author when the lesson post type is save |
|
| 50 | - * |
|
| 51 | - * @param int $post_id |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 49 | + * Update the quiz author when the lesson post type is save |
|
| 50 | + * |
|
| 51 | + * @param int $post_id |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | 54 | public function update_author( $post_id ){ |
| 55 | 55 | |
| 56 | 56 | // If this isn't a 'lesson' post, don't update it. |
| 57 | - // if this is a revision don't save it |
|
| 58 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 59 | - || wp_is_post_revision( $post_id ) ) { |
|
| 57 | + // if this is a revision don't save it |
|
| 58 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 59 | + || wp_is_post_revision( $post_id ) ) { |
|
| 60 | 60 | |
| 61 | - return; |
|
| 61 | + return; |
|
| 62 | 62 | |
| 63 | - } |
|
| 64 | - // get the lesson author id to be use late |
|
| 65 | - $saved_post = get_post( $post_id ); |
|
| 66 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 63 | + } |
|
| 64 | + // get the lesson author id to be use late |
|
| 65 | + $saved_post = get_post( $post_id ); |
|
| 66 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 67 | 67 | |
| 68 | - //get the lessons quiz |
|
| 68 | + //get the lessons quiz |
|
| 69 | 69 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
| 70 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 70 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 71 | 71 | |
| 72 | - if( ! $quiz_item ) { |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 72 | + if( ! $quiz_item ) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // setup the quiz items new author value |
|
| 76 | + // setup the quiz items new author value |
|
| 77 | 77 | $my_post = array( |
| 78 | - 'ID' => $quiz_item, |
|
| 79 | - 'post_author' => $new_lesson_author_id |
|
| 78 | + 'ID' => $quiz_item, |
|
| 79 | + 'post_author' => $new_lesson_author_id |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - // remove the action so that it doesn't fire again |
|
| 83 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 82 | + // remove the action so that it doesn't fire again |
|
| 83 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 84 | 84 | |
| 85 | 85 | // Update the post into the database |
| 86 | 86 | wp_update_post( $my_post ); |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return; |
|
| 89 | + return; |
|
| 90 | 90 | }// end update_author |
| 91 | 91 | |
| 92 | 92 | |
@@ -117,32 +117,32 @@ discard block |
||
| 117 | 117 | } // end lesson |
| 118 | 118 | |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * user_save_quiz_answers_listener |
|
| 122 | - * |
|
| 123 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
| 124 | - * @since 1.7.3 |
|
| 125 | - * @return bool $saved; |
|
| 126 | - */ |
|
| 127 | - public function user_save_quiz_answers_listener(){ |
|
| 120 | + /** |
|
| 121 | + * user_save_quiz_answers_listener |
|
| 122 | + * |
|
| 123 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
| 124 | + * @since 1.7.3 |
|
| 125 | + * @return bool $saved; |
|
| 126 | + */ |
|
| 127 | + public function user_save_quiz_answers_listener(){ |
|
| 128 | 128 | |
| 129 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 130 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 131 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 132 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 129 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 130 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 131 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 132 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - global $post; |
|
| 137 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 138 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 139 | - // call the save function |
|
| 140 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 136 | + global $post; |
|
| 137 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 138 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 139 | + // call the save function |
|
| 140 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 141 | 141 | |
| 142 | - // remove the hook as it should only fire once per click |
|
| 143 | - remove_action( 'sensei_single_quiz_content_inside_before', 'user_save_quiz_answers_listener' ); |
|
| 142 | + // remove the hook as it should only fire once per click |
|
| 143 | + remove_action( 'sensei_single_quiz_content_inside_before', 'user_save_quiz_answers_listener' ); |
|
| 144 | 144 | |
| 145 | - } // end user_save_quiz_answers_listener |
|
| 145 | + } // end user_save_quiz_answers_listener |
|
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Save the user answers for the given lesson's quiz |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @access public |
| 154 | 154 | * |
| 155 | 155 | * @param array $quiz_answers |
| 156 | - * @param array $files from global $_FILES |
|
| 156 | + * @param array $files from global $_FILES |
|
| 157 | 157 | * @param int $lesson_id |
| 158 | 158 | * @param int $user_id |
| 159 | 159 | * |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
| 163 | 163 | |
| 164 | - if( ! ( $user_id > 0 ) ){ |
|
| 165 | - $user_id = get_current_user_id(); |
|
| 166 | - } |
|
| 164 | + if( ! ( $user_id > 0 ) ){ |
|
| 165 | + $user_id = get_current_user_id(); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - // make sure the parameters are valid before continuing |
|
| 168 | + // make sure the parameters are valid before continuing |
|
| 169 | 169 | if( empty( $lesson_id ) || empty( $user_id ) |
| 170 | 170 | || 'lesson' != get_post_type( $lesson_id ) |
| 171 | 171 | ||!get_userdata( $user_id ) |
@@ -176,25 +176,25 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
| 179 | - // start the lesson before saving the data in case the user has not started the lesson |
|
| 180 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 179 | + // start the lesson before saving the data in case the user has not started the lesson |
|
| 180 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 181 | 181 | |
| 182 | 182 | //prepare the answers |
| 183 | 183 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
| 184 | 184 | |
| 185 | 185 | // save the user data |
| 186 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 186 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 187 | 187 | |
| 188 | 188 | // were the answers saved correctly? |
| 189 | 189 | if( intval( $answers_saved ) > 0){ |
| 190 | 190 | |
| 191 | - // save transient to make retrieval faster |
|
| 192 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 193 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 191 | + // save transient to make retrieval faster |
|
| 192 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 193 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 194 | 194 | |
| 195 | - // update the message showed to user |
|
| 196 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | - } |
|
| 195 | + // update the message showed to user |
|
| 196 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | return $answers_saved; |
| 200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | 204 | * Get the user answers for the given lesson's quiz. |
| 205 | - * |
|
| 206 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 207 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
| 205 | + * |
|
| 206 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 207 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
| 208 | 208 | * |
| 209 | 209 | * |
| 210 | 210 | * @since 1.7.4 |
@@ -224,27 +224,27 @@ discard block |
||
| 224 | 224 | return false; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - // save some time and get the transient cached data |
|
| 228 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 229 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 227 | + // save some time and get the transient cached data |
|
| 228 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 229 | + $transient_cached_answers = get_transient( $transient_key ); |
|
| 230 | 230 | |
| 231 | - // return the transient or get the values get the values from the comment meta |
|
| 232 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 231 | + // return the transient or get the values get the values from the comment meta |
|
| 232 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 233 | 233 | |
| 234 | - $encoded_user_answers = $transient_cached_answers; |
|
| 234 | + $encoded_user_answers = $transient_cached_answers; |
|
| 235 | 235 | |
| 236 | - }else{ |
|
| 236 | + }else{ |
|
| 237 | 237 | |
| 238 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 238 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 239 | 239 | |
| 240 | - } // end if transient check |
|
| 240 | + } // end if transient check |
|
| 241 | 241 | |
| 242 | 242 | if( ! is_array( $encoded_user_answers ) ){ |
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - //set the transient with the new valid data for faster retrieval in future |
|
| 247 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 246 | + //set the transient with the new valid data for faster retrieval in future |
|
| 247 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 248 | 248 | |
| 249 | 249 | // decode an unserialize all answers |
| 250 | 250 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | $current_quiz_id = $post->ID; |
| 279 | 279 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
| 280 | 280 | |
| 281 | - // reset all user data |
|
| 282 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 281 | + // reset all user data |
|
| 282 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 283 | 283 | |
| 284 | 284 | //this function should only run once |
| 285 | 285 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * Complete/ submit quiz hooked function |
| 291 | 291 | * |
| 292 | 292 | * This function listens to the complete button submit action and processes the users submitted answers |
| 293 | - * not that this function submits the given users quiz answers for grading. |
|
| 293 | + * not that this function submits the given users quiz answers for grading. |
|
| 294 | 294 | * |
| 295 | 295 | * @since 1.7.4 |
| 296 | 296 | * @access public |
@@ -300,90 +300,90 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | public function user_quiz_submit_listener() { |
| 302 | 302 | |
| 303 | - // only respond to valid quiz completion submissions |
|
| 304 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 305 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 306 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 307 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 308 | - return; |
|
| 309 | - } |
|
| 303 | + // only respond to valid quiz completion submissions |
|
| 304 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 305 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 306 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 307 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 308 | + return; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - global $post, $current_user; |
|
| 312 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 313 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 311 | + global $post, $current_user; |
|
| 312 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 313 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 314 | 314 | |
| 315 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 315 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 316 | 316 | |
| 317 | 317 | } // End sensei_complete_quiz() |
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * This function set's up the data need for the quiz page |
|
| 321 | - * |
|
| 322 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 323 | - * current quiz. |
|
| 324 | - * |
|
| 325 | - * @since 1.7.4 |
|
| 326 | - * @access public |
|
| 327 | - * |
|
| 328 | - */ |
|
| 329 | - public function load_global_quiz_data(){ |
|
| 319 | + /** |
|
| 320 | + * This function set's up the data need for the quiz page |
|
| 321 | + * |
|
| 322 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 323 | + * current quiz. |
|
| 324 | + * |
|
| 325 | + * @since 1.7.4 |
|
| 326 | + * @access public |
|
| 327 | + * |
|
| 328 | + */ |
|
| 329 | + public function load_global_quiz_data(){ |
|
| 330 | 330 | |
| 331 | - global $post, $current_user; |
|
| 332 | - $this->data = new stdClass(); |
|
| 331 | + global $post, $current_user; |
|
| 332 | + $this->data = new stdClass(); |
|
| 333 | 333 | |
| 334 | - // Default grade |
|
| 335 | - $grade = 0; |
|
| 334 | + // Default grade |
|
| 335 | + $grade = 0; |
|
| 336 | 336 | |
| 337 | - // Get Quiz Questions |
|
| 338 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 337 | + // Get Quiz Questions |
|
| 338 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 339 | 339 | |
| 340 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 340 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 341 | 341 | |
| 342 | - // Get quiz grade type |
|
| 343 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 342 | + // Get quiz grade type |
|
| 343 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 344 | 344 | |
| 345 | - // Get quiz pass setting |
|
| 346 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 345 | + // Get quiz pass setting |
|
| 346 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 347 | 347 | |
| 348 | - // Get quiz pass mark |
|
| 349 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 348 | + // Get quiz pass mark |
|
| 349 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 350 | 350 | |
| 351 | - // Get latest quiz answers and grades |
|
| 352 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 353 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 354 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 355 | - $user_quiz_grade = 0; |
|
| 356 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 357 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 358 | - } |
|
| 351 | + // Get latest quiz answers and grades |
|
| 352 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 353 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 354 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 355 | + $user_quiz_grade = 0; |
|
| 356 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 357 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 360 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 361 | 361 | |
| 362 | - // Check again that the lesson is complete |
|
| 363 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | - $user_lesson_complete = false; |
|
| 365 | - if ( $user_lesson_end ) { |
|
| 366 | - $user_lesson_complete = true; |
|
| 367 | - } // End If Statement |
|
| 362 | + // Check again that the lesson is complete |
|
| 363 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | + $user_lesson_complete = false; |
|
| 365 | + if ( $user_lesson_end ) { |
|
| 366 | + $user_lesson_complete = true; |
|
| 367 | + } // End If Statement |
|
| 368 | 368 | |
| 369 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | - //backwards compatibility |
|
| 371 | - if( 'on' == $reset_allowed ) { |
|
| 372 | - $reset_allowed = 1; |
|
| 373 | - } |
|
| 369 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | + //backwards compatibility |
|
| 371 | + if( 'on' == $reset_allowed ) { |
|
| 372 | + $reset_allowed = 1; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - // Build frontend data object for backwards compatibility |
|
| 376 | - // using this is no longer recommended |
|
| 377 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | - $this->data->quiz_passmark = $quiz_passmark; |
|
| 379 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 380 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 381 | - $this->data->user_lesson_end = $user_lesson_end; |
|
| 382 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 383 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 384 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 375 | + // Build frontend data object for backwards compatibility |
|
| 376 | + // using this is no longer recommended |
|
| 377 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | + $this->data->quiz_passmark = $quiz_passmark; |
|
| 379 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 380 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 381 | + $this->data->user_lesson_end = $user_lesson_end; |
|
| 382 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 383 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 384 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 385 | 385 | |
| 386 | - } // end load_global_quiz_data |
|
| 386 | + } // end load_global_quiz_data |
|
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -413,25 +413,25 @@ discard block |
||
| 413 | 413 | foreach( $unprepared_answers as $question_id => $answer ) { |
| 414 | 414 | |
| 415 | 415 | //get the current questions question type |
| 416 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 416 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | 417 | |
| 418 | 418 | // Sanitise answer |
| 419 | 419 | if( 0 == get_magic_quotes_gpc() ) { |
| 420 | 420 | $answer = wp_unslash( $answer ); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - // compress the answer for saving |
|
| 423 | + // compress the answer for saving |
|
| 424 | 424 | if( 'multi-line' == $question_type ) { |
| 425 | - $answer = esc_html( $answer ); |
|
| 426 | - }elseif( 'file-upload' == $question_type ){ |
|
| 427 | - $file_key = 'file_upload_' . $question_id; |
|
| 428 | - if( isset( $files[ $file_key ] ) ) { |
|
| 429 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 430 | - if( $attachment_id ) { |
|
| 431 | - $answer = $attachment_id; |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } // end if |
|
| 425 | + $answer = esc_html( $answer ); |
|
| 426 | + }elseif( 'file-upload' == $question_type ){ |
|
| 427 | + $file_key = 'file_upload_' . $question_id; |
|
| 428 | + if( isset( $files[ $file_key ] ) ) { |
|
| 429 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 430 | + if( $attachment_id ) { |
|
| 431 | + $answer = $attachment_id; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } // end if |
|
| 435 | 435 | |
| 436 | 436 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
| 437 | 437 | |
@@ -440,813 +440,813 @@ discard block |
||
| 440 | 440 | return $prepared_answers; |
| 441 | 441 | } // prepare_form_submitted_answers |
| 442 | 442 | |
| 443 | - /** |
|
| 444 | - * Reset user submitted questions |
|
| 445 | - * |
|
| 446 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 447 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 448 | - * |
|
| 449 | - * @since 1.7.4 |
|
| 450 | - * @access public |
|
| 451 | - * |
|
| 452 | - * @return bool $reset_success |
|
| 453 | - * @param int $user_id |
|
| 454 | - * @param int $lesson_id |
|
| 455 | - */ |
|
| 456 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 443 | + /** |
|
| 444 | + * Reset user submitted questions |
|
| 445 | + * |
|
| 446 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 447 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 448 | + * |
|
| 449 | + * @since 1.7.4 |
|
| 450 | + * @access public |
|
| 451 | + * |
|
| 452 | + * @return bool $reset_success |
|
| 453 | + * @param int $user_id |
|
| 454 | + * @param int $lesson_id |
|
| 455 | + */ |
|
| 456 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 457 | + |
|
| 458 | + //make sure the parameters are valid |
|
| 459 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 460 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 461 | + || ! get_userdata( $user_id ) ){ |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + //get the users lesson status to make |
|
| 468 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 469 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 470 | + // this user is not taking this lesson so this process is not needed |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + //get the lesson quiz and course |
|
| 475 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 476 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 477 | + |
|
| 478 | + // reset the transients |
|
| 479 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 480 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 481 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 482 | + delete_transient( $answers_transient_key ); |
|
| 483 | + delete_transient( $grades_transient_key ); |
|
| 484 | + delete_transient( $answers_feedback_transient_key ); |
|
| 485 | + |
|
| 486 | + // reset the quiz answers and feedback notes |
|
| 487 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 488 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 489 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 490 | + |
|
| 491 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 492 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 493 | + |
|
| 494 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 495 | + |
|
| 496 | + // Update course completion |
|
| 497 | + Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 457 | 498 | |
| 458 | - //make sure the parameters are valid |
|
| 459 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 460 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 461 | - || ! get_userdata( $user_id ) ){ |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - //get the users lesson status to make |
|
| 468 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 469 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 470 | - // this user is not taking this lesson so this process is not needed |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 499 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 500 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 501 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 473 | 502 | |
| 474 | - //get the lesson quiz and course |
|
| 475 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 476 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 503 | + return ( $deleted_answers && $deleted_grades ) ; |
|
| 477 | 504 | |
| 478 | - // reset the transients |
|
| 479 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 480 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 481 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 482 | - delete_transient( $answers_transient_key ); |
|
| 483 | - delete_transient( $grades_transient_key ); |
|
| 484 | - delete_transient( $answers_feedback_transient_key ); |
|
| 505 | + } // end reset_user_lesson_data |
|
| 485 | 506 | |
| 486 | - // reset the quiz answers and feedback notes |
|
| 487 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 488 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 489 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 507 | + /** |
|
| 508 | + * Submit the users quiz answers for grading |
|
| 509 | + * |
|
| 510 | + * This function accepts users answers and stores it but also initiates the grading |
|
| 511 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 512 | + * |
|
| 513 | + * @since 1.7.4 |
|
| 514 | + * @access public |
|
| 515 | + * |
|
| 516 | + * @param array $quiz_answers |
|
| 517 | + * @param array $files from $_FILES |
|
| 518 | + * @param int $user_id |
|
| 519 | + * @param int $lesson_id |
|
| 520 | + * |
|
| 521 | + * @return bool $answers_submitted |
|
| 522 | + */ |
|
| 523 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 490 | 524 | |
| 491 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 492 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 525 | + $answers_submitted = false; |
|
| 493 | 526 | |
| 494 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 527 | + // get the user_id if none was passed in use the current logged in user |
|
| 528 | + if( ! intval( $user_id ) > 0 ) { |
|
| 529 | + $user_id = get_current_user_id(); |
|
| 530 | + } |
|
| 495 | 531 | |
| 496 | - // Update course completion |
|
| 497 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 532 | + // make sure the parameters are valid before continuing |
|
| 533 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 534 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 535 | + ||!get_userdata( $user_id ) |
|
| 536 | + || !is_array( $quiz_answers ) ){ |
|
| 498 | 537 | |
| 499 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 500 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 501 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 538 | + return false; |
|
| 502 | 539 | |
| 503 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 540 | + } |
|
| 504 | 541 | |
| 505 | - } // end reset_user_lesson_data |
|
| 542 | + // Default grade |
|
| 543 | + $grade = 0; |
|
| 506 | 544 | |
| 507 | - /** |
|
| 508 | - * Submit the users quiz answers for grading |
|
| 509 | - * |
|
| 510 | - * This function accepts users answers and stores it but also initiates the grading |
|
| 511 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 512 | - * |
|
| 513 | - * @since 1.7.4 |
|
| 514 | - * @access public |
|
| 515 | - * |
|
| 516 | - * @param array $quiz_answers |
|
| 517 | - * @param array $files from $_FILES |
|
| 518 | - * @param int $user_id |
|
| 519 | - * @param int $lesson_id |
|
| 520 | - * |
|
| 521 | - * @return bool $answers_submitted |
|
| 522 | - */ |
|
| 523 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 545 | + // Get Quiz ID |
|
| 546 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 524 | 547 | |
| 525 | - $answers_submitted = false; |
|
| 548 | + // Get quiz grade type |
|
| 549 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 526 | 550 | |
| 527 | - // get the user_id if none was passed in use the current logged in user |
|
| 528 | - if( ! intval( $user_id ) > 0 ) { |
|
| 529 | - $user_id = get_current_user_id(); |
|
| 530 | - } |
|
| 551 | + // Get quiz pass setting |
|
| 552 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 531 | 553 | |
| 532 | - // make sure the parameters are valid before continuing |
|
| 533 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 534 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 535 | - ||!get_userdata( $user_id ) |
|
| 536 | - || !is_array( $quiz_answers ) ){ |
|
| 554 | + // Get the minimum percentage need to pass this quiz |
|
| 555 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 537 | 556 | |
| 538 | - return false; |
|
| 557 | + // Handle Quiz Questions asked |
|
| 558 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 559 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 560 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 561 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 562 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 563 | + if( empty( $questions_asked ) ){ |
|
| 539 | 564 | |
| 540 | - } |
|
| 565 | + $questions_asked = array_keys( $quiz_answers ); |
|
| 566 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
| 541 | 567 | |
| 542 | - // Default grade |
|
| 543 | - $grade = 0; |
|
| 568 | + // Save questions that were asked in this quiz |
|
| 569 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 544 | 570 | |
| 545 | - // Get Quiz ID |
|
| 546 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 571 | + } |
|
| 547 | 572 | |
| 548 | - // Get quiz grade type |
|
| 549 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 573 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 574 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 550 | 575 | |
| 551 | - // Get quiz pass setting |
|
| 552 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 576 | + // Grade quiz |
|
| 577 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 553 | 578 | |
| 554 | - // Get the minimum percentage need to pass this quiz |
|
| 555 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 579 | + // Get Lesson Grading Setting |
|
| 580 | + $lesson_metadata = array(); |
|
| 581 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 556 | 582 | |
| 557 | - // Handle Quiz Questions asked |
|
| 558 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 559 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 560 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 561 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 562 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 563 | - if( empty( $questions_asked ) ){ |
|
| 583 | + // At this point the answers have been submitted |
|
| 584 | + $answers_submitted = true; |
|
| 564 | 585 | |
| 565 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 566 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 567 | - |
|
| 568 | - // Save questions that were asked in this quiz |
|
| 569 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 586 | + // if this condition is false the quiz should manually be graded by admin |
|
| 587 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 570 | 588 | |
| 571 | - } |
|
| 589 | + // Quiz has been automatically Graded |
|
| 590 | + if ( 'on' == $pass_required ) { |
|
| 572 | 591 | |
| 573 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 574 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 592 | + // Student has reached the pass mark and lesson is complete |
|
| 593 | + if ( $quiz_pass_percentage <= $grade ) { |
|
| 575 | 594 | |
| 576 | - // Grade quiz |
|
| 577 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 595 | + $lesson_status = 'passed'; |
|
| 578 | 596 | |
| 579 | - // Get Lesson Grading Setting |
|
| 580 | - $lesson_metadata = array(); |
|
| 581 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 597 | + } else { |
|
| 582 | 598 | |
| 583 | - // At this point the answers have been submitted |
|
| 584 | - $answers_submitted = true; |
|
| 599 | + $lesson_status = 'failed'; |
|
| 585 | 600 | |
| 586 | - // if this condition is false the quiz should manually be graded by admin |
|
| 587 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 601 | + } // End If Statement |
|
| 588 | 602 | |
| 589 | - // Quiz has been automatically Graded |
|
| 590 | - if ( 'on' == $pass_required ) { |
|
| 603 | + } else { |
|
| 591 | 604 | |
| 592 | - // Student has reached the pass mark and lesson is complete |
|
| 593 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 605 | + // Student only has to partake the quiz |
|
| 606 | + $lesson_status = 'graded'; |
|
| 607 | + |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 611 | + |
|
| 612 | + } // end if ! is_wp_error( $grade ... |
|
| 613 | + |
|
| 614 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 594 | 615 | |
| 595 | - $lesson_status = 'passed'; |
|
| 616 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 596 | 617 | |
| 597 | - } else { |
|
| 618 | + /** |
|
| 619 | + * Lesson end action hook |
|
| 620 | + * |
|
| 621 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 622 | + * |
|
| 623 | + * @param int $user_id |
|
| 624 | + * @param int $lesson_id |
|
| 625 | + */ |
|
| 626 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 598 | 627 | |
| 599 | - $lesson_status = 'failed'; |
|
| 628 | + } |
|
| 600 | 629 | |
| 601 | - } // End If Statement |
|
| 630 | + /** |
|
| 631 | + * User quiz has been submitted |
|
| 632 | + * |
|
| 633 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 634 | + * results. |
|
| 635 | + * |
|
| 636 | + * @param int $user_id |
|
| 637 | + * @param int $quiz_id |
|
| 638 | + * @param string $grade |
|
| 639 | + * @param string $quiz_pass_percentage |
|
| 640 | + * @param string $quiz_grade_type |
|
| 641 | + */ |
|
| 642 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 602 | 643 | |
| 603 | - } else { |
|
| 644 | + return $answers_submitted; |
|
| 604 | 645 | |
| 605 | - // Student only has to partake the quiz |
|
| 606 | - $lesson_status = 'graded'; |
|
| 607 | - |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 611 | - |
|
| 612 | - } // end if ! is_wp_error( $grade ... |
|
| 613 | - |
|
| 614 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 646 | + }// end submit_answers_for_grading |
|
| 615 | 647 | |
| 616 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 648 | + /** |
|
| 649 | + * Get the user question answer |
|
| 650 | + * |
|
| 651 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 652 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 653 | + * |
|
| 654 | + * @since 1.7.4 |
|
| 655 | + * |
|
| 656 | + * @param int $lesson_id |
|
| 657 | + * @param int $question_id |
|
| 658 | + * @param int $user_id ( optional ) |
|
| 659 | + * |
|
| 660 | + * @return bool|null $answers_submitted |
|
| 661 | + */ |
|
| 662 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 617 | 663 | |
| 618 | - /** |
|
| 619 | - * Lesson end action hook |
|
| 620 | - * |
|
| 621 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 622 | - * |
|
| 623 | - * @param int $user_id |
|
| 624 | - * @param int $lesson_id |
|
| 625 | - */ |
|
| 626 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 664 | + // parameter validation |
|
| 665 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 666 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 667 | + || ! ( intval( $question_id ) > 0 ) |
|
| 668 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 669 | + || 'question' != get_post_type( $question_id )) { |
|
| 627 | 670 | |
| 628 | - } |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | + $user_id = get_current_user_id(); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | + |
|
| 680 | + if( !$users_answers || empty( $users_answers ) |
|
| 681 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 682 | + |
|
| 683 | + //Fallback for pre 1.7.4 data |
|
| 684 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | + |
|
| 686 | + if( ! isset( $comment->comment_content ) ){ |
|
| 687 | + return NULL; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return $users_answers[ $question_id ]; |
|
| 694 | + |
|
| 695 | + }// end get_user_question_answer |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Saving the users quiz question grades |
|
| 699 | + * |
|
| 700 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
| 701 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 702 | + * |
|
| 703 | + * @since 1.7.4 |
|
| 704 | + * |
|
| 705 | + * @param array $quiz_grades{ |
|
| 706 | + * @type int $question_id |
|
| 707 | + * @type int $question_grade |
|
| 708 | + * } |
|
| 709 | + * @param $lesson_id |
|
| 710 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 711 | + * |
|
| 712 | + * @return bool |
|
| 713 | + */ |
|
| 714 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | + |
|
| 716 | + // get the user_id if none was passed in use the current logged in user |
|
| 717 | + if( ! intval( $user_id ) > 0 ) { |
|
| 718 | + $user_id = get_current_user_id(); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + // make sure the parameters are valid before continuing |
|
| 722 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 723 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 724 | + ||!get_userdata( $user_id ) |
|
| 725 | + || !is_array( $quiz_grades ) ){ |
|
| 726 | + |
|
| 727 | + return false; |
|
| 728 | + |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + $success = false; |
|
| 732 | + |
|
| 733 | + // save that data for the user on the lesson comment meta |
|
| 734 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | + |
|
| 736 | + // were the grades save successfully ? |
|
| 737 | + if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | + |
|
| 739 | + $success = true; |
|
| 740 | + // save transient |
|
| 741 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 742 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return $success; |
|
| 746 | + |
|
| 747 | + }// end set_user_grades |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * Retrieve the users quiz question grades |
|
| 751 | + * |
|
| 752 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 753 | + * |
|
| 754 | + * @since 1.7.4 |
|
| 755 | + * |
|
| 756 | + * @param $lesson_id |
|
| 757 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 758 | + * |
|
| 759 | + * @return array $user_quiz_grades or false if none exists for this users |
|
| 760 | + */ |
|
| 761 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | + |
|
| 763 | + $user_grades = array(); |
|
| 764 | + |
|
| 765 | + // get the user_id if none was passed in use the current logged in user |
|
| 766 | + if( ! intval( $user_id ) > 0 ) { |
|
| 767 | + $user_id = get_current_user_id(); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 771 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 772 | + return false; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + // save some time and get the transient cached data |
|
| 776 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 777 | + $user_grades = get_transient( $transient_key ); |
|
| 778 | + |
|
| 779 | + // get the data if nothing was stored in the transient |
|
| 780 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | + |
|
| 782 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | + |
|
| 784 | + //set the transient with the new valid data for faster retrieval in future |
|
| 785 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | + |
|
| 787 | + } // end if transient check |
|
| 788 | + |
|
| 789 | + // if there is no data for this user |
|
| 790 | + if( ! is_array( $user_grades ) ){ |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + return $user_grades; |
|
| 795 | + |
|
| 796 | + }// end get_user_grades |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Get the user question grade |
|
| 800 | + * |
|
| 801 | + * This function gets the grade on a quiz for the given question parameter |
|
| 802 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 803 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 804 | + * |
|
| 805 | + * @since 1.7.4 |
|
| 806 | + * |
|
| 807 | + * @param int $lesson_id |
|
| 808 | + * @param int $question_id |
|
| 809 | + * @param int $user_id ( optional ) |
|
| 810 | + * |
|
| 811 | + * @return bool $question_grade |
|
| 812 | + */ |
|
| 813 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | + |
|
| 815 | + // parameter validation |
|
| 816 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 817 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 818 | + || ! ( intval( $question_id ) > 0 ) |
|
| 819 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 820 | + || 'question' != get_post_type( $question_id )) { |
|
| 821 | + |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | + |
|
| 827 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | + |
|
| 829 | + //fallback to data pre 1.7.4 |
|
| 830 | + $args = array( |
|
| 831 | + 'post_id' => $question_id, |
|
| 832 | + 'user_id' => $user_id, |
|
| 833 | + 'type' => 'sensei_user_answer' |
|
| 834 | + ); |
|
| 835 | + |
|
| 836 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | + $fall_back_grade = false; |
|
| 838 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 839 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + return $fall_back_grade; |
|
| 843 | + |
|
| 844 | + } // end if $all_user_grades... |
|
| 845 | + |
|
| 846 | + return $all_user_grades[ $question_id ]; |
|
| 847 | + |
|
| 848 | + }// end get_user_question_grade |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Save the user's answers feedback |
|
| 852 | + * |
|
| 853 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
| 854 | + * The data will be saved on the lesson ID supplied. |
|
| 855 | + * |
|
| 856 | + * @since 1.7.5 |
|
| 857 | + * @access public |
|
| 858 | + * |
|
| 859 | + * @param array $answers_feedback{ |
|
| 860 | + * $type int $question_id |
|
| 861 | + * $type string $question_feedback |
|
| 862 | + * } |
|
| 863 | + * @param int $lesson_id |
|
| 864 | + * @param int $user_id |
|
| 865 | + * |
|
| 866 | + * @return false or int $feedback_saved |
|
| 867 | + */ |
|
| 868 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | + |
|
| 870 | + // make sure the parameters are valid before continuing |
|
| 871 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 872 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 873 | + ||!get_userdata( $user_id ) |
|
| 874 | + || !is_array( $answers_feedback ) ){ |
|
| 875 | + |
|
| 876 | + return false; |
|
| 877 | + |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
| 882 | + if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 883 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 884 | + } |
|
| 629 | 885 | |
| 630 | - /** |
|
| 631 | - * User quiz has been submitted |
|
| 632 | - * |
|
| 633 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 634 | - * results. |
|
| 635 | - * |
|
| 636 | - * @param int $user_id |
|
| 637 | - * @param int $quiz_id |
|
| 638 | - * @param string $grade |
|
| 639 | - * @param string $quiz_pass_percentage |
|
| 640 | - * @param string $quiz_grade_type |
|
| 641 | - */ |
|
| 642 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 886 | + // encode the feedback |
|
| 887 | + $encoded_answers_feedback = array(); |
|
| 888 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 889 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + // save the user data |
|
| 893 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | + |
|
| 895 | + //Were the the question feedback save correctly? |
|
| 896 | + if( intval( $feedback_saved ) > 0){ |
|
| 897 | + |
|
| 898 | + // save transient to make retrieval faster in future |
|
| 899 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 900 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 643 | 901 | |
| 644 | - return $answers_submitted; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $feedback_saved; |
|
| 905 | + |
|
| 906 | + } // end save_user_answers_feedback |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Get the user's answers feedback. |
|
| 910 | + * |
|
| 911 | + * This function returns the feedback submitted by the teacher/admin |
|
| 912 | + * during grading. Grading occurs manually or automatically. |
|
| 913 | + * |
|
| 914 | + * @since 1.7.5 |
|
| 915 | + * @access public |
|
| 916 | + * |
|
| 917 | + * @param int $lesson_id |
|
| 918 | + * @param int $user_id |
|
| 919 | + * |
|
| 920 | + * @return false | array $answers_feedback{ |
|
| 921 | + * $type int $question_id |
|
| 922 | + * $type string $question_feedback |
|
| 923 | + * } |
|
| 924 | + */ |
|
| 925 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | + |
|
| 927 | + $answers_feedback = array(); |
|
| 645 | 928 | |
| 646 | - }// end submit_answers_for_grading |
|
| 929 | + // get the user_id if none was passed in use the current logged in user |
|
| 930 | + if( ! intval( $user_id ) > 0 ) { |
|
| 931 | + $user_id = get_current_user_id(); |
|
| 932 | + } |
|
| 647 | 933 | |
| 648 | - /** |
|
| 649 | - * Get the user question answer |
|
| 650 | - * |
|
| 651 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 652 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 653 | - * |
|
| 654 | - * @since 1.7.4 |
|
| 655 | - * |
|
| 656 | - * @param int $lesson_id |
|
| 657 | - * @param int $question_id |
|
| 658 | - * @param int $user_id ( optional ) |
|
| 659 | - * |
|
| 660 | - * @return bool|null $answers_submitted |
|
| 661 | - */ |
|
| 662 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 934 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 935 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 936 | + return false; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + // first check the transient to save a few split seconds |
|
| 940 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 941 | + $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | + |
|
| 943 | + // get the data if nothing was stored in the transient |
|
| 944 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | + |
|
| 946 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | + |
|
| 948 | + //set the transient with the new valid data for faster retrieval in future |
|
| 949 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | + |
|
| 951 | + } // end if transient check |
|
| 663 | 952 | |
| 664 | - // parameter validation |
|
| 665 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 666 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 667 | - || ! ( intval( $question_id ) > 0 ) |
|
| 668 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 669 | - || 'question' != get_post_type( $question_id )) { |
|
| 953 | + // if there is no data for this user |
|
| 954 | + if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | + return false; |
|
| 956 | + } |
|
| 670 | 957 | |
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | - $user_id = get_current_user_id(); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | - |
|
| 680 | - if( !$users_answers || empty( $users_answers ) |
|
| 681 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 682 | - |
|
| 683 | - //Fallback for pre 1.7.4 data |
|
| 684 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | - |
|
| 686 | - if( ! isset( $comment->comment_content ) ){ |
|
| 687 | - return NULL; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return $users_answers[ $question_id ]; |
|
| 694 | - |
|
| 695 | - }// end get_user_question_answer |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Saving the users quiz question grades |
|
| 699 | - * |
|
| 700 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
| 701 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 702 | - * |
|
| 703 | - * @since 1.7.4 |
|
| 704 | - * |
|
| 705 | - * @param array $quiz_grades{ |
|
| 706 | - * @type int $question_id |
|
| 707 | - * @type int $question_grade |
|
| 708 | - * } |
|
| 709 | - * @param $lesson_id |
|
| 710 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 711 | - * |
|
| 712 | - * @return bool |
|
| 713 | - */ |
|
| 714 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | - |
|
| 716 | - // get the user_id if none was passed in use the current logged in user |
|
| 717 | - if( ! intval( $user_id ) > 0 ) { |
|
| 718 | - $user_id = get_current_user_id(); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - // make sure the parameters are valid before continuing |
|
| 722 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 723 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 724 | - ||!get_userdata( $user_id ) |
|
| 725 | - || !is_array( $quiz_grades ) ){ |
|
| 726 | - |
|
| 727 | - return false; |
|
| 728 | - |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - $success = false; |
|
| 732 | - |
|
| 733 | - // save that data for the user on the lesson comment meta |
|
| 734 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | - |
|
| 736 | - // were the grades save successfully ? |
|
| 737 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | - |
|
| 739 | - $success = true; |
|
| 740 | - // save transient |
|
| 741 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 742 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return $success; |
|
| 746 | - |
|
| 747 | - }// end set_user_grades |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * Retrieve the users quiz question grades |
|
| 751 | - * |
|
| 752 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 753 | - * |
|
| 754 | - * @since 1.7.4 |
|
| 755 | - * |
|
| 756 | - * @param $lesson_id |
|
| 757 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 758 | - * |
|
| 759 | - * @return array $user_quiz_grades or false if none exists for this users |
|
| 760 | - */ |
|
| 761 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | - |
|
| 763 | - $user_grades = array(); |
|
| 764 | - |
|
| 765 | - // get the user_id if none was passed in use the current logged in user |
|
| 766 | - if( ! intval( $user_id ) > 0 ) { |
|
| 767 | - $user_id = get_current_user_id(); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 771 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 772 | - return false; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - // save some time and get the transient cached data |
|
| 776 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 777 | - $user_grades = get_transient( $transient_key ); |
|
| 778 | - |
|
| 779 | - // get the data if nothing was stored in the transient |
|
| 780 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | - |
|
| 782 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | - |
|
| 784 | - //set the transient with the new valid data for faster retrieval in future |
|
| 785 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | - |
|
| 787 | - } // end if transient check |
|
| 788 | - |
|
| 789 | - // if there is no data for this user |
|
| 790 | - if( ! is_array( $user_grades ) ){ |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - return $user_grades; |
|
| 795 | - |
|
| 796 | - }// end get_user_grades |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Get the user question grade |
|
| 800 | - * |
|
| 801 | - * This function gets the grade on a quiz for the given question parameter |
|
| 802 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 803 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 804 | - * |
|
| 805 | - * @since 1.7.4 |
|
| 806 | - * |
|
| 807 | - * @param int $lesson_id |
|
| 808 | - * @param int $question_id |
|
| 809 | - * @param int $user_id ( optional ) |
|
| 810 | - * |
|
| 811 | - * @return bool $question_grade |
|
| 812 | - */ |
|
| 813 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | - |
|
| 815 | - // parameter validation |
|
| 816 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 817 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 818 | - || ! ( intval( $question_id ) > 0 ) |
|
| 819 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 820 | - || 'question' != get_post_type( $question_id )) { |
|
| 821 | - |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | - |
|
| 827 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | - |
|
| 829 | - //fallback to data pre 1.7.4 |
|
| 830 | - $args = array( |
|
| 831 | - 'post_id' => $question_id, |
|
| 832 | - 'user_id' => $user_id, |
|
| 833 | - 'type' => 'sensei_user_answer' |
|
| 834 | - ); |
|
| 835 | - |
|
| 836 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | - $fall_back_grade = false; |
|
| 838 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 839 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - return $fall_back_grade; |
|
| 843 | - |
|
| 844 | - } // end if $all_user_grades... |
|
| 845 | - |
|
| 846 | - return $all_user_grades[ $question_id ]; |
|
| 847 | - |
|
| 848 | - }// end get_user_question_grade |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Save the user's answers feedback |
|
| 852 | - * |
|
| 853 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
| 854 | - * The data will be saved on the lesson ID supplied. |
|
| 855 | - * |
|
| 856 | - * @since 1.7.5 |
|
| 857 | - * @access public |
|
| 858 | - * |
|
| 859 | - * @param array $answers_feedback{ |
|
| 860 | - * $type int $question_id |
|
| 861 | - * $type string $question_feedback |
|
| 862 | - * } |
|
| 863 | - * @param int $lesson_id |
|
| 864 | - * @param int $user_id |
|
| 865 | - * |
|
| 866 | - * @return false or int $feedback_saved |
|
| 867 | - */ |
|
| 868 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | - |
|
| 870 | - // make sure the parameters are valid before continuing |
|
| 871 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 872 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 873 | - ||!get_userdata( $user_id ) |
|
| 874 | - || !is_array( $answers_feedback ) ){ |
|
| 875 | - |
|
| 876 | - return false; |
|
| 877 | - |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
| 882 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 883 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - // encode the feedback |
|
| 887 | - $encoded_answers_feedback = array(); |
|
| 888 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 889 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - // save the user data |
|
| 893 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | - |
|
| 895 | - //Were the the question feedback save correctly? |
|
| 896 | - if( intval( $feedback_saved ) > 0){ |
|
| 897 | - |
|
| 898 | - // save transient to make retrieval faster in future |
|
| 899 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 900 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 901 | - |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $feedback_saved; |
|
| 905 | - |
|
| 906 | - } // end save_user_answers_feedback |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Get the user's answers feedback. |
|
| 910 | - * |
|
| 911 | - * This function returns the feedback submitted by the teacher/admin |
|
| 912 | - * during grading. Grading occurs manually or automatically. |
|
| 913 | - * |
|
| 914 | - * @since 1.7.5 |
|
| 915 | - * @access public |
|
| 916 | - * |
|
| 917 | - * @param int $lesson_id |
|
| 918 | - * @param int $user_id |
|
| 919 | - * |
|
| 920 | - * @return false | array $answers_feedback{ |
|
| 921 | - * $type int $question_id |
|
| 922 | - * $type string $question_feedback |
|
| 923 | - * } |
|
| 924 | - */ |
|
| 925 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | - |
|
| 927 | - $answers_feedback = array(); |
|
| 928 | - |
|
| 929 | - // get the user_id if none was passed in use the current logged in user |
|
| 930 | - if( ! intval( $user_id ) > 0 ) { |
|
| 931 | - $user_id = get_current_user_id(); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 935 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 936 | - return false; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - // first check the transient to save a few split seconds |
|
| 940 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 941 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | - |
|
| 943 | - // get the data if nothing was stored in the transient |
|
| 944 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | - |
|
| 946 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | - |
|
| 948 | - //set the transient with the new valid data for faster retrieval in future |
|
| 949 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | - |
|
| 951 | - } // end if transient check |
|
| 952 | - |
|
| 953 | - // if there is no data for this user |
|
| 954 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | - return false; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 958 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 959 | 959 | |
| 960 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 960 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 961 | 961 | |
| 962 | - } |
|
| 962 | + } |
|
| 963 | 963 | |
| 964 | - return $answers_feedback; |
|
| 964 | + return $answers_feedback; |
|
| 965 | 965 | |
| 966 | - } // end get_user_answers_feedback |
|
| 966 | + } // end get_user_answers_feedback |
|
| 967 | 967 | |
| 968 | - /** |
|
| 969 | - * Get the user's answer feedback for a specific question. |
|
| 970 | - * |
|
| 971 | - * This function gives you a single answer note/feedback string |
|
| 972 | - * for the user on the given question. |
|
| 973 | - * |
|
| 974 | - * @since 1.7.5 |
|
| 975 | - * @access public |
|
| 976 | - * |
|
| 977 | - * @param int $lesson_id |
|
| 978 | - * @param int $question_id |
|
| 979 | - * @param int $user_id |
|
| 980 | - * |
|
| 981 | - * @return string $feedback or bool if false |
|
| 982 | - */ |
|
| 983 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 968 | + /** |
|
| 969 | + * Get the user's answer feedback for a specific question. |
|
| 970 | + * |
|
| 971 | + * This function gives you a single answer note/feedback string |
|
| 972 | + * for the user on the given question. |
|
| 973 | + * |
|
| 974 | + * @since 1.7.5 |
|
| 975 | + * @access public |
|
| 976 | + * |
|
| 977 | + * @param int $lesson_id |
|
| 978 | + * @param int $question_id |
|
| 979 | + * @param int $user_id |
|
| 980 | + * |
|
| 981 | + * @return string $feedback or bool if false |
|
| 982 | + */ |
|
| 983 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 984 | 984 | |
| 985 | - $feedback = false; |
|
| 985 | + $feedback = false; |
|
| 986 | 986 | |
| 987 | - // parameter validation |
|
| 988 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 989 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 990 | - || ! ( intval( $question_id ) > 0 ) |
|
| 991 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 992 | - || 'question' != get_post_type( $question_id )) { |
|
| 987 | + // parameter validation |
|
| 988 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 989 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 990 | + || ! ( intval( $question_id ) > 0 ) |
|
| 991 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 992 | + || 'question' != get_post_type( $question_id )) { |
|
| 993 | 993 | |
| 994 | - return false; |
|
| 995 | - } |
|
| 994 | + return false; |
|
| 995 | + } |
|
| 996 | 996 | |
| 997 | - // get all the feedback for the user on the given lesson |
|
| 998 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 997 | + // get all the feedback for the user on the given lesson |
|
| 998 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 999 | 999 | |
| 1000 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1001 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1000 | + if( !$all_feedback || empty( $all_feedback ) |
|
| 1001 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1002 | 1002 | |
| 1003 | - //fallback to data pre 1.7.4 |
|
| 1003 | + //fallback to data pre 1.7.4 |
|
| 1004 | 1004 | |
| 1005 | - // setup the sensei data query |
|
| 1006 | - $args = array( |
|
| 1007 | - 'post_id' => $question_id, |
|
| 1008 | - 'user_id' => $user_id, |
|
| 1009 | - 'type' => 'sensei_user_answer' |
|
| 1010 | - ); |
|
| 1011 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1005 | + // setup the sensei data query |
|
| 1006 | + $args = array( |
|
| 1007 | + 'post_id' => $question_id, |
|
| 1008 | + 'user_id' => $user_id, |
|
| 1009 | + 'type' => 'sensei_user_answer' |
|
| 1010 | + ); |
|
| 1011 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1012 | 1012 | |
| 1013 | - // set the default to false and return that if no old data is available. |
|
| 1014 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1015 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1016 | - } |
|
| 1013 | + // set the default to false and return that if no old data is available. |
|
| 1014 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 1015 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1016 | + } |
|
| 1017 | 1017 | |
| 1018 | - // finally use the default question feedback |
|
| 1019 | - if( empty( $feedback ) ){ |
|
| 1020 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1021 | - } |
|
| 1018 | + // finally use the default question feedback |
|
| 1019 | + if( empty( $feedback ) ){ |
|
| 1020 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1021 | + } |
|
| 1022 | 1022 | |
| 1023 | - return $feedback; |
|
| 1023 | + return $feedback; |
|
| 1024 | 1024 | |
| 1025 | - } |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | - return $all_feedback[ $question_id ]; |
|
| 1027 | + return $all_feedback[ $question_id ]; |
|
| 1028 | 1028 | |
| 1029 | - } // end get_user_question_feedback |
|
| 1029 | + } // end get_user_question_feedback |
|
| 1030 | 1030 | |
| 1031 | - /** |
|
| 1032 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1033 | - * |
|
| 1034 | - * Though a quiz is created for each lesson, it should not be visible |
|
| 1035 | - * unless it has questions. |
|
| 1036 | - * |
|
| 1037 | - * @since 1.9.0 |
|
| 1038 | - * @access public |
|
| 1039 | - * @param none |
|
| 1040 | - * @return void |
|
| 1041 | - */ |
|
| 1031 | + /** |
|
| 1032 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1033 | + * |
|
| 1034 | + * Though a quiz is created for each lesson, it should not be visible |
|
| 1035 | + * unless it has questions. |
|
| 1036 | + * |
|
| 1037 | + * @since 1.9.0 |
|
| 1038 | + * @access public |
|
| 1039 | + * @param none |
|
| 1040 | + * @return void |
|
| 1041 | + */ |
|
| 1042 | 1042 | |
| 1043 | - public function quiz_has_no_questions() { |
|
| 1043 | + public function quiz_has_no_questions() { |
|
| 1044 | 1044 | |
| 1045 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1046 | - return; |
|
| 1047 | - } |
|
| 1045 | + if( ! is_singular( 'quiz' ) ) { |
|
| 1046 | + return; |
|
| 1047 | + } |
|
| 1048 | 1048 | |
| 1049 | - global $post; |
|
| 1049 | + global $post; |
|
| 1050 | 1050 | |
| 1051 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1051 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1052 | 1052 | |
| 1053 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1053 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1054 | 1054 | |
| 1055 | - $lesson = get_post($lesson_id); |
|
| 1055 | + $lesson = get_post($lesson_id); |
|
| 1056 | 1056 | |
| 1057 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1057 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1058 | 1058 | |
| 1059 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1060 | - exit; |
|
| 1059 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1060 | + exit; |
|
| 1061 | 1061 | |
| 1062 | - } |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - } // end quiz_has_no_questions |
|
| 1064 | + } // end quiz_has_no_questions |
|
| 1065 | 1065 | |
| 1066 | 1066 | /** |
| 1067 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1068 | - * |
|
| 1069 | - * @deprecated since 1.9.0 |
|
| 1070 | - */ |
|
| 1067 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1068 | + * |
|
| 1069 | + * @deprecated since 1.9.0 |
|
| 1070 | + */ |
|
| 1071 | 1071 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
| 1072 | 1072 | |
| 1073 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1073 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1074 | 1074 | |
| 1075 | 1075 | } |
| 1076 | - /* |
|
| 1076 | + /* |
|
| 1077 | 1077 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
| 1078 | 1078 | * |
| 1079 | 1079 | * @deprecated since 1.9.0 |
| 1080 | 1080 | */ |
| 1081 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1081 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1082 | 1082 | |
| 1083 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1083 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1084 | 1084 | |
| 1085 | - } |
|
| 1085 | + } |
|
| 1086 | 1086 | |
| 1087 | - /** |
|
| 1088 | - * Filter the single title and add the Quiz to it. |
|
| 1089 | - * |
|
| 1090 | - * @param string $title |
|
| 1091 | - * @param int $id title post id |
|
| 1092 | - * @return string $quiz_title |
|
| 1093 | - */ |
|
| 1094 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1087 | + /** |
|
| 1088 | + * Filter the single title and add the Quiz to it. |
|
| 1089 | + * |
|
| 1090 | + * @param string $title |
|
| 1091 | + * @param int $id title post id |
|
| 1092 | + * @return string $quiz_title |
|
| 1093 | + */ |
|
| 1094 | + public static function single_quiz_title( $title, $post_id ){ |
|
| 1095 | 1095 | |
| 1096 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1096 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1097 | 1097 | |
| 1098 | - $title_with_no_quizzes = $title; |
|
| 1098 | + $title_with_no_quizzes = $title; |
|
| 1099 | 1099 | |
| 1100 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1101 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1100 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1101 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1102 | 1102 | |
| 1103 | - // remove all possible appearances of quiz |
|
| 1104 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1105 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1106 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1103 | + // remove all possible appearances of quiz |
|
| 1104 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1105 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1106 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1107 | 1107 | |
| 1108 | - } |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1111 | - } |
|
| 1110 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | - /** |
|
| 1114 | - * hook document in class-woothemes-sensei-message.php |
|
| 1115 | - */ |
|
| 1116 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1113 | + /** |
|
| 1114 | + * hook document in class-woothemes-sensei-message.php |
|
| 1115 | + */ |
|
| 1116 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1117 | 1117 | |
| 1118 | - } |
|
| 1118 | + } |
|
| 1119 | 1119 | |
| 1120 | - /** |
|
| 1121 | - * Initialize the quiz question loop on the single quiz template |
|
| 1122 | - * |
|
| 1123 | - * The function will create a global quiz loop varialbe. |
|
| 1124 | - * |
|
| 1125 | - * @since 1.9.0 |
|
| 1126 | - * |
|
| 1127 | - */ |
|
| 1128 | - public static function start_quiz_questions_loop(){ |
|
| 1120 | + /** |
|
| 1121 | + * Initialize the quiz question loop on the single quiz template |
|
| 1122 | + * |
|
| 1123 | + * The function will create a global quiz loop varialbe. |
|
| 1124 | + * |
|
| 1125 | + * @since 1.9.0 |
|
| 1126 | + * |
|
| 1127 | + */ |
|
| 1128 | + public static function start_quiz_questions_loop(){ |
|
| 1129 | 1129 | |
| 1130 | - global $sensei_question_loop; |
|
| 1130 | + global $sensei_question_loop; |
|
| 1131 | 1131 | |
| 1132 | - //intialize the questions loop object |
|
| 1133 | - $sensei_question_loop['current'] = -1; |
|
| 1134 | - $sensei_question_loop['total'] = 0; |
|
| 1135 | - $sensei_question_loop['questions'] = array(); |
|
| 1132 | + //intialize the questions loop object |
|
| 1133 | + $sensei_question_loop['current'] = -1; |
|
| 1134 | + $sensei_question_loop['total'] = 0; |
|
| 1135 | + $sensei_question_loop['questions'] = array(); |
|
| 1136 | 1136 | |
| 1137 | 1137 | |
| 1138 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1138 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1139 | 1139 | |
| 1140 | - if( count( $questions ) > 0 ){ |
|
| 1140 | + if( count( $questions ) > 0 ){ |
|
| 1141 | 1141 | |
| 1142 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1143 | - $sensei_question_loop['questions'] = $questions; |
|
| 1144 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1142 | + $sensei_question_loop['total'] = count( $questions ); |
|
| 1143 | + $sensei_question_loop['questions'] = $questions; |
|
| 1144 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1145 | 1145 | |
| 1146 | - } |
|
| 1146 | + } |
|
| 1147 | 1147 | |
| 1148 | - }// static function |
|
| 1148 | + }// static function |
|
| 1149 | 1149 | |
| 1150 | - /** |
|
| 1151 | - * Initialize the quiz question loop on the single quiz template |
|
| 1152 | - * |
|
| 1153 | - * The function will create a global quiz loop varialbe. |
|
| 1154 | - * |
|
| 1155 | - * @since 1.9.0 |
|
| 1156 | - * |
|
| 1157 | - */ |
|
| 1158 | - public static function stop_quiz_questions_loop(){ |
|
| 1150 | + /** |
|
| 1151 | + * Initialize the quiz question loop on the single quiz template |
|
| 1152 | + * |
|
| 1153 | + * The function will create a global quiz loop varialbe. |
|
| 1154 | + * |
|
| 1155 | + * @since 1.9.0 |
|
| 1156 | + * |
|
| 1157 | + */ |
|
| 1158 | + public static function stop_quiz_questions_loop(){ |
|
| 1159 | 1159 | |
| 1160 | - $sensei_question_loop['total'] = 0; |
|
| 1161 | - $sensei_question_loop['questions'] = array(); |
|
| 1162 | - $sensei_question_loop['quiz_id'] = ''; |
|
| 1160 | + $sensei_question_loop['total'] = 0; |
|
| 1161 | + $sensei_question_loop['questions'] = array(); |
|
| 1162 | + $sensei_question_loop['quiz_id'] = ''; |
|
| 1163 | 1163 | |
| 1164 | - } |
|
| 1164 | + } |
|
| 1165 | 1165 | |
| 1166 | - /** |
|
| 1167 | - * Output the title for the single quiz page |
|
| 1168 | - * |
|
| 1169 | - * @since 1.9.0 |
|
| 1170 | - */ |
|
| 1171 | - public static function the_title(){ |
|
| 1172 | - ?> |
|
| 1166 | + /** |
|
| 1167 | + * Output the title for the single quiz page |
|
| 1168 | + * |
|
| 1169 | + * @since 1.9.0 |
|
| 1170 | + */ |
|
| 1171 | + public static function the_title(){ |
|
| 1172 | + ?> |
|
| 1173 | 1173 | <header> |
| 1174 | 1174 | |
| 1175 | 1175 | <h1> |
| 1176 | 1176 | |
| 1177 | 1177 | <?php |
| 1178 | - /** |
|
| 1179 | - * Filter documented in class-sensei-messages.php the_title |
|
| 1180 | - */ |
|
| 1181 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1182 | - ?> |
|
| 1178 | + /** |
|
| 1179 | + * Filter documented in class-sensei-messages.php the_title |
|
| 1180 | + */ |
|
| 1181 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1182 | + ?> |
|
| 1183 | 1183 | |
| 1184 | 1184 | </h1> |
| 1185 | 1185 | |
| 1186 | 1186 | </header> |
| 1187 | 1187 | |
| 1188 | 1188 | <?php |
| 1189 | - }//the_title |
|
| 1189 | + }//the_title |
|
| 1190 | 1190 | |
| 1191 | - /** |
|
| 1192 | - * Output the sensei quiz status message. |
|
| 1193 | - * |
|
| 1194 | - * @param $quiz_id |
|
| 1195 | - */ |
|
| 1196 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1191 | + /** |
|
| 1192 | + * Output the sensei quiz status message. |
|
| 1193 | + * |
|
| 1194 | + * @param $quiz_id |
|
| 1195 | + */ |
|
| 1196 | + public static function the_user_status_message( $quiz_id ){ |
|
| 1197 | 1197 | |
| 1198 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1199 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1200 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1198 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1199 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1200 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1201 | 1201 | |
| 1202 | - } |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | - /** |
|
| 1205 | - * This functions runs the old sensei_quiz_action_buttons action |
|
| 1206 | - * for backwards compatiblity sake. |
|
| 1207 | - * |
|
| 1208 | - * @since 1.9.0 |
|
| 1209 | - * @deprecated |
|
| 1210 | - */ |
|
| 1211 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1204 | + /** |
|
| 1205 | + * This functions runs the old sensei_quiz_action_buttons action |
|
| 1206 | + * for backwards compatiblity sake. |
|
| 1207 | + * |
|
| 1208 | + * @since 1.9.0 |
|
| 1209 | + * @deprecated |
|
| 1210 | + */ |
|
| 1211 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1212 | 1212 | |
| 1213 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1213 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1214 | 1214 | |
| 1215 | - } |
|
| 1215 | + } |
|
| 1216 | 1216 | |
| 1217 | - /** |
|
| 1218 | - * The quiz action buttons needed to ouput quiz |
|
| 1219 | - * action such as reset complete and save. |
|
| 1220 | - * |
|
| 1221 | - * @since 1.3.0 |
|
| 1222 | - */ |
|
| 1223 | - public static function action_buttons() { |
|
| 1217 | + /** |
|
| 1218 | + * The quiz action buttons needed to ouput quiz |
|
| 1219 | + * action such as reset complete and save. |
|
| 1220 | + * |
|
| 1221 | + * @since 1.3.0 |
|
| 1222 | + */ |
|
| 1223 | + public static function action_buttons() { |
|
| 1224 | 1224 | |
| 1225 | - global $post, $current_user; |
|
| 1225 | + global $post, $current_user; |
|
| 1226 | 1226 | |
| 1227 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1228 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1229 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1230 | - $show_actions = true; |
|
| 1231 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1227 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1228 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1229 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1230 | + $show_actions = true; |
|
| 1231 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1232 | 1232 | |
| 1233 | - //setup quiz grade |
|
| 1234 | - $user_quiz_grade = ''; |
|
| 1235 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1236 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | - } |
|
| 1233 | + //setup quiz grade |
|
| 1234 | + $user_quiz_grade = ''; |
|
| 1235 | + if( ! empty( $user_lesson_status ) ){ |
|
| 1236 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | 1239 | |
| 1240 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1240 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1241 | 1241 | |
| 1242 | - // If the user hasn't completed the prereq then hide the current actions |
|
| 1243 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1242 | + // If the user hasn't completed the prereq then hide the current actions |
|
| 1243 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1244 | 1244 | |
| 1245 | - } |
|
| 1246 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1245 | + } |
|
| 1246 | + if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1247 | 1247 | |
| 1248 | - // Get Reset Settings |
|
| 1249 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1248 | + // Get Reset Settings |
|
| 1249 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1250 | 1250 | |
| 1251 | 1251 | <!-- Action Nonce's --> |
| 1252 | 1252 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1273,55 +1273,55 @@ discard block |
||
| 1273 | 1273 | |
| 1274 | 1274 | <?php } |
| 1275 | 1275 | |
| 1276 | - } // End sensei_quiz_action_buttons() |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Fetch the quiz grade |
|
| 1280 | - * |
|
| 1281 | - * @since 1.9.0 |
|
| 1282 | - * |
|
| 1283 | - * @param int $lesson_id |
|
| 1284 | - * @param int $user_id |
|
| 1285 | - * |
|
| 1286 | - * @return double $user_quiz_grade |
|
| 1287 | - */ |
|
| 1288 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1289 | - |
|
| 1290 | - // get the quiz grade |
|
| 1291 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1292 | - $user_quiz_grade = 0; |
|
| 1293 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1294 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - return (double) $user_quiz_grade; |
|
| 1298 | - |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - /** |
|
| 1302 | - * Check the quiz reset property for a given lesson's quiz. |
|
| 1303 | - * |
|
| 1304 | - * The data is stored on the quiz but going forward the quiz post |
|
| 1305 | - * type will be retired, hence the lesson_id is a require parameter. |
|
| 1306 | - * |
|
| 1307 | - * @since 1.9.0 |
|
| 1308 | - * |
|
| 1309 | - * @param int $lesson_id |
|
| 1310 | - * @return bool |
|
| 1311 | - */ |
|
| 1312 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1313 | - |
|
| 1314 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1315 | - |
|
| 1316 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1317 | - //backwards compatibility |
|
| 1318 | - if( 'on' == $reset_allowed ) { |
|
| 1319 | - $reset_allowed = 1; |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - return (bool) $reset_allowed; |
|
| 1323 | - |
|
| 1324 | - } |
|
| 1276 | + } // End sensei_quiz_action_buttons() |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Fetch the quiz grade |
|
| 1280 | + * |
|
| 1281 | + * @since 1.9.0 |
|
| 1282 | + * |
|
| 1283 | + * @param int $lesson_id |
|
| 1284 | + * @param int $user_id |
|
| 1285 | + * |
|
| 1286 | + * @return double $user_quiz_grade |
|
| 1287 | + */ |
|
| 1288 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1289 | + |
|
| 1290 | + // get the quiz grade |
|
| 1291 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1292 | + $user_quiz_grade = 0; |
|
| 1293 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1294 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + return (double) $user_quiz_grade; |
|
| 1298 | + |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + /** |
|
| 1302 | + * Check the quiz reset property for a given lesson's quiz. |
|
| 1303 | + * |
|
| 1304 | + * The data is stored on the quiz but going forward the quiz post |
|
| 1305 | + * type will be retired, hence the lesson_id is a require parameter. |
|
| 1306 | + * |
|
| 1307 | + * @since 1.9.0 |
|
| 1308 | + * |
|
| 1309 | + * @param int $lesson_id |
|
| 1310 | + * @return bool |
|
| 1311 | + */ |
|
| 1312 | + public static function is_reset_allowed( $lesson_id ){ |
|
| 1313 | + |
|
| 1314 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1315 | + |
|
| 1316 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1317 | + //backwards compatibility |
|
| 1318 | + if( 'on' == $reset_allowed ) { |
|
| 1319 | + $reset_allowed = 1; |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + return (bool) $reset_allowed; |
|
| 1323 | + |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | 1326 | } // End Class WooThemes_Sensei_Quiz |
| 1327 | 1327 | |