| @@ -7,37 +7,28 @@ | ||
| 7 | 7 | * @version 1.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | use LearnPress\Helpers\Template; |
| 11 | +use LearnPress\Models\CourseModel; | |
| 12 | +use LearnPress\Models\CoursePostModel; | |
| 13 | +use LearnPress\Models\UserItems\UserCourseModel; | |
| 14 | +use LearnPress\Models\UserModel; | |
| 15 | +use LearnPress\TemplateHooks\Course\CourseMaterialTemplate; | |
| 16 | +use LearnPress\TemplateHooks\Course\SingleCourseTemplate; | |
| 11 | 17 | |
| 12 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | 19 | exit; |
| 14 | 20 | } |
| 15 | 21 | |
| 16 | -/** | |
| 17 | - * @see LP_Template_Course::button_retry() | |
| 18 | - * @see LP_Template_Course::course_continue_button() | |
| 19 | - * @see LP_Template_Course::course_external_button() | |
| 20 | - */ | |
| 21 | 22 | if ( ! function_exists( 'learn_press_add_course_buttons' ) ) { |
| 22 | 23 | function learn_press_add_course_buttons() { |
| 23 | - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_enroll_button' ), 5 ); | |
| 24 | - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_purchase_button' ), 10 ); | |
| 25 | - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_external_button' ), 15 ); | |
| 26 | - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'button_retry' ), 20 ); | |
| 27 | - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_continue_button' ), 25 ); | |
| 28 | - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_finish_button' ), 30 ); | |
| 24 | + _deprecated_function( __FUNCTION__, '4.3.2.4' ); | |
| 29 | 25 | } |
| 30 | 26 | } |
| 31 | 27 | |
| 32 | 28 | if ( ! function_exists( 'learn_press_remove_course_buttons' ) ) { |
| 33 | 29 | function learn_press_remove_course_buttons() { |
| 34 | - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_enroll_button' ), 5 ); | |
| 35 | - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_purchase_button' ), 10 ); | |
| 36 | - //remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_external_button' ), 15 ); | |
| 37 | - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'button_retry' ), 20 ); | |
| 38 | - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_continue_button' ), 25 ); | |
| 39 | - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_finish_button' ), 30 ); | |
| 30 | + _deprecated_function( __FUNCTION__, '4.3.2.4' ); | |
| 40 | 31 | } |
| 41 | 32 | } |
| 42 | 33 | |
| 43 | 34 | if ( ! function_exists( 'learn_press_get_course_tabs' ) ) { |
| @@ -44,83 +35,93 @@ | ||
| 44 | 35 | /** |
| 45 | 36 | * Return an array of tabs display in single course page. |
| 46 | 37 | * |
| 47 | 38 | * @return array |
| 39 | + * @throws Exception | |
| 48 | 40 | */ |
| 49 | 41 | function learn_press_get_course_tabs() { |
| 50 | - $course = learn_press_get_course(); | |
| 51 | - $user = learn_press_get_current_user(); | |
| 42 | + $courseModel = CourseModel::find( get_the_ID(), true ); | |
| 43 | + if ( ! $courseModel ) { | |
| 44 | + return []; | |
| 45 | + } | |
| 52 | 46 | |
| 53 | - $defaults = array(); | |
| 47 | + $userModel = UserModel::find( get_current_user_id(), true ); | |
| 54 | 48 | |
| 55 | - /** | |
| 56 | - * Show tab overview if | |
| 57 | - * 1. Course is preview | |
| 58 | - * OR | |
| 59 | - * 2. Course's content not empty | |
| 60 | - */ | |
| 61 | - if ( isset( $_GET['preview'] ) || $course ) { | |
| 62 | - $defaults['overview'] = array( | |
| 63 | - 'title' => esc_html__( 'Overview', 'learnpress' ), | |
| 64 | - 'priority' => 10, | |
| 65 | - 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/overview.php' ), | |
| 66 | - ); | |
| 67 | - } | |
| 68 | - | |
| 69 | - $defaults['curriculum'] = array( | |
| 49 | + $defaults = []; | |
| 50 | + $defaults['overview'] = [ | |
| 51 | + 'title' => esc_html__( 'Overview', 'learnpress' ), | |
| 52 | + 'priority' => 10, | |
| 53 | + 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/overview.php' ), | |
| 54 | + ]; | |
| 55 | + $defaults['curriculum'] = [ | |
| 70 | 56 | 'title' => esc_html__( 'Curriculum', 'learnpress' ), |
| 71 | 57 | 'priority' => 30, |
| 72 | - 'callback' => LearnPress::instance()->template( 'course' )->func( 'course_curriculum' ), | |
| 73 | - ); | |
| 74 | - | |
| 75 | - $defaults['instructor'] = array( | |
| 58 | + 'callback' => function () use ( $courseModel, $userModel ) { | |
| 59 | + $singleCourseTemplate = SingleCourseTemplate::instance(); | |
| 60 | + echo $singleCourseTemplate->html_curriculum( $courseModel, $userModel ); | |
| 61 | + }, | |
| 62 | + ]; | |
| 63 | + $defaults['instructor'] = [ | |
| 76 | 64 | 'title' => esc_html__( 'Instructor', 'learnpress' ), |
| 77 | 65 | 'priority' => 40, |
| 78 | 66 | 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/instructor.php' ), |
| 79 | - ); | |
| 67 | + ]; | |
| 80 | 68 | |
| 81 | - if ( $course->get_faqs() ) { | |
| 82 | - $defaults['faqs'] = array( | |
| 69 | + $faq = $courseModel->get_meta_value_by_key( CoursePostModel::META_KEY_FAQS, [] ); | |
| 70 | + if ( ! empty( $faq ) ) { | |
| 71 | + $defaults['faqs'] = [ | |
| 83 | 72 | 'title' => esc_html__( 'FAQs', 'learnpress' ), |
| 84 | 73 | 'priority' => 50, |
| 85 | - 'callback' => LearnPress::instance()->template( 'course' )->func( 'faqs' ), | |
| 86 | - ); | |
| 74 | + 'callback' => function () use ( $courseModel ) { | |
| 75 | + $singleCourseTemplate = SingleCourseTemplate::instance(); | |
| 76 | + echo $singleCourseTemplate->html_faqs( $courseModel, [ 'show_heading' => false ] ); | |
| 77 | + }, | |
| 78 | + ]; | |
| 87 | 79 | } |
| 88 | 80 | |
| 89 | - $tabs = apply_filters( 'learn-press/course-tabs', $defaults ); | |
| 81 | + $singleCourseTemplate = SingleCourseTemplate::instance(); | |
| 82 | + $html_material = $singleCourseTemplate->html_material( $courseModel, $userModel, [ 'show_heading' => false ] ); | |
| 83 | + if ( ! empty( $html_material ) ) { | |
| 84 | + $defaults['materials'] = [ | |
| 85 | + 'title' => esc_html__( 'Materials', 'learnpress' ), | |
| 86 | + 'priority' => 45, | |
| 87 | + 'callback' => function () use ( $html_material ) { | |
| 88 | + echo $html_material; | |
| 89 | + }, | |
| 90 | + ]; | |
| 91 | + } | |
| 90 | 92 | |
| 91 | - if ( $tabs ) { | |
| 92 | - uasort( $tabs, 'learn_press_sort_list_by_priority_callback' ); | |
| 93 | - $request_tab = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ?? '' ); | |
| 94 | - $has_active = false; | |
| 93 | + // @since 4.2.8.7.1 update new parameter $courseModel | |
| 94 | + $tabs = apply_filters( 'learn-press/course-tabs', $defaults, $courseModel ); | |
| 95 | 95 | |
| 96 | + if ( ! empty( $tabs ) ) { | |
| 97 | + $has_tab_active = false; | |
| 98 | + | |
| 99 | + // sort tabs by priority, from low to high | |
| 100 | + uasort( | |
| 101 | + $tabs, | |
| 102 | + function ( $a, $b ) { | |
| 103 | + $priority1 = $a['priority'] ?? 1; | |
| 104 | + $priority2 = $b['priority'] ?? 2; | |
| 105 | + | |
| 106 | + return ( $priority1 < $priority2 ) ? - 1 : 1; | |
| 107 | + } | |
| 108 | + ); | |
| 109 | + | |
| 96 | 110 | foreach ( $tabs as $k => $v ) { |
| 97 | - $v['id'] = ! empty( $v['id'] ) ? $v['id'] : 'tab-' . $k; | |
| 111 | + $v['id'] = $v['id'] ?? 'tab-' . $k; | |
| 112 | + if ( ! empty( $v['active'] ) ) { | |
| 113 | + $has_tab_active = true; | |
| 114 | + } | |
| 98 | 115 | |
| 99 | - if ( $request_tab === $v['id'] ) { | |
| 100 | - $v['active'] = true; | |
| 101 | - $has_active = $k; | |
| 102 | - } elseif ( isset( $v['active'] ) && $v['active'] ) { | |
| 103 | - $has_active = true; | |
| 104 | - } | |
| 105 | 116 | $tabs[ $k ] = $v; |
| 106 | 117 | } |
| 107 | 118 | |
| 108 | - if ( ! $has_active ) { | |
| 109 | - if ( $course && $user->has_course_status( | |
| 110 | - $course->get_id(), | |
| 111 | - array( | |
| 112 | - 'enrolled', | |
| 113 | - 'finished', | |
| 114 | - ) | |
| 115 | - ) && ! empty( $tabs['curriculum'] ) | |
| 116 | - ) { | |
| 117 | - $tabs['curriculum']['active'] = true; | |
| 118 | - } elseif ( ! empty( $tabs['overview'] ) ) { | |
| 119 | - $tabs['overview']['active'] = true; | |
| 120 | - } else { | |
| 121 | - $keys = array_keys( $tabs ); | |
| 122 | - $first_key = reset( $keys ); | |
| 119 | + // Check if there is no tab active, set first tab active | |
| 120 | + if ( ! $has_tab_active ) { | |
| 121 | + // set first tab active | |
| 122 | + $first_key = array_key_first( $tabs ); | |
| 123 | + if ( $first_key ) { | |
| 123 | 124 | $tabs[ $first_key ]['active'] = true; |
| 124 | 125 | } |
| 125 | 126 | } |
| 126 | 127 | } |
| @@ -239,9 +240,8 @@ | ||
| 239 | 240 | ) |
| 240 | 241 | ); |
| 241 | 242 | } |
| 242 | 243 | } |
| 243 | - | |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | add_filter( 'admin_bar_menu', 'learn_press_content_item_edit_links', 90 ); |
| 247 | 247 | |
| @@ -254,11 +254,10 @@ | ||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $quiz = LP_Global::course_item_quiz(); |
| 257 | 257 | $course = learn_press_get_course(); |
| 258 | - | |
| 258 | + $user = learn_press_get_current_user(); | |
| 259 | 259 | if ( $quiz && $course ) { |
| 260 | - $user = learn_press_get_current_user(); | |
| 261 | 260 | $course_id = $course->get_id(); |
| 262 | 261 | //$user_quiz = $user->get_item_data( $quiz->get_id(), $course_id ); |
| 263 | 262 | |
| 264 | 263 | /*if ( $user_quiz ) { |
| @@ -276,9 +275,9 @@ | ||
| 276 | 275 | 'navigationPosition' => LP_Settings::get_option( 'navigation_position', 'yes' ), |
| 277 | 276 | ); |
| 278 | 277 | } |
| 279 | 278 | |
| 280 | - return $args; | |
| 279 | + return apply_filters( 'learn-press/localize_script/quiz', $args, $user, $course, $quiz ); | |
| 281 | 280 | } |
| 282 | 281 | } |
| 283 | 282 | |
| 284 | 283 | if ( ! function_exists( 'learn_press_single_document_title_parts' ) ) { |
| @@ -314,9 +313,9 @@ | ||
| 314 | 313 | $title['title'] = esc_html__( 'Course Search Results', 'learnpress' ); |
| 315 | 314 | } else { |
| 316 | 315 | $title['title'] = esc_html__( 'Courses', 'learnpress' ); |
| 317 | 316 | } |
| 318 | - } elseif ( learn_press_is_profile() ) { | |
| 317 | + } elseif ( LP_Page_Controller::is_page_profile() ) { | |
| 319 | 318 | $profile = LP_Profile::instance(); |
| 320 | 319 | $tab_slug = $profile->get_current_tab(); |
| 321 | 320 | $tab = $profile->get_tab_at( $tab_slug ); |
| 322 | 321 | $page_id = learn_press_get_page_id( 'profile' ); |
| @@ -345,9 +344,10 @@ | ||
| 345 | 344 | return $title; |
| 346 | 345 | } |
| 347 | 346 | } |
| 348 | 347 | |
| 349 | -if ( ! function_exists( 'learn_press_course_item_class' ) ) { | |
| 348 | +// @deprecated 4.2.7.3 | |
| 349 | +/*if ( ! function_exists( 'learn_press_course_item_class' ) ) { | |
| 350 | 350 | function learn_press_course_item_class( $item_id, $course_id = 0, $class = null ) { |
| 351 | 351 | switch ( get_post_type( $item_id ) ) { |
| 352 | 352 | case 'lp_lesson': |
| 353 | 353 | learn_press_course_lesson_class( $item_id, $course_id, $class ); |
| @@ -356,139 +356,141 @@ | ||
| 356 | 356 | learn_press_course_quiz_class( $item_id, $course_id, $class ); |
| 357 | 357 | break; |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | -} | |
| 360 | +}*/ | |
| 361 | 361 | |
| 362 | -if ( ! function_exists( 'learn_press_course_lesson_class' ) ) { | |
| 363 | - /** | |
| 364 | - * The class of lesson in course curriculum | |
| 365 | - * | |
| 366 | - * @param int $lesson_id | |
| 367 | - * @param int $course_id | |
| 368 | - * @param array|string $class | |
| 369 | - * @param boolean $echo | |
| 370 | - * | |
| 371 | - * @return mixed | |
| 372 | - */ | |
| 373 | - function learn_press_course_lesson_class( $lesson_id = null, $course_id = 0, $class = null, $echo = true ) { | |
| 374 | - $user = learn_press_get_current_user(); | |
| 362 | +// @deprecated 4.2.7.3 | |
| 363 | +//if ( ! function_exists( 'learn_press_course_lesson_class' ) ) { | |
| 364 | +// /** | |
| 365 | +// * The class of lesson in course curriculum | |
| 366 | +// * | |
| 367 | +// * @param int $lesson_id | |
| 368 | +// * @param int $course_id | |
| 369 | +// * @param array|string $class | |
| 370 | +// * @param boolean $echo | |
| 371 | +// * | |
| 372 | +// * @return mixed | |
| 373 | +// */ | |
| 374 | +// function learn_press_course_lesson_class( $lesson_id = null, $course_id = 0, $class = null, $echo = true ) { | |
| 375 | +// $user = learn_press_get_current_user(); | |
| 376 | +// | |
| 377 | +// if ( ! $course_id ) { | |
| 378 | +// $course_id = get_the_ID(); | |
| 379 | +// } | |
| 380 | +// | |
| 381 | +// $course = learn_press_get_course( $course_id ); | |
| 382 | +// if ( ! $course ) { | |
| 383 | +// return ''; | |
| 384 | +// } | |
| 385 | +// | |
| 386 | +// if ( is_string( $class ) && $class ) { | |
| 387 | +// $class = preg_split( '!\s+!', $class ); | |
| 388 | +// } else { | |
| 389 | +// $class = array(); | |
| 390 | +// } | |
| 391 | +// | |
| 392 | +// $classes = array( | |
| 393 | +// 'course-lesson course-item course-item-' . $lesson_id, | |
| 394 | +// ); | |
| 395 | +// | |
| 396 | +// $user = learn_press_get_current_user(); | |
| 397 | +// $status = $user->get_item_status( $lesson_id ); | |
| 398 | +// | |
| 399 | +// if ( $status ) { | |
| 400 | +// $classes[] = "item-has-status item-{$status}"; | |
| 401 | +// } | |
| 402 | +// | |
| 403 | +// if ( $lesson_id && $course->is_current_item( $lesson_id ) ) { | |
| 404 | +// $classes[] = 'item-current'; | |
| 405 | +// } | |
| 406 | +// | |
| 407 | +// if ( learn_press_is_course() ) { | |
| 408 | +// if ( $course->is_free() ) { | |
| 409 | +// $classes[] = 'free-item'; | |
| 410 | +// } | |
| 411 | +// } | |
| 412 | +// | |
| 413 | +// $lesson = LP_Lesson::get_lesson( $lesson_id ); | |
| 414 | +// | |
| 415 | +// if ( $lesson && $lesson->is_preview() ) { | |
| 416 | +// $classes[] = 'preview-item'; | |
| 417 | +// } | |
| 418 | +// | |
| 419 | +// $classes = array_unique( array_merge( $classes, $class ) ); | |
| 420 | +// | |
| 421 | +// if ( $echo ) { | |
| 422 | +// echo 'class="' . implode( ' ', $classes ) . '"'; | |
| 423 | +// } | |
| 424 | +// | |
| 425 | +// return $classes; | |
| 426 | +// } | |
| 427 | +//} | |
| 375 | 428 | |
| 376 | - if ( ! $course_id ) { | |
| 377 | - $course_id = get_the_ID(); | |
| 378 | - } | |
| 429 | +// @deprecated 4.2.7.3 | |
| 430 | +//if ( ! function_exists( 'learn_press_course_quiz_class' ) ) { | |
| 431 | +// /** | |
| 432 | +// * The class of lesson in course curriculum | |
| 433 | +// * | |
| 434 | +// * @param int $quiz_id | |
| 435 | +// * @param int $course_id | |
| 436 | +// * @param string|array $class | |
| 437 | +// * @param boolean $echo | |
| 438 | +// * | |
| 439 | +// * @return mixed | |
| 440 | +// */ | |
| 441 | +// function learn_press_course_quiz_class( $quiz_id = null, $course_id = 0, $class = null, $echo = true ) { | |
| 442 | +// $user = learn_press_get_current_user(); | |
| 443 | +// | |
| 444 | +// if ( ! $course_id ) { | |
| 445 | +// $course_id = get_the_ID(); | |
| 446 | +// } | |
| 447 | +// | |
| 448 | +// if ( is_string( $class ) && $class ) { | |
| 449 | +// $class = preg_split( '!\s+!', $class ); | |
| 450 | +// } else { | |
| 451 | +// $class = array(); | |
| 452 | +// } | |
| 453 | +// | |
| 454 | +// $course = learn_press_get_course( $course_id ); | |
| 455 | +// | |
| 456 | +// if ( ! $course ) { | |
| 457 | +// return ''; | |
| 458 | +// } | |
| 459 | +// | |
| 460 | +// $classes = array( | |
| 461 | +// 'course-quiz course-item course-item-' . $quiz_id, | |
| 462 | +// ); | |
| 463 | +// | |
| 464 | +// $status = $user->get_item_status( $quiz_id ); | |
| 465 | +// | |
| 466 | +// if ( $status ) { | |
| 467 | +// $classes[] = "item-has-status item-{$status}"; | |
| 468 | +// } | |
| 469 | +// | |
| 470 | +// if ( $quiz_id && $course->is_current_item( $quiz_id ) ) { | |
| 471 | +// $classes[] = 'item-current'; | |
| 472 | +// } | |
| 473 | +// | |
| 474 | +// /* | |
| 475 | +// if ( $user->can_view_item( $quiz_id, $course_id )->flag ) { | |
| 476 | +// $classes[] = 'viewable'; | |
| 477 | +// }*/ | |
| 478 | +// | |
| 479 | +// if ( $course->get_evaluation_type() == 'evaluate_final_quiz' && $course->is_final_quiz( $quiz_id ) ) { | |
| 480 | +// $classes[] = 'final-quiz'; | |
| 481 | +// } | |
| 482 | +// | |
| 483 | +// $classes = array_unique( array_merge( $classes, $class ) ); | |
| 484 | +// | |
| 485 | +// if ( $echo ) { | |
| 486 | +// echo 'class="' . implode( ' ', $classes ) . '"'; | |
| 487 | +// } | |
| 488 | +// | |
| 489 | +// return $classes; | |
| 490 | +// } | |
| 491 | +//} | |
| 379 | 492 | |
| 380 | - $course = learn_press_get_course( $course_id ); | |
| 381 | - if ( ! $course ) { | |
| 382 | - return ''; | |
| 383 | - } | |
| 384 | - | |
| 385 | - if ( is_string( $class ) && $class ) { | |
| 386 | - $class = preg_split( '!\s+!', $class ); | |
| 387 | - } else { | |
| 388 | - $class = array(); | |
| 389 | - } | |
| 390 | - | |
| 391 | - $classes = array( | |
| 392 | - 'course-lesson course-item course-item-' . $lesson_id, | |
| 393 | - ); | |
| 394 | - | |
| 395 | - $user = learn_press_get_current_user(); | |
| 396 | - $status = $user->get_item_status( $lesson_id ); | |
| 397 | - | |
| 398 | - if ( $status ) { | |
| 399 | - $classes[] = "item-has-status item-{$status}"; | |
| 400 | - } | |
| 401 | - | |
| 402 | - if ( $lesson_id && $course->is_current_item( $lesson_id ) ) { | |
| 403 | - $classes[] = 'item-current'; | |
| 404 | - } | |
| 405 | - | |
| 406 | - if ( learn_press_is_course() ) { | |
| 407 | - if ( $course->is_free() ) { | |
| 408 | - $classes[] = 'free-item'; | |
| 409 | - } | |
| 410 | - } | |
| 411 | - | |
| 412 | - $lesson = LP_Lesson::get_lesson( $lesson_id ); | |
| 413 | - | |
| 414 | - if ( $lesson && $lesson->is_preview() ) { | |
| 415 | - $classes[] = 'preview-item'; | |
| 416 | - } | |
| 417 | - | |
| 418 | - $classes = array_unique( array_merge( $classes, $class ) ); | |
| 419 | - | |
| 420 | - if ( $echo ) { | |
| 421 | - echo 'class="' . implode( ' ', $classes ) . '"'; | |
| 422 | - } | |
| 423 | - | |
| 424 | - return $classes; | |
| 425 | - } | |
| 426 | -} | |
| 427 | - | |
| 428 | -if ( ! function_exists( 'learn_press_course_quiz_class' ) ) { | |
| 429 | - /** | |
| 430 | - * The class of lesson in course curriculum | |
| 431 | - * | |
| 432 | - * @param int $quiz_id | |
| 433 | - * @param int $course_id | |
| 434 | - * @param string|array $class | |
| 435 | - * @param boolean $echo | |
| 436 | - * | |
| 437 | - * @return mixed | |
| 438 | - */ | |
| 439 | - function learn_press_course_quiz_class( $quiz_id = null, $course_id = 0, $class = null, $echo = true ) { | |
| 440 | - $user = learn_press_get_current_user(); | |
| 441 | - | |
| 442 | - if ( ! $course_id ) { | |
| 443 | - $course_id = get_the_ID(); | |
| 444 | - } | |
| 445 | - | |
| 446 | - if ( is_string( $class ) && $class ) { | |
| 447 | - $class = preg_split( '!\s+!', $class ); | |
| 448 | - } else { | |
| 449 | - $class = array(); | |
| 450 | - } | |
| 451 | - | |
| 452 | - $course = learn_press_get_course( $course_id ); | |
| 453 | - | |
| 454 | - if ( ! $course ) { | |
| 455 | - return ''; | |
| 456 | - } | |
| 457 | - | |
| 458 | - $classes = array( | |
| 459 | - 'course-quiz course-item course-item-' . $quiz_id, | |
| 460 | - ); | |
| 461 | - | |
| 462 | - $status = $user->get_item_status( $quiz_id ); | |
| 463 | - | |
| 464 | - if ( $status ) { | |
| 465 | - $classes[] = "item-has-status item-{$status}"; | |
| 466 | - } | |
| 467 | - | |
| 468 | - if ( $quiz_id && $course->is_current_item( $quiz_id ) ) { | |
| 469 | - $classes[] = 'item-current'; | |
| 470 | - } | |
| 471 | - | |
| 472 | - /* | |
| 473 | - if ( $user->can_view_item( $quiz_id, $course_id )->flag ) { | |
| 474 | - $classes[] = 'viewable'; | |
| 475 | - }*/ | |
| 476 | - | |
| 477 | - if ( $course->is_final_quiz( $quiz_id ) ) { | |
| 478 | - $classes[] = 'final-quiz'; | |
| 479 | - } | |
| 480 | - | |
| 481 | - $classes = array_unique( array_merge( $classes, $class ) ); | |
| 482 | - | |
| 483 | - if ( $echo ) { | |
| 484 | - echo 'class="' . implode( ' ', $classes ) . '"'; | |
| 485 | - } | |
| 486 | - | |
| 487 | - return $classes; | |
| 488 | - } | |
| 489 | -} | |
| 490 | - | |
| 491 | 493 | if ( ! function_exists( 'learn_press_course_class' ) ) { |
| 492 | 494 | /** |
| 493 | 495 | * Append new class to course post type |
| 494 | 496 | * |
| @@ -519,15 +521,18 @@ | ||
| 519 | 521 | |
| 520 | 522 | function learn_press_setup_user() { |
| 521 | 523 | $GLOBALS['lp_user'] = learn_press_get_current_user(); |
| 522 | 524 | } |
| 523 | -add_action( 'init', 'learn_press_setup_user', 1000 ); | |
| 524 | 525 | |
| 526 | +//add_action( 'init', 'learn_press_setup_user', 1000 ); | |
| 527 | + | |
| 525 | 528 | /** |
| 526 | 529 | * Display a message immediately with out push into queue |
| 527 | 530 | * |
| 528 | 531 | * @param $message |
| 529 | - * @param string $type | |
| 532 | + * @param string $type | |
| 533 | + * | |
| 534 | + * @Todo tungnx review code. | |
| 530 | 535 | */ |
| 531 | 536 | |
| 532 | 537 | function learn_press_display_message( $message, $type = 'success' ) { |
| 533 | 538 | $messages = learn_press_session_get( learn_press_session_message_id() ); |
| @@ -557,12 +562,14 @@ | ||
| 557 | 562 | |
| 558 | 563 | /** |
| 559 | 564 | * Add new message into queue for displaying. |
| 560 | 565 | * |
| 561 | - * @param string $message | |
| 562 | - * @param string $type | |
| 563 | - * @param array $options | |
| 566 | + * @param string $message | |
| 567 | + * @param string $type | |
| 568 | + * @param array $options | |
| 564 | 569 | * @param int|bool $current_user . @since 3.0.9 - add for current user only |
| 570 | + * | |
| 571 | + * @deprecated 4.2.2.1 | |
| 565 | 572 | */ |
| 566 | 573 | function learn_press_add_message( $message, $type = 'success', $options = array(), $current_user = true ) { |
| 567 | 574 | if ( is_string( $options ) ) { |
| 568 | 575 | $options = array( 'id' => $options ); |
| @@ -607,47 +614,65 @@ | ||
| 607 | 614 | |
| 608 | 615 | /** |
| 609 | 616 | * Set LP message to COOKIE. |
| 610 | 617 | * |
| 611 | - * @param array $message_data | |
| 618 | + * @param array $message_data ['status' => 'success/warning/error', 'content' => 'Message content'] | |
| 619 | + * | |
| 620 | + * @return void | |
| 621 | + * @version 1.0.0 | |
| 612 | 622 | * @since 4.2.0 |
| 613 | - * @version 1.0.0 | |
| 614 | - * @return void | |
| 615 | 623 | */ |
| 616 | 624 | function learn_press_set_message( array $message_data = [] ) { |
| 617 | 625 | if ( ! isset( $message_data ['status'] ) ) { |
| 618 | 626 | error_log( 'Message data must have status' ); |
| 627 | + | |
| 619 | 628 | return; |
| 620 | 629 | } |
| 621 | 630 | if ( ! isset( $message_data ['content'] ) ) { |
| 622 | 631 | error_log( 'Message data must have content' ); |
| 632 | + | |
| 623 | 633 | return; |
| 624 | 634 | } |
| 625 | 635 | |
| 626 | - // Set cookie for lp-message, allow get,set cookie on js. | |
| 627 | - add_option( 'lp-message', $message_data ); | |
| 636 | + $customer_id = LP_Session_Handler::instance()->get_customer_id(); | |
| 637 | + $customer_message = [ $customer_id => $message_data ]; | |
| 638 | + update_option( 'lp-customer-message', $customer_message ); | |
| 628 | 639 | } |
| 629 | 640 | |
| 630 | 641 | /** |
| 631 | 642 | * Show message only one time. |
| 643 | + * @return void | |
| 644 | + * @version 1.0.1 | |
| 632 | 645 | * @since 4.2.0 |
| 633 | - * @version 1.0.0 | |
| 634 | - * @return void | |
| 635 | 646 | */ |
| 636 | 647 | function learn_press_show_message() { |
| 637 | 648 | try { |
| 638 | - $message_data = get_option( 'lp-message' ); | |
| 639 | - delete_option( 'lp-message' ); | |
| 640 | - Template::instance()->get_frontend_template( 'global/lp-message.php', compact( 'message_data' ) ); | |
| 649 | + $customer_id = LP_Session_Handler::instance()->get_customer_id(); | |
| 650 | + $message_data = get_option( 'lp-customer-message' ) ?? []; | |
| 651 | + $customer_message = $message_data[ $customer_id ] ?? ''; | |
| 652 | + if ( ! $customer_message ) { | |
| 653 | + return; | |
| 654 | + } | |
| 655 | + | |
| 656 | + unset( $message_data[ $customer_id ] ); | |
| 657 | + update_option( 'lp-customer-message', $message_data ); | |
| 658 | + //delete_option( 'lp-message' ); | |
| 659 | + //Template::instance()->get_frontend_template( 'global/lp-message.php', compact( 'customer_message' ) ); | |
| 660 | + Template::print_message( | |
| 661 | + $customer_message['content'] ?? '', | |
| 662 | + $customer_message['status'] ?? '' | |
| 663 | + ); | |
| 641 | 664 | } catch ( Throwable $e ) { |
| 642 | 665 | error_log( $e->getMessage() ); |
| 643 | 666 | } |
| 644 | 667 | } |
| 645 | 668 | |
| 669 | +add_action( 'learn-press/before-course-item-content', 'learn_press_show_message', 50 ); | |
| 670 | + | |
| 646 | 671 | /** |
| 647 | 672 | * Remove message added into queue by id and/or type. |
| 648 | 673 | * |
| 649 | - * @param string $id | |
| 674 | + * @param string $id | |
| 650 | 675 | * @param string|array $type |
| 651 | 676 | * |
| 652 | 677 | * @since 3.0.0 |
| 653 | 678 | */ |
| @@ -698,48 +723,12 @@ | ||
| 698 | 723 | learn_press_session_set( learn_press_session_message_id(), array() ); |
| 699 | 724 | } |
| 700 | 725 | } |
| 701 | 726 | |
| 702 | -/** | |
| 703 | - * @deprecated 4.2.0 | |
| 704 | - */ | |
| 705 | -function learn_press_message_count( $type = '' ) { | |
| 706 | - _deprecated_function( __FUNCTION__, '4.2.0' ); | |
| 707 | - $count = 0; | |
| 708 | - $messages = learn_press_session_get( learn_press_session_message_id(), array() ); | |
| 709 | - | |
| 710 | - if ( isset( $messages[ $type ] ) ) { | |
| 711 | - $count = absint( sizeof( $messages[ $type ] ) ); | |
| 712 | - } elseif ( empty( $type ) ) { | |
| 713 | - foreach ( $messages as $message ) { | |
| 714 | - $count += absint( sizeof( $message ) ); | |
| 715 | - } | |
| 716 | - } | |
| 717 | - | |
| 718 | - return $count; | |
| 719 | -} | |
| 720 | - | |
| 721 | 727 | function learn_press_session_message_id() { |
| 722 | 728 | return 'messages' . get_current_user_id(); |
| 723 | 729 | } |
| 724 | 730 | |
| 725 | -/** | |
| 726 | - * Displays messages before main content | |
| 727 | - * | |
| 728 | - * @deprecated 4.2.0 | |
| 729 | - */ | |
| 730 | -function _learn_press_print_messages() { | |
| 731 | - //_deprecated_function( __FUNCTION__, '4.2.0' ); | |
| 732 | - $item = LP_Global::course_item(); | |
| 733 | - if ( ( 'learn_press_before_main_content' == current_action() ) && $item ) { | |
| 734 | - return; | |
| 735 | - } | |
| 736 | - learn_press_print_messages( true ); | |
| 737 | -} | |
| 738 | - | |
| 739 | -//add_action( 'learn_press_before_main_content', '_learn_press_print_messages', 50 ); | |
| 740 | -add_action( 'learn-press/before-course-item-content', 'learn_press_show_message', 50 ); | |
| 741 | - | |
| 742 | 731 | if ( ! function_exists( 'learn_press_page_title' ) ) { |
| 743 | 732 | |
| 744 | 733 | /** |
| 745 | 734 | * learn_press_page_title function. |
| @@ -744,8 +733,9 @@ | ||
| 744 | 733 | /** |
| 745 | 734 | * learn_press_page_title function. |
| 746 | 735 | * |
| 747 | 736 | * @param boolean $echo |
| 737 | + * | |
| 748 | 738 | * @return string |
| 749 | 739 | */ |
| 750 | 740 | function learn_press_page_title( bool $echo = false ): string { |
| 751 | 741 | $page_title = ''; |
| @@ -831,9 +821,9 @@ | ||
| 831 | 821 | /** |
| 832 | 822 | * Get other templates passing attributes and including the file. |
| 833 | 823 | * |
| 834 | 824 | * @param string $template_name . |
| 835 | - * @param array $args (default: array()) . | |
| 825 | + * @param array $args (default: array()) . | |
| 836 | 826 | * @param string $template_path (default: ''). |
| 837 | 827 | * @param string $default_path (default: ''). |
| 838 | 828 | * |
| 839 | 829 | * @return void |
| @@ -883,11 +873,11 @@ | ||
| 883 | 873 | /** |
| 884 | 874 | * Get template content |
| 885 | 875 | * |
| 886 | 876 | * @param $template_name |
| 887 | - * @param array $args | |
| 888 | - * @param string $template_path | |
| 889 | - * @param string $default_path | |
| 877 | + * @param array $args | |
| 878 | + * @param string $template_path | |
| 879 | + * @param string $default_path | |
| 890 | 880 | * |
| 891 | 881 | * @return string |
| 892 | 882 | * @uses learn_press_get_template(); |
| 893 | 883 | */ |
| @@ -1006,9 +996,9 @@ | ||
| 1006 | 996 | /** |
| 1007 | 997 | * Find a full path of a view and display the content in admin |
| 1008 | 998 | * |
| 1009 | 999 | * @param $name |
| 1010 | - * @param array $args | |
| 1000 | + * @param array $args | |
| 1011 | 1001 | * @param bool|false $include_once |
| 1012 | 1002 | * @param bool |
| 1013 | 1003 | * |
| 1014 | 1004 | * @return bool |
| @@ -1045,10 +1035,14 @@ | ||
| 1045 | 1035 | |
| 1046 | 1036 | if ( ! function_exists( 'learn_press_is_404' ) ) { |
| 1047 | 1037 | /** |
| 1048 | 1038 | * Set header is 404 |
| 1039 | + * @deprecated 4.2.8 | |
| 1049 | 1040 | */ |
| 1050 | 1041 | function learn_press_is_404() { |
| 1042 | + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' ); | |
| 1043 | + | |
| 1044 | + return; | |
| 1051 | 1045 | global $wp_query; |
| 1052 | 1046 | $wp_query->set_404(); |
| 1053 | 1047 | status_header( 404 ); |
| 1054 | 1048 | } |
| @@ -1056,10 +1050,15 @@ | ||
| 1056 | 1050 | |
| 1057 | 1051 | if ( ! function_exists( 'learn_press_404_page' ) ) { |
| 1058 | 1052 | /** |
| 1059 | 1053 | * Display 404 page |
| 1054 | + * | |
| 1055 | + * @deprecated 4.2.8 | |
| 1060 | 1056 | */ |
| 1061 | 1057 | function learn_press_404_page() { |
| 1058 | + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' ); | |
| 1059 | + | |
| 1060 | + return; | |
| 1062 | 1061 | learn_press_is_404(); |
| 1063 | 1062 | } |
| 1064 | 1063 | } |
| 1065 | 1064 | |
| @@ -1115,15 +1114,18 @@ | ||
| 1115 | 1114 | } |
| 1116 | 1115 | } |
| 1117 | 1116 | } |
| 1118 | 1117 | |
| 1119 | -if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) { | |
| 1118 | +/** | |
| 1119 | + * @deprecated 4.4.5 | |
| 1120 | + */ | |
| 1121 | +/*if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) { | |
| 1120 | 1122 | function learn_press_sort_course_tabs( $tabs = array() ) { |
| 1121 | 1123 | uasort( $tabs, 'learn_press_sort_list_by_priority_callback' ); |
| 1122 | 1124 | |
| 1123 | 1125 | return $tabs; |
| 1124 | 1126 | } |
| 1125 | -} | |
| 1127 | +}*/ | |
| 1126 | 1128 | |
| 1127 | 1129 | if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) { |
| 1128 | 1130 | /** |
| 1129 | 1131 | * Get Display name publicly as in Profile page |
| @@ -1152,51 +1154,8 @@ | ||
| 1152 | 1154 | return $info ? $info->display_name : ''; |
| 1153 | 1155 | } |
| 1154 | 1156 | } |
| 1155 | 1157 | |
| 1156 | -/** | |
| 1157 | - * @deprecated 4.1.6.9 | |
| 1158 | - */ | |
| 1159 | -/*if ( ! function_exists( 'learn_press_content_item_comments' ) ) { | |
| 1160 | - function learn_press_content_item_comments() { | |
| 1161 | - $item = LP_Global::course_item(); | |
| 1162 | - | |
| 1163 | - if ( ! $item ) { | |
| 1164 | - return; | |
| 1165 | - } | |
| 1166 | - | |
| 1167 | - if ( ! $item->is_support( 'comments' ) ) { | |
| 1168 | - return; | |
| 1169 | - } | |
| 1170 | - | |
| 1171 | - global $post; | |
| 1172 | - | |
| 1173 | - $post = get_post( $item->get_id() ); | |
| 1174 | - | |
| 1175 | - setup_postdata( $post ); | |
| 1176 | - | |
| 1177 | - if ( ! have_comments() ) { | |
| 1178 | - return; | |
| 1179 | - } | |
| 1180 | - | |
| 1181 | - add_filter( 'deprecated_file_trigger_error', '__return_false' ); | |
| 1182 | - comments_template(); | |
| 1183 | - remove_filter( 'deprecated_file_trigger_error', '__return_false' ); | |
| 1184 | - | |
| 1185 | - wp_reset_postdata(); | |
| 1186 | - } | |
| 1187 | -}*/ | |
| 1188 | - | |
| 1189 | -function learn_press_course_comments_open( $open, $post_id ) { | |
| 1190 | - $post = get_post( $post_id ); | |
| 1191 | - | |
| 1192 | - if ( LP_COURSE_CPT == $post->post_type ) { | |
| 1193 | - $open = false; | |
| 1194 | - } | |
| 1195 | - | |
| 1196 | - return $open; | |
| 1197 | -} | |
| 1198 | - | |
| 1199 | 1158 | function learn_press_is_content_item_only() { |
| 1200 | 1159 | return ! empty( $_REQUEST['content-item-only'] ); |
| 1201 | 1160 | } |
| 1202 | 1161 | |
| @@ -1208,74 +1167,16 @@ | ||
| 1208 | 1167 | <?php |
| 1209 | 1168 | } |
| 1210 | 1169 | |
| 1211 | 1170 | /** |
| 1212 | - * @deprecated 4.1.6.4 | |
| 1213 | - */ | |
| 1214 | -function learn_press_get_course_redirect( $link ) { | |
| 1215 | - _deprecated_function( __FUNCTION__, '4.1.6.4' ); | |
| 1216 | - if ( empty( $_SERVER['HTTP_REFERER'] ) ) { | |
| 1217 | - return $link; | |
| 1218 | - } | |
| 1219 | - | |
| 1220 | - $referer = $_SERVER['HTTP_REFERER']; | |
| 1221 | - $info_a = parse_url( $referer ); | |
| 1222 | - $info_b = parse_url( $link ); | |
| 1223 | - | |
| 1224 | - $a = explode( '/', $info_a['path'] ); | |
| 1225 | - $a = array_filter( $a ); | |
| 1226 | - | |
| 1227 | - $b = explode( '/', $info_b['path'] ); | |
| 1228 | - $b = array_filter( $b ); | |
| 1229 | - | |
| 1230 | - $same = array_intersect_assoc( $a, $b ); | |
| 1231 | - | |
| 1232 | - $a = array_diff_assoc( $a, $same ); | |
| 1233 | - $b = array_diff_assoc( $b, $same ); | |
| 1234 | - | |
| 1235 | - $a = array_values( $a ); | |
| 1236 | - $b = array_values( $b ); | |
| 1237 | - | |
| 1238 | - if ( array_shift( $a ) === 'popup' ) { | |
| 1239 | - unset( $a[0] ); | |
| 1240 | - | |
| 1241 | - if ( ! ( array_diff_assoc( $a, $b ) ) ) { | |
| 1242 | - $link = ''; | |
| 1243 | - foreach ( array( 'scheme', 'host', 'port', 'path' ) as $v ) { | |
| 1244 | - if ( ! isset( $info_a[ $v ] ) ) { | |
| 1245 | - continue; | |
| 1246 | - } | |
| 1247 | - | |
| 1248 | - if ( $v == 'scheme' ) { | |
| 1249 | - $sep = '://'; | |
| 1250 | - } elseif ( $v == 'host' ) { | |
| 1251 | - $sep = ''; | |
| 1252 | - } elseif ( $v == 'port' ) { | |
| 1253 | - $link .= ':'; | |
| 1254 | - $sep = ''; | |
| 1255 | - } else { | |
| 1256 | - $sep = '/'; | |
| 1257 | - } | |
| 1258 | - $link = $link . $info_a[ $v ] . $sep; | |
| 1259 | - } | |
| 1260 | - | |
| 1261 | - if ( ! empty( $info_b['query'] ) ) { | |
| 1262 | - $link .= '?' . $info_b['query']; | |
| 1263 | - } | |
| 1264 | - | |
| 1265 | - if ( ! empty( $info_b['fragment'] ) ) { | |
| 1266 | - $link .= '#' . $info_b['fragment']; | |
| 1267 | - } | |
| 1268 | - } | |
| 1269 | - } | |
| 1270 | - | |
| 1271 | - return $link; | |
| 1272 | -} | |
| 1273 | - | |
| 1274 | -/** | |
| 1275 | 1171 | * @param LP_Quiz $item |
| 1172 | + * | |
| 1173 | + * @deprecated 4.2.3.5 | |
| 1276 | 1174 | */ |
| 1277 | 1175 | function learn_press_quiz_meta_final( $item ) { |
| 1176 | + _deprecated_function( __METHOD__, '4.2.3.5' ); | |
| 1177 | + | |
| 1178 | + return; | |
| 1278 | 1179 | $course = learn_press_get_course(); |
| 1279 | 1180 | |
| 1280 | 1181 | if ( ! $course->is_final_quiz( $item->get_id() ) ) { |
| 1281 | 1182 | return; |
| @@ -1292,40 +1193,58 @@ | ||
| 1292 | 1193 | |
| 1293 | 1194 | return $comment_args; |
| 1294 | 1195 | } |
| 1295 | 1196 | |
| 1296 | -if ( ! function_exists( 'learn_press_filter_get_comments_number' ) ) { | |
| 1297 | - function learn_press_filter_get_comments_number( $count, $post_id = 0 ) { | |
| 1298 | - global $wpdb; | |
| 1197 | +add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' ); | |
| 1299 | 1198 | |
| 1300 | - if ( ! $post_id ) { | |
| 1301 | - $post_id = learn_press_get_course_id(); | |
| 1302 | - } | |
| 1199 | +function learn_press_comment_form_logged_in( $html_login ) { | |
| 1200 | + if ( get_post_type() == LP_COURSE_CPT || get_post_type() == LP_LESSON_CPT ) { | |
| 1201 | + $html_login = ''; | |
| 1202 | + } | |
| 1303 | 1203 | |
| 1204 | + return $html_login; | |
| 1205 | +} | |
| 1206 | + | |
| 1207 | +add_filter( 'comment_form_logged_in', 'learn_press_comment_form_logged_in' ); | |
| 1208 | + | |
| 1209 | +function learn_press_comment_form_defaults( $defaults ) { | |
| 1210 | + if ( get_post_type() == LP_COURSE_CPT || get_post_type() == LP_LESSON_CPT ) { | |
| 1211 | + $defaults['comment_notes_before'] = ''; | |
| 1212 | + } | |
| 1213 | + | |
| 1214 | + return $defaults; | |
| 1215 | +} | |
| 1216 | + | |
| 1217 | +add_filter( 'comment_form_defaults', 'learn_press_comment_form_defaults' ); | |
| 1218 | + | |
| 1219 | +function learn_press_filter_get_comments_number( $count, $post_id = 0 ) { | |
| 1220 | + global $wpdb; | |
| 1221 | + | |
| 1222 | + if ( ! $post_id ) { | |
| 1223 | + $post_id = get_the_ID(); | |
| 1304 | 1224 | if ( ! $post_id ) { |
| 1305 | 1225 | return $count; |
| 1306 | 1226 | } |
| 1227 | + } | |
| 1307 | 1228 | |
| 1308 | - if ( get_post_type( $post_id ) == LP_COURSE_CPT ) { | |
| 1309 | - $sql = $wpdb->prepare( | |
| 1310 | - ' SELECT count(*) ' | |
| 1311 | - . " FROM {$wpdb->comments} " | |
| 1312 | - . ' WHERE comment_post_ID = %d ' | |
| 1313 | - . ' AND comment_approved = 1 ' | |
| 1314 | - . ' AND comment_type != %s ', | |
| 1315 | - $post_id, | |
| 1316 | - 'review' | |
| 1317 | - ); | |
| 1229 | + if ( get_post_type( $post_id ) == LP_COURSE_CPT ) { | |
| 1230 | + $sql = $wpdb->prepare( | |
| 1231 | + ' SELECT count(*) ' | |
| 1232 | + . " FROM {$wpdb->comments} " | |
| 1233 | + . ' WHERE comment_post_ID = %d ' | |
| 1234 | + . ' AND comment_approved = 1 ' | |
| 1235 | + . ' AND comment_type != %s ', | |
| 1236 | + $post_id, | |
| 1237 | + 'review' | |
| 1238 | + ); | |
| 1318 | 1239 | |
| 1319 | - $count = $wpdb->get_var( $sql ); | |
| 1240 | + $count = $wpdb->get_var( $sql ); | |
| 1241 | + } | |
| 1320 | 1242 | |
| 1321 | - // @since 3.0.0 | |
| 1322 | - $count = apply_filters( 'learn-press/course-comments-number', $count, $post_id ); | |
| 1323 | - } | |
| 1243 | + return $count; | |
| 1244 | +} | |
| 1324 | 1245 | |
| 1325 | - return $count; | |
| 1326 | - } | |
| 1327 | -} | |
| 1246 | +add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' ); | |
| 1328 | 1247 | |
| 1329 | 1248 | /** |
| 1330 | 1249 | * Add custom classes to body tag class name |
| 1331 | 1250 | * |
| @@ -1333,34 +1252,22 @@ | ||
| 1333 | 1252 | * |
| 1334 | 1253 | * @return array |
| 1335 | 1254 | * |
| 1336 | 1255 | * @since 3.0.0 |
| 1256 | + * @Todo tungnx review to remove | |
| 1257 | + * @deprecated 4.2.3 | |
| 1337 | 1258 | */ |
| 1338 | 1259 | function learn_press_body_classes( $classes ) { |
| 1339 | - $pages = learn_press_static_page_ids(); | |
| 1340 | - | |
| 1341 | - if ( $pages ) { | |
| 1342 | - $is_lp_page = false; | |
| 1343 | - settype( $classes, 'array' ); | |
| 1344 | - | |
| 1345 | - foreach ( $pages as $slug => $id ) { | |
| 1346 | - if ( is_page( $id ) ) { | |
| 1347 | - $classes[] = $slug; | |
| 1348 | - $is_lp_page = true; | |
| 1349 | - } | |
| 1350 | - } | |
| 1351 | - | |
| 1352 | - if ( $is_lp_page || is_learnpress() ) { | |
| 1353 | - $classes[] = get_stylesheet(); | |
| 1354 | - $classes[] = 'learnpress'; | |
| 1355 | - $classes[] = 'learnpress-page'; | |
| 1356 | - } | |
| 1260 | + if ( is_learnpress() ) { | |
| 1261 | + $classes[] = get_stylesheet(); | |
| 1262 | + $classes[] = 'learnpress'; | |
| 1263 | + $classes[] = 'learnpress-page'; | |
| 1357 | 1264 | } |
| 1358 | 1265 | |
| 1359 | 1266 | return $classes; |
| 1360 | 1267 | } |
| 1361 | 1268 | |
| 1362 | -add_filter( 'body_class', 'learn_press_body_classes', 10 ); | |
| 1269 | +//add_filter( 'body_class', 'learn_press_body_classes', 10 ); | |
| 1363 | 1270 | |
| 1364 | 1271 | /** |
| 1365 | 1272 | * Return true if user is learning a course |
| 1366 | 1273 | * |
| @@ -1388,61 +1295,8 @@ | ||
| 1388 | 1295 | |
| 1389 | 1296 | return apply_filters( 'lp/is-learning-course', $is_learning, $course_id ); |
| 1390 | 1297 | } |
| 1391 | 1298 | |
| 1392 | -/** | |
| 1393 | - * Output custom css from settings | |
| 1394 | - * | |
| 1395 | - * @since 4.0.0 | |
| 1396 | - */ | |
| 1397 | -if ( ! function_exists( 'learn_press_print_custom_styles' ) ) { | |
| 1398 | - function learn_press_print_custom_styles() { | |
| 1399 | - $primary_color = LP_Settings::instance()->get( 'primary_color' ); | |
| 1400 | - $secondary_color = LP_Settings::instance()->get( 'secondary_color' ); | |
| 1401 | - ?> | |
| 1402 | - | |
| 1403 | - <style id="learn-press-custom-css"> | |
| 1404 | - :root { | |
| 1405 | - --lp-primary-color: <?php echo ! empty( $primary_color ) ? $primary_color : '#ffb606'; ?>; | |
| 1406 | - --lp-secondary-color: <?php echo ! empty( $secondary_color ) ? $secondary_color : '#442e66'; ?>; | |
| 1407 | - } | |
| 1408 | - </style> | |
| 1409 | - | |
| 1410 | - <?php | |
| 1411 | - } | |
| 1412 | - | |
| 1413 | - add_action( 'wp_head', 'learn_press_print_custom_styles' ); | |
| 1414 | -} | |
| 1415 | - | |
| 1416 | -/** | |
| 1417 | - * Return TRUE if current user has already enroll course in single view. | |
| 1418 | - * | |
| 1419 | - * @return bool | |
| 1420 | - * @since 3.0.0 | |
| 1421 | - * @editor tungnx | |
| 1422 | - * @version 4.1.3 | |
| 1423 | - */ | |
| 1424 | -function learn_press_current_user_enrolled_course() { | |
| 1425 | - _deprecated_function( __FUNCTION__, '4.1.3' ); | |
| 1426 | -} | |
| 1427 | - | |
| 1428 | -/** | |
| 1429 | - * Check if an user can access content of a course. | |
| 1430 | - * | |
| 1431 | - * @param int $course_id | |
| 1432 | - * @param int $user_id | |
| 1433 | - * | |
| 1434 | - * @return bool | |
| 1435 | - * @since 3.x.x | |
| 1436 | - * @editor tungnx | |
| 1437 | - * @modify 4.1.3 | |
| 1438 | - * @reason comment - not use | |
| 1439 | - */ | |
| 1440 | - | |
| 1441 | -function learn_press_user_can_access_course( $course_id, $user_id = 0 ) { | |
| 1442 | - _deprecated_function( __FUNCTION__, '4.1.2' ); | |
| 1443 | -} | |
| 1444 | - | |
| 1445 | 1299 | function learn_press_content_item_summary_class( $more = '', $echo = true ) { |
| 1446 | 1300 | $classes = array( 'content-item-summary' ); |
| 1447 | 1301 | $classes = LP_Helper::merge_class( $classes, $more ); |
| 1448 | 1302 | $classes = apply_filters( 'learn-press/content-item-summary-class', $classes ); |
| @@ -1454,9 +1308,13 @@ | ||
| 1454 | 1308 | |
| 1455 | 1309 | return $output; |
| 1456 | 1310 | } |
| 1457 | 1311 | |
| 1312 | +/** | |
| 1313 | + * @deprecated 4.2.3.1 | |
| 1314 | + */ | |
| 1458 | 1315 | function learn_press_content_item_summary_classes( $classes ) { |
| 1316 | + _deprecated_function( __FUNCTION__, '4.2.3.1' ); | |
| 1459 | 1317 | $item = LP_Global::course_item(); |
| 1460 | 1318 | |
| 1461 | 1319 | if ( ! $item ) { |
| 1462 | 1320 | return $classes; |
| @@ -1488,10 +1346,10 @@ | ||
| 1488 | 1346 | function learn_press_courses_layouts() { |
| 1489 | 1347 | return apply_filters( |
| 1490 | 1348 | 'learnpress/archive-courses-layouts', |
| 1491 | 1349 | [ |
| 1492 | - 'grid' => 'Grid', | |
| 1493 | - 'list' => 'List', | |
| 1350 | + 'grid' => __( 'Grid', 'learnpress' ), | |
| 1351 | + 'list' => __( 'List', 'learnpress' ), | |
| 1494 | 1352 | ] |
| 1495 | 1353 | ); |
| 1496 | 1354 | } |
| 1497 | 1355 | |
| @@ -1520,10 +1378,10 @@ | ||
| 1520 | 1378 | 'id' => 'course-sidebar', |
| 1521 | 1379 | 'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ), |
| 1522 | 1380 | 'before_widget' => '<div id="%1$s" class="widget %2$s">', |
| 1523 | 1381 | 'after_widget' => '</div>', |
| 1524 | - 'before_title' => '<h2 class="widgettitle">', | |
| 1525 | - 'after_title' => '</h2>', | |
| 1382 | + 'before_title' => '<h3 class="widget-title">', | |
| 1383 | + 'after_title' => '</h3>', | |
| 1526 | 1384 | ) |
| 1527 | 1385 | ); |
| 1528 | 1386 | register_sidebar( |
| 1529 | 1387 | array( |
| @@ -1531,10 +1389,10 @@ | ||
| 1531 | 1389 | 'id' => 'archive-courses-sidebar', |
| 1532 | 1390 | 'description' => esc_html__( 'Widgets in this area will be shown on all course pages', 'learnpress' ), |
| 1533 | 1391 | 'before_widget' => '<div id="%1$s" class="widget %2$s">', |
| 1534 | 1392 | 'after_widget' => '</div>', |
| 1535 | - 'before_title' => '<h2 class="widgettitle">', | |
| 1536 | - 'after_title' => '</h2>', | |
| 1393 | + 'before_title' => '<h3 class="widget-title">', | |
| 1394 | + 'after_title' => '</h3>', | |
| 1537 | 1395 | ) |
| 1538 | 1396 | ); |
| 1539 | 1397 | } |
| 1540 | 1398 | |
| @@ -1557,9 +1415,9 @@ | ||
| 1557 | 1415 | add_action( 'after_setup_theme', 'learn_press_setup_theme' ); |
| 1558 | 1416 | |
| 1559 | 1417 | /** |
| 1560 | 1418 | * @param LP_Question $question |
| 1561 | - * @param array $args | |
| 1419 | + * @param array $args | |
| 1562 | 1420 | * |
| 1563 | 1421 | * @return array |
| 1564 | 1422 | * @since 4.x.x |
| 1565 | 1423 | */ |
| @@ -1567,9 +1425,9 @@ | ||
| 1567 | 1425 | $args = wp_parse_args( |
| 1568 | 1426 | $args, |
| 1569 | 1427 | array( |
| 1570 | 1428 | 'cryptoJsAes' => false, |
| 1571 | - 'include_is_true' => true, | |
| 1429 | + 'include_is_true' => false, | |
| 1572 | 1430 | 'answer' => false, |
| 1573 | 1431 | ) |
| 1574 | 1432 | ); |
| 1575 | 1433 | |
| @@ -1607,9 +1465,9 @@ | ||
| 1607 | 1465 | |
| 1608 | 1466 | /** |
| 1609 | 1467 | * Get post meta with key _lp_duration and translate. |
| 1610 | 1468 | * |
| 1611 | - * @param int $post_id | |
| 1469 | + * @param int $post_id | |
| 1612 | 1470 | * @param string $default |
| 1613 | 1471 | * |
| 1614 | 1472 | * @return string |
| 1615 | 1473 | * @since 4.0.0 |
| @@ -1674,9 +1532,9 @@ | ||
| 1674 | 1532 | function lp_course_level() { |
| 1675 | 1533 | return apply_filters( |
| 1676 | 1534 | 'lp/template/function/course/level', |
| 1677 | 1535 | array( |
| 1678 | - '' => esc_html__( 'All levels', 'learnpress' ), | |
| 1536 | + 'all' => esc_html__( 'All levels', 'learnpress' ), | |
| 1679 | 1537 | 'beginner' => esc_html__( 'Beginner', 'learnpress' ), |
| 1680 | 1538 | 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ), |
| 1681 | 1539 | 'expert' => esc_html__( 'Expert', 'learnpress' ), |
| 1682 | 1540 | ) |
| @@ -1682,14 +1540,8 @@ | ||
| 1682 | 1540 | ) |
| 1683 | 1541 | ); |
| 1684 | 1542 | } |
| 1685 | 1543 | |
| 1686 | -// function learn_press_is_preview_course() { | |
| 1687 | -// $course_id = isset( $GLOBALS['preview_course'] ) ? $GLOBALS['preview_course'] : 0; | |
| 1688 | -// | |
| 1689 | -// return $course_id && get_post_type( $course_id ) === LP_COURSE_CPT; | |
| 1690 | -// } | |
| 1691 | - | |
| 1692 | 1544 | /** |
| 1693 | 1545 | * Get slug for logout action in user profile. |
| 1694 | 1546 | * |
| 1695 | 1547 | * @return string |
| @@ -1714,9 +1566,9 @@ | ||
| 1714 | 1566 | function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) { |
| 1715 | 1567 | ?> |
| 1716 | 1568 | <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>"> |
| 1717 | 1569 | <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?> |
| 1718 | - <li style="width: <?php echo esc_attr( $width === 'random' ? wp_rand( 60, 100 ) . '%' : $width ); ?>; <?php echo ! empty( $styleli ) ? $styleli : ''; ?>"></li> | |
| 1570 | + <li style="width: <?php echo esc_attr( $width === 'random' ? wp_rand( 90, 100 ) . '%' : $width ); ?>; <?php echo ! empty( $styleli ) ? $styleli : ''; ?>"></li> | |
| 1719 | 1571 | <?php endfor; ?> |
| 1720 | 1572 | </ul> |
| 1721 | 1573 | |
| 1722 | 1574 | <?php |
| @@ -1763,9 +1615,10 @@ | ||
| 1763 | 1615 | if ( is_search() ) { |
| 1764 | 1616 | return; |
| 1765 | 1617 | } |
| 1766 | 1618 | |
| 1767 | - if ( is_post_type_archive( LP_COURSE_CPT ) && in_array( absint( get_query_var( 'paged' ) ), array( 0, 1 ), true ) ) { | |
| 1619 | + if ( is_post_type_archive( LP_COURSE_CPT ) | |
| 1620 | + && in_array( absint( get_query_var( 'paged' ) ), array( 0, 1 ), true ) ) { | |
| 1768 | 1621 | $profile_id = learn_press_get_page_id( 'courses' ); |
| 1769 | 1622 | |
| 1770 | 1623 | if ( $profile_id ) { |
| 1771 | 1624 | $profile_page = get_post( $profile_id ); |
| @@ -1799,41 +1652,35 @@ | ||
| 1799 | 1652 | * |
| 1800 | 1653 | * @return array |
| 1801 | 1654 | */ |
| 1802 | 1655 | function lp_archive_skeleton_get_args(): array { |
| 1803 | - global $post, $wp; | |
| 1656 | + $args = []; | |
| 1804 | 1657 | |
| 1805 | - $args = array(); | |
| 1806 | - | |
| 1807 | 1658 | if ( ! empty( $_GET ) ) { |
| 1808 | - $args = (array) $_GET; | |
| 1659 | + $args = $_GET; | |
| 1809 | 1660 | } |
| 1810 | 1661 | |
| 1811 | - $params = apply_filters( | |
| 1812 | - 'lp/template/archive-course/skeleton/args', | |
| 1813 | - array( | |
| 1814 | - 'paged' => 1, | |
| 1815 | - 'c_search' => '', | |
| 1816 | - 'orderby' => '', | |
| 1817 | - 'order' => '', | |
| 1818 | - ) | |
| 1819 | - ); | |
| 1662 | + global $wp_query; | |
| 1663 | + if ( ! empty( $wp_query->get( 'paged' ) ) ) { | |
| 1664 | + $args['paged'] = $wp_query->get( 'paged' ); | |
| 1665 | + } | |
| 1820 | 1666 | |
| 1821 | 1667 | if ( learn_press_is_course_category() || learn_press_is_course_tag() ) { |
| 1822 | 1668 | $cat = get_queried_object(); |
| 1823 | 1669 | |
| 1824 | - $args['term_id'] = $cat->term_id; | |
| 1825 | - $args['taxonomy'] = $cat->taxonomy; | |
| 1670 | + // Info of page | |
| 1671 | + if ( learn_press_is_course_category() ) { | |
| 1672 | + $args['page_term_id_current'] = $cat->term_id; | |
| 1673 | + } elseif ( learn_press_is_course_tag() ) { | |
| 1674 | + $args['page_tag_id_current'] = $cat->term_id; | |
| 1675 | + } | |
| 1676 | + | |
| 1677 | + $args['page_term_url'] = get_term_link( $cat ); | |
| 1826 | 1678 | } |
| 1827 | 1679 | |
| 1828 | - if ( learn_press_is_course_archive() ) { | |
| 1829 | - foreach ( $params as $key => $param ) { | |
| 1830 | - if ( isset( $_REQUEST[ $key ] ) ) { | |
| 1831 | - $args[ $key ] = LP_Helper::sanitize_params_submitted( $_REQUEST[ $key ] ); | |
| 1832 | - } else { | |
| 1833 | - $args[ $key ] = $param; | |
| 1834 | - } | |
| 1835 | - } | |
| 1680 | + $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args ); | |
| 1681 | + if ( ! is_array( $args ) ) { | |
| 1682 | + $args = []; | |
| 1836 | 1683 | } |
| 1837 | 1684 | |
| 1838 | - return $args; | |
| 1685 | + return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' ); | |
| 1839 | 1686 | } |