PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/admin/lp-admin-functions.php +111 -532 4.1.6.94.4.8 View file →
@@ -11,8 +11,25 @@
11 11 * Prevent loading this file directly
12 12 */
13 13 defined( 'ABSPATH' ) || exit();
14 14
15 +/**
16 + * Check whether MCP capabilities are available in current WordPress runtime.
17 + *
18 + * @return bool
19 + */
20 +function learn_press_is_mcp_available(): bool {
21 + $wp_version = (string) get_bloginfo( 'version' );
22 +
23 + if ( version_compare( $wp_version, '6.9', '<' ) ) {
24 + return false;
25 + }
26 +
27 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
28 +
29 + return is_plugin_active( 'mcp-adapter/mcp-adapter.php' );
30 +}
31 +
15 32 if ( ! function_exists( 'learn_press_add_row_action_link' ) ) {
16 33 /**
17 34 * Setup action links to the admin course, lesson, quiz, question. e.g: Add Duplicate link, hide View link for lesson, quiz so on.
18 35 *
@@ -47,9 +64,9 @@
47 64 $link['class'],
48 65 $link['data'],
49 66 $link['title']
50 67 ) . '</li>';
51 - };
68 + }
52 69
53 70 $drop_down[] = '</ul>';
54 71 $link = sprintf(
55 72 '<div class="lpr-row-actions"><a href="%s">%s</a>%s</div>',
@@ -105,30 +122,9 @@
105 122 add_filter( 'post_row_actions', 'learn_press_add_row_action_link' );
106 123 add_filter( 'page_row_actions', 'learn_press_add_row_action_link' );
107 124 }
108 125
109 -if ( ! function_exists( 'learn_press_settings_tabs_array' ) ) {
110 - /**
111 - * Default admin settings pages
112 - *
113 - * @return mixed
114 - * @depecated 4.1.6.4
115 - */
116 - /*function learn_press_settings_tabs_array() {
117 - $tabs = array(
118 - 'general' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-general.php',
119 - 'courses' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-courses.php',
120 - 'profile' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-profile.php',
121 - 'payments' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-payments.php',
122 - 'emails' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-emails.php',
123 - 'advanced' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-advanced.php',
124 - );
125 -
126 - return apply_filters( 'learn-press/admin/settings-tabs-array', $tabs );
127 - }*/
128 -}
129 -
130 -function learn_press_is_hidden_post_box( $id, $user_id = 0 ) {
126 +/*function learn_press_is_hidden_post_box( $id, $user_id = 0 ) {
131 127 if ( ! $user_id ) {
132 128 $user_id = get_current_user_id();
133 129 }
134 130
@@ -137,88 +133,11 @@
137 133 $data = array();
138 134 }
139 135
140 136 return false !== array_search( $id, $data );
141 -}
137 +}*/
142 138
143 139 /**
144 - * Get html view path for admin to display
145 - *
146 - * @param $name
147 - * @param $plugin_file
148 - *
149 - * @return mixed
150 - */
151 -function learn_press_get_admin_view( $name, $plugin_file = null ) {
152 - if ( ! preg_match( '/\.(html|php)$/', $name ) ) {
153 - $name .= '.php';
154 - }
155 - if ( $plugin_file ) {
156 - $view = dirname( $plugin_file ) . '/inc/admin/views/' . $name;
157 - } else {
158 - $view = LP()->plugin_path( 'inc/admin/views/' . $name );
159 - }
160 -
161 - return apply_filters( 'learn_press_admin_view', $view, $name );
162 -}
163 -
164 -function learn_press_admin_view_content( $name, $args = array() ) {
165 - return learn_press_admin_view( $name, $args, false, true );
166 -}
167 -
168 -/**
169 - * Find a full path of a view and display the content in admin
170 - *
171 - * @param $name
172 - * @param array $args
173 - * @param bool|false $include_once
174 - * @param bool
175 - *
176 - * @return bool
177 - */
178 -function learn_press_admin_view( $name, $args = array(), $include_once = false, $return = false ) {
179 - $view = learn_press_get_admin_view( $name, ! empty( $args['plugin_file'] ) ? $args['plugin_file'] : null );
180 -
181 - if ( file_exists( $view ) ) {
182 -
183 - ob_start();
184 -
185 - is_array( $args ) && extract( $args );
186 -
187 - do_action( 'learn_press_before_display_admin_view', $name, $args );
188 -
189 - if ( $include_once ) {
190 - include_once $view;
191 - } else {
192 - include $view;
193 - }
194 -
195 - do_action( 'learn_press_after_display_admin_view', $name, $args );
196 - $output = ob_get_clean();
197 -
198 - if ( ! $return ) {
199 - learn_press_echo_vuejs_write_on_php( $output );
200 - }
201 -
202 - return $return ? $output : true;
203 - }
204 -
205 - return false;
206 -}
207 -
208 -/**
209 - * Vue write php has script, so when sanitize will error, so use code is mask pass check sanitize, esc
210 - *
211 - * @param $content
212 - *
213 - * @return void
214 - * @since 4.1.6.9
215 - */
216 -function learn_press_echo_vuejs_write_on_php( $content ) {
217 - echo ( $content );
218 -}
219 -
220 -/**
221 140 * List all pages as a dropdown with "Add New Page" option
222 141 *
223 142 * @param $name
224 143 * @param bool|false $selected
@@ -229,11 +148,9 @@
229 148 function learn_press_pages_dropdown( $name, $selected = false, $args = array() ) {
230 149 $id = null;
231 150 $class = null;
232 151 $css = null;
233 - $before = array(
234 - 'add_new_page' => __( '[ Add a new page ]', 'learnpress' ),
235 - );
152 + $before = [];
236 153 $after = null;
237 154 $echo = true;
238 155 $allow_create = true;
239 156
@@ -246,9 +163,9 @@
246 163 if ( empty( $id ) ) {
247 164 $id = $name;
248 165 }
249 166
250 - $class .= 'list-pages lp-list-pages learn-press-select2';
167 + $class .= 'list-pages lp-list-pages lp-tom-select';
251 168
252 169 $args = array(
253 170 'name' => $name,
254 171 'id' => $id,
@@ -299,9 +216,9 @@
299 216
300 217 if ( $allow_create ) {
301 218 ob_start(); ?>
302 219
303 - <?php echo esc_html( _x( 'or', 'drop down pages', 'learnpress' ) ); ?>
220 + <?php echo esc_html( _x( 'or', 'dropdown pages', 'learnpress' ) ); ?>
304 221
305 222 <button class="button button-quick-add-page" data-id="<?php echo esc_attr( $id ); ?>" type="button">
306 223 <?php esc_html_e( 'Create new', 'learnpress' ); ?>
307 224 </button>
@@ -321,8 +238,10 @@
321 238 &#124;
322 239 <a class="view-page" href="<?php echo get_permalink( $selected ); ?>"
323 240 target="_blank"><?php esc_html_e( 'View page', 'learnpress' ); ?></a>
324 241 </p>
242 + <!-- Not use input on here, will be not save value -->
243 + <div class="field_name" name="<?php echo esc_attr( $id ); ?>"></div>
325 244
326 245 <?php
327 246 $output .= ob_get_clean();
328 247 } else {
@@ -333,9 +252,10 @@
333 252
334 253 if ( $echo ) {
335 254 $allowed_html = wp_kses_allowed_html( 'post' );
336 255 $allowed_html['select'] = [
337 - 'name' => [],
256 + 'name' => [],
257 + 'class' => [],
338 258 ];
339 259 $allowed_html['option'] = [
340 260 'value' => [],
341 261 'selected' => [],
@@ -343,9 +263,15 @@
343 263 ];
344 264 $allowed_html['input'] = [
345 265 'type' => [],
346 266 'placeholder' => [],
267 + 'name' => [],
268 + 'class' => [],
347 269 ];
270 + $allowed_html['div'] = [
271 + 'name' => [],
272 + 'class' => [],
273 + ];
348 274
349 275 echo wp_kses( $output, $allowed_html );
350 276 }
351 277
@@ -462,10 +388,11 @@
462 388 *
463 389 * @param array $args
464 390 *
465 391 * @return string
392 + * @deprecated 4.2.6.9.3
466 393 */
467 -function learn_press_email_formats_dropdown( $args = array() ) {
394 +/*function learn_press_email_formats_dropdown( $args = array() ) {
468 395 $args = wp_parse_args(
469 396 $args,
470 397 array(
471 398 'name' => 'learn-press-dropdown-email-formats',
@@ -514,9 +441,9 @@
514 441 echo wp_kses_post( $output );
515 442 }
516 443
517 444 return $output;
518 -}
445 +}*/
519 446
520 447 /**
521 448 * Return array of email formats.
522 449 *
@@ -549,195 +476,8 @@
549 476 return $content;
550 477 }
551 478
552 479 /**
553 - * Get list of themes that support LearnPress.
554 - *
555 - * @return mixed
556 - */
557 -function learn_press_get_education_themes() {
558 -
559 - // New theme can be added here
560 - return apply_filters(
561 - 'learn-press/education-themes',
562 - array(
563 - '23451388' => 'kindergarten',
564 - '22773871' => 'ivy-school',
565 - '20370918' => 'wordpress-lms',
566 - '14058034' => 'eduma',
567 - '17097658' => 'coach',
568 - '11797847' => 'lms',
569 - )
570 - );
571 -}
572 -
573 -if ( ! function_exists( 'learn_press_get_item_referral' ) ) {
574 - /**
575 - * Set item link referral.
576 - *
577 - * @param int|string $item_id
578 - *
579 - * @return string
580 - */
581 - function learn_press_get_item_referral( $item_id ) {
582 - $affiliate_links = array(
583 - 14058034 => 'https://1.envato.market/G5Ook', // Eduma
584 - 22773871 => 'https://1.envato.market/akrzZ', // Ivy-school
585 - 20370918 => 'https://1.envato.market/13Zkd', // Course Builder LMS
586 - 17097658 => 'https://1.envato.market/Xq2Ra', // Coach
587 - 23451388 => 'https://1.envato.market/oWov9', // StarKid
588 - 11797847 => 'https://1.envato.market/zknvM', // Epsilon
589 - 13321455 => 'https://1.envato.market/G5Rkk', // Sailing
590 - 19029758 => 'https://1.envato.market/mAYdZ', // Travel Tour Booking
591 - 12124219 => 'https://1.envato.market/qJYdO', // Resca
592 - 18828322 => 'https://1.envato.market/VW2K3', // LuxStay
593 - 8254575 => 'https://1.envato.market/xWYdO', // Squareroot
594 - 13782850 => 'https://1.envato.market/Qo71z',
595 - 14025178 => 'https://1.envato.market/9R0oQ',
596 - 17739078 => 'https://1.envato.market/jkYda',
597 - 16210005 => 'https://1.envato.market/56oJD',
598 - 11733602 => 'https://1.envato.market/keYdv',
599 - 13513609 => 'https://1.envato.market/aq7dQ',
600 - 19693761 => 'https://1.envato.market/A976D',
601 - 12532973 => 'https://1.envato.market/Ge79B',
602 - 19305239 => 'https://1.envato.market/10JAB',
603 - 23716060 => 'https://1.envato.market/ZO7WW',
604 - 20466233 => 'https://1.envato.market/gjYd0',
605 - 21070438 => 'https://1.envato.market/xPz65',
606 - 20794183 => 'https://1.envato.market/o1YdY',
607 - 20979215 => 'https://1.envato.market/03R5V',
608 - 11151269 => 'https://1.envato.market/Br7L4',
609 - 8905392 => 'https://1.envato.market/zEYd7',
610 - 23168294 => 'https://1.envato.market/Wn7on',
611 - 17719422 => 'https://1.envato.market/0WVaL',
612 - 21680592 => 'https://1.envato.market/qqO6y',
613 - );
614 -
615 - return isset( $affiliate_links[ $item_id ] ) ? $affiliate_links[ $item_id ] : 'https://themeforest.net/user/thimpress/portfolio/';
616 - }
617 -}
618 -
619 -/**
620 - * Display advertisement about related themes at the bottom of admin pages.
621 - *
622 - * @updated 12 Nov 2018 - Enable/Disable shuffle the list of themes
623 - *
624 - * @return bool|void
625 - */
626 -function learn_press_footer_advertisement() {
627 - $admin_post_type = array(
628 - 'lp_course',
629 - 'lp_lesson',
630 - 'lp_quiz',
631 - 'lp_question',
632 - 'lp_order',
633 - );
634 -
635 - // And our admin pages
636 - $pages = array(
637 - 'learnpress_page_learn-press-statistics',
638 - 'learnpress_page_learn-press-settings',
639 - 'learnpress_page_learn-press-tools',
640 -
641 - );
642 -
643 - $screen = get_current_screen();
644 -
645 - if ( ! $screen ) {
646 - return;
647 - }
648 -
649 - if ( ! ( ( in_array(
650 - $screen->post_type,
651 - $admin_post_type
652 - ) && $screen->base === 'edit' ) || ( in_array( $screen->id, $pages ) ) ) ) {
653 - return;
654 - }
655 -
656 - $theme_ids = learn_press_get_education_themes();
657 - $current_theme = wp_get_theme();
658 -
659 - $include = array_keys( $theme_ids );
660 -
661 - $key = array_search( $current_theme->name, $theme_ids, true );
662 -
663 - if ( false !== $key ) {
664 - unset( $theme_ids[ $key ] );
665 - }
666 -
667 - $list_themes = (array) LP_Plugins_Helper::get_related_themes(
668 - 'education',
669 - array(
670 - 'include' => $include,
671 - )
672 - );
673 -
674 - if ( empty( $list_themes ) ) {
675 - return;
676 - }
677 -
678 - // Disable shuffle themes for 3 days
679 - $shuffle = LP_Settings::instance()->get( 'ad_shuffle_themes' );
680 -
681 - if ( ! $shuffle ) {
682 - if ( wp_next_scheduled( 'learn-press/schedule-enable-shuffle-themes' ) === false ) {
683 - wp_schedule_single_event( time() + 3 * DAY_IN_SECONDS, 'learn-press/schedule-enable-shuffle-themes' );
684 - }
685 -
686 - // Keep the first theme always in #1 and shuffle other themes
687 - $first_theme = array_shift( $list_themes );
688 - shuffle( $list_themes );
689 - array_unshift( $list_themes, $first_theme );
690 - } else {
691 - shuffle( $list_themes );
692 - }
693 - ?>
694 -
695 - <div id="learn-press-advertisement" class="learn-press-advertisement-slider">
696 - <?php
697 - foreach ( $list_themes as $theme ) {
698 - if ( empty( $theme['url'] ) ) {
699 - continue;
700 - }
701 -
702 - $url = learn_press_get_item_referral( $theme['id'] );
703 - $full_description = learn_press_trim_content( $theme['description'] );
704 - $short_description = learn_press_trim_content( $theme['description'], 75 );
705 - $url_demo = $theme['attributes'][4]['value'];
706 - ?>
707 -
708 - <div id="thimpress-<?php echo esc_attr( $theme['id'] ); ?>" class="slide-item">
709 - <div class="slide-thumbnail">
710 - <a href="<?php echo esc_url_raw( $url ); ?>">
711 - <img src="<?php echo esc_url_raw( $theme['previews']['landscape_preview']['landscape_url'] ); ?>"/>
712 - </a>
713 - </div>
714 -
715 - <div class="slide-detail">
716 - <h2><a href="<?php echo esc_url_raw( $url ); ?>"><?php echo esc_html( $theme['name'] ); ?></a></h2>
717 - <p class="slide-description description-full">
718 - <?php echo wp_kses_post( $full_description ); ?>
719 - </p>
720 -
721 - <p class="slide-description description-short">
722 - <?php echo wp_kses_post( $short_description ); ?>
723 - </p>
724 -
725 - <p class="slide-controls">
726 - <a href="<?php echo esc_url_raw( $url ); ?>" class="button button-primary"
727 - target="_blank"><?php esc_html_e( 'Get it now', 'learnpress' ); ?></a>
728 - <a href="<?php echo esc_url_raw( $url_demo ); ?>" class="button"
729 - target="_blank"><?php esc_html_e( 'View Demo', 'learnpress' ); ?></a>
730 - </p>
731 - </div>
732 - </div>
733 -
734 - <?php } ?>
735 - </div>
736 - <?php
737 -}
738 -
739 -/**
740 480 * Count number of orders between to dates
741 481 *
742 482 * @param string
743 483 * @param int
@@ -837,10 +577,11 @@
837 577 *
838 578 * @param string
839 579 *
840 580 * @return int
581 + * @deprecated 4.2.6.9.3
841 582 */
842 -function learn_press_get_courses_by_price( $fee ) {
583 +/*function learn_press_get_courses_by_price( $fee ) {
843 584 global $wpdb;
844 585
845 586 $user_id = get_current_user_id();
846 587
@@ -863,9 +604,9 @@
863 604 )
864 605 );
865 606
866 607 return $courses;
867 -}
608 +}*/
868 609
869 610 /**
870 611 * Get data about students to render in chart
871 612 *
@@ -873,15 +614,16 @@
873 614 * @param null $by
874 615 * @param float $time_ago
875 616 *
876 617 * @return array
618 + * @deprecated 4.2.6.9.3
877 619 */
878 -function learn_press_get_chart_students( $from = null, $by = null, $time_ago = 0 ) {
620 +/*function learn_press_get_chart_students( $from = null, $by = null, $time_ago = 0 ) {
879 621 $labels = array();
880 622 $datasets = array();
881 623
882 624 if ( is_null( $from ) ) {
883 - $from = current_time( 'mysql' );
625 + $from = current_time( 'mysql', 1 );
884 626 }
885 627
886 628 if ( is_null( $by ) ) {
887 629 $by = 'days';
@@ -915,9 +657,9 @@
915 657 return array(
916 658 'labels' => $labels,
917 659 'datasets' => $datasets,
918 660 );
919 -}
661 +}*/
920 662
921 663 /**
922 664 * Get data about students to render in chart
923 665 *
@@ -925,10 +667,11 @@
925 667 * @param null $by
926 668 * @param float $time_ago
927 669 *
928 670 * @return array
671 + * @deprecated 4.2.6.9.3
929 672 */
930 -function learn_press_get_chart_users( $from = null, $by = null, $time_ago = 0 ) {
673 +/*function learn_press_get_chart_users( $from = null, $by = null, $time_ago = 0 ) {
931 674 global $wpdb;
932 675
933 676 $labels = array();
934 677 $datasets = array();
@@ -933,9 +676,9 @@
933 676 $labels = array();
934 677 $datasets = array();
935 678
936 679 if ( is_null( $from ) ) {
937 - $from = current_time( 'mysql' );
680 + $from = current_time( 'mysql', 1 );
938 681 }
939 682
940 683 if ( is_null( $by ) ) {
941 684 $by = 'days';
@@ -1066,9 +809,9 @@
1066 809 'labels' => $labels,
1067 810 'datasets' => $datasets,
1068 811 'sql' => $query,
1069 812 );
1070 -}
813 +}*/
1071 814
1072 815
1073 816 /**
1074 817 * Get data about students to render in chart
@@ -1077,10 +820,11 @@
1077 820 * @param null $by
1078 821 * @param float $time_ago
1079 822 *
1080 823 * @return array
824 + * @deprecated 4.2.6.9.3
1081 825 */
1082 -function learn_press_get_chart_courses( $from = null, $by = null, $time_ago = 0 ) {
826 +/*function learn_press_get_chart_courses( $from = null, $by = null, $time_ago = 0 ) {
1083 827 global $wpdb;
1084 828
1085 829 $labels = array();
1086 830 $datasets = array();
@@ -1085,9 +829,9 @@
1085 829 $labels = array();
1086 830 $datasets = array();
1087 831
1088 832 if ( is_null( $from ) ) {
1089 - $from = current_time( 'mysql' );
833 + $from = current_time( 'mysql', 1 );
1090 834 }
1091 835
1092 836 if ( is_null( $by ) ) {
1093 837 $by = 'days';
@@ -1270,9 +1014,9 @@
1270 1014 'labels' => $labels,
1271 1015 'datasets' => $datasets,
1272 1016 'sql' => $query,
1273 1017 );
1274 -}
1018 +}*/
1275 1019
1276 1020
1277 1021 /**
1278 1022 * Get data about students to render in chart
@@ -1281,13 +1025,14 @@
1281 1025 * @param null $by
1282 1026 * @param float $time_ago
1283 1027 *
1284 1028 * @return array
1029 + * @deprecated 4.2.6.9.3
1285 1030 */
1286 -function learn_press_get_chart_orders( $from = null, $by = null, $time_ago = 0 ) {
1031 +/*function learn_press_get_chart_orders( $from = null, $by = null, $time_ago = 0 ) {
1287 1032 global $wpdb;
1288 - // var_dump( current_user_can(LP_TEACHER_ROLE) );
1289 - // exit();
1033 + $sql_join = '';
1034 +
1290 1035 $report_sales_by = learn_press_get_request( 'report_sales_by' );
1291 1036 $course_id = learn_press_get_request( 'course_id' );
1292 1037 $cat_id = learn_press_get_request( 'cat_id' );
1293 1038
@@ -1293,9 +1038,9 @@
1293 1038
1294 1039 $labels = array();
1295 1040 $datasets = array();
1296 1041 if ( is_null( $from ) ) {
1297 - $from = current_time( 'mysql' );
1042 + $from = current_time( 'mysql', 1 );
1298 1043 }
1299 1044 if ( is_null( $by ) ) {
1300 1045 $by = 'days';
1301 1046 }
@@ -1337,15 +1082,16 @@
1337 1082 }
1338 1083
1339 1084 $query_join = '';
1340 1085 $query_where = '';
1086 + $sql_join = '';
1341 1087 if ( 'course' === $report_sales_by ) {
1342 1088 $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` "
1343 - . ' ON o.ID=lpoi.order_id '
1344 - . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1345 - . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1346 - . " AND loim.meta_key='_course_id' "
1347 - . ' AND CAST(loim.meta_value AS SIGNED)=%d ';
1089 + . ' ON o.ID=lpoi.order_id '
1090 + . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1091 + . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1092 + . " AND loim.meta_key='_course_id' "
1093 + . ' AND CAST(loim.meta_value AS SIGNED)=%d ';
1348 1094 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1349 1095 $user_id = learn_press_get_current_user_id();
1350 1096 $sql_join .= $wpdb->prepare(
1351 1097 ' AND CAST(loim.meta_value AS SIGNED) IN '
@@ -1357,18 +1103,18 @@
1357 1103 $query_join .= $wpdb->prepare( $sql_join, $course_id );
1358 1104
1359 1105 } elseif ( 'category' === $report_sales_by ) {
1360 1106 $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` "
1361 - . ' ON o.ID=lpoi.order_id '
1362 - . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1363 - . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1364 - . " AND loim.meta_key='_course_id' "
1365 - . ' AND CAST(loim.meta_value AS SIGNED) IN('
1366 - // sub query
1367 - . ' SELECT tr.object_id '
1368 - . " FROM {$wpdb->prefix}term_taxonomy tt INNER JOIN {$wpdb->prefix}term_relationships tr "
1369 - . " ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='course_category' "
1370 - . ' WHERE tt.term_id=%d)';
1107 + . ' ON o.ID=lpoi.order_id '
1108 + . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1109 + . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1110 + . " AND loim.meta_key='_course_id' "
1111 + . ' AND CAST(loim.meta_value AS SIGNED) IN('
1112 + // sub query
1113 + . ' SELECT tr.object_id '
1114 + . " FROM {$wpdb->prefix}term_taxonomy tt INNER JOIN {$wpdb->prefix}term_relationships tr "
1115 + . " ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='course_category' "
1116 + . ' WHERE tt.term_id=%d)';
1371 1117 $query_join .= $wpdb->prepare( $sql_join, $cat_id );
1372 1118 }
1373 1119 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1374 1120 $user_id = learn_press_get_current_user_id();
@@ -1476,19 +1222,20 @@
1476 1222 'labels' => $labels,
1477 1223 'datasets' => $datasets,
1478 1224 'sql' => $query,
1479 1225 );
1480 -}
1226 +}*/
1481 1227
1482 1228 /**
1483 1229 * Get data about courses to render in the chart
1484 1230 *
1485 1231 * @return array
1232 + * @deprecated 4.2.6.9.3
1486 1233 */
1487 -function learn_press_get_chart_courses2() {
1234 +/*function learn_press_get_chart_courses2() {
1488 1235 $labels = array(
1489 - __( 'Pending Courses / Publish Courses', 'learnpress' ),
1490 - __( 'Free Courses / Priced Courses', 'learnpress' ),
1236 + __( 'Pending Courses/Publish Courses', 'learnpress' ),
1237 + __( 'Free Courses/Paid Courses', 'learnpress' ),
1491 1238 );
1492 1239
1493 1240 $datasets = array();
1494 1241 $datasets[0]['data'] = array(
@@ -1510,9 +1257,9 @@
1510 1257 return array(
1511 1258 'labels' => $labels,
1512 1259 'datasets' => $datasets,
1513 1260 );
1514 -}
1261 +}*/
1515 1262
1516 1263 /**
1517 1264 * Get colors setting up by admin user
1518 1265 *
@@ -1656,31 +1403,8 @@
1656 1403
1657 1404 return $slug;
1658 1405 }
1659 1406
1660 -function learn_press_request_query( $vars = array() ) {
1661 - global $typenow, $wp_query, $wp_post_statuses;
1662 -
1663 - if ( LP_ORDER_CPT === $typenow ) {
1664 - if ( ! isset( $vars['post_status'] ) ) {
1665 - $post_statuses = learn_press_get_order_statuses();
1666 -
1667 - foreach ( $post_statuses as $status => $value ) {
1668 - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
1669 - unset( $post_statuses[ $status ] );
1670 - }
1671 - }
1672 -
1673 - $vars['post_status'] = array_keys( $post_statuses );
1674 -
1675 - }
1676 - }
1677 -
1678 - return $vars;
1679 -}
1680 -
1681 -add_filter( 'request', 'learn_press_request_query', 0 );
1682 -
1683 1407 function _learn_press_reset_course_data() {
1684 1408 if ( empty( $_REQUEST['reset-course-data'] ) ) {
1685 1409 return false;
1686 1410 }
@@ -1866,9 +1590,13 @@
1866 1590 'post_excerpt' => $post->post_excerpt,
1867 1591 'post_parent' => $post->post_parent,
1868 1592 'post_password' => $post->post_password,
1869 1593 'post_status' => 'draft',
1870 - 'post_title' => $post->post_title . __( ' Copy', 'learnpress' ),
1594 + 'post_title' => sprintf(
1595 + '%1$s (%2$s)',
1596 + $post->post_title,
1597 + _x( 'Copy', 'Duplicate item title suffix', 'learnpress' )
1598 + ),
1871 1599 'post_type' => $post->post_type,
1872 1600 'to_ping' => $post->to_ping,
1873 1601 'menu_order' => $post->menu_order,
1874 1602 'exclude_meta' => array(),
@@ -1899,55 +1627,37 @@
1899 1627 }
1900 1628 }
1901 1629
1902 1630 /**
1631 + * Duplicate post meta.
1632 + *
1903 1633 * @editor tungnx
1904 - * @modify 4.1.4 - fix sanitize query
1634 + * @sicne 3.0.0
1635 + * @version 4.0.1
1905 1636 */
1906 1637 if ( ! function_exists( 'learn_press_duplicate_post_meta' ) ) {
1907 1638 function learn_press_duplicate_post_meta( $old_post_id, $new_post_id, $excerpt = array() ) {
1908 - global $wpdb;
1639 + $lp_db = LP_Database::getInstance();
1909 1640
1910 - $post_meta_infos = $wpdb->get_results(
1911 - $wpdb->prepare(
1912 - "SELECT meta_key, meta_value FROM $wpdb->postmeta
1913 - WHERE post_id = %d",
1641 + try {
1642 + $excerpt = array_merge( array( '_edit_lock', '_edit_last' ), $excerpt );
1643 + $excerpt_name_keys = implode( "','", $excerpt );
1644 + $sql_query = $lp_db->wpdb->prepare(
1645 + "INSERT INTO $lp_db->tb_postmeta (post_id, meta_key, meta_value)
1646 + SELECT %d, pmc.meta_key, pmc.meta_value
1647 + FROM $lp_db->tb_postmeta AS pmc
1648 + WHERE post_id = %d
1649 + AND meta_key not in ('{$excerpt_name_keys}')
1650 + ",
1651 + $new_post_id,
1914 1652 $old_post_id
1915 - )
1916 - );
1917 -
1918 - if ( count( $post_meta_infos ) != 0 ) {
1919 - $excerpt = array_merge( array( '_edit_lock', '_edit_last' ), $excerpt );
1920 - $excerpt = apply_filters(
1921 - 'learn_press_excerpt_duplicate_post_meta',
1922 - $excerpt,
1923 - $old_post_id,
1924 - $new_post_id
1925 1653 );
1926 - $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
1927 - $sql_query_sel = array();
1928 1654
1929 - foreach ( $post_meta_infos as $meta ) {
1930 - if ( in_array( $meta->meta_key, $excerpt ) ) {
1931 - continue;
1932 - }
1655 + $lp_db->check_execute_has_error();
1933 1656
1934 - if ( $meta->meta_key === '_lp_course_author' ) {
1935 - $meta->meta_value = get_current_user_id();
1936 - }
1937 -
1938 - $meta_key = $meta->meta_key;
1939 - $meta_value = addslashes( $meta->meta_value );
1940 - $sql_query_sel[] = $wpdb->prepare(
1941 - 'SELECT %d, %s, %s',
1942 - $new_post_id,
1943 - $meta_key,
1944 - $meta_value
1945 - );
1946 - }
1947 -
1948 - $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
1949 - $wpdb->query( $sql_query );
1657 + $lp_db->wpdb->query( $sql_query );
1658 + } catch ( Throwable $e ) {
1659 + error_log( $e->getMessage() );
1950 1660 }
1951 1661 }
1952 1662 }
1953 1663
@@ -1970,9 +1680,9 @@
1970 1680 }
1971 1681
1972 1682 for ( $j = $i + 1; $j < count( $ktypes ); $j ++ ) {
1973 1683 if ( isset( $question_types[ $ktypes[ $j ] ], $question_types[ $ktypes[ $max ] ] )
1974 - && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ]
1684 + && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ]
1975 1685 ) {
1976 1686 $max = $j;
1977 1687 }
1978 1688 }
@@ -2078,12 +1788,15 @@
2078 1788 global $wpdb;
2079 1789
2080 1790 $new_quiz_id = learn_press_duplicate_post( $quiz_id, $args, true );
2081 1791 $quiz = LP_Quiz::get_quiz( $quiz_id );
2082 - $questions = $quiz->get_questions();
1792 + if ( ! $quiz ) {
1793 + return 0;
1794 + }
2083 1795
1796 + $questions = $quiz->get_question_ids();
1797 +
2084 1798 if ( $questions ) {
2085 - $questions = array_keys( $questions );
2086 1799 foreach ( $questions as $question_id ) {
2087 1800 $new_question_id = learn_press_duplicate_post( $question_id );
2088 1801
2089 1802 $sql = $wpdb->prepare(
@@ -2163,9 +1876,9 @@
2163 1876 $labels = array();
2164 1877 $datasets = array();
2165 1878
2166 1879 if ( is_null( $from ) ) {
2167 - $from = current_time( 'mysql' );
1880 + $from = current_time( 'mysql', 1 );
2168 1881 }
2169 1882
2170 1883 if ( is_null( $by ) ) {
2171 1884 $by = 'days';
@@ -2445,53 +2158,8 @@
2445 2158 }
2446 2159 }
2447 2160
2448 2161 /**
2449 - * Filter to modal search items to void filter the posts by author.
2450 - *
2451 - * @param int|string $context_id
2452 - * @param string $context
2453 - *
2454 - * @return bool|int|string
2455 - * @since 3.0.4
2456 - */
2457 -function learn_press_modal_search_items_context( $context_id, $context ) {
2458 - if ( 'order-items' === $context ) {
2459 - $context_id = false;
2460 - }
2461 -
2462 - return $context_id;
2463 -}
2464 -
2465 -add_filter( 'learn-press/modal-search-items/context-id', 'learn_press_modal_search_items_context', 10, 2 );
2466 -
2467 -/**
2468 - * Sync post meta when saving post type.
2469 - *
2470 - * @param int $post_id
2471 - *
2472 - * @since 3.2.0
2473 - * @editor tungnx
2474 - * @modify 1.4.1 - comment - not use
2475 - */
2476 -/*function learn_press_maybe_sync_data( $post_id ) {
2477 - $post_type = get_post_type( $post_id );
2478 -
2479 - switch ( $post_type ) {
2480 - case LP_COURSE_CPT:
2481 - LP_Repair_Database::instance()->sync_user_courses();
2482 - break;
2483 - case LP_LESSON_CPT:
2484 - break;
2485 - case LP_QUIZ_CPT:
2486 - break;
2487 - default:
2488 - }
2489 -}*/
2490 -
2491 -//add_action( 'save_post', 'learn_press_maybe_sync_data' );
2492 -
2493 -/**
2494 2162 * Return id of current screen.
2495 2163 *
2496 2164 * @return bool|string
2497 2165 * @since 3.2.6
@@ -2496,101 +2164,12 @@
2496 2164 * @return bool|string
2497 2165 * @since 3.2.6
2498 2166 */
2499 2167 function learn_press_get_screen_id() {
2168 + _deprecated_function( __METHOD__, '4.2.3.6' );
2500 2169 $screen = get_current_screen();
2501 2170 $screen_id = $screen ? $screen->id : false;
2502 2171
2503 2172 return $screen_id;
2504 -}
2505 -
2506 -/**
2507 - * Check if current screen is a page of LP or
2508 - * editing post type of LP such as course, lesson, etc...
2509 - *
2510 - * @return bool
2511 - * @since 3.2.6
2512 - */
2513 -/*
2514 -function learn_press_is_admin_page() {
2515 - $screen_id = learn_press_get_screen_id();
2516 - $is_learnpress = false;
2517 -
2518 - $post_types = apply_filters(
2519 - 'learn-press/admin-post-type-pages',
2520 - array( LP_COURSE_CPT, LP_QUIZ_CPT, LP_LESSON_CPT, LP_QUESTION_CPT, LP_ORDER_CPT, 'lp_cert', 'lp_assignment' )
2521 - );
2522 - foreach ( $post_types as $post_type ) {
2523 - if ( in_array( $screen_id, array( "edit-{$post_type}", $post_type ) ) ) {
2524 - $is_learnpress = true;
2525 - break;
2526 - }
2527 - }
2528 -
2529 - if ( strpos( $screen_id, 'learnpress_page_' ) === 0 ) {
2530 - $is_learnpress = true;
2531 - }
2532 -
2533 - return apply_filters( 'learn-press/is-admin-page', $is_learnpress, $screen_id );
2534 -}*/
2535 -
2536 -function learn_press_get_orders_status_chart_data() {
2537 - $data = array(
2538 - 'type' => 'pie',
2539 - 'data' => array(
2540 - 'labels' => array(),
2541 - 'datasets' => array(
2542 - array(
2543 - 'label' => '# of Votes',
2544 - 'data' => array(),
2545 - 'backgroundColor' => array(
2546 - 'rgba(54, 162, 235, 0.2)',
2547 - 'rgba(255, 206, 86, 0.2)',
2548 - 'rgba(75, 192, 192, 0.2)',
2549 - 'rgba(153, 102, 255, 0.2)',
2550 - 'rgba(255, 159, 64, 0.2)',
2551 - ),
2552 - 'borderColor' => array(
2553 - 'rgba(54, 162, 235, 1)',
2554 - 'rgba(255, 206, 86, 1)',
2555 - 'rgba(75, 192, 192, 1)',
2556 - 'rgba(153, 102, 255, 1)',
2557 - 'rgba(255, 159, 64, 1)',
2558 - ),
2559 - 'borderWidth' => 1,
2560 - ),
2561 - ),
2562 - ),
2563 - 'options' => array(
2564 - 'scales' => array(
2565 - 'yAxes' => array(
2566 - array(
2567 - 'ticks' => array(
2568 - 'beginAtZero' => true,
2569 - ),
2570 - ),
2571 - ),
2572 - ),
2573 - ),
2574 - );
2575 -
2576 - $order_statuses = learn_press_get_order_statuses( true, true );
2577 - $specific_statuses = array( 'lp-completed', 'lp-failed' );
2578 -
2579 - foreach ( $order_statuses as $status ) {
2580 - if ( ! in_array( $status, $specific_statuses ) ) {
2581 - $specific_statuses[] = $status;
2582 - }
2583 - }
2584 -
2585 - $labels = learn_press_get_order_statuses();
2586 - $counts = learn_press_count_orders( array( 'status' => $specific_statuses ) );
2587 -
2588 - foreach ( $counts as $k => $v ) {
2589 - $data['data']['labels'][] = isset( $labels[ $k ] ) ? $labels[ $k ] : 'Untitled';
2590 - $data['data']['datasets'][0]['data'][] = $v;
2591 - }
2592 -
2593 - return $data;
2594 2173 }
2595 2174
2596 2175 require_once 'class-lp-post-type-actions.php';