| @@ -11,9 +11,11 @@ | ||
| 11 | 11 | /** |
| 12 | 12 | * Prevent loading this file directly |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | +use LearnPress\Helpers\Response; | |
| 15 | 16 | use LearnPress\Helpers\Template; |
| 17 | +use LearnPress\Models\UserModel; | |
| 16 | 18 | |
| 17 | 19 | defined( 'ABSPATH' ) || exit(); |
| 18 | 20 | |
| 19 | 21 | if ( ! class_exists( 'LP_Admin_Ajax' ) ) { |
| @@ -52,9 +54,9 @@ | ||
| 52 | 54 | |
| 53 | 55 | do_action( 'learn-press/ajax/admin-load', __CLASS__ ); |
| 54 | 56 | |
| 55 | 57 | $ajax_events = array( |
| 56 | - 'search_items' => 'modal_search_items', | |
| 58 | + //'search_items' => 'modal_search_items', | |
| 57 | 59 | 'update-payment-order', |
| 58 | 60 | // Update ordering of payments when user changing. |
| 59 | 61 | 'update-payment-status', |
| 60 | 62 | // Enable type payment |
| @@ -59,14 +61,14 @@ | ||
| 59 | 61 | 'update-payment-status', |
| 60 | 62 | // Enable type payment |
| 61 | 63 | |
| 62 | 64 | // admin editor |
| 63 | - 'admin_course_editor', | |
| 64 | - 'admin_quiz_editor', | |
| 65 | - 'admin_question_editor', | |
| 65 | + //'admin_course_editor', | |
| 66 | + //'admin_quiz_editor', | |
| 67 | + //'admin_question_editor', | |
| 66 | 68 | 'duplicator', |
| 67 | 69 | // Duplicate course, lesson, quiz, question. |
| 68 | - 'modal_search_items', | |
| 70 | + //'modal_search_items', | |
| 69 | 71 | // Used to search courses on LP Order |
| 70 | 72 | //'modal_search_users', |
| 71 | 73 | // Used to search users on LP Order |
| 72 | 74 | 'add_items_to_order', |
| @@ -74,9 +76,9 @@ | ||
| 74 | 76 | 'remove_items_from_order', |
| 75 | 77 | // Used to remove items from LP Order |
| 76 | 78 | 'update_email_status', |
| 77 | 79 | // Use for enable email on LP Settings |
| 78 | - 'search-authors', | |
| 80 | + //'search-authors', | |
| 79 | 81 | // Used to search username on input some page (list courses, lp orders, quizzes, questions... on the Backend |
| 80 | 82 | //'skip-notice-install', |
| 81 | 83 | ); |
| 82 | 84 | |
| @@ -99,9 +101,9 @@ | ||
| 99 | 101 | |
| 100 | 102 | /** |
| 101 | 103 | * Search user on some pages on the Backend |
| 102 | 104 | */ |
| 103 | - public static function search_authors() { | |
| 105 | + /*public static function search_authors() { | |
| 104 | 106 | $args = array( |
| 105 | 107 | 'orderby' => 'name', |
| 106 | 108 | 'order' => 'ASC', |
| 107 | 109 | 'search' => sprintf( '*%s*', esc_attr( LP_Request::get_string( 'term' ) ) ), |
| @@ -125,9 +127,9 @@ | ||
| 125 | 127 | 'results' => $users, |
| 126 | 128 | ) |
| 127 | 129 | ); |
| 128 | 130 | die(); |
| 129 | - } | |
| 131 | + }*/ | |
| 130 | 132 | |
| 131 | 133 | /** |
| 132 | 134 | * Handle ajax admin course editor. |
| 133 | 135 | * |
| @@ -132,9 +134,9 @@ | ||
| 132 | 134 | * Handle ajax admin course editor. |
| 133 | 135 | * |
| 134 | 136 | * @since 3.0.0 |
| 135 | 137 | */ |
| 136 | - public static function admin_course_editor() { | |
| 138 | + /*public static function admin_course_editor() { | |
| 137 | 139 | $editor = LP_Admin_Editor::get_editor_course(); |
| 138 | 140 | self::admin_editor( $editor ); |
| 139 | 141 | } |
| 140 | 142 | |
| @@ -142,9 +144,9 @@ | ||
| 142 | 144 | * Handle ajax admin question editor. |
| 143 | 145 | * |
| 144 | 146 | * @since 3.0.0 |
| 145 | 147 | */ |
| 146 | - public static function admin_question_editor() { | |
| 148 | + /*public static function admin_question_editor() { | |
| 147 | 149 | $editor = LP_Admin_Editor::get_editor_question(); |
| 148 | 150 | self::admin_editor( $editor ); |
| 149 | 151 | } |
| 150 | 152 | |
| @@ -152,9 +154,9 @@ | ||
| 152 | 154 | * Handle ajax admin quiz editor. |
| 153 | 155 | * |
| 154 | 156 | * @since 3.0.0 |
| 155 | 157 | */ |
| 156 | - public static function admin_quiz_editor() { | |
| 158 | + /*public static function admin_quiz_editor() { | |
| 157 | 159 | $editor = LP_Admin_Editor::get_editor_quiz(); |
| 158 | 160 | self::admin_editor( $editor ); |
| 159 | 161 | } |
| 160 | 162 | |
| @@ -162,9 +164,9 @@ | ||
| 162 | 164 | * @param LP_Admin_Editor $editor |
| 163 | 165 | * |
| 164 | 166 | * @since 3.0.2 |
| 165 | 167 | */ |
| 166 | - public static function admin_editor( &$editor ) { | |
| 168 | + /*public static function admin_editor( &$editor ) { | |
| 167 | 169 | $result = $editor->dispatch(); |
| 168 | 170 | |
| 169 | 171 | if ( is_wp_error( $result ) ) { |
| 170 | 172 | learn_press_send_json_error( $result->get_error_message() ); |
| @@ -172,9 +174,9 @@ | ||
| 172 | 174 | learn_press_send_json_error(); |
| 173 | 175 | } |
| 174 | 176 | |
| 175 | 177 | learn_press_send_json_success( $result ); |
| 176 | - } | |
| 178 | + }*/ | |
| 177 | 179 | |
| 178 | 180 | /** |
| 179 | 181 | * Duplicate course, lesson, quiz, question. |
| 180 | 182 | * |
| @@ -351,9 +353,9 @@ | ||
| 351 | 353 | |
| 352 | 354 | /** |
| 353 | 355 | * Search items by requesting params. |
| 354 | 356 | */ |
| 355 | - public static function modal_search_items() { | |
| 357 | + /*public static function modal_search_items() { | |
| 356 | 358 | $term = LP_Request::get_param( 'term' ); |
| 357 | 359 | $type = LP_Request::get_param( 'type' ); |
| 358 | 360 | $context = LP_Request::get_param( 'context' ); |
| 359 | 361 | $context_id = LP_Request::get_param( 'context_id' ); |
| @@ -388,9 +390,9 @@ | ||
| 388 | 390 | 'nav' => $search->get_pagination(), |
| 389 | 391 | 'items' => $search->get_items(), |
| 390 | 392 | ) |
| 391 | 393 | ); |
| 392 | - } | |
| 394 | + }*/ | |
| 393 | 395 | |
| 394 | 396 | /** |
| 395 | 397 | * Search items by requesting params. |
| 396 | 398 | * |
| @@ -498,9 +500,9 @@ | ||
| 498 | 500 | $currency_symbol = learn_press_get_currency_symbol( $order_data['currency'] ); |
| 499 | 501 | $order_data['subtotal_html'] = learn_press_format_price( $order_data['subtotal'], $currency_symbol ); |
| 500 | 502 | $order_data['total_html'] = learn_press_format_price( $order_data['total'], $currency_symbol ); |
| 501 | 503 | $order_items = $order->get_items(); |
| 502 | - $html = ''; | |
| 504 | + $html = ''; | |
| 503 | 505 | if ( $order_items ) { |
| 504 | 506 | foreach ( $order_items as $item ) { |
| 505 | 507 | ob_start(); |
| 506 | 508 | include learn_press_get_admin_view( 'meta-boxes/order/order-item.php' ); |
| @@ -617,39 +619,38 @@ | ||
| 617 | 619 | * |
| 618 | 620 | * @note tungnnx checked use |
| 619 | 621 | */ |
| 620 | 622 | public static function create_page() { |
| 621 | - $response = array( | |
| 622 | - 'code' => 0, | |
| 623 | - 'message' => '', | |
| 624 | - ); | |
| 623 | + $response = new Response(); | |
| 625 | 624 | |
| 626 | - /** | |
| 627 | - * Check valid | |
| 628 | - * | |
| 629 | - * 1. Capability - user can edit pages (add\edit\delete) | |
| 630 | - * 2. Check nonce return true | |
| 631 | - * 3. param post page_name not empty | |
| 632 | - * | |
| 633 | - * @since 3.2.6.8 | |
| 634 | - * @author tungnx | |
| 635 | - */ | |
| 636 | - if ( ! current_user_can( 'edit_pages' ) || empty( $_POST['page_name'] ) ) { | |
| 637 | - $response['message'] = 'Request invalid'; | |
| 638 | - learn_press_send_json( $response ); | |
| 639 | - } | |
| 625 | + try { | |
| 626 | + /** | |
| 627 | + * Check valid | |
| 628 | + * | |
| 629 | + * 1. Capability - user can edit pages (add\edit\delete) | |
| 630 | + * 2. Check nonce return true | |
| 631 | + * 3. param post page_name not empty | |
| 632 | + * | |
| 633 | + * @since 3.2.6.8 | |
| 634 | + */ | |
| 635 | + if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) | |
| 636 | + || empty( $_POST['page_name'] ) ) { | |
| 637 | + throw new Exception( 'Request invalid' ); | |
| 638 | + } | |
| 640 | 639 | |
| 641 | - // Check nonce | |
| 642 | - $nonce = LP_Request::get_param( 'nonce' ); | |
| 643 | - if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) ) { | |
| 644 | - $response['message'] = 'Request invalid'; | |
| 645 | - learn_press_send_json( $response ); | |
| 646 | - } | |
| 640 | + // Check nonce | |
| 641 | + $nonce = LP_Request::get_param( 'nonce' ); | |
| 642 | + if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) ) { | |
| 643 | + throw new Exception( 'Request invalid' ); | |
| 644 | + } | |
| 647 | 645 | |
| 648 | - $page_name = LP_Helper::sanitize_params_submitted( $_POST['page_name'] ); | |
| 649 | - $field_name = LP_Request::get_param( 'field_name' ); | |
| 646 | + $page_name = LP_Helper::sanitize_params_submitted( $_POST['page_name'] ); | |
| 647 | + $field_name = LP_Request::get_param( 'field_name' ); | |
| 650 | 648 | |
| 651 | - if ( $page_name ) { | |
| 649 | + if ( ! $page_name ) { | |
| 650 | + throw new Exception( __( 'Empty page name!', 'learnpress' ) ); | |
| 651 | + } | |
| 652 | + | |
| 652 | 653 | $data_create_page = array( |
| 653 | 654 | 'post_title' => $page_name, |
| 654 | 655 | ); |
| 655 | 656 | |
| @@ -654,24 +655,19 @@ | ||
| 654 | 655 | ); |
| 655 | 656 | |
| 656 | 657 | $page_id = LP_Helper::create_page( $data_create_page, $field_name ); |
| 657 | 658 | |
| 658 | - if ( $page_id ) { | |
| 659 | - $response['code'] = 1; | |
| 660 | - $response['message'] = 'create page success'; | |
| 661 | - $response['page'] = get_post( $page_id ); | |
| 662 | - $html = learn_press_pages_dropdown( '', '', array( 'echo' => false ) ); | |
| 663 | - preg_match_all( '!value=\"([0-9]+)\"!', $html, $matches ); | |
| 664 | - $response['positions'] = $matches[1]; | |
| 665 | - $response['html'] = '<a href="' . get_edit_post_link( $page_id ) . '" target="_blank">' . __( 'Edit Page', 'learnpress' ) . '</a> '; | |
| 666 | - $response['html'] .= '<a href="' . get_permalink( $page_id ) . '" target="_blank">' . __( 'View Page', 'learnpress' ) . '</a>'; | |
| 667 | - } else { | |
| 668 | - $response['error'] = __( 'Error! Page creation failed. Please try again.', 'learnpress' ); | |
| 659 | + if ( ! $page_id ) { | |
| 660 | + throw new Exception( __( 'Error! Page creation failed. Please try again.', 'learnpress' ) ); | |
| 669 | 661 | } |
| 670 | - } else { | |
| 671 | - $response['error'] = __( 'Empty page name!', 'learnpress' ); | |
| 662 | + | |
| 663 | + $response->status = Response::STATUS_SUCCESS; | |
| 664 | + $response->message = 'create page success'; | |
| 665 | + } catch ( Exception $e ) { | |
| 666 | + $response->message = $e->getMessage(); | |
| 672 | 667 | } |
| 673 | - learn_press_send_json( $response ); | |
| 668 | + | |
| 669 | + wp_send_json( $response ); | |
| 674 | 670 | } |
| 675 | 671 | |
| 676 | 672 | /** |
| 677 | 673 | * Get edit|view link of a page |
| @@ -680,11 +676,11 @@ | ||
| 680 | 676 | $page_id = (int) $_REQUEST['page_id'] ?? 0; |
| 681 | 677 | ?> |
| 682 | 678 | |
| 683 | 679 | <a href="<?php echo get_edit_post_link( $page_id ); ?>" |
| 684 | - target="_blank"><?php _e( 'Edit Page', 'learnpress' ); ?></a> | |
| 680 | + target="_blank"><?php _e( 'Edit Page', 'learnpress' ); ?></a> | |
| 685 | 681 | <a href="<?php echo get_permalink( $page_id ); ?>" |
| 686 | - target="_blank"><?php _e( 'View Page', 'learnpress' ); ?></a> | |
| 682 | + target="_blank"><?php _e( 'View Page', 'learnpress' ); ?></a> | |
| 687 | 683 | |
| 688 | 684 | <?php |
| 689 | 685 | die(); |
| 690 | 686 | } |