| @@ -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,9 +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 | -function learn_press_is_hidden_post_box( $id, $user_id = 0 ) { | |
| 126 | +/*function learn_press_is_hidden_post_box( $id, $user_id = 0 ) { | |
| 110 | 127 | if ( ! $user_id ) { |
| 111 | 128 | $user_id = get_current_user_id(); |
| 112 | 129 | } |
| 113 | 130 | |
| @@ -116,76 +133,11 @@ | ||
| 116 | 133 | $data = array(); |
| 117 | 134 | } |
| 118 | 135 | |
| 119 | 136 | return false !== array_search( $id, $data ); |
| 120 | -} | |
| 137 | +}*/ | |
| 121 | 138 | |
| 122 | 139 | /** |
| 123 | - * Get html view path for admin to display | |
| 124 | - * | |
| 125 | - * @param $name | |
| 126 | - * @param $plugin_file | |
| 127 | - * | |
| 128 | - * @return mixed | |
| 129 | - */ | |
| 130 | -function learn_press_get_admin_view( $name, $plugin_file = null ) { | |
| 131 | - if ( ! preg_match( '/\.(html|php)$/', $name ) ) { | |
| 132 | - $name .= '.php'; | |
| 133 | - } | |
| 134 | - if ( $plugin_file ) { | |
| 135 | - $view = dirname( $plugin_file ) . '/inc/admin/views/' . $name; | |
| 136 | - } else { | |
| 137 | - $view = LearnPress::instance()->plugin_path( 'inc/admin/views/' . $name ); | |
| 138 | - } | |
| 139 | - | |
| 140 | - return apply_filters( 'learn_press_admin_view', $view, $name ); | |
| 141 | -} | |
| 142 | - | |
| 143 | -function learn_press_admin_view_content( $name, $args = array() ) { | |
| 144 | - return learn_press_admin_view( $name, $args, false, true ); | |
| 145 | -} | |
| 146 | - | |
| 147 | -/** | |
| 148 | - * Find a full path of a view and display the content in admin | |
| 149 | - * | |
| 150 | - * @param $name | |
| 151 | - * @param array $args | |
| 152 | - * @param bool|false $include_once | |
| 153 | - * @param bool | |
| 154 | - * | |
| 155 | - * @return bool | |
| 156 | - */ | |
| 157 | -function learn_press_admin_view( $name, $args = array(), $include_once = false, $return = false ) { | |
| 158 | - $view = learn_press_get_admin_view( $name, ! empty( $args['plugin_file'] ) ? $args['plugin_file'] : null ); | |
| 159 | - | |
| 160 | - if ( file_exists( $view ) ) { | |
| 161 | - | |
| 162 | - ob_start(); | |
| 163 | - | |
| 164 | - is_array( $args ) && extract( $args ); | |
| 165 | - | |
| 166 | - do_action( 'learn_press_before_display_admin_view', $name, $args ); | |
| 167 | - | |
| 168 | - if ( $include_once ) { | |
| 169 | - include_once $view; | |
| 170 | - } else { | |
| 171 | - include $view; | |
| 172 | - } | |
| 173 | - | |
| 174 | - do_action( 'learn_press_after_display_admin_view', $name, $args ); | |
| 175 | - $output = ob_get_clean(); | |
| 176 | - | |
| 177 | - if ( ! $return ) { | |
| 178 | - learn_press_echo_vuejs_write_on_php( $output ); | |
| 179 | - } | |
| 180 | - | |
| 181 | - return $return ? $output : true; | |
| 182 | - } | |
| 183 | - | |
| 184 | - return false; | |
| 185 | -} | |
| 186 | - | |
| 187 | -/** | |
| 188 | 140 | * List all pages as a dropdown with "Add New Page" option |
| 189 | 141 | * |
| 190 | 142 | * @param $name |
| 191 | 143 | * @param bool|false $selected |
| @@ -196,11 +148,9 @@ | ||
| 196 | 148 | function learn_press_pages_dropdown( $name, $selected = false, $args = array() ) { |
| 197 | 149 | $id = null; |
| 198 | 150 | $class = null; |
| 199 | 151 | $css = null; |
| 200 | - $before = array( | |
| 201 | - 'add_new_page' => __( '[ Add a new page ]', 'learnpress' ), | |
| 202 | - ); | |
| 152 | + $before = []; | |
| 203 | 153 | $after = null; |
| 204 | 154 | $echo = true; |
| 205 | 155 | $allow_create = true; |
| 206 | 156 | |
| @@ -213,9 +163,9 @@ | ||
| 213 | 163 | if ( empty( $id ) ) { |
| 214 | 164 | $id = $name; |
| 215 | 165 | } |
| 216 | 166 | |
| 217 | - $class .= 'list-pages lp-list-pages learn-press-select2'; | |
| 167 | + $class .= 'list-pages lp-list-pages lp-tom-select'; | |
| 218 | 168 | |
| 219 | 169 | $args = array( |
| 220 | 170 | 'name' => $name, |
| 221 | 171 | 'id' => $id, |
| @@ -288,8 +238,10 @@ | ||
| 288 | 238 | | |
| 289 | 239 | <a class="view-page" href="<?php echo get_permalink( $selected ); ?>" |
| 290 | 240 | target="_blank"><?php esc_html_e( 'View page', 'learnpress' ); ?></a> |
| 291 | 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> | |
| 292 | 244 | |
| 293 | 245 | <?php |
| 294 | 246 | $output .= ob_get_clean(); |
| 295 | 247 | } else { |
| @@ -300,9 +252,10 @@ | ||
| 300 | 252 | |
| 301 | 253 | if ( $echo ) { |
| 302 | 254 | $allowed_html = wp_kses_allowed_html( 'post' ); |
| 303 | 255 | $allowed_html['select'] = [ |
| 304 | - 'name' => [], | |
| 256 | + 'name' => [], | |
| 257 | + 'class' => [], | |
| 305 | 258 | ]; |
| 306 | 259 | $allowed_html['option'] = [ |
| 307 | 260 | 'value' => [], |
| 308 | 261 | 'selected' => [], |
| @@ -310,9 +263,15 @@ | ||
| 310 | 263 | ]; |
| 311 | 264 | $allowed_html['input'] = [ |
| 312 | 265 | 'type' => [], |
| 313 | 266 | 'placeholder' => [], |
| 267 | + 'name' => [], | |
| 268 | + 'class' => [], | |
| 314 | 269 | ]; |
| 270 | + $allowed_html['div'] = [ | |
| 271 | + 'name' => [], | |
| 272 | + 'class' => [], | |
| 273 | + ]; | |
| 315 | 274 | |
| 316 | 275 | echo wp_kses( $output, $allowed_html ); |
| 317 | 276 | } |
| 318 | 277 | |
| @@ -429,10 +388,11 @@ | ||
| 429 | 388 | * |
| 430 | 389 | * @param array $args |
| 431 | 390 | * |
| 432 | 391 | * @return string |
| 392 | + * @deprecated 4.2.6.9.3 | |
| 433 | 393 | */ |
| 434 | -function learn_press_email_formats_dropdown( $args = array() ) { | |
| 394 | +/*function learn_press_email_formats_dropdown( $args = array() ) { | |
| 435 | 395 | $args = wp_parse_args( |
| 436 | 396 | $args, |
| 437 | 397 | array( |
| 438 | 398 | 'name' => 'learn-press-dropdown-email-formats', |
| @@ -481,9 +441,9 @@ | ||
| 481 | 441 | echo wp_kses_post( $output ); |
| 482 | 442 | } |
| 483 | 443 | |
| 484 | 444 | return $output; |
| 485 | -} | |
| 445 | +}*/ | |
| 486 | 446 | |
| 487 | 447 | /** |
| 488 | 448 | * Return array of email formats. |
| 489 | 449 | * |
| @@ -516,195 +476,8 @@ | ||
| 516 | 476 | return $content; |
| 517 | 477 | } |
| 518 | 478 | |
| 519 | 479 | /** |
| 520 | - * Get list of themes that support LearnPress. | |
| 521 | - * | |
| 522 | - * @return mixed | |
| 523 | - */ | |
| 524 | -function learn_press_get_education_themes() { | |
| 525 | - | |
| 526 | - // New theme can be added here | |
| 527 | - return apply_filters( | |
| 528 | - 'learn-press/education-themes', | |
| 529 | - array( | |
| 530 | - '23451388' => 'kindergarten', | |
| 531 | - '22773871' => 'ivy-school', | |
| 532 | - '20370918' => 'wordpress-lms', | |
| 533 | - '14058034' => 'eduma', | |
| 534 | - '17097658' => 'coach', | |
| 535 | - '11797847' => 'lms', | |
| 536 | - ) | |
| 537 | - ); | |
| 538 | -} | |
| 539 | - | |
| 540 | -if ( ! function_exists( 'learn_press_get_item_referral' ) ) { | |
| 541 | - /** | |
| 542 | - * Set item link referral. | |
| 543 | - * | |
| 544 | - * @param int|string $item_id | |
| 545 | - * | |
| 546 | - * @return string | |
| 547 | - */ | |
| 548 | - function learn_press_get_item_referral( $item_id ) { | |
| 549 | - $affiliate_links = array( | |
| 550 | - 14058034 => 'https://1.envato.market/G5Ook', // Eduma | |
| 551 | - 22773871 => 'https://1.envato.market/akrzZ', // Ivy-school | |
| 552 | - 20370918 => 'https://1.envato.market/13Zkd', // Course Builder LMS | |
| 553 | - 17097658 => 'https://1.envato.market/Xq2Ra', // Coach | |
| 554 | - 23451388 => 'https://1.envato.market/oWov9', // StarKid | |
| 555 | - 11797847 => 'https://1.envato.market/zknvM', // Epsilon | |
| 556 | - 13321455 => 'https://1.envato.market/G5Rkk', // Sailing | |
| 557 | - 19029758 => 'https://1.envato.market/mAYdZ', // Travel Tour Booking | |
| 558 | - 12124219 => 'https://1.envato.market/qJYdO', // Resca | |
| 559 | - 18828322 => 'https://1.envato.market/VW2K3', // LuxStay | |
| 560 | - 8254575 => 'https://1.envato.market/xWYdO', // Squareroot | |
| 561 | - 13782850 => 'https://1.envato.market/Qo71z', | |
| 562 | - 14025178 => 'https://1.envato.market/9R0oQ', | |
| 563 | - 17739078 => 'https://1.envato.market/jkYda', | |
| 564 | - 16210005 => 'https://1.envato.market/56oJD', | |
| 565 | - 11733602 => 'https://1.envato.market/keYdv', | |
| 566 | - 13513609 => 'https://1.envato.market/aq7dQ', | |
| 567 | - 19693761 => 'https://1.envato.market/A976D', | |
| 568 | - 12532973 => 'https://1.envato.market/Ge79B', | |
| 569 | - 19305239 => 'https://1.envato.market/10JAB', | |
| 570 | - 23716060 => 'https://1.envato.market/ZO7WW', | |
| 571 | - 20466233 => 'https://1.envato.market/gjYd0', | |
| 572 | - 21070438 => 'https://1.envato.market/xPz65', | |
| 573 | - 20794183 => 'https://1.envato.market/o1YdY', | |
| 574 | - 20979215 => 'https://1.envato.market/03R5V', | |
| 575 | - 11151269 => 'https://1.envato.market/Br7L4', | |
| 576 | - 8905392 => 'https://1.envato.market/zEYd7', | |
| 577 | - 23168294 => 'https://1.envato.market/Wn7on', | |
| 578 | - 17719422 => 'https://1.envato.market/0WVaL', | |
| 579 | - 21680592 => 'https://1.envato.market/qqO6y', | |
| 580 | - ); | |
| 581 | - | |
| 582 | - return isset( $affiliate_links[ $item_id ] ) ? $affiliate_links[ $item_id ] : 'https://themeforest.net/user/thimpress/portfolio/'; | |
| 583 | - } | |
| 584 | -} | |
| 585 | - | |
| 586 | -/** | |
| 587 | - * Display advertisement about related themes at the bottom of admin pages. | |
| 588 | - * | |
| 589 | - * @updated 12 Nov 2018 - Enable/Disable shuffle the list of themes | |
| 590 | - * | |
| 591 | - * @return bool|void | |
| 592 | - */ | |
| 593 | -function learn_press_footer_advertisement() { | |
| 594 | - $admin_post_type = array( | |
| 595 | - 'lp_course', | |
| 596 | - 'lp_lesson', | |
| 597 | - 'lp_quiz', | |
| 598 | - 'lp_question', | |
| 599 | - 'lp_order', | |
| 600 | - ); | |
| 601 | - | |
| 602 | - // And our admin pages | |
| 603 | - $pages = array( | |
| 604 | - 'learnpress_page_learn-press-statistics', | |
| 605 | - 'learnpress_page_learn-press-settings', | |
| 606 | - 'learnpress_page_learn-press-tools', | |
| 607 | - | |
| 608 | - ); | |
| 609 | - | |
| 610 | - $screen = get_current_screen(); | |
| 611 | - | |
| 612 | - if ( ! $screen ) { | |
| 613 | - return; | |
| 614 | - } | |
| 615 | - | |
| 616 | - if ( ! ( ( in_array( | |
| 617 | - $screen->post_type, | |
| 618 | - $admin_post_type | |
| 619 | - ) && $screen->base === 'edit' ) || ( in_array( $screen->id, $pages ) ) ) ) { | |
| 620 | - return; | |
| 621 | - } | |
| 622 | - | |
| 623 | - $theme_ids = learn_press_get_education_themes(); | |
| 624 | - $current_theme = wp_get_theme(); | |
| 625 | - | |
| 626 | - $include = array_keys( $theme_ids ); | |
| 627 | - | |
| 628 | - $key = array_search( $current_theme->name, $theme_ids, true ); | |
| 629 | - | |
| 630 | - if ( false !== $key ) { | |
| 631 | - unset( $theme_ids[ $key ] ); | |
| 632 | - } | |
| 633 | - | |
| 634 | - $list_themes = (array) LP_Plugins_Helper::get_related_themes( | |
| 635 | - 'education', | |
| 636 | - array( | |
| 637 | - 'include' => $include, | |
| 638 | - ) | |
| 639 | - ); | |
| 640 | - | |
| 641 | - if ( empty( $list_themes ) ) { | |
| 642 | - return; | |
| 643 | - } | |
| 644 | - | |
| 645 | - // Disable shuffle themes for 3 days | |
| 646 | - $shuffle = LP_Settings::instance()->get( 'ad_shuffle_themes' ); | |
| 647 | - | |
| 648 | - if ( ! $shuffle ) { | |
| 649 | - if ( wp_next_scheduled( 'learn-press/schedule-enable-shuffle-themes' ) === false ) { | |
| 650 | - wp_schedule_single_event( time() + 3 * DAY_IN_SECONDS, 'learn-press/schedule-enable-shuffle-themes' ); | |
| 651 | - } | |
| 652 | - | |
| 653 | - // Keep the first theme always in #1 and shuffle other themes | |
| 654 | - $first_theme = array_shift( $list_themes ); | |
| 655 | - shuffle( $list_themes ); | |
| 656 | - array_unshift( $list_themes, $first_theme ); | |
| 657 | - } else { | |
| 658 | - shuffle( $list_themes ); | |
| 659 | - } | |
| 660 | - ?> | |
| 661 | - | |
| 662 | - <div id="learn-press-advertisement" class="learn-press-advertisement-slider"> | |
| 663 | - <?php | |
| 664 | - foreach ( $list_themes as $theme ) { | |
| 665 | - if ( empty( $theme['url'] ) ) { | |
| 666 | - continue; | |
| 667 | - } | |
| 668 | - | |
| 669 | - $url = learn_press_get_item_referral( $theme['id'] ); | |
| 670 | - $full_description = learn_press_trim_content( $theme['description'] ); | |
| 671 | - $short_description = learn_press_trim_content( $theme['description'], 75 ); | |
| 672 | - $url_demo = $theme['attributes'][4]['value']; | |
| 673 | - ?> | |
| 674 | - | |
| 675 | - <div id="thimpress-<?php echo esc_attr( $theme['id'] ); ?>" class="slide-item"> | |
| 676 | - <div class="slide-thumbnail"> | |
| 677 | - <a href="<?php echo esc_url_raw( $url ); ?>"> | |
| 678 | - <img src="<?php echo esc_url_raw( $theme['previews']['landscape_preview']['landscape_url'] ); ?>"/> | |
| 679 | - </a> | |
| 680 | - </div> | |
| 681 | - | |
| 682 | - <div class="slide-detail"> | |
| 683 | - <h2><a href="<?php echo esc_url_raw( $url ); ?>"><?php echo esc_html( $theme['name'] ); ?></a></h2> | |
| 684 | - <p class="slide-description description-full"> | |
| 685 | - <?php echo wp_kses_post( $full_description ); ?> | |
| 686 | - </p> | |
| 687 | - | |
| 688 | - <p class="slide-description description-short"> | |
| 689 | - <?php echo wp_kses_post( $short_description ); ?> | |
| 690 | - </p> | |
| 691 | - | |
| 692 | - <p class="slide-controls"> | |
| 693 | - <a href="<?php echo esc_url_raw( $url ); ?>" class="button button-primary" | |
| 694 | - target="_blank"><?php esc_html_e( 'Get it now', 'learnpress' ); ?></a> | |
| 695 | - <a href="<?php echo esc_url_raw( $url_demo ); ?>" class="button" | |
| 696 | - target="_blank"><?php esc_html_e( 'View Demo', 'learnpress' ); ?></a> | |
| 697 | - </p> | |
| 698 | - </div> | |
| 699 | - </div> | |
| 700 | - | |
| 701 | - <?php } ?> | |
| 702 | - </div> | |
| 703 | - <?php | |
| 704 | -} | |
| 705 | - | |
| 706 | -/** | |
| 707 | 480 | * Count number of orders between to dates |
| 708 | 481 | * |
| 709 | 482 | * @param string |
| 710 | 483 | * @param int |
| @@ -804,10 +577,11 @@ | ||
| 804 | 577 | * |
| 805 | 578 | * @param string |
| 806 | 579 | * |
| 807 | 580 | * @return int |
| 581 | + * @deprecated 4.2.6.9.3 | |
| 808 | 582 | */ |
| 809 | -function learn_press_get_courses_by_price( $fee ) { | |
| 583 | +/*function learn_press_get_courses_by_price( $fee ) { | |
| 810 | 584 | global $wpdb; |
| 811 | 585 | |
| 812 | 586 | $user_id = get_current_user_id(); |
| 813 | 587 | |
| @@ -830,9 +604,9 @@ | ||
| 830 | 604 | ) |
| 831 | 605 | ); |
| 832 | 606 | |
| 833 | 607 | return $courses; |
| 834 | -} | |
| 608 | +}*/ | |
| 835 | 609 | |
| 836 | 610 | /** |
| 837 | 611 | * Get data about students to render in chart |
| 838 | 612 | * |
| @@ -840,10 +614,11 @@ | ||
| 840 | 614 | * @param null $by |
| 841 | 615 | * @param float $time_ago |
| 842 | 616 | * |
| 843 | 617 | * @return array |
| 618 | + * @deprecated 4.2.6.9.3 | |
| 844 | 619 | */ |
| 845 | -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 ) { | |
| 846 | 621 | $labels = array(); |
| 847 | 622 | $datasets = array(); |
| 848 | 623 | |
| 849 | 624 | if ( is_null( $from ) ) { |
| @@ -882,9 +657,9 @@ | ||
| 882 | 657 | return array( |
| 883 | 658 | 'labels' => $labels, |
| 884 | 659 | 'datasets' => $datasets, |
| 885 | 660 | ); |
| 886 | -} | |
| 661 | +}*/ | |
| 887 | 662 | |
| 888 | 663 | /** |
| 889 | 664 | * Get data about students to render in chart |
| 890 | 665 | * |
| @@ -892,10 +667,11 @@ | ||
| 892 | 667 | * @param null $by |
| 893 | 668 | * @param float $time_ago |
| 894 | 669 | * |
| 895 | 670 | * @return array |
| 671 | + * @deprecated 4.2.6.9.3 | |
| 896 | 672 | */ |
| 897 | -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 ) { | |
| 898 | 674 | global $wpdb; |
| 899 | 675 | |
| 900 | 676 | $labels = array(); |
| 901 | 677 | $datasets = array(); |
| @@ -1033,9 +809,9 @@ | ||
| 1033 | 809 | 'labels' => $labels, |
| 1034 | 810 | 'datasets' => $datasets, |
| 1035 | 811 | 'sql' => $query, |
| 1036 | 812 | ); |
| 1037 | -} | |
| 813 | +}*/ | |
| 1038 | 814 | |
| 1039 | 815 | |
| 1040 | 816 | /** |
| 1041 | 817 | * Get data about students to render in chart |
| @@ -1044,10 +820,11 @@ | ||
| 1044 | 820 | * @param null $by |
| 1045 | 821 | * @param float $time_ago |
| 1046 | 822 | * |
| 1047 | 823 | * @return array |
| 824 | + * @deprecated 4.2.6.9.3 | |
| 1048 | 825 | */ |
| 1049 | -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 ) { | |
| 1050 | 827 | global $wpdb; |
| 1051 | 828 | |
| 1052 | 829 | $labels = array(); |
| 1053 | 830 | $datasets = array(); |
| @@ -1237,9 +1014,9 @@ | ||
| 1237 | 1014 | 'labels' => $labels, |
| 1238 | 1015 | 'datasets' => $datasets, |
| 1239 | 1016 | 'sql' => $query, |
| 1240 | 1017 | ); |
| 1241 | -} | |
| 1018 | +}*/ | |
| 1242 | 1019 | |
| 1243 | 1020 | |
| 1244 | 1021 | /** |
| 1245 | 1022 | * Get data about students to render in chart |
| @@ -1248,13 +1025,14 @@ | ||
| 1248 | 1025 | * @param null $by |
| 1249 | 1026 | * @param float $time_ago |
| 1250 | 1027 | * |
| 1251 | 1028 | * @return array |
| 1029 | + * @deprecated 4.2.6.9.3 | |
| 1252 | 1030 | */ |
| 1253 | -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 ) { | |
| 1254 | 1032 | global $wpdb; |
| 1255 | - // var_dump( current_user_can(LP_TEACHER_ROLE) ); | |
| 1256 | - // exit(); | |
| 1033 | + $sql_join = ''; | |
| 1034 | + | |
| 1257 | 1035 | $report_sales_by = learn_press_get_request( 'report_sales_by' ); |
| 1258 | 1036 | $course_id = learn_press_get_request( 'course_id' ); |
| 1259 | 1037 | $cat_id = learn_press_get_request( 'cat_id' ); |
| 1260 | 1038 | |
| @@ -1304,15 +1082,16 @@ | ||
| 1304 | 1082 | } |
| 1305 | 1083 | |
| 1306 | 1084 | $query_join = ''; |
| 1307 | 1085 | $query_where = ''; |
| 1086 | + $sql_join = ''; | |
| 1308 | 1087 | if ( 'course' === $report_sales_by ) { |
| 1309 | 1088 | $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` " |
| 1310 | - . ' ON o.ID=lpoi.order_id ' | |
| 1311 | - . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim " | |
| 1312 | - . ' ON lpoi.order_item_id=loim.learnpress_order_item_id ' | |
| 1313 | - . " AND loim.meta_key='_course_id' " | |
| 1314 | - . ' 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 '; | |
| 1315 | 1094 | if ( current_user_can( LP_TEACHER_ROLE ) ) { |
| 1316 | 1095 | $user_id = learn_press_get_current_user_id(); |
| 1317 | 1096 | $sql_join .= $wpdb->prepare( |
| 1318 | 1097 | ' AND CAST(loim.meta_value AS SIGNED) IN ' |
| @@ -1324,18 +1103,18 @@ | ||
| 1324 | 1103 | $query_join .= $wpdb->prepare( $sql_join, $course_id ); |
| 1325 | 1104 | |
| 1326 | 1105 | } elseif ( 'category' === $report_sales_by ) { |
| 1327 | 1106 | $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` " |
| 1328 | - . ' ON o.ID=lpoi.order_id ' | |
| 1329 | - . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim " | |
| 1330 | - . ' ON lpoi.order_item_id=loim.learnpress_order_item_id ' | |
| 1331 | - . " AND loim.meta_key='_course_id' " | |
| 1332 | - . ' AND CAST(loim.meta_value AS SIGNED) IN(' | |
| 1333 | - // sub query | |
| 1334 | - . ' SELECT tr.object_id ' | |
| 1335 | - . " FROM {$wpdb->prefix}term_taxonomy tt INNER JOIN {$wpdb->prefix}term_relationships tr " | |
| 1336 | - . " ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='course_category' " | |
| 1337 | - . ' 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)'; | |
| 1338 | 1117 | $query_join .= $wpdb->prepare( $sql_join, $cat_id ); |
| 1339 | 1118 | } |
| 1340 | 1119 | if ( current_user_can( LP_TEACHER_ROLE ) ) { |
| 1341 | 1120 | $user_id = learn_press_get_current_user_id(); |
| @@ -1443,16 +1222,17 @@ | ||
| 1443 | 1222 | 'labels' => $labels, |
| 1444 | 1223 | 'datasets' => $datasets, |
| 1445 | 1224 | 'sql' => $query, |
| 1446 | 1225 | ); |
| 1447 | -} | |
| 1226 | +}*/ | |
| 1448 | 1227 | |
| 1449 | 1228 | /** |
| 1450 | 1229 | * Get data about courses to render in the chart |
| 1451 | 1230 | * |
| 1452 | 1231 | * @return array |
| 1232 | + * @deprecated 4.2.6.9.3 | |
| 1453 | 1233 | */ |
| 1454 | -function learn_press_get_chart_courses2() { | |
| 1234 | +/*function learn_press_get_chart_courses2() { | |
| 1455 | 1235 | $labels = array( |
| 1456 | 1236 | __( 'Pending Courses/Publish Courses', 'learnpress' ), |
| 1457 | 1237 | __( 'Free Courses/Paid Courses', 'learnpress' ), |
| 1458 | 1238 | ); |
| @@ -1477,9 +1257,9 @@ | ||
| 1477 | 1257 | return array( |
| 1478 | 1258 | 'labels' => $labels, |
| 1479 | 1259 | 'datasets' => $datasets, |
| 1480 | 1260 | ); |
| 1481 | -} | |
| 1261 | +}*/ | |
| 1482 | 1262 | |
| 1483 | 1263 | /** |
| 1484 | 1264 | * Get colors setting up by admin user |
| 1485 | 1265 | * |
| @@ -1623,31 +1403,8 @@ | ||
| 1623 | 1403 | |
| 1624 | 1404 | return $slug; |
| 1625 | 1405 | } |
| 1626 | 1406 | |
| 1627 | -function learn_press_request_query( $vars = array() ) { | |
| 1628 | - global $typenow, $wp_query, $wp_post_statuses; | |
| 1629 | - | |
| 1630 | - if ( LP_ORDER_CPT === $typenow ) { | |
| 1631 | - if ( ! isset( $vars['post_status'] ) ) { | |
| 1632 | - $post_statuses = learn_press_get_order_statuses(); | |
| 1633 | - | |
| 1634 | - foreach ( $post_statuses as $status => $value ) { | |
| 1635 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { | |
| 1636 | - unset( $post_statuses[ $status ] ); | |
| 1637 | - } | |
| 1638 | - } | |
| 1639 | - | |
| 1640 | - $vars['post_status'] = array_keys( $post_statuses ); | |
| 1641 | - | |
| 1642 | - } | |
| 1643 | - } | |
| 1644 | - | |
| 1645 | - return $vars; | |
| 1646 | -} | |
| 1647 | - | |
| 1648 | -add_filter( 'request', 'learn_press_request_query', 0 ); | |
| 1649 | - | |
| 1650 | 1407 | function _learn_press_reset_course_data() { |
| 1651 | 1408 | if ( empty( $_REQUEST['reset-course-data'] ) ) { |
| 1652 | 1409 | return false; |
| 1653 | 1410 | } |
| @@ -1833,9 +1590,13 @@ | ||
| 1833 | 1590 | 'post_excerpt' => $post->post_excerpt, |
| 1834 | 1591 | 'post_parent' => $post->post_parent, |
| 1835 | 1592 | 'post_password' => $post->post_password, |
| 1836 | 1593 | 'post_status' => 'draft', |
| 1837 | - '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 | + ), | |
| 1838 | 1599 | 'post_type' => $post->post_type, |
| 1839 | 1600 | 'to_ping' => $post->to_ping, |
| 1840 | 1601 | 'menu_order' => $post->menu_order, |
| 1841 | 1602 | 'exclude_meta' => array(), |
| @@ -1919,9 +1680,9 @@ | ||
| 1919 | 1680 | } |
| 1920 | 1681 | |
| 1921 | 1682 | for ( $j = $i + 1; $j < count( $ktypes ); $j ++ ) { |
| 1922 | 1683 | if ( isset( $question_types[ $ktypes[ $j ] ], $question_types[ $ktypes[ $max ] ] ) |
| 1923 | - && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ] | |
| 1684 | + && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ] | |
| 1924 | 1685 | ) { |
| 1925 | 1686 | $max = $j; |
| 1926 | 1687 | } |
| 1927 | 1688 | } |
| @@ -2397,53 +2158,8 @@ | ||
| 2397 | 2158 | } |
| 2398 | 2159 | } |
| 2399 | 2160 | |
| 2400 | 2161 | /** |
| 2401 | - * Filter to modal search items to void filter the posts by author. | |
| 2402 | - * | |
| 2403 | - * @param int|string $context_id | |
| 2404 | - * @param string $context | |
| 2405 | - * | |
| 2406 | - * @return bool|int|string | |
| 2407 | - * @since 3.0.4 | |
| 2408 | - */ | |
| 2409 | -function learn_press_modal_search_items_context( $context_id, $context ) { | |
| 2410 | - if ( 'order-items' === $context ) { | |
| 2411 | - $context_id = false; | |
| 2412 | - } | |
| 2413 | - | |
| 2414 | - return $context_id; | |
| 2415 | -} | |
| 2416 | - | |
| 2417 | -add_filter( 'learn-press/modal-search-items/context-id', 'learn_press_modal_search_items_context', 10, 2 ); | |
| 2418 | - | |
| 2419 | -/** | |
| 2420 | - * Sync post meta when saving post type. | |
| 2421 | - * | |
| 2422 | - * @param int $post_id | |
| 2423 | - * | |
| 2424 | - * @since 3.2.0 | |
| 2425 | - * @editor tungnx | |
| 2426 | - * @modify 1.4.1 - comment - not use | |
| 2427 | - */ | |
| 2428 | -/*function learn_press_maybe_sync_data( $post_id ) { | |
| 2429 | - $post_type = get_post_type( $post_id ); | |
| 2430 | - | |
| 2431 | - switch ( $post_type ) { | |
| 2432 | - case LP_COURSE_CPT: | |
| 2433 | - LP_Repair_Database::instance()->sync_user_courses(); | |
| 2434 | - break; | |
| 2435 | - case LP_LESSON_CPT: | |
| 2436 | - break; | |
| 2437 | - case LP_QUIZ_CPT: | |
| 2438 | - break; | |
| 2439 | - default: | |
| 2440 | - } | |
| 2441 | -}*/ | |
| 2442 | - | |
| 2443 | -//add_action( 'save_post', 'learn_press_maybe_sync_data' ); | |
| 2444 | - | |
| 2445 | -/** | |
| 2446 | 2162 | * Return id of current screen. |
| 2447 | 2163 | * |
| 2448 | 2164 | * @return bool|string |
| 2449 | 2165 | * @since 3.2.6 |
| @@ -2448,101 +2164,12 @@ | ||
| 2448 | 2164 | * @return bool|string |
| 2449 | 2165 | * @since 3.2.6 |
| 2450 | 2166 | */ |
| 2451 | 2167 | function learn_press_get_screen_id() { |
| 2168 | + _deprecated_function( __METHOD__, '4.2.3.6' ); | |
| 2452 | 2169 | $screen = get_current_screen(); |
| 2453 | 2170 | $screen_id = $screen ? $screen->id : false; |
| 2454 | 2171 | |
| 2455 | 2172 | return $screen_id; |
| 2456 | -} | |
| 2457 | - | |
| 2458 | -/** | |
| 2459 | - * Check if current screen is a page of LP or | |
| 2460 | - * editing post type of LP such as course, lesson, etc... | |
| 2461 | - * | |
| 2462 | - * @return bool | |
| 2463 | - * @since 3.2.6 | |
| 2464 | - */ | |
| 2465 | -/* | |
| 2466 | -function learn_press_is_admin_page() { | |
| 2467 | - $screen_id = learn_press_get_screen_id(); | |
| 2468 | - $is_learnpress = false; | |
| 2469 | - | |
| 2470 | - $post_types = apply_filters( | |
| 2471 | - 'learn-press/admin-post-type-pages', | |
| 2472 | - array( LP_COURSE_CPT, LP_QUIZ_CPT, LP_LESSON_CPT, LP_QUESTION_CPT, LP_ORDER_CPT, 'lp_cert', 'lp_assignment' ) | |
| 2473 | - ); | |
| 2474 | - foreach ( $post_types as $post_type ) { | |
| 2475 | - if ( in_array( $screen_id, array( "edit-{$post_type}", $post_type ) ) ) { | |
| 2476 | - $is_learnpress = true; | |
| 2477 | - break; | |
| 2478 | - } | |
| 2479 | - } | |
| 2480 | - | |
| 2481 | - if ( strpos( $screen_id, 'learnpress_page_' ) === 0 ) { | |
| 2482 | - $is_learnpress = true; | |
| 2483 | - } | |
| 2484 | - | |
| 2485 | - return apply_filters( 'learn-press/is-admin-page', $is_learnpress, $screen_id ); | |
| 2486 | -}*/ | |
| 2487 | - | |
| 2488 | -function learn_press_get_orders_status_chart_data() { | |
| 2489 | - $data = array( | |
| 2490 | - 'type' => 'pie', | |
| 2491 | - 'data' => array( | |
| 2492 | - 'labels' => array(), | |
| 2493 | - 'datasets' => array( | |
| 2494 | - array( | |
| 2495 | - 'label' => '# of Votes', | |
| 2496 | - 'data' => array(), | |
| 2497 | - 'backgroundColor' => array( | |
| 2498 | - 'rgba(54, 162, 235, 0.2)', | |
| 2499 | - 'rgba(255, 206, 86, 0.2)', | |
| 2500 | - 'rgba(75, 192, 192, 0.2)', | |
| 2501 | - 'rgba(153, 102, 255, 0.2)', | |
| 2502 | - 'rgba(255, 159, 64, 0.2)', | |
| 2503 | - ), | |
| 2504 | - 'borderColor' => array( | |
| 2505 | - 'rgba(54, 162, 235, 1)', | |
| 2506 | - 'rgba(255, 206, 86, 1)', | |
| 2507 | - 'rgba(75, 192, 192, 1)', | |
| 2508 | - 'rgba(153, 102, 255, 1)', | |
| 2509 | - 'rgba(255, 159, 64, 1)', | |
| 2510 | - ), | |
| 2511 | - 'borderWidth' => 1, | |
| 2512 | - ), | |
| 2513 | - ), | |
| 2514 | - ), | |
| 2515 | - 'options' => array( | |
| 2516 | - 'scales' => array( | |
| 2517 | - 'yAxes' => array( | |
| 2518 | - array( | |
| 2519 | - 'ticks' => array( | |
| 2520 | - 'beginAtZero' => true, | |
| 2521 | - ), | |
| 2522 | - ), | |
| 2523 | - ), | |
| 2524 | - ), | |
| 2525 | - ), | |
| 2526 | - ); | |
| 2527 | - | |
| 2528 | - $order_statuses = learn_press_get_order_statuses( true, true ); | |
| 2529 | - $specific_statuses = array( 'lp-completed', 'lp-failed' ); | |
| 2530 | - | |
| 2531 | - foreach ( $order_statuses as $status ) { | |
| 2532 | - if ( ! in_array( $status, $specific_statuses ) ) { | |
| 2533 | - $specific_statuses[] = $status; | |
| 2534 | - } | |
| 2535 | - } | |
| 2536 | - | |
| 2537 | - $labels = learn_press_get_order_statuses(); | |
| 2538 | - $counts = learn_press_count_orders( array( 'status' => $specific_statuses ) ); | |
| 2539 | - | |
| 2540 | - foreach ( $counts as $k => $v ) { | |
| 2541 | - $data['data']['labels'][] = isset( $labels[ $k ] ) ? $labels[ $k ] : 'Untitled'; | |
| 2542 | - $data['data']['datasets'][0]['data'][] = $v; | |
| 2543 | - } | |
| 2544 | - | |
| 2545 | - return $data; | |
| 2546 | 2173 | } |
| 2547 | 2174 | |
| 2548 | 2175 | require_once 'class-lp-post-type-actions.php'; |