| @@ -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,76 +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 | 140 | * List all pages as a dropdown with "Add New Page" option |
| 210 | 141 | * |
| 211 | 142 | * @param $name |
| 212 | 143 | * @param bool|false $selected |
| @@ -217,11 +148,9 @@ | ||
| 217 | 148 | function learn_press_pages_dropdown( $name, $selected = false, $args = array() ) { |
| 218 | 149 | $id = null; |
| 219 | 150 | $class = null; |
| 220 | 151 | $css = null; |
| 221 | - $before = array( | |
| 222 | - 'add_new_page' => __( '[ Add a new page ]', 'learnpress' ), | |
| 223 | - ); | |
| 152 | + $before = []; | |
| 224 | 153 | $after = null; |
| 225 | 154 | $echo = true; |
| 226 | 155 | $allow_create = true; |
| 227 | 156 | |
| @@ -234,9 +163,9 @@ | ||
| 234 | 163 | if ( empty( $id ) ) { |
| 235 | 164 | $id = $name; |
| 236 | 165 | } |
| 237 | 166 | |
| 238 | - $class .= 'list-pages lp-list-pages learn-press-select2'; | |
| 167 | + $class .= 'list-pages lp-list-pages lp-tom-select'; | |
| 239 | 168 | |
| 240 | 169 | $args = array( |
| 241 | 170 | 'name' => $name, |
| 242 | 171 | 'id' => $id, |
| @@ -287,9 +216,9 @@ | ||
| 287 | 216 | |
| 288 | 217 | if ( $allow_create ) { |
| 289 | 218 | ob_start(); ?> |
| 290 | 219 | |
| 291 | - <?php echo esc_html( _x( 'or', 'drop down pages', 'learnpress' ) ); ?> | |
| 220 | + <?php echo esc_html( _x( 'or', 'dropdown pages', 'learnpress' ) ); ?> | |
| 292 | 221 | |
| 293 | 222 | <button class="button button-quick-add-page" data-id="<?php echo esc_attr( $id ); ?>" type="button"> |
| 294 | 223 | <?php esc_html_e( 'Create new', 'learnpress' ); ?> |
| 295 | 224 | </button> |
| @@ -309,8 +238,10 @@ | ||
| 309 | 238 | | |
| 310 | 239 | <a class="view-page" href="<?php echo get_permalink( $selected ); ?>" |
| 311 | 240 | target="_blank"><?php esc_html_e( 'View page', 'learnpress' ); ?></a> |
| 312 | 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> | |
| 313 | 244 | |
| 314 | 245 | <?php |
| 315 | 246 | $output .= ob_get_clean(); |
| 316 | 247 | } else { |
| @@ -321,9 +252,10 @@ | ||
| 321 | 252 | |
| 322 | 253 | if ( $echo ) { |
| 323 | 254 | $allowed_html = wp_kses_allowed_html( 'post' ); |
| 324 | 255 | $allowed_html['select'] = [ |
| 325 | - 'name' => [], | |
| 256 | + 'name' => [], | |
| 257 | + 'class' => [], | |
| 326 | 258 | ]; |
| 327 | 259 | $allowed_html['option'] = [ |
| 328 | 260 | 'value' => [], |
| 329 | 261 | 'selected' => [], |
| @@ -331,9 +263,15 @@ | ||
| 331 | 263 | ]; |
| 332 | 264 | $allowed_html['input'] = [ |
| 333 | 265 | 'type' => [], |
| 334 | 266 | 'placeholder' => [], |
| 267 | + 'name' => [], | |
| 268 | + 'class' => [], | |
| 335 | 269 | ]; |
| 270 | + $allowed_html['div'] = [ | |
| 271 | + 'name' => [], | |
| 272 | + 'class' => [], | |
| 273 | + ]; | |
| 336 | 274 | |
| 337 | 275 | echo wp_kses( $output, $allowed_html ); |
| 338 | 276 | } |
| 339 | 277 | |
| @@ -450,10 +388,11 @@ | ||
| 450 | 388 | * |
| 451 | 389 | * @param array $args |
| 452 | 390 | * |
| 453 | 391 | * @return string |
| 392 | + * @deprecated 4.2.6.9.3 | |
| 454 | 393 | */ |
| 455 | -function learn_press_email_formats_dropdown( $args = array() ) { | |
| 394 | +/*function learn_press_email_formats_dropdown( $args = array() ) { | |
| 456 | 395 | $args = wp_parse_args( |
| 457 | 396 | $args, |
| 458 | 397 | array( |
| 459 | 398 | 'name' => 'learn-press-dropdown-email-formats', |
| @@ -502,9 +441,9 @@ | ||
| 502 | 441 | echo wp_kses_post( $output ); |
| 503 | 442 | } |
| 504 | 443 | |
| 505 | 444 | return $output; |
| 506 | -} | |
| 445 | +}*/ | |
| 507 | 446 | |
| 508 | 447 | /** |
| 509 | 448 | * Return array of email formats. |
| 510 | 449 | * |
| @@ -537,195 +476,8 @@ | ||
| 537 | 476 | return $content; |
| 538 | 477 | } |
| 539 | 478 | |
| 540 | 479 | /** |
| 541 | - * Get list of themes that support LearnPress. | |
| 542 | - * | |
| 543 | - * @return mixed | |
| 544 | - */ | |
| 545 | -function learn_press_get_education_themes() { | |
| 546 | - | |
| 547 | - // New theme can be added here | |
| 548 | - return apply_filters( | |
| 549 | - 'learn-press/education-themes', | |
| 550 | - array( | |
| 551 | - '23451388' => 'kindergarten', | |
| 552 | - '22773871' => 'ivy-school', | |
| 553 | - '20370918' => 'wordpress-lms', | |
| 554 | - '14058034' => 'eduma', | |
| 555 | - '17097658' => 'coach', | |
| 556 | - '11797847' => 'lms', | |
| 557 | - ) | |
| 558 | - ); | |
| 559 | -} | |
| 560 | - | |
| 561 | -if ( ! function_exists( 'learn_press_get_item_referral' ) ) { | |
| 562 | - /** | |
| 563 | - * Set item link referral. | |
| 564 | - * | |
| 565 | - * @param int|string $item_id | |
| 566 | - * | |
| 567 | - * @return string | |
| 568 | - */ | |
| 569 | - function learn_press_get_item_referral( $item_id ) { | |
| 570 | - $affiliate_links = array( | |
| 571 | - 14058034 => 'https://1.envato.market/G5Ook', // Eduma | |
| 572 | - 22773871 => 'https://1.envato.market/akrzZ', // Ivy-school | |
| 573 | - 20370918 => 'https://1.envato.market/13Zkd', // Course Builder LMS | |
| 574 | - 17097658 => 'https://1.envato.market/Xq2Ra', // Coach | |
| 575 | - 23451388 => 'https://1.envato.market/oWov9', // StarKid | |
| 576 | - 11797847 => 'https://1.envato.market/zknvM', // Epsilon | |
| 577 | - 13321455 => 'https://1.envato.market/G5Rkk', // Sailing | |
| 578 | - 19029758 => 'https://1.envato.market/mAYdZ', // Travel Tour Booking | |
| 579 | - 12124219 => 'https://1.envato.market/qJYdO', // Resca | |
| 580 | - 18828322 => 'https://1.envato.market/VW2K3', // LuxStay | |
| 581 | - 8254575 => 'https://1.envato.market/xWYdO', // Squareroot | |
| 582 | - 13782850 => 'https://1.envato.market/Qo71z', | |
| 583 | - 14025178 => 'https://1.envato.market/9R0oQ', | |
| 584 | - 17739078 => 'https://1.envato.market/jkYda', | |
| 585 | - 16210005 => 'https://1.envato.market/56oJD', | |
| 586 | - 11733602 => 'https://1.envato.market/keYdv', | |
| 587 | - 13513609 => 'https://1.envato.market/aq7dQ', | |
| 588 | - 19693761 => 'https://1.envato.market/A976D', | |
| 589 | - 12532973 => 'https://1.envato.market/Ge79B', | |
| 590 | - 19305239 => 'https://1.envato.market/10JAB', | |
| 591 | - 23716060 => 'https://1.envato.market/ZO7WW', | |
| 592 | - 20466233 => 'https://1.envato.market/gjYd0', | |
| 593 | - 21070438 => 'https://1.envato.market/xPz65', | |
| 594 | - 20794183 => 'https://1.envato.market/o1YdY', | |
| 595 | - 20979215 => 'https://1.envato.market/03R5V', | |
| 596 | - 11151269 => 'https://1.envato.market/Br7L4', | |
| 597 | - 8905392 => 'https://1.envato.market/zEYd7', | |
| 598 | - 23168294 => 'https://1.envato.market/Wn7on', | |
| 599 | - 17719422 => 'https://1.envato.market/0WVaL', | |
| 600 | - 21680592 => 'https://1.envato.market/qqO6y', | |
| 601 | - ); | |
| 602 | - | |
| 603 | - return isset( $affiliate_links[ $item_id ] ) ? $affiliate_links[ $item_id ] : 'https://themeforest.net/user/thimpress/portfolio/'; | |
| 604 | - } | |
| 605 | -} | |
| 606 | - | |
| 607 | -/** | |
| 608 | - * Display advertisement about related themes at the bottom of admin pages. | |
| 609 | - * | |
| 610 | - * @updated 12 Nov 2018 - Enable/Disable shuffle the list of themes | |
| 611 | - * | |
| 612 | - * @return bool|void | |
| 613 | - */ | |
| 614 | -function learn_press_footer_advertisement() { | |
| 615 | - $admin_post_type = array( | |
| 616 | - 'lp_course', | |
| 617 | - 'lp_lesson', | |
| 618 | - 'lp_quiz', | |
| 619 | - 'lp_question', | |
| 620 | - 'lp_order', | |
| 621 | - ); | |
| 622 | - | |
| 623 | - // And our admin pages | |
| 624 | - $pages = array( | |
| 625 | - 'learnpress_page_learn-press-statistics', | |
| 626 | - 'learnpress_page_learn-press-settings', | |
| 627 | - 'learnpress_page_learn-press-tools', | |
| 628 | - | |
| 629 | - ); | |
| 630 | - | |
| 631 | - $screen = get_current_screen(); | |
| 632 | - | |
| 633 | - if ( ! $screen ) { | |
| 634 | - return; | |
| 635 | - } | |
| 636 | - | |
| 637 | - if ( ! ( ( in_array( | |
| 638 | - $screen->post_type, | |
| 639 | - $admin_post_type | |
| 640 | - ) && $screen->base === 'edit' ) || ( in_array( $screen->id, $pages ) ) ) ) { | |
| 641 | - return; | |
| 642 | - } | |
| 643 | - | |
| 644 | - $theme_ids = learn_press_get_education_themes(); | |
| 645 | - $current_theme = wp_get_theme(); | |
| 646 | - | |
| 647 | - $include = array_keys( $theme_ids ); | |
| 648 | - | |
| 649 | - $key = array_search( $current_theme->name, $theme_ids, true ); | |
| 650 | - | |
| 651 | - if ( false !== $key ) { | |
| 652 | - unset( $theme_ids[ $key ] ); | |
| 653 | - } | |
| 654 | - | |
| 655 | - $list_themes = (array) LP_Plugins_Helper::get_related_themes( | |
| 656 | - 'education', | |
| 657 | - array( | |
| 658 | - 'include' => $include, | |
| 659 | - ) | |
| 660 | - ); | |
| 661 | - | |
| 662 | - if ( empty( $list_themes ) ) { | |
| 663 | - return; | |
| 664 | - } | |
| 665 | - | |
| 666 | - // Disable shuffle themes for 3 days | |
| 667 | - $shuffle = LP_Settings::instance()->get( 'ad_shuffle_themes' ); | |
| 668 | - | |
| 669 | - if ( ! $shuffle ) { | |
| 670 | - if ( wp_next_scheduled( 'learn-press/schedule-enable-shuffle-themes' ) === false ) { | |
| 671 | - wp_schedule_single_event( time() + 3 * DAY_IN_SECONDS, 'learn-press/schedule-enable-shuffle-themes' ); | |
| 672 | - } | |
| 673 | - | |
| 674 | - // Keep the first theme always in #1 and shuffle other themes | |
| 675 | - $first_theme = array_shift( $list_themes ); | |
| 676 | - shuffle( $list_themes ); | |
| 677 | - array_unshift( $list_themes, $first_theme ); | |
| 678 | - } else { | |
| 679 | - shuffle( $list_themes ); | |
| 680 | - } | |
| 681 | - ?> | |
| 682 | - | |
| 683 | - <div id="learn-press-advertisement" class="learn-press-advertisement-slider"> | |
| 684 | - <?php | |
| 685 | - foreach ( $list_themes as $theme ) { | |
| 686 | - if ( empty( $theme['url'] ) ) { | |
| 687 | - continue; | |
| 688 | - } | |
| 689 | - | |
| 690 | - $url = learn_press_get_item_referral( $theme['id'] ); | |
| 691 | - $full_description = learn_press_trim_content( $theme['description'] ); | |
| 692 | - $short_description = learn_press_trim_content( $theme['description'], 75 ); | |
| 693 | - $url_demo = $theme['attributes'][4]['value']; | |
| 694 | - ?> | |
| 695 | - | |
| 696 | - <div id="thimpress-<?php echo esc_attr( $theme['id'] ); ?>" class="slide-item"> | |
| 697 | - <div class="slide-thumbnail"> | |
| 698 | - <a href="<?php echo esc_url_raw( $url ); ?>"> | |
| 699 | - <img src="<?php echo esc_url_raw( $theme['previews']['landscape_preview']['landscape_url'] ); ?>"/> | |
| 700 | - </a> | |
| 701 | - </div> | |
| 702 | - | |
| 703 | - <div class="slide-detail"> | |
| 704 | - <h2><a href="<?php echo esc_url_raw( $url ); ?>"><?php echo esc_html( $theme['name'] ); ?></a></h2> | |
| 705 | - <p class="slide-description description-full"> | |
| 706 | - <?php echo wp_kses_post( $full_description ); ?> | |
| 707 | - </p> | |
| 708 | - | |
| 709 | - <p class="slide-description description-short"> | |
| 710 | - <?php echo wp_kses_post( $short_description ); ?> | |
| 711 | - </p> | |
| 712 | - | |
| 713 | - <p class="slide-controls"> | |
| 714 | - <a href="<?php echo esc_url_raw( $url ); ?>" class="button button-primary" | |
| 715 | - target="_blank"><?php esc_html_e( 'Get it now', 'learnpress' ); ?></a> | |
| 716 | - <a href="<?php echo esc_url_raw( $url_demo ); ?>" class="button" | |
| 717 | - target="_blank"><?php esc_html_e( 'View Demo', 'learnpress' ); ?></a> | |
| 718 | - </p> | |
| 719 | - </div> | |
| 720 | - </div> | |
| 721 | - | |
| 722 | - <?php } ?> | |
| 723 | - </div> | |
| 724 | - <?php | |
| 725 | -} | |
| 726 | - | |
| 727 | -/** | |
| 728 | 480 | * Count number of orders between to dates |
| 729 | 481 | * |
| 730 | 482 | * @param string |
| 731 | 483 | * @param int |
| @@ -825,10 +577,11 @@ | ||
| 825 | 577 | * |
| 826 | 578 | * @param string |
| 827 | 579 | * |
| 828 | 580 | * @return int |
| 581 | + * @deprecated 4.2.6.9.3 | |
| 829 | 582 | */ |
| 830 | -function learn_press_get_courses_by_price( $fee ) { | |
| 583 | +/*function learn_press_get_courses_by_price( $fee ) { | |
| 831 | 584 | global $wpdb; |
| 832 | 585 | |
| 833 | 586 | $user_id = get_current_user_id(); |
| 834 | 587 | |
| @@ -851,9 +604,9 @@ | ||
| 851 | 604 | ) |
| 852 | 605 | ); |
| 853 | 606 | |
| 854 | 607 | return $courses; |
| 855 | -} | |
| 608 | +}*/ | |
| 856 | 609 | |
| 857 | 610 | /** |
| 858 | 611 | * Get data about students to render in chart |
| 859 | 612 | * |
| @@ -861,15 +614,16 @@ | ||
| 861 | 614 | * @param null $by |
| 862 | 615 | * @param float $time_ago |
| 863 | 616 | * |
| 864 | 617 | * @return array |
| 618 | + * @deprecated 4.2.6.9.3 | |
| 865 | 619 | */ |
| 866 | -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 ) { | |
| 867 | 621 | $labels = array(); |
| 868 | 622 | $datasets = array(); |
| 869 | 623 | |
| 870 | 624 | if ( is_null( $from ) ) { |
| 871 | - $from = current_time( 'mysql' ); | |
| 625 | + $from = current_time( 'mysql', 1 ); | |
| 872 | 626 | } |
| 873 | 627 | |
| 874 | 628 | if ( is_null( $by ) ) { |
| 875 | 629 | $by = 'days'; |
| @@ -903,9 +657,9 @@ | ||
| 903 | 657 | return array( |
| 904 | 658 | 'labels' => $labels, |
| 905 | 659 | 'datasets' => $datasets, |
| 906 | 660 | ); |
| 907 | -} | |
| 661 | +}*/ | |
| 908 | 662 | |
| 909 | 663 | /** |
| 910 | 664 | * Get data about students to render in chart |
| 911 | 665 | * |
| @@ -913,10 +667,11 @@ | ||
| 913 | 667 | * @param null $by |
| 914 | 668 | * @param float $time_ago |
| 915 | 669 | * |
| 916 | 670 | * @return array |
| 671 | + * @deprecated 4.2.6.9.3 | |
| 917 | 672 | */ |
| 918 | -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 ) { | |
| 919 | 674 | global $wpdb; |
| 920 | 675 | |
| 921 | 676 | $labels = array(); |
| 922 | 677 | $datasets = array(); |
| @@ -921,9 +676,9 @@ | ||
| 921 | 676 | $labels = array(); |
| 922 | 677 | $datasets = array(); |
| 923 | 678 | |
| 924 | 679 | if ( is_null( $from ) ) { |
| 925 | - $from = current_time( 'mysql' ); | |
| 680 | + $from = current_time( 'mysql', 1 ); | |
| 926 | 681 | } |
| 927 | 682 | |
| 928 | 683 | if ( is_null( $by ) ) { |
| 929 | 684 | $by = 'days'; |
| @@ -1054,9 +809,9 @@ | ||
| 1054 | 809 | 'labels' => $labels, |
| 1055 | 810 | 'datasets' => $datasets, |
| 1056 | 811 | 'sql' => $query, |
| 1057 | 812 | ); |
| 1058 | -} | |
| 813 | +}*/ | |
| 1059 | 814 | |
| 1060 | 815 | |
| 1061 | 816 | /** |
| 1062 | 817 | * Get data about students to render in chart |
| @@ -1065,10 +820,11 @@ | ||
| 1065 | 820 | * @param null $by |
| 1066 | 821 | * @param float $time_ago |
| 1067 | 822 | * |
| 1068 | 823 | * @return array |
| 824 | + * @deprecated 4.2.6.9.3 | |
| 1069 | 825 | */ |
| 1070 | -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 ) { | |
| 1071 | 827 | global $wpdb; |
| 1072 | 828 | |
| 1073 | 829 | $labels = array(); |
| 1074 | 830 | $datasets = array(); |
| @@ -1073,9 +829,9 @@ | ||
| 1073 | 829 | $labels = array(); |
| 1074 | 830 | $datasets = array(); |
| 1075 | 831 | |
| 1076 | 832 | if ( is_null( $from ) ) { |
| 1077 | - $from = current_time( 'mysql' ); | |
| 833 | + $from = current_time( 'mysql', 1 ); | |
| 1078 | 834 | } |
| 1079 | 835 | |
| 1080 | 836 | if ( is_null( $by ) ) { |
| 1081 | 837 | $by = 'days'; |
| @@ -1258,9 +1014,9 @@ | ||
| 1258 | 1014 | 'labels' => $labels, |
| 1259 | 1015 | 'datasets' => $datasets, |
| 1260 | 1016 | 'sql' => $query, |
| 1261 | 1017 | ); |
| 1262 | -} | |
| 1018 | +}*/ | |
| 1263 | 1019 | |
| 1264 | 1020 | |
| 1265 | 1021 | /** |
| 1266 | 1022 | * Get data about students to render in chart |
| @@ -1269,13 +1025,14 @@ | ||
| 1269 | 1025 | * @param null $by |
| 1270 | 1026 | * @param float $time_ago |
| 1271 | 1027 | * |
| 1272 | 1028 | * @return array |
| 1029 | + * @deprecated 4.2.6.9.3 | |
| 1273 | 1030 | */ |
| 1274 | -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 ) { | |
| 1275 | 1032 | global $wpdb; |
| 1276 | - // var_dump( current_user_can(LP_TEACHER_ROLE) ); | |
| 1277 | - // exit(); | |
| 1033 | + $sql_join = ''; | |
| 1034 | + | |
| 1278 | 1035 | $report_sales_by = learn_press_get_request( 'report_sales_by' ); |
| 1279 | 1036 | $course_id = learn_press_get_request( 'course_id' ); |
| 1280 | 1037 | $cat_id = learn_press_get_request( 'cat_id' ); |
| 1281 | 1038 | |
| @@ -1281,9 +1038,9 @@ | ||
| 1281 | 1038 | |
| 1282 | 1039 | $labels = array(); |
| 1283 | 1040 | $datasets = array(); |
| 1284 | 1041 | if ( is_null( $from ) ) { |
| 1285 | - $from = current_time( 'mysql' ); | |
| 1042 | + $from = current_time( 'mysql', 1 ); | |
| 1286 | 1043 | } |
| 1287 | 1044 | if ( is_null( $by ) ) { |
| 1288 | 1045 | $by = 'days'; |
| 1289 | 1046 | } |
| @@ -1325,15 +1082,16 @@ | ||
| 1325 | 1082 | } |
| 1326 | 1083 | |
| 1327 | 1084 | $query_join = ''; |
| 1328 | 1085 | $query_where = ''; |
| 1086 | + $sql_join = ''; | |
| 1329 | 1087 | if ( 'course' === $report_sales_by ) { |
| 1330 | 1088 | $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` " |
| 1331 | - . ' ON o.ID=lpoi.order_id ' | |
| 1332 | - . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim " | |
| 1333 | - . ' ON lpoi.order_item_id=loim.learnpress_order_item_id ' | |
| 1334 | - . " AND loim.meta_key='_course_id' " | |
| 1335 | - . ' 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 '; | |
| 1336 | 1094 | if ( current_user_can( LP_TEACHER_ROLE ) ) { |
| 1337 | 1095 | $user_id = learn_press_get_current_user_id(); |
| 1338 | 1096 | $sql_join .= $wpdb->prepare( |
| 1339 | 1097 | ' AND CAST(loim.meta_value AS SIGNED) IN ' |
| @@ -1345,18 +1103,18 @@ | ||
| 1345 | 1103 | $query_join .= $wpdb->prepare( $sql_join, $course_id ); |
| 1346 | 1104 | |
| 1347 | 1105 | } elseif ( 'category' === $report_sales_by ) { |
| 1348 | 1106 | $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` " |
| 1349 | - . ' ON o.ID=lpoi.order_id ' | |
| 1350 | - . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim " | |
| 1351 | - . ' ON lpoi.order_item_id=loim.learnpress_order_item_id ' | |
| 1352 | - . " AND loim.meta_key='_course_id' " | |
| 1353 | - . ' AND CAST(loim.meta_value AS SIGNED) IN(' | |
| 1354 | - // sub query | |
| 1355 | - . ' SELECT tr.object_id ' | |
| 1356 | - . " FROM {$wpdb->prefix}term_taxonomy tt INNER JOIN {$wpdb->prefix}term_relationships tr " | |
| 1357 | - . " ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='course_category' " | |
| 1358 | - . ' 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)'; | |
| 1359 | 1117 | $query_join .= $wpdb->prepare( $sql_join, $cat_id ); |
| 1360 | 1118 | } |
| 1361 | 1119 | if ( current_user_can( LP_TEACHER_ROLE ) ) { |
| 1362 | 1120 | $user_id = learn_press_get_current_user_id(); |
| @@ -1464,19 +1222,20 @@ | ||
| 1464 | 1222 | 'labels' => $labels, |
| 1465 | 1223 | 'datasets' => $datasets, |
| 1466 | 1224 | 'sql' => $query, |
| 1467 | 1225 | ); |
| 1468 | -} | |
| 1226 | +}*/ | |
| 1469 | 1227 | |
| 1470 | 1228 | /** |
| 1471 | 1229 | * Get data about courses to render in the chart |
| 1472 | 1230 | * |
| 1473 | 1231 | * @return array |
| 1232 | + * @deprecated 4.2.6.9.3 | |
| 1474 | 1233 | */ |
| 1475 | -function learn_press_get_chart_courses2() { | |
| 1234 | +/*function learn_press_get_chart_courses2() { | |
| 1476 | 1235 | $labels = array( |
| 1477 | - __( 'Pending Courses / Publish Courses', 'learnpress' ), | |
| 1478 | - __( 'Free Courses / Priced Courses', 'learnpress' ), | |
| 1236 | + __( 'Pending Courses/Publish Courses', 'learnpress' ), | |
| 1237 | + __( 'Free Courses/Paid Courses', 'learnpress' ), | |
| 1479 | 1238 | ); |
| 1480 | 1239 | |
| 1481 | 1240 | $datasets = array(); |
| 1482 | 1241 | $datasets[0]['data'] = array( |
| @@ -1498,9 +1257,9 @@ | ||
| 1498 | 1257 | return array( |
| 1499 | 1258 | 'labels' => $labels, |
| 1500 | 1259 | 'datasets' => $datasets, |
| 1501 | 1260 | ); |
| 1502 | -} | |
| 1261 | +}*/ | |
| 1503 | 1262 | |
| 1504 | 1263 | /** |
| 1505 | 1264 | * Get colors setting up by admin user |
| 1506 | 1265 | * |
| @@ -1644,31 +1403,8 @@ | ||
| 1644 | 1403 | |
| 1645 | 1404 | return $slug; |
| 1646 | 1405 | } |
| 1647 | 1406 | |
| 1648 | -function learn_press_request_query( $vars = array() ) { | |
| 1649 | - global $typenow, $wp_query, $wp_post_statuses; | |
| 1650 | - | |
| 1651 | - if ( LP_ORDER_CPT === $typenow ) { | |
| 1652 | - if ( ! isset( $vars['post_status'] ) ) { | |
| 1653 | - $post_statuses = learn_press_get_order_statuses(); | |
| 1654 | - | |
| 1655 | - foreach ( $post_statuses as $status => $value ) { | |
| 1656 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { | |
| 1657 | - unset( $post_statuses[ $status ] ); | |
| 1658 | - } | |
| 1659 | - } | |
| 1660 | - | |
| 1661 | - $vars['post_status'] = array_keys( $post_statuses ); | |
| 1662 | - | |
| 1663 | - } | |
| 1664 | - } | |
| 1665 | - | |
| 1666 | - return $vars; | |
| 1667 | -} | |
| 1668 | - | |
| 1669 | -add_filter( 'request', 'learn_press_request_query', 0 ); | |
| 1670 | - | |
| 1671 | 1407 | function _learn_press_reset_course_data() { |
| 1672 | 1408 | if ( empty( $_REQUEST['reset-course-data'] ) ) { |
| 1673 | 1409 | return false; |
| 1674 | 1410 | } |
| @@ -1854,9 +1590,13 @@ | ||
| 1854 | 1590 | 'post_excerpt' => $post->post_excerpt, |
| 1855 | 1591 | 'post_parent' => $post->post_parent, |
| 1856 | 1592 | 'post_password' => $post->post_password, |
| 1857 | 1593 | 'post_status' => 'draft', |
| 1858 | - '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 | + ), | |
| 1859 | 1599 | 'post_type' => $post->post_type, |
| 1860 | 1600 | 'to_ping' => $post->to_ping, |
| 1861 | 1601 | 'menu_order' => $post->menu_order, |
| 1862 | 1602 | 'exclude_meta' => array(), |
| @@ -1940,9 +1680,9 @@ | ||
| 1940 | 1680 | } |
| 1941 | 1681 | |
| 1942 | 1682 | for ( $j = $i + 1; $j < count( $ktypes ); $j ++ ) { |
| 1943 | 1683 | if ( isset( $question_types[ $ktypes[ $j ] ], $question_types[ $ktypes[ $max ] ] ) |
| 1944 | - && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ] | |
| 1684 | + && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ] | |
| 1945 | 1685 | ) { |
| 1946 | 1686 | $max = $j; |
| 1947 | 1687 | } |
| 1948 | 1688 | } |
| @@ -2048,12 +1788,15 @@ | ||
| 2048 | 1788 | global $wpdb; |
| 2049 | 1789 | |
| 2050 | 1790 | $new_quiz_id = learn_press_duplicate_post( $quiz_id, $args, true ); |
| 2051 | 1791 | $quiz = LP_Quiz::get_quiz( $quiz_id ); |
| 2052 | - $questions = $quiz->get_questions(); | |
| 1792 | + if ( ! $quiz ) { | |
| 1793 | + return 0; | |
| 1794 | + } | |
| 2053 | 1795 | |
| 1796 | + $questions = $quiz->get_question_ids(); | |
| 1797 | + | |
| 2054 | 1798 | if ( $questions ) { |
| 2055 | - $questions = array_keys( $questions ); | |
| 2056 | 1799 | foreach ( $questions as $question_id ) { |
| 2057 | 1800 | $new_question_id = learn_press_duplicate_post( $question_id ); |
| 2058 | 1801 | |
| 2059 | 1802 | $sql = $wpdb->prepare( |
| @@ -2133,9 +1876,9 @@ | ||
| 2133 | 1876 | $labels = array(); |
| 2134 | 1877 | $datasets = array(); |
| 2135 | 1878 | |
| 2136 | 1879 | if ( is_null( $from ) ) { |
| 2137 | - $from = current_time( 'mysql' ); | |
| 1880 | + $from = current_time( 'mysql', 1 ); | |
| 2138 | 1881 | } |
| 2139 | 1882 | |
| 2140 | 1883 | if ( is_null( $by ) ) { |
| 2141 | 1884 | $by = 'days'; |
| @@ -2415,53 +2158,8 @@ | ||
| 2415 | 2158 | } |
| 2416 | 2159 | } |
| 2417 | 2160 | |
| 2418 | 2161 | /** |
| 2419 | - * Filter to modal search items to void filter the posts by author. | |
| 2420 | - * | |
| 2421 | - * @param int|string $context_id | |
| 2422 | - * @param string $context | |
| 2423 | - * | |
| 2424 | - * @return bool|int|string | |
| 2425 | - * @since 3.0.4 | |
| 2426 | - */ | |
| 2427 | -function learn_press_modal_search_items_context( $context_id, $context ) { | |
| 2428 | - if ( 'order-items' === $context ) { | |
| 2429 | - $context_id = false; | |
| 2430 | - } | |
| 2431 | - | |
| 2432 | - return $context_id; | |
| 2433 | -} | |
| 2434 | - | |
| 2435 | -add_filter( 'learn-press/modal-search-items/context-id', 'learn_press_modal_search_items_context', 10, 2 ); | |
| 2436 | - | |
| 2437 | -/** | |
| 2438 | - * Sync post meta when saving post type. | |
| 2439 | - * | |
| 2440 | - * @param int $post_id | |
| 2441 | - * | |
| 2442 | - * @since 3.2.0 | |
| 2443 | - * @editor tungnx | |
| 2444 | - * @modify 1.4.1 - comment - not use | |
| 2445 | - */ | |
| 2446 | -/*function learn_press_maybe_sync_data( $post_id ) { | |
| 2447 | - $post_type = get_post_type( $post_id ); | |
| 2448 | - | |
| 2449 | - switch ( $post_type ) { | |
| 2450 | - case LP_COURSE_CPT: | |
| 2451 | - LP_Repair_Database::instance()->sync_user_courses(); | |
| 2452 | - break; | |
| 2453 | - case LP_LESSON_CPT: | |
| 2454 | - break; | |
| 2455 | - case LP_QUIZ_CPT: | |
| 2456 | - break; | |
| 2457 | - default: | |
| 2458 | - } | |
| 2459 | -}*/ | |
| 2460 | - | |
| 2461 | -//add_action( 'save_post', 'learn_press_maybe_sync_data' ); | |
| 2462 | - | |
| 2463 | -/** | |
| 2464 | 2162 | * Return id of current screen. |
| 2465 | 2163 | * |
| 2466 | 2164 | * @return bool|string |
| 2467 | 2165 | * @since 3.2.6 |
| @@ -2466,101 +2164,12 @@ | ||
| 2466 | 2164 | * @return bool|string |
| 2467 | 2165 | * @since 3.2.6 |
| 2468 | 2166 | */ |
| 2469 | 2167 | function learn_press_get_screen_id() { |
| 2168 | + _deprecated_function( __METHOD__, '4.2.3.6' ); | |
| 2470 | 2169 | $screen = get_current_screen(); |
| 2471 | 2170 | $screen_id = $screen ? $screen->id : false; |
| 2472 | 2171 | |
| 2473 | 2172 | return $screen_id; |
| 2474 | -} | |
| 2475 | - | |
| 2476 | -/** | |
| 2477 | - * Check if current screen is a page of LP or | |
| 2478 | - * editing post type of LP such as course, lesson, etc... | |
| 2479 | - * | |
| 2480 | - * @return bool | |
| 2481 | - * @since 3.2.6 | |
| 2482 | - */ | |
| 2483 | -/* | |
| 2484 | -function learn_press_is_admin_page() { | |
| 2485 | - $screen_id = learn_press_get_screen_id(); | |
| 2486 | - $is_learnpress = false; | |
| 2487 | - | |
| 2488 | - $post_types = apply_filters( | |
| 2489 | - 'learn-press/admin-post-type-pages', | |
| 2490 | - array( LP_COURSE_CPT, LP_QUIZ_CPT, LP_LESSON_CPT, LP_QUESTION_CPT, LP_ORDER_CPT, 'lp_cert', 'lp_assignment' ) | |
| 2491 | - ); | |
| 2492 | - foreach ( $post_types as $post_type ) { | |
| 2493 | - if ( in_array( $screen_id, array( "edit-{$post_type}", $post_type ) ) ) { | |
| 2494 | - $is_learnpress = true; | |
| 2495 | - break; | |
| 2496 | - } | |
| 2497 | - } | |
| 2498 | - | |
| 2499 | - if ( strpos( $screen_id, 'learnpress_page_' ) === 0 ) { | |
| 2500 | - $is_learnpress = true; | |
| 2501 | - } | |
| 2502 | - | |
| 2503 | - return apply_filters( 'learn-press/is-admin-page', $is_learnpress, $screen_id ); | |
| 2504 | -}*/ | |
| 2505 | - | |
| 2506 | -function learn_press_get_orders_status_chart_data() { | |
| 2507 | - $data = array( | |
| 2508 | - 'type' => 'pie', | |
| 2509 | - 'data' => array( | |
| 2510 | - 'labels' => array(), | |
| 2511 | - 'datasets' => array( | |
| 2512 | - array( | |
| 2513 | - 'label' => '# of Votes', | |
| 2514 | - 'data' => array(), | |
| 2515 | - 'backgroundColor' => array( | |
| 2516 | - 'rgba(54, 162, 235, 0.2)', | |
| 2517 | - 'rgba(255, 206, 86, 0.2)', | |
| 2518 | - 'rgba(75, 192, 192, 0.2)', | |
| 2519 | - 'rgba(153, 102, 255, 0.2)', | |
| 2520 | - 'rgba(255, 159, 64, 0.2)', | |
| 2521 | - ), | |
| 2522 | - 'borderColor' => array( | |
| 2523 | - 'rgba(54, 162, 235, 1)', | |
| 2524 | - 'rgba(255, 206, 86, 1)', | |
| 2525 | - 'rgba(75, 192, 192, 1)', | |
| 2526 | - 'rgba(153, 102, 255, 1)', | |
| 2527 | - 'rgba(255, 159, 64, 1)', | |
| 2528 | - ), | |
| 2529 | - 'borderWidth' => 1, | |
| 2530 | - ), | |
| 2531 | - ), | |
| 2532 | - ), | |
| 2533 | - 'options' => array( | |
| 2534 | - 'scales' => array( | |
| 2535 | - 'yAxes' => array( | |
| 2536 | - array( | |
| 2537 | - 'ticks' => array( | |
| 2538 | - 'beginAtZero' => true, | |
| 2539 | - ), | |
| 2540 | - ), | |
| 2541 | - ), | |
| 2542 | - ), | |
| 2543 | - ), | |
| 2544 | - ); | |
| 2545 | - | |
| 2546 | - $order_statuses = learn_press_get_order_statuses( true, true ); | |
| 2547 | - $specific_statuses = array( 'lp-completed', 'lp-failed' ); | |
| 2548 | - | |
| 2549 | - foreach ( $order_statuses as $status ) { | |
| 2550 | - if ( ! in_array( $status, $specific_statuses ) ) { | |
| 2551 | - $specific_statuses[] = $status; | |
| 2552 | - } | |
| 2553 | - } | |
| 2554 | - | |
| 2555 | - $labels = learn_press_get_order_statuses(); | |
| 2556 | - $counts = learn_press_count_orders( array( 'status' => $specific_statuses ) ); | |
| 2557 | - | |
| 2558 | - foreach ( $counts as $k => $v ) { | |
| 2559 | - $data['data']['labels'][] = isset( $labels[ $k ] ) ? $labels[ $k ] : 'Untitled'; | |
| 2560 | - $data['data']['datasets'][0]['data'][] = $v; | |
| 2561 | - } | |
| 2562 | - | |
| 2563 | - return $data; | |
| 2564 | 2173 | } |
| 2565 | 2174 | |
| 2566 | 2175 | require_once 'class-lp-post-type-actions.php'; |