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