PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9
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 4.2.1 All 138 releases
learnpress / inc / lp-template-functions.php

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

1,680 lines 44.8 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 if ( ! function_exists( 'learn_press_sort_course_tabs' ) ) {
1115 function learn_press_sort_course_tabs( $tabs = array() ) {
1116 uasort( $tabs, 'learn_press_sort_list_by_priority_callback' );
1117
1118 return $tabs;
1119 }
1120 }
1121
1122 if ( ! function_exists( 'learn_press_get_profile_display_name' ) ) {
1123 /**
1124 * Get Display name publicly as in Profile page
1125 */
1126 function learn_press_get_profile_display_name( $user ) {
1127 if ( empty( $user ) ) {
1128 return '';
1129 }
1130
1131 $id = '';
1132
1133 if ( $user instanceof LP_Abstract_User ) {
1134 $id = $user->get_id();
1135 } elseif ( $user instanceof WP_User ) {
1136 $id = $user->ID;
1137 } elseif ( is_numeric( $user ) ) {
1138 $id = $user;
1139 }
1140
1141 if ( ! isset( $id ) ) {
1142 return '';
1143 }
1144
1145 $info = get_userdata( $id );
1146
1147 return $info ? $info->display_name : '';
1148 }
1149 }
1150
1151 function learn_press_is_content_item_only() {
1152 return ! empty( $_REQUEST['content-item-only'] );
1153 }
1154
1155 function learn_press_label_html( $label, $type = '' ) {
1156 ?>
1157 <span class="lp-label label-<?php echo esc_attr( $type ? $type : $label ); ?>">
1158 <?php echo esc_html( $label ); ?>
1159 </span>
1160 <?php
1161 }
1162
1163 /**
1164 * @param LP_Quiz $item
1165 *
1166 * @deprecated 4.2.3.5
1167 */
1168 function learn_press_quiz_meta_final( $item ) {
1169 _deprecated_function( __METHOD__, '4.2.3.5' );
1170
1171 return;
1172 $course = learn_press_get_course();
1173
1174 if ( ! $course->is_final_quiz( $item->get_id() ) ) {
1175 return;
1176 }
1177 echo '<span class="item-meta final-quiz">' . esc_html__( 'Final', 'learnpress' ) . '</span>';
1178 }
1179
1180 function learn_press_comments_template_query_args( $comment_args ) {
1181 $post_type = get_post_type( $comment_args['post_id'] );
1182
1183 if ( $post_type == LP_COURSE_CPT ) {
1184 $comment_args['type__not_in'] = 'review';
1185 }
1186
1187 return $comment_args;
1188 }
1189
1190 add_filter( 'comments_template_query_args', 'learn_press_comments_template_query_args' );
1191
1192 function learn_press_comment_form_logged_in( $html_login ) {
1193 if ( get_post_type() == LP_COURSE_CPT || get_post_type() == LP_LESSON_CPT ) {
1194 $html_login = '';
1195 }
1196
1197 return $html_login;
1198 }
1199
1200 add_filter( 'comment_form_logged_in', 'learn_press_comment_form_logged_in' );
1201
1202 function learn_press_comment_form_defaults( $defaults ) {
1203 if ( get_post_type() == LP_COURSE_CPT || get_post_type() == LP_LESSON_CPT ) {
1204 $defaults['comment_notes_before'] = '';
1205 }
1206
1207 return $defaults;
1208 }
1209
1210 add_filter( 'comment_form_defaults', 'learn_press_comment_form_defaults' );
1211
1212 function learn_press_filter_get_comments_number( $count, $post_id = 0 ) {
1213 global $wpdb;
1214
1215 if ( ! $post_id ) {
1216 $post_id = get_the_ID();
1217 if ( ! $post_id ) {
1218 return $count;
1219 }
1220 }
1221
1222 if ( get_post_type( $post_id ) == LP_COURSE_CPT ) {
1223 $sql = $wpdb->prepare(
1224 ' SELECT count(*) '
1225 . " FROM {$wpdb->comments} "
1226 . ' WHERE comment_post_ID = %d '
1227 . ' AND comment_approved = 1 '
1228 . ' AND comment_type != %s ',
1229 $post_id,
1230 'review'
1231 );
1232
1233 $count = $wpdb->get_var( $sql );
1234 }
1235
1236 return $count;
1237 }
1238
1239 add_filter( 'get_comments_number', 'learn_press_filter_get_comments_number' );
1240
1241 /**
1242 * Add custom classes to body tag class name
1243 *
1244 * @param array $classes
1245 *
1246 * @return array
1247 *
1248 * @since 3.0.0
1249 * @Todo tungnx review to remove
1250 * @deprecated 4.2.3
1251 */
1252 function learn_press_body_classes( $classes ) {
1253 if ( is_learnpress() ) {
1254 $classes[] = get_stylesheet();
1255 $classes[] = 'learnpress';
1256 $classes[] = 'learnpress-page';
1257 }
1258
1259 return $classes;
1260 }
1261
1262 //add_filter( 'body_class', 'learn_press_body_classes', 10 );
1263
1264 /**
1265 * Return true if user is learning a course
1266 *
1267 * @param int $course_id
1268 *
1269 * @return bool
1270 * @since 3.0
1271 * @version 1.0.1
1272 */
1273 function learn_press_is_learning_course( int $course_id = 0 ): bool {
1274 $is_learning = false;
1275 $user = learn_press_get_current_user();
1276 $course = learn_press_get_course( $course_id );
1277 if ( ! $course ) {
1278 return $is_learning;
1279 }
1280
1281 if ( $user ) {
1282 return $user->has_enrolled_or_finished( $course_id );
1283 }
1284
1285 if ( $course->is_no_required_enroll() ) {
1286 $is_learning = true;
1287 }
1288
1289 return apply_filters( 'lp/is-learning-course', $is_learning, $course_id );
1290 }
1291
1292 function learn_press_content_item_summary_class( $more = '', $echo = true ) {
1293 $classes = array( 'content-item-summary' );
1294 $classes = LP_Helper::merge_class( $classes, $more );
1295 $classes = apply_filters( 'learn-press/content-item-summary-class', $classes );
1296 $output = 'class="' . esc_attr( join( ' ', $classes ) ) . '"';
1297
1298 if ( $echo ) {
1299 echo wp_kses_post( $output );
1300 }
1301
1302 return $output;
1303 }
1304
1305 /**
1306 * @deprecated 4.2.3.1
1307 */
1308 function learn_press_content_item_summary_classes( $classes ) {
1309 _deprecated_function( __FUNCTION__, '4.2.3.1' );
1310 $item = LP_Global::course_item();
1311
1312 if ( ! $item ) {
1313 return $classes;
1314 }
1315
1316 if ( $item->get_post_type() !== LP_LESSON_CPT ) {
1317 return $classes;
1318 }
1319
1320 return $classes;
1321 }
1322
1323 function learn_press_maybe_load_comment_js() {
1324 $item = LP_Global::course_item();
1325
1326 if ( $item ) {
1327 wp_enqueue_script( 'comment-reply' );
1328 }
1329 }
1330
1331 add_action( 'wp_enqueue_scripts', 'learn_press_maybe_load_comment_js' );
1332
1333 /**
1334 * Get list layouts archive course setting
1335 *
1336 * @editor tungnx
1337 * @modify 4.1.3
1338 */
1339 function learn_press_courses_layouts() {
1340 return apply_filters(
1341 'learnpress/archive-courses-layouts',
1342 [
1343 'grid' => __( 'Grid', 'learnpress' ),
1344 'list' => __( 'List', 'learnpress' ),
1345 ]
1346 );
1347 }
1348
1349 /**
1350 * Get layout template for archive course page.
1351 *
1352 * @return mixed
1353 * @since 3.3.0
1354 * @editor tungnx
1355 * @modify 4.1.3
1356 */
1357 function learn_press_get_courses_layout() {
1358 $layout = LP_Request::get_cookie( 'courses-layout' );
1359
1360 if ( ! $layout ) {
1361 $layout = LP_Settings::get_option( 'archive_courses_layout', 'list' );
1362 }
1363
1364 return $layout;
1365 }
1366
1367 function learn_press_register_sidebars() {
1368 register_sidebar(
1369 array(
1370 'name' => esc_html__( 'Course Sidebar', 'learnpress' ),
1371 'id' => 'course-sidebar',
1372 'description' => esc_html__( 'Widgets in this area will be shown in a single course', 'learnpress' ),
1373 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1374 'after_widget' => '</div>',
1375 'before_title' => '<h3 class="widget-title">',
1376 'after_title' => '</h3>',
1377 )
1378 );
1379 register_sidebar(
1380 array(
1381 'name' => esc_html__( 'All Courses', 'learnpress' ),
1382 'id' => 'archive-courses-sidebar',
1383 'description' => esc_html__( 'Widgets in this area will be shown on all course pages', 'learnpress' ),
1384 'before_widget' => '<div id="%1$s" class="widget %2$s">',
1385 'after_widget' => '</div>',
1386 'before_title' => '<h3 class="widget-title">',
1387 'after_title' => '</h3>',
1388 )
1389 );
1390 }
1391
1392 add_action( 'widgets_init', 'learn_press_register_sidebars' );
1393
1394 function learn_press_setup_theme() {
1395 $support = array(
1396 'widgets' => array(
1397 // Place three core-defined widgets in the sidebar area.
1398 'course-sidebar' => array(
1399 'xxx' => array( 'lp-widget-course-progress' ),
1400 'yyy' => array( 'lp-widget-course-info' ),
1401 ),
1402 ),
1403 );
1404
1405 add_theme_support( 'starter-content', $support );
1406 }
1407
1408 add_action( 'after_setup_theme', 'learn_press_setup_theme' );
1409
1410 /**
1411 * @param LP_Question $question
1412 * @param array $args
1413 *
1414 * @return array
1415 * @since 4.x.x
1416 */
1417 function learn_press_get_question_options_for_js( $question, $args = array() ) {
1418 $args = wp_parse_args(
1419 $args,
1420 array(
1421 'cryptoJsAes' => false,
1422 'include_is_true' => true,
1423 'answer' => false,
1424 )
1425 );
1426
1427 if ( $args['cryptoJsAes'] ) {
1428 $options = array_values( $question->get_answer_options() );
1429
1430 $key = uniqid();
1431 $options = array(
1432 'data' => cryptoJsAesEncrypt( $key, wp_json_encode( $options ) ),
1433 'key' => $key,
1434 );
1435 } else {
1436 $exclude_option_key = array( 'question_id', 'order' );
1437 if ( ! $args['include_is_true'] ) {
1438 $exclude_option_key[] = 'is_true';
1439 }
1440
1441 $options = array_values(
1442 $question->get_answer_options(
1443 array(
1444 'exclude' => $exclude_option_key,
1445 'map' => array( 'question_answer_id' => 'uid' ),
1446 'answer' => $args['answer'],
1447 )
1448 )
1449 );
1450 }
1451
1452 return $options;
1453 }
1454
1455 function learn_press_custom_excerpt_length( $length ) {
1456 return 20;
1457 }
1458
1459 /**
1460 * Get post meta with key _lp_duration and translate.
1461 *
1462 * @param int $post_id
1463 * @param string $default
1464 *
1465 * @return string
1466 * @since 4.0.0
1467 */
1468 function learn_press_get_post_translated_duration( $post_id, $default = '' ) {
1469 $duration = get_post_meta( $post_id, '_lp_duration', true );
1470
1471 $duration_arr = explode( ' ', $duration );
1472 $duration_str = '';
1473
1474 if ( count( $duration_arr ) > 1 ) {
1475 $duration_number = $duration_arr[0];
1476 $duration_text = $duration_arr[1];
1477
1478 switch ( strtolower( $duration_text ) ) {
1479 case 'minute':
1480 $duration_str = sprintf(
1481 _n( '%s minute', '%s minutes', $duration_number, 'learnpress' ),
1482 $duration_number
1483 );
1484 break;
1485 case 'hour':
1486 $duration_str = sprintf(
1487 _n( '%s hour', '%s hours', $duration_number, 'learnpress' ),
1488 $duration_number
1489 );
1490 break;
1491 case 'day':
1492 $duration_str = sprintf( _n( '%s day', '%s days', $duration_number, 'learnpress' ), $duration_number );
1493 break;
1494 case 'week':
1495 $duration_str = sprintf(
1496 _n( '%s week', '%s weeks', $duration_number, 'learnpress' ),
1497 $duration_number
1498 );
1499 break;
1500 default:
1501 $duration_str = $duration;
1502 }
1503 }
1504
1505 return empty( absint( $duration ) ) ? $default : $duration_str;
1506 }
1507
1508 /**
1509 * Get level post meta.
1510 *
1511 * @param int $post_id
1512 *
1513 * @return string
1514 */
1515 function learn_press_get_post_level( $post_id ) {
1516 $level = get_post_meta( $post_id, '_lp_level', true );
1517
1518 return apply_filters(
1519 'learn-press/level-label',
1520 ! empty( $level ) ? lp_course_level()[ $level ] : esc_html__( 'All levels', 'learnpress' ),
1521 $post_id
1522 );
1523 }
1524
1525 function lp_course_level() {
1526 return apply_filters(
1527 'lp/template/function/course/level',
1528 array(
1529 'all' => esc_html__( 'All levels', 'learnpress' ),
1530 'beginner' => esc_html__( 'Beginner', 'learnpress' ),
1531 'intermediate' => esc_html__( 'Intermediate', 'learnpress' ),
1532 'expert' => esc_html__( 'Expert', 'learnpress' ),
1533 )
1534 );
1535 }
1536
1537 /**
1538 * Get slug for logout action in user profile.
1539 *
1540 * @return string
1541 * @since 4.0.0
1542 */
1543 function learn_press_profile_logout_slug() {
1544 return apply_filters( 'learn-press/profile-logout-slug', 'lp-logout' );
1545 }
1546
1547 function lp_get_email_content( $format, $meta = array(), $field = array() ) {
1548 if ( $meta && isset( $meta[ $format ] ) ) {
1549 $content = stripslashes( $meta[ $format ] );
1550 } else {
1551 $template = ! empty( $field["template_{$format}"] ) ? $field["template_{$format}"] : null;
1552 $template_file = $field['template_base'] . $template;
1553 $content = LP_WP_Filesystem::instance()->file_get_contents( $template_file );
1554 }
1555
1556 return $content;
1557 }
1558
1559 function lp_skeleton_animation_html( $count_li = 3, $width = 'random', $styleli = '', $styleul = '' ) {
1560 ?>
1561 <ul class="lp-skeleton-animation" style="<?php echo esc_attr( $styleul ); ?>">
1562 <?php for ( $i = 0; $i < absint( $count_li ); $i ++ ) : ?>
1563 <li style="width: <?php echo esc_attr( $width === 'random' ? wp_rand( 90, 100 ) . '%' : $width ); ?>; <?php echo ! empty( $styleli ) ? $styleli : ''; ?>"></li>
1564 <?php endfor; ?>
1565 </ul>
1566
1567 <?php
1568 }
1569
1570 add_filter( 'lp_format_page_content', 'wptexturize' );
1571 add_filter( 'lp_format_page_content', 'convert_smilies' );
1572 add_filter( 'lp_format_page_content', 'convert_chars' );
1573 add_filter( 'lp_format_page_content', 'wpautop' );
1574 add_filter( 'lp_format_page_content', 'shortcode_unautop' );
1575 add_filter( 'lp_format_page_content', 'prepend_attachment' );
1576 add_filter( 'lp_format_page_content', 'do_shortcode', 11 );
1577 add_filter( 'lp_format_page_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
1578
1579 if ( function_exists( 'do_blocks' ) ) {
1580 add_filter( 'lp_format_page_content', 'do_blocks', 9 );
1581 }
1582
1583 function lp_format_page_content( $raw_string ) {
1584 return apply_filters( 'lp_format_page_content', $raw_string );
1585 }
1586
1587 if ( ! function_exists( 'lp_profile_page_content' ) ) {
1588 function lp_profile_page_content() {
1589 $profile_id = learn_press_get_page_id( 'profile' );
1590
1591 if ( $profile_id ) {
1592 $profile_page = get_post( $profile_id );
1593
1594 // remove_shortcode( 'learn_press_profile' );
1595 $description = lp_format_page_content( wp_kses_post( $profile_page->post_content ) );
1596
1597 if ( $description ) {
1598 echo '<div class="lp-profile-page__content">' . $description . '</div>';
1599 }
1600 }
1601 }
1602 }
1603
1604 if ( ! function_exists( 'lp_archive_course_page_content' ) ) {
1605 add_action( 'lp/template/archive-course/description', 'lp_archive_course_page_content' );
1606
1607 function lp_archive_course_page_content() {
1608 if ( is_search() ) {
1609 return;
1610 }
1611
1612 if ( is_post_type_archive( LP_COURSE_CPT )
1613 && in_array( absint( get_query_var( 'paged' ) ), array( 0, 1 ), true ) ) {
1614 $profile_id = learn_press_get_page_id( 'courses' );
1615
1616 if ( $profile_id ) {
1617 $profile_page = get_post( $profile_id );
1618
1619 $description = lp_format_page_content( wp_kses_post( $profile_page->post_content ) );
1620 if ( $description ) {
1621 echo '<div class="lp-course-page__content">' . $description . '</div>';
1622 }
1623 }
1624 }
1625 }
1626 }
1627
1628 if ( ! function_exists( 'lp_taxonomy_archive_course_description' ) ) {
1629 add_action( 'lp/template/archive-course/description', 'lp_taxonomy_archive_course_description' );
1630
1631 function lp_taxonomy_archive_course_description() {
1632
1633 if ( learn_press_is_course_tax() && 0 === absint( get_query_var( 'paged' ) ) ) {
1634 $term = get_queried_object();
1635
1636 if ( $term && ! empty( $term->description ) ) {
1637 echo '<div class="lp-archive-course-term-description">' . lp_format_page_content( wp_kses_post( $term->description ) ) . '</div>';
1638 }
1639 }
1640 }
1641 }
1642
1643 /**
1644 * Params to query courses on Archive Course.
1645 *
1646 * @return array
1647 */
1648 function lp_archive_skeleton_get_args(): array {
1649 $args = [];
1650
1651 if ( ! empty( $_GET ) ) {
1652 $args = $_GET;
1653 }
1654
1655 global $wp_query;
1656 if ( ! empty( $wp_query->get( 'paged' ) ) ) {
1657 $args['paged'] = $wp_query->get( 'paged' );
1658 }
1659
1660 if ( learn_press_is_course_category() || learn_press_is_course_tag() ) {
1661 $cat = get_queried_object();
1662
1663 // Info of page
1664 if ( learn_press_is_course_category() ) {
1665 $args['page_term_id_current'] = $cat->term_id;
1666 } elseif ( learn_press_is_course_tag() ) {
1667 $args['page_tag_id_current'] = $cat->term_id;
1668 }
1669
1670 $args['page_term_url'] = get_term_link( $cat );
1671 }
1672
1673 $args = apply_filters( 'lp/template/archive-course/skeleton/args', $args );
1674 if ( ! is_array( $args ) ) {
1675 $args = [];
1676 }
1677
1678 return LP_Helper::sanitize_params_submitted( $args, 'sanitize_text_field' );
1679 }
1680