PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.5
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.5
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.5, at inc/lp-template-functions.php

1,683 lines 43.2 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.0
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 } catch ( Throwable $e ) {
661 error_log( $e->getMessage() );
662 }
663 }
664
665 add_action( 'learn-press/before-course-item-content', 'learn_press_show_message', 50 );
666
667 /**
668 * Remove message added into queue by id and/or type.
669 *
670 * @param string $id
671 * @param string|array $type
672 *
673 * @since 3.0.0
674 */
675 function learn_press_remove_message( $id = '', $type = '' ) {
676 $groups = learn_press_session_get( learn_press_session_message_id() );
677
678 if ( ! $groups ) {
679 return;
680 }
681
682 settype( $type, 'array' );
683
684 if ( $id ) {
685 foreach ( $groups as $message_type => $messages ) {
686 if ( ! sizeof( $type ) ) {
687 if ( isset( $groups[ $message_type ][ $id ] ) ) {
688 unset( $groups[ $message_type ][ $id ] );
689 }
690 } elseif ( in_array( $message_type, $type ) ) {
691 if ( isset( $groups[ $message_type ][ $id ] ) ) {
692 unset( $groups[ $message_type ][ $id ] );
693 }
694 }
695 }
696 } elseif ( sizeof( $type ) ) {
697 foreach ( $type as $t ) {
698 if ( isset( $groups[ $t ] ) ) {
699 unset( $groups[ $t ] );
700 }
701 }
702 } else {
703 $groups = array();
704 }
705
706 learn_press_session_set( learn_press_session_message_id(), $groups );
707 }
708
709 /**
710 * Print out the message stored in the queue
711 *
712 * @param bool
713 */
714 function learn_press_print_messages( $clear = true ) {
715 $messages = learn_press_session_get( learn_press_session_message_id() );
716 learn_press_get_template( 'global/message.php', array( 'messages' => $messages ) );
717
718 if ( $clear ) {
719 learn_press_session_set( learn_press_session_message_id(), array() );
720 }
721 }
722
723 function learn_press_session_message_id() {
724 return 'messages' . get_current_user_id();
725 }
726
727 if ( ! function_exists( 'learn_press_page_title' ) ) {
728
729 /**
730 * learn_press_page_title function.
731 *
732 * @param boolean $echo
733 *
734 * @return string
735 */
736 function learn_press_page_title( bool $echo = false ): string {
737 $page_title = '';
738
739 if ( is_search() ) {
740 // Comment by tungnx
741 /*$page_title = sprintf( __( 'Search Results for: &ldquo;%s&rdquo;', 'learnpress' ), get_search_query() );
742
743 if ( get_query_var( 'paged' ) ) {
744 $page_title .= sprintf( __( '&nbsp;&ndash; Page %s', 'learnpress' ), get_query_var( 'paged' ) );
745 }*/
746 } elseif ( is_tax() ) {
747 $page_title = single_term_title( '', false );
748 } else {
749 $courses_page_id = learn_press_get_page_id( 'courses' );
750 $page_title = get_the_title( $courses_page_id );
751 }
752
753 return apply_filters( 'learn_press_page_title', $page_title );
754 }
755 }
756
757 /**
758 * Get template part.
759 *
760 * @param string $slug
761 * @param string $name
762 *
763 * @return string
764 */
765 function learn_press_get_template_part( $slug, $name = '' ) {
766 $template = '';
767
768 if ( $name ) {
769 $template = locate_template(
770 array(
771 "{$slug}-{$name}.php",
772 learn_press_template_path() . "/{$slug}-{$name}.php",
773 )
774 );
775 }
776
777 // Get default slug-name.php
778 if ( ! $template && $name && file_exists( LP_PLUGIN_PATH . "/templates/{$slug}-{$name}.php" ) ) {
779 $template = LP_PLUGIN_PATH . "/templates/{$slug}-{$name}.php";
780 }
781
782 // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/learnpress/slug.php
783 if ( ! $template ) {
784 $template = locate_template( array( "{$slug}.php", learn_press_template_path() . "/{$slug}.php" ) );
785 }
786 // override path of child theme in parent theme - Fix for eduma by tuanta
787 $file_ct_in_pr = apply_filters( 'learn_press_child_in_parrent_template_path', '' );
788 if ( $file_ct_in_pr && $name ) {
789 $template_child = locate_template(
790 array(
791 "{$slug}-{$name}.php",
792 'lp-child-path/' . learn_press_template_path() . '/' . $file_ct_in_pr . "/{$slug}-{$name}.php",
793 )
794 );
795 if ( $template_child && file_exists( $template_child ) ) {
796 $template = $template_child;
797 }
798 // check in child theme if have filter learn_press_child_in_parrent_template_path
799
800 $check_child_theme = get_stylesheet_directory() . '/' . learn_press_template_path() . "{$slug}-{$name}.php";
801 if ( $check_child_theme && file_exists( $check_child_theme ) ) {
802 $template = $check_child_theme;
803 }
804 }
805
806 // Allow 3rd party plugin filter template file from their plugin
807 if ( $template ) {
808 $template = apply_filters( 'learn_press_get_template_part', $template, $slug, $name );
809 }
810 if ( $template && file_exists( $template ) ) {
811 load_template( $template, false );
812 }
813
814 return $template;
815 }
816
817 /**
818 * Get other templates passing attributes and including the file.
819 *
820 * @param string $template_name .
821 * @param array $args (default: array()) .
822 * @param string $template_path (default: '').
823 * @param string $default_path (default: '').
824 *
825 * @return void
826 */
827 function learn_press_get_template( $template_name = '', $args = array(), $template_path = '', $default_path = '' ) {
828 if ( $args && is_array( $args ) ) {
829 extract( $args );
830 }
831
832 if ( false === strpos( $template_name, '.php' ) ) {
833 $template_name .= '.php';
834 }
835
836 $located = learn_press_locate_template( $template_name, $template_path, $default_path );
837
838 if ( ! file_exists( $located ) ) {
839 _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
840
841 $log = sprintf( 'TEMPLATE MISSING: Template %s doesn\'t exists.', $template_name );
842 error_log( $log );
843
844 if ( LP_Debug::is_debug() ) {
845 echo sprintf( '<span title="%s" class="learn-press-template-warning"></span>', $log );
846 }
847
848 return;
849 }
850
851 // Allow 3rd party plugin filter template file from their plugin
852 $located = apply_filters(
853 'learn_press_get_template',
854 $located,
855 $template_name,
856 $args,
857 $template_path,
858 $default_path
859 );
860 if ( $located != '' ) {
861 do_action( 'learn_press_before_template_part', $template_name, $template_path, $located, $args );
862
863 include $located;
864
865 do_action( 'learn_press_after_template_part', $template_name, $template_path, $located, $args );
866 }
867 }
868
869 /**
870 * Get template content
871 *
872 * @param $template_name
873 * @param array $args
874 * @param string $template_path
875 * @param string $default_path
876 *
877 * @return string
878 * @uses learn_press_get_template();
879 */
880 function learn_press_get_template_content( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
881 ob_start();
882 learn_press_get_template( $template_name, $args, $template_path, $default_path );
883
884 return ob_get_clean();
885 }
886
887 /**
888 * Locate a template and return the path for inclusion.
889 *
890 * @param string $template_name
891 * @param string $template_path (default: '')
892 * @param string $default_path (default: '')
893 *
894 * @return string
895 */
896 function learn_press_locate_template( $template_name, $template_path = '', $default_path = '' ) {
897 if ( ! $template_path ) {
898 $template_path = learn_press_template_path();
899 }
900
901 if ( ! $default_path ) {
902 $default_path = LP_PLUGIN_PATH . 'templates/';
903 }
904
905 /**
906 * Disable override templates in theme by default since LP 4.0.0
907 */
908 if ( learn_press_override_templates() ) {
909 $template = locate_template(
910 array(
911 trailingslashit( $template_path ) . $template_name,
912 $template_name,
913 )
914 );
915 // override path of child theme in parent theme - Fix for eduma by tuanta
916 $file_ct_in_pr = apply_filters( 'learn_press_child_in_parrent_template_path', '' );
917 if ( $file_ct_in_pr ) {
918 $template_child = locate_template(
919 array(
920 trailingslashit( 'lp-child-path/' . $template_path . '/' . $file_ct_in_pr ) . $template_name,
921 $template_name,
922 )
923 );
924 if ( $template_child && file_exists( $template_child ) ) {
925 $template = $template_child;
926 }
927 // check in child theme if have filter learn_press_child_in_parrent_template_path
928 $check_child_theme = get_stylesheet_directory() . '/' . trailingslashit( $template_path ) . $template_name;
929 if ( $check_child_theme && file_exists( $check_child_theme ) ) {
930 $template = $check_child_theme;
931 }
932 }
933 }
934 if ( ! isset( $template ) || ! $template ) {
935 $template = trailingslashit( $default_path ) . $template_name;
936 }
937
938 return apply_filters( 'learn_press_locate_template', $template, $template_name, $template_path );
939 }
940
941 /**
942 * Returns the name of folder contains override template files in theme
943 *
944 * @return string
945 * @since 3.0.0
946 * @version 1.0.1
947 */
948 function learn_press_template_path(): string {
949 $lp_folder_name_override = apply_filters( 'learn_press_template_path', LP_PLUGIN_FOLDER_NAME );
950 if ( ! is_string( $lp_folder_name_override ) ) {
951 $lp_folder_name_override = LP_PLUGIN_FOLDER_NAME;
952 }
953
954 return $lp_folder_name_override;
955 }
956
957 /**
958 * Disable override templates in theme by default
959 *
960 * @return bool
961 * @since 4.0.0
962 */
963 function learn_press_override_templates() {
964 return apply_filters( 'learn-press/override-templates', false );
965 }
966
967 /**
968 * Get html view path for admin to display
969 *
970 * @param $name
971 * @param $plugin_file
972 *
973 * @return mixed
974 */
975 function learn_press_get_admin_view( $name, $plugin_file = null ) {
976 if ( ! preg_match( '/\.(html|php)$/', $name ) ) {
977 $name .= '.php';
978 }
979 if ( $plugin_file ) {
980 $view = dirname( $plugin_file ) . '/inc/admin/views/' . $name;
981 } else {
982 $view = LearnPress::instance()->plugin_path( 'inc/admin/views/' . $name );
983 }
984
985 return apply_filters( 'learn_press_admin_view', $view, $name );
986 }
987
988 function learn_press_admin_view_content( $name, $args = array() ) {
989 return learn_press_admin_view( $name, $args, false, true );
990 }
991
992 /**
993 * Find a full path of a view and display the content in admin
994 *
995 * @param $name
996 * @param array $args
997 * @param bool|false $include_once
998 * @param bool
999 *
1000 * @return bool
1001 */
1002 function learn_press_admin_view( $name, $args = array(), $include_once = false, $return = false ) {
1003 $view = learn_press_get_admin_view( $name, ! empty( $args['plugin_file'] ) ? $args['plugin_file'] : null );
1004
1005 if ( file_exists( $view ) ) {
1006
1007 ob_start();
1008
1009 is_array( $args ) && extract( $args );
1010
1011 do_action( 'learn_press_before_display_admin_view', $name, $args );
1012
1013 if ( $include_once ) {
1014 include_once $view;
1015 } else {
1016 include $view;
1017 }
1018
1019 do_action( 'learn_press_after_display_admin_view', $name, $args );
1020 $output = ob_get_clean();
1021
1022 if ( ! $return ) {
1023 learn_press_echo_vuejs_write_on_php( $output );
1024 }
1025
1026 return $return ? $output : true;
1027 }
1028
1029 return false;
1030 }
1031
1032 if ( ! function_exists( 'learn_press_is_404' ) ) {
1033 /**
1034 * Set header is 404
1035 * @deprecated 4.2.8
1036 */
1037 function learn_press_is_404() {
1038 _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1039
1040 return;
1041 global $wp_query;
1042 $wp_query->set_404();
1043 status_header( 404 );
1044 }
1045 }
1046
1047 if ( ! function_exists( 'learn_press_404_page' ) ) {
1048 /**
1049 * Display 404 page
1050 *
1051 * @deprecated 4.2.8
1052 */
1053 function learn_press_404_page() {
1054 _deprecated_function( __FUNCTION__, '4.2.8', 'LP_Page_Controller::set_page_404' );
1055
1056 return;
1057 learn_press_is_404();
1058 }
1059 }
1060
1061 if ( ! function_exists( 'learn_press_generate_template_information' ) ) {
1062 function learn_press_generate_template_information( $template_name, $template_path, $located, $args ) {
1063 $debug = learn_press_get_request( 'show-template-location' );
1064 if ( $debug == 'on' ) {
1065 echo '<!-- Template Location:' . str_replace( array( LP_PLUGIN_PATH, ABSPATH ), '', $located ) . ' -->';
1066 }
1067 }
1068 }
1069
1070 if ( ! function_exists( 'learn_press_course_remaining_time' ) ) {
1071 /**
1072 * Show the time remain of a course
1073 */
1074 function learn_press_course_remaining_time() {
1075 $user = learn_press_get_current_user();
1076 if ( ! $user->has_finished_course( get_the_ID() ) && $text = learn_press_get_course( get_the_ID() )->get_user_duration_html( $user->get_id() ) ) {
1077 learn_press_display_message( $text );
1078 }
1079 }
1080 }
1081
1082 if ( ! function_exists( 'learn_press_item_meta_type' ) ) {
1083 function learn_press_item_meta_type( $course, $item ) {
1084 ?>
1085
1086 <?php if ( $item->post_type == 'lp_quiz' ) { ?>
1087
1088 <span class="lp-label lp-label-quiz"><?php _e( 'Quiz', 'learnpress' ); ?></span>
1089
1090 <?php if ( $course->final_quiz == $item->ID ) { ?>
1091
1092 <span class="lp-label lp-label-final"><?php _e( 'Final', 'learnpress' ); ?></span>
1093
1094 <?php } ?>
1095
1096 <?php } elseif ( $item->post_type == 'lp_lesson' ) { ?>
1097
1098 <span class="lp-label lp-label-lesson"><?php _e( 'Lesson', 'learnpress' ); ?></span>
1099 <?php if ( get_post_meta( $item->ID, '_lp_preview', true ) == 'yes' ) { ?>
1100
1101 <span class="lp-label lp-label-preview"><?php _e( 'Preview', 'learnpress' ); ?></span>
1102
1103 <?php } ?>
1104
1105 <?php } else { ?>
1106
1107 <?php do_action( 'learn_press_item_meta_type', $course, $item ); ?>
1108
1109 <?php
1110 }
1111 }
1112 }
1113
1114 /**
1115 * @deprecated 4.4.5
1116 */
1117 /*if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1118 function learn_press_sort_course_tabs( $tabs = array() ) {
1119 uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
1120
1121 return $tabs;
1122 }
1123 }*/
1124
1125 if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) {
1126 /**
1127 * Get Display name publicly as in Profile page
1128 */
1129 function learn_press_get_profile_display_name( $user ) {
1130 if ( empty( $user ) ) {
1131 return '';
1132 }
1133
1134 $id = '';
1135
1136 if ( $user instanceof LP_Abstract_User ) {
1137 $id = $user->get_id();
1138 } elseif ( $user instanceof WP_User ) {
1139 $id = $user->ID;
1140 } elseif ( is_numeric( $user ) ) {
1141 $id = $user;
1142 }
1143
1144 if ( ! isset( $id ) ) {
1145 return '';
1146 }
1147
1148 $info = get_userdata( $id );
1149
1150 return $info ? $info->display_name : '';
1151 }
1152 }
1153
1154 function learn_press_is_content_item_only() {
1155 return ! empty( $_REQUEST['content-item-only'] );
1156 }
1157
1158 function learn_press_label_html( $label, $type = '' ) {
1159 ?>
1160 <span class="lp-label label-<?php echo esc_attr( $type ? $type : $label ); ?>">
1161 <?php echo esc_html( $label ); ?>
1162 </span>
1163 <?php
1164 }
1165
1166 /**
1167 * @param LP_Quiz $item
1168 *
1169 * @deprecated 4.2.3.5
1170 */
1171 function learn_press_quiz_meta_final( $item ) {
1172 _deprecated_function( __METHOD__, '4.2.3.5' );
1173
1174 return;
1175 $course = learn_press_get_course();
1176
1177 if ( ! $course->is_final_quiz( $item->get_id() ) ) {
1178 return;
1179 }
1180 echo '<span class="item-meta final-quiz">' . esc_html__( 'Final', 'learnpress' ) . '</span>';
1181 }
1182
1183 function learn_press_comments_template_query_args( $comment_args ) {
1184 $post_type = get_post_type( $comment_args['post_id'] );
1185
1186 if ( $post_type == LP_COURSE_CPT ) {
1187 $comment_args['type__not_in'] = 'review';
1188 }
1189
1190 return $comment_args;
1191 }
1192
1193 add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' );
1194
1195 function learn_press_comment_form_logged_in( $html_login ) {
1196 if ( get_post_type() == LP_COURSE_CPT || get_post_type() == LP_LESSON_CPT ) {
1197 $html_login = '';
1198 }
1199
1200 return $html_login;
1201 }
1202
1203 add_filter( 'comment_form_logged_in', 'learn_press_comment_form_logged_in' );
1204
1205 function learn_press_comment_form_defaults( $defaults ) {
1206 if ( get_post_type() == LP_COURSE_CPT || get_post_type() == LP_LESSON_CPT ) {
1207 $defaults['comment_notes_before'] = '';
1208 }
1209
1210 return $defaults;
1211 }
1212
1213 add_filter( 'comment_form_defaults', 'learn_press_comment_form_defaults' );
1214
1215 function learn_press_filter_get_comments_number( $count, $post_id = 0 ) {
1216 global $wpdb;
1217
1218 if ( ! $post_id ) {
1219 $post_id = get_the_ID();
1220 if ( ! $post_id ) {
1221 return $count;
1222 }
1223 }
1224
1225 if ( get_post_type( $post_id ) == LP_COURSE_CPT ) {
1226 $sql = $wpdb->prepare(
1227 ' SELECT count(*) '
1228 . " FROM {$wpdb->comments} "
1229 . ' WHERE comment_post_ID = %d '
1230 . ' AND comment_approved = 1 '
1231 . ' AND comment_type != %s ',
1232 $post_id,
1233 'review'
1234 );
1235
1236 $count = $wpdb->get_var( $sql );
1237 }
1238
1239 return $count;
1240 }
1241
1242 add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' );
1243
1244 /**
1245 * Add custom classes to body tag class name
1246 *
1247 * @param array $classes
1248 *
1249 * @return array
1250 *
1251 * @since 3.0.0
1252 * @Todo tungnx review to remove
1253 * @deprecated 4.2.3
1254 */
1255 function learn_press_body_classes( $classes ) {
1256 if ( is_learnpress() ) {
1257 $classes[] = get_stylesheet();
1258 $classes[] = 'learnpress';
1259 $classes[] = 'learnpress-page';
1260 }
1261
1262 return $classes;
1263 }
1264
1265 //add_filter( 'body_class', 'learn_press_body_classes', 10 );
1266
1267 /**
1268 * Return true if user is learning a course
1269 *
1270 * @param int $course_id
1271 *
1272 * @return bool
1273 * @since 3.0
1274 * @version 1.0.1
1275 */
1276 function learn_press_is_learning_course( int $course_id = 0 ): bool {
1277 $is_learning = false;
1278 $user = learn_press_get_current_user();
1279 $course = learn_press_get_course( $course_id );
1280 if ( ! $course ) {
1281 return $is_learning;
1282 }
1283
1284 if ( $user ) {
1285 return $user->has_enrolled_or_finished( $course_id );
1286 }
1287
1288 if ( $course->is_no_required_enroll() ) {
1289 $is_learning = true;
1290 }
1291
1292 return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
1293 }
1294
1295 function learn_press_content_item_summary_class( $more = '', $echo = true ) {
1296 $classes = array( 'content-item-summary' );
1297 $classes = LP_Helper::merge_class( $classes, $more );
1298 $classes = apply_filters( 'learn-press/content-item-summary-class', $classes );
1299 $output = 'class="' . esc_attr( join( ' ', $classes ) ) . '"';
1300
1301 if ( $echo ) {
1302 echo wp_kses_post( $output );
1303 }
1304
1305 return $output;
1306 }
1307
1308 /**
1309 * @deprecated 4.2.3.1
1310 */
1311 function learn_press_content_item_summary_classes( $classes ) {
1312 _deprecated_function( __FUNCTION__, '4.2.3.1' );
1313 $item = LP_Global::course_item();
1314
1315 if ( ! $item ) {
1316 return $classes;
1317 }
1318
1319 if ( $item->get_post_type() !== LP_LESSON_CPT ) {
1320 return $classes;
1321 }
1322
1323 return $classes;
1324 }
1325
1326 function learn_press_maybe_load_comment_js() {
1327 $item = LP_Global::course_item();
1328
1329 if ( $item ) {
1330 wp_enqueue_script( 'comment-reply' );
1331 }
1332 }
1333
1334 add_action( 'wp_enqueue_scripts', 'learn_press_maybe_load_comment_js' );
1335
1336 /**
1337 * Get list layouts archive course setting
1338 *
1339 * @editor tungnx
1340 * @modify 4.1.3
1341 */
1342 function learn_press_courses_layouts() {
1343 return apply_filters(
1344 'learnpress/archive-courses-layouts',
1345 [
1346 'grid' => __( 'Grid', 'learnpress' ),
1347 'list' => __( 'List', 'learnpress' ),
1348 ]
1349 );
1350 }
1351
1352 /**
1353 * Get layout template for archive course page.
1354 *
1355 * @return mixed
1356 * @since 3.3.0
1357 * @editor tungnx
1358 * @modify 4.1.3
1359 */
1360 function learn_press_get_courses_layout() {
1361 $layout = LP_Request::get_cookie( 'courses-layout' );
1362
1363 if ( ! $layout ) {
1364 $layout = LP_Settings::get_option( 'archive_courses_layout', 'list' );
1365 }
1366
1367 return $layout;
1368 }
1369
1370 function learn_press_register_sidebars() {
1371 register_sidebar(
1372 array(
1373 'name' => esc_html__( 'Course Sidebar', 'learnpress' ),
1374 'id' => 'course-sidebar',
1375 'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ),
1376 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1377 'after_widget' => '</div>',
1378 'before_title' => '<h3 class="widget-title">',
1379 'after_title' => '</h3>',
1380 )
1381 );
1382 register_sidebar(
1383 array(
1384 'name' => esc_html__( 'All Courses', 'learnpress' ),
1385 'id' => 'archive-courses-sidebar',
1386 'description' => esc_html__( 'Widgets in this area will be shown on all course pages', 'learnpress' ),
1387 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1388 'after_widget' => '</div>',
1389 'before_title' => '<h3 class="widget-title">',
1390 'after_title' => '</h3>',
1391 )
1392 );
1393 }
1394
1395 add_action( 'widgets_init', 'learn_press_register_sidebars' );
1396
1397 function learn_press_setup_theme() {
1398 $support = array(
1399 'widgets' => array(
1400 // Place three core-defined widgets in the sidebar area.
1401 'course-sidebar' => array(
1402 'xxx' => array( 'lp-widget-course-progress' ),
1403 'yyy' => array( 'lp-widget-course-info' ),
1404 ),
1405 ),
1406 );
1407
1408 add_theme_support( 'starter-content', $support );
1409 }
1410
1411 add_action( 'after_setup_theme', 'learn_press_setup_theme' );
1412
1413 /**
1414 * @param LP_Question $question
1415 * @param array $args
1416 *
1417 * @return array
1418 * @since 4.x.x
1419 */
1420 function learn_press_get_question_options_for_js( $question, $args = array() ) {
1421 $args = wp_parse_args(
1422 $args,
1423 array(
1424 'cryptoJsAes' => false,
1425 'include_is_true' => false,
1426 'answer' => false,
1427 )
1428 );
1429
1430 if ( $args['cryptoJsAes'] ) {
1431 $options = array_values( $question->get_answer_options() );
1432
1433 $key = uniqid();
1434 $options = array(
1435 'data' => cryptoJsAesEncrypt( $key, wp_json_encode( $options ) ),
1436 'key' => $key,
1437 );
1438 } else {
1439 $exclude_option_key = array( 'question_id', 'order' );
1440 if ( ! $args['include_is_true'] ) {
1441 $exclude_option_key[] = 'is_true';
1442 }
1443
1444 $options = array_values(
1445 $question->get_answer_options(
1446 array(
1447 'exclude' => $exclude_option_key,
1448 'map' => array( 'question_answer_id' => 'uid' ),
1449 'answer' => $args['answer'],
1450 )
1451 )
1452 );
1453 }
1454
1455 return $options;
1456 }
1457
1458 function learn_press_custom_excerpt_length( $length ) {
1459 return 20;
1460 }
1461
1462 /**
1463 * Get post meta with key _lp_duration and translate.
1464 *
1465 * @param int $post_id
1466 * @param string $default
1467 *
1468 * @return string
1469 * @since 4.0.0
1470 */
1471 function learn_press_get_post_translated_duration( $post_id, $default = '' ) {
1472 $duration = get_post_meta( $post_id, '_lp_duration', true );
1473
1474 $duration_arr = explode( ' ', $duration );
1475 $duration_str = '';
1476
1477 if ( count( $duration_arr ) > 1 ) {
1478 $duration_number = $duration_arr[0];
1479 $duration_text = $duration_arr[1];
1480
1481 switch ( strtolower( $duration_text ) ) {
1482 case 'minute':
1483 $duration_str = sprintf(
1484 _n( '%s minute', '%s minutes', $duration_number, 'learnpress' ),
1485 $duration_number
1486 );
1487 break;
1488 case 'hour':
1489 $duration_str = sprintf(
1490 _n( '%s hour', '%s hours', $duration_number, 'learnpress' ),
1491 $duration_number
1492 );
1493 break;
1494 case 'day':
1495 $duration_str = sprintf( _n( '%s day', '%s days', $duration_number, 'learnpress' ), $duration_number );
1496 break;
1497 case 'week':
1498 $duration_str = sprintf(
1499 _n( '%s week', '%s weeks', $duration_number, 'learnpress' ),
1500 $duration_number
1501 );
1502 break;
1503 default:
1504 $duration_str = $duration;
1505 }
1506 }
1507
1508 return empty( absint( $duration ) ) ? $default : $duration_str;
1509 }
1510
1511 /**
1512 * Get level post meta.
1513 *
1514 * @param int $post_id
1515 *
1516 * @return string
1517 */
1518 function learn_press_get_post_level( $post_id ) {
1519 $level = get_post_meta( $post_id, '_lp_level', true );
1520
1521 return apply_filters(
1522 'learn-press/level-label',
1523 ! empty( $level ) ? lp_course_level()[ $level ] : esc_html__( 'All levels', 'learnpress' ),
1524 $post_id
1525 );
1526 }
1527
1528 function lp_course_level() {
1529 return apply_filters(
1530 'lp/template/function/course/level',
1531 array(
1532 'all' => esc_html__( 'All levels', 'learnpress' ),
1533 'beginner' => esc_html__( 'Beginner', 'learnpress' ),
1534 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ),
1535 'expert' => esc_html__( 'Expert', 'learnpress' ),
1536 )
1537 );
1538 }
1539
1540 /**
1541 * Get slug for logout action in user profile.
1542 *
1543 * @return string
1544 * @since 4.0.0
1545 */
1546 function learn_press_profile_logout_slug() {
1547 return apply_filters( 'learn-press/profile-logout-slug', 'lp-logout' );
1548 }
1549
1550 function lp_get_email_content( $format, $meta = array(), $field = array() ) {
1551 if ( $meta && isset( $meta[ $format ] ) ) {
1552 $content = stripslashes( $meta[ $format ] );
1553 } else {
1554 $template = ! empty( $field["template_{$format}"] ) ? $field["template_{$format}"] : null;
1555 $template_file = $field['template_base'] . $template;
1556 $content = LP_WP_Filesystem::instance()->file_get_contents( $template_file );
1557 }
1558
1559 return $content;
1560 }
1561
1562 function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) {
1563 ?>
1564 <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>">
1565 <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?>
1566 <li style="width: <?php echo esc_attr( $width === 'random' ? wp_rand( 90, 100 ) . '%' : $width ); ?>; <?php echo ! empty( $styleli ) ? $styleli : ''; ?>"></li>
1567 <?php endfor; ?>
1568 </ul>
1569
1570 <?php
1571 }
1572
1573 add_filter( 'lp_format_page_content', 'wptexturize' );
1574 add_filter( 'lp_format_page_content', 'convert_smilies' );
1575 add_filter( 'lp_format_page_content', 'convert_chars' );
1576 add_filter( 'lp_format_page_content', 'wpautop' );
1577 add_filter( 'lp_format_page_content', 'shortcode_unautop' );
1578 add_filter( 'lp_format_page_content', 'prepend_attachment' );
1579 add_filter( 'lp_format_page_content', 'do_shortcode', 11 );
1580 add_filter( 'lp_format_page_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
1581
1582 if ( function_exists( 'do_blocks' ) ) {
1583 add_filter( 'lp_format_page_content', 'do_blocks', 9 );
1584 }
1585
1586 function lp_format_page_content( $raw_string ) {
1587 return apply_filters( 'lp_format_page_content', $raw_string );
1588 }
1589
1590 if ( ! function_exists( 'lp_profile_page_content' ) ) {
1591 function lp_profile_page_content() {
1592 $profile_id = learn_press_get_page_id( 'profile' );
1593
1594 if ( $profile_id ) {
1595 $profile_page = get_post( $profile_id );
1596
1597 // remove_shortcode( 'learn_press_profile' );
1598 $description = lp_format_page_content( wp_kses_post( $profile_page->post_content ) );
1599
1600 if ( $description ) {
1601 echo '<div class="lp-profile-page__content">' . $description . '</div>';
1602 }
1603 }
1604 }
1605 }
1606
1607 if ( ! function_exists( 'lp_archive_course_page_content' ) ) {
1608 add_action( 'lp/template/archive-course/description', 'lp_archive_course_page_content' );
1609
1610 function lp_archive_course_page_content() {
1611 if ( is_search() ) {
1612 return;
1613 }
1614
1615 if ( is_post_type_archive( LP_COURSE_CPT )
1616 && in_array( absint( get_query_var( 'paged' ) ), array( 0, 1 ), true ) ) {
1617 $profile_id = learn_press_get_page_id( 'courses' );
1618
1619 if ( $profile_id ) {
1620 $profile_page = get_post( $profile_id );
1621
1622 $description = lp_format_page_content( wp_kses_post( $profile_page->post_content ) );
1623 if ( $description ) {
1624 echo '<div class="lp-course-page__content">' . $description . '</div>';
1625 }
1626 }
1627 }
1628 }
1629 }
1630
1631 if ( ! function_exists( 'lp_taxonomy_archive_course_description' ) ) {
1632 add_action( 'lp/template/archive-course/description', 'lp_taxonomy_archive_course_description' );
1633
1634 function lp_taxonomy_archive_course_description() {
1635
1636 if ( learn_press_is_course_tax() && 0 === absint( get_query_var( 'paged' ) ) ) {
1637 $term = get_queried_object();
1638
1639 if ( $term && ! empty( $term->description ) ) {
1640 echo '<div class="lp-archive-course-term-description">' . lp_format_page_content( wp_kses_post( $term->description ) ) . '</div>';
1641 }
1642 }
1643 }
1644 }
1645
1646 /**
1647 * Params to query courses on Archive Course.
1648 *
1649 * @return array
1650 */
1651 function lp_archive_skeleton_get_args(): array {
1652 $args = [];
1653
1654 if ( ! empty( $_GET ) ) {
1655 $args = $_GET;
1656 }
1657
1658 global $wp_query;
1659 if ( ! empty( $wp_query->get( 'paged' ) ) ) {
1660 $args['paged'] = $wp_query->get( 'paged' );
1661 }
1662
1663 if ( learn_press_is_course_category() || learn_press_is_course_tag() ) {
1664 $cat = get_queried_object();
1665
1666 // Info of page
1667 if ( learn_press_is_course_category() ) {
1668 $args['page_term_id_current'] = $cat->term_id;
1669 } elseif ( learn_press_is_course_tag() ) {
1670 $args['page_tag_id_current'] = $cat->term_id;
1671 }
1672
1673 $args['page_term_url'] = get_term_link( $cat );
1674 }
1675
1676 $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args );
1677 if ( ! is_array( $args ) ) {
1678 $args = [];
1679 }
1680
1681 return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' );
1682 }
1683