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 +481 -543 4.1.7.14.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', LP()->template( 'course' )->func( 'course_enroll_button' ), 5 );
21 - add_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'course_purchase_button' ), 10 );
22 - add_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'course_external_button' ), 15 );
23 - add_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'button_retry' ), 20 );
24 - add_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'course_continue_button' ), 25 );
25 - add_action( 'learn-press/course-buttons', LP()->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', LP()->template( 'course' )->func( 'course_enroll_button' ), 5 );
32 - remove_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'course_purchase_button' ), 10 );
33 - //remove_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'course_external_button' ), 15 );
34 - remove_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'button_retry' ), 20 );
35 - remove_action( 'learn-press/course-buttons', LP()->template( 'course' )->func( 'course_continue_button' ), 25 );
36 - remove_action( 'learn-press/course-buttons', LP()->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' => LP()->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' => LP()->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 - 'callback' => LP()->template( 'course' )->callback( 'single-course/tabs/instructor.php' ),
76 - );
66 + 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/instructor.php' ),
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' => LP()->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,24 +254,23 @@
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 - 'totalTime' => $quiz->get_duration()->get(),
270 - 'remainingTime' => $remaining_time ? $remaining_time->get() : $quiz->get_duration()->get(),
271 + //'totalTime' => -1,
272 + //'remainingTime' => $remaining_time ? $remaining_time->get() : $quiz->get_duration()->get(),
271 273 'status' => $user->get_item_status( $quiz->get_id(), $course_id ),
272 274 'checkNorequizenroll' => $course->is_no_required_enroll(),
273 275 'navigationPosition' => LP_Settings::get_option( 'navigation_position', 'yes' ),
274 276 );
@@ -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,144 +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 - /*
415 - if ( $user->can_view_item( $lesson_id, $course_id )->flag ) {
416 - $classes[] = 'viewable';
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 -}
428 -
429 -if ( ! function_exists( 'learn_press_course_quiz_class' ) ) {
430 - /**
431 - * The class of lesson in course curriculum
432 - *
433 - * @param int $quiz_id
434 - * @param int $course_id
435 - * @param string|array $class
436 - * @param boolean $echo
437 - *
438 - * @return mixed
439 - */
440 - function learn_press_course_quiz_class( $quiz_id = null, $course_id = 0, $class = null, $echo = true ) {
441 - $user = learn_press_get_current_user();
442 -
443 - if ( ! $course_id ) {
444 - $course_id = get_the_ID();
445 - }
446 -
447 - if ( is_string( $class ) && $class ) {
448 - $class = preg_split( '!\s+!', $class );
449 - } else {
450 - $class = array();
451 - }
452 -
453 - $course = learn_press_get_course( $course_id );
454 -
455 - if ( ! $course ) {
456 - return '';
457 - }
458 -
459 - $classes = array(
460 - 'course-quiz course-item course-item-' . $quiz_id,
461 - );
462 -
463 - $status = $user->get_item_status( $quiz_id );
464 -
465 - if ( $status ) {
466 - $classes[] = "item-has-status item-{$status}";
467 - }
468 -
469 - if ( $quiz_id && $course->is_current_item( $quiz_id ) ) {
470 - $classes[] = 'item-current';
471 - }
472 -
473 - /*
474 - if ( $user->can_view_item( $quiz_id, $course_id )->flag ) {
475 - $classes[] = 'viewable';
476 - }*/
477 -
478 - if ( $course->is_final_quiz( $quiz_id ) ) {
479 - $classes[] = 'final-quiz';
480 - }
481 -
482 - $classes = array_unique( array_merge( $classes, $class ) );
483 -
484 - if ( $echo ) {
485 - echo 'class="' . implode( ' ', $classes ) . '"';
486 - }
487 -
488 - return $classes;
489 - }
490 -}
491 -
492 493 if ( ! function_exists( 'learn_press_course_class' ) ) {
493 494 /**
494 495 * Append new class to course post type
495 496 *
@@ -520,15 +521,18 @@
520 521
521 522 function learn_press_setup_user() {
522 523 $GLOBALS['lp_user'] = learn_press_get_current_user();
523 524 }
524 -add_action( 'init', 'learn_press_setup_user', 1000 );
525 525
526 +//add_action( 'init', 'learn_press_setup_user', 1000 );
527 +
526 528 /**
527 529 * Display a message immediately with out push into queue
528 530 *
529 531 * @param $message
530 - * @param string $type
532 + * @param string $type
533 + *
534 + * @Todo tungnx review code.
531 535 */
532 536
533 537 function learn_press_display_message( $message, $type = 'success' ) {
534 538 $messages = learn_press_session_get( learn_press_session_message_id() );
@@ -558,12 +562,14 @@
558 562
559 563 /**
560 564 * Add new message into queue for displaying.
561 565 *
562 - * @param string $message
563 - * @param string $type
564 - * @param array $options
566 + * @param string $message
567 + * @param string $type
568 + * @param array $options
565 569 * @param int|bool $current_user . @since 3.0.9 - add for current user only
570 + *
571 + * @deprecated 4.2.2.1
566 572 */
567 573 function learn_press_add_message( $message, $type = 'success', $options = array(), $current_user = true ) {
568 574 if ( is_string( $options ) ) {
569 575 $options = array( 'id' => $options );
@@ -606,11 +612,67 @@
606 612 return $message;
607 613 }
608 614
609 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 +/**
610 672 * Remove message added into queue by id and/or type.
611 673 *
612 - * @param string $id
674 + * @param string $id
613 675 * @param string|array $type
614 676 *
615 677 * @since 3.0.0
616 678 */
@@ -661,41 +723,12 @@
661 723 learn_press_session_set( learn_press_session_message_id(), array() );
662 724 }
663 725 }
664 726
665 -function learn_press_message_count( $type = '' ) {
666 - $count = 0;
667 - $messages = learn_press_session_get( learn_press_session_message_id(), array() );
668 -
669 - if ( isset( $messages[ $type ] ) ) {
670 - $count = absint( sizeof( $messages[ $type ] ) );
671 - } elseif ( empty( $type ) ) {
672 - foreach ( $messages as $message ) {
673 - $count += absint( sizeof( $message ) );
674 - }
675 - }
676 -
677 - return $count;
678 -}
679 -
680 727 function learn_press_session_message_id() {
681 728 return 'messages' . get_current_user_id();
682 729 }
683 730
684 -/**
685 - * Displays messages before main content
686 - */
687 -function _learn_press_print_messages() {
688 - $item = LP_Global::course_item();
689 - if ( ( 'learn_press_before_main_content' == current_action() ) && $item ) {
690 - return;
691 - }
692 - learn_press_print_messages( true );
693 -}
694 -
695 -add_action( 'learn_press_before_main_content', '_learn_press_print_messages', 50 );
696 -add_action( 'learn-press/before-course-item-content', '_learn_press_print_messages', 50 );
697 -
698 731 if ( ! function_exists( 'learn_press_page_title' ) ) {
699 732
700 733 /**
701 734 * learn_press_page_title function.
@@ -700,8 +733,9 @@
700 733 /**
701 734 * learn_press_page_title function.
702 735 *
703 736 * @param boolean $echo
737 + *
704 738 * @return string
705 739 */
706 740 function learn_press_page_title( bool $echo = false ): string {
707 741 $page_title = '';
@@ -724,25 +758,8 @@
724 758 }
725 759 }
726 760
727 761 /**
728 - * @depecated 4.1.6.4
729 - */
730 -function learn_press_template_redirect() {
731 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
732 - global $wp_query, $wp;
733 -
734 - // When default permalinks are enabled, redirect shop page to post type archive url
735 - if ( ! empty( $_GET['page_id'] ) && get_option( 'permalink_structure' ) == '' && $_GET['page_id'] == learn_press_get_page_id( 'courses' ) ) {
736 - wp_safe_redirect( get_post_type_archive_link( 'lp_course' ) );
737 - exit;
738 - }
739 -}
740 -
741 -// add_action( 'template_redirect', 'learn_press_template_redirect' );
742 -
743 -
744 -/**
745 762 * Get template part.
746 763 *
747 764 * @param string $slug
748 765 * @param string $name
@@ -804,9 +821,9 @@
804 821 /**
805 822 * Get other templates passing attributes and including the file.
806 823 *
807 824 * @param string $template_name .
808 - * @param array $args (default: array()) .
825 + * @param array $args (default: array()) .
809 826 * @param string $template_path (default: '').
810 827 * @param string $default_path (default: '').
811 828 *
812 829 * @return void
@@ -856,11 +873,11 @@
856 873 /**
857 874 * Get template content
858 875 *
859 876 * @param $template_name
860 - * @param array $args
861 - * @param string $template_path
862 - * @param string $default_path
877 + * @param array $args
878 + * @param string $template_path
879 + * @param string $default_path
863 880 *
864 881 * @return string
865 882 * @uses learn_press_get_template();
866 883 */
@@ -925,16 +942,21 @@
925 942 return apply_filters( 'learn_press_locate_template', $template, $template_name, $template_path );
926 943 }
927 944
928 945 /**
929 - * Returns the name of folder contains template files in theme
946 + * Returns the name of folder contains override template files in theme
930 947 *
931 - * @param bool
932 - *
933 948 * @return string
949 + * @since 3.0.0
950 + * @version 1.0.1
934 951 */
935 -function learn_press_template_path( $slash = false ) {
936 - 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;
937 959 }
938 960
939 961 /**
940 962 * Disable override templates in theme by default
@@ -945,17 +967,83 @@
945 967 function learn_press_override_templates() {
946 968 return apply_filters( 'learn-press/override-templates', false );
947 969 }
948 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 +
949 1036 if ( ! function_exists( 'learn_press_is_404' ) ) {
950 1037 /**
951 1038 * Set header is 404
1039 + * @deprecated 4.2.8
952 1040 */
953 1041 function learn_press_is_404() {
1042 + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1043 +
1044 + return;
954 1045 global $wp_query;
955 - if ( ! empty( $_REQUEST['debug-404'] ) ) {
956 - learn_press_debug( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $_REQUEST['debug-404'] ) );
957 - }
958 1046 $wp_query->set_404();
959 1047 status_header( 404 );
960 1048 }
961 1049 }
@@ -962,10 +1050,15 @@
962 1050
963 1051 if ( ! function_exists( 'learn_press_404_page' ) ) {
964 1052 /**
965 1053 * Display 404 page
1054 + *
1055 + * @deprecated 4.2.8
966 1056 */
967 1057 function learn_press_404_page() {
1058 + _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1059 +
1060 + return;
968 1061 learn_press_is_404();
969 1062 }
970 1063 }
971 1064
@@ -1021,15 +1114,18 @@
1021 1114 }
1022 1115 }
1023 1116 }
1024 1117
1025 -if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1118 +/**
1119 + * @deprecated 4.4.5
1120 + */
1121 +/*if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1026 1122 function learn_press_sort_course_tabs( $tabs = array() ) {
1027 1123 uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
1028 1124
1029 1125 return $tabs;
1030 1126 }
1031 -}
1127 +}*/
1032 1128
1033 1129 if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) {
1034 1130 /**
1035 1131 * Get Display name publicly as in Profile page
@@ -1058,51 +1154,8 @@
1058 1154 return $info ? $info->display_name : '';
1059 1155 }
1060 1156 }
1061 1157
1062 -/**
1063 - * @depecated 4.1.6.9
1064 - */
1065 -/*if ( ! function_exists( 'learn_press_content_item_comments' ) ) {
1066 - function learn_press_content_item_comments() {
1067 - $item = LP_Global::course_item();
1068 -
1069 - if ( ! $item ) {
1070 - return;
1071 - }
1072 -
1073 - if ( ! $item->is_support( 'comments' ) ) {
1074 - return;
1075 - }
1076 -
1077 - global $post;
1078 -
1079 - $post = get_post( $item->get_id() );
1080 -
1081 - setup_postdata( $post );
1082 -
1083 - if ( ! have_comments() ) {
1084 - return;
1085 - }
1086 -
1087 - add_filter( 'deprecated_file_trigger_error', '__return_false' );
1088 - comments_template();
1089 - remove_filter( 'deprecated_file_trigger_error', '__return_false' );
1090 -
1091 - wp_reset_postdata();
1092 - }
1093 -}*/
1094 -
1095 -function learn_press_course_comments_open( $open, $post_id ) {
1096 - $post = get_post( $post_id );
1097 -
1098 - if ( LP_COURSE_CPT == $post->post_type ) {
1099 - $open = false;
1100 - }
1101 -
1102 - return $open;
1103 -}
1104 -
1105 1158 function learn_press_is_content_item_only() {
1106 1159 return ! empty( $_REQUEST['content-item-only'] );
1107 1160 }
1108 1161
@@ -1114,74 +1167,16 @@
1114 1167 <?php
1115 1168 }
1116 1169
1117 1170 /**
1118 - * @depecated 4.1.6.4
1119 - */
1120 -function learn_press_get_course_redirect( $link ) {
1121 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
1122 - if ( empty( $_SERVER['HTTP_REFERER'] ) ) {
1123 - return $link;
1124 - }
1125 -
1126 - $referer = $_SERVER['HTTP_REFERER'];
1127 - $info_a = parse_url( $referer );
1128 - $info_b = parse_url( $link );
1129 -
1130 - $a = explode( '/', $info_a['path'] );
1131 - $a = array_filter( $a );
1132 -
1133 - $b = explode( '/', $info_b['path'] );
1134 - $b = array_filter( $b );
1135 -
1136 - $same = array_intersect_assoc( $a, $b );
1137 -
1138 - $a = array_diff_assoc( $a, $same );
1139 - $b = array_diff_assoc( $b, $same );
1140 -
1141 - $a = array_values( $a );
1142 - $b = array_values( $b );
1143 -
1144 - if ( array_shift( $a ) === 'popup' ) {
1145 - unset( $a[0] );
1146 -
1147 - if ( ! ( array_diff_assoc( $a, $b ) ) ) {
1148 - $link = '';
1149 - foreach ( array( 'scheme', 'host', 'port', 'path' ) as $v ) {
1150 - if ( ! isset( $info_a[ $v ] ) ) {
1151 - continue;
1152 - }
1153 -
1154 - if ( $v == 'scheme' ) {
1155 - $sep = '://';
1156 - } elseif ( $v == 'host' ) {
1157 - $sep = '';
1158 - } elseif ( $v == 'port' ) {
1159 - $link .= ':';
1160 - $sep = '';
1161 - } else {
1162 - $sep = '/';
1163 - }
1164 - $link = $link . $info_a[ $v ] . $sep;
1165 - }
1166 -
1167 - if ( ! empty( $info_b['query'] ) ) {
1168 - $link .= '?' . $info_b['query'];
1169 - }
1170 -
1171 - if ( ! empty( $info_b['fragment'] ) ) {
1172 - $link .= '#' . $info_b['fragment'];
1173 - }
1174 - }
1175 - }
1176 -
1177 - return $link;
1178 -}
1179 -
1180 -/**
1181 1171 * @param LP_Quiz $item
1172 + *
1173 + * @deprecated 4.2.3.5
1182 1174 */
1183 1175 function learn_press_quiz_meta_final( $item ) {
1176 + _deprecated_function( __METHOD__, '4.2.3.5' );
1177 +
1178 + return;
1184 1179 $course = learn_press_get_course();
1185 1180
1186 1181 if ( ! $course->is_final_quiz( $item->get_id() ) ) {
1187 1182 return;
@@ -1198,40 +1193,58 @@
1198 1193
1199 1194 return $comment_args;
1200 1195 }
1201 1196
1202 -if ( ! function_exists( 'learn_press_filter_get_comments_number' ) ) {
1203 - function learn_press_filter_get_comments_number( $count, $post_id = 0 ) {
1204 - global $wpdb;
1197 +add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' );
1205 1198
1206 - if ( ! $post_id ) {
1207 - $post_id = learn_press_get_course_id();
1208 - }
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 + }
1209 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();
1210 1224 if ( ! $post_id ) {
1211 1225 return $count;
1212 1226 }
1227 + }
1213 1228
1214 - if ( get_post_type( $post_id ) == LP_COURSE_CPT ) {
1215 - $sql = $wpdb->prepare(
1216 - ' SELECT count(*) '
1217 - . " FROM {$wpdb->comments} "
1218 - . ' WHERE comment_post_ID = %d '
1219 - . ' AND comment_approved = 1 '
1220 - . ' AND comment_type != %s ',
1221 - $post_id,
1222 - 'review'
1223 - );
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 + );
1224 1239
1225 - $count = $wpdb->get_var( $sql );
1240 + $count = $wpdb->get_var( $sql );
1241 + }
1226 1242
1227 - // @since 3.0.0
1228 - $count = apply_filters( 'learn-press/course-comments-number', $count, $post_id );
1229 - }
1243 + return $count;
1244 +}
1230 1245
1231 - return $count;
1232 - }
1233 -}
1246 +add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' );
1234 1247
1235 1248 /**
1236 1249 * Add custom classes to body tag class name
1237 1250 *
@@ -1239,34 +1252,22 @@
1239 1252 *
1240 1253 * @return array
1241 1254 *
1242 1255 * @since 3.0.0
1256 + * @Todo tungnx review to remove
1257 + * @deprecated 4.2.3
1243 1258 */
1244 1259 function learn_press_body_classes( $classes ) {
1245 - $pages = learn_press_static_page_ids();
1246 -
1247 - if ( $pages ) {
1248 - $is_lp_page = false;
1249 - settype( $classes, 'array' );
1250 -
1251 - foreach ( $pages as $slug => $id ) {
1252 - if ( is_page( $id ) ) {
1253 - $classes[] = $slug;
1254 - $is_lp_page = true;
1255 - }
1256 - }
1257 -
1258 - if ( $is_lp_page || is_learnpress() ) {
1259 - $classes[] = get_stylesheet();
1260 - $classes[] = 'learnpress';
1261 - $classes[] = 'learnpress-page';
1262 - }
1260 + if ( is_learnpress() ) {
1261 + $classes[] = get_stylesheet();
1262 + $classes[] = 'learnpress';
1263 + $classes[] = 'learnpress-page';
1263 1264 }
1264 1265
1265 1266 return $classes;
1266 1267 }
1267 1268
1268 -add_filter( 'body_class', 'learn_press_body_classes', 10 );
1269 +//add_filter( 'body_class', 'learn_press_body_classes', 10 );
1269 1270
1270 1271 /**
1271 1272 * Return true if user is learning a course
1272 1273 *
@@ -1271,87 +1272,31 @@
1271 1272 * Return true if user is learning a course
1272 1273 *
1273 1274 * @param int $course_id
1274 1275 *
1275 - * @return bool|mixed
1276 + * @return bool
1276 1277 * @since 3.0
1278 + * @version 1.0.1
1277 1279 */
1278 -function learn_press_is_learning_course( $course_id = 0 ) {
1280 +function learn_press_is_learning_course( int $course_id = 0 ): bool {
1281 + $is_learning = false;
1279 1282 $user = learn_press_get_current_user();
1280 1283 $course = learn_press_get_course( $course_id );
1281 - $is_learning = false;
1282 - $has_status = false;
1284 + if ( ! $course ) {
1285 + return $is_learning;
1286 + }
1283 1287
1284 - if ( $user && $course ) {
1285 - $has_status = $user->has_course_status(
1286 - $course->get_id(),
1287 - array(
1288 - 'enrolled',
1289 - 'finished',
1290 - )
1291 - );
1288 + if ( $user ) {
1289 + return $user->has_enrolled_or_finished( $course_id );
1292 1290 }
1293 1291
1294 - if ( $course && ( ! $course->is_required_enroll() || $has_status ) ) {
1292 + if ( $course->is_no_required_enroll() ) {
1295 1293 $is_learning = true;
1296 1294 }
1297 1295
1298 - return apply_filters( 'learn-press/is-learning-course', $is_learning );
1296 + return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
1299 1297 }
1300 1298
1301 -/**
1302 - * Output custom css from settings
1303 - *
1304 - * @since 4.0.0
1305 - */
1306 -if ( ! function_exists( 'learn_press_print_custom_styles' ) ) {
1307 - function learn_press_print_custom_styles() {
1308 - $primary_color = LP_Settings::instance()->get( 'primary_color' );
1309 - $secondary_color = LP_Settings::instance()->get( 'secondary_color' );
1310 - ?>
1311 -
1312 - <style id="learn-press-custom-css">
1313 - :root {
1314 - --lp-primary-color: <?php echo ! empty( $primary_color ) ? $primary_color : '#ffb606'; ?>;
1315 - --lp-secondary-color: <?php echo ! empty( $secondary_color ) ? $secondary_color : '#442e66'; ?>;
1316 - }
1317 - </style>
1318 -
1319 - <?php
1320 - }
1321 -
1322 - add_action( 'wp_head', 'learn_press_print_custom_styles' );
1323 -}
1324 -
1325 -/**
1326 - * Return TRUE if current user has already enroll course in single view.
1327 - *
1328 - * @return bool
1329 - * @since 3.0.0
1330 - * @editor tungnx
1331 - * @version 4.1.3
1332 - */
1333 -function learn_press_current_user_enrolled_course() {
1334 - _deprecated_function( __FUNCTION__, '4.1.3' );
1335 -}
1336 -
1337 -/**
1338 - * Check if an user can access content of a course.
1339 - *
1340 - * @param int $course_id
1341 - * @param int $user_id
1342 - *
1343 - * @return bool
1344 - * @since 3.x.x
1345 - * @editor tungnx
1346 - * @modify 4.1.3
1347 - * @reason comment - not use
1348 - */
1349 -
1350 -function learn_press_user_can_access_course( $course_id, $user_id = 0 ) {
1351 - _deprecated_function( __FUNCTION__, '4.1.2' );
1352 -}
1353 -
1354 1299 function learn_press_content_item_summary_class( $more = '', $echo = true ) {
1355 1300 $classes = array( 'content-item-summary' );
1356 1301 $classes = LP_Helper::merge_class( $classes, $more );
1357 1302 $classes = apply_filters( 'learn-press/content-item-summary-class', $classes );
@@ -1363,9 +1308,13 @@
1363 1308
1364 1309 return $output;
1365 1310 }
1366 1311
1312 +/**
1313 + * @deprecated 4.2.3.1
1314 + */
1367 1315 function learn_press_content_item_summary_classes( $classes ) {
1316 + _deprecated_function( __FUNCTION__, '4.2.3.1' );
1368 1317 $item = LP_Global::course_item();
1369 1318
1370 1319 if ( ! $item ) {
1371 1320 return $classes;
@@ -1397,10 +1346,10 @@
1397 1346 function learn_press_courses_layouts() {
1398 1347 return apply_filters(
1399 1348 'learnpress/archive-courses-layouts',
1400 1349 [
1401 - 'grid' => 'Grid',
1402 - 'list' => 'List',
1350 + 'grid' => __( 'Grid', 'learnpress' ),
1351 + 'list' => __( 'List', 'learnpress' ),
1403 1352 ]
1404 1353 );
1405 1354 }
1406 1355
@@ -1426,13 +1375,13 @@
1426 1375 register_sidebar(
1427 1376 array(
1428 1377 'name' => esc_html__( 'Course Sidebar', 'learnpress' ),
1429 1378 'id' => 'course-sidebar',
1430 - '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' ),
1431 1380 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1432 1381 'after_widget' => '</div>',
1433 - 'before_title' => '<h2 class="widgettitle">',
1434 - 'after_title' => '</h2>',
1382 + 'before_title' => '<h3 class="widget-title">',
1383 + 'after_title' => '</h3>',
1435 1384 )
1436 1385 );
1437 1386 register_sidebar(
1438 1387 array(
@@ -1437,13 +1386,13 @@
1437 1386 register_sidebar(
1438 1387 array(
1439 1388 'name' => esc_html__( 'All Courses', 'learnpress' ),
1440 1389 'id' => 'archive-courses-sidebar',
1441 - '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' ),
1442 1391 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1443 1392 'after_widget' => '</div>',
1444 - 'before_title' => '<h2 class="widgettitle">',
1445 - 'after_title' => '</h2>',
1393 + 'before_title' => '<h3 class="widget-title">',
1394 + 'after_title' => '</h3>',
1446 1395 )
1447 1396 );
1448 1397 }
1449 1398
@@ -1466,9 +1415,9 @@
1466 1415 add_action( 'after_setup_theme', 'learn_press_setup_theme' );
1467 1416
1468 1417 /**
1469 1418 * @param LP_Question $question
1470 - * @param array $args
1419 + * @param array $args
1471 1420 *
1472 1421 * @return array
1473 1422 * @since 4.x.x
1474 1423 */
@@ -1476,9 +1425,9 @@
1476 1425 $args = wp_parse_args(
1477 1426 $args,
1478 1427 array(
1479 1428 'cryptoJsAes' => false,
1480 - 'include_is_true' => true,
1429 + 'include_is_true' => false,
1481 1430 'answer' => false,
1482 1431 )
1483 1432 );
1484 1433
@@ -1516,9 +1465,9 @@
1516 1465
1517 1466 /**
1518 1467 * Get post meta with key _lp_duration and translate.
1519 1468 *
1520 - * @param int $post_id
1469 + * @param int $post_id
1521 1470 * @param string $default
1522 1471 *
1523 1472 * @return string
1524 1473 * @since 4.0.0
@@ -1583,9 +1532,9 @@
1583 1532 function lp_course_level() {
1584 1533 return apply_filters(
1585 1534 'lp/template/function/course/level',
1586 1535 array(
1587 - '' => esc_html__( 'All levels', 'learnpress' ),
1536 + 'all' => esc_html__( 'All levels', 'learnpress' ),
1588 1537 'beginner' => esc_html__( 'Beginner', 'learnpress' ),
1589 1538 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ),
1590 1539 'expert' => esc_html__( 'Expert', 'learnpress' ),
1591 1540 )
@@ -1591,14 +1540,8 @@
1591 1540 )
1592 1541 );
1593 1542 }
1594 1543
1595 -// function learn_press_is_preview_course() {
1596 -// $course_id = isset( $GLOBALS['preview_course'] ) ? $GLOBALS['preview_course'] : 0;
1597 -//
1598 -// return $course_id && get_post_type( $course_id ) === LP_COURSE_CPT;
1599 -// }
1600 -
1601 1544 /**
1602 1545 * Get slug for logout action in user profile.
1603 1546 *
1604 1547 * @return string
@@ -1623,9 +1566,9 @@
1623 1566 function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) {
1624 1567 ?>
1625 1568 <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>">
1626 1569 <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?>
1627 - <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>
1628 1571 <?php endfor; ?>
1629 1572 </ul>
1630 1573
1631 1574 <?php
@@ -1672,9 +1615,10 @@
1672 1615 if ( is_search() ) {
1673 1616 return;
1674 1617 }
1675 1618
1676 - 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 ) ) {
1677 1621 $profile_id = learn_press_get_page_id( 'courses' );
1678 1622
1679 1623 if ( $profile_id ) {
1680 1624 $profile_page = get_post( $profile_id );
@@ -1708,41 +1652,35 @@
1708 1652 *
1709 1653 * @return array
1710 1654 */
1711 1655 function lp_archive_skeleton_get_args(): array {
1712 - global $post, $wp;
1656 + $args = [];
1713 1657
1714 - $args = array();
1715 -
1716 1658 if ( ! empty( $_GET ) ) {
1717 - $args = (array) $_GET;
1659 + $args = $_GET;
1718 1660 }
1719 1661
1720 - $params = apply_filters(
1721 - 'lp/template/archive-course/skeleton/args',
1722 - array(
1723 - 'paged' => 1,
1724 - 'c_search' => '',
1725 - 'orderby' => '',
1726 - 'order' => '',
1727 - )
1728 - );
1662 + global $wp_query;
1663 + if ( ! empty( $wp_query->get( 'paged' ) ) ) {
1664 + $args['paged'] = $wp_query->get( 'paged' );
1665 + }
1729 1666
1730 1667 if ( learn_press_is_course_category() || learn_press_is_course_tag() ) {
1731 1668 $cat = get_queried_object();
1732 1669
1733 - $args['term_id'] = $cat->term_id;
1734 - $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 );
1735 1678 }
1736 1679
1737 - if ( learn_press_is_course_archive() ) {
1738 - foreach ( $params as $key => $param ) {
1739 - if ( isset( $_REQUEST[ $key ] ) ) {
1740 - $args[ $key ] = LP_Helper::sanitize_params_submitted( $_REQUEST[ $key ] );
1741 - } else {
1742 - $args[ $key ] = $param;
1743 - }
1744 - }
1680 + $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args );
1681 + if ( ! is_array( $args ) ) {
1682 + $args = [];
1745 1683 }
1746 1684
1747 - return $args;
1685 + return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' );
1748 1686 }