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 +465 -502 4.1.7.34.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 = '';
@@ -782,9 +821,9 @@
782 821 /**
783 822 * Get other templates passing attributes and including the file.
784 823 *
785 824 * @param string $template_name .
786 - * @param array $args (default: array()) .
825 + * @param array $args (default: array()) .
787 826 * @param string $template_path (default: '').
788 827 * @param string $default_path (default: '').
789 828 *
790 829 * @return void
@@ -834,11 +873,11 @@
834 873 /**
835 874 * Get template content
836 875 *
837 876 * @param $template_name
838 - * @param array $args
839 - * @param string $template_path
840 - * @param string $default_path
877 + * @param array $args
878 + * @param string $template_path
879 + * @param string $default_path
841 880 *
842 881 * @return string
843 882 * @uses learn_press_get_template();
844 883 */
@@ -903,16 +942,21 @@
903 942 return apply_filters( 'learn_press_locate_template', $template, $template_name, $template_path );
904 943 }
905 944
906 945 /**
907 - * Returns the name of folder contains template files in theme
946 + * Returns the name of folder contains override template files in theme
908 947 *
909 - * @param bool
910 - *
911 948 * @return string
949 + * @since 3.0.0
950 + * @version 1.0.1
912 951 */
913 -function learn_press_template_path( $slash = false ) {
914 - 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;
915 959 }
916 960
917 961 /**
918 962 * Disable override templates in theme by default
@@ -923,17 +967,83 @@
923 967 function learn_press_override_templates() {
924 968 return apply_filters( 'learn-press/override-templates', false );
925 969 }
926 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 +
927 1036 if ( ! function_exists( 'learn_press_is_404' ) ) {
928 1037 /**
929 1038 * Set header is 404
1039 + * @deprecated 4.2.8
930 1040 */
931 1041 function learn_press_is_404() {
1042 + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1043 +
1044 + return;
932 1045 global $wp_query;
933 - if ( ! empty( $_REQUEST['debug-404'] ) ) {
934 - learn_press_debug( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $_REQUEST['debug-404'] ) );
935 - }
936 1046 $wp_query->set_404();
937 1047 status_header( 404 );
938 1048 }
939 1049 }
@@ -940,10 +1050,15 @@
940 1050
941 1051 if ( ! function_exists( 'learn_press_404_page' ) ) {
942 1052 /**
943 1053 * Display 404 page
1054 + *
1055 + * @deprecated 4.2.8
944 1056 */
945 1057 function learn_press_404_page() {
1058 + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1059 +
1060 + return;
946 1061 learn_press_is_404();
947 1062 }
948 1063 }
949 1064
@@ -999,15 +1114,18 @@
999 1114 }
1000 1115 }
1001 1116 }
1002 1117
1003 -if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1118 +/**
1119 + * @deprecated 4.4.5
1120 + */
1121 +/*if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1004 1122 function learn_press_sort_course_tabs( $tabs = array() ) {
1005 1123 uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
1006 1124
1007 1125 return $tabs;
1008 1126 }
1009 -}
1127 +}*/
1010 1128
1011 1129 if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) {
1012 1130 /**
1013 1131 * Get Display name publicly as in Profile page
@@ -1036,51 +1154,8 @@
1036 1154 return $info ? $info->display_name : '';
1037 1155 }
1038 1156 }
1039 1157
1040 -/**
1041 - * @deprecated 4.1.6.9
1042 - */
1043 -/*if ( ! function_exists( 'learn_press_content_item_comments' ) ) {
1044 - function learn_press_content_item_comments() {
1045 - $item = LP_Global::course_item();
1046 -
1047 - if ( ! $item ) {
1048 - return;
1049 - }
1050 -
1051 - if ( ! $item->is_support( 'comments' ) ) {
1052 - return;
1053 - }
1054 -
1055 - global $post;
1056 -
1057 - $post = get_post( $item->get_id() );
1058 -
1059 - setup_postdata( $post );
1060 -
1061 - if ( ! have_comments() ) {
1062 - return;
1063 - }
1064 -
1065 - add_filter( 'deprecated_file_trigger_error', '__return_false' );
1066 - comments_template();
1067 - remove_filter( 'deprecated_file_trigger_error', '__return_false' );
1068 -
1069 - wp_reset_postdata();
1070 - }
1071 -}*/
1072 -
1073 -function learn_press_course_comments_open( $open, $post_id ) {
1074 - $post = get_post( $post_id );
1075 -
1076 - if ( LP_COURSE_CPT == $post->post_type ) {
1077 - $open = false;
1078 - }
1079 -
1080 - return $open;
1081 -}
1082 -
1083 1158 function learn_press_is_content_item_only() {
1084 1159 return ! empty( $_REQUEST['content-item-only'] );
1085 1160 }
1086 1161
@@ -1092,74 +1167,16 @@
1092 1167 <?php
1093 1168 }
1094 1169
1095 1170 /**
1096 - * @deprecated 4.1.6.4
1097 - */
1098 -function learn_press_get_course_redirect( $link ) {
1099 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
1100 - if ( empty( $_SERVER['HTTP_REFERER'] ) ) {
1101 - return $link;
1102 - }
1103 -
1104 - $referer = $_SERVER['HTTP_REFERER'];
1105 - $info_a = parse_url( $referer );
1106 - $info_b = parse_url( $link );
1107 -
1108 - $a = explode( '/', $info_a['path'] );
1109 - $a = array_filter( $a );
1110 -
1111 - $b = explode( '/', $info_b['path'] );
1112 - $b = array_filter( $b );
1113 -
1114 - $same = array_intersect_assoc( $a, $b );
1115 -
1116 - $a = array_diff_assoc( $a, $same );
1117 - $b = array_diff_assoc( $b, $same );
1118 -
1119 - $a = array_values( $a );
1120 - $b = array_values( $b );
1121 -
1122 - if ( array_shift( $a ) === 'popup' ) {
1123 - unset( $a[0] );
1124 -
1125 - if ( ! ( array_diff_assoc( $a, $b ) ) ) {
1126 - $link = '';
1127 - foreach ( array( 'scheme', 'host', 'port', 'path' ) as $v ) {
1128 - if ( ! isset( $info_a[ $v ] ) ) {
1129 - continue;
1130 - }
1131 -
1132 - if ( $v == 'scheme' ) {
1133 - $sep = '://';
1134 - } elseif ( $v == 'host' ) {
1135 - $sep = '';
1136 - } elseif ( $v == 'port' ) {
1137 - $link .= ':';
1138 - $sep = '';
1139 - } else {
1140 - $sep = '/';
1141 - }
1142 - $link = $link . $info_a[ $v ] . $sep;
1143 - }
1144 -
1145 - if ( ! empty( $info_b['query'] ) ) {
1146 - $link .= '?' . $info_b['query'];
1147 - }
1148 -
1149 - if ( ! empty( $info_b['fragment'] ) ) {
1150 - $link .= '#' . $info_b['fragment'];
1151 - }
1152 - }
1153 - }
1154 -
1155 - return $link;
1156 -}
1157 -
1158 -/**
1159 1171 * @param LP_Quiz $item
1172 + *
1173 + * @deprecated 4.2.3.5
1160 1174 */
1161 1175 function learn_press_quiz_meta_final( $item ) {
1176 + _deprecated_function( __METHOD__, '4.2.3.5' );
1177 +
1178 + return;
1162 1179 $course = learn_press_get_course();
1163 1180
1164 1181 if ( ! $course->is_final_quiz( $item->get_id() ) ) {
1165 1182 return;
@@ -1176,40 +1193,58 @@
1176 1193
1177 1194 return $comment_args;
1178 1195 }
1179 1196
1180 -if ( ! function_exists( 'learn_press_filter_get_comments_number' ) ) {
1181 - function learn_press_filter_get_comments_number( $count, $post_id = 0 ) {
1182 - global $wpdb;
1197 +add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' );
1183 1198
1184 - if ( ! $post_id ) {
1185 - $post_id = learn_press_get_course_id();
1186 - }
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 + }
1187 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();
1188 1224 if ( ! $post_id ) {
1189 1225 return $count;
1190 1226 }
1227 + }
1191 1228
1192 - if ( get_post_type( $post_id ) == LP_COURSE_CPT ) {
1193 - $sql = $wpdb->prepare(
1194 - ' SELECT count(*) '
1195 - . " FROM {$wpdb->comments} "
1196 - . ' WHERE comment_post_ID = %d '
1197 - . ' AND comment_approved = 1 '
1198 - . ' AND comment_type != %s ',
1199 - $post_id,
1200 - 'review'
1201 - );
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 + );
1202 1239
1203 - $count = $wpdb->get_var( $sql );
1240 + $count = $wpdb->get_var( $sql );
1241 + }
1204 1242
1205 - // @since 3.0.0
1206 - $count = apply_filters( 'learn-press/course-comments-number', $count, $post_id );
1207 - }
1243 + return $count;
1244 +}
1208 1245
1209 - return $count;
1210 - }
1211 -}
1246 +add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' );
1212 1247
1213 1248 /**
1214 1249 * Add custom classes to body tag class name
1215 1250 *
@@ -1217,34 +1252,22 @@
1217 1252 *
1218 1253 * @return array
1219 1254 *
1220 1255 * @since 3.0.0
1256 + * @Todo tungnx review to remove
1257 + * @deprecated 4.2.3
1221 1258 */
1222 1259 function learn_press_body_classes( $classes ) {
1223 - $pages = learn_press_static_page_ids();
1224 -
1225 - if ( $pages ) {
1226 - $is_lp_page = false;
1227 - settype( $classes, 'array' );
1228 -
1229 - foreach ( $pages as $slug => $id ) {
1230 - if ( is_page( $id ) ) {
1231 - $classes[] = $slug;
1232 - $is_lp_page = true;
1233 - }
1234 - }
1235 -
1236 - if ( $is_lp_page || is_learnpress() ) {
1237 - $classes[] = get_stylesheet();
1238 - $classes[] = 'learnpress';
1239 - $classes[] = 'learnpress-page';
1240 - }
1260 + if ( is_learnpress() ) {
1261 + $classes[] = get_stylesheet();
1262 + $classes[] = 'learnpress';
1263 + $classes[] = 'learnpress-page';
1241 1264 }
1242 1265
1243 1266 return $classes;
1244 1267 }
1245 1268
1246 -add_filter( 'body_class', 'learn_press_body_classes', 10 );
1269 +//add_filter( 'body_class', 'learn_press_body_classes', 10 );
1247 1270
1248 1271 /**
1249 1272 * Return true if user is learning a course
1250 1273 *
@@ -1272,61 +1295,8 @@
1272 1295
1273 1296 return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
1274 1297 }
1275 1298
1276 -/**
1277 - * Output custom css from settings
1278 - *
1279 - * @since 4.0.0
1280 - */
1281 -if ( ! function_exists( 'learn_press_print_custom_styles' ) ) {
1282 - function learn_press_print_custom_styles() {
1283 - $primary_color = LP_Settings::instance()->get( 'primary_color' );
1284 - $secondary_color = LP_Settings::instance()->get( 'secondary_color' );
1285 - ?>
1286 -
1287 - <style id="learn-press-custom-css">
1288 - :root {
1289 - --lp-primary-color: <?php echo ! empty( $primary_color ) ? $primary_color : '#ffb606'; ?>;
1290 - --lp-secondary-color: <?php echo ! empty( $secondary_color ) ? $secondary_color : '#442e66'; ?>;
1291 - }
1292 - </style>
1293 -
1294 - <?php
1295 - }
1296 -
1297 - add_action( 'wp_head', 'learn_press_print_custom_styles' );
1298 -}
1299 -
1300 -/**
1301 - * Return TRUE if current user has already enroll course in single view.
1302 - *
1303 - * @return bool
1304 - * @since 3.0.0
1305 - * @editor tungnx
1306 - * @version 4.1.3
1307 - */
1308 -function learn_press_current_user_enrolled_course() {
1309 - _deprecated_function( __FUNCTION__, '4.1.3' );
1310 -}
1311 -
1312 -/**
1313 - * Check if an user can access content of a course.
1314 - *
1315 - * @param int $course_id
1316 - * @param int $user_id
1317 - *
1318 - * @return bool
1319 - * @since 3.x.x
1320 - * @editor tungnx
1321 - * @modify 4.1.3
1322 - * @reason comment - not use
1323 - */
1324 -
1325 -function learn_press_user_can_access_course( $course_id, $user_id = 0 ) {
1326 - _deprecated_function( __FUNCTION__, '4.1.2' );
1327 -}
1328 -
1329 1299 function learn_press_content_item_summary_class( $more = '', $echo = true ) {
1330 1300 $classes = array( 'content-item-summary' );
1331 1301 $classes = LP_Helper::merge_class( $classes, $more );
1332 1302 $classes = apply_filters( 'learn-press/content-item-summary-class', $classes );
@@ -1338,9 +1308,13 @@
1338 1308
1339 1309 return $output;
1340 1310 }
1341 1311
1312 +/**
1313 + * @deprecated 4.2.3.1
1314 + */
1342 1315 function learn_press_content_item_summary_classes( $classes ) {
1316 + _deprecated_function( __FUNCTION__, '4.2.3.1' );
1343 1317 $item = LP_Global::course_item();
1344 1318
1345 1319 if ( ! $item ) {
1346 1320 return $classes;
@@ -1372,10 +1346,10 @@
1372 1346 function learn_press_courses_layouts() {
1373 1347 return apply_filters(
1374 1348 'learnpress/archive-courses-layouts',
1375 1349 [
1376 - 'grid' => 'Grid',
1377 - 'list' => 'List',
1350 + 'grid' => __( 'Grid', 'learnpress' ),
1351 + 'list' => __( 'List', 'learnpress' ),
1378 1352 ]
1379 1353 );
1380 1354 }
1381 1355
@@ -1404,10 +1378,10 @@
1404 1378 'id' => 'course-sidebar',
1405 1379 'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ),
1406 1380 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1407 1381 'after_widget' => '</div>',
1408 - 'before_title' => '<h2 class="widgettitle">',
1409 - 'after_title' => '</h2>',
1382 + 'before_title' => '<h3 class="widget-title">',
1383 + 'after_title' => '</h3>',
1410 1384 )
1411 1385 );
1412 1386 register_sidebar(
1413 1387 array(
@@ -1415,10 +1389,10 @@
1415 1389 'id' => 'archive-courses-sidebar',
1416 1390 'description' => esc_html__( 'Widgets in this area will be shown on all course pages', 'learnpress' ),
1417 1391 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1418 1392 'after_widget' => '</div>',
1419 - 'before_title' => '<h2 class="widgettitle">',
1420 - 'after_title' => '</h2>',
1393 + 'before_title' => '<h3 class="widget-title">',
1394 + 'after_title' => '</h3>',
1421 1395 )
1422 1396 );
1423 1397 }
1424 1398
@@ -1441,9 +1415,9 @@
1441 1415 add_action( 'after_setup_theme', 'learn_press_setup_theme' );
1442 1416
1443 1417 /**
1444 1418 * @param LP_Question $question
1445 - * @param array $args
1419 + * @param array $args
1446 1420 *
1447 1421 * @return array
1448 1422 * @since 4.x.x
1449 1423 */
@@ -1451,9 +1425,9 @@
1451 1425 $args = wp_parse_args(
1452 1426 $args,
1453 1427 array(
1454 1428 'cryptoJsAes' => false,
1455 - 'include_is_true' => true,
1429 + 'include_is_true' => false,
1456 1430 'answer' => false,
1457 1431 )
1458 1432 );
1459 1433
@@ -1491,9 +1465,9 @@
1491 1465
1492 1466 /**
1493 1467 * Get post meta with key _lp_duration and translate.
1494 1468 *
1495 - * @param int $post_id
1469 + * @param int $post_id
1496 1470 * @param string $default
1497 1471 *
1498 1472 * @return string
1499 1473 * @since 4.0.0
@@ -1558,9 +1532,9 @@
1558 1532 function lp_course_level() {
1559 1533 return apply_filters(
1560 1534 'lp/template/function/course/level',
1561 1535 array(
1562 - '' => esc_html__( 'All levels', 'learnpress' ),
1536 + 'all' => esc_html__( 'All levels', 'learnpress' ),
1563 1537 'beginner' => esc_html__( 'Beginner', 'learnpress' ),
1564 1538 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ),
1565 1539 'expert' => esc_html__( 'Expert', 'learnpress' ),
1566 1540 )
@@ -1566,14 +1540,8 @@
1566 1540 )
1567 1541 );
1568 1542 }
1569 1543
1570 -// function learn_press_is_preview_course() {
1571 -// $course_id = isset( $GLOBALS['preview_course'] ) ? $GLOBALS['preview_course'] : 0;
1572 -//
1573 -// return $course_id && get_post_type( $course_id ) === LP_COURSE_CPT;
1574 -// }
1575 -
1576 1544 /**
1577 1545 * Get slug for logout action in user profile.
1578 1546 *
1579 1547 * @return string
@@ -1598,9 +1566,9 @@
1598 1566 function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) {
1599 1567 ?>
1600 1568 <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>">
1601 1569 <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?>
1602 - <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>
1603 1571 <?php endfor; ?>
1604 1572 </ul>
1605 1573
1606 1574 <?php
@@ -1647,9 +1615,10 @@
1647 1615 if ( is_search() ) {
1648 1616 return;
1649 1617 }
1650 1618
1651 - 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 ) ) {
1652 1621 $profile_id = learn_press_get_page_id( 'courses' );
1653 1622
1654 1623 if ( $profile_id ) {
1655 1624 $profile_page = get_post( $profile_id );
@@ -1683,41 +1652,35 @@
1683 1652 *
1684 1653 * @return array
1685 1654 */
1686 1655 function lp_archive_skeleton_get_args(): array {
1687 - global $post, $wp;
1656 + $args = [];
1688 1657
1689 - $args = array();
1690 -
1691 1658 if ( ! empty( $_GET ) ) {
1692 - $args = (array) $_GET;
1659 + $args = $_GET;
1693 1660 }
1694 1661
1695 - $params = apply_filters(
1696 - 'lp/template/archive-course/skeleton/args',
1697 - array(
1698 - 'paged' => 1,
1699 - 'c_search' => '',
1700 - 'orderby' => '',
1701 - 'order' => '',
1702 - )
1703 - );
1662 + global $wp_query;
1663 + if ( ! empty( $wp_query->get( 'paged' ) ) ) {
1664 + $args['paged'] = $wp_query->get( 'paged' );
1665 + }
1704 1666
1705 1667 if ( learn_press_is_course_category() || learn_press_is_course_tag() ) {
1706 1668 $cat = get_queried_object();
1707 1669
1708 - $args['term_id'] = $cat->term_id;
1709 - $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 );
1710 1678 }
1711 1679
1712 - if ( learn_press_is_course_archive() ) {
1713 - foreach ( $params as $key => $param ) {
1714 - if ( isset( $_REQUEST[ $key ] ) ) {
1715 - $args[ $key ] = LP_Helper::sanitize_params_submitted( $_REQUEST[ $key ] );
1716 - } else {
1717 - $args[ $key ] = $param;
1718 - }
1719 - }
1680 + $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args );
1681 + if ( ! is_array( $args ) ) {
1682 + $args = [];
1720 1683 }
1721 1684
1722 - return $args;
1685 + return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' );
1723 1686 }