PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/lp-core-functions.php +217 -1750 4.1.6.94.4.8 View file →
@@ -7,10 +7,24 @@
7 7 * @package LearnPress/Functions
8 8 * @version 1.0
9 9 */
10 10
11 +use LearnPress\Helpers\Config;
12 +
11 13 defined( 'ABSPATH' ) || exit;
12 14
15 +/**
16 + * Vue write php has script, so when sanitize will error, so use code is mask pass check sanitize, esc
17 + *
18 + * @param $content
19 + *
20 + * @return void
21 + * @since 4.1.6.9
22 + */
23 +function learn_press_echo_vuejs_write_on_php( $content ) {
24 + echo ( $content );
25 +}
26 +
13 27 function learnpress_gutenberg_disable_cpt( $can_edit, $post_type ) {
14 28 $post_types = array(
15 29 LP_COURSE_CPT => LP_Settings::get_option( 'enable_gutenberg_course', 'no' ),
16 30 LP_LESSON_CPT => LP_Settings::get_option( 'enable_gutenberg_lesson', 'no' ),
@@ -27,37 +41,13 @@
27 41 return $can_edit;
28 42 }
29 43 add_filter( 'use_block_editor_for_post_type', 'learnpress_gutenberg_disable_cpt', 10, 2 );
30 44
31 -/**
32 - * Get instance of a CURD class by type
33 - *
34 - * @param string $type
35 - *
36 - * @return bool|LP_Course_CURD|LP_User_CURD|LP_Quiz_CURD|LP_Question_CURD
37 - */
38 -function learn_press_get_curd( $type ) {
39 - $curds = array(
40 - 'user' => 'LP_User_CURD',
41 - 'course' => 'LP_Course_CURD',
42 - 'quiz' => 'LP_Quiz_CURD',
43 - 'question' => 'LP_Question_CURD',
44 - );
45 -
46 - $curd = false;
47 -
48 - if ( ! empty( $curds[ $type ] ) && class_exists( $curds[ $type ] ) ) {
49 - $curd = new $curds[ $type ]();
50 - }
51 -
52 - return apply_filters( 'learn-press/curd', $curd, $type, $curds );
53 -}
54 -
55 45 if ( ! function_exists( 'lp_add_body_class' ) ) {
56 46 function lp_add_body_class( $classes ) {
57 47 $classes = (array) $classes;
58 48
59 - if ( learn_press_is_profile() ) {
49 + if ( LP_Page_Controller::is_page_profile() ) {
60 50 $classes[] = 'learnpress-profile';
61 51 } elseif ( learn_press_is_checkout() ) {
62 52 $classes[] = 'learnpress-checkout';
63 53 }
@@ -114,9 +104,9 @@
114 104 }
115 105 $atts = ' ' . implode( ' ', $options );
116 106 }
117 107
118 - $tip = sprintf( '<span class="learn-press-tip" ' . $atts . '>%s</span>', $tip );
108 + $tip = sprintf( '<div class="learn-press-tip" ' . $atts . '><span>%s</span></div>', $tip );
119 109
120 110 if ( $echo ) {
121 111 echo wp_kses_post( $tip );
122 112 }
@@ -124,20 +114,8 @@
124 114 return $tip;
125 115 }
126 116
127 117 /**
128 - * Return TRUE if defined WP_DEBUG and is true or 1.
129 - *
130 - * @return bool
131 - * @editor tungnx
132 - * @depecated 4.1.6.4
133 - */
134 -function learn_press_is_debug() {
135 - _deprecated_function( __FUNCTION__, '4.1.6.4' );
136 - return LP_Debug::is_debug();
137 -}
138 -
139 -/**
140 118 * Get current post ID.
141 119 *
142 120 * @return int
143 121 */
@@ -163,9 +141,9 @@
163 141 *
164 142 * @return string
165 143 */
166 144 function learn_press_plugin_url( $sub_dir = '' ) {
167 - return LP()->plugin_url( $sub_dir );
145 + return LearnPress::instance()->plugin_url( $sub_dir );
168 146 }
169 147
170 148 /**
171 149 * Get the LearnPress plugin path.
@@ -174,9 +152,9 @@
174 152 *
175 153 * @return string
176 154 */
177 155 function learn_press_plugin_path( $sub_dir = '' ) {
178 - return LP()->plugin_path( $sub_dir );
156 + return LearnPress::instance()->plugin_path( $sub_dir );
179 157 }
180 158
181 159 /**
182 160 * Includes file base on LearnPress path
@@ -294,39 +272,39 @@
294 272 /**
295 273 * Get current URL user is viewing.
296 274 *
297 275 * @return string
276 + * @deprecated 4.2.2
298 277 */
299 278 function learn_press_get_current_url() {
300 - static $current_url;
279 + //_deprecated_function( __FUNCTION__, '4.2.2', 'LP_Helper::getUrlCurrent' );
280 + return LP_Helper::getUrlCurrent();
301 281
302 - if ( ! $current_url ) {
303 - $url = untrailingslashit( esc_url_raw( $_SERVER['REQUEST_URI'] ) );
282 + $url = untrailingslashit( esc_url_raw( $_SERVER['REQUEST_URI'] ) );
304 283
305 - if ( ! preg_match( '!^https?!', $url ) ) {
306 - $siteurl = trailingslashit( get_home_url() );
307 - $home_query = '';
284 + if ( ! preg_match( '!^https?!', $url ) ) {
285 + $siteurl = trailingslashit( get_home_url() );
286 + $home_query = '';
308 287
309 - if ( strpos( $siteurl, '?' ) !== false ) {
310 - $parts = explode( '?', $siteurl );
311 - $home_query = $parts[1];
312 - $siteurl = $parts[0];
313 - }
288 + if ( strpos( $siteurl, '?' ) !== false ) {
289 + $parts = explode( '?', $siteurl );
290 + $home_query = $parts[1];
291 + $siteurl = $parts[0];
292 + }
314 293
315 - if ( $home_query ) {
316 - parse_str( untrailingslashit( $home_query ), $home_query );
317 - $url = esc_url_raw( add_query_arg( $home_query, $url ) );
318 - }
294 + if ( $home_query ) {
295 + parse_str( untrailingslashit( $home_query ), $home_query );
296 + $url = esc_url_raw( add_query_arg( $home_query, $url ) );
297 + }
319 298
320 - $segs1 = explode( '/', $siteurl );
321 - $segs2 = explode( '/', $url );
299 + $segs1 = explode( '/', $siteurl );
300 + $segs2 = explode( '/', $url );
322 301
323 - if ( $removed = array_intersect( $segs1, $segs2 ) ) {
324 - if ( $segs2 = array_diff( $segs2, $removed ) ) {
325 - $current_url = $siteurl . join( '/', $segs2 );
326 - if ( strpos( $current_url, '?' ) === false ) {
327 - $current_url = trailingslashit( $current_url );
328 - }
302 + if ( $removed = array_intersect( $segs1, $segs2 ) ) {
303 + if ( $segs2 = array_diff( $segs2, $removed ) ) {
304 + $current_url = $siteurl . join( '/', $segs2 );
305 + if ( strpos( $current_url, '?' ) === false ) {
306 + $current_url = trailingslashit( $current_url );
329 307 }
330 308 }
331 309 }
332 310 }
@@ -334,21 +312,8 @@
334 312 return $current_url;
335 313 }
336 314
337 315 /**
338 - * Compares an url with current URL user is viewing
339 - *
340 - * @param string $url
341 - *
342 - * @return bool
343 - */
344 -function learn_press_is_current_url( $url ) {
345 - $current_url = learn_press_get_current_url();
346 -
347 - return ( $current_url && $url ) && strcmp( $current_url, learn_press_sanitize_url( $url ) ) == 0;
348 -}
349 -
350 -/**
351 316 * Remove unneeded characters in an URL
352 317 *
353 318 * @param string $url
354 319 * @param bool $trailingslashit
@@ -362,9 +327,9 @@
362 327 $url_without_http = preg_replace( '![/]+!', '/', $url_without_http );
363 328 $url = $matches[1] . $url_without_http;
364 329
365 330 return ( $trailingslashit &&
366 - strpos( $url, '?' ) === false ) ? trailingslashit( $url ) : untrailingslashit( $url );
331 + strpos( $url, '?' ) === false ) ? trailingslashit( $url ) : untrailingslashit( $url );
367 332 }
368 333
369 334 return $url;
370 335 }
@@ -392,47 +357,8 @@
392 357 return apply_filters( 'learn-press/question/slug-to-name', $name, $slug );
393 358 }
394 359
395 360 /**
396 - * Get the post types which supported to insert into course's section
397 - *
398 - * @return array
399 - */
400 -function learn_press_section_item_types() {
401 - $types = array(
402 - 'lp_lesson' => esc_html__( 'Lesson', 'learnpress' ),
403 - 'lp_quiz' => esc_html__( 'Quiz', 'learnpress' ),
404 - );
405 -
406 - return apply_filters( 'learn-press/section/support-item-type', $types );
407 -}
408 -
409 -/**
410 - * Enqueue js code to print out
411 - *
412 - * @param string $code
413 - * @param bool $script_tag - wrap code between <script> tag
414 - * @depecated 4.1.6.8
415 - */
416 -function learn_press_enqueue_script( $code, $script_tag = false ) {
417 - _deprecated_function( __FUNCTION__, '4.1.6.8' );
418 - global $learn_press_queued_js, $learn_press_queued_js_tag;
419 -
420 - if ( $script_tag ) {
421 - if ( empty( $learn_press_queued_js_tag ) ) {
422 - $learn_press_queued_js_tag = '';
423 - }
424 - $learn_press_queued_js_tag .= "\n" . $code . "\n";
425 - } else {
426 - if ( empty( $learn_press_queued_js ) ) {
427 - $learn_press_queued_js = '';
428 - }
429 -
430 - $learn_press_queued_js .= "\n" . $code . "\n";
431 - }
432 -}
433 -
434 -/**
435 361 * Get terms of a course by taxonomy.
436 362 * E.g: course_tag, course_category
437 363 *
438 364 * @param int $course_id
@@ -487,11 +413,11 @@
487 413 // This isn't needed for get_terms
488 414 unset( $args['orderby'] );
489 415
490 416 // Set args for get_terms
491 - $args['menu_order'] = isset( $args['order'] ) ? $args['order'] : 'ASC';
492 - $args['hide_empty'] = isset( $args['hide_empty'] ) ? $args['hide_empty'] : 0;
493 - $args['fields'] = isset( $args['fields'] ) ? $args['fields'] : 'names';
417 + $args['menu_order'] = $args['order'] ?? 'ASC';
418 + $args['hide_empty'] = $args['hide_empty'] ?? 0;
419 + $args['fields'] = $args['fields'] ?? 'names';
494 420
495 421 // Ensure slugs is valid for get_terms - slugs isn't supported
496 422 $args['fields'] = $args['fields'] === 'slugs' ? 'id=>slug' : $args['fields'];
497 423 $terms = get_terms( $taxonomy, $args );
@@ -572,115 +498,8 @@
572 498
573 499 return $id ? get_post( $id ) : false;
574 500 }
575 501
576 -/**
577 - * Cache static pages
578 - *
579 - * @deprecated 4.1.6.8
580 - */
581 -/*function learn_press_setup_pages() {
582 - global $wpdb;
583 -
584 - $page_ids = LP_Object_Cache::get( 'static-page-ids', 'learn-press' );
585 -
586 - if ( false === $page_ids ) {
587 - $pages = learn_press_static_pages( true );
588 - $page_ids = array();
589 -
590 - foreach ( $pages as $page ) {
591 - $id = get_option( 'learn_press_' . $page . '_page_id' );
592 -
593 - if ( absint( $id ) > 0 ) {
594 - $page_ids[] = $id;
595 - }
596 - }
597 -
598 - if ( ! $page_ids ) {
599 - return;
600 - }
601 -
602 - $query = $wpdb->prepare(
603 - "
604 - SELECT ID, post_title, post_name, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_parent, post_type
605 - FROM {$wpdb->posts}
606 - WHERE %d AND ID IN(" . join( ',', $page_ids ) . ')
607 - AND post_status <> %s
608 - ',
609 - 1,
610 - 'trash'
611 - );
612 -
613 - if ( ! $rows = $wpdb->get_results( $query ) ) {
614 - return;
615 - }
616 -
617 - foreach ( $rows as $page ) {
618 - $page = sanitize_post( $page, 'raw' );
619 - wp_cache_add( $page->ID, $page, 'posts' );
620 - }
621 - }
622 -}*/
623 -
624 -function learn_press_get_course_item_object( $post_type ) {
625 - switch ( $post_type ) {
626 - case 'lp_quiz':
627 - $class = 'LP_Quiz';
628 - break;
629 - case 'lp_lesson':
630 - $class = 'LP_Lesson';
631 - break;
632 - case 'lp_question':
633 - $class = 'LP_Question';
634 - }
635 -}
636 -
637 -/**
638 - * Print out js code in the queue
639 - *
640 - * @depecated 4.1.6.8
641 - */
642 -function learn_press_print_script() {
643 - _deprecated_function( __FUNCTION__, '4.1.6.8' );
644 - global $learn_press_queued_js, $learn_press_queued_js_tag;
645 -
646 - if ( ! empty( $learn_press_queued_js ) ) {
647 - ?>
648 - <!-- LearnPress JavaScript -->
649 - <script type="text/javascript">
650 - jQuery(function ($) {
651 - <?php
652 - $learn_press_queued_js = wp_check_invalid_utf8( $learn_press_queued_js );
653 - $learn_press_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $learn_press_queued_js );
654 - $learn_press_queued_js = str_replace( "\r", '', $learn_press_queued_js );
655 -
656 - // echo $learn_press_queued_js;
657 - ?>
658 - })
659 - </script>
660 -
661 - <?php
662 - unset( $learn_press_queued_js );
663 - }
664 -
665 - if ( ! empty( $learn_press_queued_js_tag ) ) {
666 - // echo $learn_press_queued_js_tag;
667 - }
668 -}
669 -
670 -// add_action( 'wp_footer', 'learn_press_print_script' );
671 -// add_action( 'admin_footer', 'learn_press_print_script' );
672 -
673 -
674 -/**
675 - * @param string $str
676 - * @param int $lines
677 - * @depecated 4.1.6.8
678 - */
679 -/*function learn_press_email_new_line( $lines = 1, $str = "\r\n" ) {
680 - echo str_repeat( $str, $lines );
681 -}*/
682 -
683 502 if ( ! function_exists( 'learn_press_is_ajax' ) ) {
684 503 function learn_press_is_ajax() {
685 504 return defined( 'LP_DOING_AJAX' ) && LP_DOING_AJAX && 'yes' != learn_press_get_request( 'noajax' );
686 505 }
@@ -690,16 +509,18 @@
690 509 * Get page id from admin settings page
691 510 *
692 511 * @param string $name
693 512 *
513 + * @since 3.0.0
514 + * @version 1.0.2
694 515 * @return int
695 516 */
696 517 function learn_press_get_page_id( string $name ): int {
697 - $page_id = LP_Settings::instance()->get( "{$name}_page_id", false );
518 + $page_id = LP_Settings::get_option( "{$name}_page_id", false );
698 519
699 - if ( function_exists( 'icl_object_id' ) ) {
520 + /*if ( function_exists( 'icl_object_id' ) ) {
700 521 $page_id = icl_object_id( $page_id, 'page', false, defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '' );
701 - }
522 + }*/
702 523
703 524 $page_id = (int) $page_id;
704 525
705 526 return apply_filters( 'learn_press_get_page_id', $page_id, $name );
@@ -802,9 +623,9 @@
802 623
803 624 if ( $links ) {
804 625 ?>
805 626 <div class="<?php echo esc_attr( $args['wrapper_class'] ); ?>">
806 - <?php echo wp_kses_post( $links ); ?>
627 + <?php echo wp_kses_post( $links ); ?>
807 628 </div>
808 629 <?php
809 630 }
810 631
@@ -835,9 +656,9 @@
835 656
836 657 $pages = absint( $total / $limit );
837 658
838 659 if ( $total % $limit != 0 ) {
839 - $pages ++;
660 + ++$pages;
840 661 }
841 662
842 663 return $pages;
843 664 }
@@ -930,78 +751,12 @@
930 751 return $a1;
931 752 }
932 753
933 754 /**
934 - * Send email notification.
935 - *
936 - * @param string $to .
937 - * @param string $action .
938 - * @param array $vars .
939 - *
940 - * @return bool
941 - */
942 -function learn_press_send_mail( $to = '', $action = '', $vars = array() ) {
943 - $email_settings = LP_Settings::instance();
944 -
945 - if ( ! $email_settings->get( $action . '.enable' ) ) {
946 - return "The action {$action} doesnt support";
947 - }
948 -
949 - $user = get_user_by( 'email', $to );
950 -
951 - $vars['log_in'] = apply_filters( 'learn_press_site_url', get_home_url() );
952 -
953 - // Send email.
954 - $email = new LP_Email();
955 - $email->set_action( $action );
956 - $email->parse_email( $vars );
957 - $email->add_recipient( $to );
958 -
959 - return $email->send();
960 -}
961 -
962 -/*
963 - * Send email notification when a course be published
964 - */
965 -function learn_press_publish_course( $new_status, $old_status, $post ) {
966 - if ( $old_status == 'pending' && $new_status == 'publish' && $post->post_type == 'lp_course' ) {
967 - $instructor = get_userdata( $post->post_author );
968 - $mail_to = $instructor->user_email;
969 -
970 - learn_press_send_mail(
971 - $mail_to,
972 - 'published_course',
973 - apply_filters(
974 - 'learn_press_vars_enrolled_course',
975 - array(
976 - 'user_name' => $instructor->display_name,
977 - 'course_name' => $post->post_title,
978 - 'course_link' => get_permalink( $post->ID ),
979 - ),
980 - $post,
981 - $instructor
982 - )
983 - );
984 - }
985 -}
986 -
987 -add_action( 'transition_post_status', 'learn_press_publish_course', 10, 3 );
988 -
989 -/**
990 755 * @param $user_id
991 756 *
992 757 * @return WP_Query
993 - * @depecated 4.1.6.4
994 758 */
995 -function learn_press_get_enrolled_courses( $user_id ) {
996 - return LP()->get_user( $user_id )->get( 'enrolled-courses' );
997 -}
998 -
999 -/**
1000 - * @param $user_id
1001 - *
1002 - * @return WP_Query
1003 - */
1004 759 function learn_press_get_own_courses( $user_id ) {
1005 760 $arr_query = array(
1006 761 'post_type' => 'lp_course',
1007 762 'author' => $user_id,
@@ -1078,365 +833,35 @@
1078 833 /**
1079 834 * Get the list of currencies with code and name.
1080 835 *
1081 836 * @return array
1082 - * @version 3.0.0
837 + * @version 3.0.1
1083 838 *
1084 839 * @author ThimPress
1085 840 */
1086 841 function learn_press_currencies() {
1087 - $currencies = array(
1088 - 'AFN' => __( 'Afghan afghani', 'learnpress' ),
1089 - 'ALL' => __( 'Albanian lek', 'learnpress' ),
1090 - 'DZD' => __( 'Algerian dinar', 'learnpress' ),
1091 - 'EUR' => __( 'Euro', 'learnpress' ),
1092 - 'AOA' => __( 'Angolan kwanza', 'learnpress' ),
1093 - 'XCD' => __( 'East Caribbean dollar', 'learnpress' ),
1094 - 'ARS' => __( 'Argentine peso', 'learnpress' ),
1095 - 'AMD' => __( 'Armenian dram', 'learnpress' ),
1096 - 'AWG' => __( 'Aruban florin', 'learnpress' ),
1097 - 'AUD' => __( 'Australian dollar', 'learnpress' ),
1098 - 'AZN' => __( 'Azerbaijani manat', 'learnpress' ),
1099 - 'BSD' => __( 'Bahamian dollar', 'learnpress' ),
1100 - 'BHD' => __( 'Bahraini dinar', 'learnpress' ),
1101 - 'BDT' => __( 'Bangladeshi taka', 'learnpress' ),
1102 - 'BBD' => __( 'Barbadian dollar', 'learnpress' ),
1103 - 'BYR' => __( 'Belarusian ruble', 'learnpress' ),
1104 - 'BZD' => __( 'Belizean dollar', 'learnpress' ),
1105 - 'XOF' => __( 'West African CFA franc', 'learnpress' ),
1106 - 'BMD' => __( 'Bermudian dollar', 'learnpress' ),
1107 - 'BTN' => __( 'Bhutanese ngultrum', 'learnpress' ),
1108 - 'BOB' => __( 'Bolivian boliviano', 'learnpress' ),
1109 - 'USD' => __( 'US dollar', 'learnpress' ),
1110 - 'BAM' => __( 'Bosnia and Herzegovina convertible mark', 'learnpress' ),
1111 - 'BWP' => __( 'Botswana pula', 'learnpress' ),
1112 - 'BRL' => __( 'Brazilian real', 'learnpress' ),
1113 - 'BND' => __( 'Brunei dollar', 'learnpress' ),
1114 - 'BGN' => __( 'Bulgarian lev', 'learnpress' ),
1115 - 'MMK' => __( 'Burmese kyat', 'learnpress' ),
1116 - 'BIF' => __( 'Burundian franc', 'learnpress' ),
1117 - 'KHR' => __( 'Cambodian riel', 'learnpress' ),
1118 - 'XAF' => __( 'Central African CFA franc', 'learnpress' ),
1119 - 'CAD' => __( 'Canadian dollar', 'learnpress' ),
1120 - 'CVE' => __( 'Cape Verdean escudo', 'learnpress' ),
1121 - 'KYD' => __( 'Cayman Islands dollar', 'learnpress' ),
1122 - 'CLP' => __( 'Chilean peso', 'learnpress' ),
1123 - 'CNY' => __( 'Chinese renminbi', 'learnpress' ),
1124 - 'COP' => __( 'Colombian peso', 'learnpress' ),
1125 - 'KMF' => __( 'Comorian franc', 'learnpress' ),
1126 - 'CDF' => __( 'Congolese franc', 'learnpress' ),
1127 - 'NZD' => __( 'New Zealand dollar', 'learnpress' ),
1128 - 'CRC' => __( 'Costa Rican colón', 'learnpress' ),
1129 - 'HRK' => __( 'Croatian kuna', 'learnpress' ),
1130 - 'CUC' => __( 'Cuban peso', 'learnpress' ),
1131 - 'ANG' => __( 'Netherlands Antilles guilder', 'learnpress' ),
1132 - 'CZK' => __( 'Czech koruna', 'learnpress' ),
1133 - 'DKK' => __( 'Danish krone', 'learnpress' ),
1134 - 'DJF' => __( 'Djiboutian franc', 'learnpress' ),
1135 - 'DOP' => __( 'Dominican peso', 'learnpress' ),
1136 - 'EGP' => __( 'Egyptian pound', 'learnpress' ),
1137 - 'SVC' => __( 'Salvadoran colón', 'learnpress' ),
1138 - 'ERN' => __( 'Eritrean nakfa', 'learnpress' ),
1139 - 'ETB' => __( 'Ethiopian birr', 'learnpress' ),
1140 - 'FKP' => __( 'Falkland Islands pound', 'learnpress' ),
1141 - 'FJD' => __( 'Fijian dollar', 'learnpress' ),
1142 - 'XPF' => __( 'CFP franc', 'learnpress' ),
1143 - 'GMD' => __( 'Gambian dalasi', 'learnpress' ),
1144 - 'GEL' => __( 'Georgian lari', 'learnpress' ),
1145 - 'GHS' => __( 'Ghanian cedi', 'learnpress' ),
1146 - 'GIP' => __( 'Gibraltar pound', 'learnpress' ),
1147 - 'GTQ' => __( 'Guatemalan quetzal', 'learnpress' ),
1148 - 'GBP' => __( 'British pound', 'learnpress' ),
1149 - 'GNF' => __( 'Guinean franc', 'learnpress' ),
1150 - 'GYD' => __( 'Guyanese dollar', 'learnpress' ),
1151 - 'HTG' => __( 'Haitian gourde', 'learnpress' ),
1152 - 'HNL' => __( 'Honduran lempira', 'learnpress' ),
1153 - 'HKD' => __( 'Hong Kong dollar', 'learnpress' ),
1154 - 'HUF' => __( 'Hungarian forint', 'learnpress' ),
1155 - 'ISK' => __( 'Icelandic króna', 'learnpress' ),
1156 - 'INR' => __( 'Indian rupee', 'learnpress' ),
1157 - 'IDR' => __( 'Indonesian rupiah', 'learnpress' ),
1158 - 'IRR' => __( 'Iranian rial', 'learnpress' ),
1159 - 'IQD' => __( 'Iraqi dinar', 'learnpress' ),
1160 - 'ILS' => __( 'Israeli new sheqel', 'learnpress' ),
1161 - 'JMD' => __( 'Jamaican dollar', 'learnpress' ),
1162 - 'JPY' => __( 'Japanese yen ', 'learnpress' ),
1163 - 'JOD' => __( 'Jordanian dinar', 'learnpress' ),
1164 - 'KZT' => __( 'Kazakhstani tenge', 'learnpress' ),
1165 - 'KES' => __( 'Kenyan shilling', 'learnpress' ),
1166 - 'KPW' => __( 'North Korean won', 'learnpress' ),
1167 - 'KWD' => __( 'Kuwaiti dinar', 'learnpress' ),
1168 - 'KGS' => __( 'Kyrgyzstani som', 'learnpress' ),
1169 - 'KRW' => __( 'South Korean won', 'learnpress' ),
1170 - 'LAK' => __( 'Lao kip', 'learnpress' ),
1171 - 'LVL' => __( 'Latvian lats', 'learnpress' ),
1172 - 'LBP' => __( 'Lebanese pound', 'learnpress' ),
1173 - 'LSL' => __( 'Lesotho loti', 'learnpress' ),
1174 - 'LRD' => __( 'Liberian dollar', 'learnpress' ),
1175 - 'LD' => __( 'Libyan dinar', 'learnpress' ),
1176 - 'CHF' => __( 'Swiss franc', 'learnpress' ),
1177 - 'LTL' => __( 'Lithuanian litas', 'learnpress' ),
1178 - 'MOP' => __( 'Macanese pataca', 'learnpress' ),
1179 - 'MKD' => __( 'Macedonian denar', 'learnpress' ),
1180 - 'MGA' => __( 'Malagasy ariary', 'learnpress' ),
1181 - 'MWK' => __( 'Malawian kwacha', 'learnpress' ),
1182 - 'MYR' => __( 'Malaysian ringgit', 'learnpress' ),
1183 - 'MVR' => __( 'Maldivian rufiyaa', 'learnpress' ),
1184 - 'MRO' => __( 'Mauritanian ouguiya', 'learnpress' ),
1185 - 'MUR' => __( 'Mauritian rupee', 'learnpress' ),
1186 - 'MXN' => __( 'Mexican peso', 'learnpress' ),
1187 - 'MDL' => __( 'Moldovan leu', 'learnpress' ),
1188 - 'MNT' => __( 'Mongolian tugrik', 'learnpress' ),
1189 - 'MAD' => __( 'Moroccan dirham', 'learnpress' ),
1190 - 'MZN' => __( 'Mozambican metical', 'learnpress' ),
1191 - 'NAD' => __( 'Namibian dollar', 'learnpress' ),
1192 - 'NPR' => __( 'Nepalese rupee', 'learnpress' ),
1193 - 'NIO' => __( 'Nicaraguan córdoba', 'learnpress' ),
1194 - 'NGN' => __( 'Nigerian naira', 'learnpress' ),
1195 - 'NOK' => __( 'Norwegian krone', 'learnpress' ),
1196 - 'OMR' => __( 'Omani rial', 'learnpress' ),
1197 - 'PKR' => __( 'Pakistani rupee', 'learnpress' ),
1198 - 'PAB' => __( 'Panamanian balboa', 'learnpress' ),
1199 - 'PGK' => __( 'Papua New Guinea kina', 'learnpress' ),
1200 - 'PYG' => __( 'Paraguayan guarani', 'learnpress' ),
1201 - 'PEN' => __( 'Peruvian nuevo sol', 'learnpress' ),
1202 - 'PHP' => __( 'Philippine peso', 'learnpress' ),
1203 - 'PLN' => __( 'Polish zloty', 'learnpress' ),
1204 - 'QAR' => __( 'Qatari riyal', 'learnpress' ),
1205 - 'RON' => __( 'Romanian leu', 'learnpress' ),
1206 - 'RUB' => __( 'Russian ruble', 'learnpress' ),
1207 - 'RWF' => __( 'Rwandan franc', 'learnpress' ),
1208 - 'WST' => __( 'Samoan tālā', 'learnpress' ),
1209 - 'STD' => __( 'São Tomé and Príncipe dobra', 'learnpress' ),
1210 - 'SAR' => __( 'Saudi riyal', 'learnpress' ),
1211 - 'RSD' => __( 'Serbian dinar', 'learnpress' ),
1212 - 'SCR' => __( 'Seychellois rupee', 'learnpress' ),
1213 - 'SLL' => __( 'Sierra Leonean leone', 'learnpress' ),
1214 - 'SGD' => __( 'Singapore dollar', 'learnpress' ),
1215 - 'SBD' => __( 'Solomon Islands dollar', 'learnpress' ),
1216 - 'SOS' => __( 'Somali shilling', 'learnpress' ),
1217 - 'ZAR' => __( 'South African rand', 'learnpress' ),
1218 - 'LKR' => __( 'Sri Lankan rupee', 'learnpress' ),
1219 - 'SHP' => __( 'St. Helena pound', 'learnpress' ),
1220 - 'SDG' => __( 'Sudanese pound', 'learnpress' ),
1221 - 'SRD' => __( 'Surinamese dollar', 'learnpress' ),
1222 - 'SZL' => __( 'Swazi lilangeni', 'learnpress' ),
1223 - 'SEK' => __( 'Swedish krona', 'learnpress' ),
1224 - 'SYP' => __( 'Syrian pound', 'learnpress' ),
1225 - 'TWD' => __( 'New Taiwan dollar', 'learnpress' ),
1226 - 'TJS' => __( 'Tajikistani somoni', 'learnpress' ),
1227 - 'TZS' => __( 'Tanzanian shilling', 'learnpress' ),
1228 - 'THB' => __( 'Thai baht ', 'learnpress' ),
1229 - 'TOP' => __( 'Tongan pa’anga', 'learnpress' ),
1230 - 'TTD' => __( 'Trinidad and Tobago dollar', 'learnpress' ),
1231 - 'TND' => __( 'Tunisian dinar', 'learnpress' ),
1232 - 'TRY' => __( 'Turkish lira', 'learnpress' ),
1233 - 'TMT' => __( 'Turkmenistani manat', 'learnpress' ),
1234 - 'UGX' => __( 'Ugandan shilling', 'learnpress' ),
1235 - 'UAH' => __( 'Ukrainian hryvnia', 'learnpress' ),
1236 - 'AED' => __( 'United Arab Emirates dirham', 'learnpress' ),
1237 - 'UYU' => __( 'Uruguayan peso', 'learnpress' ),
1238 - 'UZS' => __( 'Uzbekistani som', 'learnpress' ),
1239 - 'VUV' => __( 'Vanuatu vatu', 'learnpress' ),
1240 - 'VEF' => __( 'Venezuelan bolivar', 'learnpress' ),
1241 - 'VND' => __( 'Vietnamese dong', 'learnpress' ),
1242 - 'YER' => __( 'Yemeni rial', 'learnpress' ),
1243 - 'ZMK' => __( 'Zambian kwacha', 'learnpress' ),
1244 - 'ZWL' => __( 'Zimbabwean dollar', 'learnpress' ),
1245 - 'JEP' => __( 'Jersey pound', 'learnpress' ),
1246 - 'LYD' => __( 'Libyan dinar', 'learnpress' ),
1247 - );
1248 -
1249 - asort( $currencies );
1250 -
1251 - return apply_filters( 'learn-press/currencies', $currencies );
842 + return Config::instance()->get( 'currencies', 'settings' );
1252 843 }
1253 844
1254 845 /**
1255 - * Get current setting of currency.
846 + * Return list of common symbols of the currencies on the world.
1256 847 *
1257 - * @return string
848 + * @return array
849 + * @version 3.0.1
1258 850 */
1259 -function learn_press_get_currency() {
1260 - $currency = apply_filters( 'learn_press_currency', LP_Settings::instance()->get( 'currency', 'USD' ) );
1261 -
1262 - return apply_filters( 'learn-press/currency', $currency );
851 +function learn_press_currency_symbols() {
852 + return Config::instance()->get( 'currency-symbols', 'settings' );
1263 853 }
1264 854
1265 855 /**
1266 - * Return list of common symbols of the currencies on the world.
856 + * Get current setting of currency.
1267 857 *
1268 - * @return array
858 + * @return string
1269 859 */
1270 -function learn_press_currency_symbols() {
1271 - $symbols = array(
1272 - 'AED' => '&#x62f;.&#x625;',
1273 - 'AFN' => '&#x60b;',
1274 - 'ALL' => 'L',
1275 - 'AMD' => 'AMD',
1276 - 'ANG' => '&fnof;',
1277 - 'AOA' => 'Kz',
1278 - 'ARS' => '&#36;',
1279 - 'AUD' => '&#36;',
1280 - 'AWG' => 'Afl.',
1281 - 'AZN' => 'AZN',
1282 - 'BAM' => 'KM',
1283 - 'BBD' => '&#36;',
1284 - 'BDT' => '&#2547;&nbsp;',
1285 - 'BGN' => '&#1083;&#1074;.',
1286 - 'BHD' => '.&#x62f;.&#x628;',
1287 - 'BIF' => 'Fr',
1288 - 'BMD' => '&#36;',
1289 - 'BND' => '&#36;',
1290 - 'BOB' => 'Bs.',
1291 - 'BRL' => '&#82;&#36;',
1292 - 'BSD' => '&#36;',
1293 - 'BTC' => '&#3647;',
1294 - 'BTN' => 'Nu.',
1295 - 'BWP' => 'P',
1296 - 'BYR' => 'Br',
1297 - 'BYN' => 'Br',
1298 - 'BZD' => '&#36;',
1299 - 'CAD' => '&#36;',
1300 - 'CDF' => 'Fr',
1301 - 'CHF' => '&#67;&#72;&#70;',
1302 - 'CLP' => '&#36;',
1303 - 'CNY' => '&yen;',
1304 - 'COP' => '&#36;',
1305 - 'CRC' => '&#x20a1;',
1306 - 'CUC' => '&#36;',
1307 - 'CUP' => '&#36;',
1308 - 'CVE' => '&#36;',
1309 - 'CZK' => '&#75;&#269;',
1310 - 'DJF' => 'Fr',
1311 - 'DKK' => 'DKK',
1312 - 'DOP' => 'RD&#36;',
1313 - 'DZD' => '&#x62f;.&#x62c;',
1314 - 'EGP' => 'EGP',
1315 - 'ERN' => 'Nfk',
1316 - 'ETB' => 'Br',
1317 - 'EUR' => '&euro;',
1318 - 'FJD' => '&#36;',
1319 - 'FKP' => '&pound;',
1320 - 'GBP' => '&pound;',
1321 - 'GEL' => '&#x20be;',
1322 - 'GGP' => '&pound;',
1323 - 'GHS' => '&#x20b5;',
1324 - 'GIP' => '&pound;',
1325 - 'GMD' => 'D',
1326 - 'GNF' => 'Fr',
1327 - 'GTQ' => 'Q',
1328 - 'GYD' => '&#36;',
1329 - 'HKD' => '&#36;',
1330 - 'HNL' => 'L',
1331 - 'HRK' => 'kn',
1332 - 'HTG' => 'G',
1333 - 'HUF' => '&#70;&#116;',
1334 - 'IDR' => 'Rp',
1335 - 'ILS' => '&#8362;',
1336 - 'IMP' => '&pound;',
1337 - 'INR' => '&#8377;',
1338 - 'IQD' => '&#x639;.&#x62f;',
1339 - 'IRR' => '&#xfdfc;',
1340 - 'IRT' => '&#x062A;&#x0648;&#x0645;&#x0627;&#x0646;',
1341 - 'ISK' => 'kr.',
1342 - 'JEP' => '&pound;',
1343 - 'JMD' => '&#36;',
1344 - 'JOD' => '&#x62f;.&#x627;',
1345 - 'JPY' => '&yen;',
1346 - 'KES' => 'KSh',
1347 - 'KGS' => '&#x441;&#x43e;&#x43c;',
1348 - 'KHR' => '&#x17db;',
1349 - 'KMF' => 'Fr',
1350 - 'KPW' => '&#x20a9;',
1351 - 'KRW' => '&#8361;',
1352 - 'KWD' => '&#x62f;.&#x643;',
1353 - 'KYD' => '&#36;',
1354 - 'KZT' => '&#8376;',
1355 - 'LAK' => '&#8365;',
1356 - 'LBP' => '&#x644;.&#x644;',
1357 - 'LKR' => '&#xdbb;&#xdd4;',
1358 - 'LRD' => '&#36;',
1359 - 'LSL' => 'L',
1360 - 'LYD' => '&#x644;.&#x62f;',
1361 - 'MAD' => '&#x62f;.&#x645;.',
1362 - 'MDL' => 'MDL',
1363 - 'MGA' => 'Ar',
1364 - 'MKD' => '&#x434;&#x435;&#x43d;',
1365 - 'MMK' => 'Ks',
1366 - 'MNT' => '&#x20ae;',
1367 - 'MOP' => 'P',
1368 - 'MRU' => 'UM',
1369 - 'MUR' => '&#x20a8;',
1370 - 'MVR' => '.&#x783;',
1371 - 'MWK' => 'MK',
1372 - 'MXN' => '&#36;',
1373 - 'MYR' => '&#82;&#77;',
1374 - 'MZN' => 'MT',
1375 - 'NAD' => 'N&#36;',
1376 - 'NGN' => '&#8358;',
1377 - 'NIO' => 'C&#36;',
1378 - 'NOK' => '&#107;&#114;',
1379 - 'NPR' => '&#8360;',
1380 - 'NZD' => '&#36;',
1381 - 'OMR' => '&#x631;.&#x639;.',
1382 - 'PAB' => 'B/.',
1383 - 'PEN' => 'S/',
1384 - 'PGK' => 'K',
1385 - 'PHP' => '&#8369;',
1386 - 'PKR' => '&#8360;',
1387 - 'PLN' => '&#122;&#322;',
1388 - 'PRB' => '&#x440;.',
1389 - 'PYG' => '&#8370;',
1390 - 'QAR' => '&#x631;.&#x642;',
1391 - 'RMB' => '&yen;',
1392 - 'RON' => 'lei',
1393 - 'RSD' => '&#1088;&#1089;&#1076;',
1394 - 'RUB' => '&#8381;',
1395 - 'RWF' => 'Fr',
1396 - 'SAR' => '&#x631;.&#x633;',
1397 - 'SBD' => '&#36;',
1398 - 'SCR' => '&#x20a8;',
1399 - 'SDG' => '&#x62c;.&#x633;.',
1400 - 'SEK' => '&#107;&#114;',
1401 - 'SGD' => '&#36;',
1402 - 'SHP' => '&pound;',
1403 - 'SLL' => 'Le',
1404 - 'SOS' => 'Sh',
1405 - 'SRD' => '&#36;',
1406 - 'SSP' => '&pound;',
1407 - 'STN' => 'Db',
1408 - 'SYP' => '&#x644;.&#x633;',
1409 - 'SZL' => 'L',
1410 - 'THB' => '&#3647;',
1411 - 'TJS' => '&#x405;&#x41c;',
1412 - 'TMT' => 'm',
1413 - 'TND' => '&#x62f;.&#x62a;',
1414 - 'TOP' => 'T&#36;',
1415 - 'TRY' => '&#8378;',
1416 - 'TTD' => '&#36;',
1417 - 'TWD' => '&#78;&#84;&#36;',
1418 - 'TZS' => 'Sh',
1419 - 'UAH' => '&#8372;',
1420 - 'UGX' => 'UGX',
1421 - 'USD' => '&#36;',
1422 - 'UYU' => '&#36;',
1423 - 'UZS' => 'UZS',
1424 - 'VEF' => 'Bs F',
1425 - 'VES' => 'Bs.S',
1426 - 'VND' => '&#8363;',
1427 - 'VUV' => 'Vt',
1428 - 'WST' => 'T',
1429 - 'XAF' => 'CFA',
1430 - 'XCD' => '&#36;',
1431 - 'XOF' => 'CFA',
1432 - 'XPF' => 'Fr',
1433 - 'YER' => '&#xfdfc;',
1434 - 'ZAR' => '&#82;',
1435 - 'ZMW' => 'ZK',
1436 - );
860 +function learn_press_get_currency(): string {
861 + $currency = LP_Settings::instance()->get( 'currency', 'USD' );
1437 862
1438 - return apply_filters( 'learn-press/currency-symbols', $symbols );
863 + return esc_html( apply_filters( 'learn-press/currency', $currency ) );
1439 864 }
1440 865
1441 866 /**
1442 867 * Return currency symbol from the code.
@@ -1449,9 +874,9 @@
1449 874 if ( ! $currency ) {
1450 875 $currency = learn_press_get_currency();
1451 876 }
1452 877 $symbols = learn_press_currency_symbols();
1453 - $currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : '';
878 + $currency_symbol = $symbols[ $currency ] ?? '';
1454 879
1455 880 $currency_symbol = apply_filters( 'learn_press_currency_symbol', $currency_symbol, $currency );
1456 881
1457 882 return apply_filters( 'learn-press/currency-symbol', $currency_symbol, $currency );
@@ -1466,14 +891,19 @@
1466 891 * @editor tungnx
1467 892 * @modify 4.1.4
1468 893 */
1469 894 function learn_press_get_page_link( string $key ): string {
1470 - $page_id = learn_press_get_page_id( $key );
1471 - $link = '';
895 + $page_id = learn_press_get_page_id( $key );
896 + $key_cache = "lp/page-link/{$key}";
897 + $link = LP_Cache::cache_load_first( 'get', $key_cache );
898 + if ( false !== $link ) {
899 + return $link;
900 + }
1472 901
1473 902 if ( $page_id && get_post_status( $page_id ) == 'publish' ) {
1474 903 $permalink = get_permalink( $page_id );
1475 904 $link = apply_filters( 'learn-press/get-page-link', trailingslashit( $permalink ), $page_id, $key );
905 + LP_Cache::cache_load_first( 'set', $key_cache, $link );
1476 906 }
1477 907
1478 908 return $link;
1479 909 }
@@ -1574,54 +1004,8 @@
1574 1004
1575 1005 return $result;
1576 1006 }
1577 1007
1578 -/**
1579 - * @depecated since version 4.1.6.6
1580 - */
1581 -/*function learn_press_get_query_var( $var ) {
1582 - global $wp_query;
1583 -
1584 - $return = null;
1585 - if ( ! empty( $wp_query->query_vars[ $var ] ) ) {
1586 - $return = $wp_query->query_vars[ $var ];
1587 - } elseif ( ! empty( $_REQUEST[ $var ] ) ) {
1588 - $return = $_REQUEST[ $var ];
1589 - }
1590 -
1591 - return apply_filters( 'learn_press_query_var', $return, $var );
1592 -}*/
1593 -
1594 -function learn_press_course_lesson_permalink_friendly( $permalink, $lesson_id, $course_id ) {
1595 - if ( '' != get_option( 'permalink_structure' ) ) {
1596 - if ( preg_match( '!\?lesson=([^\?\&]*)!', $permalink, $matches ) ) {
1597 - $permalink = preg_replace(
1598 - '!/?\?lesson=([^\?\&]*)!',
1599 - '/' . basename( get_permalink( $matches[1] ) ),
1600 - untrailingslashit( $permalink )
1601 - );
1602 - }
1603 - }
1604 -
1605 - return $permalink;
1606 -}
1607 -
1608 -function learn_press_course_question_permalink_friendly( $permalink, $lesson_id, $course_id ) {
1609 - if ( '' != get_option( 'permalink_structure' ) ) {
1610 - if ( preg_match( '!\?lesson=([^\?\&]*)!', $permalink, $matches ) ) {
1611 - $permalink = preg_replace(
1612 - '!/?\?lesson=([^\?\&]*)!',
1613 - '/' . basename( get_permalink( $matches[1] ) ),
1614 - untrailingslashit( $permalink )
1615 - );
1616 - }
1617 - }
1618 -
1619 - return $permalink;
1620 -}
1621 -
1622 -add_filter( 'learn_press_course_lesson_permalink', 'learn_press_course_lesson_permalink_friendly', 10, 3 );
1623 -
1624 1008 function learn_press_user_maybe_is_a_teacher( $user = null ) {
1625 1009 if ( ! $user ) {
1626 1010 $user = learn_press_get_current_user();
1627 1011 } elseif ( is_numeric( $user ) ) {
@@ -1626,9 +1010,9 @@
1626 1010 $user = learn_press_get_current_user();
1627 1011 } elseif ( is_numeric( $user ) ) {
1628 1012 $user = learn_press_get_user( $user );
1629 1013 }
1630 - if ( ! $user ) {
1014 + if ( ! $user || $user instanceof LP_User_Guest ) {
1631 1015 return false;
1632 1016 }
1633 1017
1634 1018 $role = $user->has_role( 'administrator' ) ? 'administrator' : false;
@@ -1659,60 +1043,8 @@
1659 1043 }
1660 1044
1661 1045 add_filter( 'gettext_with_context', '_learn_press_translate_user_roles', 10, 4 );
1662 1046
1663 -/**
1664 - * Modifies the statement $where to make the search works correct
1665 - *
1666 - * @param string
1667 - *
1668 - * @return string
1669 - */
1670 -function learn_press_posts_where_statement_search( $where ) {
1671 - // gets the global query var object
1672 - global $wp_query, $wpdb;
1673 -
1674 - /**
1675 - * Need to wrap this block into () in order to make it works correctly when filter by specific post type => maybe a bug :)
1676 - * from => ( wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') OR wp_2_terms.name LIKE '%s%'
1677 - * to => ( ( wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') OR wp_2_terms.name LIKE '%s%' )
1678 - */
1679 - $a = preg_match( '!(' . $wpdb->posts . '.post_status)!', $where );
1680 - $b = preg_match( '!(OR\s+' . $wpdb->terms . '.name LIKE \'%' . $wp_query->get( 's' ) . '%\')!', $where );
1681 -
1682 - if ( $a && $b ) {
1683 - // append ( to the start of the block
1684 - $where = preg_replace( '!(' . $wpdb->posts . '.post_status)!', '( $1', $where, 1 );
1685 -
1686 - // append ) to the end of the block
1687 - $where = preg_replace(
1688 - '!(OR\s+' . $wpdb->terms . '.name LIKE \'%' . $wp_query->get( 's' ) . '%\')!',
1689 - '$1 )',
1690 - $where
1691 - );
1692 - }
1693 - remove_filter( 'posts_where', 'learn_press_posts_where_statement_search', 99 );
1694 -
1695 - return $where;
1696 -}
1697 -
1698 -/**
1699 - * Filter post type for search function
1700 - * Only search lpr_course if see the param ref=course in request
1701 - *
1702 - * @param WP_Query $q
1703 - */
1704 -function learn_press_filter_search( $q ) {
1705 - if ( $q->is_main_query() && $q->is_search() && ( ! empty( $_REQUEST['ref'] ) && sanitize_text_field( $_REQUEST['ref'] ) == 'course' ) ) {
1706 - $q->set( 'post_type', 'lp_course' );
1707 -
1708 - add_filter( 'posts_where', 'learn_press_posts_where_statement_search', 99 );
1709 - remove_filter( 'pre_get_posts', 'learn_press_filter_search', 99 );
1710 - }
1711 -}
1712 -
1713 -add_filter( 'pre_get_posts', 'learn_press_filter_search', 99 );
1714 -
1715 1047 if ( ! function_exists( 'learn_press_send_json' ) ) {
1716 1048 function learn_press_send_json( $data ) {
1717 1049 echo '<-- LP_AJAX_START -->';
1718 1050 echo wp_json_encode( $data );
@@ -1779,9 +1111,10 @@
1779 1111 */
1780 1112 function learn_press_maybe_send_json( $data, $callback = null ) {
1781 1113 if ( learn_press_is_ajax() ) {
1782 1114 is_callable( $callback ) && call_user_func( $callback );
1783 - if ( empty( $data['message'] ) && ( $message = learn_press_get_messages( true ) ) ) {
1115 + $message = learn_press_get_messages( true );
1116 + if ( empty( $data['message'] ) && $message ) {
1784 1117 $data['message'] = $message;
1785 1118 }
1786 1119 learn_press_send_json( $data );
1787 1120 }
@@ -1798,13 +1131,13 @@
1798 1131 *
1799 1132 * @return mixed
1800 1133 */
1801 1134 function learn_press_get_request( $key, $default = null, $hash = null ) {
1802 - $return = LP_Helper::sanitize_params_submitted( $default );
1135 + $return = $default;
1803 1136
1804 1137 if ( $hash ) {
1805 1138 if ( ! empty( $hash[ $key ] ) ) {
1806 - $return = LP_Helper::sanitize_params_submitted( $hash[ $key ] );
1139 + $return = $hash[ $key ];
1807 1140 }
1808 1141 } else {
1809 1142 if ( ! empty( $_POST[ $key ] ) ) {
1810 1143 $return = LP_Helper::sanitize_params_submitted( $_POST[ $key ] );
@@ -1845,14 +1178,13 @@
1845 1178 function learn_press_is_course_archive() {
1846 1179 global $wp_query;
1847 1180
1848 1181 $queried_object_id = ! empty( $wp_query->queried_object ) ? $wp_query->queried_object : 0;
1849 - $is_courses = defined( 'LEARNPRESS_IS_COURSES' ) && LEARNPRESS_IS_COURSES;
1850 1182 $is_tag = defined( 'LEARNPRESS_IS_TAG' ) && LEARNPRESS_IS_TAG || is_tax( 'course_tag' );
1851 1183 $is_category = defined( 'LEARNPRESS_IS_CATEGORY' ) && LEARNPRESS_IS_CATEGORY || is_tax( 'course_category' );
1852 1184 $page_id = learn_press_get_page_id( 'courses' );
1853 1185
1854 - return ( $is_courses || $is_category || $is_tag ) || is_post_type_archive( 'lp_course' ) || ( $page_id && ( $queried_object_id && is_page( $page_id ) ) );
1186 + return ( $is_category || $is_tag ) || is_post_type_archive( 'lp_course' ) || ( $page_id && ( $queried_object_id && is_page( $page_id ) ) );
1855 1187 }
1856 1188 }
1857 1189
1858 1190 if ( ! function_exists( 'learn_press_is_course_tax' ) ) {
@@ -1881,10 +1213,15 @@
1881 1213 }
1882 1214 }
1883 1215
1884 1216 if ( ! function_exists( 'learn_press_is_course' ) ) {
1885 - function learn_press_is_course() {
1886 - return is_singular( array( LP_COURSE_CPT ) );
1217 + function learn_press_is_course(): bool {
1218 + try {
1219 + return is_singular( array( LP_COURSE_CPT ) );
1220 + } catch ( Throwable $e ) {
1221 + }
1222 +
1223 + return false;
1887 1224 }
1888 1225 }
1889 1226
1890 1227 if ( ! function_exists( 'learn_press_is_lesson' ) ) {
@@ -1934,8 +1271,19 @@
1934 1271
1935 1272 return apply_filters( 'learn-press/is-checkout', false );
1936 1273 }
1937 1274
1275 +function learn_press_is_instructors() {
1276 + $page_id = learn_press_get_page_id( 'instructors' );
1277 +
1278 + if ( $page_id && is_page( $page_id ) ) {
1279 + return true;
1280 + }
1281 +
1282 + return apply_filters( 'learn-press/is-instructor', false );
1283 +}
1284 +
1285 +
1938 1286 /**
1939 1287 * Return register permalink
1940 1288 *
1941 1289 * @return mixed
@@ -1950,10 +1298,12 @@
1950 1298 * @param string
1951 1299 * @param string
1952 1300 *
1953 1301 * @return mixed
1302 + * @deprecated 4.2.5
1954 1303 */
1955 1304 function learn_press_add_notice( $message, $type = 'updated' ) {
1305 + _deprecated_function( __FUNCTION__, '4.2.5' );
1956 1306 LP_Admin_Notice::instance()->add( $message, $type );
1957 1307 }
1958 1308
1959 1309 /**
@@ -1958,29 +1308,29 @@
1958 1308
1959 1309 /**
1960 1310 * Set user's cookie
1961 1311 *
1962 - * @param $name
1963 - * @param $value
1964 - * @param int $expire
1965 - * @param bool $secure
1312 + * @param string $name
1313 + * @param mixed $value
1314 + * @param int $expire
1315 + * @param bool $httponly
1966 1316 *
1967 1317 * @editor tungnx
1968 - * @version 1.0.2
1318 + * @version 1.0.3
1969 1319 */
1970 -function learn_press_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
1971 - $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
1972 -
1973 - @setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, $httponly );
1320 +function learn_press_setcookie( string $name = '', string $value = '', int $expire = 0, bool $httponly = true ) {
1321 + @setcookie( $name, $value, $expire, COOKIEPATH ?: '/', COOKIE_DOMAIN, is_ssl(), $httponly );
1974 1322 }
1975 1323
1976 1324 /**
1977 1325 * Clear cookie
1978 1326 *
1979 - * @param $name
1327 + * @param string $name
1980 1328 */
1981 -function learn_press_remove_cookie( $name ) {
1982 - setcookie( $name, '', time() - YEAR_IN_SECONDS, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN );
1329 +function learn_press_remove_cookie( string $name = '' ) {
1330 + if ( ! empty( $name ) ) {
1331 + setcookie( $name, '', time() - YEAR_IN_SECONDS, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, is_ssl(), true );
1332 + }
1983 1333
1984 1334 if ( array_key_exists( $name, $_COOKIE ) ) {
1985 1335 unset( $_COOKIE[ $name ] );
1986 1336 }
@@ -1986,9 +1336,9 @@
1986 1336 }
1987 1337 }
1988 1338
1989 1339 /**
1990 - * Filter the login url so third-party can be customize
1340 + * Filter the login url so third-party can be customized
1991 1341 *
1992 1342 * @param string $redirect
1993 1343 *
1994 1344 * @return mixed
@@ -2019,9 +1369,9 @@
2019 1369 $url = get_permalink();
2020 1370 }
2021 1371
2022 1372 // Map endpoint to options
2023 - $name = isset( LP()->query_vars[ $name ] ) ? LP()->query_vars[ $name ] : $name;
1373 + $name = isset( LearnPress::instance()->query_vars[ $name ] ) ? LearnPress::instance()->query_vars[ $name ] : $name;
2024 1374
2025 1375 if ( get_option( 'permalink_structure' ) ) {
2026 1376 if ( strstr( $url, '?' ) ) {
2027 1377 $query_string = '?' . parse_url( $url, PHP_URL_QUERY );
@@ -2038,45 +1388,12 @@
2038 1388 return apply_filters( 'learn_press_get_endpoint_url', esc_url_raw( $url ), $name, $value, $url );
2039 1389 }
2040 1390
2041 1391 /**
2042 - * Add all endpoints from settings to the pages.
1392 + * @deprecated 4.2.3
2043 1393 */
2044 -function learn_press_add_endpoints() {
2045 - $settings = LP_Settings::instance();
2046 -
2047 - $endpoints = $settings->get_checkout_endpoints();
2048 - if ( $endpoints ) {
2049 - foreach ( $endpoints as $endpoint => $value ) {
2050 - LP()->query_vars[ $endpoint ] = $value;
2051 - add_rewrite_endpoint( $value, EP_PAGES );
2052 - }
2053 - }
2054 -
2055 - $endpoints = $settings->get_profile_endpoints();
2056 - if ( $endpoints ) {
2057 - foreach ( $endpoints as $endpoint => $value ) {
2058 - LP()->query_vars[ $endpoint ] = $value;
2059 - add_rewrite_endpoint( $value, EP_PAGES );
2060 - }
2061 - }
2062 -
2063 - $endpoints = $settings->get( 'quiz_endpoints' );
2064 - if ( $endpoints ) {
2065 - foreach ( $endpoints as $endpoint => $value ) {
2066 - $endpoint = preg_replace( '!_!', '-', $endpoint );
2067 - LP()->query_vars[ $endpoint ] = $value;
2068 - add_rewrite_endpoint(
2069 - $value, /*EP_ROOT | */
2070 - EP_PAGES
2071 - );
2072 - }
2073 - }
2074 -}
2075 -
2076 -add_action( 'init', 'learn_press_add_endpoints' );
2077 -
2078 1394 function learn_press_is_yes( $value ) {
1395 + _deprecated_function( __FUNCTION__, '4.2.3' );
2079 1396 return ( $value === 1 ) || ( $value === '1' ) || ( $value == 'yes' ) || ( $value == true ) || ( $value == 'on' );
2080 1397 }
2081 1398
2082 1399 /**
@@ -2082,10 +1399,12 @@
2082 1399 /**
2083 1400 * @param mixed $value
2084 1401 *
2085 1402 * @return bool
1403 + * @deprecated 4.2.3
2086 1404 */
2087 1405 function _is_false_value( $value ) {
1406 + _deprecated_function( __FUNCTION__, '4.2.3' );
2088 1407 if ( is_numeric( $value ) ) {
2089 1408 return $value == 0;
2090 1409 } elseif ( is_string( $value ) ) {
2091 1410 return ( empty( $value ) || is_null( $value ) || in_array( $value, array( 'no', 'off', 'false' ) ) );
@@ -2101,9 +1420,9 @@
2101 1420 function learn_press_parse_request() {
2102 1421 global $wp;
2103 1422
2104 1423 // Map query vars to their keys, or get them if endpoints are not supported
2105 - foreach ( LP()->query_vars as $key => $var ) {
1424 + foreach ( LearnPress::instance()->query_vars as $key => $var ) {
2106 1425 if ( isset( $_GET[ $var ] ) ) {
2107 1426 $wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $_GET[ $var ] ?? '' );
2108 1427 } elseif ( isset( $wp->query_vars[ $var ] ) ) {
2109 1428 $wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $wp->query_vars[ $var ] ?? '' );
@@ -2125,53 +1444,18 @@
2125 1444 }
2126 1445 }
2127 1446
2128 1447 /**
2129 - * @param string $handle
2130 - * @param bool $hash
2131 - *
2132 - * @return string
2133 - */
2134 -function learn_press_get_log_file_path( $handle, $hash = false ) {
2135 - if ( $hash ) {
2136 - $hash = '-' . sanitize_file_name( wp_hash( $handle ) );
2137 - }
2138 -
2139 - return trailingslashit( LP_LOG_PATH ) . $handle . $hash . '.log';
2140 -}
2141 -
2142 -/**
2143 1448 * Get the cart object in checkout page
2144 1449 *
2145 1450 * @return LP_Cart
1451 + * @deprecated 4.2.0
2146 1452 */
2147 1453 function learn_press_get_checkout_cart() {
2148 - return apply_filters( 'learn_press_checkout_cart', LP()->cart );
1454 + _deprecated_function( __FUNCTION__, '4.2.0', 'LearnPress::instance()->cart' );
1455 + return apply_filters( 'learn_press_checkout_cart', LearnPress::instance()->cart );
2149 1456 }
2150 1457
2151 -/*function learn_press_front_scripts() {
2152 - if ( is_admin() ) {
2153 - return;
2154 - }
2155 - $js = array(
2156 - 'ajax' => admin_url( 'admin-ajax.php' ),
2157 - 'plugin_url' => LP()->plugin_url(),
2158 - 'siteurl' => home_url(),
2159 - 'current_url' => learn_press_get_current_url(),
2160 - 'localize' => array(
2161 - 'button_ok' => __( 'OK', 'learnpress' ),
2162 - 'button_cancel' => __( 'Cancel', 'learnpress' ),
2163 - 'button_yes' => __( 'Yes', 'learnpress' ),
2164 - 'button_no' => __( 'No', 'learnpress' ),
2165 - ),
2166 - );
2167 - foreach ( $js as $k => $v ) {
2168 - LP_Assets::add_param( $k, $v, array( 'learn-press-single-course', 'learn-press-global' ), 'LP_Settings' );
2169 - }
2170 -}
2171 -
2172 -add_action( 'wp_print_scripts', 'learn_press_front_scripts' );*/
2173 -
2174 1458 function learn_press_user_time( $time, $format = 'timestamp' ) {
2175 1459 if ( is_string( $time ) ) {
2176 1460 $time = @strtotime( $time );
2177 1461 }
@@ -2197,13 +1481,20 @@
2197 1481 *
2198 1482 * @param bool $default
2199 1483 *
2200 1484 * @return mixed|string
1485 + * @deprecated 4.2.2
1486 + * addon commission 4.0.2 still use this function
2201 1487 */
2202 1488 function learn_press_get_current_profile_tab( $default = true ) {
2203 1489 global $wp_query, $wp;
2204 1490 $current = '';
2205 1491
1492 + // Only load on profile page.
1493 + if ( ! LP_Page_Controller::is_page_profile() ) {
1494 + return false;
1495 + }
1496 +
2206 1497 if ( ! empty( $_REQUEST['tab'] ) ) {
2207 1498 $current = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] );
2208 1499 } elseif ( ! empty( $wp_query->query_vars['tab'] ) ) {
2209 1500 $current = $wp_query->query_vars['tab'];
@@ -2224,9 +1515,9 @@
2224 1515
2225 1516 return $current;
2226 1517 }
2227 1518
2228 -add_action( 'init', 'learn_press_get_current_profile_tab' );
1519 +//add_action( 'init', 'learn_press_get_current_profile_tab' );
2229 1520
2230 1521 function learn_press_profile_tab_exists( $tab ) {
2231 1522 $tabs = learn_press_get_user_profile_tabs();
2232 1523
@@ -2236,39 +1527,8 @@
2236 1527
2237 1528 return false;
2238 1529 }
2239 1530
2240 -/**
2241 - * Replace the spacing with the + (plus) char.
2242 - *
2243 - * @param string $string
2244 - *
2245 - * @return string
2246 - */
2247 -function _learn_press_urlencode( $string ) {
2248 - return preg_replace( '/\s/', '+', $string );
2249 -}
2250 -
2251 -/**
2252 - * Point the archive post type link to course page if current
2253 - * post type is course and the page for displaying course is
2254 - * setup.
2255 - *
2256 - * @param string $link
2257 - * @param string $post_type
2258 - *
2259 - * @return string
2260 - */
2261 -function learn_press_post_type_archive_link( $link, $post_type ) {
2262 - if ( $post_type == LP_COURSE_CPT && learn_press_get_page_id( 'courses' ) ) {
2263 - $link = learn_press_get_page_link( 'courses' );
2264 - }
2265 -
2266 - return $link;
2267 -}
2268 -
2269 -add_filter( 'post_type_archive_link', 'learn_press_post_type_archive_link', 10, 2 );
2270 -
2271 1531 function learn_press_single_term_title( $prefix = '', $display = true ) {
2272 1532 $term = get_queried_object();
2273 1533
2274 1534 if ( ! $term ) {
@@ -2289,9 +1549,9 @@
2289 1549 return single_term_title( $prefix, $display );
2290 1550 }
2291 1551
2292 1552 if ( $display ) {
2293 - echo $prefix . $term_name;
1553 + echo wp_kses_post( $prefix . $term_name );
2294 1554 }
2295 1555
2296 1556 return $prefix . $term_name;
2297 1557 }
@@ -2368,9 +1628,9 @@
2368 1628 ),
2369 1629 array(
2370 1630 'title' => __( 'Enable cart', 'learnpress' ),
2371 1631 'desc' => __(
2372 - 'Check this option to enable user purchase multiple courses at one time.',
1632 + 'Check this option to enable users to purchase multiple courses at one time.',
2373 1633 'learnpress'
2374 1634 ),
2375 1635 'id' => $class->get_field_name( 'enable_cart' ),
2376 1636 'default' => 'yes',
@@ -2377,9 +1637,9 @@
2377 1637 'type' => 'checkbox',
2378 1638 ),
2379 1639 array(
2380 1640 'title' => __( 'Add to cart redirect', 'learnpress' ),
2381 - 'desc' => __( 'Redirect to checkout immediately after adding course to cart.', 'learnpress' ),
1641 + 'desc' => __( 'Redirect to checkout immediately after adding the course to the cart.', 'learnpress' ),
2382 1642 'id' => $class->get_field_name( 'redirect_after_add' ),
2383 1643 'default' => 'yes',
2384 1644 'type' => 'checkbox',
2385 1645 ),
@@ -2384,9 +1644,9 @@
2384 1644 'type' => 'checkbox',
2385 1645 ),
2386 1646 array(
2387 1647 'title' => __( 'AJAX add to cart', 'learnpress' ),
2388 - 'desc' => __( 'Using AJAX to add course to cart.', 'learnpress' ),
1648 + 'desc' => __( 'Using AJAX to add the course to the cart.', 'learnpress' ),
2389 1649 'id' => $class->get_field_name( 'ajax_add_to_cart' ),
2390 1650 'default' => 'no',
2391 1651 'type' => 'checkbox',
2392 1652 ),
@@ -2435,9 +1695,9 @@
2435 1695 /**
2436 1696 * @return string
2437 1697 */
2438 1698 function learn_press_checkout_needs_payment() {
2439 - return LP()->cart->needs_payment();
1699 + return LearnPress::instance()->cart->needs_payment();
2440 1700 }
2441 1701
2442 1702 /**
2443 1703 * Return plugin basename
@@ -2515,32 +1775,8 @@
2515 1775 die( __FUNCTION__ );
2516 1776 }
2517 1777 }
2518 1778
2519 -/**
2520 - * Get current time to user for calculate remaining time of quiz.
2521 - *
2522 - * @return int
2523 - */
2524 -function learn_press_get_current_time() {
2525 - $current_time = apply_filters( 'learn_press_get_current_time', 0 );
2526 -
2527 - if ( $current_time > 0 ) {
2528 - return $current_time;
2529 - }
2530 -
2531 - $a = current_time( 'timestamp' );
2532 - $b = time();
2533 - $c = current_time( 'mysql' );
2534 - $d = strtotime( $c );
2535 -
2536 - if ( $d == $a ) {
2537 - return $a;
2538 - } else {
2539 - return $b;
2540 - }
2541 -}
2542 -
2543 1779 function learn_press_get_requested_post_type() {
2544 1780 global $pagenow;
2545 1781 if ( $pagenow == 'post-new.php' && ! empty( $_REQUEST['post_type'] ) ) {
2546 1782 $post_type = LP_Helper::sanitize_params_submitted( $_REQUEST['post_type'] );
@@ -2576,24 +1812,8 @@
2576 1812
2577 1813 return apply_filters( 'learn-press/get-graduation-text', $text, $slug );
2578 1814 }
2579 1815
2580 -/*function learn_press_execute_time( $n = 1 ) {
2581 - static $time;
2582 - if ( empty( $time ) ) {
2583 - $time = microtime( true );
2584 -
2585 - return $time;
2586 - } else {
2587 - $execute_time = microtime( true ) - $time;
2588 -
2589 - echo 'Execute time ' . $n * $execute_time . "\n";
2590 - $time = 0;
2591 -
2592 - return $execute_time;
2593 - }
2594 -}*/
2595 -
2596 1816 if ( ! function_exists( 'learn_press_is_negative_value' ) ) {
2597 1817 function learn_press_is_negative_value( $value ) {
2598 1818 $return = in_array( $value, array( 'no', 'off', 'false', '0' ) ) || ! $value || $value == '' || $value == null;
2599 1819
@@ -2657,15 +1877,8 @@
2657 1877 }
2658 1878
2659 1879 add_filter( 'comment_reply_link', 'learn_press_comment_reply_link', 10, 4 );
2660 1880
2661 -function learn_press_deprecated_function( $function, $version, $replacement = null ) {
2662 - if ( LP_Debug::is_debug() ) {
2663 - _deprecated_function( $function, $version, $replacement );
2664 - }
2665 -}
2666 -
2667 -
2668 1881 /**
2669 1882 * Sanitize content of tooltip
2670 1883 *
2671 1884 * @param string $tooltip
@@ -2703,29 +1916,14 @@
2703 1916 echo '<span class="learn-press-tooltip" data-tooltip="' . esc_attr( $tooltip ) . '"></span>';
2704 1917 }
2705 1918
2706 1919 /**
2707 - * Get timezone offset from wp settings.
2708 - *
2709 - * @return float|int
2710 - * @since 3.0.0
2711 - */
2712 -function learn_press_timezone_offset() {
2713 - if ( $tz = get_option( 'timezone_string' ) ) {
2714 - $timezone = new DateTimeZone( $tz );
2715 -
2716 - return $timezone->getOffset( new DateTime( 'now' ) );
2717 - } else {
2718 - return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS;
2719 - }
2720 -}
2721 -
2722 -/**
2723 1920 * Get default static pages of LP.
2724 1921 *
2725 1922 * @return array
2726 1923 *
2727 1924 * @since 3.0.0
1925 + * @deprecated 4.2.3
2728 1926 */
2729 1927 function learn_press_static_page_ids() {
2730 1928 $pages = LP_Object_Cache::get( 'static-page-ids', 'learn-press' );
2731 1929
@@ -2749,237 +1947,8 @@
2749 1947 return apply_filters( 'learn-press/static-page-ids', $pages );
2750 1948 }
2751 1949
2752 1950 /**
2753 - * Get default static pages of LP.
2754 - *
2755 - * @param bool $name - Optional. TRUE will return name only.
2756 - *
2757 - * @return array
2758 - *
2759 - * @since 3.0.0
2760 - */
2761 -function learn_press_static_pages( $name = false ) {
2762 - $pages = apply_filters(
2763 - 'learn-press/static-pages',
2764 - array(
2765 - 'checkout' => _x( 'Checkout', 'static-page-name', 'learnpress' ),
2766 - 'courses' => _x( 'Courses', 'static-page-name', 'learnpress' ),
2767 - 'profile' => _x( 'Profile', 'static-page-name', 'learnpress' ),
2768 - 'become_a_teacher' => _x( 'Become a Teacher', 'static-page-name', 'learnpress' ),
2769 - )
2770 - );
2771 -
2772 - if ( $name ) {
2773 - return array_keys( $pages );
2774 - }
2775 -
2776 - return $pages;
2777 -}
2778 -
2779 -/*function learn_press_cache_path( $group, $key = '' ) {
2780 - $path = LP_PLUGIN_PATH . 'cache';
2781 - if ( ! file_exists( $path ) ) {
2782 - @mkdir( $path );
2783 - }
2784 - $path = $path . '/' . $group;
2785 -
2786 - if ( ! file_exists( $path ) ) {
2787 - @mkdir( $path );
2788 - }
2789 - if ( $key ) {
2790 - $path = $path . '/' . $key . '.ch';
2791 - }
2792 -
2793 - return $path;
2794 -}*/
2795 -
2796 -function learn_press_cache_get( $key, $group, $found = null ) {
2797 - //$file = learn_press_cache_path( $group, $key );
2798 - $data = wp_cache_get( $key, $group, $found );
2799 -
2800 - /*if ( ! file_exists( $file ) ) {
2801 - return false;
2802 - }*/
2803 -
2804 - /*if ( false === $data ) {
2805 - $content = file_get_contents( $file );
2806 -
2807 - if ( file_exists( $file ) && $content ) {
2808 - try {
2809 - $data = unserialize( $content );
2810 - } catch ( Exception $ex ) {
2811 - print_r( $content );
2812 - die();
2813 - }
2814 - wp_cache_set( $key, $data, $group, $found );
2815 - }
2816 - }*/
2817 -
2818 - return $data;
2819 -}
2820 -
2821 -function learn_press_cache_set( $key, $data, $group = '', $expire = 0 ) {
2822 - //$file = learn_press_cache_path( $group, $key );
2823 - wp_cache_set( $key, $data, $group, $expire );
2824 -
2825 - /*if ( ! is_string( $data ) ) {
2826 - $data = serialize( $data );
2827 - }
2828 - file_put_contents( $file, $data );*/
2829 -}
2830 -
2831 -function learn_press_cache_replace( $key, $data, $group = '', $expire = 0 ) {
2832 - wp_cache_replace( $key, $data, $group, $expire );
2833 -}
2834 -
2835 -function learn_press_cache_add( $key, $data, $group = '', $expire = 0 ) {
2836 - wp_cache_add( $key, $data, $group, $expire );
2837 -}
2838 -
2839 -if ( ! function_exists( 'learn_press_get_widget_course_object' ) ) {
2840 - /**
2841 - * Get course object for widget query.
2842 - *
2843 - * @param $query
2844 - *
2845 - * @return array
2846 - * @deprecated v4.1.6.1 - we will remove on the version 4.1.7
2847 - */
2848 - function learn_press_get_widget_course_object( $query ) {
2849 -
2850 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2851 -
2852 - global $wpdb;
2853 -
2854 - $posts = $wpdb->get_results( $query );
2855 - if ( $posts ) {
2856 - // get lp courses object from WordPress post
2857 - $courses = array_map( 'learn_press_get_lp_course', $posts );
2858 - $courses = array_filter( $courses );
2859 -
2860 - } else {
2861 - $courses = array();
2862 - }
2863 -
2864 - return $courses;
2865 - }
2866 -}
2867 -
2868 -if ( ! function_exists( 'learn_press_get_lp_course' ) ) {
2869 - /**
2870 - * Get learn press course from WordPress post object
2871 - *
2872 - * @param object - reference $post WordPress post object
2873 - *
2874 - * @return LP_Course course
2875 - * @deprecated v4.1.6.1 - we will remove on the version 4.1.7
2876 - */
2877 - function learn_press_get_lp_course( $post ) {
2878 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2879 -
2880 - $id = $post->ID;
2881 - $course = null;
2882 - if ( ! empty( $id ) ) {
2883 - // $course = new LP_Course( $id );
2884 - $course = learn_press_get_course( $id );
2885 - }
2886 -
2887 - return $course;
2888 - }
2889 -}
2890 -
2891 -/**
2892 - * Get all items are unassigned to any course.
2893 - *
2894 - * @param string|array $type - Optional. Types of items to get, default is all.
2895 - *
2896 - * @return array
2897 - * @since 3.0.0
2898 - * @deprecated 4.1.4.1 - Will remove on version 4.1.7
2899 - */
2900 -function learn_press_get_unassigned_items( $type = '' ) {
2901 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2902 -
2903 - global $wpdb;
2904 -
2905 - if ( ! $type ) {
2906 - $type = learn_press_course_get_support_item_types();
2907 - $type = array_keys( $type );
2908 - }
2909 -
2910 - settype( $type, 'array' );
2911 - $key = 'items-' . md5( serialize( $type ) );
2912 -
2913 - if ( false === ( $items = LP_Object_Cache::get( $key, 'learn-press/unassigned' ) ) ) {
2914 - $format = array_fill( 0, sizeof( $type ), '%s' );
2915 -
2916 - $query = $wpdb->prepare(
2917 - "
2918 - SELECT p.ID
2919 - FROM {$wpdb->posts} p
2920 - WHERE p.post_type IN(" . join( ',', $format ) . ")
2921 - AND p.ID NOT IN(
2922 - SELECT si.item_id
2923 - FROM {$wpdb->learnpress_section_items} si
2924 - INNER JOIN {$wpdb->posts} p ON p.ID = si.item_id
2925 - WHERE p.post_type IN(" . join( ',', $format ) . ')
2926 - )
2927 - AND p.post_status NOT IN(%s, %s)
2928 - ',
2929 - array_merge( $type, $type, array( 'auto-draft', 'trash' ) )
2930 - );
2931 -
2932 - $items = $wpdb->get_col( $query );
2933 -
2934 - //LP_Debug::var_dump($query, __FILE__, __LINE__);
2935 -
2936 - LP_Object_Cache::set( $key, $items, 'learn-press/unassigned' );
2937 - }
2938 -
2939 - return $items;
2940 -}
2941 -
2942 -/**
2943 - * Get all questions are unassigned to any quiz.
2944 - *
2945 - * @return array
2946 - * @since 3.0.0
2947 - * @deprecated 4.1.6.1 - Will remove on version 4.1.7
2948 - */
2949 -function learn_press_get_unassigned_questions() {
2950 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2951 -
2952 - global $wpdb;
2953 -
2954 - if ( false === ( $questions = LP_Object_Cache::get( 'questions', 'learn-press/unassigned' ) ) ) {
2955 - $query = $wpdb->prepare(
2956 - "
2957 - SELECT p.ID
2958 - FROM {$wpdb->posts} p
2959 - WHERE p.post_type = %s
2960 - AND p.ID NOT IN(
2961 - SELECT qq.question_id
2962 - FROM {$wpdb->learnpress_quiz_questions} qq
2963 - INNER JOIN {$wpdb->posts} p ON p.ID = qq.question_id
2964 - WHERE p.post_type = %s
2965 - )
2966 - AND p.post_status NOT IN(%s, %s)
2967 - ",
2968 - LP_QUESTION_CPT,
2969 - LP_QUESTION_CPT,
2970 - 'auto-draft',
2971 - 'trash'
2972 - );
2973 -
2974 - $questions = $wpdb->get_col( $query );
2975 - LP_Object_Cache::set( 'questions', $questions, 'learn-press/unassigned' );
2976 - }
2977 -
2978 - return $questions;
2979 -}
2980 -
2981 -/**
2982 1951 * Callback function for sorting to array|object by key|prop priority.
2983 1952 *
2984 1953 * @param array|object $a
2985 1954 * @param array|object $b
@@ -2985,10 +1954,11 @@
2985 1954 * @param array|object $b
2986 1955 *
2987 1956 * @return int
2988 1957 * @since 3.0.0
1958 + * @deprecated 4.4.5
2989 1959 */
2990 -function learn_press_sort_list_by_priority_callback( $a, $b ) {
1960 +/*function learn_press_sort_list_by_priority_callback( $a, $b ) {
2991 1961 $a_priority = null;
2992 1962 $b_priority = null;
2993 1963
2994 1964 if ( is_array( $a ) && array_key_exists( 'priority', $a ) ) {
@@ -3015,75 +1985,35 @@
3015 1985 return 0;
3016 1986 }
3017 1987
3018 1988 return ( $a_priority < $b_priority ) ? - 1 : 1;
3019 -}
1989 +}*/
3020 1990
3021 1991 /**
3022 1992 * Localize date with custom format.
3023 1993 *
3024 - * @param string $timestamp
1994 + * @param int|bool $timestamp
3025 1995 * @param string $format
3026 1996 * @param bool $gmt
3027 1997 *
3028 1998 * @return string
3029 1999 * @since 3.0.0
2000 + * @deprcated 4.2.6 use LP_Datetime format instead
3030 2001 */
3031 -function learn_press_date_i18n( $timestamp = '', $format = '', $gmt = false ) {
2002 +function learn_press_date_i18n( $timestamp = 0, string $format = '', bool $gmt = false ): string {
3032 2003 if ( ! $format ) {
3033 2004 $format = get_option( 'date_format' );
3034 2005 }
3035 2006
3036 - return date_i18n( $format, $timestamp, $gmt );
3037 -}
2007 + $date_str = date_i18n( $format, $timestamp, $gmt );
2008 + if ( ! is_string( $date_str ) ) {
2009 + $date_str = '';
2010 + }
3038 2011
3039 -function learn_press_date() {
3040 -
2012 + return $date_str;
3041 2013 }
3042 2014
3043 2015 /**
3044 - * Remove user items.
3045 - *
3046 - * @param int $item_id
3047 - * @param int $course_id
3048 - * @param int $user_id
3049 - * @param int $keep
3050 - *
3051 - * @since 3.0.8
3052 - * @deprecated 4.1.6.1 - Will remove on version 4.1.7
3053 - */
3054 -function learn_press_remove_user_items_history( $item_id, $course_id, $user_id, $keep = 10 ) {
3055 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
3056 -
3057 - $user = learn_press_get_user( $user_id );
3058 - if ( $rows = $user->get_item_archive( $item_id, $course_id ) ) {
3059 -
3060 - global $wpdb;
3061 -
3062 - $args = array( $user_id, $item_id, $course_id );
3063 - $query = $wpdb->prepare(
3064 - "
3065 - DELETE
3066 - FROM {$wpdb->learnpress_user_items}
3067 - WHERE user_id = %d AND item_id = %d
3068 - AND ref_id = %d
3069 - ",
3070 - $args
3071 - );
3072 -
3073 - if ( $keep ) {
3074 - $user_item_ids = array_keys( $rows );
3075 - $user_item_ids = array_splice( $user_item_ids, 0, $keep );
3076 - $format = array_fill( 0, sizeof( $user_item_ids ), '%d' );
3077 -
3078 - $query .= $wpdb->prepare( ' AND user_item_id NOT IN(' . join( ',', $format ) . ')', $user_item_ids );
3079 - }
3080 -
3081 - $wpdb->query( $query );
3082 - }
3083 -}
3084 -
3085 -/**
3086 2016 * Get item types of course support for blocking. Default is lp_lesson
3087 2017 *
3088 2018 * @return array
3089 2019 * @since 3.0.0
@@ -3126,38 +2056,8 @@
3126 2056 return $post_type;
3127 2057 }
3128 2058
3129 2059 /**
3130 - * Add post type of a post into cache
3131 - *
3132 - * @param int|array $id
3133 - * @param string $type
3134 - *
3135 - * @since 3.1.0
3136 - */
3137 -function learn_press_cache_add_post_type( $id, $type = '' ) {
3138 - if ( false === ( $post_types = LP_Object_Cache::get( 'post-types', 'learn-press' ) ) ) {
3139 - $post_types = array();
3140 - }
3141 -
3142 - if ( func_num_args() == 1 && is_array( $id ) ) {
3143 - $post_types = $post_types + $id;
3144 - } else {
3145 - $post_types[ $id ] = $type;
3146 - }
3147 -
3148 - LP_Object_Cache::set( 'post-types', $post_types, 'learn-press' );
3149 -}
3150 -
3151 -function learn_press_has_option( $name ) {
3152 - global $wpdb;
3153 -
3154 - $query = $wpdb->prepare( "SELECT option_id FROM {$wpdb->options} WHERE option_name = %s", $name );
3155 -
3156 - return $wpdb->get_var( $query ) > 0;
3157 -}
3158 -
3159 -/**
3160 2060 * Update option to enable shuffle themes for ad.
3161 2061 *
3162 2062 * @since 3.2.1
3163 2063 */
@@ -3166,139 +2066,37 @@
3166 2066 }
3167 2067
3168 2068 add_action( 'learn-press/schedule-enable-shuffle-themes', '_learn_press_schedule_enable_shuffle_themes' );
3169 2069
3170 -function learn_press_show_log() {
3171 - if ( trim( LP_Request::get( 'show_log' ) ) === md5( AUTH_KEY ) ) {
3172 - call_user_func_array( 'learn_press_debug', func_get_args() );
3173 - }
3174 -}
3175 -
3176 2070 /**
2071 + * Return localize script data for admin.
2072 + *
3177 2073 * @return array
3178 2074 * @since 3.2.6
2075 + * @version 1.0.1
3179 2076 */
3180 -function learn_press_global_script_params() {
3181 - $js = array(
3182 - 'ajax' => admin_url( 'admin-ajax.php' ),
3183 - 'plugin_url' => LP()->plugin_url(),
3184 - 'siteurl' => home_url(),
3185 - 'current_url' => learn_press_get_current_url(),
3186 - 'theme' => get_stylesheet(),
3187 - 'localize' => array(
2077 +function learn_press_global_script_params(): array {
2078 + $localize = [
2079 + 'ajax' => admin_url( 'admin-ajax.php' ),
2080 + 'plugin_url' => LearnPress::instance()->plugin_url(),
2081 + 'siteurl' => home_url(),
2082 + //'current_url' => learn_press_get_current_url(),
2083 + 'theme' => get_stylesheet(),
2084 + 'localize' => array(
3188 2085 'button_ok' => __( 'OK', 'learnpress' ),
3189 2086 'button_cancel' => __( 'Cancel', 'learnpress' ),
3190 2087 'button_yes' => __( 'Yes', 'learnpress' ),
3191 2088 'button_no' => __( 'No', 'learnpress' ),
3192 2089 ),
3193 - 'root' => esc_url_raw( rest_url() ),
3194 - 'nonce' => wp_create_nonce( 'wp_rest' ),
3195 - );
2090 + 'rest' => esc_url_raw( rest_url() ),
2091 + 'nonce' => wp_create_nonce( 'wp_rest' ),
2092 + 'is_admin' => current_user_can( ADMIN_ROLE ),
2093 + ];
3196 2094
3197 - return $js;
2095 + return apply_filters( 'lp/admin/localize/scripts', $localize );
3198 2096 }
3199 2097
3200 2098 /**
3201 - * Get url for setup cron job on server.
3202 - *
3203 - * @return string
3204 - * @since 3.3.0
3205 - */
3206 -function learn_press_get_cron_url() {
3207 - $nonce = get_option( 'learnpress_cron_url_nonce' );
3208 -
3209 - if ( ! $nonce ) {
3210 - $nonce = md5( microtime( true ) );
3211 - update_option( 'learnpress_cron_url_nonce', $nonce );
3212 - }
3213 - $url = add_query_arg(
3214 - array(
3215 - 'lp-ajax' => 'cron',
3216 - 'sid' => $nonce,
3217 - ),
3218 - get_home_url()
3219 - );
3220 -
3221 - return $url;
3222 -}
3223 -
3224 -/**
3225 - * Get courses expired.
3226 - *
3227 - * @return array
3228 - * @since 3.3.0
3229 - */
3230 -function learn_press_get_expired_courses() {
3231 - global $wpdb;
3232 -
3233 - $query = $wpdb->prepare(
3234 - "
3235 - SELECT X.*
3236 - FROM(
3237 - SELECT ui.*
3238 - FROM {$wpdb->learnpress_user_items} ui
3239 - LEFT JOIN {$wpdb->learnpress_user_items} uix
3240 - ON ui.item_id = uix.item_id
3241 - AND ui.user_id = uix.user_id
3242 - AND ui.user_item_id < uix.user_item_id
3243 - WHERE uix.user_item_id IS NULL
3244 - ) X
3245 - INNER JOIN {$wpdb->users} u ON u.ID = X.user_id
3246 - INNER JOIN {$wpdb->posts} p ON p.ID = X.item_id
3247 - WHERE X.item_type = %s
3248 - AND X.status = %s
3249 - #AND expiration_time_gmt <= UTC_TIMESTAMP()
3250 - AND expiration_time <= UTC_TIMESTAMP()
3251 - LIMIT 0, 10
3252 - ",
3253 - LP_COURSE_CPT,
3254 - 'enrolled'
3255 - );
3256 -
3257 -}
3258 -
3259 -/**
3260 - * Add new error log. Support message as an array|object.
3261 - * Convert message to string if it is not a string.
3262 - *
3263 - * @param mixed $value
3264 - *
3265 - * @since 4.0.0
3266 - */
3267 -function learn_press_error_log( $value ) {
3268 - if ( is_array( $value ) || is_object( $value ) ) {
3269 - ob_start();
3270 - print_r( $value );
3271 - $value = ob_get_clean();
3272 - }
3273 -
3274 - error_log( $value );
3275 -}
3276 -
3277 -/**
3278 - * Get status of global course for current user.
3279 - *
3280 - * @param int $user_id
3281 - * @param int $course_id
3282 - *
3283 - * @return bool|string
3284 - * @since 3.3.0
3285 - * @editor tungnx
3286 - * @modify 4.1.3 - comment - not use
3287 - */
3288 -/*function learn_press_user_course_status( $user_id = 0, $course_id = 0 ) {
3289 - if ( ! $user = learn_press_get_user( $user_id ? $user_id : get_current_user_id() ) ) {
3290 - return false;
3291 - }
3292 -
3293 - if ( ! $userCourse = $user->get_course_data( $course_id ) ) {
3294 - return false;
3295 - }
3296 -
3297 - return $userCourse->get_status();
3298 -}*/
3299 -
3300 -/**
3301 2099 * Return list types of questions that support answer options.
3302 2100 *
3303 2101 * @return array
3304 2102 * @since 3.3.0
@@ -3332,84 +2130,15 @@
3332 2130 return $questions;
3333 2131 }
3334 2132
3335 2133 /**
3336 - * Helper function to output html for rendering a 'circle progress bar'
2134 + * LP Cookie
3337 2135 *
3338 - * @param int $percent
3339 - * @param int $width
3340 - * @param int $border
3341 - * @param string $color
2136 + * @param $name
2137 + * @param $namespace
3342 2138 *
3343 - * @since 3.3.0
2139 + * @return mixed|null
3344 2140 */
3345 -function learn_press_circle_progress_html( $percent = 0, $width = 32, $border = 4, $color = '' ) {
3346 - $radius = $width / 2;
3347 - $r = ( $width - $border ) / 2;
3348 - $circumference = $r * 2 * pi();
3349 - $offset = $circumference - $percent / 100 * $circumference;
3350 -
3351 - printf(
3352 - '<svg class="circle-progress-bar" width="%d" height="%d">
3353 - <circle class="circle-progress-bar__circle"
3354 - stroke="%s"
3355 - stroke-width="%d"
3356 - style="stroke-dasharray:%s %s; stroke-dashoffset:%s;"
3357 - fill="transparent"
3358 - r="%d" cx="%d" cy="%d"></circle>
3359 - </svg>',
3360 - $width,
3361 - $width,
3362 - $color,
3363 - $border,
3364 - $circumference,
3365 - $circumference,
3366 - $offset,
3367 - $r,
3368 - $radius,
3369 - $radius
3370 - );
3371 -}
3372 -
3373 -function learn_press_is_page( $page_name ) {
3374 - $page_id = learn_press_get_page_id( $page_name );
3375 -
3376 - return $page_id && is_page( $page_id );
3377 -}
3378 -
3379 -/**
3380 - * Get end-date from start date with a duration.
3381 - *
3382 - * @param string|int $duration
3383 - * @param string|int $start
3384 - *
3385 - * @return false|string
3386 - * @since 3.x.x
3387 - */
3388 -function learn_press_date_end_from( $duration, $start = '' ) {
3389 - $format = 'Y-m-d H:i:s';
3390 -
3391 - if ( ! $start ) {
3392 - $start = time();
3393 - } elseif ( ! is_numeric( $start ) ) {
3394 - $start = strtotime( $start );
3395 - }
3396 -
3397 - // is LP duration format, e.g: 10 weeks
3398 - if ( preg_match( '/^[0-9]+ [a-z]+$/', $duration ) ) {
3399 - $duration = ( new LP_Duration( $duration ) )->get();
3400 - } elseif ( ! is_numeric( $duration ) ) {
3401 - // 10 days 5 hours ...
3402 - $duration = strtotime( $duration, 0 );
3403 - }
3404 -
3405 - return date( $format, $start + $duration );
3406 -}
3407 -
3408 -function learn_press_date_diff( $from, $to ) {
3409 -
3410 -}
3411 -
3412 2141 function learn_press_cookie_get( $name, $namespace = 'LP' ) {
3413 2142 if ( $namespace ) {
3414 2143 $cookie = ! empty( $_COOKIE[ $namespace ] ) ? (array) json_decode( LP_Helper::sanitize_params_submitted( stripslashes( $_COOKIE[ $namespace ] ), 'html' ) ) : array();
3415 2144 } else {
@@ -3419,28 +2148,8 @@
3419 2148 return $cookie[ $name ] ?? null;
3420 2149 }
3421 2150
3422 2151 /**
3423 - * Get list of levels support in course.
3424 - *
3425 - * @return array
3426 - * @since 3.x.x
3427 - * @editor tungnx
3428 - * @reason comment - not use
3429 - */
3430 -/*
3431 -function learn_press_default_course_levels() {
3432 - $levels = array(
3433 - 'beginner' => __( 'Beginner', 'learnpress' ),
3434 - 'intermediate' => __( 'Intermediate', 'learnpress' ),
3435 - 'expert' => __( 'Expert', 'learnpress' ),
3436 - '' => __( 'All levels', 'learnpress' ),
3437 - );
3438 -
3439 - return apply_filters( 'learn-press/default-course-levels', $levels );
3440 -}*/
3441 -
3442 -/**
3443 2152 * Get default methods to evaluate course results.
3444 2153 *
3445 2154 * @param string $return - Optional. 'keys' will return keys instead of all.
3446 2155 *
@@ -3447,67 +2156,76 @@
3447 2156 * @return array
3448 2157 * @since 3.x.x
3449 2158 */
3450 2159 function learn_press_course_evaluation_methods( $postid, $return = '', $final_quizz_passing = '' ) {
3451 - $course_tip = '<span class="learn-press-tip">%s</span>';
3452 - $final_quiz_btn = '<a href="#" class="lp-metabox-get-final-quiz" data-postid="' . $postid . '" data-loading="' . esc_attr__(
3453 - 'Loading...',
3454 - 'learnpress'
3455 - ) . '">' . esc_html__( 'Get Passing Grade', 'learnpress' ) . '</a>';
2160 + $final_quiz_btn = sprintf(
2161 + '<a href="#" class="lp-metabox-get-final-quiz" data-postid="%d" data-loading="%s">%s</a>',
2162 + $postid,
2163 + esc_attr__( 'Loading...', 'learnpress' ),
2164 + esc_html__( 'Get A Passing Grade', 'learnpress' )
2165 + );
3456 2166
3457 - $course_desc = array(
2167 + $evaluations_desc = array(
3458 2168 'evaluate_lesson' => sprintf(
3459 2169 '<p>%s<br/>%s</p>',
3460 - __( 'Evaluate by the number of lessons completed per total number of lessons.', 'learnpress' ),
3461 - __( 'E.g: Course has 10 lessons and user completed 5 lessons then the result = 5/10 (50.%)', 'learnpress' )
2170 + __( 'Evaluate by the number of completed lessons per the total number of lessons.', 'learnpress' ),
2171 + __( 'E.g: If a course has 10 lessons and a user completes 5 lessons, then the result is 5/10 (50%).', 'learnpress' )
3462 2172 ),
3463 2173 'evaluate_final_quiz' => __(
3464 - 'Evaluate by result of final quiz in the course. You have to add a quiz to the end of the course.',
2174 + 'Evaluate by the result of the final quiz in the course. You have to add a quiz at the end of the course.',
3465 2175 'learnpress'
3466 2176 ),
3467 2177 'evaluate_quiz' => sprintf(
3468 2178 '<p>%s<br/>%s</p>',
3469 - __( 'Evaluate by the number of quizzes passed per total number of quizzes.', 'learnpress' ),
2179 + __( 'Evaluate by the number of passed quizzes per the total number of quizzes.', 'learnpress' ),
3470 2180 __(
3471 - 'E.g: The course has 10 quizzes and the user passed 5 quizzes then the result = 5/10 (50%).',
2181 + 'E.g: If the course has 10 quizzes and the user passes 5 quizzes, then the result is 5/10 (50%).',
3472 2182 'learnpress'
3473 2183 )
3474 2184 ),
3475 2185 'evaluate_questions' => sprintf(
3476 2186 '<p>%s<br/>%s</p>',
3477 - __( 'Evaluate by total number of correct answers per total number of questions.', 'learnpress' ),
2187 + __( 'Evaluate by the number of correct answers per the total number of questions.', 'learnpress' ),
3478 2188 __(
3479 - 'E.g: Course has 10 questions. User correct 5 questions. Result is 5/10 (50%).',
2189 + 'E.g: If the course has 10 questions and the user corrects 5 questions, then the result is 5/10 (50%).',
3480 2190 'learnpress'
3481 2191 )
3482 2192 ),
3483 - 'evaluate_mark' => __( 'Evaluate by total score achieved per total score of the questions.', 'learnpress' ),
2193 + 'evaluate_mark' => __( 'Evaluate by the number of achieved scores per the total score of the questions.', 'learnpress' ),
3484 2194 );
3485 2195
3486 2196 $methods = apply_filters(
3487 2197 'learnpress/course-evaluation/methods',
3488 2198 array(
3489 - 'evaluate_lesson' => __(
3490 - 'Evaluate via lessons',
3491 - 'learnpress'
3492 - ) . learn_press_quick_tip( $course_desc['evaluate_lesson'], false ),
3493 - 'evaluate_final_quiz' => __( 'Evaluate via results of the final quiz', 'learnpress' ) . sprintf(
3494 - $course_tip,
3495 - $course_desc['evaluate_final_quiz']
3496 - ) . $final_quiz_btn . $final_quizz_passing,
3497 - 'evaluate_quiz' => __( 'Evaluate via quizzes passed', 'learnpress' ) . sprintf(
3498 - $course_tip,
3499 - $course_desc['evaluate_quiz']
2199 + 'evaluate_lesson' => sprintf(
2200 + '%s %s',
2201 + __( 'Evaluate via lessons', 'learnpress' ),
2202 + learn_press_quick_tip( $evaluations_desc['evaluate_lesson'], false )
3500 2203 ),
3501 - 'evaluate_questions' => __( 'Evaluate via questions', 'learnpress' ) . sprintf(
3502 - $course_tip,
3503 - $course_desc['evaluate_questions']
2204 + 'evaluate_final_quiz' => sprintf(
2205 + '%s %s %s %s',
2206 + __( 'Evaluate via results of the final quiz', 'learnpress' ),
2207 + learn_press_quick_tip( $evaluations_desc['evaluate_final_quiz'], false ),
2208 + $final_quiz_btn,
2209 + $final_quizz_passing
3504 2210 ),
3505 - 'evaluate_mark' => __( 'Evaluate via mark', 'learnpress' ) . sprintf(
3506 - $course_tip,
3507 - $course_desc['evaluate_mark']
2211 + 'evaluate_quiz' => sprintf(
2212 + '%s %s',
2213 + __( 'Evaluate via passed quizzes', 'learnpress' ),
2214 + learn_press_quick_tip( $evaluations_desc['evaluate_quiz'], false )
3508 2215 ),
3509 - )
2216 + 'evaluate_questions' => sprintf(
2217 + '%s %s',
2218 + __( 'Evaluate via questions', 'learnpress' ),
2219 + learn_press_quick_tip( $evaluations_desc['evaluate_questions'], false )
2220 + ),
2221 + 'evaluate_mark' => sprintf(
2222 + '%s %s',
2223 + __( 'Evaluate via mark', 'learnpress' ),
2224 + learn_press_quick_tip( $evaluations_desc['evaluate_mark'], false )
2225 + ),
2226 + ),
2227 + $postid
3510 2228 );
3511 2229
3512 2230 return apply_filters(
3513 2231 'learn-press/course-evaluation-methods',
@@ -3516,143 +2234,8 @@
3516 2234 );
3517 2235 }
3518 2236
3519 2237 /**
3520 - * Wrap WP Core function current_time with mysql format.
3521 - *
3522 - * @param bool $gmt
3523 - *
3524 - * @return int|string
3525 - * @since 4.0.0
3526 - * @editor tungnx
3527 - * @modify 4.1.4.1 - comment - not use
3528 - */
3529 -/*function learn_press_mysql_time( $gmt = true ) {
3530 - return current_time( 'mysql', $gmt );
3531 -}*/
3532 -
3533 -/**
3534 - * Wrap WP Core function current_time with timestamp format.
3535 - *
3536 - * @param bool $gmt
3537 - *
3538 - * @return int|string
3539 - * @since 4.0.0
3540 - */
3541 -function learn_press_timestamp( $gmt = true ) {
3542 - return current_time( 'timestamp', $gmt );
3543 -}
3544 -
3545 -/**
3546 - * Convert time from GMT to local.
3547 - *
3548 - * @param string|int|LP_Datetime $gmt_time
3549 - * @param string $format
3550 - *
3551 - * @return false|int|string
3552 - * @since 4.0.0
3553 - */
3554 -function learn_press_time_from_gmt( $gmt_time, $format = 'Y-m-d H:i:s' ) {
3555 - if ( is_string( $gmt_time ) ) {
3556 - $gmt_time = strtotime( $gmt_time );
3557 - } elseif ( $gmt_time instanceof LP_Datetime ) {
3558 - $gmt_time = strtotime( $gmt_time . '' );
3559 - }
3560 -
3561 - $current_time = $gmt_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
3562 -
3563 - if ( $format ) {
3564 - return date( $format, $current_time );
3565 - }
3566 -
3567 - return $current_time;
3568 -}
3569 -
3570 -/**
3571 - * Count all users has enrolled courses of an instructor.
3572 - *
3573 - * @param int $instructor_id . Author of course
3574 - *
3575 - SELECT COUNT(DISTINCT (user_id)) AS total
3576 - FROM wp_learnpress_user_items
3577 - WHERE 1 = 1
3578 - AND item_type = 'lp_course'
3579 - AND item_id IN (
3580 - SELECT ID
3581 - FROM wp_posts
3582 - WHERE post_author = 1
3583 - AND post_type = 'lp_course'
3584 - AND post_status = 'publish'
3585 - );
3586 - *
3587 - * @return int
3588 - * @since 4.0.0
3589 - * @editor tungnx
3590 - * @version 1.0.1
3591 - * @deprecated 4.1.6 replace to "get_statistic_info" function
3592 - */
3593 -//function learn_press_count_instructor_users( int $instructor_id = 0 ): int {
3594 -// try {
3595 -// $filter_course = new LP_Course_Filter();
3596 -// $filter_course->only_fields = array( 'ID' );
3597 -// $filter_course->post_author = $instructor_id;
3598 -// $filter_course->post_status = 'publish';
3599 -// $filter_course->return_string_query = true;
3600 -// $query_courses_str = LP_Course_DB::getInstance()->get_courses( $filter_course );
3601 -//
3602 -// $filter = new LP_User_Items_Filter();
3603 -// $filter->only_fields = array( 'DISTINCT (ui.user_id)' );
3604 -// $filter->field_count = 'DISTINCT (ui.user_id)';
3605 -// $filter->where[] = "AND item_id IN ({$query_courses_str})";
3606 -// $filter->query_count = true;
3607 -//
3608 -// return LP_User_Item_Course::get_user_courses( $filter );
3609 -// //return LP_User_Items_DB::getInstance()->get_user_courses( $filter );
3610 -// } catch ( Throwable $e ) {
3611 -// error_log( __FUNCTION__ . ': ' . $e->getMessage() );
3612 -//
3613 -// return 0;
3614 -// }
3615 -//
3616 -// /*$curd = new LP_User_CURD();
3617 -// $own_courses = $curd->query_own_courses( $instructor_id );
3618 -// $course_ids = $own_courses->get_items();*/
3619 -//
3620 -// /*
3621 -// global $wpdb;
3622 -// $filter = new LP_Course_Filter();
3623 -// $filter->post_author = $instructor_id;
3624 -// $filter->limit = -1;
3625 -// $courses = LP_Course::get_courses( $filter );
3626 -// $course_ids = LP_Course::get_course_ids( $courses );
3627 -//
3628 -// if ( ! empty( $course_ids ) ) {
3629 -// $query = $wpdb->prepare(
3630 -// "
3631 -// SELECT COUNT(user_id)
3632 -// FROM (
3633 -// SELECT item_id, user_id
3634 -// FROM {$wpdb->learnpress_user_items}
3635 -// WHERE item_type = %s
3636 -// GROUP BY item_id, user_id
3637 -// HAVING item_id IN(" . join( ',', $course_ids ) . ')
3638 -// ) X
3639 -// GROUP BY item_id
3640 -// ',
3641 -// LP_COURSE_CPT
3642 -// );
3643 -//
3644 -// $rows = $wpdb->get_col( $query );
3645 -//
3646 -// if ( $rows ) {
3647 -// return array_sum( $rows );
3648 -// }
3649 -// }
3650 -//
3651 -// return 0;*/
3652 -//}
3653 -
3654 -/**
3655 2238 * Get max retrying quiz allowed.
3656 2239 *
3657 2240 * @param int $quiz_id
3658 2241 * @param int $course_id
@@ -3664,34 +2247,9 @@
3664 2247 return apply_filters( 'learn-press/max-retry-quiz-allowed', 1, $quiz_id, $course_id );
3665 2248 }
3666 2249
3667 2250 /**
3668 - * Get max retrying course allowed.
3669 - *
3670 - * @param int $course_id
3671 - *
3672 - * @return int
3673 - * @since 4.0.0
3674 - */
3675 -function learn_press_get_course_max_retrying( $course_id ) {
3676 - return apply_filters( 'learn-press/max-retry-course-allowed', 1, $course_id );
3677 -}
3678 -
3679 -/**
3680 2251 * Get slug for status of course/lesson/quiz if user
3681 - * completed/finished and graduation is failed.
3682 - *
3683 - * @param string $type
3684 - *
3685 - * @return string
3686 - * @since 4.0.0
3687 - */
3688 -function learn_press_user_item_failed_slug( $type = '' ) {
3689 - return apply_filters( 'learn-press/user-item-failed-slug', 'failed', $type );
3690 -}
3691 -
3692 -/**
3693 - * Get slug for status of course/lesson/quiz if user
3694 2252 * completed/finished and graduation is passed.
3695 2253 *
3696 2254 * @param string $type
3697 2255 *
@@ -3697,21 +2255,8 @@
3697 2255 *
3698 2256 * @return string
3699 2257 * @since 4.0.0
3700 2258 */
3701 -function learn_press_user_item_passed_slug( $type = '' ) {
3702 - return apply_filters( 'learn-press/user-item-passed-slug', 'passed', $type );
3703 -}
3704 -
3705 -/**
3706 - * Get slug for status of course/lesson/quiz if user
3707 - * completed/finished and graduation is passed.
3708 - *
3709 - * @param string $type
3710 - *
3711 - * @return string
3712 - * @since 4.0.0
3713 - */
3714 2259 function learn_press_user_item_in_progress_slug( $type = '' ) {
3715 2260 return apply_filters( 'learn-press/user-item-in-progress-slug', 'in-progress', $type );
3716 2261 }
3717 2262
@@ -3740,29 +2285,9 @@
3740 2285
3741 2286 /**
3742 2287 * @return array
3743 2288 * @since 4.0.0
3744 - * @editor tungnx
3745 - * @modify 4.1.3 - comment - not use
3746 2289 */
3747 -function learn_press_course_enrolled_slugs(): array {
3748 - _deprecated_function( __FUNCTION__, '4.1.3' );
3749 - return apply_filters(
3750 - 'learn-press/course-enrolled-slugs',
3751 - array(
3752 - learn_press_user_item_passed_slug(),
3753 - learn_press_user_item_failed_slug(),
3754 - 'in-progress',
3755 - 'enrolled',
3756 - 'finished', // deprecated
3757 - )
3758 - );
3759 -}
3760 -
3761 -/**
3762 - * @return array
3763 - * @since 4.0.0
3764 - */
3765 2290 function lp_item_course_class( $class = array() ) {
3766 2291 $classes = array_merge(
3767 2292 $class,
3768 2293 array( 'learn-press-courses' )
@@ -3771,82 +2296,24 @@
3771 2296 }
3772 2297
3773 2298 //require_once dirname( __FILE__ ) . '/lp-custom-hooks.php';
3774 2299
3775 -
3776 -/**
3777 - * Disable auto update
3778 - *
3779 - * @param $update
3780 - * @param $item
3781 - *
3782 - * @return false
3783 - * @author hungkv
3784 - */
3785 -/*function learnpress_disable_auto_update( $update, $item ) {
3786 - $plugins = array( // Plugins to auto-update
3787 - 'learnpress',
3788 - );
3789 - // Auto-update specified plugins
3790 - if ( in_array( $item->slug, $plugins ) ) {
3791 - return false;
3792 - }
3793 -}
3794 -add_filter( 'auto_update_plugin', 'learnpress_disable_auto_update', 10, 2 );*/
3795 -
3796 -add_action(
2300 +// Notify update message for LearnPress plugin
2301 +/*add_action(
3797 2302 'in_plugin_update_message-learnpress/learnpress.php',
3798 2303 function ( $plugin_data ) {
3799 - version_update_warning( LEARNPRESS_VERSION, $plugin_data['new_version'] );
3800 - }
3801 -);
3802 -/**
3803 - * Custom message warning have new version
3804 - *
3805 - * @param $current_version
3806 - * @param $new_version
3807 - * @author hungkv
3808 - */
3809 -function version_update_warning( $current_version, $new_version ) {
3810 - $current_version_minor_part = explode( '.', $current_version )[1];
3811 - $new_version_minor_part = explode( '.', $new_version )[1];
3812 - if ( $current_version_minor_part === $new_version_minor_part ) {
3813 - return;
3814 - }
3815 -
3816 - $info = get_plugin_data( LP_PLUGIN_FILE );
3817 - ?>
3818 - <hr class="lp-update--warning__separator"/>
3819 - <div class="lp-update--warning">
3820 - <div>
3821 - <div class="lp-update-warning__title">
3822 - <?php echo esc_html__( 'Heads up, Please backup before upgrade!', 'learnpress' ); ?>
3823 - </div>
3824 - <div class="lp-update-warning__message">
3825 - <?php echo esc_html__( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you backup your site before upgrading, and make sure you first update in a staging environment', 'learnpress' ); ?>
3826 - <?php echo esc_html__( 'Learners require WordPress version ' . $info['Requires at least'] . ' or higher.', 'learnpress' ); ?>
3827 - </div>
3828 - </div>
3829 - </div>
3830 -
3831 - <?php
3832 -}
3833 -
3834 -// If profile content don't have shortcode profile.
3835 -function lp_add_shortcode_profile() {
3836 - global $post;
3837 -
3838 - if ( learn_press_is_profile() && is_object( $post ) ) {
3839 - if ( ! has_shortcode( $post->post_content, 'learn_press_profile' ) ) {
3840 - $post->post_content .= '<!-- wp:shortcode -->[' . apply_filters( 'learn-press/shortcode/profile/tag', 'learn_press_profile' ) . ']<!-- /wp:shortcode -->';
2304 + if ( version_compare( $plugin_data['new_version'], LEARNPRESS_VERSION, '<=' ) ) {
2305 + return;
3841 2306 }
3842 2307
3843 - wp_update_post( $post );
2308 + echo sprintf(
2309 + '<hr/><h3>%s</h3><div>%s</div>',
2310 + esc_html__( 'Heads up! Please backup before upgrading!', 'learnpress' ),
2311 + esc_html__( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you backup your site before upgrading, and make sure you first update in a staging environment', 'learnpress' )
2312 + );
3844 2313 }
3845 -}
2314 +);*/
3846 2315
3847 -add_action( 'template_redirect', 'lp_add_shortcode_profile' );
3848 -
3849 2316 /**
3850 2317 * If Elementor Pro set Theme builder type "Archive", will not show content on page "Archive course"
3851 2318 *
3852 2319 * @editor tungnx
@@ -3856,9 +2323,9 @@
3856 2323 * @version 1.0.1
3857 2324 */
3858 2325 add_filter(
3859 2326 'elementor/theme/get_location_templates/template_id',
3860 - function( $theme_template_id ) {
2327 + function ( $theme_template_id ) {
3861 2328 $elementor_template_type = get_post_meta( $theme_template_id, '_elementor_template_type', true );
3862 2329
3863 2330 if ( in_array( $elementor_template_type, array( 'archive' ) ) ) {
3864 2331 if ( LP_PAGE_COURSES === LP_Page_Controller::page_current() && class_exists( 'ElementorPro\Modules\ThemeBuilder\Conditions\Archive' ) ) {