| @@ -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' => 'د.إ', | |
| 1139 | - 'AFN' => '؋', | |
| 1140 | - 'ALL' => 'L', | |
| 1141 | - 'AMD' => 'AMD', | |
| 1142 | - 'ANG' => 'ƒ', | |
| 1143 | - 'AOA' => 'Kz', | |
| 1144 | - 'ARS' => '$', | |
| 1145 | - 'AUD' => '$', | |
| 1146 | - 'AWG' => 'Afl.', | |
| 1147 | - 'AZN' => 'AZN', | |
| 1148 | - 'BAM' => 'KM', | |
| 1149 | - 'BBD' => '$', | |
| 1150 | - 'BDT' => '৳ ', | |
| 1151 | - 'BGN' => 'лв.', | |
| 1152 | - 'BHD' => '.د.ب', | |
| 1153 | - 'BIF' => 'Fr', | |
| 1154 | - 'BMD' => '$', | |
| 1155 | - 'BND' => '$', | |
| 1156 | - 'BOB' => 'Bs.', | |
| 1157 | - 'BRL' => 'R$', | |
| 1158 | - 'BSD' => '$', | |
| 1159 | - 'BTC' => '฿', | |
| 1160 | - 'BTN' => 'Nu.', | |
| 1161 | - 'BWP' => 'P', | |
| 1162 | - 'BYR' => 'Br', | |
| 1163 | - 'BYN' => 'Br', | |
| 1164 | - 'BZD' => '$', | |
| 1165 | - 'CAD' => '$', | |
| 1166 | - 'CDF' => 'Fr', | |
| 1167 | - 'CHF' => 'CHF', | |
| 1168 | - 'CLP' => '$', | |
| 1169 | - 'CNY' => '¥', | |
| 1170 | - 'COP' => '$', | |
| 1171 | - 'CRC' => '₡', | |
| 1172 | - 'CUC' => '$', | |
| 1173 | - 'CUP' => '$', | |
| 1174 | - 'CVE' => '$', | |
| 1175 | - 'CZK' => 'Kč', | |
| 1176 | - 'DJF' => 'Fr', | |
| 1177 | - 'DKK' => 'DKK', | |
| 1178 | - 'DOP' => 'RD$', | |
| 1179 | - 'DZD' => 'د.ج', | |
| 1180 | - 'EGP' => 'EGP', | |
| 1181 | - 'ERN' => 'Nfk', | |
| 1182 | - 'ETB' => 'Br', | |
| 1183 | - 'EUR' => '€', | |
| 1184 | - 'FJD' => '$', | |
| 1185 | - 'FKP' => '£', | |
| 1186 | - 'GBP' => '£', | |
| 1187 | - 'GEL' => '₾', | |
| 1188 | - 'GGP' => '£', | |
| 1189 | - 'GHS' => '₵', | |
| 1190 | - 'GIP' => '£', | |
| 1191 | - 'GMD' => 'D', | |
| 1192 | - 'GNF' => 'Fr', | |
| 1193 | - 'GTQ' => 'Q', | |
| 1194 | - 'GYD' => '$', | |
| 1195 | - 'HKD' => '$', | |
| 1196 | - 'HNL' => 'L', | |
| 1197 | - 'HRK' => 'kn', | |
| 1198 | - 'HTG' => 'G', | |
| 1199 | - 'HUF' => 'Ft', | |
| 1200 | - 'IDR' => 'Rp', | |
| 1201 | - 'ILS' => '₪', | |
| 1202 | - 'IMP' => '£', | |
| 1203 | - 'INR' => '₹', | |
| 1204 | - 'IQD' => 'ع.د', | |
| 1205 | - 'IRR' => '﷼', | |
| 1206 | - 'IRT' => 'تومان', | |
| 1207 | - 'ISK' => 'kr.', | |
| 1208 | - 'JEP' => '£', | |
| 1209 | - 'JMD' => '$', | |
| 1210 | - 'JOD' => 'د.ا', | |
| 1211 | - 'JPY' => '¥', | |
| 1212 | - 'KES' => 'KSh', | |
| 1213 | - 'KGS' => 'сом', | |
| 1214 | - 'KHR' => '៛', | |
| 1215 | - 'KMF' => 'Fr', | |
| 1216 | - 'KPW' => '₩', | |
| 1217 | - 'KRW' => '₩', | |
| 1218 | - 'KWD' => 'د.ك', | |
| 1219 | - 'KYD' => '$', | |
| 1220 | - 'KZT' => '₸', | |
| 1221 | - 'LAK' => '₭', | |
| 1222 | - 'LBP' => 'ل.ل', | |
| 1223 | - 'LKR' => 'රු', | |
| 1224 | - 'LRD' => '$', | |
| 1225 | - 'LSL' => 'L', | |
| 1226 | - 'LYD' => 'ل.د', | |
| 1227 | - 'MAD' => 'د.م.', | |
| 1228 | - 'MDL' => 'MDL', | |
| 1229 | - 'MGA' => 'Ar', | |
| 1230 | - 'MKD' => 'ден', | |
| 1231 | - 'MMK' => 'Ks', | |
| 1232 | - 'MNT' => '₮', | |
| 1233 | - 'MOP' => 'P', | |
| 1234 | - 'MRU' => 'UM', | |
| 1235 | - 'MUR' => '₨', | |
| 1236 | - 'MVR' => '.ރ', | |
| 1237 | - 'MWK' => 'MK', | |
| 1238 | - 'MXN' => '$', | |
| 1239 | - 'MYR' => 'RM', | |
| 1240 | - 'MZN' => 'MT', | |
| 1241 | - 'NAD' => 'N$', | |
| 1242 | - 'NGN' => '₦', | |
| 1243 | - 'NIO' => 'C$', | |
| 1244 | - 'NOK' => 'kr', | |
| 1245 | - 'NPR' => '₨', | |
| 1246 | - 'NZD' => '$', | |
| 1247 | - 'OMR' => 'ر.ع.', | |
| 1248 | - 'PAB' => 'B/.', | |
| 1249 | - 'PEN' => 'S/', | |
| 1250 | - 'PGK' => 'K', | |
| 1251 | - 'PHP' => '₱', | |
| 1252 | - 'PKR' => '₨', | |
| 1253 | - 'PLN' => 'zł', | |
| 1254 | - 'PRB' => 'р.', | |
| 1255 | - 'PYG' => '₲', | |
| 1256 | - 'QAR' => 'ر.ق', | |
| 1257 | - 'RMB' => '¥', | |
| 1258 | - 'RON' => 'lei', | |
| 1259 | - 'RSD' => 'рсд', | |
| 1260 | - 'RUB' => '₽', | |
| 1261 | - 'RWF' => 'Fr', | |
| 1262 | - 'SAR' => 'ر.س', | |
| 1263 | - 'SBD' => '$', | |
| 1264 | - 'SCR' => '₨', | |
| 1265 | - 'SDG' => 'ج.س.', | |
| 1266 | - 'SEK' => 'kr', | |
| 1267 | - 'SGD' => '$', | |
| 1268 | - 'SHP' => '£', | |
| 1269 | - 'SLL' => 'Le', | |
| 1270 | - 'SOS' => 'Sh', | |
| 1271 | - 'SRD' => '$', | |
| 1272 | - 'SSP' => '£', | |
| 1273 | - 'STN' => 'Db', | |
| 1274 | - 'SYP' => 'ل.س', | |
| 1275 | - 'SZL' => 'L', | |
| 1276 | - 'THB' => '฿', | |
| 1277 | - 'TJS' => 'ЅМ', | |
| 1278 | - 'TMT' => 'm', | |
| 1279 | - 'TND' => 'د.ت', | |
| 1280 | - 'TOP' => 'T$', | |
| 1281 | - 'TRY' => '₺', | |
| 1282 | - 'TTD' => '$', | |
| 1283 | - 'TWD' => 'NT$', | |
| 1284 | - 'TZS' => 'Sh', | |
| 1285 | - 'UAH' => '₴', | |
| 1286 | - 'UGX' => 'UGX', | |
| 1287 | - 'USD' => '$', | |
| 1288 | - 'UYU' => '$', | |
| 1289 | - 'UZS' => 'UZS', | |
| 1290 | - 'VEF' => 'Bs F', | |
| 1291 | - 'VES' => 'Bs.S', | |
| 1292 | - 'VND' => '₫', | |
| 1293 | - 'VUV' => 'Vt', | |
| 1294 | - 'WST' => 'T', | |
| 1295 | - 'XAF' => 'CFA', | |
| 1296 | - 'XCD' => '$', | |
| 1297 | - 'XOF' => 'CFA', | |
| 1298 | - 'XPF' => 'Fr', | |
| 1299 | - 'YER' => '﷼', | |
| 1300 | - 'ZAR' => 'R', | |
| 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,10 +1213,15 @@ | ||
| 1731 | 1213 | } |
| 1732 | 1214 | } |
| 1733 | 1215 | |
| 1734 | 1216 | if ( ! function_exists( 'learn_press_is_course' ) ) { |
| 1735 | - function learn_press_is_course() { | |
| 1736 | - 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; | |
| 1737 | 1224 | } |
| 1738 | 1225 | } |
| 1739 | 1226 | |
| 1740 | 1227 | if ( ! function_exists( 'learn_press_is_lesson' ) ) { |
| @@ -1784,8 +1271,19 @@ | ||
| 1784 | 1271 | |
| 1785 | 1272 | return apply_filters( 'learn-press/is-checkout', false ); |
| 1786 | 1273 | } |
| 1787 | 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 | + | |
| 1788 | 1286 | /** |
| 1789 | 1287 | * Return register permalink |
| 1790 | 1288 | * |
| 1791 | 1289 | * @return mixed |
| @@ -1800,10 +1298,12 @@ | ||
| 1800 | 1298 | * @param string |
| 1801 | 1299 | * @param string |
| 1802 | 1300 | * |
| 1803 | 1301 | * @return mixed |
| 1302 | + * @deprecated 4.2.5 | |
| 1804 | 1303 | */ |
| 1805 | 1304 | function learn_press_add_notice( $message, $type = 'updated' ) { |
| 1305 | + _deprecated_function( __FUNCTION__, '4.2.5' ); | |
| 1806 | 1306 | LP_Admin_Notice::instance()->add( $message, $type ); |
| 1807 | 1307 | } |
| 1808 | 1308 | |
| 1809 | 1309 | /** |
| @@ -1808,29 +1308,29 @@ | ||
| 1808 | 1308 | |
| 1809 | 1309 | /** |
| 1810 | 1310 | * Set user's cookie |
| 1811 | 1311 | * |
| 1812 | - * @param $name | |
| 1813 | - * @param $value | |
| 1814 | - * @param int $expire | |
| 1815 | - * @param bool $secure | |
| 1312 | + * @param string $name | |
| 1313 | + * @param mixed $value | |
| 1314 | + * @param int $expire | |
| 1315 | + * @param bool $httponly | |
| 1816 | 1316 | * |
| 1817 | 1317 | * @editor tungnx |
| 1818 | - * @version 1.0.2 | |
| 1318 | + * @version 1.0.3 | |
| 1819 | 1319 | */ |
| 1820 | -function learn_press_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { | |
| 1821 | - $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) ); | |
| 1822 | - | |
| 1823 | - @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 ); | |
| 1824 | 1322 | } |
| 1825 | 1323 | |
| 1826 | 1324 | /** |
| 1827 | 1325 | * Clear cookie |
| 1828 | 1326 | * |
| 1829 | - * @param $name | |
| 1327 | + * @param string $name | |
| 1830 | 1328 | */ |
| 1831 | -function learn_press_remove_cookie( $name ) { | |
| 1832 | - 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 | + } | |
| 1833 | 1333 | |
| 1834 | 1334 | if ( array_key_exists( $name, $_COOKIE ) ) { |
| 1835 | 1335 | unset( $_COOKIE[ $name ] ); |
| 1836 | 1336 | } |
| @@ -1836,9 +1336,9 @@ | ||
| 1836 | 1336 | } |
| 1837 | 1337 | } |
| 1838 | 1338 | |
| 1839 | 1339 | /** |
| 1840 | - * Filter the login url so third-party can be customize | |
| 1340 | + * Filter the login url so third-party can be customized | |
| 1841 | 1341 | * |
| 1842 | 1342 | * @param string $redirect |
| 1843 | 1343 | * |
| 1844 | 1344 | * @return mixed |
| @@ -1869,9 +1369,9 @@ | ||
| 1869 | 1369 | $url = get_permalink(); |
| 1870 | 1370 | } |
| 1871 | 1371 | |
| 1872 | 1372 | // Map endpoint to options |
| 1873 | - $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; | |
| 1874 | 1374 | |
| 1875 | 1375 | if ( get_option( 'permalink_structure' ) ) { |
| 1876 | 1376 | if ( strstr( $url, '?' ) ) { |
| 1877 | 1377 | $query_string = '?' . parse_url( $url, PHP_URL_QUERY ); |
| @@ -1888,45 +1388,12 @@ | ||
| 1888 | 1388 | return apply_filters( 'learn_press_get_endpoint_url', esc_url_raw( $url ), $name, $value, $url ); |
| 1889 | 1389 | } |
| 1890 | 1390 | |
| 1891 | 1391 | /** |
| 1892 | - * Add all endpoints from settings to the pages. | |
| 1392 | + * @deprecated 4.2.3 | |
| 1893 | 1393 | */ |
| 1894 | -function learn_press_add_endpoints() { | |
| 1895 | - $settings = LP_Settings::instance(); | |
| 1896 | - | |
| 1897 | - $endpoints = $settings->get_checkout_endpoints(); | |
| 1898 | - if ( $endpoints ) { | |
| 1899 | - foreach ( $endpoints as $endpoint => $value ) { | |
| 1900 | - LP()->query_vars[ $endpoint ] = $value; | |
| 1901 | - add_rewrite_endpoint( $value, EP_PAGES ); | |
| 1902 | - } | |
| 1903 | - } | |
| 1904 | - | |
| 1905 | - $endpoints = $settings->get_profile_endpoints(); | |
| 1906 | - if ( $endpoints ) { | |
| 1907 | - foreach ( $endpoints as $endpoint => $value ) { | |
| 1908 | - LP()->query_vars[ $endpoint ] = $value; | |
| 1909 | - add_rewrite_endpoint( $value, EP_PAGES ); | |
| 1910 | - } | |
| 1911 | - } | |
| 1912 | - | |
| 1913 | - $endpoints = $settings->get( 'quiz_endpoints' ); | |
| 1914 | - if ( $endpoints ) { | |
| 1915 | - foreach ( $endpoints as $endpoint => $value ) { | |
| 1916 | - $endpoint = preg_replace( '!_!', '-', $endpoint ); | |
| 1917 | - LP()->query_vars[ $endpoint ] = $value; | |
| 1918 | - add_rewrite_endpoint( | |
| 1919 | - $value, /*EP_ROOT | */ | |
| 1920 | - EP_PAGES | |
| 1921 | - ); | |
| 1922 | - } | |
| 1923 | - } | |
| 1924 | -} | |
| 1925 | - | |
| 1926 | -add_action( 'init', 'learn_press_add_endpoints' ); | |
| 1927 | - | |
| 1928 | 1394 | function learn_press_is_yes( $value ) { |
| 1395 | + _deprecated_function( __FUNCTION__, '4.2.3' ); | |
| 1929 | 1396 | return ( $value === 1 ) || ( $value === '1' ) || ( $value == 'yes' ) || ( $value == true ) || ( $value == 'on' ); |
| 1930 | 1397 | } |
| 1931 | 1398 | |
| 1932 | 1399 | /** |
| @@ -1932,10 +1399,12 @@ | ||
| 1932 | 1399 | /** |
| 1933 | 1400 | * @param mixed $value |
| 1934 | 1401 | * |
| 1935 | 1402 | * @return bool |
| 1403 | + * @deprecated 4.2.3 | |
| 1936 | 1404 | */ |
| 1937 | 1405 | function _is_false_value( $value ) { |
| 1406 | + _deprecated_function( __FUNCTION__, '4.2.3' ); | |
| 1938 | 1407 | if ( is_numeric( $value ) ) { |
| 1939 | 1408 | return $value == 0; |
| 1940 | 1409 | } elseif ( is_string( $value ) ) { |
| 1941 | 1410 | return ( empty( $value ) || is_null( $value ) || in_array( $value, array( 'no', 'off', 'false' ) ) ); |
| @@ -1951,9 +1420,9 @@ | ||
| 1951 | 1420 | function learn_press_parse_request() { |
| 1952 | 1421 | global $wp; |
| 1953 | 1422 | |
| 1954 | 1423 | // Map query vars to their keys, or get them if endpoints are not supported |
| 1955 | - foreach ( LP()->query_vars as $key => $var ) { | |
| 1424 | + foreach ( LearnPress::instance()->query_vars as $key => $var ) { | |
| 1956 | 1425 | if ( isset( $_GET[ $var ] ) ) { |
| 1957 | 1426 | $wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $_GET[ $var ] ?? '' ); |
| 1958 | 1427 | } elseif ( isset( $wp->query_vars[ $var ] ) ) { |
| 1959 | 1428 | $wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $wp->query_vars[ $var ] ?? '' ); |
| @@ -1975,53 +1444,18 @@ | ||
| 1975 | 1444 | } |
| 1976 | 1445 | } |
| 1977 | 1446 | |
| 1978 | 1447 | /** |
| 1979 | - * @param string $handle | |
| 1980 | - * @param bool $hash | |
| 1981 | - * | |
| 1982 | - * @return string | |
| 1983 | - */ | |
| 1984 | -function learn_press_get_log_file_path( $handle, $hash = false ) { | |
| 1985 | - if ( $hash ) { | |
| 1986 | - $hash = '-' . sanitize_file_name( wp_hash( $handle ) ); | |
| 1987 | - } | |
| 1988 | - | |
| 1989 | - return trailingslashit( LP_LOG_PATH ) . $handle . $hash . '.log'; | |
| 1990 | -} | |
| 1991 | - | |
| 1992 | -/** | |
| 1993 | 1448 | * Get the cart object in checkout page |
| 1994 | 1449 | * |
| 1995 | 1450 | * @return LP_Cart |
| 1451 | + * @deprecated 4.2.0 | |
| 1996 | 1452 | */ |
| 1997 | 1453 | function learn_press_get_checkout_cart() { |
| 1998 | - 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 ); | |
| 1999 | 1456 | } |
| 2000 | 1457 | |
| 2001 | -/*function learn_press_front_scripts() { | |
| 2002 | - if ( is_admin() ) { | |
| 2003 | - return; | |
| 2004 | - } | |
| 2005 | - $js = array( | |
| 2006 | - 'ajax' => admin_url( 'admin-ajax.php' ), | |
| 2007 | - 'plugin_url' => LP()->plugin_url(), | |
| 2008 | - 'siteurl' => home_url(), | |
| 2009 | - 'current_url' => learn_press_get_current_url(), | |
| 2010 | - 'localize' => array( | |
| 2011 | - 'button_ok' => __( 'OK', 'learnpress' ), | |
| 2012 | - 'button_cancel' => __( 'Cancel', 'learnpress' ), | |
| 2013 | - 'button_yes' => __( 'Yes', 'learnpress' ), | |
| 2014 | - 'button_no' => __( 'No', 'learnpress' ), | |
| 2015 | - ), | |
| 2016 | - ); | |
| 2017 | - foreach ( $js as $k => $v ) { | |
| 2018 | - LP_Assets::add_param( $k, $v, array( 'learn-press-single-course', 'learn-press-global' ), 'LP_Settings' ); | |
| 2019 | - } | |
| 2020 | -} | |
| 2021 | - | |
| 2022 | -add_action( 'wp_print_scripts', 'learn_press_front_scripts' );*/ | |
| 2023 | - | |
| 2024 | 1458 | function learn_press_user_time( $time, $format = 'timestamp' ) { |
| 2025 | 1459 | if ( is_string( $time ) ) { |
| 2026 | 1460 | $time = @strtotime( $time ); |
| 2027 | 1461 | } |
| @@ -2047,13 +1481,20 @@ | ||
| 2047 | 1481 | * |
| 2048 | 1482 | * @param bool $default |
| 2049 | 1483 | * |
| 2050 | 1484 | * @return mixed|string |
| 1485 | + * @deprecated 4.2.2 | |
| 1486 | + * addon commission 4.0.2 still use this function | |
| 2051 | 1487 | */ |
| 2052 | 1488 | function learn_press_get_current_profile_tab( $default = true ) { |
| 2053 | 1489 | global $wp_query, $wp; |
| 2054 | 1490 | $current = ''; |
| 2055 | 1491 | |
| 1492 | + // Only load on profile page. | |
| 1493 | + if ( ! LP_Page_Controller::is_page_profile() ) { | |
| 1494 | + return false; | |
| 1495 | + } | |
| 1496 | + | |
| 2056 | 1497 | if ( ! empty( $_REQUEST['tab'] ) ) { |
| 2057 | 1498 | $current = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ); |
| 2058 | 1499 | } elseif ( ! empty( $wp_query->query_vars['tab'] ) ) { |
| 2059 | 1500 | $current = $wp_query->query_vars['tab']; |
| @@ -2074,9 +1515,9 @@ | ||
| 2074 | 1515 | |
| 2075 | 1516 | return $current; |
| 2076 | 1517 | } |
| 2077 | 1518 | |
| 2078 | -add_action( 'init', 'learn_press_get_current_profile_tab' ); | |
| 1519 | +//add_action( 'init', 'learn_press_get_current_profile_tab' ); | |
| 2079 | 1520 | |
| 2080 | 1521 | function learn_press_profile_tab_exists( $tab ) { |
| 2081 | 1522 | $tabs = learn_press_get_user_profile_tabs(); |
| 2082 | 1523 | |
| @@ -2086,39 +1527,8 @@ | ||
| 2086 | 1527 | |
| 2087 | 1528 | return false; |
| 2088 | 1529 | } |
| 2089 | 1530 | |
| 2090 | -/** | |
| 2091 | - * Replace the spacing with the + (plus) char. | |
| 2092 | - * | |
| 2093 | - * @param string $string | |
| 2094 | - * | |
| 2095 | - * @return string | |
| 2096 | - */ | |
| 2097 | -function _learn_press_urlencode( $string ) { | |
| 2098 | - return preg_replace( '/\s/', '+', $string ); | |
| 2099 | -} | |
| 2100 | - | |
| 2101 | -/** | |
| 2102 | - * Point the archive post type link to course page if current | |
| 2103 | - * post type is course and the page for displaying course is | |
| 2104 | - * setup. | |
| 2105 | - * | |
| 2106 | - * @param string $link | |
| 2107 | - * @param string $post_type | |
| 2108 | - * | |
| 2109 | - * @return string | |
| 2110 | - */ | |
| 2111 | -function learn_press_post_type_archive_link( $link, $post_type ) { | |
| 2112 | - if ( $post_type == LP_COURSE_CPT && learn_press_get_page_id( 'courses' ) ) { | |
| 2113 | - $link = learn_press_get_page_link( 'courses' ); | |
| 2114 | - } | |
| 2115 | - | |
| 2116 | - return $link; | |
| 2117 | -} | |
| 2118 | - | |
| 2119 | -add_filter( 'post_type_archive_link', 'learn_press_post_type_archive_link', 10, 2 ); | |
| 2120 | - | |
| 2121 | 1531 | function learn_press_single_term_title( $prefix = '', $display = true ) { |
| 2122 | 1532 | $term = get_queried_object(); |
| 2123 | 1533 | |
| 2124 | 1534 | if ( ! $term ) { |
| @@ -2218,9 +1628,9 @@ | ||
| 2218 | 1628 | ), |
| 2219 | 1629 | array( |
| 2220 | 1630 | 'title' => __( 'Enable cart', 'learnpress' ), |
| 2221 | 1631 | 'desc' => __( |
| 2222 | - '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.', | |
| 2223 | 1633 | 'learnpress' |
| 2224 | 1634 | ), |
| 2225 | 1635 | 'id' => $class->get_field_name( 'enable_cart' ), |
| 2226 | 1636 | 'default' => 'yes', |
| @@ -2227,9 +1637,9 @@ | ||
| 2227 | 1637 | 'type' => 'checkbox', |
| 2228 | 1638 | ), |
| 2229 | 1639 | array( |
| 2230 | 1640 | 'title' => __( 'Add to cart redirect', 'learnpress' ), |
| 2231 | - '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' ), | |
| 2232 | 1642 | 'id' => $class->get_field_name( 'redirect_after_add' ), |
| 2233 | 1643 | 'default' => 'yes', |
| 2234 | 1644 | 'type' => 'checkbox', |
| 2235 | 1645 | ), |
| @@ -2234,9 +1644,9 @@ | ||
| 2234 | 1644 | 'type' => 'checkbox', |
| 2235 | 1645 | ), |
| 2236 | 1646 | array( |
| 2237 | 1647 | 'title' => __( 'AJAX add to cart', 'learnpress' ), |
| 2238 | - 'desc' => __( 'Using AJAX to add course to cart.', 'learnpress' ), | |
| 1648 | + 'desc' => __( 'Using AJAX to add the course to the cart.', 'learnpress' ), | |
| 2239 | 1649 | 'id' => $class->get_field_name( 'ajax_add_to_cart' ), |
| 2240 | 1650 | 'default' => 'no', |
| 2241 | 1651 | 'type' => 'checkbox', |
| 2242 | 1652 | ), |
| @@ -2285,9 +1695,9 @@ | ||
| 2285 | 1695 | /** |
| 2286 | 1696 | * @return string |
| 2287 | 1697 | */ |
| 2288 | 1698 | function learn_press_checkout_needs_payment() { |
| 2289 | - return LP()->cart->needs_payment(); | |
| 1699 | + return LearnPress::instance()->cart->needs_payment(); | |
| 2290 | 1700 | } |
| 2291 | 1701 | |
| 2292 | 1702 | /** |
| 2293 | 1703 | * Return plugin basename |
| @@ -2365,32 +1775,8 @@ | ||
| 2365 | 1775 | die( __FUNCTION__ ); |
| 2366 | 1776 | } |
| 2367 | 1777 | } |
| 2368 | 1778 | |
| 2369 | -/** | |
| 2370 | - * Get current time to user for calculate remaining time of quiz. | |
| 2371 | - * | |
| 2372 | - * @return int | |
| 2373 | - */ | |
| 2374 | -function learn_press_get_current_time() { | |
| 2375 | - $current_time = apply_filters( 'learn_press_get_current_time', 0 ); | |
| 2376 | - | |
| 2377 | - if ( $current_time > 0 ) { | |
| 2378 | - return $current_time; | |
| 2379 | - } | |
| 2380 | - | |
| 2381 | - $a = current_time( 'timestamp' ); | |
| 2382 | - $b = time(); | |
| 2383 | - $c = current_time( 'mysql' ); | |
| 2384 | - $d = strtotime( $c ); | |
| 2385 | - | |
| 2386 | - if ( $d == $a ) { | |
| 2387 | - return $a; | |
| 2388 | - } else { | |
| 2389 | - return $b; | |
| 2390 | - } | |
| 2391 | -} | |
| 2392 | - | |
| 2393 | 1779 | function learn_press_get_requested_post_type() { |
| 2394 | 1780 | global $pagenow; |
| 2395 | 1781 | if ( $pagenow == 'post-new.php' && ! empty( $_REQUEST['post_type'] ) ) { |
| 2396 | 1782 | $post_type = LP_Helper::sanitize_params_submitted( $_REQUEST['post_type'] ); |
| @@ -2426,24 +1812,8 @@ | ||
| 2426 | 1812 | |
| 2427 | 1813 | return apply_filters( 'learn-press/get-graduation-text', $text, $slug ); |
| 2428 | 1814 | } |
| 2429 | 1815 | |
| 2430 | -/*function learn_press_execute_time( $n = 1 ) { | |
| 2431 | - static $time; | |
| 2432 | - if ( empty( $time ) ) { | |
| 2433 | - $time = microtime( true ); | |
| 2434 | - | |
| 2435 | - return $time; | |
| 2436 | - } else { | |
| 2437 | - $execute_time = microtime( true ) - $time; | |
| 2438 | - | |
| 2439 | - echo 'Execute time ' . $n * $execute_time . "\n"; | |
| 2440 | - $time = 0; | |
| 2441 | - | |
| 2442 | - return $execute_time; | |
| 2443 | - } | |
| 2444 | -}*/ | |
| 2445 | - | |
| 2446 | 1816 | if ( ! function_exists( 'learn_press_is_negative_value' ) ) { |
| 2447 | 1817 | function learn_press_is_negative_value( $value ) { |
| 2448 | 1818 | $return = in_array( $value, array( 'no', 'off', 'false', '0' ) ) || ! $value || $value == '' || $value == null; |
| 2449 | 1819 | |
| @@ -2507,15 +1877,8 @@ | ||
| 2507 | 1877 | } |
| 2508 | 1878 | |
| 2509 | 1879 | add_filter( 'comment_reply_link', 'learn_press_comment_reply_link', 10, 4 ); |
| 2510 | 1880 | |
| 2511 | -function learn_press_deprecated_function( $function, $version, $replacement = null ) { | |
| 2512 | - if ( LP_Debug::is_debug() ) { | |
| 2513 | - _deprecated_function( $function, $version, $replacement ); | |
| 2514 | - } | |
| 2515 | -} | |
| 2516 | - | |
| 2517 | - | |
| 2518 | 1881 | /** |
| 2519 | 1882 | * Sanitize content of tooltip |
| 2520 | 1883 | * |
| 2521 | 1884 | * @param string $tooltip |
| @@ -2553,29 +1916,14 @@ | ||
| 2553 | 1916 | echo '<span class="learn-press-tooltip" data-tooltip="' . esc_attr( $tooltip ) . '"></span>'; |
| 2554 | 1917 | } |
| 2555 | 1918 | |
| 2556 | 1919 | /** |
| 2557 | - * Get timezone offset from wp settings. | |
| 2558 | - * | |
| 2559 | - * @return float|int | |
| 2560 | - * @since 3.0.0 | |
| 2561 | - */ | |
| 2562 | -function learn_press_timezone_offset() { | |
| 2563 | - if ( $tz = get_option( 'timezone_string' ) ) { | |
| 2564 | - $timezone = new DateTimeZone( $tz ); | |
| 2565 | - | |
| 2566 | - return $timezone->getOffset( new DateTime( 'now' ) ); | |
| 2567 | - } else { | |
| 2568 | - return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS; | |
| 2569 | - } | |
| 2570 | -} | |
| 2571 | - | |
| 2572 | -/** | |
| 2573 | 1920 | * Get default static pages of LP. |
| 2574 | 1921 | * |
| 2575 | 1922 | * @return array |
| 2576 | 1923 | * |
| 2577 | 1924 | * @since 3.0.0 |
| 1925 | + * @deprecated 4.2.3 | |
| 2578 | 1926 | */ |
| 2579 | 1927 | function learn_press_static_page_ids() { |
| 2580 | 1928 | $pages = LP_Object_Cache::get( 'static-page-ids', 'learn-press' ); |
| 2581 | 1929 | |
| @@ -2599,237 +1947,8 @@ | ||
| 2599 | 1947 | return apply_filters( 'learn-press/static-page-ids', $pages ); |
| 2600 | 1948 | } |
| 2601 | 1949 | |
| 2602 | 1950 | /** |
| 2603 | - * Get default static pages of LP. | |
| 2604 | - * | |
| 2605 | - * @param bool $name - Optional. TRUE will return name only. | |
| 2606 | - * | |
| 2607 | - * @return array | |
| 2608 | - * | |
| 2609 | - * @since 3.0.0 | |
| 2610 | - */ | |
| 2611 | -function learn_press_static_pages( $name = false ) { | |
| 2612 | - $pages = apply_filters( | |
| 2613 | - 'learn-press/static-pages', | |
| 2614 | - array( | |
| 2615 | - 'checkout' => _x( 'Checkout', 'static-page-name', 'learnpress' ), | |
| 2616 | - 'courses' => _x( 'Courses', 'static-page-name', 'learnpress' ), | |
| 2617 | - 'profile' => _x( 'Profile', 'static-page-name', 'learnpress' ), | |
| 2618 | - 'become_a_teacher' => _x( 'Become a Teacher', 'static-page-name', 'learnpress' ), | |
| 2619 | - ) | |
| 2620 | - ); | |
| 2621 | - | |
| 2622 | - if ( $name ) { | |
| 2623 | - return array_keys( $pages ); | |
| 2624 | - } | |
| 2625 | - | |
| 2626 | - return $pages; | |
| 2627 | -} | |
| 2628 | - | |
| 2629 | -/*function learn_press_cache_path( $group, $key = '' ) { | |
| 2630 | - $path = LP_PLUGIN_PATH . 'cache'; | |
| 2631 | - if ( ! file_exists( $path ) ) { | |
| 2632 | - @mkdir( $path ); | |
| 2633 | - } | |
| 2634 | - $path = $path . '/' . $group; | |
| 2635 | - | |
| 2636 | - if ( ! file_exists( $path ) ) { | |
| 2637 | - @mkdir( $path ); | |
| 2638 | - } | |
| 2639 | - if ( $key ) { | |
| 2640 | - $path = $path . '/' . $key . '.ch'; | |
| 2641 | - } | |
| 2642 | - | |
| 2643 | - return $path; | |
| 2644 | -}*/ | |
| 2645 | - | |
| 2646 | -function learn_press_cache_get( $key, $group, $found = null ) { | |
| 2647 | - //$file = learn_press_cache_path( $group, $key ); | |
| 2648 | - $data = wp_cache_get( $key, $group, $found ); | |
| 2649 | - | |
| 2650 | - /*if ( ! file_exists( $file ) ) { | |
| 2651 | - return false; | |
| 2652 | - }*/ | |
| 2653 | - | |
| 2654 | - /*if ( false === $data ) { | |
| 2655 | - $content = file_get_contents( $file ); | |
| 2656 | - | |
| 2657 | - if ( file_exists( $file ) && $content ) { | |
| 2658 | - try { | |
| 2659 | - $data = unserialize( $content ); | |
| 2660 | - } catch ( Exception $ex ) { | |
| 2661 | - print_r( $content ); | |
| 2662 | - die(); | |
| 2663 | - } | |
| 2664 | - wp_cache_set( $key, $data, $group, $found ); | |
| 2665 | - } | |
| 2666 | - }*/ | |
| 2667 | - | |
| 2668 | - return $data; | |
| 2669 | -} | |
| 2670 | - | |
| 2671 | -function learn_press_cache_set( $key, $data, $group = '', $expire = 0 ) { | |
| 2672 | - //$file = learn_press_cache_path( $group, $key ); | |
| 2673 | - wp_cache_set( $key, $data, $group, $expire ); | |
| 2674 | - | |
| 2675 | - /*if ( ! is_string( $data ) ) { | |
| 2676 | - $data = serialize( $data ); | |
| 2677 | - } | |
| 2678 | - file_put_contents( $file, $data );*/ | |
| 2679 | -} | |
| 2680 | - | |
| 2681 | -function learn_press_cache_replace( $key, $data, $group = '', $expire = 0 ) { | |
| 2682 | - wp_cache_replace( $key, $data, $group, $expire ); | |
| 2683 | -} | |
| 2684 | - | |
| 2685 | -function learn_press_cache_add( $key, $data, $group = '', $expire = 0 ) { | |
| 2686 | - wp_cache_add( $key, $data, $group, $expire ); | |
| 2687 | -} | |
| 2688 | - | |
| 2689 | -if ( ! function_exists( 'learn_press_get_widget_course_object' ) ) { | |
| 2690 | - /** | |
| 2691 | - * Get course object for widget query. | |
| 2692 | - * | |
| 2693 | - * @param $query | |
| 2694 | - * | |
| 2695 | - * @return array | |
| 2696 | - * @deprecated v4.1.6.1 - we will remove on the version 4.1.7 | |
| 2697 | - */ | |
| 2698 | - function learn_press_get_widget_course_object( $query ) { | |
| 2699 | - | |
| 2700 | - _deprecated_function( __FUNCTION__, '4.1.6.1' ); | |
| 2701 | - | |
| 2702 | - global $wpdb; | |
| 2703 | - | |
| 2704 | - $posts = $wpdb->get_results( $query ); | |
| 2705 | - if ( $posts ) { | |
| 2706 | - // get lp courses object from WordPress post | |
| 2707 | - $courses = array_map( 'learn_press_get_lp_course', $posts ); | |
| 2708 | - $courses = array_filter( $courses ); | |
| 2709 | - | |
| 2710 | - } else { | |
| 2711 | - $courses = array(); | |
| 2712 | - } | |
| 2713 | - | |
| 2714 | - return $courses; | |
| 2715 | - } | |
| 2716 | -} | |
| 2717 | - | |
| 2718 | -if ( ! function_exists( 'learn_press_get_lp_course' ) ) { | |
| 2719 | - /** | |
| 2720 | - * Get learn press course from WordPress post object | |
| 2721 | - * | |
| 2722 | - * @param object - reference $post WordPress post object | |
| 2723 | - * | |
| 2724 | - * @return LP_Course course | |
| 2725 | - * @deprecated v4.1.6.1 - we will remove on the version 4.1.7 | |
| 2726 | - */ | |
| 2727 | - function learn_press_get_lp_course( $post ) { | |
| 2728 | - _deprecated_function( __FUNCTION__, '4.1.6.1' ); | |
| 2729 | - | |
| 2730 | - $id = $post->ID; | |
| 2731 | - $course = null; | |
| 2732 | - if ( ! empty( $id ) ) { | |
| 2733 | - // $course = new LP_Course( $id ); | |
| 2734 | - $course = learn_press_get_course( $id ); | |
| 2735 | - } | |
| 2736 | - | |
| 2737 | - return $course; | |
| 2738 | - } | |
| 2739 | -} | |
| 2740 | - | |
| 2741 | -/** | |
| 2742 | - * Get all items are unassigned to any course. | |
| 2743 | - * | |
| 2744 | - * @param string|array $type - Optional. Types of items to get, default is all. | |
| 2745 | - * | |
| 2746 | - * @return array | |
| 2747 | - * @since 3.0.0 | |
| 2748 | - * @deprecated 4.1.4.1 - Will remove on version 4.1.7 | |
| 2749 | - */ | |
| 2750 | -function learn_press_get_unassigned_items( $type = '' ) { | |
| 2751 | - _deprecated_function( __FUNCTION__, '4.1.6.1' ); | |
| 2752 | - | |
| 2753 | - global $wpdb; | |
| 2754 | - | |
| 2755 | - if ( ! $type ) { | |
| 2756 | - $type = learn_press_course_get_support_item_types(); | |
| 2757 | - $type = array_keys( $type ); | |
| 2758 | - } | |
| 2759 | - | |
| 2760 | - settype( $type, 'array' ); | |
| 2761 | - $key = 'items-' . md5( serialize( $type ) ); | |
| 2762 | - | |
| 2763 | - if ( false === ( $items = LP_Object_Cache::get( $key, 'learn-press/unassigned' ) ) ) { | |
| 2764 | - $format = array_fill( 0, sizeof( $type ), '%s' ); | |
| 2765 | - | |
| 2766 | - $query = $wpdb->prepare( | |
| 2767 | - " | |
| 2768 | - SELECT p.ID | |
| 2769 | - FROM {$wpdb->posts} p | |
| 2770 | - WHERE p.post_type IN(" . join( ',', $format ) . ") | |
| 2771 | - AND p.ID NOT IN( | |
| 2772 | - SELECT si.item_id | |
| 2773 | - FROM {$wpdb->learnpress_section_items} si | |
| 2774 | - INNER JOIN {$wpdb->posts} p ON p.ID = si.item_id | |
| 2775 | - WHERE p.post_type IN(" . join( ',', $format ) . ') | |
| 2776 | - ) | |
| 2777 | - AND p.post_status NOT IN(%s, %s) | |
| 2778 | - ', | |
| 2779 | - array_merge( $type, $type, array( 'auto-draft', 'trash' ) ) | |
| 2780 | - ); | |
| 2781 | - | |
| 2782 | - $items = $wpdb->get_col( $query ); | |
| 2783 | - | |
| 2784 | - //LP_Debug::var_dump($query, __FILE__, __LINE__); | |
| 2785 | - | |
| 2786 | - LP_Object_Cache::set( $key, $items, 'learn-press/unassigned' ); | |
| 2787 | - } | |
| 2788 | - | |
| 2789 | - return $items; | |
| 2790 | -} | |
| 2791 | - | |
| 2792 | -/** | |
| 2793 | - * Get all questions are unassigned to any quiz. | |
| 2794 | - * | |
| 2795 | - * @return array | |
| 2796 | - * @since 3.0.0 | |
| 2797 | - * @deprecated 4.1.6.1 - Will remove on version 4.1.7 | |
| 2798 | - */ | |
| 2799 | -function learn_press_get_unassigned_questions() { | |
| 2800 | - _deprecated_function( __FUNCTION__, '4.1.6.1' ); | |
| 2801 | - | |
| 2802 | - global $wpdb; | |
| 2803 | - | |
| 2804 | - if ( false === ( $questions = LP_Object_Cache::get( 'questions', 'learn-press/unassigned' ) ) ) { | |
| 2805 | - $query = $wpdb->prepare( | |
| 2806 | - " | |
| 2807 | - SELECT p.ID | |
| 2808 | - FROM {$wpdb->posts} p | |
| 2809 | - WHERE p.post_type = %s | |
| 2810 | - AND p.ID NOT IN( | |
| 2811 | - SELECT qq.question_id | |
| 2812 | - FROM {$wpdb->learnpress_quiz_questions} qq | |
| 2813 | - INNER JOIN {$wpdb->posts} p ON p.ID = qq.question_id | |
| 2814 | - WHERE p.post_type = %s | |
| 2815 | - ) | |
| 2816 | - AND p.post_status NOT IN(%s, %s) | |
| 2817 | - ", | |
| 2818 | - LP_QUESTION_CPT, | |
| 2819 | - LP_QUESTION_CPT, | |
| 2820 | - 'auto-draft', | |
| 2821 | - 'trash' | |
| 2822 | - ); | |
| 2823 | - | |
| 2824 | - $questions = $wpdb->get_col( $query ); | |
| 2825 | - LP_Object_Cache::set( 'questions', $questions, 'learn-press/unassigned' ); | |
| 2826 | - } | |
| 2827 | - | |
| 2828 | - return $questions; | |
| 2829 | -} | |
| 2830 | - | |
| 2831 | -/** | |
| 2832 | 1951 | * Callback function for sorting to array|object by key|prop priority. |
| 2833 | 1952 | * |
| 2834 | 1953 | * @param array|object $a |
| 2835 | 1954 | * @param array|object $b |
| @@ -2835,10 +1954,11 @@ | ||
| 2835 | 1954 | * @param array|object $b |
| 2836 | 1955 | * |
| 2837 | 1956 | * @return int |
| 2838 | 1957 | * @since 3.0.0 |
| 1958 | + * @deprecated 4.4.5 | |
| 2839 | 1959 | */ |
| 2840 | -function learn_press_sort_list_by_priority_callback( $a, $b ) { | |
| 1960 | +/*function learn_press_sort_list_by_priority_callback( $a, $b ) { | |
| 2841 | 1961 | $a_priority = null; |
| 2842 | 1962 | $b_priority = null; |
| 2843 | 1963 | |
| 2844 | 1964 | if ( is_array( $a ) && array_key_exists( 'priority', $a ) ) { |
| @@ -2865,75 +1985,35 @@ | ||
| 2865 | 1985 | return 0; |
| 2866 | 1986 | } |
| 2867 | 1987 | |
| 2868 | 1988 | return ( $a_priority < $b_priority ) ? - 1 : 1; |
| 2869 | -} | |
| 1989 | +}*/ | |
| 2870 | 1990 | |
| 2871 | 1991 | /** |
| 2872 | 1992 | * Localize date with custom format. |
| 2873 | 1993 | * |
| 2874 | - * @param string $timestamp | |
| 1994 | + * @param int|bool $timestamp | |
| 2875 | 1995 | * @param string $format |
| 2876 | 1996 | * @param bool $gmt |
| 2877 | 1997 | * |
| 2878 | 1998 | * @return string |
| 2879 | 1999 | * @since 3.0.0 |
| 2000 | + * @deprcated 4.2.6 use LP_Datetime format instead | |
| 2880 | 2001 | */ |
| 2881 | -function learn_press_date_i18n( $timestamp = '', $format = '', $gmt = false ) { | |
| 2002 | +function learn_press_date_i18n( $timestamp = 0, string $format = '', bool $gmt = false ): string { | |
| 2882 | 2003 | if ( ! $format ) { |
| 2883 | 2004 | $format = get_option( 'date_format' ); |
| 2884 | 2005 | } |
| 2885 | 2006 | |
| 2886 | - return date_i18n( $format, $timestamp, $gmt ); | |
| 2887 | -} | |
| 2007 | + $date_str = date_i18n( $format, $timestamp, $gmt ); | |
| 2008 | + if ( ! is_string( $date_str ) ) { | |
| 2009 | + $date_str = ''; | |
| 2010 | + } | |
| 2888 | 2011 | |
| 2889 | -function learn_press_date() { | |
| 2890 | - | |
| 2012 | + return $date_str; | |
| 2891 | 2013 | } |
| 2892 | 2014 | |
| 2893 | 2015 | /** |
| 2894 | - * Remove user items. | |
| 2895 | - * | |
| 2896 | - * @param int $item_id | |
| 2897 | - * @param int $course_id | |
| 2898 | - * @param int $user_id | |
| 2899 | - * @param int $keep | |
| 2900 | - * | |
| 2901 | - * @since 3.0.8 | |
| 2902 | - * @deprecated 4.1.6.1 - Will remove on version 4.1.7 | |
| 2903 | - */ | |
| 2904 | -function learn_press_remove_user_items_history( $item_id, $course_id, $user_id, $keep = 10 ) { | |
| 2905 | - _deprecated_function( __FUNCTION__, '4.1.6.1' ); | |
| 2906 | - | |
| 2907 | - $user = learn_press_get_user( $user_id ); | |
| 2908 | - if ( $rows = $user->get_item_archive( $item_id, $course_id ) ) { | |
| 2909 | - | |
| 2910 | - global $wpdb; | |
| 2911 | - | |
| 2912 | - $args = array( $user_id, $item_id, $course_id ); | |
| 2913 | - $query = $wpdb->prepare( | |
| 2914 | - " | |
| 2915 | - DELETE | |
| 2916 | - FROM {$wpdb->learnpress_user_items} | |
| 2917 | - WHERE user_id = %d AND item_id = %d | |
| 2918 | - AND ref_id = %d | |
| 2919 | - ", | |
| 2920 | - $args | |
| 2921 | - ); | |
| 2922 | - | |
| 2923 | - if ( $keep ) { | |
| 2924 | - $user_item_ids = array_keys( $rows ); | |
| 2925 | - $user_item_ids = array_splice( $user_item_ids, 0, $keep ); | |
| 2926 | - $format = array_fill( 0, sizeof( $user_item_ids ), '%d' ); | |
| 2927 | - | |
| 2928 | - $query .= $wpdb->prepare( ' AND user_item_id NOT IN(' . join( ',', $format ) . ')', $user_item_ids ); | |
| 2929 | - } | |
| 2930 | - | |
| 2931 | - $wpdb->query( $query ); | |
| 2932 | - } | |
| 2933 | -} | |
| 2934 | - | |
| 2935 | -/** | |
| 2936 | 2016 | * Get item types of course support for blocking. Default is lp_lesson |
| 2937 | 2017 | * |
| 2938 | 2018 | * @return array |
| 2939 | 2019 | * @since 3.0.0 |
| @@ -2976,38 +2056,8 @@ | ||
| 2976 | 2056 | return $post_type; |
| 2977 | 2057 | } |
| 2978 | 2058 | |
| 2979 | 2059 | /** |
| 2980 | - * Add post type of a post into cache | |
| 2981 | - * | |
| 2982 | - * @param int|array $id | |
| 2983 | - * @param string $type | |
| 2984 | - * | |
| 2985 | - * @since 3.1.0 | |
| 2986 | - */ | |
| 2987 | -function learn_press_cache_add_post_type( $id, $type = '' ) { | |
| 2988 | - if ( false === ( $post_types = LP_Object_Cache::get( 'post-types', 'learn-press' ) ) ) { | |
| 2989 | - $post_types = array(); | |
| 2990 | - } | |
| 2991 | - | |
| 2992 | - if ( func_num_args() == 1 && is_array( $id ) ) { | |
| 2993 | - $post_types = $post_types + $id; | |
| 2994 | - } else { | |
| 2995 | - $post_types[ $id ] = $type; | |
| 2996 | - } | |
| 2997 | - | |
| 2998 | - LP_Object_Cache::set( 'post-types', $post_types, 'learn-press' ); | |
| 2999 | -} | |
| 3000 | - | |
| 3001 | -function learn_press_has_option( $name ) { | |
| 3002 | - global $wpdb; | |
| 3003 | - | |
| 3004 | - $query = $wpdb->prepare( "SELECT option_id FROM {$wpdb->options} WHERE option_name = %s", $name ); | |
| 3005 | - | |
| 3006 | - return $wpdb->get_var( $query ) > 0; | |
| 3007 | -} | |
| 3008 | - | |
| 3009 | -/** | |
| 3010 | 2060 | * Update option to enable shuffle themes for ad. |
| 3011 | 2061 | * |
| 3012 | 2062 | * @since 3.2.1 |
| 3013 | 2063 | */ |
| @@ -3016,139 +2066,37 @@ | ||
| 3016 | 2066 | } |
| 3017 | 2067 | |
| 3018 | 2068 | add_action( 'learn-press/schedule-enable-shuffle-themes', '_learn_press_schedule_enable_shuffle_themes' ); |
| 3019 | 2069 | |
| 3020 | -function learn_press_show_log() { | |
| 3021 | - if ( trim( LP_Request::get( 'show_log' ) ) === md5( AUTH_KEY ) ) { | |
| 3022 | - call_user_func_array( 'learn_press_debug', func_get_args() ); | |
| 3023 | - } | |
| 3024 | -} | |
| 3025 | - | |
| 3026 | 2070 | /** |
| 2071 | + * Return localize script data for admin. | |
| 2072 | + * | |
| 3027 | 2073 | * @return array |
| 3028 | 2074 | * @since 3.2.6 |
| 2075 | + * @version 1.0.1 | |
| 3029 | 2076 | */ |
| 3030 | -function learn_press_global_script_params() { | |
| 3031 | - $js = array( | |
| 3032 | - 'ajax' => admin_url( 'admin-ajax.php' ), | |
| 3033 | - 'plugin_url' => LP()->plugin_url(), | |
| 3034 | - 'siteurl' => home_url(), | |
| 3035 | - 'current_url' => learn_press_get_current_url(), | |
| 3036 | - 'theme' => get_stylesheet(), | |
| 3037 | - '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( | |
| 3038 | 2085 | 'button_ok' => __( 'OK', 'learnpress' ), |
| 3039 | 2086 | 'button_cancel' => __( 'Cancel', 'learnpress' ), |
| 3040 | 2087 | 'button_yes' => __( 'Yes', 'learnpress' ), |
| 3041 | 2088 | 'button_no' => __( 'No', 'learnpress' ), |
| 3042 | 2089 | ), |
| 3043 | - 'root' => esc_url_raw( rest_url() ), | |
| 3044 | - 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 3045 | - ); | |
| 2090 | + 'rest' => esc_url_raw( rest_url() ), | |
| 2091 | + 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 2092 | + 'is_admin' => current_user_can( ADMIN_ROLE ), | |
| 2093 | + ]; | |
| 3046 | 2094 | |
| 3047 | - return $js; | |
| 2095 | + return apply_filters( 'lp/admin/localize/scripts', $localize ); | |
| 3048 | 2096 | } |
| 3049 | 2097 | |
| 3050 | 2098 | /** |
| 3051 | - * Get url for setup cron job on server. | |
| 3052 | - * | |
| 3053 | - * @return string | |
| 3054 | - * @since 3.3.0 | |
| 3055 | - */ | |
| 3056 | -function learn_press_get_cron_url() { | |
| 3057 | - $nonce = get_option( 'learnpress_cron_url_nonce' ); | |
| 3058 | - | |
| 3059 | - if ( ! $nonce ) { | |
| 3060 | - $nonce = md5( microtime( true ) ); | |
| 3061 | - update_option( 'learnpress_cron_url_nonce', $nonce ); | |
| 3062 | - } | |
| 3063 | - $url = add_query_arg( | |
| 3064 | - array( | |
| 3065 | - 'lp-ajax' => 'cron', | |
| 3066 | - 'sid' => $nonce, | |
| 3067 | - ), | |
| 3068 | - get_home_url() | |
| 3069 | - ); | |
| 3070 | - | |
| 3071 | - return $url; | |
| 3072 | -} | |
| 3073 | - | |
| 3074 | -/** | |
| 3075 | - * Get courses expired. | |
| 3076 | - * | |
| 3077 | - * @return array | |
| 3078 | - * @since 3.3.0 | |
| 3079 | - */ | |
| 3080 | -function learn_press_get_expired_courses() { | |
| 3081 | - global $wpdb; | |
| 3082 | - | |
| 3083 | - $query = $wpdb->prepare( | |
| 3084 | - " | |
| 3085 | - SELECT X.* | |
| 3086 | - FROM( | |
| 3087 | - SELECT ui.* | |
| 3088 | - FROM {$wpdb->learnpress_user_items} ui | |
| 3089 | - LEFT JOIN {$wpdb->learnpress_user_items} uix | |
| 3090 | - ON ui.item_id = uix.item_id | |
| 3091 | - AND ui.user_id = uix.user_id | |
| 3092 | - AND ui.user_item_id < uix.user_item_id | |
| 3093 | - WHERE uix.user_item_id IS NULL | |
| 3094 | - ) X | |
| 3095 | - INNER JOIN {$wpdb->users} u ON u.ID = X.user_id | |
| 3096 | - INNER JOIN {$wpdb->posts} p ON p.ID = X.item_id | |
| 3097 | - WHERE X.item_type = %s | |
| 3098 | - AND X.status = %s | |
| 3099 | - #AND expiration_time_gmt <= UTC_TIMESTAMP() | |
| 3100 | - AND expiration_time <= UTC_TIMESTAMP() | |
| 3101 | - LIMIT 0, 10 | |
| 3102 | - ", | |
| 3103 | - LP_COURSE_CPT, | |
| 3104 | - 'enrolled' | |
| 3105 | - ); | |
| 3106 | - | |
| 3107 | -} | |
| 3108 | - | |
| 3109 | -/** | |
| 3110 | - * Add new error log. Support message as an array|object. | |
| 3111 | - * Convert message to string if it is not a string. | |
| 3112 | - * | |
| 3113 | - * @param mixed $value | |
| 3114 | - * | |
| 3115 | - * @since 4.0.0 | |
| 3116 | - */ | |
| 3117 | -function learn_press_error_log( $value ) { | |
| 3118 | - if ( is_array( $value ) || is_object( $value ) ) { | |
| 3119 | - ob_start(); | |
| 3120 | - print_r( $value ); | |
| 3121 | - $value = ob_get_clean(); | |
| 3122 | - } | |
| 3123 | - | |
| 3124 | - error_log( $value ); | |
| 3125 | -} | |
| 3126 | - | |
| 3127 | -/** | |
| 3128 | - * Get status of global course for current user. | |
| 3129 | - * | |
| 3130 | - * @param int $user_id | |
| 3131 | - * @param int $course_id | |
| 3132 | - * | |
| 3133 | - * @return bool|string | |
| 3134 | - * @since 3.3.0 | |
| 3135 | - * @editor tungnx | |
| 3136 | - * @modify 4.1.3 - comment - not use | |
| 3137 | - */ | |
| 3138 | -/*function learn_press_user_course_status( $user_id = 0, $course_id = 0 ) { | |
| 3139 | - if ( ! $user = learn_press_get_user( $user_id ? $user_id : get_current_user_id() ) ) { | |
| 3140 | - return false; | |
| 3141 | - } | |
| 3142 | - | |
| 3143 | - if ( ! $userCourse = $user->get_course_data( $course_id ) ) { | |
| 3144 | - return false; | |
| 3145 | - } | |
| 3146 | - | |
| 3147 | - return $userCourse->get_status(); | |
| 3148 | -}*/ | |
| 3149 | - | |
| 3150 | -/** | |
| 3151 | 2099 | * Return list types of questions that support answer options. |
| 3152 | 2100 | * |
| 3153 | 2101 | * @return array |
| 3154 | 2102 | * @since 3.3.0 |
| @@ -3182,84 +2130,15 @@ | ||
| 3182 | 2130 | return $questions; |
| 3183 | 2131 | } |
| 3184 | 2132 | |
| 3185 | 2133 | /** |
| 3186 | - * Helper function to output html for rendering a 'circle progress bar' | |
| 2134 | + * LP Cookie | |
| 3187 | 2135 | * |
| 3188 | - * @param int $percent | |
| 3189 | - * @param int $width | |
| 3190 | - * @param int $border | |
| 3191 | - * @param string $color | |
| 2136 | + * @param $name | |
| 2137 | + * @param $namespace | |
| 3192 | 2138 | * |
| 3193 | - * @since 3.3.0 | |
| 2139 | + * @return mixed|null | |
| 3194 | 2140 | */ |
| 3195 | -function learn_press_circle_progress_html( $percent = 0, $width = 32, $border = 4, $color = '' ) { | |
| 3196 | - $radius = $width / 2; | |
| 3197 | - $r = ( $width - $border ) / 2; | |
| 3198 | - $circumference = $r * 2 * pi(); | |
| 3199 | - $offset = $circumference - $percent / 100 * $circumference; | |
| 3200 | - | |
| 3201 | - printf( | |
| 3202 | - '<svg class="circle-progress-bar" width="%d" height="%d"> | |
| 3203 | - <circle class="circle-progress-bar__circle" | |
| 3204 | - stroke="%s" | |
| 3205 | - stroke-width="%d" | |
| 3206 | - style="stroke-dasharray:%s %s; stroke-dashoffset:%s;" | |
| 3207 | - fill="transparent" | |
| 3208 | - r="%d" cx="%d" cy="%d"></circle> | |
| 3209 | - </svg>', | |
| 3210 | - $width, | |
| 3211 | - $width, | |
| 3212 | - $color, | |
| 3213 | - $border, | |
| 3214 | - $circumference, | |
| 3215 | - $circumference, | |
| 3216 | - $offset, | |
| 3217 | - $r, | |
| 3218 | - $radius, | |
| 3219 | - $radius | |
| 3220 | - ); | |
| 3221 | -} | |
| 3222 | - | |
| 3223 | -function learn_press_is_page( $page_name ) { | |
| 3224 | - $page_id = learn_press_get_page_id( $page_name ); | |
| 3225 | - | |
| 3226 | - return $page_id && is_page( $page_id ); | |
| 3227 | -} | |
| 3228 | - | |
| 3229 | -/** | |
| 3230 | - * Get end-date from start date with a duration. | |
| 3231 | - * | |
| 3232 | - * @param string|int $duration | |
| 3233 | - * @param string|int $start | |
| 3234 | - * | |
| 3235 | - * @return false|string | |
| 3236 | - * @since 3.x.x | |
| 3237 | - */ | |
| 3238 | -function learn_press_date_end_from( $duration, $start = '' ) { | |
| 3239 | - $format = 'Y-m-d H:i:s'; | |
| 3240 | - | |
| 3241 | - if ( ! $start ) { | |
| 3242 | - $start = time(); | |
| 3243 | - } elseif ( ! is_numeric( $start ) ) { | |
| 3244 | - $start = strtotime( $start ); | |
| 3245 | - } | |
| 3246 | - | |
| 3247 | - // is LP duration format, e.g: 10 weeks | |
| 3248 | - if ( preg_match( '/^[0-9]+ [a-z]+$/', $duration ) ) { | |
| 3249 | - $duration = ( new LP_Duration( $duration ) )->get(); | |
| 3250 | - } elseif ( ! is_numeric( $duration ) ) { | |
| 3251 | - // 10 days 5 hours ... | |
| 3252 | - $duration = strtotime( $duration, 0 ); | |
| 3253 | - } | |
| 3254 | - | |
| 3255 | - return date( $format, $start + $duration ); | |
| 3256 | -} | |
| 3257 | - | |
| 3258 | -function learn_press_date_diff( $from, $to ) { | |
| 3259 | - | |
| 3260 | -} | |
| 3261 | - | |
| 3262 | 2141 | function learn_press_cookie_get( $name, $namespace = 'LP' ) { |
| 3263 | 2142 | if ( $namespace ) { |
| 3264 | 2143 | $cookie = ! empty( $_COOKIE[ $namespace ] ) ? (array) json_decode( LP_Helper::sanitize_params_submitted( stripslashes( $_COOKIE[ $namespace ] ), 'html' ) ) : array(); |
| 3265 | 2144 | } else { |
| @@ -3269,28 +2148,8 @@ | ||
| 3269 | 2148 | return $cookie[ $name ] ?? null; |
| 3270 | 2149 | } |
| 3271 | 2150 | |
| 3272 | 2151 | /** |
| 3273 | - * Get list of levels support in course. | |
| 3274 | - * | |
| 3275 | - * @return array | |
| 3276 | - * @since 3.x.x | |
| 3277 | - * @editor tungnx | |
| 3278 | - * @reason comment - not use | |
| 3279 | - */ | |
| 3280 | -/* | |
| 3281 | -function learn_press_default_course_levels() { | |
| 3282 | - $levels = array( | |
| 3283 | - 'beginner' => __( 'Beginner', 'learnpress' ), | |
| 3284 | - 'intermediate' => __( 'Intermediate', 'learnpress' ), | |
| 3285 | - 'expert' => __( 'Expert', 'learnpress' ), | |
| 3286 | - '' => __( 'All levels', 'learnpress' ), | |
| 3287 | - ); | |
| 3288 | - | |
| 3289 | - return apply_filters( 'learn-press/default-course-levels', $levels ); | |
| 3290 | -}*/ | |
| 3291 | - | |
| 3292 | -/** | |
| 3293 | 2152 | * Get default methods to evaluate course results. |
| 3294 | 2153 | * |
| 3295 | 2154 | * @param string $return - Optional. 'keys' will return keys instead of all. |
| 3296 | 2155 | * |
| @@ -3297,67 +2156,76 @@ | ||
| 3297 | 2156 | * @return array |
| 3298 | 2157 | * @since 3.x.x |
| 3299 | 2158 | */ |
| 3300 | 2159 | function learn_press_course_evaluation_methods( $postid, $return = '', $final_quizz_passing = '' ) { |
| 3301 | - $course_tip = '<span class="learn-press-tip">%s</span>'; | |
| 3302 | - $final_quiz_btn = '<a href="#" class="lp-metabox-get-final-quiz" data-postid="' . $postid . '" data-loading="' . esc_attr__( | |
| 3303 | - 'Loading...', | |
| 3304 | - 'learnpress' | |
| 3305 | - ) . '">' . 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 | + ); | |
| 3306 | 2166 | |
| 3307 | - $course_desc = array( | |
| 2167 | + $evaluations_desc = array( | |
| 3308 | 2168 | 'evaluate_lesson' => sprintf( |
| 3309 | 2169 | '<p>%s<br/>%s</p>', |
| 3310 | - __( 'Evaluate by the number of lessons completed per total number of lessons.', 'learnpress' ), | |
| 3311 | - __( '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' ) | |
| 3312 | 2172 | ), |
| 3313 | 2173 | 'evaluate_final_quiz' => __( |
| 3314 | - '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.', | |
| 3315 | 2175 | 'learnpress' |
| 3316 | 2176 | ), |
| 3317 | 2177 | 'evaluate_quiz' => sprintf( |
| 3318 | 2178 | '<p>%s<br/>%s</p>', |
| 3319 | - __( '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' ), | |
| 3320 | 2180 | __( |
| 3321 | - '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%).', | |
| 3322 | 2182 | 'learnpress' |
| 3323 | 2183 | ) |
| 3324 | 2184 | ), |
| 3325 | 2185 | 'evaluate_questions' => sprintf( |
| 3326 | 2186 | '<p>%s<br/>%s</p>', |
| 3327 | - __( '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' ), | |
| 3328 | 2188 | __( |
| 3329 | - '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%).', | |
| 3330 | 2190 | 'learnpress' |
| 3331 | 2191 | ) |
| 3332 | 2192 | ), |
| 3333 | - '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' ), | |
| 3334 | 2194 | ); |
| 3335 | 2195 | |
| 3336 | 2196 | $methods = apply_filters( |
| 3337 | 2197 | 'learnpress/course-evaluation/methods', |
| 3338 | 2198 | array( |
| 3339 | - 'evaluate_lesson' => __( | |
| 3340 | - 'Evaluate via lessons', | |
| 3341 | - 'learnpress' | |
| 3342 | - ) . learn_press_quick_tip( $course_desc['evaluate_lesson'], false ), | |
| 3343 | - 'evaluate_final_quiz' => __( 'Evaluate via results of the final quiz', 'learnpress' ) . sprintf( | |
| 3344 | - $course_tip, | |
| 3345 | - $course_desc['evaluate_final_quiz'] | |
| 3346 | - ) . $final_quiz_btn . $final_quizz_passing, | |
| 3347 | - 'evaluate_quiz' => __( 'Evaluate via quizzes passed', 'learnpress' ) . sprintf( | |
| 3348 | - $course_tip, | |
| 3349 | - $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 ) | |
| 3350 | 2203 | ), |
| 3351 | - 'evaluate_questions' => __( 'Evaluate via questions', 'learnpress' ) . sprintf( | |
| 3352 | - $course_tip, | |
| 3353 | - $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 | |
| 3354 | 2210 | ), |
| 3355 | - 'evaluate_mark' => __( 'Evaluate via mark', 'learnpress' ) . sprintf( | |
| 3356 | - $course_tip, | |
| 3357 | - $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 ) | |
| 3358 | 2215 | ), |
| 3359 | - ) | |
| 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 | |
| 3360 | 2228 | ); |
| 3361 | 2229 | |
| 3362 | 2230 | return apply_filters( |
| 3363 | 2231 | 'learn-press/course-evaluation-methods', |
| @@ -3366,143 +2234,8 @@ | ||
| 3366 | 2234 | ); |
| 3367 | 2235 | } |
| 3368 | 2236 | |
| 3369 | 2237 | /** |
| 3370 | - * Wrap WP Core function current_time with mysql format. | |
| 3371 | - * | |
| 3372 | - * @param bool $gmt | |
| 3373 | - * | |
| 3374 | - * @return int|string | |
| 3375 | - * @since 4.0.0 | |
| 3376 | - * @editor tungnx | |
| 3377 | - * @modify 4.1.4.1 - comment - not use | |
| 3378 | - */ | |
| 3379 | -/*function learn_press_mysql_time( $gmt = true ) { | |
| 3380 | - return current_time( 'mysql', $gmt ); | |
| 3381 | -}*/ | |
| 3382 | - | |
| 3383 | -/** | |
| 3384 | - * Wrap WP Core function current_time with timestamp format. | |
| 3385 | - * | |
| 3386 | - * @param bool $gmt | |
| 3387 | - * | |
| 3388 | - * @return int|string | |
| 3389 | - * @since 4.0.0 | |
| 3390 | - */ | |
| 3391 | -function learn_press_timestamp( $gmt = true ) { | |
| 3392 | - return current_time( 'timestamp', $gmt ); | |
| 3393 | -} | |
| 3394 | - | |
| 3395 | -/** | |
| 3396 | - * Convert time from GMT to local. | |
| 3397 | - * | |
| 3398 | - * @param string|int|LP_Datetime $gmt_time | |
| 3399 | - * @param string $format | |
| 3400 | - * | |
| 3401 | - * @return false|int|string | |
| 3402 | - * @since 4.0.0 | |
| 3403 | - */ | |
| 3404 | -function learn_press_time_from_gmt( $gmt_time, $format = 'Y-m-d H:i:s' ) { | |
| 3405 | - if ( is_string( $gmt_time ) ) { | |
| 3406 | - $gmt_time = strtotime( $gmt_time ); | |
| 3407 | - } elseif ( $gmt_time instanceof LP_Datetime ) { | |
| 3408 | - $gmt_time = strtotime( $gmt_time . '' ); | |
| 3409 | - } | |
| 3410 | - | |
| 3411 | - $current_time = $gmt_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; | |
| 3412 | - | |
| 3413 | - if ( $format ) { | |
| 3414 | - return date( $format, $current_time ); | |
| 3415 | - } | |
| 3416 | - | |
| 3417 | - return $current_time; | |
| 3418 | -} | |
| 3419 | - | |
| 3420 | -/** | |
| 3421 | - * Count all users has enrolled courses of an instructor. | |
| 3422 | - * | |
| 3423 | - * @param int $instructor_id . Author of course | |
| 3424 | - * | |
| 3425 | - SELECT COUNT(DISTINCT (user_id)) AS total | |
| 3426 | - FROM wp_learnpress_user_items | |
| 3427 | - WHERE 1 = 1 | |
| 3428 | - AND item_type = 'lp_course' | |
| 3429 | - AND item_id IN ( | |
| 3430 | - SELECT ID | |
| 3431 | - FROM wp_posts | |
| 3432 | - WHERE post_author = 1 | |
| 3433 | - AND post_type = 'lp_course' | |
| 3434 | - AND post_status = 'publish' | |
| 3435 | - ); | |
| 3436 | - * | |
| 3437 | - * @return int | |
| 3438 | - * @since 4.0.0 | |
| 3439 | - * @editor tungnx | |
| 3440 | - * @version 1.0.1 | |
| 3441 | - * @deprecated 4.1.6 replace to "get_statistic_info" function | |
| 3442 | - */ | |
| 3443 | -//function learn_press_count_instructor_users( int $instructor_id = 0 ): int { | |
| 3444 | -// try { | |
| 3445 | -// $filter_course = new LP_Course_Filter(); | |
| 3446 | -// $filter_course->only_fields = array( 'ID' ); | |
| 3447 | -// $filter_course->post_author = $instructor_id; | |
| 3448 | -// $filter_course->post_status = 'publish'; | |
| 3449 | -// $filter_course->return_string_query = true; | |
| 3450 | -// $query_courses_str = LP_Course_DB::getInstance()->get_courses( $filter_course ); | |
| 3451 | -// | |
| 3452 | -// $filter = new LP_User_Items_Filter(); | |
| 3453 | -// $filter->only_fields = array( 'DISTINCT (ui.user_id)' ); | |
| 3454 | -// $filter->field_count = 'DISTINCT (ui.user_id)'; | |
| 3455 | -// $filter->where[] = "AND item_id IN ({$query_courses_str})"; | |
| 3456 | -// $filter->query_count = true; | |
| 3457 | -// | |
| 3458 | -// return LP_User_Item_Course::get_user_courses( $filter ); | |
| 3459 | -// //return LP_User_Items_DB::getInstance()->get_user_courses( $filter ); | |
| 3460 | -// } catch ( Throwable $e ) { | |
| 3461 | -// error_log( __FUNCTION__ . ': ' . $e->getMessage() ); | |
| 3462 | -// | |
| 3463 | -// return 0; | |
| 3464 | -// } | |
| 3465 | -// | |
| 3466 | -// /*$curd = new LP_User_CURD(); | |
| 3467 | -// $own_courses = $curd->query_own_courses( $instructor_id ); | |
| 3468 | -// $course_ids = $own_courses->get_items();*/ | |
| 3469 | -// | |
| 3470 | -// /* | |
| 3471 | -// global $wpdb; | |
| 3472 | -// $filter = new LP_Course_Filter(); | |
| 3473 | -// $filter->post_author = $instructor_id; | |
| 3474 | -// $filter->limit = -1; | |
| 3475 | -// $courses = LP_Course::get_courses( $filter ); | |
| 3476 | -// $course_ids = LP_Course::get_course_ids( $courses ); | |
| 3477 | -// | |
| 3478 | -// if ( ! empty( $course_ids ) ) { | |
| 3479 | -// $query = $wpdb->prepare( | |
| 3480 | -// " | |
| 3481 | -// SELECT COUNT(user_id) | |
| 3482 | -// FROM ( | |
| 3483 | -// SELECT item_id, user_id | |
| 3484 | -// FROM {$wpdb->learnpress_user_items} | |
| 3485 | -// WHERE item_type = %s | |
| 3486 | -// GROUP BY item_id, user_id | |
| 3487 | -// HAVING item_id IN(" . join( ',', $course_ids ) . ') | |
| 3488 | -// ) X | |
| 3489 | -// GROUP BY item_id | |
| 3490 | -// ', | |
| 3491 | -// LP_COURSE_CPT | |
| 3492 | -// ); | |
| 3493 | -// | |
| 3494 | -// $rows = $wpdb->get_col( $query ); | |
| 3495 | -// | |
| 3496 | -// if ( $rows ) { | |
| 3497 | -// return array_sum( $rows ); | |
| 3498 | -// } | |
| 3499 | -// } | |
| 3500 | -// | |
| 3501 | -// return 0;*/ | |
| 3502 | -//} | |
| 3503 | - | |
| 3504 | -/** | |
| 3505 | 2238 | * Get max retrying quiz allowed. |
| 3506 | 2239 | * |
| 3507 | 2240 | * @param int $quiz_id |
| 3508 | 2241 | * @param int $course_id |
| @@ -3514,34 +2247,9 @@ | ||
| 3514 | 2247 | return apply_filters( 'learn-press/max-retry-quiz-allowed', 1, $quiz_id, $course_id ); |
| 3515 | 2248 | } |
| 3516 | 2249 | |
| 3517 | 2250 | /** |
| 3518 | - * Get max retrying course allowed. | |
| 3519 | - * | |
| 3520 | - * @param int $course_id | |
| 3521 | - * | |
| 3522 | - * @return int | |
| 3523 | - * @since 4.0.0 | |
| 3524 | - */ | |
| 3525 | -function learn_press_get_course_max_retrying( $course_id ) { | |
| 3526 | - return apply_filters( 'learn-press/max-retry-course-allowed', 1, $course_id ); | |
| 3527 | -} | |
| 3528 | - | |
| 3529 | -/** | |
| 3530 | 2251 | * Get slug for status of course/lesson/quiz if user |
| 3531 | - * completed/finished and graduation is failed. | |
| 3532 | - * | |
| 3533 | - * @param string $type | |
| 3534 | - * | |
| 3535 | - * @return string | |
| 3536 | - * @since 4.0.0 | |
| 3537 | - */ | |
| 3538 | -function learn_press_user_item_failed_slug( $type = '' ) { | |
| 3539 | - return apply_filters( 'learn-press/user-item-failed-slug', 'failed', $type ); | |
| 3540 | -} | |
| 3541 | - | |
| 3542 | -/** | |
| 3543 | - * Get slug for status of course/lesson/quiz if user | |
| 3544 | 2252 | * completed/finished and graduation is passed. |
| 3545 | 2253 | * |
| 3546 | 2254 | * @param string $type |
| 3547 | 2255 | * |
| @@ -3547,21 +2255,8 @@ | ||
| 3547 | 2255 | * |
| 3548 | 2256 | * @return string |
| 3549 | 2257 | * @since 4.0.0 |
| 3550 | 2258 | */ |
| 3551 | -function learn_press_user_item_passed_slug( $type = '' ) { | |
| 3552 | - return apply_filters( 'learn-press/user-item-passed-slug', 'passed', $type ); | |
| 3553 | -} | |
| 3554 | - | |
| 3555 | -/** | |
| 3556 | - * Get slug for status of course/lesson/quiz if user | |
| 3557 | - * completed/finished and graduation is passed. | |
| 3558 | - * | |
| 3559 | - * @param string $type | |
| 3560 | - * | |
| 3561 | - * @return string | |
| 3562 | - * @since 4.0.0 | |
| 3563 | - */ | |
| 3564 | 2259 | function learn_press_user_item_in_progress_slug( $type = '' ) { |
| 3565 | 2260 | return apply_filters( 'learn-press/user-item-in-progress-slug', 'in-progress', $type ); |
| 3566 | 2261 | } |
| 3567 | 2262 | |
| @@ -3590,29 +2285,9 @@ | ||
| 3590 | 2285 | |
| 3591 | 2286 | /** |
| 3592 | 2287 | * @return array |
| 3593 | 2288 | * @since 4.0.0 |
| 3594 | - * @editor tungnx | |
| 3595 | - * @modify 4.1.3 - comment - not use | |
| 3596 | 2289 | */ |
| 3597 | -function learn_press_course_enrolled_slugs(): array { | |
| 3598 | - _deprecated_function( __FUNCTION__, '4.1.3' ); | |
| 3599 | - return apply_filters( | |
| 3600 | - 'learn-press/course-enrolled-slugs', | |
| 3601 | - array( | |
| 3602 | - learn_press_user_item_passed_slug(), | |
| 3603 | - learn_press_user_item_failed_slug(), | |
| 3604 | - 'in-progress', | |
| 3605 | - 'enrolled', | |
| 3606 | - 'finished', // deprecated | |
| 3607 | - ) | |
| 3608 | - ); | |
| 3609 | -} | |
| 3610 | - | |
| 3611 | -/** | |
| 3612 | - * @return array | |
| 3613 | - * @since 4.0.0 | |
| 3614 | - */ | |
| 3615 | 2290 | function lp_item_course_class( $class = array() ) { |
| 3616 | 2291 | $classes = array_merge( |
| 3617 | 2292 | $class, |
| 3618 | 2293 | array( 'learn-press-courses' ) |
| @@ -3621,82 +2296,24 @@ | ||
| 3621 | 2296 | } |
| 3622 | 2297 | |
| 3623 | 2298 | //require_once dirname( __FILE__ ) . '/lp-custom-hooks.php'; |
| 3624 | 2299 | |
| 3625 | - | |
| 3626 | -/** | |
| 3627 | - * Disable auto update | |
| 3628 | - * | |
| 3629 | - * @param $update | |
| 3630 | - * @param $item | |
| 3631 | - * | |
| 3632 | - * @return false | |
| 3633 | - * @author hungkv | |
| 3634 | - */ | |
| 3635 | -/*function learnpress_disable_auto_update( $update, $item ) { | |
| 3636 | - $plugins = array( // Plugins to auto-update | |
| 3637 | - 'learnpress', | |
| 3638 | - ); | |
| 3639 | - // Auto-update specified plugins | |
| 3640 | - if ( in_array( $item->slug, $plugins ) ) { | |
| 3641 | - return false; | |
| 3642 | - } | |
| 3643 | -} | |
| 3644 | -add_filter( 'auto_update_plugin', 'learnpress_disable_auto_update', 10, 2 );*/ | |
| 3645 | - | |
| 3646 | -add_action( | |
| 2300 | +// Notify update message for LearnPress plugin | |
| 2301 | +/*add_action( | |
| 3647 | 2302 | 'in_plugin_update_message-learnpress/learnpress.php', |
| 3648 | 2303 | function ( $plugin_data ) { |
| 3649 | - version_update_warning( LEARNPRESS_VERSION, $plugin_data['new_version'] ); | |
| 3650 | - } | |
| 3651 | -); | |
| 3652 | -/** | |
| 3653 | - * Custom message warning have new version | |
| 3654 | - * | |
| 3655 | - * @param $current_version | |
| 3656 | - * @param $new_version | |
| 3657 | - * @author hungkv | |
| 3658 | - */ | |
| 3659 | -function version_update_warning( $current_version, $new_version ) { | |
| 3660 | - $current_version_minor_part = explode( '.', $current_version )[1]; | |
| 3661 | - $new_version_minor_part = explode( '.', $new_version )[1]; | |
| 3662 | - if ( $current_version_minor_part === $new_version_minor_part ) { | |
| 3663 | - return; | |
| 3664 | - } | |
| 3665 | - | |
| 3666 | - $info = get_plugin_data( LP_PLUGIN_FILE ); | |
| 3667 | - ?> | |
| 3668 | - <hr class="lp-update--warning__separator"/> | |
| 3669 | - <div class="lp-update--warning"> | |
| 3670 | - <div> | |
| 3671 | - <div class="lp-update-warning__title"> | |
| 3672 | - <?php echo esc_html__( 'Heads up, Please backup before upgrade!', 'learnpress' ); ?> | |
| 3673 | - </div> | |
| 3674 | - <div class="lp-update-warning__message"> | |
| 3675 | - <?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' ); ?> | |
| 3676 | - <?php echo esc_html__( 'Learners require WordPress version ' . $info['Requires at least'] . ' or higher.', 'learnpress' ); ?> | |
| 3677 | - </div> | |
| 3678 | - </div> | |
| 3679 | - </div> | |
| 3680 | - | |
| 3681 | - <?php | |
| 3682 | -} | |
| 3683 | - | |
| 3684 | -// If profile content don't have shortcode profile. | |
| 3685 | -function lp_add_shortcode_profile() { | |
| 3686 | - global $post; | |
| 3687 | - | |
| 3688 | - if ( learn_press_is_profile() && is_object( $post ) ) { | |
| 3689 | - if ( ! has_shortcode( $post->post_content, 'learn_press_profile' ) ) { | |
| 3690 | - $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; | |
| 3691 | 2306 | } |
| 3692 | 2307 | |
| 3693 | - 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 | + ); | |
| 3694 | 2313 | } |
| 3695 | -} | |
| 2314 | +);*/ | |
| 3696 | 2315 | |
| 3697 | -add_action( 'template_redirect', 'lp_add_shortcode_profile' ); | |
| 3698 | - | |
| 3699 | 2316 | /** |
| 3700 | 2317 | * If Elementor Pro set Theme builder type "Archive", will not show content on page "Archive course" |
| 3701 | 2318 | * |
| 3702 | 2319 | * @editor tungnx |
| @@ -3706,9 +2323,9 @@ | ||
| 3706 | 2323 | * @version 1.0.1 |
| 3707 | 2324 | */ |
| 3708 | 2325 | add_filter( |
| 3709 | 2326 | 'elementor/theme/get_location_templates/template_id', |
| 3710 | - function( $theme_template_id ) { | |
| 2327 | + function ( $theme_template_id ) { | |
| 3711 | 2328 | $elementor_template_type = get_post_meta( $theme_template_id, '_elementor_template_type', true ); |
| 3712 | 2329 | |
| 3713 | 2330 | if ( in_array( $elementor_template_type, array( 'archive' ) ) ) { |
| 3714 | 2331 | if ( LP_PAGE_COURSES === LP_Page_Controller::page_current() && class_exists( 'ElementorPro\Modules\ThemeBuilder\Conditions\Archive' ) ) { |