Plugin Directory

Changeset 3435885


Ignore:
Timestamp:
01/09/2026 12:13:53 PM (6 weeks ago)
Author:
coursebox
Message:

Update handle import

Location:
course-box
Files:
19 added
2 edited

Legend:

Unmodified
Added
Removed
  • course-box/trunk/course-box.php

    r3372308 r3435885  
    44 * Plugin URI:
    55 * Description: A WordPress plugin that integrates with WooCommerce to import products from an external API with advanced features like pagination, search, and import.
    6  * Version: 1.0.3
     6 * Version: 1.0.4
    77 * Author: Coursebox Pty Ltd
    88 * Author URI: https://www.coursebox.ai/
     
    296296         */
    297297        public function handle_import_ajax() {
    298             check_ajax_referer('course_box_nonce', 'nonce');
    299            
    300             if (!current_user_can('manage_options')) {
    301                 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'course-box' ) );
    302             }
    303            
    304              $course_data_raw = isset( $_POST['course_data'] )
    305             ? wp_unslash( sanitize_text_field( wp_unslash( $_POST['course_data'] ) ) )
    306             : '';
    307             $course_data = json_decode(stripslashes($course_data_raw), true);
    308            
    309             if (!$course_data) {
    310                 wp_send_json_error(__('Invalid course data', 'course-box'));
    311             }
    312            
    313             $result = $this->import_course($course_data);
    314            
    315             if ($result['success']) {
    316                 wp_send_json_success($result['data']);
    317             } else {
    318                 wp_send_json_error($result['data']);
    319             }
    320         }
     298       
     299            // 1. Security
     300            check_ajax_referer('course_box_nonce', 'nonce');
     301       
     302            if ( ! current_user_can('manage_options') ) {
     303                wp_send_json_error(
     304                    __('You do not have sufficient permissions to access this page.', 'course-box'),
     305                    403
     306                );
     307            }
     308       
     309            // 2. Validate presence
     310            if ( empty($_POST['course_data']) ) {
     311                wp_send_json_error(__('Missing course data', 'course-box'), 400);
     312            }
     313       
     314            // 3. Get RAW JSON (do NOT sanitize)
     315            $course_data_raw = wp_unslash($_POST['course_data']);
     316       
     317            // 4. Decode JSON
     318            $course_data = json_decode($course_data_raw, true);
     319       
     320            // 5. Validate JSON
     321            if ( json_last_error() !== JSON_ERROR_NONE || ! is_array($course_data) ) {
     322                wp_send_json_error(
     323                    __('Invalid course data', 'course-box') . ': ' . json_last_error_msg(),
     324                    400
     325                );
     326            }
     327       
     328            // 6. Import
     329            $result = $this->import_course($course_data);
     330       
     331            // 7. Response
     332            if ( ! empty($result['success']) ) {
     333                wp_send_json_success($result['data']);
     334            }
     335       
     336            wp_send_json_error(
     337                $result['data'] ?? __('Import failed', 'course-box'),
     338                500
     339            );
     340        }
    321341       
    322342        /**
  • course-box/trunk/readme.txt

    r3372308 r3435885  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77Requires PHP: 7.4
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.