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
learnpress / inc / lp-template-functions.php

lp-template-functions.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at inc/lp-template-functions.php

1,687 lines 43.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * All functions for LearnPress template
4 *
5 * @author ThimPress
6 * @package LearnPress/Functions
7 * @version 1.0
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
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 if ( ! function_exists( 'learn_press_add_course_buttons' ) ) {
23 function learn_press_add_course_buttons() {
24 _deprecated_function( __FUNCTION__, '4.3.2.4' );
25 }
26 }
27
28 if ( ! function_exists( 'learn_press_remove_course_buttons' ) ) {
29 function learn_press_remove_course_buttons() {
30 _deprecated_function( __FUNCTION__, '4.3.2.4' );
31 }
32 }
33
34 if ( ! function_exists( 'learn_press_get_course_tabs' ) ) {
35 /**
36 * Return an array of tabs display in single course page.
37 *
38 * @return array
39 * @throws Exception
40 */
41 function learn_press_get_course_tabs() {
42 $courseModel = CourseModel::find( get_the_ID(), true );
43 if ( ! $courseModel ) {
44 return [];
45 }
46
47 $userModel = UserModel::find( get_current_user_id(), true );
48
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'] = [
56 'title' => esc_html__( 'Curriculum', 'learnpress' ),
57 'priority' => 30,
58 'callback' => function () use ( $courseModel, $userModel ) {
59 $singleCourseTemplate = SingleCourseTemplate::instance();
60 echo $singleCourseTemplate->html_curriculum( $courseModel, $userModel );
61 },
62 ];
63 $defaults['instructor'] = [
64 'title' => esc_html__( 'Instructor', 'learnpress' ),
65 'priority' => 40,
66 'callback' => LearnPress::instance()->template( 'course' )->callback( 'single-course/tabs/instructor.php' ),
67 ];
68
69 $faq = $courseModel->get_meta_value_by_key( CoursePostModel::META_KEY_FAQS, [] );
70 if ( ! empty( $faq ) ) {
71 $defaults['faqs'] = [
72 'title' => esc_html__( 'FAQs', 'learnpress' ),
73 'priority' => 50,
74 'callback' => function () use ( $courseModel ) {
75 $singleCourseTemplate = SingleCourseTemplate::instance();
76 echo $singleCourseTemplate->html_faqs( $courseModel, [ 'show_heading' => false ] );
77 },
78 ];
79 }
80
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 }
92
93 // @since 4.2.8.7.1 update new parameter $courseModel
94 $tabs = apply_filters( 'learn-press/course-tabs', $defaults, $courseModel );
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
110 foreach ( $tabs as $k => $v ) {
111 $v['id'] = $v['id'] ?? 'tab-' . $k;
112 if ( ! empty( $v['active'] ) ) {
113 $has_tab_active = true;
114 }
115
116 $tabs[ $k ] = $v;
117 }
118
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 ) {
124 $tabs[ $first_key ]['active'] = true;
125 }
126 }
127 }
128
129 return $tabs;
130 }
131 }
132
133 if ( ! function_exists( 'learn_press_content_item_summary_question' ) ) {
134 function learn_press_content_item_summary_question() {
135 $quiz = LP_Global::course_item_quiz();
136 $question = $quiz->get_viewing_question();
137
138 if ( $question ) {
139 $course = learn_press_get_course();
140 $user = learn_press_get_current_user();
141 $answered = false;
142 $course_data = $user->get_course_data( $course->get_id() );
143 $user_quiz = $course_data->get_item_quiz( $quiz->get_id() );
144
145 if ( $user_quiz ) {
146 $answered = $user_quiz->get_question_answer( $question->get_id() );
147 $question->show_correct_answers(
148 $user->has_checked_answer(
149 $question->get_id(),
150 $quiz->get_id(),
151 $course->get_id()
152 ) ? 'yes' : false
153 );
154 $question->disable_answers( $user_quiz->get_status() == 'completed' ? 'yes' : false );
155 }
156
157 $question->render( $answered );
158 }
159 }
160 }
161
162
163 if ( ! function_exists( 'learn_press_content_item_body_class' ) ) {
164 // Add more assets into page that displaying content of an item
165 add_filter( 'body_class', 'learn_press_content_item_body_class', 10 );
166
167 function learn_press_content_item_body_class( $classes ) {
168 global $lp_course_item;
169
170 if ( wp_is_mobile() ) {
171 $sidebar_toggle_class = 'lp-sidebar-toggle__close';
172 } else {
173 $sidebar_toggle_class = learn_press_cookie_get( 'sidebar-toggle' ) ? 'lp-sidebar-toggle__close' : 'lp-sidebar-toggle__open';
174 }
175
176 if ( $lp_course_item ) {
177 $classes[] = 'course-item-popup';
178 $classes[] = 'viewing-course-item';
179 $classes[] = 'viewing-course-item-' . $lp_course_item->get_id();
180 $classes[] = 'course-item-' . $lp_course_item->get_item_type();
181 $classes[] = $sidebar_toggle_class;
182 }
183
184 return $classes;
185 }
186 }
187
188 if ( ! function_exists( 'learn_press_content_item_edit_links' ) ) {
189 /**
190 * Add edit links for course item question to admin bar.
191 */
192 function learn_press_content_item_edit_links() {
193 global $wp_admin_bar, $post, $lp_course_item, $lp_quiz_question;
194
195 if ( ! ( ! is_admin() && is_user_logged_in() ) ) {
196 return;
197 }
198
199 /**
200 * Edit link for lesson/quiz or any other course's item.
201 */
202 if ( $lp_course_item ) {
203 $post_type_object = get_post_type_object( $lp_course_item->get_item_type() );
204
205 if ( $post_type_object && current_user_can(
206 'edit_post',
207 $lp_course_item->get_id()
208 ) && $post_type_object->show_in_admin_bar && get_edit_post_link( $lp_course_item->get_id() ) ) {
209 $type = get_post_type( $lp_course_item->get_id() );
210
211 if ( apply_filters( 'learn-press/edit-admin-bar-button', true, $lp_course_item ) ) {
212 $wp_admin_bar->add_menu(
213 array(
214 'id' => 'edit-' . $type,
215 'title' => $post_type_object->labels->edit_item,
216 'href' => get_edit_post_link( $lp_course_item->get_id() ),
217 )
218 );
219 }
220 }
221 }
222
223 /**
224 * Edit link for quiz's question.
225 */
226 if ( $lp_quiz_question ) {
227 $post_type_object = get_post_type_object( $lp_quiz_question->get_item_type() );
228 $edit_post_link = get_edit_post_link( $lp_quiz_question->get_id() );
229
230 if ( $post_type_object && current_user_can(
231 'edit_post',
232 $lp_quiz_question->get_id()
233 ) && $post_type_object->show_in_admin_bar && $edit_post_link ) {
234 $type = get_post_type( $lp_quiz_question->get_id() );
235 $wp_admin_bar->add_menu(
236 array(
237 'id' => 'edit-' . $type,
238 'title' => $post_type_object->labels->edit_item,
239 'href' => $edit_post_link,
240 )
241 );
242 }
243 }
244 }
245 }
246 add_filter( 'admin_bar_menu', 'learn_press_content_item_edit_links', 90 );
247
248 if ( ! function_exists( 'learn_press_single_quiz_args' ) ) {
249 function learn_press_single_quiz_args() {
250 $args = array();
251
252 if ( LP_PAGE_QUIZ !== LP_Page_Controller::page_current() ) {
253 return $args;
254 }
255
256 $quiz = LP_Global::course_item_quiz();
257 $course = learn_press_get_course();
258 $user = learn_press_get_current_user();
259 if ( $quiz && $course ) {
260 $course_id = $course->get_id();
261 //$user_quiz = $user->get_item_data( $quiz->get_id(), $course_id );
262
263 /*if ( $user_quiz ) {
264 $remaining_time = $user_quiz->get_time_remaining();
265 } else {
266 $remaining_time = false;
267 }*/
268
269 $args = array(
270 'id' => $quiz->get_id(),
271 //'totalTime' => -1,
272 //'remainingTime' => $remaining_time ? $remaining_time->get() : $quiz->get_duration()->get(),
273 'status' => $user->get_item_status( $quiz->get_id(), $course_id ),
274 'checkNorequizenroll' => $course->is_no_required_enroll(),
275 'navigationPosition' => LP_Settings::get_option( 'navigation_position', 'yes' ),
276 );
277 }
278
279 return apply_filters( 'learn-press/localize_script/quiz', $args, $user, $course, $quiz );
280 }
281 }
282
283 if ( ! function_exists( 'learn_press_single_document_title_parts' ) ) {
284 /**
285 * Custom document title depending on LP current page.
286 * E.g: Single course, profile, etc...
287 *
288 * @param array $title
289 *
290 * @return array
291 * @since 3.0.0
292 * @version 3.0.1
293 */
294 function learn_press_single_document_title_parts( $title ) {
295 if ( learn_press_is_course() ) {
296 $item = LP_Global::course_item();
297
298 if ( $item ) {
299 $title['title'] = join(
300 ' ',
301 apply_filters(
302 'learn-press/document-course-title-parts',
303 array(
304 $title['title'],
305 ' &rarr; ',
306 $item->get_title(),
307 )
308 )
309 );
310 }
311 } elseif ( learn_press_is_courses() ) {
312 if ( learn_press_is_search() ) {
313 $title['title'] = esc_html__( 'Course Search Results', 'learnpress' );
314 } else {
315 $title['title'] = esc_html__( 'Courses', 'learnpress' );
316 }
317 } elseif ( LP_Page_Controller::is_page_profile() ) {
318 $profile = LP_Profile::instance();
319 $tab_slug = $profile->get_current_tab();
320 $tab = $profile->get_tab_at( $tab_slug );
321 $page_id = learn_press_get_page_id( 'profile' );
322
323 if ( $page_id ) {
324 $page_title = get_the_title( $page_id );
325 } else {
326 $page_title = '';
327 }
328
329 if ( $tab instanceof LP_Profile_Tab ) {
330 $title['title'] = join(
331 ' ',
332 apply_filters(
333 'learn-press/document-profile-title-parts',
334 array(
335 $page_title,
336 '&rarr;',
337 $tab->get( 'title' ),
338 )
339 )
340 );
341 }
342 }
343
344 return $title;
345 }
346 }
347
348 // @deprecated 4.2.7.3
349 /*if ( ! function_exists( 'learn_press_course_item_class' ) ) {
350 function learn_press_course_item_class( $item_id, $course_id = 0, $class = null ) {
351 switch ( get_post_type( $item_id ) ) {
352 case 'lp_lesson':
353 learn_press_course_lesson_class( $item_id, $course_id, $class );
354 break;
355 case 'lp_quiz':
356 learn_press_course_quiz_class( $item_id, $course_id, $class );
357 break;
358 }
359 }
360 }*/
361
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 //}
428
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 //}
492
493 if ( ! function_exists( 'learn_press_course_class' ) ) {
494 /**
495 * Append new class to course post type
496 *
497 * @param $classes
498 * @param $class
499 * @param $post_id
500 *
501 * @return string
502 */
503 function learn_press_course_class( $classes, $class, $post_id = '' ) {
504 if ( is_learnpress() ) {
505 $classes = (array) $classes;
506 }
507
508 if ( $post_id === 0 ) {
509 $classes[] = 'page type-page';
510 }
511
512 if ( ! $post_id || 'lp_course' !== get_post_type( $post_id ) ) {
513 return $classes;
514 }
515
516 $classes[] = 'course';
517
518 return apply_filters( 'learn_press_course_class', $classes );
519 }
520 }
521
522 function learn_press_setup_user() {
523 $GLOBALS['lp_user'] = learn_press_get_current_user();
524 }
525
526 //add_action( 'init', 'learn_press_setup_user', 1000 );
527
528 /**
529 * Display a message immediately with out push into queue
530 *
531 * @param $message
532 * @param string $type
533 *
534 * @Todo tungnx review code.
535 */
536
537 function learn_press_display_message( $message, $type = 'success' ) {
538 $messages = learn_press_session_get( learn_press_session_message_id() );
539 learn_press_session_set( learn_press_session_message_id(), null );
540
541 // add new notice and display
542 learn_press_add_message( $message, $type );
543 echo learn_press_get_messages( true );
544
545 // store back messages
546 learn_press_session_set( learn_press_session_message_id(), $messages );
547 }
548
549 /**
550 * Returns all notices added
551 *
552 * @param bool $clear
553 *
554 * @return string
555 */
556 function learn_press_get_messages( $clear = false ) {
557 ob_start();
558 learn_press_print_messages( $clear );
559
560 return ob_get_clean();
561 }
562
563 /**
564 * Add new message into queue for displaying.
565 *
566 * @param string $message
567 * @param string $type
568 * @param array $options
569 * @param int|bool $current_user . @since 3.0.9 - add for current user only
570 *
571 * @deprecated 4.2.2.1
572 */
573 function learn_press_add_message( $message, $type = 'success', $options = array(), $current_user = true ) {
574 if ( is_string( $options ) ) {
575 $options = array( 'id' => $options );
576 }
577
578 $options = wp_parse_args(
579 $options,
580 array(
581 'id' => '',
582 )
583 );
584
585 if ( $current_user ) {
586 if ( true === $current_user ) {
587 $current_user = get_current_user_id();
588 }
589 }
590
591 $key = "messages{$current_user}";
592
593 $messages = learn_press_session_get( $key );
594
595 if ( empty( $messages[ $type ] ) ) {
596 $messages[ $type ] = array();
597 }
598
599 $messages[ $type ][ $options['id'] ] = array(
600 'content' => $message,
601 'options' => $options,
602 );
603
604 learn_press_session_set( $key, $messages );
605 }
606
607 function learn_press_get_message( $message, $type = 'success' ) {
608 ob_start();
609 learn_press_display_message( $message, $type );
610 $message = ob_get_clean();
611
612 return $message;
613 }
614
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 /**
672 * Remove message added into queue by id and/or type.
673 *
674 * @param string $id
675 * @param string|array $type
676 *
677 * @since 3.0.0
678 */
679 function learn_press_remove_message( $id = '', $type = '' ) {
680 $groups = learn_press_session_get( learn_press_session_message_id() );
681
682 if ( ! $groups ) {
683 return;
684 }
685
686 settype( $type, 'array' );
687
688 if ( $id ) {
689 foreach ( $groups as $message_type => $messages ) {
690 if ( ! sizeof( $type ) ) {
691 if ( isset( $groups[ $message_type ][ $id ] ) ) {
692 unset( $groups[ $message_type ][ $id ] );
693 }
694 } elseif ( in_array( $message_type, $type ) ) {
695 if ( isset( $groups[ $message_type ][ $id ] ) ) {
696 unset( $groups[ $message_type ][ $id ] );
697 }
698 }
699 }
700 } elseif ( sizeof( $type ) ) {
701 foreach ( $type as $t ) {
702 if ( isset( $groups[ $t ] ) ) {
703 unset( $groups[ $t ] );
704 }
705 }
706 } else {
707 $groups = array();
708 }
709
710 learn_press_session_set( learn_press_session_message_id(), $groups );
711 }
712
713 /**
714 * Print out the message stored in the queue
715 *
716 * @param bool
717 */
718 function learn_press_print_messages( $clear = true ) {
719 $messages = learn_press_session_get( learn_press_session_message_id() );
720 learn_press_get_template( 'global/message.php', array( 'messages' => $messages ) );
721
722 if ( $clear ) {
723 learn_press_session_set( learn_press_session_message_id(), array() );
724 }
725 }
726
727 function learn_press_session_message_id() {
728 return 'messages' . get_current_user_id();
729 }
730
731 if ( ! function_exists( 'learn_press_page_title' ) ) {
732
733 /**
734 * learn_press_page_title function.
735 *
736 * @param boolean $echo
737 *
738 * @return string
739 */
740 function learn_press_page_title( bool $echo = false ): string {
741 $page_title = '';
742
743 if ( is_search() ) {
744 // Comment by tungnx
745 /*$page_title = sprintf( __( 'Search Results for: &ldquo;%s&rdquo;', 'learnpress' ), get_search_query() );
746
747 if ( get_query_var( 'paged' ) ) {
748 $page_title .= sprintf( __( '&nbsp;&ndash; Page %s', 'learnpress' ), get_query_var( 'paged' ) );
749 }*/
750 } elseif ( is_tax() ) {
751 $page_title = single_term_title( '', false );
752 } else {
753 $courses_page_id = learn_press_get_page_id( 'courses' );
754 $page_title = get_the_title( $courses_page_id );
755 }
756
757 return apply_filters( 'learn_press_page_title', $page_title );
758 }
759 }
760
761 /**
762 * Get template part.
763 *
764 * @param string $slug
765 * @param string $name
766 *
767 * @return string
768 */
769 function learn_press_get_template_part( $slug, $name = '' ) {
770 $template = '';
771
772 if ( $name ) {
773 $template = locate_template(
774 array(
775 "{$slug}-{$name}.php",
776 learn_press_template_path() . "/{$slug}-{$name}.php",
777 )
778 );
779 }
780
781 // Get default slug-name.php
782 if ( ! $template && $name && file_exists( LP_PLUGIN_PATH . "/templates/{$slug}-{$name}.php" ) ) {
783 $template = LP_PLUGIN_PATH . "/templates/{$slug}-{$name}.php";
784 }
785
786 // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/learnpress/slug.php
787 if ( ! $template ) {
788 $template = locate_template( array( "{$slug}.php", learn_press_template_path() . "/{$slug}.php" ) );
789 }
790 // override path of child theme in parent theme - Fix for eduma by tuanta
791 $file_ct_in_pr = apply_filters( 'learn_press_child_in_parrent_template_path', '' );
792 if ( $file_ct_in_pr && $name ) {
793 $template_child = locate_template(
794 array(
795 "{$slug}-{$name}.php",
796 'lp-child-path/' . learn_press_template_path() . '/' . $file_ct_in_pr . "/{$slug}-{$name}.php",
797 )
798 );
799 if ( $template_child && file_exists( $template_child ) ) {
800 $template = $template_child;
801 }
802 // check in child theme if have filter learn_press_child_in_parrent_template_path
803
804 $check_child_theme = get_stylesheet_directory() . '/' . learn_press_template_path() . "{$slug}-{$name}.php";
805 if ( $check_child_theme && file_exists( $check_child_theme ) ) {
806 $template = $check_child_theme;
807 }
808 }
809
810 // Allow 3rd party plugin filter template file from their plugin
811 if ( $template ) {
812 $template = apply_filters( 'learn_press_get_template_part', $template, $slug, $name );
813 }
814 if ( $template && file_exists( $template ) ) {
815 load_template( $template, false );
816 }
817
818 return $template;
819 }
820
821 /**
822 * Get other templates passing attributes and including the file.
823 *
824 * @param string $template_name .
825 * @param array $args (default: array()) .
826 * @param string $template_path (default: '').
827 * @param string $default_path (default: '').
828 *
829 * @return void
830 */
831 function learn_press_get_template( $template_name = '', $args = array(), $template_path = '', $default_path = '' ) {
832 if ( $args && is_array( $args ) ) {
833 extract( $args );
834 }
835
836 if ( false === strpos( $template_name, '.php' ) ) {
837 $template_name .= '.php';
838 }
839
840 $located = learn_press_locate_template( $template_name, $template_path, $default_path );
841
842 if ( ! file_exists( $located ) ) {
843 _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
844
845 $log = sprintf( 'TEMPLATE MISSING: Template %s doesn\'t exists.', $template_name );
846 error_log( $log );
847
848 if ( LP_Debug::is_debug() ) {
849 echo sprintf( '<span title="%s" class="learn-press-template-warning"></span>', $log );
850 }
851
852 return;
853 }
854
855 // Allow 3rd party plugin filter template file from their plugin
856 $located = apply_filters(
857 'learn_press_get_template',
858 $located,
859 $template_name,
860 $args,
861 $template_path,
862 $default_path
863 );
864 if ( $located != '' ) {
865 do_action( 'learn_press_before_template_part', $template_name, $template_path, $located, $args );
866
867 include $located;
868
869 do_action( 'learn_press_after_template_part', $template_name, $template_path, $located, $args );
870 }
871 }
872
873 /**
874 * Get template content
875 *
876 * @param $template_name
877 * @param array $args
878 * @param string $template_path
879 * @param string $default_path
880 *
881 * @return string
882 * @uses learn_press_get_template();
883 */
884 function learn_press_get_template_content( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
885 ob_start();
886 learn_press_get_template( $template_name, $args, $template_path, $default_path );
887
888 return ob_get_clean();
889 }
890
891 /**
892 * Locate a template and return the path for inclusion.
893 *
894 * @param string $template_name
895 * @param string $template_path (default: '')
896 * @param string $default_path (default: '')
897 *
898 * @return string
899 */
900 function learn_press_locate_template( $template_name, $template_path = '', $default_path = '' ) {
901 if ( ! $template_path ) {
902 $template_path = learn_press_template_path();
903 }
904
905 if ( ! $default_path ) {
906 $default_path = LP_PLUGIN_PATH . 'templates/';
907 }
908
909 /**
910 * Disable override templates in theme by default since LP 4.0.0
911 */
912 if ( learn_press_override_templates() ) {
913 $template = locate_template(
914 array(
915 trailingslashit( $template_path ) . $template_name,
916 $template_name,
917 )
918 );
919 // override path of child theme in parent theme - Fix for eduma by tuanta
920 $file_ct_in_pr = apply_filters( 'learn_press_child_in_parrent_template_path', '' );
921 if ( $file_ct_in_pr ) {
922 $template_child = locate_template(
923 array(
924 trailingslashit( 'lp-child-path/' . $template_path . '/' . $file_ct_in_pr ) . $template_name,
925 $template_name,
926 )
927 );
928 if ( $template_child && file_exists( $template_child ) ) {
929 $template = $template_child;
930 }
931 // check in child theme if have filter learn_press_child_in_parrent_template_path
932 $check_child_theme = get_stylesheet_directory() . '/' . trailingslashit( $template_path ) . $template_name;
933 if ( $check_child_theme && file_exists( $check_child_theme ) ) {
934 $template = $check_child_theme;
935 }
936 }
937 }
938 if ( ! isset( $template ) || ! $template ) {
939 $template = trailingslashit( $default_path ) . $template_name;
940 }
941
942 return apply_filters( 'learn_press_locate_template', $template, $template_name, $template_path );
943 }
944
945 /**
946 * Returns the name of folder contains override template files in theme
947 *
948 * @return string
949 * @since 3.0.0
950 * @version 1.0.1
951 */
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;
959 }
960
961 /**
962 * Disable override templates in theme by default
963 *
964 * @return bool
965 * @since 4.0.0
966 */
967 function learn_press_override_templates() {
968 return apply_filters( 'learn-press/override-templates', false );
969 }
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
1036 if ( ! function_exists( 'learn_press_is_404' ) ) {
1037 /**
1038 * Set header is 404
1039 * @deprecated 4.2.8
1040 */
1041 function learn_press_is_404() {
1042 _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1043
1044 return;
1045 global $wp_query;
1046 $wp_query->set_404();
1047 status_header( 404 );
1048 }
1049 }
1050
1051 if ( ! function_exists( 'learn_press_404_page' ) ) {
1052 /**
1053 * Display 404 page
1054 *
1055 * @deprecated 4.2.8
1056 */
1057 function learn_press_404_page() {
1058 _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1059
1060 return;
1061 learn_press_is_404();
1062 }
1063 }
1064
1065 if ( ! function_exists( 'learn_press_generate_template_information' ) ) {
1066 function learn_press_generate_template_information( $template_name, $template_path, $located, $args ) {
1067 $debug = learn_press_get_request( 'show-template-location' );
1068 if ( $debug == 'on' ) {
1069 echo '<!-- Template Location:' . str_replace( array( LP_PLUGIN_PATH, ABSPATH ), '', $located ) . ' -->';
1070 }
1071 }
1072 }
1073
1074 if ( ! function_exists( 'learn_press_course_remaining_time' ) ) {
1075 /**
1076 * Show the time remain of a course
1077 */
1078 function learn_press_course_remaining_time() {
1079 $user = learn_press_get_current_user();
1080 if ( ! $user->has_finished_course( get_the_ID() ) && $text = learn_press_get_course( get_the_ID() )->get_user_duration_html( $user->get_id() ) ) {
1081 learn_press_display_message( $text );
1082 }
1083 }
1084 }
1085
1086 if ( ! function_exists( 'learn_press_item_meta_type' ) ) {
1087 function learn_press_item_meta_type( $course, $item ) {
1088 ?>
1089
1090 <?php if ( $item->post_type == 'lp_quiz' ) { ?>
1091
1092 <span class="lp-label lp-label-quiz"><?php _e( 'Quiz', 'learnpress' ); ?></span>
1093
1094 <?php if ( $course->final_quiz == $item->ID ) { ?>
1095
1096 <span class="lp-label lp-label-final"><?php _e( 'Final', 'learnpress' ); ?></span>
1097
1098 <?php } ?>
1099
1100 <?php } elseif ( $item->post_type == 'lp_lesson' ) { ?>
1101
1102 <span class="lp-label lp-label-lesson"><?php _e( 'Lesson', 'learnpress' ); ?></span>
1103 <?php if ( get_post_meta( $item->ID, '_lp_preview', true ) == 'yes' ) { ?>
1104
1105 <span class="lp-label lp-label-preview"><?php _e( 'Preview', 'learnpress' ); ?></span>
1106
1107 <?php } ?>
1108
1109 <?php } else { ?>
1110
1111 <?php do_action( 'learn_press_item_meta_type', $course, $item ); ?>
1112
1113 <?php
1114 }
1115 }
1116 }
1117
1118 /**
1119 * @deprecated 4.4.5
1120 */
1121 /*if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1122 function learn_press_sort_course_tabs( $tabs = array() ) {
1123 uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
1124
1125 return $tabs;
1126 }
1127 }*/
1128
1129 if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) {
1130 /**
1131 * Get Display name publicly as in Profile page
1132 */
1133 function learn_press_get_profile_display_name( $user ) {
1134 if ( empty( $user ) ) {
1135 return '';
1136 }
1137
1138 $id = '';
1139
1140 if ( $user instanceof LP_Abstract_User ) {
1141 $id = $user->get_id();
1142 } elseif ( $user instanceof WP_User ) {
1143 $id = $user->ID;
1144 } elseif ( is_numeric( $user ) ) {
1145 $id = $user;
1146 }
1147
1148 if ( ! isset( $id ) ) {
1149 return '';
1150 }
1151
1152 $info = get_userdata( $id );
1153
1154 return $info ? $info->display_name : '';
1155 }
1156 }
1157
1158 function learn_press_is_content_item_only() {
1159 return ! empty( $_REQUEST['content-item-only'] );
1160 }
1161
1162 function learn_press_label_html( $label, $type = '' ) {
1163 ?>
1164 <span class="lp-label label-<?php echo esc_attr( $type ? $type : $label ); ?>">
1165 <?php echo esc_html( $label ); ?>
1166 </span>
1167 <?php
1168 }
1169
1170 /**
1171 * @param LP_Quiz $item
1172 *
1173 * @deprecated 4.2.3.5
1174 */
1175 function learn_press_quiz_meta_final( $item ) {
1176 _deprecated_function( __METHOD__, '4.2.3.5' );
1177
1178 return;
1179 $course = learn_press_get_course();
1180
1181 if ( ! $course->is_final_quiz( $item->get_id() ) ) {
1182 return;
1183 }
1184 echo '<span class="item-meta final-quiz">' . esc_html__( 'Final', 'learnpress' ) . '</span>';
1185 }
1186
1187 function learn_press_comments_template_query_args( $comment_args ) {
1188 $post_type = get_post_type( $comment_args['post_id'] );
1189
1190 if ( $post_type == LP_COURSE_CPT ) {
1191 $comment_args['type__not_in'] = 'review';
1192 }
1193
1194 return $comment_args;
1195 }
1196
1197 add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' );
1198
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 }
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();
1224 if ( ! $post_id ) {
1225 return $count;
1226 }
1227 }
1228
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 );
1239
1240 $count = $wpdb->get_var( $sql );
1241 }
1242
1243 return $count;
1244 }
1245
1246 add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' );
1247
1248 /**
1249 * Add custom classes to body tag class name
1250 *
1251 * @param array $classes
1252 *
1253 * @return array
1254 *
1255 * @since 3.0.0
1256 * @Todo tungnx review to remove
1257 * @deprecated 4.2.3
1258 */
1259 function learn_press_body_classes( $classes ) {
1260 if ( is_learnpress() ) {
1261 $classes[] = get_stylesheet();
1262 $classes[] = 'learnpress';
1263 $classes[] = 'learnpress-page';
1264 }
1265
1266 return $classes;
1267 }
1268
1269 //add_filter( 'body_class', 'learn_press_body_classes', 10 );
1270
1271 /**
1272 * Return true if user is learning a course
1273 *
1274 * @param int $course_id
1275 *
1276 * @return bool
1277 * @since 3.0
1278 * @version 1.0.1
1279 */
1280 function learn_press_is_learning_course( int $course_id = 0 ): bool {
1281 $is_learning = false;
1282 $user = learn_press_get_current_user();
1283 $course = learn_press_get_course( $course_id );
1284 if ( ! $course ) {
1285 return $is_learning;
1286 }
1287
1288 if ( $user ) {
1289 return $user->has_enrolled_or_finished( $course_id );
1290 }
1291
1292 if ( $course->is_no_required_enroll() ) {
1293 $is_learning = true;
1294 }
1295
1296 return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
1297 }
1298
1299 function learn_press_content_item_summary_class( $more = '', $echo = true ) {
1300 $classes = array( 'content-item-summary' );
1301 $classes = LP_Helper::merge_class( $classes, $more );
1302 $classes = apply_filters( 'learn-press/content-item-summary-class', $classes );
1303 $output = 'class="' . esc_attr( join( ' ', $classes ) ) . '"';
1304
1305 if ( $echo ) {
1306 echo wp_kses_post( $output );
1307 }
1308
1309 return $output;
1310 }
1311
1312 /**
1313 * @deprecated 4.2.3.1
1314 */
1315 function learn_press_content_item_summary_classes( $classes ) {
1316 _deprecated_function( __FUNCTION__, '4.2.3.1' );
1317 $item = LP_Global::course_item();
1318
1319 if ( ! $item ) {
1320 return $classes;
1321 }
1322
1323 if ( $item->get_post_type() !== LP_LESSON_CPT ) {
1324 return $classes;
1325 }
1326
1327 return $classes;
1328 }
1329
1330 function learn_press_maybe_load_comment_js() {
1331 $item = LP_Global::course_item();
1332
1333 if ( $item ) {
1334 wp_enqueue_script( 'comment-reply' );
1335 }
1336 }
1337
1338 add_action( 'wp_enqueue_scripts', 'learn_press_maybe_load_comment_js' );
1339
1340 /**
1341 * Get list layouts archive course setting
1342 *
1343 * @editor tungnx
1344 * @modify 4.1.3
1345 */
1346 function learn_press_courses_layouts() {
1347 return apply_filters(
1348 'learnpress/archive-courses-layouts',
1349 [
1350 'grid' => __( 'Grid', 'learnpress' ),
1351 'list' => __( 'List', 'learnpress' ),
1352 ]
1353 );
1354 }
1355
1356 /**
1357 * Get layout template for archive course page.
1358 *
1359 * @return mixed
1360 * @since 3.3.0
1361 * @editor tungnx
1362 * @modify 4.1.3
1363 */
1364 function learn_press_get_courses_layout() {
1365 $layout = LP_Request::get_cookie( 'courses-layout' );
1366
1367 if ( ! $layout ) {
1368 $layout = LP_Settings::get_option( 'archive_courses_layout', 'list' );
1369 }
1370
1371 return $layout;
1372 }
1373
1374 function learn_press_register_sidebars() {
1375 register_sidebar(
1376 array(
1377 'name' => esc_html__( 'Course Sidebar', 'learnpress' ),
1378 'id' => 'course-sidebar',
1379 'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ),
1380 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1381 'after_widget' => '</div>',
1382 'before_title' => '<h3 class="widget-title">',
1383 'after_title' => '</h3>',
1384 )
1385 );
1386 register_sidebar(
1387 array(
1388 'name' => esc_html__( 'All Courses', 'learnpress' ),
1389 'id' => 'archive-courses-sidebar',
1390 'description' => esc_html__( 'Widgets in this area will be shown on all course pages', 'learnpress' ),
1391 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1392 'after_widget' => '</div>',
1393 'before_title' => '<h3 class="widget-title">',
1394 'after_title' => '</h3>',
1395 )
1396 );
1397 }
1398
1399 add_action( 'widgets_init', 'learn_press_register_sidebars' );
1400
1401 function learn_press_setup_theme() {
1402 $support = array(
1403 'widgets' => array(
1404 // Place three core-defined widgets in the sidebar area.
1405 'course-sidebar' => array(
1406 'xxx' => array( 'lp-widget-course-progress' ),
1407 'yyy' => array( 'lp-widget-course-info' ),
1408 ),
1409 ),
1410 );
1411
1412 add_theme_support( 'starter-content', $support );
1413 }
1414
1415 add_action( 'after_setup_theme', 'learn_press_setup_theme' );
1416
1417 /**
1418 * @param LP_Question $question
1419 * @param array $args
1420 *
1421 * @return array
1422 * @since 4.x.x
1423 */
1424 function learn_press_get_question_options_for_js( $question, $args = array() ) {
1425 $args = wp_parse_args(
1426 $args,
1427 array(
1428 'cryptoJsAes' => false,
1429 'include_is_true' => false,
1430 'answer' => false,
1431 )
1432 );
1433
1434 if ( $args['cryptoJsAes'] ) {
1435 $options = array_values( $question->get_answer_options() );
1436
1437 $key = uniqid();
1438 $options = array(
1439 'data' => cryptoJsAesEncrypt( $key, wp_json_encode( $options ) ),
1440 'key' => $key,
1441 );
1442 } else {
1443 $exclude_option_key = array( 'question_id', 'order' );
1444 if ( ! $args['include_is_true'] ) {
1445 $exclude_option_key[] = 'is_true';
1446 }
1447
1448 $options = array_values(
1449 $question->get_answer_options(
1450 array(
1451 'exclude' => $exclude_option_key,
1452 'map' => array( 'question_answer_id' => 'uid' ),
1453 'answer' => $args['answer'],
1454 )
1455 )
1456 );
1457 }
1458
1459 return $options;
1460 }
1461
1462 function learn_press_custom_excerpt_length( $length ) {
1463 return 20;
1464 }
1465
1466 /**
1467 * Get post meta with key _lp_duration and translate.
1468 *
1469 * @param int $post_id
1470 * @param string $default
1471 *
1472 * @return string
1473 * @since 4.0.0
1474 */
1475 function learn_press_get_post_translated_duration( $post_id, $default = '' ) {
1476 $duration = get_post_meta( $post_id, '_lp_duration', true );
1477
1478 $duration_arr = explode( ' ', $duration );
1479 $duration_str = '';
1480
1481 if ( count( $duration_arr ) > 1 ) {
1482 $duration_number = $duration_arr[0];
1483 $duration_text = $duration_arr[1];
1484
1485 switch ( strtolower( $duration_text ) ) {
1486 case 'minute':
1487 $duration_str = sprintf(
1488 _n( '%s minute', '%s minutes', $duration_number, 'learnpress' ),
1489 $duration_number
1490 );
1491 break;
1492 case 'hour':
1493 $duration_str = sprintf(
1494 _n( '%s hour', '%s hours', $duration_number, 'learnpress' ),
1495 $duration_number
1496 );
1497 break;
1498 case 'day':
1499 $duration_str = sprintf( _n( '%s day', '%s days', $duration_number, 'learnpress' ), $duration_number );
1500 break;
1501 case 'week':
1502 $duration_str = sprintf(
1503 _n( '%s week', '%s weeks', $duration_number, 'learnpress' ),
1504 $duration_number
1505 );
1506 break;
1507 default:
1508 $duration_str = $duration;
1509 }
1510 }
1511
1512 return empty( absint( $duration ) ) ? $default : $duration_str;
1513 }
1514
1515 /**
1516 * Get level post meta.
1517 *
1518 * @param int $post_id
1519 *
1520 * @return string
1521 */
1522 function learn_press_get_post_level( $post_id ) {
1523 $level = get_post_meta( $post_id, '_lp_level', true );
1524
1525 return apply_filters(
1526 'learn-press/level-label',
1527 ! empty( $level ) ? lp_course_level()[ $level ] : esc_html__( 'All levels', 'learnpress' ),
1528 $post_id
1529 );
1530 }
1531
1532 function lp_course_level() {
1533 return apply_filters(
1534 'lp/template/function/course/level',
1535 array(
1536 'all' => esc_html__( 'All levels', 'learnpress' ),
1537 'beginner' => esc_html__( 'Beginner', 'learnpress' ),
1538 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ),
1539 'expert' => esc_html__( 'Expert', 'learnpress' ),
1540 )
1541 );
1542 }
1543
1544 /**
1545 * Get slug for logout action in user profile.
1546 *
1547 * @return string
1548 * @since 4.0.0
1549 */
1550 function learn_press_profile_logout_slug() {
1551 return apply_filters( 'learn-press/profile-logout-slug', 'lp-logout' );
1552 }
1553
1554 function lp_get_email_content( $format, $meta = array(), $field = array() ) {
1555 if ( $meta && isset( $meta[ $format ] ) ) {
1556 $content = stripslashes( $meta[ $format ] );
1557 } else {
1558 $template = ! empty( $field[ "template_{$format}" ] ) ? $field[ "template_{$format}" ] : null;
1559 $template_file = $field['template_base'] . $template;
1560 $content = LP_WP_Filesystem::instance()->file_get_contents( $template_file );
1561 }
1562
1563 return $content;
1564 }
1565
1566 function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) {
1567 ?>
1568 <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>">
1569 <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?>
1570 <li style="width: <?php echo esc_attr( $width === 'random' ? wp_rand( 90, 100 ) . '%' : $width ); ?>; <?php echo ! empty( $styleli ) ? $styleli : ''; ?>"></li>
1571 <?php endfor; ?>
1572 </ul>
1573
1574 <?php
1575 }
1576
1577 add_filter( 'lp_format_page_content', 'wptexturize' );
1578 add_filter( 'lp_format_page_content', 'convert_smilies' );
1579 add_filter( 'lp_format_page_content', 'convert_chars' );
1580 add_filter( 'lp_format_page_content', 'wpautop' );
1581 add_filter( 'lp_format_page_content', 'shortcode_unautop' );
1582 add_filter( 'lp_format_page_content', 'prepend_attachment' );
1583 add_filter( 'lp_format_page_content', 'do_shortcode', 11 );
1584 add_filter( 'lp_format_page_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
1585
1586 if ( function_exists( 'do_blocks' ) ) {
1587 add_filter( 'lp_format_page_content', 'do_blocks', 9 );
1588 }
1589
1590 function lp_format_page_content( $raw_string ) {
1591 return apply_filters( 'lp_format_page_content', $raw_string );
1592 }
1593
1594 if ( ! function_exists( 'lp_profile_page_content' ) ) {
1595 function lp_profile_page_content() {
1596 $profile_id = learn_press_get_page_id( 'profile' );
1597
1598 if ( $profile_id ) {
1599 $profile_page = get_post( $profile_id );
1600
1601 // remove_shortcode( 'learn_press_profile' );
1602 $description = lp_format_page_content( wp_kses_post( $profile_page->post_content ) );
1603
1604 if ( $description ) {
1605 echo '<div class="lp-profile-page__content">' . $description . '</div>';
1606 }
1607 }
1608 }
1609 }
1610
1611 if ( ! function_exists( 'lp_archive_course_page_content' ) ) {
1612 add_action( 'lp/template/archive-course/description', 'lp_archive_course_page_content' );
1613
1614 function lp_archive_course_page_content() {
1615 if ( is_search() ) {
1616 return;
1617 }
1618
1619 if ( is_post_type_archive( LP_COURSE_CPT )
1620 && in_array( absint( get_query_var( 'paged' ) ), array( 0, 1 ), true ) ) {
1621 $profile_id = learn_press_get_page_id( 'courses' );
1622
1623 if ( $profile_id ) {
1624 $profile_page = get_post( $profile_id );
1625
1626 $description = lp_format_page_content( wp_kses_post( $profile_page->post_content ) );
1627 if ( $description ) {
1628 echo '<div class="lp-course-page__content">' . $description . '</div>';
1629 }
1630 }
1631 }
1632 }
1633 }
1634
1635 if ( ! function_exists( 'lp_taxonomy_archive_course_description' ) ) {
1636 add_action( 'lp/template/archive-course/description', 'lp_taxonomy_archive_course_description' );
1637
1638 function lp_taxonomy_archive_course_description() {
1639
1640 if ( learn_press_is_course_tax() && 0 === absint( get_query_var( 'paged' ) ) ) {
1641 $term = get_queried_object();
1642
1643 if ( $term && ! empty( $term->description ) ) {
1644 echo '<div class="lp-archive-course-term-description">' . lp_format_page_content( wp_kses_post( $term->description ) ) . '</div>';
1645 }
1646 }
1647 }
1648 }
1649
1650 /**
1651 * Params to query courses on Archive Course.
1652 *
1653 * @return array
1654 */
1655 function lp_archive_skeleton_get_args(): array {
1656 $args = [];
1657
1658 if ( ! empty( $_GET ) ) {
1659 $args = $_GET;
1660 }
1661
1662 global $wp_query;
1663 if ( ! empty( $wp_query->get( 'paged' ) ) ) {
1664 $args['paged'] = $wp_query->get( 'paged' );
1665 }
1666
1667 if ( learn_press_is_course_category() || learn_press_is_course_tag() ) {
1668 $cat = get_queried_object();
1669
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 );
1678 }
1679
1680 $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args );
1681 if ( ! is_array( $args ) ) {
1682 $args = [];
1683 }
1684
1685 return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' );
1686 }
1687