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 +200 -1592 4.1.7.14.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 }
@@ -460,11 +413,11 @@
460 413 // This isn't needed for get_terms
461 414 unset( $args['orderby'] );
462 415
463 416 // Set args for get_terms
464 - $args['menu_order'] = isset( $args['order'] ) ? $args['order'] : 'ASC';
465 - $args['hide_empty'] = isset( $args['hide_empty'] ) ? $args['hide_empty'] : 0;
466 - $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';
467 420
468 421 // Ensure slugs is valid for get_terms - slugs isn't supported
469 422 $args['fields'] = $args['fields'] === 'slugs' ? 'id=>slug' : $args['fields'];
470 423 $terms = get_terms( $taxonomy, $args );
@@ -556,16 +509,18 @@
556 509 * Get page id from admin settings page
557 510 *
558 511 * @param string $name
559 512 *
513 + * @since 3.0.0
514 + * @version 1.0.2
560 515 * @return int
561 516 */
562 517 function learn_press_get_page_id( string $name ): int {
563 - $page_id = LP_Settings::instance()->get( "{$name}_page_id", false );
518 + $page_id = LP_Settings::get_option( "{$name}_page_id", false );
564 519
565 - if ( function_exists( 'icl_object_id' ) ) {
520 + /*if ( function_exists( 'icl_object_id' ) ) {
566 521 $page_id = icl_object_id( $page_id, 'page', false, defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '' );
567 - }
522 + }*/
568 523
569 524 $page_id = (int) $page_id;
570 525
571 526 return apply_filters( 'learn_press_get_page_id', $page_id, $name );
@@ -668,9 +623,9 @@
668 623
669 624 if ( $links ) {
670 625 ?>
671 626 <div class="<?php echo esc_attr( $args['wrapper_class'] ); ?>">
672 - <?php echo wp_kses_post( $links ); ?>
627 + <?php echo wp_kses_post( $links ); ?>
673 628 </div>
674 629 <?php
675 630 }
676 631
@@ -701,9 +656,9 @@
701 656
702 657 $pages = absint( $total / $limit );
703 658
704 659 if ( $total % $limit != 0 ) {
705 - $pages ++;
660 + ++$pages;
706 661 }
707 662
708 663 return $pages;
709 664 }
@@ -796,78 +751,12 @@
796 751 return $a1;
797 752 }
798 753
799 754 /**
800 - * Send email notification.
801 - *
802 - * @param string $to .
803 - * @param string $action .
804 - * @param array $vars .
805 - *
806 - * @return bool
807 - */
808 -function learn_press_send_mail( $to = '', $action = '', $vars = array() ) {
809 - $email_settings = LP_Settings::instance();
810 -
811 - if ( ! $email_settings->get( $action . '.enable' ) ) {
812 - return "The action {$action} doesnt support";
813 - }
814 -
815 - $user = get_user_by( 'email', $to );
816 -
817 - $vars['log_in'] = apply_filters( 'learn_press_site_url', get_home_url() );
818 -
819 - // Send email.
820 - $email = new LP_Email();
821 - $email->set_action( $action );
822 - $email->parse_email( $vars );
823 - $email->add_recipient( $to );
824 -
825 - return $email->send();
826 -}
827 -
828 -/*
829 - * Send email notification when a course be published
830 - */
831 -function learn_press_publish_course( $new_status, $old_status, $post ) {
832 - if ( $old_status == 'pending' && $new_status == 'publish' && $post->post_type == 'lp_course' ) {
833 - $instructor = get_userdata( $post->post_author );
834 - $mail_to = $instructor->user_email;
835 -
836 - learn_press_send_mail(
837 - $mail_to,
838 - 'published_course',
839 - apply_filters(
840 - 'learn_press_vars_enrolled_course',
841 - array(
842 - 'user_name' => $instructor->display_name,
843 - 'course_name' => $post->post_title,
844 - 'course_link' => get_permalink( $post->ID ),
845 - ),
846 - $post,
847 - $instructor
848 - )
849 - );
850 - }
851 -}
852 -
853 -add_action( 'transition_post_status', 'learn_press_publish_course', 10, 3 );
854 -
855 -/**
856 755 * @param $user_id
857 756 *
858 757 * @return WP_Query
859 - * @depecated 4.1.6.4
860 758 */
861 -function learn_press_get_enrolled_courses( $user_id ) {
862 - return LP()->get_user( $user_id )->get( 'enrolled-courses' );
863 -}
864 -
865 -/**
866 - * @param $user_id
867 - *
868 - * @return WP_Query
869 - */
870 759 function learn_press_get_own_courses( $user_id ) {
871 760 $arr_query = array(
872 761 'post_type' => 'lp_course',
873 762 'author' => $user_id,
@@ -944,365 +833,35 @@
944 833 /**
945 834 * Get the list of currencies with code and name.
946 835 *
947 836 * @return array
948 - * @version 3.0.0
837 + * @version 3.0.1
949 838 *
950 839 * @author ThimPress
951 840 */
952 841 function learn_press_currencies() {
953 - $currencies = array(
954 - 'AFN' => __( 'Afghan afghani', 'learnpress' ),
955 - 'ALL' => __( 'Albanian lek', 'learnpress' ),
956 - 'DZD' => __( 'Algerian dinar', 'learnpress' ),
957 - 'EUR' => __( 'Euro', 'learnpress' ),
958 - 'AOA' => __( 'Angolan kwanza', 'learnpress' ),
959 - 'XCD' => __( 'East Caribbean dollar', 'learnpress' ),
960 - 'ARS' => __( 'Argentine peso', 'learnpress' ),
961 - 'AMD' => __( 'Armenian dram', 'learnpress' ),
962 - 'AWG' => __( 'Aruban florin', 'learnpress' ),
963 - 'AUD' => __( 'Australian dollar', 'learnpress' ),
964 - 'AZN' => __( 'Azerbaijani manat', 'learnpress' ),
965 - 'BSD' => __( 'Bahamian dollar', 'learnpress' ),
966 - 'BHD' => __( 'Bahraini dinar', 'learnpress' ),
967 - 'BDT' => __( 'Bangladeshi taka', 'learnpress' ),
968 - 'BBD' => __( 'Barbadian dollar', 'learnpress' ),
969 - 'BYR' => __( 'Belarusian ruble', 'learnpress' ),
970 - 'BZD' => __( 'Belizean dollar', 'learnpress' ),
971 - 'XOF' => __( 'West African CFA franc', 'learnpress' ),
972 - 'BMD' => __( 'Bermudian dollar', 'learnpress' ),
973 - 'BTN' => __( 'Bhutanese ngultrum', 'learnpress' ),
974 - 'BOB' => __( 'Bolivian boliviano', 'learnpress' ),
975 - 'USD' => __( 'US dollar', 'learnpress' ),
976 - 'BAM' => __( 'Bosnia and Herzegovina convertible mark', 'learnpress' ),
977 - 'BWP' => __( 'Botswana pula', 'learnpress' ),
978 - 'BRL' => __( 'Brazilian real', 'learnpress' ),
979 - 'BND' => __( 'Brunei dollar', 'learnpress' ),
980 - 'BGN' => __( 'Bulgarian lev', 'learnpress' ),
981 - 'MMK' => __( 'Burmese kyat', 'learnpress' ),
982 - 'BIF' => __( 'Burundian franc', 'learnpress' ),
983 - 'KHR' => __( 'Cambodian riel', 'learnpress' ),
984 - 'XAF' => __( 'Central African CFA franc', 'learnpress' ),
985 - 'CAD' => __( 'Canadian dollar', 'learnpress' ),
986 - 'CVE' => __( 'Cape Verdean escudo', 'learnpress' ),
987 - 'KYD' => __( 'Cayman Islands dollar', 'learnpress' ),
988 - 'CLP' => __( 'Chilean peso', 'learnpress' ),
989 - 'CNY' => __( 'Chinese renminbi', 'learnpress' ),
990 - 'COP' => __( 'Colombian peso', 'learnpress' ),
991 - 'KMF' => __( 'Comorian franc', 'learnpress' ),
992 - 'CDF' => __( 'Congolese franc', 'learnpress' ),
993 - 'NZD' => __( 'New Zealand dollar', 'learnpress' ),
994 - 'CRC' => __( 'Costa Rican colón', 'learnpress' ),
995 - 'HRK' => __( 'Croatian kuna', 'learnpress' ),
996 - 'CUC' => __( 'Cuban peso', 'learnpress' ),
997 - 'ANG' => __( 'Netherlands Antilles guilder', 'learnpress' ),
998 - 'CZK' => __( 'Czech koruna', 'learnpress' ),
999 - 'DKK' => __( 'Danish krone', 'learnpress' ),
1000 - 'DJF' => __( 'Djiboutian franc', 'learnpress' ),
1001 - 'DOP' => __( 'Dominican peso', 'learnpress' ),
1002 - 'EGP' => __( 'Egyptian pound', 'learnpress' ),
1003 - 'SVC' => __( 'Salvadoran colón', 'learnpress' ),
1004 - 'ERN' => __( 'Eritrean nakfa', 'learnpress' ),
1005 - 'ETB' => __( 'Ethiopian birr', 'learnpress' ),
1006 - 'FKP' => __( 'Falkland Islands pound', 'learnpress' ),
1007 - 'FJD' => __( 'Fijian dollar', 'learnpress' ),
1008 - 'XPF' => __( 'CFP franc', 'learnpress' ),
1009 - 'GMD' => __( 'Gambian dalasi', 'learnpress' ),
1010 - 'GEL' => __( 'Georgian lari', 'learnpress' ),
1011 - 'GHS' => __( 'Ghanian cedi', 'learnpress' ),
1012 - 'GIP' => __( 'Gibraltar pound', 'learnpress' ),
1013 - 'GTQ' => __( 'Guatemalan quetzal', 'learnpress' ),
1014 - 'GBP' => __( 'British pound', 'learnpress' ),
1015 - 'GNF' => __( 'Guinean franc', 'learnpress' ),
1016 - 'GYD' => __( 'Guyanese dollar', 'learnpress' ),
1017 - 'HTG' => __( 'Haitian gourde', 'learnpress' ),
1018 - 'HNL' => __( 'Honduran lempira', 'learnpress' ),
1019 - 'HKD' => __( 'Hong Kong dollar', 'learnpress' ),
1020 - 'HUF' => __( 'Hungarian forint', 'learnpress' ),
1021 - 'ISK' => __( 'Icelandic króna', 'learnpress' ),
1022 - 'INR' => __( 'Indian rupee', 'learnpress' ),
1023 - 'IDR' => __( 'Indonesian rupiah', 'learnpress' ),
1024 - 'IRR' => __( 'Iranian rial', 'learnpress' ),
1025 - 'IQD' => __( 'Iraqi dinar', 'learnpress' ),
1026 - 'ILS' => __( 'Israeli new sheqel', 'learnpress' ),
1027 - 'JMD' => __( 'Jamaican dollar', 'learnpress' ),
1028 - 'JPY' => __( 'Japanese yen ', 'learnpress' ),
1029 - 'JOD' => __( 'Jordanian dinar', 'learnpress' ),
1030 - 'KZT' => __( 'Kazakhstani tenge', 'learnpress' ),
1031 - 'KES' => __( 'Kenyan shilling', 'learnpress' ),
1032 - 'KPW' => __( 'North Korean won', 'learnpress' ),
1033 - 'KWD' => __( 'Kuwaiti dinar', 'learnpress' ),
1034 - 'KGS' => __( 'Kyrgyzstani som', 'learnpress' ),
1035 - 'KRW' => __( 'South Korean won', 'learnpress' ),
1036 - 'LAK' => __( 'Lao kip', 'learnpress' ),
1037 - 'LVL' => __( 'Latvian lats', 'learnpress' ),
1038 - 'LBP' => __( 'Lebanese pound', 'learnpress' ),
1039 - 'LSL' => __( 'Lesotho loti', 'learnpress' ),
1040 - 'LRD' => __( 'Liberian dollar', 'learnpress' ),
1041 - 'LD' => __( 'Libyan dinar', 'learnpress' ),
1042 - 'CHF' => __( 'Swiss franc', 'learnpress' ),
1043 - 'LTL' => __( 'Lithuanian litas', 'learnpress' ),
1044 - 'MOP' => __( 'Macanese pataca', 'learnpress' ),
1045 - 'MKD' => __( 'Macedonian denar', 'learnpress' ),
1046 - 'MGA' => __( 'Malagasy ariary', 'learnpress' ),
1047 - 'MWK' => __( 'Malawian kwacha', 'learnpress' ),
1048 - 'MYR' => __( 'Malaysian ringgit', 'learnpress' ),
1049 - 'MVR' => __( 'Maldivian rufiyaa', 'learnpress' ),
1050 - 'MRO' => __( 'Mauritanian ouguiya', 'learnpress' ),
1051 - 'MUR' => __( 'Mauritian rupee', 'learnpress' ),
1052 - 'MXN' => __( 'Mexican peso', 'learnpress' ),
1053 - 'MDL' => __( 'Moldovan leu', 'learnpress' ),
1054 - 'MNT' => __( 'Mongolian tugrik', 'learnpress' ),
1055 - 'MAD' => __( 'Moroccan dirham', 'learnpress' ),
1056 - 'MZN' => __( 'Mozambican metical', 'learnpress' ),
1057 - 'NAD' => __( 'Namibian dollar', 'learnpress' ),
1058 - 'NPR' => __( 'Nepalese rupee', 'learnpress' ),
1059 - 'NIO' => __( 'Nicaraguan córdoba', 'learnpress' ),
1060 - 'NGN' => __( 'Nigerian naira', 'learnpress' ),
1061 - 'NOK' => __( 'Norwegian krone', 'learnpress' ),
1062 - 'OMR' => __( 'Omani rial', 'learnpress' ),
1063 - 'PKR' => __( 'Pakistani rupee', 'learnpress' ),
1064 - 'PAB' => __( 'Panamanian balboa', 'learnpress' ),
1065 - 'PGK' => __( 'Papua New Guinea kina', 'learnpress' ),
1066 - 'PYG' => __( 'Paraguayan guarani', 'learnpress' ),
1067 - 'PEN' => __( 'Peruvian nuevo sol', 'learnpress' ),
1068 - 'PHP' => __( 'Philippine peso', 'learnpress' ),
1069 - 'PLN' => __( 'Polish zloty', 'learnpress' ),
1070 - 'QAR' => __( 'Qatari riyal', 'learnpress' ),
1071 - 'RON' => __( 'Romanian leu', 'learnpress' ),
1072 - 'RUB' => __( 'Russian ruble', 'learnpress' ),
1073 - 'RWF' => __( 'Rwandan franc', 'learnpress' ),
1074 - 'WST' => __( 'Samoan tālā', 'learnpress' ),
1075 - 'STD' => __( 'São Tomé and Príncipe dobra', 'learnpress' ),
1076 - 'SAR' => __( 'Saudi riyal', 'learnpress' ),
1077 - 'RSD' => __( 'Serbian dinar', 'learnpress' ),
1078 - 'SCR' => __( 'Seychellois rupee', 'learnpress' ),
1079 - 'SLL' => __( 'Sierra Leonean leone', 'learnpress' ),
1080 - 'SGD' => __( 'Singapore dollar', 'learnpress' ),
1081 - 'SBD' => __( 'Solomon Islands dollar', 'learnpress' ),
1082 - 'SOS' => __( 'Somali shilling', 'learnpress' ),
1083 - 'ZAR' => __( 'South African rand', 'learnpress' ),
1084 - 'LKR' => __( 'Sri Lankan rupee', 'learnpress' ),
1085 - 'SHP' => __( 'St. Helena pound', 'learnpress' ),
1086 - 'SDG' => __( 'Sudanese pound', 'learnpress' ),
1087 - 'SRD' => __( 'Surinamese dollar', 'learnpress' ),
1088 - 'SZL' => __( 'Swazi lilangeni', 'learnpress' ),
1089 - 'SEK' => __( 'Swedish krona', 'learnpress' ),
1090 - 'SYP' => __( 'Syrian pound', 'learnpress' ),
1091 - 'TWD' => __( 'New Taiwan dollar', 'learnpress' ),
1092 - 'TJS' => __( 'Tajikistani somoni', 'learnpress' ),
1093 - 'TZS' => __( 'Tanzanian shilling', 'learnpress' ),
1094 - 'THB' => __( 'Thai baht ', 'learnpress' ),
1095 - 'TOP' => __( 'Tongan pa’anga', 'learnpress' ),
1096 - 'TTD' => __( 'Trinidad and Tobago dollar', 'learnpress' ),
1097 - 'TND' => __( 'Tunisian dinar', 'learnpress' ),
1098 - 'TRY' => __( 'Turkish lira', 'learnpress' ),
1099 - 'TMT' => __( 'Turkmenistani manat', 'learnpress' ),
1100 - 'UGX' => __( 'Ugandan shilling', 'learnpress' ),
1101 - 'UAH' => __( 'Ukrainian hryvnia', 'learnpress' ),
1102 - 'AED' => __( 'United Arab Emirates dirham', 'learnpress' ),
1103 - 'UYU' => __( 'Uruguayan peso', 'learnpress' ),
1104 - 'UZS' => __( 'Uzbekistani som', 'learnpress' ),
1105 - 'VUV' => __( 'Vanuatu vatu', 'learnpress' ),
1106 - 'VEF' => __( 'Venezuelan bolivar', 'learnpress' ),
1107 - 'VND' => __( 'Vietnamese dong', 'learnpress' ),
1108 - 'YER' => __( 'Yemeni rial', 'learnpress' ),
1109 - 'ZMK' => __( 'Zambian kwacha', 'learnpress' ),
1110 - 'ZWL' => __( 'Zimbabwean dollar', 'learnpress' ),
1111 - 'JEP' => __( 'Jersey pound', 'learnpress' ),
1112 - 'LYD' => __( 'Libyan dinar', 'learnpress' ),
1113 - );
1114 -
1115 - asort( $currencies );
1116 -
1117 - return apply_filters( 'learn-press/currencies', $currencies );
842 + return Config::instance()->get( 'currencies', 'settings' );
1118 843 }
1119 844
1120 845 /**
1121 - * Get current setting of currency.
846 + * Return list of common symbols of the currencies on the world.
1122 847 *
1123 - * @return string
848 + * @return array
849 + * @version 3.0.1
1124 850 */
1125 -function learn_press_get_currency() {
1126 - $currency = apply_filters( 'learn_press_currency', LP_Settings::instance()->get( 'currency', 'USD' ) );
1127 -
1128 - return apply_filters( 'learn-press/currency', $currency );
851 +function learn_press_currency_symbols() {
852 + return Config::instance()->get( 'currency-symbols', 'settings' );
1129 853 }
1130 854
1131 855 /**
1132 - * Return list of common symbols of the currencies on the world.
856 + * Get current setting of currency.
1133 857 *
1134 - * @return array
858 + * @return string
1135 859 */
1136 -function learn_press_currency_symbols() {
1137 - $symbols = array(
1138 - 'AED' => '&#x62f;.&#x625;',
1139 - 'AFN' => '&#x60b;',
1140 - 'ALL' => 'L',
1141 - 'AMD' => 'AMD',
1142 - 'ANG' => '&fnof;',
1143 - 'AOA' => 'Kz',
1144 - 'ARS' => '&#36;',
1145 - 'AUD' => '&#36;',
1146 - 'AWG' => 'Afl.',
1147 - 'AZN' => 'AZN',
1148 - 'BAM' => 'KM',
1149 - 'BBD' => '&#36;',
1150 - 'BDT' => '&#2547;&nbsp;',
1151 - 'BGN' => '&#1083;&#1074;.',
1152 - 'BHD' => '.&#x62f;.&#x628;',
1153 - 'BIF' => 'Fr',
1154 - 'BMD' => '&#36;',
1155 - 'BND' => '&#36;',
1156 - 'BOB' => 'Bs.',
1157 - 'BRL' => '&#82;&#36;',
1158 - 'BSD' => '&#36;',
1159 - 'BTC' => '&#3647;',
1160 - 'BTN' => 'Nu.',
1161 - 'BWP' => 'P',
1162 - 'BYR' => 'Br',
1163 - 'BYN' => 'Br',
1164 - 'BZD' => '&#36;',
1165 - 'CAD' => '&#36;',
1166 - 'CDF' => 'Fr',
1167 - 'CHF' => '&#67;&#72;&#70;',
1168 - 'CLP' => '&#36;',
1169 - 'CNY' => '&yen;',
1170 - 'COP' => '&#36;',
1171 - 'CRC' => '&#x20a1;',
1172 - 'CUC' => '&#36;',
1173 - 'CUP' => '&#36;',
1174 - 'CVE' => '&#36;',
1175 - 'CZK' => '&#75;&#269;',
1176 - 'DJF' => 'Fr',
1177 - 'DKK' => 'DKK',
1178 - 'DOP' => 'RD&#36;',
1179 - 'DZD' => '&#x62f;.&#x62c;',
1180 - 'EGP' => 'EGP',
1181 - 'ERN' => 'Nfk',
1182 - 'ETB' => 'Br',
1183 - 'EUR' => '&euro;',
1184 - 'FJD' => '&#36;',
1185 - 'FKP' => '&pound;',
1186 - 'GBP' => '&pound;',
1187 - 'GEL' => '&#x20be;',
1188 - 'GGP' => '&pound;',
1189 - 'GHS' => '&#x20b5;',
1190 - 'GIP' => '&pound;',
1191 - 'GMD' => 'D',
1192 - 'GNF' => 'Fr',
1193 - 'GTQ' => 'Q',
1194 - 'GYD' => '&#36;',
1195 - 'HKD' => '&#36;',
1196 - 'HNL' => 'L',
1197 - 'HRK' => 'kn',
1198 - 'HTG' => 'G',
1199 - 'HUF' => '&#70;&#116;',
1200 - 'IDR' => 'Rp',
1201 - 'ILS' => '&#8362;',
1202 - 'IMP' => '&pound;',
1203 - 'INR' => '&#8377;',
1204 - 'IQD' => '&#x639;.&#x62f;',
1205 - 'IRR' => '&#xfdfc;',
1206 - 'IRT' => '&#x062A;&#x0648;&#x0645;&#x0627;&#x0646;',
1207 - 'ISK' => 'kr.',
1208 - 'JEP' => '&pound;',
1209 - 'JMD' => '&#36;',
1210 - 'JOD' => '&#x62f;.&#x627;',
1211 - 'JPY' => '&yen;',
1212 - 'KES' => 'KSh',
1213 - 'KGS' => '&#x441;&#x43e;&#x43c;',
1214 - 'KHR' => '&#x17db;',
1215 - 'KMF' => 'Fr',
1216 - 'KPW' => '&#x20a9;',
1217 - 'KRW' => '&#8361;',
1218 - 'KWD' => '&#x62f;.&#x643;',
1219 - 'KYD' => '&#36;',
1220 - 'KZT' => '&#8376;',
1221 - 'LAK' => '&#8365;',
1222 - 'LBP' => '&#x644;.&#x644;',
1223 - 'LKR' => '&#xdbb;&#xdd4;',
1224 - 'LRD' => '&#36;',
1225 - 'LSL' => 'L',
1226 - 'LYD' => '&#x644;.&#x62f;',
1227 - 'MAD' => '&#x62f;.&#x645;.',
1228 - 'MDL' => 'MDL',
1229 - 'MGA' => 'Ar',
1230 - 'MKD' => '&#x434;&#x435;&#x43d;',
1231 - 'MMK' => 'Ks',
1232 - 'MNT' => '&#x20ae;',
1233 - 'MOP' => 'P',
1234 - 'MRU' => 'UM',
1235 - 'MUR' => '&#x20a8;',
1236 - 'MVR' => '.&#x783;',
1237 - 'MWK' => 'MK',
1238 - 'MXN' => '&#36;',
1239 - 'MYR' => '&#82;&#77;',
1240 - 'MZN' => 'MT',
1241 - 'NAD' => 'N&#36;',
1242 - 'NGN' => '&#8358;',
1243 - 'NIO' => 'C&#36;',
1244 - 'NOK' => '&#107;&#114;',
1245 - 'NPR' => '&#8360;',
1246 - 'NZD' => '&#36;',
1247 - 'OMR' => '&#x631;.&#x639;.',
1248 - 'PAB' => 'B/.',
1249 - 'PEN' => 'S/',
1250 - 'PGK' => 'K',
1251 - 'PHP' => '&#8369;',
1252 - 'PKR' => '&#8360;',
1253 - 'PLN' => '&#122;&#322;',
1254 - 'PRB' => '&#x440;.',
1255 - 'PYG' => '&#8370;',
1256 - 'QAR' => '&#x631;.&#x642;',
1257 - 'RMB' => '&yen;',
1258 - 'RON' => 'lei',
1259 - 'RSD' => '&#1088;&#1089;&#1076;',
1260 - 'RUB' => '&#8381;',
1261 - 'RWF' => 'Fr',
1262 - 'SAR' => '&#x631;.&#x633;',
1263 - 'SBD' => '&#36;',
1264 - 'SCR' => '&#x20a8;',
1265 - 'SDG' => '&#x62c;.&#x633;.',
1266 - 'SEK' => '&#107;&#114;',
1267 - 'SGD' => '&#36;',
1268 - 'SHP' => '&pound;',
1269 - 'SLL' => 'Le',
1270 - 'SOS' => 'Sh',
1271 - 'SRD' => '&#36;',
1272 - 'SSP' => '&pound;',
1273 - 'STN' => 'Db',
1274 - 'SYP' => '&#x644;.&#x633;',
1275 - 'SZL' => 'L',
1276 - 'THB' => '&#3647;',
1277 - 'TJS' => '&#x405;&#x41c;',
1278 - 'TMT' => 'm',
1279 - 'TND' => '&#x62f;.&#x62a;',
1280 - 'TOP' => 'T&#36;',
1281 - 'TRY' => '&#8378;',
1282 - 'TTD' => '&#36;',
1283 - 'TWD' => '&#78;&#84;&#36;',
1284 - 'TZS' => 'Sh',
1285 - 'UAH' => '&#8372;',
1286 - 'UGX' => 'UGX',
1287 - 'USD' => '&#36;',
1288 - 'UYU' => '&#36;',
1289 - 'UZS' => 'UZS',
1290 - 'VEF' => 'Bs F',
1291 - 'VES' => 'Bs.S',
1292 - 'VND' => '&#8363;',
1293 - 'VUV' => 'Vt',
1294 - 'WST' => 'T',
1295 - 'XAF' => 'CFA',
1296 - 'XCD' => '&#36;',
1297 - 'XOF' => 'CFA',
1298 - 'XPF' => 'Fr',
1299 - 'YER' => '&#xfdfc;',
1300 - 'ZAR' => '&#82;',
1301 - 'ZMW' => 'ZK',
1302 - );
860 +function learn_press_get_currency(): string {
861 + $currency = LP_Settings::instance()->get( 'currency', 'USD' );
1303 862
1304 - return apply_filters( 'learn-press/currency-symbols', $symbols );
863 + return esc_html( apply_filters( 'learn-press/currency', $currency ) );
1305 864 }
1306 865
1307 866 /**
1308 867 * Return currency symbol from the code.
@@ -1315,9 +874,9 @@
1315 874 if ( ! $currency ) {
1316 875 $currency = learn_press_get_currency();
1317 876 }
1318 877 $symbols = learn_press_currency_symbols();
1319 - $currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : '';
878 + $currency_symbol = $symbols[ $currency ] ?? '';
1320 879
1321 880 $currency_symbol = apply_filters( 'learn_press_currency_symbol', $currency_symbol, $currency );
1322 881
1323 882 return apply_filters( 'learn-press/currency-symbol', $currency_symbol, $currency );
@@ -1332,14 +891,19 @@
1332 891 * @editor tungnx
1333 892 * @modify 4.1.4
1334 893 */
1335 894 function learn_press_get_page_link( string $key ): string {
1336 - $page_id = learn_press_get_page_id( $key );
1337 - $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 + }
1338 901
1339 902 if ( $page_id && get_post_status( $page_id ) == 'publish' ) {
1340 903 $permalink = get_permalink( $page_id );
1341 904 $link = apply_filters( 'learn-press/get-page-link', trailingslashit( $permalink ), $page_id, $key );
905 + LP_Cache::cache_load_first( 'set', $key_cache, $link );
1342 906 }
1343 907
1344 908 return $link;
1345 909 }
@@ -1440,38 +1004,8 @@
1440 1004
1441 1005 return $result;
1442 1006 }
1443 1007
1444 -function learn_press_course_lesson_permalink_friendly( $permalink, $lesson_id, $course_id ) {
1445 - if ( '' != get_option( 'permalink_structure' ) ) {
1446 - if ( preg_match( '!\?lesson=([^\?\&]*)!', $permalink, $matches ) ) {
1447 - $permalink = preg_replace(
1448 - '!/?\?lesson=([^\?\&]*)!',
1449 - '/' . basename( get_permalink( $matches[1] ) ),
1450 - untrailingslashit( $permalink )
1451 - );
1452 - }
1453 - }
1454 -
1455 - return $permalink;
1456 -}
1457 -
1458 -function learn_press_course_question_permalink_friendly( $permalink, $lesson_id, $course_id ) {
1459 - if ( '' != get_option( 'permalink_structure' ) ) {
1460 - if ( preg_match( '!\?lesson=([^\?\&]*)!', $permalink, $matches ) ) {
1461 - $permalink = preg_replace(
1462 - '!/?\?lesson=([^\?\&]*)!',
1463 - '/' . basename( get_permalink( $matches[1] ) ),
1464 - untrailingslashit( $permalink )
1465 - );
1466 - }
1467 - }
1468 -
1469 - return $permalink;
1470 -}
1471 -
1472 -add_filter( 'learn_press_course_lesson_permalink', 'learn_press_course_lesson_permalink_friendly', 10, 3 );
1473 -
1474 1008 function learn_press_user_maybe_is_a_teacher( $user = null ) {
1475 1009 if ( ! $user ) {
1476 1010 $user = learn_press_get_current_user();
1477 1011 } elseif ( is_numeric( $user ) ) {
@@ -1476,9 +1010,9 @@
1476 1010 $user = learn_press_get_current_user();
1477 1011 } elseif ( is_numeric( $user ) ) {
1478 1012 $user = learn_press_get_user( $user );
1479 1013 }
1480 - if ( ! $user ) {
1014 + if ( ! $user || $user instanceof LP_User_Guest ) {
1481 1015 return false;
1482 1016 }
1483 1017
1484 1018 $role = $user->has_role( 'administrator' ) ? 'administrator' : false;
@@ -1509,60 +1043,8 @@
1509 1043 }
1510 1044
1511 1045 add_filter( 'gettext_with_context', '_learn_press_translate_user_roles', 10, 4 );
1512 1046
1513 -/**
1514 - * Modifies the statement $where to make the search works correct
1515 - *
1516 - * @param string
1517 - *
1518 - * @return string
1519 - */
1520 -function learn_press_posts_where_statement_search( $where ) {
1521 - // gets the global query var object
1522 - global $wp_query, $wpdb;
1523 -
1524 - /**
1525 - * Need to wrap this block into () in order to make it works correctly when filter by specific post type => maybe a bug :)
1526 - * from => ( wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') OR wp_2_terms.name LIKE '%s%'
1527 - * to => ( ( wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') OR wp_2_terms.name LIKE '%s%' )
1528 - */
1529 - $a = preg_match( '!(' . $wpdb->posts . '.post_status)!', $where );
1530 - $b = preg_match( '!(OR\s+' . $wpdb->terms . '.name LIKE \'%' . $wp_query->get( 's' ) . '%\')!', $where );
1531 -
1532 - if ( $a && $b ) {
1533 - // append ( to the start of the block
1534 - $where = preg_replace( '!(' . $wpdb->posts . '.post_status)!', '( $1', $where, 1 );
1535 -
1536 - // append ) to the end of the block
1537 - $where = preg_replace(
1538 - '!(OR\s+' . $wpdb->terms . '.name LIKE \'%' . $wp_query->get( 's' ) . '%\')!',
1539 - '$1 )',
1540 - $where
1541 - );
1542 - }
1543 - remove_filter( 'posts_where', 'learn_press_posts_where_statement_search', 99 );
1544 -
1545 - return $where;
1546 -}
1547 -
1548 -/**
1549 - * Filter post type for search function
1550 - * Only search lpr_course if see the param ref=course in request
1551 - *
1552 - * @param WP_Query $q
1553 - */
1554 -function learn_press_filter_search( $q ) {
1555 - if ( $q->is_main_query() && $q->is_search() && ( ! empty( $_REQUEST['ref'] ) && sanitize_text_field( $_REQUEST['ref'] ) == 'course' ) ) {
1556 - $q->set( 'post_type', 'lp_course' );
1557 -
1558 - add_filter( 'posts_where', 'learn_press_posts_where_statement_search', 99 );
1559 - remove_filter( 'pre_get_posts', 'learn_press_filter_search', 99 );
1560 - }
1561 -}
1562 -
1563 -add_filter( 'pre_get_posts', 'learn_press_filter_search', 99 );
1564 -
1565 1047 if ( ! function_exists( 'learn_press_send_json' ) ) {
1566 1048 function learn_press_send_json( $data ) {
1567 1049 echo '<-- LP_AJAX_START -->';
1568 1050 echo wp_json_encode( $data );
@@ -1629,9 +1111,10 @@
1629 1111 */
1630 1112 function learn_press_maybe_send_json( $data, $callback = null ) {
1631 1113 if ( learn_press_is_ajax() ) {
1632 1114 is_callable( $callback ) && call_user_func( $callback );
1633 - if ( empty( $data['message'] ) && ( $message = learn_press_get_messages( true ) ) ) {
1115 + $message = learn_press_get_messages( true );
1116 + if ( empty( $data['message'] ) && $message ) {
1634 1117 $data['message'] = $message;
1635 1118 }
1636 1119 learn_press_send_json( $data );
1637 1120 }
@@ -1695,14 +1178,13 @@
1695 1178 function learn_press_is_course_archive() {
1696 1179 global $wp_query;
1697 1180
1698 1181 $queried_object_id = ! empty( $wp_query->queried_object ) ? $wp_query->queried_object : 0;
1699 - $is_courses = defined( 'LEARNPRESS_IS_COURSES' ) && LEARNPRESS_IS_COURSES;
1700 1182 $is_tag = defined( 'LEARNPRESS_IS_TAG' ) && LEARNPRESS_IS_TAG || is_tax( 'course_tag' );
1701 1183 $is_category = defined( 'LEARNPRESS_IS_CATEGORY' ) && LEARNPRESS_IS_CATEGORY || is_tax( 'course_category' );
1702 1184 $page_id = learn_press_get_page_id( 'courses' );
1703 1185
1704 - 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 ) ) );
1705 1187 }
1706 1188 }
1707 1189
1708 1190 if ( ! function_exists( 'learn_press_is_course_tax' ) ) {
@@ -1731,19 +1213,15 @@
1731 1213 }
1732 1214 }
1733 1215
1734 1216 if ( ! function_exists( 'learn_press_is_course' ) ) {
1735 - function learn_press_is_course() {
1736 - /**
1737 - * @var WP_Query $wp_query
1738 - */
1739 - global $wp_query;
1740 -
1741 - if ( $wp_query->get_queried_object() ) {
1217 + function learn_press_is_course(): bool {
1218 + try {
1742 1219 return is_singular( array( LP_COURSE_CPT ) );
1743 - } else {
1744 - return false;
1220 + } catch ( Throwable $e ) {
1745 1221 }
1222 +
1223 + return false;
1746 1224 }
1747 1225 }
1748 1226
1749 1227 if ( ! function_exists( 'learn_press_is_lesson' ) ) {
@@ -1793,8 +1271,19 @@
1793 1271
1794 1272 return apply_filters( 'learn-press/is-checkout', false );
1795 1273 }
1796 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 +
1797 1286 /**
1798 1287 * Return register permalink
1799 1288 *
1800 1289 * @return mixed
@@ -1809,10 +1298,12 @@
1809 1298 * @param string
1810 1299 * @param string
1811 1300 *
1812 1301 * @return mixed
1302 + * @deprecated 4.2.5
1813 1303 */
1814 1304 function learn_press_add_notice( $message, $type = 'updated' ) {
1305 + _deprecated_function( __FUNCTION__, '4.2.5' );
1815 1306 LP_Admin_Notice::instance()->add( $message, $type );
1816 1307 }
1817 1308
1818 1309 /**
@@ -1817,29 +1308,29 @@
1817 1308
1818 1309 /**
1819 1310 * Set user's cookie
1820 1311 *
1821 - * @param $name
1822 - * @param $value
1823 - * @param int $expire
1824 - * @param bool $secure
1312 + * @param string $name
1313 + * @param mixed $value
1314 + * @param int $expire
1315 + * @param bool $httponly
1825 1316 *
1826 1317 * @editor tungnx
1827 - * @version 1.0.2
1318 + * @version 1.0.3
1828 1319 */
1829 -function learn_press_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
1830 - $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
1831 -
1832 - @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 );
1833 1322 }
1834 1323
1835 1324 /**
1836 1325 * Clear cookie
1837 1326 *
1838 - * @param $name
1327 + * @param string $name
1839 1328 */
1840 -function learn_press_remove_cookie( $name ) {
1841 - 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 + }
1842 1333
1843 1334 if ( array_key_exists( $name, $_COOKIE ) ) {
1844 1335 unset( $_COOKIE[ $name ] );
1845 1336 }
@@ -1845,9 +1336,9 @@
1845 1336 }
1846 1337 }
1847 1338
1848 1339 /**
1849 - * Filter the login url so third-party can be customize
1340 + * Filter the login url so third-party can be customized
1850 1341 *
1851 1342 * @param string $redirect
1852 1343 *
1853 1344 * @return mixed
@@ -1878,9 +1369,9 @@
1878 1369 $url = get_permalink();
1879 1370 }
1880 1371
1881 1372 // Map endpoint to options
1882 - $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;
1883 1374
1884 1375 if ( get_option( 'permalink_structure' ) ) {
1885 1376 if ( strstr( $url, '?' ) ) {
1886 1377 $query_string = '?' . parse_url( $url, PHP_URL_QUERY );
@@ -1897,45 +1388,12 @@
1897 1388 return apply_filters( 'learn_press_get_endpoint_url', esc_url_raw( $url ), $name, $value, $url );
1898 1389 }
1899 1390
1900 1391 /**
1901 - * Add all endpoints from settings to the pages.
1392 + * @deprecated 4.2.3
1902 1393 */
1903 -function learn_press_add_endpoints() {
1904 - $settings = LP_Settings::instance();
1905 -
1906 - $endpoints = $settings->get_checkout_endpoints();
1907 - if ( $endpoints ) {
1908 - foreach ( $endpoints as $endpoint => $value ) {
1909 - LP()->query_vars[ $endpoint ] = $value;
1910 - add_rewrite_endpoint( $value, EP_PAGES );
1911 - }
1912 - }
1913 -
1914 - $endpoints = $settings->get_profile_endpoints();
1915 - if ( $endpoints ) {
1916 - foreach ( $endpoints as $endpoint => $value ) {
1917 - LP()->query_vars[ $endpoint ] = $value;
1918 - add_rewrite_endpoint( $value, EP_PAGES );
1919 - }
1920 - }
1921 -
1922 - $endpoints = $settings->get( 'quiz_endpoints' );
1923 - if ( $endpoints ) {
1924 - foreach ( $endpoints as $endpoint => $value ) {
1925 - $endpoint = preg_replace( '!_!', '-', $endpoint );
1926 - LP()->query_vars[ $endpoint ] = $value;
1927 - add_rewrite_endpoint(
1928 - $value, /*EP_ROOT | */
1929 - EP_PAGES
1930 - );
1931 - }
1932 - }
1933 -}
1934 -
1935 -add_action( 'init', 'learn_press_add_endpoints' );
1936 -
1937 1394 function learn_press_is_yes( $value ) {
1395 + _deprecated_function( __FUNCTION__, '4.2.3' );
1938 1396 return ( $value === 1 ) || ( $value === '1' ) || ( $value == 'yes' ) || ( $value == true ) || ( $value == 'on' );
1939 1397 }
1940 1398
1941 1399 /**
@@ -1941,10 +1399,12 @@
1941 1399 /**
1942 1400 * @param mixed $value
1943 1401 *
1944 1402 * @return bool
1403 + * @deprecated 4.2.3
1945 1404 */
1946 1405 function _is_false_value( $value ) {
1406 + _deprecated_function( __FUNCTION__, '4.2.3' );
1947 1407 if ( is_numeric( $value ) ) {
1948 1408 return $value == 0;
1949 1409 } elseif ( is_string( $value ) ) {
1950 1410 return ( empty( $value ) || is_null( $value ) || in_array( $value, array( 'no', 'off', 'false' ) ) );
@@ -1960,9 +1420,9 @@
1960 1420 function learn_press_parse_request() {
1961 1421 global $wp;
1962 1422
1963 1423 // Map query vars to their keys, or get them if endpoints are not supported
1964 - foreach ( LP()->query_vars as $key => $var ) {
1424 + foreach ( LearnPress::instance()->query_vars as $key => $var ) {
1965 1425 if ( isset( $_GET[ $var ] ) ) {
1966 1426 $wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $_GET[ $var ] ?? '' );
1967 1427 } elseif ( isset( $wp->query_vars[ $var ] ) ) {
1968 1428 $wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $wp->query_vars[ $var ] ?? '' );
@@ -1984,53 +1444,18 @@
1984 1444 }
1985 1445 }
1986 1446
1987 1447 /**
1988 - * @param string $handle
1989 - * @param bool $hash
1990 - *
1991 - * @return string
1992 - */
1993 -function learn_press_get_log_file_path( $handle, $hash = false ) {
1994 - if ( $hash ) {
1995 - $hash = '-' . sanitize_file_name( wp_hash( $handle ) );
1996 - }
1997 -
1998 - return trailingslashit( LP_LOG_PATH ) . $handle . $hash . '.log';
1999 -}
2000 -
2001 -/**
2002 1448 * Get the cart object in checkout page
2003 1449 *
2004 1450 * @return LP_Cart
1451 + * @deprecated 4.2.0
2005 1452 */
2006 1453 function learn_press_get_checkout_cart() {
2007 - 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 );
2008 1456 }
2009 1457
2010 -/*function learn_press_front_scripts() {
2011 - if ( is_admin() ) {
2012 - return;
2013 - }
2014 - $js = array(
2015 - 'ajax' => admin_url( 'admin-ajax.php' ),
2016 - 'plugin_url' => LP()->plugin_url(),
2017 - 'siteurl' => home_url(),
2018 - 'current_url' => learn_press_get_current_url(),
2019 - 'localize' => array(
2020 - 'button_ok' => __( 'OK', 'learnpress' ),
2021 - 'button_cancel' => __( 'Cancel', 'learnpress' ),
2022 - 'button_yes' => __( 'Yes', 'learnpress' ),
2023 - 'button_no' => __( 'No', 'learnpress' ),
2024 - ),
2025 - );
2026 - foreach ( $js as $k => $v ) {
2027 - LP_Assets::add_param( $k, $v, array( 'learn-press-single-course', 'learn-press-global' ), 'LP_Settings' );
2028 - }
2029 -}
2030 -
2031 -add_action( 'wp_print_scripts', 'learn_press_front_scripts' );*/
2032 -
2033 1458 function learn_press_user_time( $time, $format = 'timestamp' ) {
2034 1459 if ( is_string( $time ) ) {
2035 1460 $time = @strtotime( $time );
2036 1461 }
@@ -2056,13 +1481,20 @@
2056 1481 *
2057 1482 * @param bool $default
2058 1483 *
2059 1484 * @return mixed|string
1485 + * @deprecated 4.2.2
1486 + * addon commission 4.0.2 still use this function
2060 1487 */
2061 1488 function learn_press_get_current_profile_tab( $default = true ) {
2062 1489 global $wp_query, $wp;
2063 1490 $current = '';
2064 1491
1492 + // Only load on profile page.
1493 + if ( ! LP_Page_Controller::is_page_profile() ) {
1494 + return false;
1495 + }
1496 +
2065 1497 if ( ! empty( $_REQUEST['tab'] ) ) {
2066 1498 $current = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] );
2067 1499 } elseif ( ! empty( $wp_query->query_vars['tab'] ) ) {
2068 1500 $current = $wp_query->query_vars['tab'];
@@ -2083,9 +1515,9 @@
2083 1515
2084 1516 return $current;
2085 1517 }
2086 1518
2087 -add_action( 'init', 'learn_press_get_current_profile_tab' );
1519 +//add_action( 'init', 'learn_press_get_current_profile_tab' );
2088 1520
2089 1521 function learn_press_profile_tab_exists( $tab ) {
2090 1522 $tabs = learn_press_get_user_profile_tabs();
2091 1523
@@ -2095,39 +1527,8 @@
2095 1527
2096 1528 return false;
2097 1529 }
2098 1530
2099 -/**
2100 - * Replace the spacing with the + (plus) char.
2101 - *
2102 - * @param string $string
2103 - *
2104 - * @return string
2105 - */
2106 -function _learn_press_urlencode( $string ) {
2107 - return preg_replace( '/\s/', '+', $string );
2108 -}
2109 -
2110 -/**
2111 - * Point the archive post type link to course page if current
2112 - * post type is course and the page for displaying course is
2113 - * setup.
2114 - *
2115 - * @param string $link
2116 - * @param string $post_type
2117 - *
2118 - * @return string
2119 - */
2120 -function learn_press_post_type_archive_link( $link, $post_type ) {
2121 - if ( $post_type == LP_COURSE_CPT && learn_press_get_page_id( 'courses' ) ) {
2122 - $link = learn_press_get_page_link( 'courses' );
2123 - }
2124 -
2125 - return $link;
2126 -}
2127 -
2128 -add_filter( 'post_type_archive_link', 'learn_press_post_type_archive_link', 10, 2 );
2129 -
2130 1531 function learn_press_single_term_title( $prefix = '', $display = true ) {
2131 1532 $term = get_queried_object();
2132 1533
2133 1534 if ( ! $term ) {
@@ -2227,9 +1628,9 @@
2227 1628 ),
2228 1629 array(
2229 1630 'title' => __( 'Enable cart', 'learnpress' ),
2230 1631 'desc' => __(
2231 - '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.',
2232 1633 'learnpress'
2233 1634 ),
2234 1635 'id' => $class->get_field_name( 'enable_cart' ),
2235 1636 'default' => 'yes',
@@ -2236,9 +1637,9 @@
2236 1637 'type' => 'checkbox',
2237 1638 ),
2238 1639 array(
2239 1640 'title' => __( 'Add to cart redirect', 'learnpress' ),
2240 - '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' ),
2241 1642 'id' => $class->get_field_name( 'redirect_after_add' ),
2242 1643 'default' => 'yes',
2243 1644 'type' => 'checkbox',
2244 1645 ),
@@ -2243,9 +1644,9 @@
2243 1644 'type' => 'checkbox',
2244 1645 ),
2245 1646 array(
2246 1647 'title' => __( 'AJAX add to cart', 'learnpress' ),
2247 - 'desc' => __( 'Using AJAX to add course to cart.', 'learnpress' ),
1648 + 'desc' => __( 'Using AJAX to add the course to the cart.', 'learnpress' ),
2248 1649 'id' => $class->get_field_name( 'ajax_add_to_cart' ),
2249 1650 'default' => 'no',
2250 1651 'type' => 'checkbox',
2251 1652 ),
@@ -2294,9 +1695,9 @@
2294 1695 /**
2295 1696 * @return string
2296 1697 */
2297 1698 function learn_press_checkout_needs_payment() {
2298 - return LP()->cart->needs_payment();
1699 + return LearnPress::instance()->cart->needs_payment();
2299 1700 }
2300 1701
2301 1702 /**
2302 1703 * Return plugin basename
@@ -2374,32 +1775,8 @@
2374 1775 die( __FUNCTION__ );
2375 1776 }
2376 1777 }
2377 1778
2378 -/**
2379 - * Get current time to user for calculate remaining time of quiz.
2380 - *
2381 - * @return int
2382 - */
2383 -function learn_press_get_current_time() {
2384 - $current_time = apply_filters( 'learn_press_get_current_time', 0 );
2385 -
2386 - if ( $current_time > 0 ) {
2387 - return $current_time;
2388 - }
2389 -
2390 - $a = current_time( 'timestamp' );
2391 - $b = time();
2392 - $c = current_time( 'mysql' );
2393 - $d = strtotime( $c );
2394 -
2395 - if ( $d == $a ) {
2396 - return $a;
2397 - } else {
2398 - return $b;
2399 - }
2400 -}
2401 -
2402 1779 function learn_press_get_requested_post_type() {
2403 1780 global $pagenow;
2404 1781 if ( $pagenow == 'post-new.php' && ! empty( $_REQUEST['post_type'] ) ) {
2405 1782 $post_type = LP_Helper::sanitize_params_submitted( $_REQUEST['post_type'] );
@@ -2435,24 +1812,8 @@
2435 1812
2436 1813 return apply_filters( 'learn-press/get-graduation-text', $text, $slug );
2437 1814 }
2438 1815
2439 -/*function learn_press_execute_time( $n = 1 ) {
2440 - static $time;
2441 - if ( empty( $time ) ) {
2442 - $time = microtime( true );
2443 -
2444 - return $time;
2445 - } else {
2446 - $execute_time = microtime( true ) - $time;
2447 -
2448 - echo 'Execute time ' . $n * $execute_time . "\n";
2449 - $time = 0;
2450 -
2451 - return $execute_time;
2452 - }
2453 -}*/
2454 -
2455 1816 if ( ! function_exists( 'learn_press_is_negative_value' ) ) {
2456 1817 function learn_press_is_negative_value( $value ) {
2457 1818 $return = in_array( $value, array( 'no', 'off', 'false', '0' ) ) || ! $value || $value == '' || $value == null;
2458 1819
@@ -2516,15 +1877,8 @@
2516 1877 }
2517 1878
2518 1879 add_filter( 'comment_reply_link', 'learn_press_comment_reply_link', 10, 4 );
2519 1880
2520 -function learn_press_deprecated_function( $function, $version, $replacement = null ) {
2521 - if ( LP_Debug::is_debug() ) {
2522 - _deprecated_function( $function, $version, $replacement );
2523 - }
2524 -}
2525 -
2526 -
2527 1881 /**
2528 1882 * Sanitize content of tooltip
2529 1883 *
2530 1884 * @param string $tooltip
@@ -2562,29 +1916,14 @@
2562 1916 echo '<span class="learn-press-tooltip" data-tooltip="' . esc_attr( $tooltip ) . '"></span>';
2563 1917 }
2564 1918
2565 1919 /**
2566 - * Get timezone offset from wp settings.
2567 - *
2568 - * @return float|int
2569 - * @since 3.0.0
2570 - */
2571 -function learn_press_timezone_offset() {
2572 - if ( $tz = get_option( 'timezone_string' ) ) {
2573 - $timezone = new DateTimeZone( $tz );
2574 -
2575 - return $timezone->getOffset( new DateTime( 'now' ) );
2576 - } else {
2577 - return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS;
2578 - }
2579 -}
2580 -
2581 -/**
2582 1920 * Get default static pages of LP.
2583 1921 *
2584 1922 * @return array
2585 1923 *
2586 1924 * @since 3.0.0
1925 + * @deprecated 4.2.3
2587 1926 */
2588 1927 function learn_press_static_page_ids() {
2589 1928 $pages = LP_Object_Cache::get( 'static-page-ids', 'learn-press' );
2590 1929
@@ -2608,237 +1947,8 @@
2608 1947 return apply_filters( 'learn-press/static-page-ids', $pages );
2609 1948 }
2610 1949
2611 1950 /**
2612 - * Get default static pages of LP.
2613 - *
2614 - * @param bool $name - Optional. TRUE will return name only.
2615 - *
2616 - * @return array
2617 - *
2618 - * @since 3.0.0
2619 - */
2620 -function learn_press_static_pages( $name = false ) {
2621 - $pages = apply_filters(
2622 - 'learn-press/static-pages',
2623 - array(
2624 - 'checkout' => _x( 'Checkout', 'static-page-name', 'learnpress' ),
2625 - 'courses' => _x( 'Courses', 'static-page-name', 'learnpress' ),
2626 - 'profile' => _x( 'Profile', 'static-page-name', 'learnpress' ),
2627 - 'become_a_teacher' => _x( 'Become a Teacher', 'static-page-name', 'learnpress' ),
2628 - )
2629 - );
2630 -
2631 - if ( $name ) {
2632 - return array_keys( $pages );
2633 - }
2634 -
2635 - return $pages;
2636 -}
2637 -
2638 -/*function learn_press_cache_path( $group, $key = '' ) {
2639 - $path = LP_PLUGIN_PATH . 'cache';
2640 - if ( ! file_exists( $path ) ) {
2641 - @mkdir( $path );
2642 - }
2643 - $path = $path . '/' . $group;
2644 -
2645 - if ( ! file_exists( $path ) ) {
2646 - @mkdir( $path );
2647 - }
2648 - if ( $key ) {
2649 - $path = $path . '/' . $key . '.ch';
2650 - }
2651 -
2652 - return $path;
2653 -}*/
2654 -
2655 -function learn_press_cache_get( $key, $group, $found = null ) {
2656 - //$file = learn_press_cache_path( $group, $key );
2657 - $data = wp_cache_get( $key, $group, $found );
2658 -
2659 - /*if ( ! file_exists( $file ) ) {
2660 - return false;
2661 - }*/
2662 -
2663 - /*if ( false === $data ) {
2664 - $content = file_get_contents( $file );
2665 -
2666 - if ( file_exists( $file ) && $content ) {
2667 - try {
2668 - $data = unserialize( $content );
2669 - } catch ( Exception $ex ) {
2670 - print_r( $content );
2671 - die();
2672 - }
2673 - wp_cache_set( $key, $data, $group, $found );
2674 - }
2675 - }*/
2676 -
2677 - return $data;
2678 -}
2679 -
2680 -function learn_press_cache_set( $key, $data, $group = '', $expire = 0 ) {
2681 - //$file = learn_press_cache_path( $group, $key );
2682 - wp_cache_set( $key, $data, $group, $expire );
2683 -
2684 - /*if ( ! is_string( $data ) ) {
2685 - $data = serialize( $data );
2686 - }
2687 - file_put_contents( $file, $data );*/
2688 -}
2689 -
2690 -function learn_press_cache_replace( $key, $data, $group = '', $expire = 0 ) {
2691 - wp_cache_replace( $key, $data, $group, $expire );
2692 -}
2693 -
2694 -function learn_press_cache_add( $key, $data, $group = '', $expire = 0 ) {
2695 - wp_cache_add( $key, $data, $group, $expire );
2696 -}
2697 -
2698 -if ( ! function_exists( 'learn_press_get_widget_course_object' ) ) {
2699 - /**
2700 - * Get course object for widget query.
2701 - *
2702 - * @param $query
2703 - *
2704 - * @return array
2705 - * @deprecated v4.1.6.1 - we will remove on the version 4.1.7
2706 - */
2707 - function learn_press_get_widget_course_object( $query ) {
2708 -
2709 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2710 -
2711 - global $wpdb;
2712 -
2713 - $posts = $wpdb->get_results( $query );
2714 - if ( $posts ) {
2715 - // get lp courses object from WordPress post
2716 - $courses = array_map( 'learn_press_get_lp_course', $posts );
2717 - $courses = array_filter( $courses );
2718 -
2719 - } else {
2720 - $courses = array();
2721 - }
2722 -
2723 - return $courses;
2724 - }
2725 -}
2726 -
2727 -if ( ! function_exists( 'learn_press_get_lp_course' ) ) {
2728 - /**
2729 - * Get learn press course from WordPress post object
2730 - *
2731 - * @param object - reference $post WordPress post object
2732 - *
2733 - * @return LP_Course course
2734 - * @deprecated v4.1.6.1 - we will remove on the version 4.1.7
2735 - */
2736 - function learn_press_get_lp_course( $post ) {
2737 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2738 -
2739 - $id = $post->ID;
2740 - $course = null;
2741 - if ( ! empty( $id ) ) {
2742 - // $course = new LP_Course( $id );
2743 - $course = learn_press_get_course( $id );
2744 - }
2745 -
2746 - return $course;
2747 - }
2748 -}
2749 -
2750 -/**
2751 - * Get all items are unassigned to any course.
2752 - *
2753 - * @param string|array $type - Optional. Types of items to get, default is all.
2754 - *
2755 - * @return array
2756 - * @since 3.0.0
2757 - * @deprecated 4.1.4.1 - Will remove on version 4.1.7
2758 - */
2759 -function learn_press_get_unassigned_items( $type = '' ) {
2760 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2761 -
2762 - global $wpdb;
2763 -
2764 - if ( ! $type ) {
2765 - $type = learn_press_course_get_support_item_types();
2766 - $type = array_keys( $type );
2767 - }
2768 -
2769 - settype( $type, 'array' );
2770 - $key = 'items-' . md5( serialize( $type ) );
2771 -
2772 - if ( false === ( $items = LP_Object_Cache::get( $key, 'learn-press/unassigned' ) ) ) {
2773 - $format = array_fill( 0, sizeof( $type ), '%s' );
2774 -
2775 - $query = $wpdb->prepare(
2776 - "
2777 - SELECT p.ID
2778 - FROM {$wpdb->posts} p
2779 - WHERE p.post_type IN(" . join( ',', $format ) . ")
2780 - AND p.ID NOT IN(
2781 - SELECT si.item_id
2782 - FROM {$wpdb->learnpress_section_items} si
2783 - INNER JOIN {$wpdb->posts} p ON p.ID = si.item_id
2784 - WHERE p.post_type IN(" . join( ',', $format ) . ')
2785 - )
2786 - AND p.post_status NOT IN(%s, %s)
2787 - ',
2788 - array_merge( $type, $type, array( 'auto-draft', 'trash' ) )
2789 - );
2790 -
2791 - $items = $wpdb->get_col( $query );
2792 -
2793 - //LP_Debug::var_dump($query, __FILE__, __LINE__);
2794 -
2795 - LP_Object_Cache::set( $key, $items, 'learn-press/unassigned' );
2796 - }
2797 -
2798 - return $items;
2799 -}
2800 -
2801 -/**
2802 - * Get all questions are unassigned to any quiz.
2803 - *
2804 - * @return array
2805 - * @since 3.0.0
2806 - * @deprecated 4.1.6.1 - Will remove on version 4.1.7
2807 - */
2808 -function learn_press_get_unassigned_questions() {
2809 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2810 -
2811 - global $wpdb;
2812 -
2813 - if ( false === ( $questions = LP_Object_Cache::get( 'questions', 'learn-press/unassigned' ) ) ) {
2814 - $query = $wpdb->prepare(
2815 - "
2816 - SELECT p.ID
2817 - FROM {$wpdb->posts} p
2818 - WHERE p.post_type = %s
2819 - AND p.ID NOT IN(
2820 - SELECT qq.question_id
2821 - FROM {$wpdb->learnpress_quiz_questions} qq
2822 - INNER JOIN {$wpdb->posts} p ON p.ID = qq.question_id
2823 - WHERE p.post_type = %s
2824 - )
2825 - AND p.post_status NOT IN(%s, %s)
2826 - ",
2827 - LP_QUESTION_CPT,
2828 - LP_QUESTION_CPT,
2829 - 'auto-draft',
2830 - 'trash'
2831 - );
2832 -
2833 - $questions = $wpdb->get_col( $query );
2834 - LP_Object_Cache::set( 'questions', $questions, 'learn-press/unassigned' );
2835 - }
2836 -
2837 - return $questions;
2838 -}
2839 -
2840 -/**
2841 1951 * Callback function for sorting to array|object by key|prop priority.
2842 1952 *
2843 1953 * @param array|object $a
2844 1954 * @param array|object $b
@@ -2844,10 +1954,11 @@
2844 1954 * @param array|object $b
2845 1955 *
2846 1956 * @return int
2847 1957 * @since 3.0.0
1958 + * @deprecated 4.4.5
2848 1959 */
2849 -function learn_press_sort_list_by_priority_callback( $a, $b ) {
1960 +/*function learn_press_sort_list_by_priority_callback( $a, $b ) {
2850 1961 $a_priority = null;
2851 1962 $b_priority = null;
2852 1963
2853 1964 if ( is_array( $a ) && array_key_exists( 'priority', $a ) ) {
@@ -2874,75 +1985,35 @@
2874 1985 return 0;
2875 1986 }
2876 1987
2877 1988 return ( $a_priority < $b_priority ) ? - 1 : 1;
2878 -}
1989 +}*/
2879 1990
2880 1991 /**
2881 1992 * Localize date with custom format.
2882 1993 *
2883 - * @param string $timestamp
1994 + * @param int|bool $timestamp
2884 1995 * @param string $format
2885 1996 * @param bool $gmt
2886 1997 *
2887 1998 * @return string
2888 1999 * @since 3.0.0
2000 + * @deprcated 4.2.6 use LP_Datetime format instead
2889 2001 */
2890 -function learn_press_date_i18n( $timestamp = '', $format = '', $gmt = false ) {
2002 +function learn_press_date_i18n( $timestamp = 0, string $format = '', bool $gmt = false ): string {
2891 2003 if ( ! $format ) {
2892 2004 $format = get_option( 'date_format' );
2893 2005 }
2894 2006
2895 - return date_i18n( $format, $timestamp, $gmt );
2896 -}
2007 + $date_str = date_i18n( $format, $timestamp, $gmt );
2008 + if ( ! is_string( $date_str ) ) {
2009 + $date_str = '';
2010 + }
2897 2011
2898 -function learn_press_date() {
2899 -
2012 + return $date_str;
2900 2013 }
2901 2014
2902 2015 /**
2903 - * Remove user items.
2904 - *
2905 - * @param int $item_id
2906 - * @param int $course_id
2907 - * @param int $user_id
2908 - * @param int $keep
2909 - *
2910 - * @since 3.0.8
2911 - * @deprecated 4.1.6.1 - Will remove on version 4.1.7
2912 - */
2913 -function learn_press_remove_user_items_history( $item_id, $course_id, $user_id, $keep = 10 ) {
2914 - _deprecated_function( __FUNCTION__, '4.1.6.1' );
2915 -
2916 - $user = learn_press_get_user( $user_id );
2917 - if ( $rows = $user->get_item_archive( $item_id, $course_id ) ) {
2918 -
2919 - global $wpdb;
2920 -
2921 - $args = array( $user_id, $item_id, $course_id );
2922 - $query = $wpdb->prepare(
2923 - "
2924 - DELETE
2925 - FROM {$wpdb->learnpress_user_items}
2926 - WHERE user_id = %d AND item_id = %d
2927 - AND ref_id = %d
2928 - ",
2929 - $args
2930 - );
2931 -
2932 - if ( $keep ) {
2933 - $user_item_ids = array_keys( $rows );
2934 - $user_item_ids = array_splice( $user_item_ids, 0, $keep );
2935 - $format = array_fill( 0, sizeof( $user_item_ids ), '%d' );
2936 -
2937 - $query .= $wpdb->prepare( ' AND user_item_id NOT IN(' . join( ',', $format ) . ')', $user_item_ids );
2938 - }
2939 -
2940 - $wpdb->query( $query );
2941 - }
2942 -}
2943 -
2944 -/**
2945 2016 * Get item types of course support for blocking. Default is lp_lesson
2946 2017 *
2947 2018 * @return array
2948 2019 * @since 3.0.0
@@ -2985,38 +2056,8 @@
2985 2056 return $post_type;
2986 2057 }
2987 2058
2988 2059 /**
2989 - * Add post type of a post into cache
2990 - *
2991 - * @param int|array $id
2992 - * @param string $type
2993 - *
2994 - * @since 3.1.0
2995 - */
2996 -function learn_press_cache_add_post_type( $id, $type = '' ) {
2997 - if ( false === ( $post_types = LP_Object_Cache::get( 'post-types', 'learn-press' ) ) ) {
2998 - $post_types = array();
2999 - }
3000 -
3001 - if ( func_num_args() == 1 && is_array( $id ) ) {
3002 - $post_types = $post_types + $id;
3003 - } else {
3004 - $post_types[ $id ] = $type;
3005 - }
3006 -
3007 - LP_Object_Cache::set( 'post-types', $post_types, 'learn-press' );
3008 -}
3009 -
3010 -function learn_press_has_option( $name ) {
3011 - global $wpdb;
3012 -
3013 - $query = $wpdb->prepare( "SELECT option_id FROM {$wpdb->options} WHERE option_name = %s", $name );
3014 -
3015 - return $wpdb->get_var( $query ) > 0;
3016 -}
3017 -
3018 -/**
3019 2060 * Update option to enable shuffle themes for ad.
3020 2061 *
3021 2062 * @since 3.2.1
3022 2063 */
@@ -3025,139 +2066,37 @@
3025 2066 }
3026 2067
3027 2068 add_action( 'learn-press/schedule-enable-shuffle-themes', '_learn_press_schedule_enable_shuffle_themes' );
3028 2069
3029 -function learn_press_show_log() {
3030 - if ( trim( LP_Request::get( 'show_log' ) ) === md5( AUTH_KEY ) ) {
3031 - call_user_func_array( 'learn_press_debug', func_get_args() );
3032 - }
3033 -}
3034 -
3035 2070 /**
2071 + * Return localize script data for admin.
2072 + *
3036 2073 * @return array
3037 2074 * @since 3.2.6
2075 + * @version 1.0.1
3038 2076 */
3039 -function learn_press_global_script_params() {
3040 - $js = array(
3041 - 'ajax' => admin_url( 'admin-ajax.php' ),
3042 - 'plugin_url' => LP()->plugin_url(),
3043 - 'siteurl' => home_url(),
3044 - 'current_url' => learn_press_get_current_url(),
3045 - 'theme' => get_stylesheet(),
3046 - '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(
3047 2085 'button_ok' => __( 'OK', 'learnpress' ),
3048 2086 'button_cancel' => __( 'Cancel', 'learnpress' ),
3049 2087 'button_yes' => __( 'Yes', 'learnpress' ),
3050 2088 'button_no' => __( 'No', 'learnpress' ),
3051 2089 ),
3052 - 'root' => esc_url_raw( rest_url() ),
3053 - 'nonce' => wp_create_nonce( 'wp_rest' ),
3054 - );
2090 + 'rest' => esc_url_raw( rest_url() ),
2091 + 'nonce' => wp_create_nonce( 'wp_rest' ),
2092 + 'is_admin' => current_user_can( ADMIN_ROLE ),
2093 + ];
3055 2094
3056 - return $js;
2095 + return apply_filters( 'lp/admin/localize/scripts', $localize );
3057 2096 }
3058 2097
3059 2098 /**
3060 - * Get url for setup cron job on server.
3061 - *
3062 - * @return string
3063 - * @since 3.3.0
3064 - */
3065 -function learn_press_get_cron_url() {
3066 - $nonce = get_option( 'learnpress_cron_url_nonce' );
3067 -
3068 - if ( ! $nonce ) {
3069 - $nonce = md5( microtime( true ) );
3070 - update_option( 'learnpress_cron_url_nonce', $nonce );
3071 - }
3072 - $url = add_query_arg(
3073 - array(
3074 - 'lp-ajax' => 'cron',
3075 - 'sid' => $nonce,
3076 - ),
3077 - get_home_url()
3078 - );
3079 -
3080 - return $url;
3081 -}
3082 -
3083 -/**
3084 - * Get courses expired.
3085 - *
3086 - * @return array
3087 - * @since 3.3.0
3088 - */
3089 -function learn_press_get_expired_courses() {
3090 - global $wpdb;
3091 -
3092 - $query = $wpdb->prepare(
3093 - "
3094 - SELECT X.*
3095 - FROM(
3096 - SELECT ui.*
3097 - FROM {$wpdb->learnpress_user_items} ui
3098 - LEFT JOIN {$wpdb->learnpress_user_items} uix
3099 - ON ui.item_id = uix.item_id
3100 - AND ui.user_id = uix.user_id
3101 - AND ui.user_item_id < uix.user_item_id
3102 - WHERE uix.user_item_id IS NULL
3103 - ) X
3104 - INNER JOIN {$wpdb->users} u ON u.ID = X.user_id
3105 - INNER JOIN {$wpdb->posts} p ON p.ID = X.item_id
3106 - WHERE X.item_type = %s
3107 - AND X.status = %s
3108 - #AND expiration_time_gmt <= UTC_TIMESTAMP()
3109 - AND expiration_time <= UTC_TIMESTAMP()
3110 - LIMIT 0, 10
3111 - ",
3112 - LP_COURSE_CPT,
3113 - 'enrolled'
3114 - );
3115 -
3116 -}
3117 -
3118 -/**
3119 - * Add new error log. Support message as an array|object.
3120 - * Convert message to string if it is not a string.
3121 - *
3122 - * @param mixed $value
3123 - *
3124 - * @since 4.0.0
3125 - */
3126 -function learn_press_error_log( $value ) {
3127 - if ( is_array( $value ) || is_object( $value ) ) {
3128 - ob_start();
3129 - print_r( $value );
3130 - $value = ob_get_clean();
3131 - }
3132 -
3133 - error_log( $value );
3134 -}
3135 -
3136 -/**
3137 - * Get status of global course for current user.
3138 - *
3139 - * @param int $user_id
3140 - * @param int $course_id
3141 - *
3142 - * @return bool|string
3143 - * @since 3.3.0
3144 - * @editor tungnx
3145 - * @modify 4.1.3 - comment - not use
3146 - */
3147 -/*function learn_press_user_course_status( $user_id = 0, $course_id = 0 ) {
3148 - if ( ! $user = learn_press_get_user( $user_id ? $user_id : get_current_user_id() ) ) {
3149 - return false;
3150 - }
3151 -
3152 - if ( ! $userCourse = $user->get_course_data( $course_id ) ) {
3153 - return false;
3154 - }
3155 -
3156 - return $userCourse->get_status();
3157 -}*/
3158 -
3159 -/**
3160 2099 * Return list types of questions that support answer options.
3161 2100 *
3162 2101 * @return array
3163 2102 * @since 3.3.0
@@ -3191,84 +2130,15 @@
3191 2130 return $questions;
3192 2131 }
3193 2132
3194 2133 /**
3195 - * Helper function to output html for rendering a 'circle progress bar'
2134 + * LP Cookie
3196 2135 *
3197 - * @param int $percent
3198 - * @param int $width
3199 - * @param int $border
3200 - * @param string $color
2136 + * @param $name
2137 + * @param $namespace
3201 2138 *
3202 - * @since 3.3.0
2139 + * @return mixed|null
3203 2140 */
3204 -function learn_press_circle_progress_html( $percent = 0, $width = 32, $border = 4, $color = '' ) {
3205 - $radius = $width / 2;
3206 - $r = ( $width - $border ) / 2;
3207 - $circumference = $r * 2 * pi();
3208 - $offset = $circumference - $percent / 100 * $circumference;
3209 -
3210 - printf(
3211 - '<svg class="circle-progress-bar" width="%d" height="%d">
3212 - <circle class="circle-progress-bar__circle"
3213 - stroke="%s"
3214 - stroke-width="%d"
3215 - style="stroke-dasharray:%s %s; stroke-dashoffset:%s;"
3216 - fill="transparent"
3217 - r="%d" cx="%d" cy="%d"></circle>
3218 - </svg>',
3219 - $width,
3220 - $width,
3221 - $color,
3222 - $border,
3223 - $circumference,
3224 - $circumference,
3225 - $offset,
3226 - $r,
3227 - $radius,
3228 - $radius
3229 - );
3230 -}
3231 -
3232 -function learn_press_is_page( $page_name ) {
3233 - $page_id = learn_press_get_page_id( $page_name );
3234 -
3235 - return $page_id && is_page( $page_id );
3236 -}
3237 -
3238 -/**
3239 - * Get end-date from start date with a duration.
3240 - *
3241 - * @param string|int $duration
3242 - * @param string|int $start
3243 - *
3244 - * @return false|string
3245 - * @since 3.x.x
3246 - */
3247 -function learn_press_date_end_from( $duration, $start = '' ) {
3248 - $format = 'Y-m-d H:i:s';
3249 -
3250 - if ( ! $start ) {
3251 - $start = time();
3252 - } elseif ( ! is_numeric( $start ) ) {
3253 - $start = strtotime( $start );
3254 - }
3255 -
3256 - // is LP duration format, e.g: 10 weeks
3257 - if ( preg_match( '/^[0-9]+ [a-z]+$/', $duration ) ) {
3258 - $duration = ( new LP_Duration( $duration ) )->get();
3259 - } elseif ( ! is_numeric( $duration ) ) {
3260 - // 10 days 5 hours ...
3261 - $duration = strtotime( $duration, 0 );
3262 - }
3263 -
3264 - return date( $format, $start + $duration );
3265 -}
3266 -
3267 -function learn_press_date_diff( $from, $to ) {
3268 -
3269 -}
3270 -
3271 2141 function learn_press_cookie_get( $name, $namespace = 'LP' ) {
3272 2142 if ( $namespace ) {
3273 2143 $cookie = ! empty( $_COOKIE[ $namespace ] ) ? (array) json_decode( LP_Helper::sanitize_params_submitted( stripslashes( $_COOKIE[ $namespace ] ), 'html' ) ) : array();
3274 2144 } else {
@@ -3278,28 +2148,8 @@
3278 2148 return $cookie[ $name ] ?? null;
3279 2149 }
3280 2150
3281 2151 /**
3282 - * Get list of levels support in course.
3283 - *
3284 - * @return array
3285 - * @since 3.x.x
3286 - * @editor tungnx
3287 - * @reason comment - not use
3288 - */
3289 -/*
3290 -function learn_press_default_course_levels() {
3291 - $levels = array(
3292 - 'beginner' => __( 'Beginner', 'learnpress' ),
3293 - 'intermediate' => __( 'Intermediate', 'learnpress' ),
3294 - 'expert' => __( 'Expert', 'learnpress' ),
3295 - '' => __( 'All levels', 'learnpress' ),
3296 - );
3297 -
3298 - return apply_filters( 'learn-press/default-course-levels', $levels );
3299 -}*/
3300 -
3301 -/**
3302 2152 * Get default methods to evaluate course results.
3303 2153 *
3304 2154 * @param string $return - Optional. 'keys' will return keys instead of all.
3305 2155 *
@@ -3306,67 +2156,76 @@
3306 2156 * @return array
3307 2157 * @since 3.x.x
3308 2158 */
3309 2159 function learn_press_course_evaluation_methods( $postid, $return = '', $final_quizz_passing = '' ) {
3310 - $course_tip = '<span class="learn-press-tip">%s</span>';
3311 - $final_quiz_btn = '<a href="#" class="lp-metabox-get-final-quiz" data-postid="' . $postid . '" data-loading="' . esc_attr__(
3312 - 'Loading...',
3313 - 'learnpress'
3314 - ) . '">' . 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 + );
3315 2166
3316 - $course_desc = array(
2167 + $evaluations_desc = array(
3317 2168 'evaluate_lesson' => sprintf(
3318 2169 '<p>%s<br/>%s</p>',
3319 - __( 'Evaluate by the number of lessons completed per total number of lessons.', 'learnpress' ),
3320 - __( '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' )
3321 2172 ),
3322 2173 'evaluate_final_quiz' => __(
3323 - '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.',
3324 2175 'learnpress'
3325 2176 ),
3326 2177 'evaluate_quiz' => sprintf(
3327 2178 '<p>%s<br/>%s</p>',
3328 - __( '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' ),
3329 2180 __(
3330 - '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%).',
3331 2182 'learnpress'
3332 2183 )
3333 2184 ),
3334 2185 'evaluate_questions' => sprintf(
3335 2186 '<p>%s<br/>%s</p>',
3336 - __( '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' ),
3337 2188 __(
3338 - '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%).',
3339 2190 'learnpress'
3340 2191 )
3341 2192 ),
3342 - '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' ),
3343 2194 );
3344 2195
3345 2196 $methods = apply_filters(
3346 2197 'learnpress/course-evaluation/methods',
3347 2198 array(
3348 - 'evaluate_lesson' => __(
3349 - 'Evaluate via lessons',
3350 - 'learnpress'
3351 - ) . learn_press_quick_tip( $course_desc['evaluate_lesson'], false ),
3352 - 'evaluate_final_quiz' => __( 'Evaluate via results of the final quiz', 'learnpress' ) . sprintf(
3353 - $course_tip,
3354 - $course_desc['evaluate_final_quiz']
3355 - ) . $final_quiz_btn . $final_quizz_passing,
3356 - 'evaluate_quiz' => __( 'Evaluate via quizzes passed', 'learnpress' ) . sprintf(
3357 - $course_tip,
3358 - $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 )
3359 2203 ),
3360 - 'evaluate_questions' => __( 'Evaluate via questions', 'learnpress' ) . sprintf(
3361 - $course_tip,
3362 - $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
3363 2210 ),
3364 - 'evaluate_mark' => __( 'Evaluate via mark', 'learnpress' ) . sprintf(
3365 - $course_tip,
3366 - $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 )
3367 2215 ),
3368 - )
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
3369 2228 );
3370 2229
3371 2230 return apply_filters(
3372 2231 'learn-press/course-evaluation-methods',
@@ -3375,143 +2234,8 @@
3375 2234 );
3376 2235 }
3377 2236
3378 2237 /**
3379 - * Wrap WP Core function current_time with mysql format.
3380 - *
3381 - * @param bool $gmt
3382 - *
3383 - * @return int|string
3384 - * @since 4.0.0
3385 - * @editor tungnx
3386 - * @modify 4.1.4.1 - comment - not use
3387 - */
3388 -/*function learn_press_mysql_time( $gmt = true ) {
3389 - return current_time( 'mysql', $gmt );
3390 -}*/
3391 -
3392 -/**
3393 - * Wrap WP Core function current_time with timestamp format.
3394 - *
3395 - * @param bool $gmt
3396 - *
3397 - * @return int|string
3398 - * @since 4.0.0
3399 - */
3400 -function learn_press_timestamp( $gmt = true ) {
3401 - return current_time( 'timestamp', $gmt );
3402 -}
3403 -
3404 -/**
3405 - * Convert time from GMT to local.
3406 - *
3407 - * @param string|int|LP_Datetime $gmt_time
3408 - * @param string $format
3409 - *
3410 - * @return false|int|string
3411 - * @since 4.0.0
3412 - */
3413 -function learn_press_time_from_gmt( $gmt_time, $format = 'Y-m-d H:i:s' ) {
3414 - if ( is_string( $gmt_time ) ) {
3415 - $gmt_time = strtotime( $gmt_time );
3416 - } elseif ( $gmt_time instanceof LP_Datetime ) {
3417 - $gmt_time = strtotime( $gmt_time . '' );
3418 - }
3419 -
3420 - $current_time = $gmt_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
3421 -
3422 - if ( $format ) {
3423 - return date( $format, $current_time );
3424 - }
3425 -
3426 - return $current_time;
3427 -}
3428 -
3429 -/**
3430 - * Count all users has enrolled courses of an instructor.
3431 - *
3432 - * @param int $instructor_id . Author of course
3433 - *
3434 - SELECT COUNT(DISTINCT (user_id)) AS total
3435 - FROM wp_learnpress_user_items
3436 - WHERE 1 = 1
3437 - AND item_type = 'lp_course'
3438 - AND item_id IN (
3439 - SELECT ID
3440 - FROM wp_posts
3441 - WHERE post_author = 1
3442 - AND post_type = 'lp_course'
3443 - AND post_status = 'publish'
3444 - );
3445 - *
3446 - * @return int
3447 - * @since 4.0.0
3448 - * @editor tungnx
3449 - * @version 1.0.1
3450 - * @deprecated 4.1.6 replace to "get_statistic_info" function
3451 - */
3452 -//function learn_press_count_instructor_users( int $instructor_id = 0 ): int {
3453 -// try {
3454 -// $filter_course = new LP_Course_Filter();
3455 -// $filter_course->only_fields = array( 'ID' );
3456 -// $filter_course->post_author = $instructor_id;
3457 -// $filter_course->post_status = 'publish';
3458 -// $filter_course->return_string_query = true;
3459 -// $query_courses_str = LP_Course_DB::getInstance()->get_courses( $filter_course );
3460 -//
3461 -// $filter = new LP_User_Items_Filter();
3462 -// $filter->only_fields = array( 'DISTINCT (ui.user_id)' );
3463 -// $filter->field_count = 'DISTINCT (ui.user_id)';
3464 -// $filter->where[] = "AND item_id IN ({$query_courses_str})";
3465 -// $filter->query_count = true;
3466 -//
3467 -// return LP_User_Item_Course::get_user_courses( $filter );
3468 -// //return LP_User_Items_DB::getInstance()->get_user_courses( $filter );
3469 -// } catch ( Throwable $e ) {
3470 -// error_log( __FUNCTION__ . ': ' . $e->getMessage() );
3471 -//
3472 -// return 0;
3473 -// }
3474 -//
3475 -// /*$curd = new LP_User_CURD();
3476 -// $own_courses = $curd->query_own_courses( $instructor_id );
3477 -// $course_ids = $own_courses->get_items();*/
3478 -//
3479 -// /*
3480 -// global $wpdb;
3481 -// $filter = new LP_Course_Filter();
3482 -// $filter->post_author = $instructor_id;
3483 -// $filter->limit = -1;
3484 -// $courses = LP_Course::get_courses( $filter );
3485 -// $course_ids = LP_Course::get_course_ids( $courses );
3486 -//
3487 -// if ( ! empty( $course_ids ) ) {
3488 -// $query = $wpdb->prepare(
3489 -// "
3490 -// SELECT COUNT(user_id)
3491 -// FROM (
3492 -// SELECT item_id, user_id
3493 -// FROM {$wpdb->learnpress_user_items}
3494 -// WHERE item_type = %s
3495 -// GROUP BY item_id, user_id
3496 -// HAVING item_id IN(" . join( ',', $course_ids ) . ')
3497 -// ) X
3498 -// GROUP BY item_id
3499 -// ',
3500 -// LP_COURSE_CPT
3501 -// );
3502 -//
3503 -// $rows = $wpdb->get_col( $query );
3504 -//
3505 -// if ( $rows ) {
3506 -// return array_sum( $rows );
3507 -// }
3508 -// }
3509 -//
3510 -// return 0;*/
3511 -//}
3512 -
3513 -/**
3514 2238 * Get max retrying quiz allowed.
3515 2239 *
3516 2240 * @param int $quiz_id
3517 2241 * @param int $course_id
@@ -3523,34 +2247,9 @@
3523 2247 return apply_filters( 'learn-press/max-retry-quiz-allowed', 1, $quiz_id, $course_id );
3524 2248 }
3525 2249
3526 2250 /**
3527 - * Get max retrying course allowed.
3528 - *
3529 - * @param int $course_id
3530 - *
3531 - * @return int
3532 - * @since 4.0.0
3533 - */
3534 -function learn_press_get_course_max_retrying( $course_id ) {
3535 - return apply_filters( 'learn-press/max-retry-course-allowed', 1, $course_id );
3536 -}
3537 -
3538 -/**
3539 2251 * Get slug for status of course/lesson/quiz if user
3540 - * completed/finished and graduation is failed.
3541 - *
3542 - * @param string $type
3543 - *
3544 - * @return string
3545 - * @since 4.0.0
3546 - */
3547 -function learn_press_user_item_failed_slug( $type = '' ) {
3548 - return apply_filters( 'learn-press/user-item-failed-slug', 'failed', $type );
3549 -}
3550 -
3551 -/**
3552 - * Get slug for status of course/lesson/quiz if user
3553 2252 * completed/finished and graduation is passed.
3554 2253 *
3555 2254 * @param string $type
3556 2255 *
@@ -3556,21 +2255,8 @@
3556 2255 *
3557 2256 * @return string
3558 2257 * @since 4.0.0
3559 2258 */
3560 -function learn_press_user_item_passed_slug( $type = '' ) {
3561 - return apply_filters( 'learn-press/user-item-passed-slug', 'passed', $type );
3562 -}
3563 -
3564 -/**
3565 - * Get slug for status of course/lesson/quiz if user
3566 - * completed/finished and graduation is passed.
3567 - *
3568 - * @param string $type
3569 - *
3570 - * @return string
3571 - * @since 4.0.0
3572 - */
3573 2259 function learn_press_user_item_in_progress_slug( $type = '' ) {
3574 2260 return apply_filters( 'learn-press/user-item-in-progress-slug', 'in-progress', $type );
3575 2261 }
3576 2262
@@ -3599,29 +2285,9 @@
3599 2285
3600 2286 /**
3601 2287 * @return array
3602 2288 * @since 4.0.0
3603 - * @editor tungnx
3604 - * @modify 4.1.3 - comment - not use
3605 2289 */
3606 -function learn_press_course_enrolled_slugs(): array {
3607 - _deprecated_function( __FUNCTION__, '4.1.3' );
3608 - return apply_filters(
3609 - 'learn-press/course-enrolled-slugs',
3610 - array(
3611 - learn_press_user_item_passed_slug(),
3612 - learn_press_user_item_failed_slug(),
3613 - 'in-progress',
3614 - 'enrolled',
3615 - 'finished', // deprecated
3616 - )
3617 - );
3618 -}
3619 -
3620 -/**
3621 - * @return array
3622 - * @since 4.0.0
3623 - */
3624 2290 function lp_item_course_class( $class = array() ) {
3625 2291 $classes = array_merge(
3626 2292 $class,
3627 2293 array( 'learn-press-courses' )
@@ -3630,82 +2296,24 @@
3630 2296 }
3631 2297
3632 2298 //require_once dirname( __FILE__ ) . '/lp-custom-hooks.php';
3633 2299
3634 -
3635 -/**
3636 - * Disable auto update
3637 - *
3638 - * @param $update
3639 - * @param $item
3640 - *
3641 - * @return false
3642 - * @author hungkv
3643 - */
3644 -/*function learnpress_disable_auto_update( $update, $item ) {
3645 - $plugins = array( // Plugins to auto-update
3646 - 'learnpress',
3647 - );
3648 - // Auto-update specified plugins
3649 - if ( in_array( $item->slug, $plugins ) ) {
3650 - return false;
3651 - }
3652 -}
3653 -add_filter( 'auto_update_plugin', 'learnpress_disable_auto_update', 10, 2 );*/
3654 -
3655 -add_action(
2300 +// Notify update message for LearnPress plugin
2301 +/*add_action(
3656 2302 'in_plugin_update_message-learnpress/learnpress.php',
3657 2303 function ( $plugin_data ) {
3658 - version_update_warning( LEARNPRESS_VERSION, $plugin_data['new_version'] );
3659 - }
3660 -);
3661 -/**
3662 - * Custom message warning have new version
3663 - *
3664 - * @param $current_version
3665 - * @param $new_version
3666 - * @author hungkv
3667 - */
3668 -function version_update_warning( $current_version, $new_version ) {
3669 - $current_version_minor_part = explode( '.', $current_version )[1];
3670 - $new_version_minor_part = explode( '.', $new_version )[1];
3671 - if ( $current_version_minor_part === $new_version_minor_part ) {
3672 - return;
3673 - }
3674 -
3675 - $info = get_plugin_data( LP_PLUGIN_FILE );
3676 - ?>
3677 - <hr class="lp-update--warning__separator"/>
3678 - <div class="lp-update--warning">
3679 - <div>
3680 - <div class="lp-update-warning__title">
3681 - <?php echo esc_html__( 'Heads up, Please backup before upgrade!', 'learnpress' ); ?>
3682 - </div>
3683 - <div class="lp-update-warning__message">
3684 - <?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' ); ?>
3685 - <?php echo esc_html__( 'Learners require WordPress version ' . $info['Requires at least'] . ' or higher.', 'learnpress' ); ?>
3686 - </div>
3687 - </div>
3688 - </div>
3689 -
3690 - <?php
3691 -}
3692 -
3693 -// If profile content don't have shortcode profile.
3694 -function lp_add_shortcode_profile() {
3695 - global $post;
3696 -
3697 - if ( learn_press_is_profile() && is_object( $post ) ) {
3698 - if ( ! has_shortcode( $post->post_content, 'learn_press_profile' ) ) {
3699 - $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;
3700 2306 }
3701 2307
3702 - 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 + );
3703 2313 }
3704 -}
2314 +);*/
3705 2315
3706 -add_action( 'template_redirect', 'lp_add_shortcode_profile' );
3707 -
3708 2316 /**
3709 2317 * If Elementor Pro set Theme builder type "Archive", will not show content on page "Archive course"
3710 2318 *
3711 2319 * @editor tungnx
@@ -3715,9 +2323,9 @@
3715 2323 * @version 1.0.1
3716 2324 */
3717 2325 add_filter(
3718 2326 'elementor/theme/get_location_templates/template_id',
3719 - function( $theme_template_id ) {
2327 + function ( $theme_template_id ) {
3720 2328 $elementor_template_type = get_post_meta( $theme_template_id, '_elementor_template_type', true );
3721 2329
3722 2330 if ( in_array( $elementor_template_type, array( 'archive' ) ) ) {
3723 2331 if ( LP_PAGE_COURSES === LP_Page_Controller::page_current() && class_exists( 'ElementorPro\Modules\ThemeBuilder\Conditions\Archive' ) ) {