PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/lp-template-functions.php +467 -521 4.1.7.24.4.8 View file →
@@ -5,36 +5,30 @@
5 5 * @author ThimPress
6 6 * @package LearnPress/Functions
7 7 * @version 1.0
8 8 */
9 +
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;
17 +
9 18 if ( ! defined( 'ABSPATH' ) ) {
10 19 exit;
11 20 }
12 21
13 -/**
14 - * @see LP_Template_Course::button_retry()
15 - * @see LP_Template_Course::course_continue_button()
16 - * @see LP_Template_Course::course_external_button()
17 - */
18 22 if ( ! function_exists( 'learn_press_add_course_buttons' ) ) {
19 23 function learn_press_add_course_buttons() {
20 - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_enroll_button' ), 5 );
21 - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_purchase_button' ), 10 );
22 - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_external_button' ), 15 );
23 - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'button_retry' ), 20 );
24 - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_continue_button' ), 25 );
25 - add_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_finish_button' ), 30 );
24 + _deprecated_function( __FUNCTION__, '4.3.2.4' );
26 25 }
27 26 }
28 27
29 28 if ( ! function_exists( 'learn_press_remove_course_buttons' ) ) {
30 29 function learn_press_remove_course_buttons() {
31 - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_enroll_button' ), 5 );
32 - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_purchase_button' ), 10 );
33 - //remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_external_button' ), 15 );
34 - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'button_retry' ), 20 );
35 - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_continue_button' ), 25 );
36 - remove_action( 'learn-press/course-buttons', LearnPress::instance()->template( 'course' )->func( 'course_finish_button' ), 30 );
30 + _deprecated_function( __FUNCTION__, '4.3.2.4' );
37 31 }
38 32 }
39 33
40 34 if ( ! function_exists( 'learn_press_get_course_tabs' ) ) {
@@ -41,83 +35,93 @@
41 35 /**
42 36 * Return an array of tabs display in single course page.
43 37 *
44 38 * @return array
39 + * @throws Exception
45 40 */
46 41 function learn_press_get_course_tabs() {
47 - $course = learn_press_get_course();
48 - $user = learn_press_get_current_user();
42 + $courseModel = CourseModel::find( get_the_ID(), true );
43 + if ( ! $courseModel ) {
44 + return [];
45 + }
49 46
50 - $defaults = array();
47 + $userModel = UserModel::find( get_current_user_id(), true );
51 48
52 - /**
53 - * Show tab overview if
54 - * 1. Course is preview
55 - * OR
56 - * 2. Course's content not empty
57 - */
58 - if ( isset( $_GET['preview'] ) || $course ) {
59 - $defaults['overview'] = array(
60 - 'title' => esc_html__( 'Overview', 'learnpress' ),
61 - 'priority' => 10,
62 - 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/overview.php' ),
63 - );
64 - }
65 -
66 - $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'] = [
67 56 'title' => esc_html__( 'Curriculum', 'learnpress' ),
68 57 'priority' => 30,
69 - 'callback' => LearnPress::instance()->template( 'course' )->func( 'course_curriculum' ),
70 - );
71 -
72 - $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'] = [
73 64 'title' => esc_html__( 'Instructor', 'learnpress' ),
74 65 'priority' => 40,
75 66 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/instructor.php' ),
76 - );
67 + ];
77 68
78 - if ( $course->get_faqs() ) {
79 - $defaults['faqs'] = array(
69 + $faq = $courseModel->get_meta_value_by_key( CoursePostModel::META_KEY_FAQS, [] );
70 + if ( ! empty( $faq ) ) {
71 + $defaults['faqs'] = [
80 72 'title' => esc_html__( 'FAQs', 'learnpress' ),
81 73 'priority' => 50,
82 - 'callback' => LearnPress::instance()->template( 'course' )->func( 'faqs' ),
83 - );
74 + 'callback' => function () use ( $courseModel ) {
75 + $singleCourseTemplate = SingleCourseTemplate::instance();
76 + echo $singleCourseTemplate->html_faqs( $courseModel, [ 'show_heading' => false ] );
77 + },
78 + ];
84 79 }
85 80
86 - $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 + }
87 92
88 - if ( $tabs ) {
89 - uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
90 - $request_tab = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ?? '' );
91 - $has_active = false;
93 + // @since 4.2.8.7.1 update new parameter $courseModel
94 + $tabs = apply_filters( 'learn-press/course-tabs', $defaults, $courseModel );
92 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 +
93 110 foreach ( $tabs as $k => $v ) {
94 - $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 + }
95 115
96 - if ( $request_tab === $v['id'] ) {
97 - $v['active'] = true;
98 - $has_active = $k;
99 - } elseif ( isset( $v['active'] ) && $v['active'] ) {
100 - $has_active = true;
101 - }
102 116 $tabs[ $k ] = $v;
103 117 }
104 118
105 - if ( ! $has_active ) {
106 - if ( $course && $user->has_course_status(
107 - $course->get_id(),
108 - array(
109 - 'enrolled',
110 - 'finished',
111 - )
112 - ) && ! empty( $tabs['curriculum'] )
113 - ) {
114 - $tabs['curriculum']['active'] = true;
115 - } elseif ( ! empty( $tabs['overview'] ) ) {
116 - $tabs['overview']['active'] = true;
117 - } else {
118 - $keys = array_keys( $tabs );
119 - $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 ) {
120 124 $tabs[ $first_key ]['active'] = true;
121 125 }
122 126 }
123 127 }
@@ -236,9 +240,8 @@
236 240 )
237 241 );
238 242 }
239 243 }
240 -
241 244 }
242 245 }
243 246 add_filter( 'admin_bar_menu', 'learn_press_content_item_edit_links', 90 );
244 247
@@ -251,19 +254,18 @@
251 254 }
252 255
253 256 $quiz = LP_Global::course_item_quiz();
254 257 $course = learn_press_get_course();
255 -
258 + $user = learn_press_get_current_user();
256 259 if ( $quiz && $course ) {
257 - $user = learn_press_get_current_user();
258 260 $course_id = $course->get_id();
259 - $user_quiz = $user->get_item_data( $quiz->get_id(), $course_id );
261 + //$user_quiz = $user->get_item_data( $quiz->get_id(), $course_id );
260 262
261 - if ( $user_quiz ) {
263 + /*if ( $user_quiz ) {
262 264 $remaining_time = $user_quiz->get_time_remaining();
263 265 } else {
264 266 $remaining_time = false;
265 - }
267 + }*/
266 268
267 269 $args = array(
268 270 'id' => $quiz->get_id(),
269 271 //'totalTime' => -1,
@@ -273,9 +275,9 @@
273 275 'navigationPosition' => LP_Settings::get_option( 'navigation_position', 'yes' ),
274 276 );
275 277 }
276 278
277 - return $args;
279 + return apply_filters( 'learn-press/localize_script/quiz', $args, $user, $course, $quiz );
278 280 }
279 281 }
280 282
281 283 if ( ! function_exists( 'learn_press_single_document_title_parts' ) ) {
@@ -286,8 +288,9 @@
286 288 * @param array $title
287 289 *
288 290 * @return array
289 291 * @since 3.0.0
292 + * @version 3.0.1
290 293 */
291 294 function learn_press_single_document_title_parts( $title ) {
292 295 if ( learn_press_is_course() ) {
293 296 $item = LP_Global::course_item();
@@ -310,9 +313,9 @@
310 313 $title['title'] = esc_html__( 'Course Search Results', 'learnpress' );
311 314 } else {
312 315 $title['title'] = esc_html__( 'Courses', 'learnpress' );
313 316 }
314 - } elseif ( learn_press_is_profile() ) {
317 + } elseif ( LP_Page_Controller::is_page_profile() ) {
315 318 $profile = LP_Profile::instance();
316 319 $tab_slug = $profile->get_current_tab();
317 320 $tab = $profile->get_tab_at( $tab_slug );
318 321 $page_id = learn_press_get_page_id( 'profile' );
@@ -322,9 +325,9 @@
322 325 } else {
323 326 $page_title = '';
324 327 }
325 328
326 - if ( $tab ) {
329 + if ( $tab instanceof LP_Profile_Tab ) {
327 330 $title['title'] = join(
328 331 ' ',
329 332 apply_filters(
330 333 'learn-press/document-profile-title-parts',
@@ -330,9 +333,9 @@
330 333 'learn-press/document-profile-title-parts',
331 334 array(
332 335 $page_title,
333 336 '&rarr;',
334 - $tab['title'],
337 + $tab->get( 'title' ),
335 338 )
336 339 )
337 340 );
338 341 }
@@ -341,9 +344,10 @@
341 344 return $title;
342 345 }
343 346 }
344 347
345 -if ( ! function_exists( 'learn_press_course_item_class' ) ) {
348 +// @deprecated 4.2.7.3
349 +/*if ( ! function_exists( 'learn_press_course_item_class' ) ) {
346 350 function learn_press_course_item_class( $item_id, $course_id = 0, $class = null ) {
347 351 switch ( get_post_type( $item_id ) ) {
348 352 case 'lp_lesson':
349 353 learn_press_course_lesson_class( $item_id, $course_id, $class );
@@ -352,139 +356,141 @@
352 356 learn_press_course_quiz_class( $item_id, $course_id, $class );
353 357 break;
354 358 }
355 359 }
356 -}
360 +}*/
357 361
358 -if ( ! function_exists( 'learn_press_course_lesson_class' ) ) {
359 - /**
360 - * The class of lesson in course curriculum
361 - *
362 - * @param int $lesson_id
363 - * @param int $course_id
364 - * @param array|string $class
365 - * @param boolean $echo
366 - *
367 - * @return mixed
368 - */
369 - function learn_press_course_lesson_class( $lesson_id = null, $course_id = 0, $class = null, $echo = true ) {
370 - $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 +//}
371 428
372 - if ( ! $course_id ) {
373 - $course_id = get_the_ID();
374 - }
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 +//}
375 492
376 - $course = learn_press_get_course( $course_id );
377 - if ( ! $course ) {
378 - return '';
379 - }
380 -
381 - if ( is_string( $class ) && $class ) {
382 - $class = preg_split( '!\s+!', $class );
383 - } else {
384 - $class = array();
385 - }
386 -
387 - $classes = array(
388 - 'course-lesson course-item course-item-' . $lesson_id,
389 - );
390 -
391 - $user = learn_press_get_current_user();
392 - $status = $user->get_item_status( $lesson_id );
393 -
394 - if ( $status ) {
395 - $classes[] = "item-has-status item-{$status}";
396 - }
397 -
398 - if ( $lesson_id && $course->is_current_item( $lesson_id ) ) {
399 - $classes[] = 'item-current';
400 - }
401 -
402 - if ( learn_press_is_course() ) {
403 - if ( $course->is_free() ) {
404 - $classes[] = 'free-item';
405 - }
406 - }
407 -
408 - $lesson = LP_Lesson::get_lesson( $lesson_id );
409 -
410 - if ( $lesson && $lesson->is_preview() ) {
411 - $classes[] = 'preview-item';
412 - }
413 -
414 - $classes = array_unique( array_merge( $classes, $class ) );
415 -
416 - if ( $echo ) {
417 - echo 'class="' . implode( ' ', $classes ) . '"';
418 - }
419 -
420 - return $classes;
421 - }
422 -}
423 -
424 -if ( ! function_exists( 'learn_press_course_quiz_class' ) ) {
425 - /**
426 - * The class of lesson in course curriculum
427 - *
428 - * @param int $quiz_id
429 - * @param int $course_id
430 - * @param string|array $class
431 - * @param boolean $echo
432 - *
433 - * @return mixed
434 - */
435 - function learn_press_course_quiz_class( $quiz_id = null, $course_id = 0, $class = null, $echo = true ) {
436 - $user = learn_press_get_current_user();
437 -
438 - if ( ! $course_id ) {
439 - $course_id = get_the_ID();
440 - }
441 -
442 - if ( is_string( $class ) && $class ) {
443 - $class = preg_split( '!\s+!', $class );
444 - } else {
445 - $class = array();
446 - }
447 -
448 - $course = learn_press_get_course( $course_id );
449 -
450 - if ( ! $course ) {
451 - return '';
452 - }
453 -
454 - $classes = array(
455 - 'course-quiz course-item course-item-' . $quiz_id,
456 - );
457 -
458 - $status = $user->get_item_status( $quiz_id );
459 -
460 - if ( $status ) {
461 - $classes[] = "item-has-status item-{$status}";
462 - }
463 -
464 - if ( $quiz_id && $course->is_current_item( $quiz_id ) ) {
465 - $classes[] = 'item-current';
466 - }
467 -
468 - /*
469 - if ( $user->can_view_item( $quiz_id, $course_id )->flag ) {
470 - $classes[] = 'viewable';
471 - }*/
472 -
473 - if ( $course->is_final_quiz( $quiz_id ) ) {
474 - $classes[] = 'final-quiz';
475 - }
476 -
477 - $classes = array_unique( array_merge( $classes, $class ) );
478 -
479 - if ( $echo ) {
480 - echo 'class="' . implode( ' ', $classes ) . '"';
481 - }
482 -
483 - return $classes;
484 - }
485 -}
486 -
487 493 if ( ! function_exists( 'learn_press_course_class' ) ) {
488 494 /**
489 495 * Append new class to course post type
490 496 *
@@ -515,15 +521,18 @@
515 521
516 522 function learn_press_setup_user() {
517 523 $GLOBALS['lp_user'] = learn_press_get_current_user();
518 524 }
519 -add_action( 'init', 'learn_press_setup_user', 1000 );
520 525
526 +//add_action( 'init', 'learn_press_setup_user', 1000 );
527 +
521 528 /**
522 529 * Display a message immediately with out push into queue
523 530 *
524 531 * @param $message
525 - * @param string $type
532 + * @param string $type
533 + *
534 + * @Todo tungnx review code.
526 535 */
527 536
528 537 function learn_press_display_message( $message, $type = 'success' ) {
529 538 $messages = learn_press_session_get( learn_press_session_message_id() );
@@ -553,12 +562,14 @@
553 562
554 563 /**
555 564 * Add new message into queue for displaying.
556 565 *
557 - * @param string $message
558 - * @param string $type
559 - * @param array $options
566 + * @param string $message
567 + * @param string $type
568 + * @param array $options
560 569 * @param int|bool $current_user . @since 3.0.9 - add for current user only
570 + *
571 + * @deprecated 4.2.2.1
561 572 */
562 573 function learn_press_add_message( $message, $type = 'success', $options = array(), $current_user = true ) {
563 574 if ( is_string( $options ) ) {
564 575 $options = array( 'id' => $options );
@@ -601,11 +612,67 @@
601 612 return $message;
602 613 }
603 614
604 615 /**
616 + * Set LP message to COOKIE.
617 + *
618 + * @param array $message_data ['status' => 'success/warning/error', 'content' => 'Message content']
619 + *
620 + * @return void
621 + * @version 1.0.0
622 + * @since 4.2.0
623 + */
624 +function learn_press_set_message( array $message_data = [] ) {
625 + if ( ! isset( $message_data ['status'] ) ) {
626 + error_log( 'Message data must have status' );
627 +
628 + return;
629 + }
630 + if ( ! isset( $message_data ['content'] ) ) {
631 + error_log( 'Message data must have content' );
632 +
633 + return;
634 + }
635 +
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 );
639 +}
640 +
641 +/**
642 + * Show message only one time.
643 + * @return void
644 + * @version 1.0.1
645 + * @since 4.2.0
646 + */
647 +function learn_press_show_message() {
648 + try {
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 + );
664 + } catch ( Throwable $e ) {
665 + error_log( $e->getMessage() );
666 + }
667 +}
668 +
669 +add_action( 'learn-press/before-course-item-content', 'learn_press_show_message', 50 );
670 +
671 +/**
605 672 * Remove message added into queue by id and/or type.
606 673 *
607 - * @param string $id
674 + * @param string $id
608 675 * @param string|array $type
609 676 *
610 677 * @since 3.0.0
611 678 */
@@ -656,41 +723,12 @@
656 723 learn_press_session_set( learn_press_session_message_id(), array() );
657 724 }
658 725 }
659 726
660 -function learn_press_message_count( $type = '' ) {
661 - $count = 0;
662 - $messages = learn_press_session_get( learn_press_session_message_id(), array() );
663 -
664 - if ( isset( $messages[ $type ] ) ) {
665 - $count = absint( sizeof( $messages[ $type ] ) );
666 - } elseif ( empty( $type ) ) {
667 - foreach ( $messages as $message ) {
668 - $count += absint( sizeof( $message ) );
669 - }
670 - }
671 -
672 - return $count;
673 -}
674 -
675 727 function learn_press_session_message_id() {
676 728 return 'messages' . get_current_user_id();
677 729 }
678 730
679 -/**
680 - * Displays messages before main content
681 - */
682 -function _learn_press_print_messages() {
683 - $item = LP_Global::course_item();
684 - if ( ( 'learn_press_before_main_content' == current_action() ) && $item ) {
685 - return;
686 - }
687 - learn_press_print_messages( true );
688 -}
689 -
690 -add_action( 'learn_press_before_main_content', '_learn_press_print_messages', 50 );
691 -add_action( 'learn-press/before-course-item-content', '_learn_press_print_messages', 50 );
692 -
693 731 if ( ! function_exists( 'learn_press_page_title' ) ) {
694 732
695 733 /**
696 734 * learn_press_page_title function.
@@ -695,8 +733,9 @@
695 733 /**
696 734 * learn_press_page_title function.
697 735 *
698 736 * @param boolean $echo
737 + *
699 738 * @return string
700 739 */
701 740 function learn_press_page_title( bool $echo = false ): string {
702 741 $page_title = '';
@@ -719,25 +758,8 @@
719 758 }
720 759 }
721 760
722 761 /**
723 - * @depecated 4.1.6.4
724 - */
725 -function learn_press_template_redirect() {
726 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
727 - global $wp_query, $wp;
728 -
729 - // When default permalinks are enabled, redirect shop page to post type archive url
730 - if ( ! empty( $_GET['page_id'] ) && get_option( 'permalink_structure' ) == '' && $_GET['page_id'] == learn_press_get_page_id( 'courses' ) ) {
731 - wp_safe_redirect( get_post_type_archive_link( 'lp_course' ) );
732 - exit;
733 - }
734 -}
735 -
736 -// add_action( 'template_redirect', 'learn_press_template_redirect' );
737 -
738 -
739 -/**
740 762 * Get template part.
741 763 *
742 764 * @param string $slug
743 765 * @param string $name
@@ -799,9 +821,9 @@
799 821 /**
800 822 * Get other templates passing attributes and including the file.
801 823 *
802 824 * @param string $template_name .
803 - * @param array $args (default: array()) .
825 + * @param array $args (default: array()) .
804 826 * @param string $template_path (default: '').
805 827 * @param string $default_path (default: '').
806 828 *
807 829 * @return void
@@ -851,11 +873,11 @@
851 873 /**
852 874 * Get template content
853 875 *
854 876 * @param $template_name
855 - * @param array $args
856 - * @param string $template_path
857 - * @param string $default_path
877 + * @param array $args
878 + * @param string $template_path
879 + * @param string $default_path
858 880 *
859 881 * @return string
860 882 * @uses learn_press_get_template();
861 883 */
@@ -920,16 +942,21 @@
920 942 return apply_filters( 'learn_press_locate_template', $template, $template_name, $template_path );
921 943 }
922 944
923 945 /**
924 - * Returns the name of folder contains template files in theme
946 + * Returns the name of folder contains override template files in theme
925 947 *
926 - * @param bool
927 - *
928 948 * @return string
949 + * @since 3.0.0
950 + * @version 1.0.1
929 951 */
930 -function learn_press_template_path( $slash = false ) {
931 - return apply_filters( 'learn_press_template_path', 'learnpress', $slash ) . ( $slash ? '/' : '' );
952 +function learn_press_template_path(): string {
953 + $lp_folder_name_override = apply_filters( 'learn_press_template_path', LP_PLUGIN_FOLDER_NAME );
954 + if ( ! is_string( $lp_folder_name_override ) ) {
955 + $lp_folder_name_override = LP_PLUGIN_FOLDER_NAME;
956 + }
957 +
958 + return $lp_folder_name_override;
932 959 }
933 960
934 961 /**
935 962 * Disable override templates in theme by default
@@ -940,17 +967,83 @@
940 967 function learn_press_override_templates() {
941 968 return apply_filters( 'learn-press/override-templates', false );
942 969 }
943 970
971 +/**
972 + * Get html view path for admin to display
973 + *
974 + * @param $name
975 + * @param $plugin_file
976 + *
977 + * @return mixed
978 + */
979 +function learn_press_get_admin_view( $name, $plugin_file = null ) {
980 + if ( ! preg_match( '/\.(html|php)$/', $name ) ) {
981 + $name .= '.php';
982 + }
983 + if ( $plugin_file ) {
984 + $view = dirname( $plugin_file ) . '/inc/admin/views/' . $name;
985 + } else {
986 + $view = LearnPress::instance()->plugin_path( 'inc/admin/views/' . $name );
987 + }
988 +
989 + return apply_filters( 'learn_press_admin_view', $view, $name );
990 +}
991 +
992 +function learn_press_admin_view_content( $name, $args = array() ) {
993 + return learn_press_admin_view( $name, $args, false, true );
994 +}
995 +
996 +/**
997 + * Find a full path of a view and display the content in admin
998 + *
999 + * @param $name
1000 + * @param array $args
1001 + * @param bool|false $include_once
1002 + * @param bool
1003 + *
1004 + * @return bool
1005 + */
1006 +function learn_press_admin_view( $name, $args = array(), $include_once = false, $return = false ) {
1007 + $view = learn_press_get_admin_view( $name, ! empty( $args['plugin_file'] ) ? $args['plugin_file'] : null );
1008 +
1009 + if ( file_exists( $view ) ) {
1010 +
1011 + ob_start();
1012 +
1013 + is_array( $args ) && extract( $args );
1014 +
1015 + do_action( 'learn_press_before_display_admin_view', $name, $args );
1016 +
1017 + if ( $include_once ) {
1018 + include_once $view;
1019 + } else {
1020 + include $view;
1021 + }
1022 +
1023 + do_action( 'learn_press_after_display_admin_view', $name, $args );
1024 + $output = ob_get_clean();
1025 +
1026 + if ( ! $return ) {
1027 + learn_press_echo_vuejs_write_on_php( $output );
1028 + }
1029 +
1030 + return $return ? $output : true;
1031 + }
1032 +
1033 + return false;
1034 +}
1035 +
944 1036 if ( ! function_exists( 'learn_press_is_404' ) ) {
945 1037 /**
946 1038 * Set header is 404
1039 + * @deprecated 4.2.8
947 1040 */
948 1041 function learn_press_is_404() {
1042 + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1043 +
1044 + return;
949 1045 global $wp_query;
950 - if ( ! empty( $_REQUEST['debug-404'] ) ) {
951 - learn_press_debug( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $_REQUEST['debug-404'] ) );
952 - }
953 1046 $wp_query->set_404();
954 1047 status_header( 404 );
955 1048 }
956 1049 }
@@ -957,10 +1050,15 @@
957 1050
958 1051 if ( ! function_exists( 'learn_press_404_page' ) ) {
959 1052 /**
960 1053 * Display 404 page
1054 + *
1055 + * @deprecated 4.2.8
961 1056 */
962 1057 function learn_press_404_page() {
1058 + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1059 +
1060 + return;
963 1061 learn_press_is_404();
964 1062 }
965 1063 }
966 1064
@@ -1016,15 +1114,18 @@
1016 1114 }
1017 1115 }
1018 1116 }
1019 1117
1020 -if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1118 +/**
1119 + * @deprecated 4.4.5
1120 + */
1121 +/*if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1021 1122 function learn_press_sort_course_tabs( $tabs = array() ) {
1022 1123 uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
1023 1124
1024 1125 return $tabs;
1025 1126 }
1026 -}
1127 +}*/
1027 1128
1028 1129 if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) {
1029 1130 /**
1030 1131 * Get Display name publicly as in Profile page
@@ -1053,51 +1154,8 @@
1053 1154 return $info ? $info->display_name : '';
1054 1155 }
1055 1156 }
1056 1157
1057 -/**
1058 - * @depecated 4.1.6.9
1059 - */
1060 -/*if ( ! function_exists( 'learn_press_content_item_comments' ) ) {
1061 - function learn_press_content_item_comments() {
1062 - $item = LP_Global::course_item();
1063 -
1064 - if ( ! $item ) {
1065 - return;
1066 - }
1067 -
1068 - if ( ! $item->is_support( 'comments' ) ) {
1069 - return;
1070 - }
1071 -
1072 - global $post;
1073 -
1074 - $post = get_post( $item->get_id() );
1075 -
1076 - setup_postdata( $post );
1077 -
1078 - if ( ! have_comments() ) {
1079 - return;
1080 - }
1081 -
1082 - add_filter( 'deprecated_file_trigger_error', '__return_false' );
1083 - comments_template();
1084 - remove_filter( 'deprecated_file_trigger_error', '__return_false' );
1085 -
1086 - wp_reset_postdata();
1087 - }
1088 -}*/
1089 -
1090 -function learn_press_course_comments_open( $open, $post_id ) {
1091 - $post = get_post( $post_id );
1092 -
1093 - if ( LP_COURSE_CPT == $post->post_type ) {
1094 - $open = false;
1095 - }
1096 -
1097 - return $open;
1098 -}
1099 -
1100 1158 function learn_press_is_content_item_only() {
1101 1159 return ! empty( $_REQUEST['content-item-only'] );
1102 1160 }
1103 1161
@@ -1109,74 +1167,16 @@
1109 1167 <?php
1110 1168 }
1111 1169
1112 1170 /**
1113 - * @depecated 4.1.6.4
1114 - */
1115 -function learn_press_get_course_redirect( $link ) {
1116 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
1117 - if ( empty( $_SERVER['HTTP_REFERER'] ) ) {
1118 - return $link;
1119 - }
1120 -
1121 - $referer = $_SERVER['HTTP_REFERER'];
1122 - $info_a = parse_url( $referer );
1123 - $info_b = parse_url( $link );
1124 -
1125 - $a = explode( '/', $info_a['path'] );
1126 - $a = array_filter( $a );
1127 -
1128 - $b = explode( '/', $info_b['path'] );
1129 - $b = array_filter( $b );
1130 -
1131 - $same = array_intersect_assoc( $a, $b );
1132 -
1133 - $a = array_diff_assoc( $a, $same );
1134 - $b = array_diff_assoc( $b, $same );
1135 -
1136 - $a = array_values( $a );
1137 - $b = array_values( $b );
1138 -
1139 - if ( array_shift( $a ) === 'popup' ) {
1140 - unset( $a[0] );
1141 -
1142 - if ( ! ( array_diff_assoc( $a, $b ) ) ) {
1143 - $link = '';
1144 - foreach ( array( 'scheme', 'host', 'port', 'path' ) as $v ) {
1145 - if ( ! isset( $info_a[ $v ] ) ) {
1146 - continue;
1147 - }
1148 -
1149 - if ( $v == 'scheme' ) {
1150 - $sep = '://';
1151 - } elseif ( $v == 'host' ) {
1152 - $sep = '';
1153 - } elseif ( $v == 'port' ) {
1154 - $link .= ':';
1155 - $sep = '';
1156 - } else {
1157 - $sep = '/';
1158 - }
1159 - $link = $link . $info_a[ $v ] . $sep;
1160 - }
1161 -
1162 - if ( ! empty( $info_b['query'] ) ) {
1163 - $link .= '?' . $info_b['query'];
1164 - }
1165 -
1166 - if ( ! empty( $info_b['fragment'] ) ) {
1167 - $link .= '#' . $info_b['fragment'];
1168 - }
1169 - }
1170 - }
1171 -
1172 - return $link;
1173 -}
1174 -
1175 -/**
1176 1171 * @param LP_Quiz $item
1172 + *
1173 + * @deprecated 4.2.3.5
1177 1174 */
1178 1175 function learn_press_quiz_meta_final( $item ) {
1176 + _deprecated_function( __METHOD__, '4.2.3.5' );
1177 +
1178 + return;
1179 1179 $course = learn_press_get_course();
1180 1180
1181 1181 if ( ! $course->is_final_quiz( $item->get_id() ) ) {
1182 1182 return;
@@ -1193,40 +1193,58 @@
1193 1193
1194 1194 return $comment_args;
1195 1195 }
1196 1196
1197 -if ( ! function_exists( 'learn_press_filter_get_comments_number' ) ) {
1198 - function learn_press_filter_get_comments_number( $count, $post_id = 0 ) {
1199 - global $wpdb;
1197 +add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' );
1200 1198
1201 - if ( ! $post_id ) {
1202 - $post_id = learn_press_get_course_id();
1203 - }
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 + }
1204 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();
1205 1224 if ( ! $post_id ) {
1206 1225 return $count;
1207 1226 }
1227 + }
1208 1228
1209 - if ( get_post_type( $post_id ) == LP_COURSE_CPT ) {
1210 - $sql = $wpdb->prepare(
1211 - ' SELECT count(*) '
1212 - . " FROM {$wpdb->comments} "
1213 - . ' WHERE comment_post_ID = %d '
1214 - . ' AND comment_approved = 1 '
1215 - . ' AND comment_type != %s ',
1216 - $post_id,
1217 - 'review'
1218 - );
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 + );
1219 1239
1220 - $count = $wpdb->get_var( $sql );
1240 + $count = $wpdb->get_var( $sql );
1241 + }
1221 1242
1222 - // @since 3.0.0
1223 - $count = apply_filters( 'learn-press/course-comments-number', $count, $post_id );
1224 - }
1243 + return $count;
1244 +}
1225 1245
1226 - return $count;
1227 - }
1228 -}
1246 +add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' );
1229 1247
1230 1248 /**
1231 1249 * Add custom classes to body tag class name
1232 1250 *
@@ -1234,34 +1252,22 @@
1234 1252 *
1235 1253 * @return array
1236 1254 *
1237 1255 * @since 3.0.0
1256 + * @Todo tungnx review to remove
1257 + * @deprecated 4.2.3
1238 1258 */
1239 1259 function learn_press_body_classes( $classes ) {
1240 - $pages = learn_press_static_page_ids();
1241 -
1242 - if ( $pages ) {
1243 - $is_lp_page = false;
1244 - settype( $classes, 'array' );
1245 -
1246 - foreach ( $pages as $slug => $id ) {
1247 - if ( is_page( $id ) ) {
1248 - $classes[] = $slug;
1249 - $is_lp_page = true;
1250 - }
1251 - }
1252 -
1253 - if ( $is_lp_page || is_learnpress() ) {
1254 - $classes[] = get_stylesheet();
1255 - $classes[] = 'learnpress';
1256 - $classes[] = 'learnpress-page';
1257 - }
1260 + if ( is_learnpress() ) {
1261 + $classes[] = get_stylesheet();
1262 + $classes[] = 'learnpress';
1263 + $classes[] = 'learnpress-page';
1258 1264 }
1259 1265
1260 1266 return $classes;
1261 1267 }
1262 1268
1263 -add_filter( 'body_class', 'learn_press_body_classes', 10 );
1269 +//add_filter( 'body_class', 'learn_press_body_classes', 10 );
1264 1270
1265 1271 /**
1266 1272 * Return true if user is learning a course
1267 1273 *
@@ -1289,61 +1295,8 @@
1289 1295
1290 1296 return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
1291 1297 }
1292 1298
1293 -/**
1294 - * Output custom css from settings
1295 - *
1296 - * @since 4.0.0
1297 - */
1298 -if ( ! function_exists( 'learn_press_print_custom_styles' ) ) {
1299 - function learn_press_print_custom_styles() {
1300 - $primary_color = LP_Settings::instance()->get( 'primary_color' );
1301 - $secondary_color = LP_Settings::instance()->get( 'secondary_color' );
1302 - ?>
1303 -
1304 - <style id="learn-press-custom-css">
1305 - :root {
1306 - --lp-primary-color: <?php echo ! empty( $primary_color ) ? $primary_color : '#ffb606'; ?>;
1307 - --lp-secondary-color: <?php echo ! empty( $secondary_color ) ? $secondary_color : '#442e66'; ?>;
1308 - }
1309 - </style>
1310 -
1311 - <?php
1312 - }
1313 -
1314 - add_action( 'wp_head', 'learn_press_print_custom_styles' );
1315 -}
1316 -
1317 -/**
1318 - * Return TRUE if current user has already enroll course in single view.
1319 - *
1320 - * @return bool
1321 - * @since 3.0.0
1322 - * @editor tungnx
1323 - * @version 4.1.3
1324 - */
1325 -function learn_press_current_user_enrolled_course() {
1326 - _deprecated_function( __FUNCTION__, '4.1.3' );
1327 -}
1328 -
1329 -/**
1330 - * Check if an user can access content of a course.
1331 - *
1332 - * @param int $course_id
1333 - * @param int $user_id
1334 - *
1335 - * @return bool
1336 - * @since 3.x.x
1337 - * @editor tungnx
1338 - * @modify 4.1.3
1339 - * @reason comment - not use
1340 - */
1341 -
1342 -function learn_press_user_can_access_course( $course_id, $user_id = 0 ) {
1343 - _deprecated_function( __FUNCTION__, '4.1.2' );
1344 -}
1345 -
1346 1299 function learn_press_content_item_summary_class( $more = '', $echo = true ) {
1347 1300 $classes = array( 'content-item-summary' );
1348 1301 $classes = LP_Helper::merge_class( $classes, $more );
1349 1302 $classes = apply_filters( 'learn-press/content-item-summary-class', $classes );
@@ -1355,9 +1308,13 @@
1355 1308
1356 1309 return $output;
1357 1310 }
1358 1311
1312 +/**
1313 + * @deprecated 4.2.3.1
1314 + */
1359 1315 function learn_press_content_item_summary_classes( $classes ) {
1316 + _deprecated_function( __FUNCTION__, '4.2.3.1' );
1360 1317 $item = LP_Global::course_item();
1361 1318
1362 1319 if ( ! $item ) {
1363 1320 return $classes;
@@ -1389,10 +1346,10 @@
1389 1346 function learn_press_courses_layouts() {
1390 1347 return apply_filters(
1391 1348 'learnpress/archive-courses-layouts',
1392 1349 [
1393 - 'grid' => 'Grid',
1394 - 'list' => 'List',
1350 + 'grid' => __( 'Grid', 'learnpress' ),
1351 + 'list' => __( 'List', 'learnpress' ),
1395 1352 ]
1396 1353 );
1397 1354 }
1398 1355
@@ -1418,13 +1375,13 @@
1418 1375 register_sidebar(
1419 1376 array(
1420 1377 'name' => esc_html__( 'Course Sidebar', 'learnpress' ),
1421 1378 'id' => 'course-sidebar',
1422 - 'description' => esc_html__( 'Widgets in this area will be shown in single course', 'learnpress' ),
1379 + 'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ),
1423 1380 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1424 1381 'after_widget' => '</div>',
1425 - 'before_title' => '<h2 class="widgettitle">',
1426 - 'after_title' => '</h2>',
1382 + 'before_title' => '<h3 class="widget-title">',
1383 + 'after_title' => '</h3>',
1427 1384 )
1428 1385 );
1429 1386 register_sidebar(
1430 1387 array(
@@ -1429,13 +1386,13 @@
1429 1386 register_sidebar(
1430 1387 array(
1431 1388 'name' => esc_html__( 'All Courses', 'learnpress' ),
1432 1389 'id' => 'archive-courses-sidebar',
1433 - 'description' => esc_html__( 'Widgets in this area will be shown in all courses page', 'learnpress' ),
1390 + 'description' => esc_html__( 'Widgets in this area will be shown on all course pages', 'learnpress' ),
1434 1391 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1435 1392 'after_widget' => '</div>',
1436 - 'before_title' => '<h2 class="widgettitle">',
1437 - 'after_title' => '</h2>',
1393 + 'before_title' => '<h3 class="widget-title">',
1394 + 'after_title' => '</h3>',
1438 1395 )
1439 1396 );
1440 1397 }
1441 1398
@@ -1458,9 +1415,9 @@
1458 1415 add_action( 'after_setup_theme', 'learn_press_setup_theme' );
1459 1416
1460 1417 /**
1461 1418 * @param LP_Question $question
1462 - * @param array $args
1419 + * @param array $args
1463 1420 *
1464 1421 * @return array
1465 1422 * @since 4.x.x
1466 1423 */
@@ -1468,9 +1425,9 @@
1468 1425 $args = wp_parse_args(
1469 1426 $args,
1470 1427 array(
1471 1428 'cryptoJsAes' => false,
1472 - 'include_is_true' => true,
1429 + 'include_is_true' => false,
1473 1430 'answer' => false,
1474 1431 )
1475 1432 );
1476 1433
@@ -1508,9 +1465,9 @@
1508 1465
1509 1466 /**
1510 1467 * Get post meta with key _lp_duration and translate.
1511 1468 *
1512 - * @param int $post_id
1469 + * @param int $post_id
1513 1470 * @param string $default
1514 1471 *
1515 1472 * @return string
1516 1473 * @since 4.0.0
@@ -1575,9 +1532,9 @@
1575 1532 function lp_course_level() {
1576 1533 return apply_filters(
1577 1534 'lp/template/function/course/level',
1578 1535 array(
1579 - '' => esc_html__( 'All levels', 'learnpress' ),
1536 + 'all' => esc_html__( 'All levels', 'learnpress' ),
1580 1537 'beginner' => esc_html__( 'Beginner', 'learnpress' ),
1581 1538 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ),
1582 1539 'expert' => esc_html__( 'Expert', 'learnpress' ),
1583 1540 )
@@ -1583,14 +1540,8 @@
1583 1540 )
1584 1541 );
1585 1542 }
1586 1543
1587 -// function learn_press_is_preview_course() {
1588 -// $course_id = isset( $GLOBALS['preview_course'] ) ? $GLOBALS['preview_course'] : 0;
1589 -//
1590 -// return $course_id && get_post_type( $course_id ) === LP_COURSE_CPT;
1591 -// }
1592 -
1593 1544 /**
1594 1545 * Get slug for logout action in user profile.
1595 1546 *
1596 1547 * @return string
@@ -1615,9 +1566,9 @@
1615 1566 function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) {
1616 1567 ?>
1617 1568 <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>">
1618 1569 <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?>
1619 - <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>
1620 1571 <?php endfor; ?>
1621 1572 </ul>
1622 1573
1623 1574 <?php
@@ -1664,9 +1615,10 @@
1664 1615 if ( is_search() ) {
1665 1616 return;
1666 1617 }
1667 1618
1668 - 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 ) ) {
1669 1621 $profile_id = learn_press_get_page_id( 'courses' );
1670 1622
1671 1623 if ( $profile_id ) {
1672 1624 $profile_page = get_post( $profile_id );
@@ -1700,41 +1652,35 @@
1700 1652 *
1701 1653 * @return array
1702 1654 */
1703 1655 function lp_archive_skeleton_get_args(): array {
1704 - global $post, $wp;
1656 + $args = [];
1705 1657
1706 - $args = array();
1707 -
1708 1658 if ( ! empty( $_GET ) ) {
1709 - $args = (array) $_GET;
1659 + $args = $_GET;
1710 1660 }
1711 1661
1712 - $params = apply_filters(
1713 - 'lp/template/archive-course/skeleton/args',
1714 - array(
1715 - 'paged' => 1,
1716 - 'c_search' => '',
1717 - 'orderby' => '',
1718 - 'order' => '',
1719 - )
1720 - );
1662 + global $wp_query;
1663 + if ( ! empty( $wp_query->get( 'paged' ) ) ) {
1664 + $args['paged'] = $wp_query->get( 'paged' );
1665 + }
1721 1666
1722 1667 if ( learn_press_is_course_category() || learn_press_is_course_tag() ) {
1723 1668 $cat = get_queried_object();
1724 1669
1725 - $args['term_id'] = $cat->term_id;
1726 - $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 );
1727 1678 }
1728 1679
1729 - if ( learn_press_is_course_archive() ) {
1730 - foreach ( $params as $key => $param ) {
1731 - if ( isset( $_REQUEST[ $key ] ) ) {
1732 - $args[ $key ] = LP_Helper::sanitize_params_submitted( $_REQUEST[ $key ] );
1733 - } else {
1734 - $args[ $key ] = $param;
1735 - }
1736 - }
1680 + $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args );
1681 + if ( ! is_array( $args ) ) {
1682 + $args = [];
1737 1683 }
1738 1684
1739 - return $args;
1685 + return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' );
1740 1686 }