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/class-lp-admin-ajax.php +40 -44 4.4.04.4.8 View file →
@@ -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' ) ) {
@@ -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>&nbsp;';
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 }