'Password must be at least 8 characters.' ) ); } $user = AIMSLMS_Auth_Register::create_user( array( 'aimslms_first_name' => isset( $_POST['aimslms_first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['aimslms_first_name'] ) ) : '', 'aimslms_last_name' => isset( $_POST['aimslms_last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['aimslms_last_name'] ) ) : '', 'aimslms_username' => isset( $_POST['aimslms_username'] ) ? sanitize_text_field( wp_unslash( $_POST['aimslms_username'] ) ) : '', 'aimslms_email' => isset( $_POST['aimslms_email'] ) ? sanitize_email( wp_unslash( $_POST['aimslms_email'] ) ) : '', 'aimslms_password' => $password, ) ); if ( is_wp_error( $user ) ) { wp_send_json_error( array( 'message' => $user->get_error_message() ) ); } wp_send_json_success( array( 'message' => 'Registration successful. Check your email to verify your account.', ) ); } /** * Authenticates a user from the login form. */ public function login() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); $email = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password value is used verbatim for authentication, not output or sanitized. $password = isset( $_POST['password'] ) ? wp_unslash( $_POST['password'] ) : ''; $remember = ! empty( $_POST['remember'] ); $user = AIMSLMS_Auth_Login::authenticate( $email, $password, $remember ); if ( is_wp_error( $user ) ) { wp_send_json_error( array( 'message' => $user->get_error_message(), ) ); } // Redirect based on role. $account_page = get_option( 'aimslms_account_page' ); wp_send_json_success( array( 'message' => __( 'Login successful.', 'aims-infosoft-lms' ), 'redirect' => get_permalink( $account_page ), ) ); } /** * Sends a password reset link for the given email or username. */ public function forgot_password() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( empty( $_POST['email'] ) ) { wp_send_json_error( array( 'message' => __( 'Please enter your email or username.', 'aims-infosoft-lms' ), ) ); } $input = sanitize_text_field( wp_unslash( $_POST['email'] ) ); if ( is_email( $input ) ) { $user = get_user_by( 'email', $input ); } else { $user = get_user_by( 'login', $input ); } if ( ! $user ) { wp_send_json_error( array( 'message' => __( 'Reset link will be sent.', 'aims-infosoft-lms' ), ) ); } $result = AIMSLMS_Auth_Password::send_reset_link( $user->user_email ); if ( is_wp_error( $result ) ) { wp_send_json_error( array( 'message' => $result->get_error_message(), ) ); } wp_send_json_success( array( 'message' => __( 'Reset link has been sent.', 'aims-infosoft-lms' ), ) ); } /** * Resets a user's password from a valid reset token. */ public function reset_password() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); $user_id = absint( $_POST['uid'] ?? 0 ); $token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password value is used verbatim for hashing, not output or sanitized. $new_password = isset( $_POST['new_password'] ) ? wp_unslash( $_POST['new_password'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password value is used verbatim for comparison, not output or sanitized. $confirm_password = isset( $_POST['confirm_password'] ) ? wp_unslash( $_POST['confirm_password'] ) : ''; if ( ! $user_id || empty( $token ) ) { wp_send_json_error( array( 'message' => __( 'Invalid or expired reset link.', 'aims-infosoft-lms' ), ) ); } if ( empty( $new_password ) || empty( $confirm_password ) ) { wp_send_json_error( array( 'message' => __( 'All fields are required.', 'aims-infosoft-lms' ), ) ); } if ( $new_password !== $confirm_password ) { wp_send_json_error( array( 'message' => __( 'Passwords do not match.', 'aims-infosoft-lms' ), ) ); } if ( strlen( $new_password ) < 8 || ! preg_match( '/[A-Z]/', $new_password ) || ! preg_match( '/[a-z]/', $new_password ) || ! preg_match( '/\d/', $new_password ) ) { wp_send_json_error( array( 'message' => __( 'Password must be at least 8 characters and include uppercase, lowercase, and a number.', 'aims-infosoft-lms' ), ) ); } $result = AIMSLMS_Auth_Password::reset_password( $user_id, $token, $new_password ); if ( is_wp_error( $result ) ) { wp_send_json_error( array( 'message' => $result->get_error_message(), ) ); } wp_send_json_success( array( 'message' => __( 'Password reset successful. You may log in now.', 'aims-infosoft-lms' ), 'redirect' => get_permalink( get_option( 'aimslms_login_page' ) ), ) ); } /** * Changes the current user's password after verifying the old one. */ public function change_password() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( array( 'message' => __( 'You must be logged in.', 'aims-infosoft-lms' ) ) ); } $user_id = get_current_user_id(); $user = get_user_by( 'id', $user_id ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password value is used verbatim for comparison, not output or sanitized. $current_password = isset( $_POST['current_password'] ) ? wp_unslash( $_POST['current_password'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password value is used verbatim for hashing, not output or sanitized. $new_password = isset( $_POST['new_password'] ) ? wp_unslash( $_POST['new_password'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password value is used verbatim for comparison, not output or sanitized. $confirm_password = isset( $_POST['confirm_password'] ) ? wp_unslash( $_POST['confirm_password'] ) : ''; if ( empty( $current_password ) || empty( $new_password ) || empty( $confirm_password ) ) { wp_send_json_error( array( 'message' => __( 'All fields are required.', 'aims-infosoft-lms' ) ) ); } if ( ! wp_check_password( $current_password, $user->user_pass, $user_id ) ) { wp_send_json_error( array( 'message' => __( 'Current password is incorrect.', 'aims-infosoft-lms' ) ) ); } if ( $new_password !== $confirm_password ) { wp_send_json_error( array( 'message' => __( 'New passwords do not match.', 'aims-infosoft-lms' ) ) ); } if ( strlen( $new_password ) < 8 || ! preg_match( '/[A-Z]/', $new_password ) || ! preg_match( '/[a-z]/', $new_password ) || ! preg_match( '/\d/', $new_password ) ) { wp_send_json_error( array( 'message' => __( 'Password must be at least 8 characters and include uppercase, lowercase, and a number.', 'aims-infosoft-lms' ), ) ); } if ( wp_check_password( $new_password, $user->user_pass, $user_id ) ) { wp_send_json_error( array( 'message' => __( 'New password must be different from the current password.', 'aims-infosoft-lms' ) ) ); } wp_set_password( $new_password, $user_id ); wp_logout(); wp_send_json_success( array( 'message' => __( 'Password changed successfully. Please log in again.', 'aims-infosoft-lms' ), 'redirect' => get_permalink( get_option( 'aimslms_login_page' ) ), ) ); } /** * Deletes the current user's account. */ public function delete_account() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( array( 'message' => __( 'Login required.', 'aims-infosoft-lms' ) ) ); } require_once ABSPATH . 'wp-admin/includes/user.php'; $user_id = get_current_user_id(); if ( current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'Administrator accounts cannot be self-deleted from this screen.', 'aims-infosoft-lms' ) ) ); } wp_destroy_current_session(); wp_clear_auth_cookie(); wp_delete_user( $user_id ); wp_send_json_success( array( 'message' => 'Account deleted.', 'redirect' => home_url(), ) ); } /** * Logs the current user out. */ public function logout_user() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); wp_logout(); wp_send_json_success( array( 'redirect' => get_permalink( get_option( 'aimslms_login_page' ) ), ) ); } /** * Updates the current user's profile and billing details. */ public function update_user() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( array( 'message' => __( 'You must be logged in.', 'aims-infosoft-lms' ) ) ); } $user_id = get_current_user_id(); // Update core profile. wp_update_user( array( 'ID' => $user_id, 'first_name' => isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : '', 'last_name' => isset( $_POST['last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) : '', ) ); // Billing meta. $meta_map = array( 'billing_phone' => '_aimslms_billing_phone', 'billing_country' => '_aimslms_billing_country', 'billing_state' => '_aimslms_billing_state', 'billing_city' => '_aimslms_billing_city', 'billing_postcode' => '_aimslms_billing_postcode', 'billing_address_1' => '_aimslms_billing_address_1', 'billing_address_2' => '_aimslms_billing_address_2', 'billing_company' => '_aimslms_billing_company', 'billing_vat' => '_aimslms_billing_vat', ); foreach ( $meta_map as $post_key => $meta_key ) { update_user_meta( $user_id, $meta_key, isset( $_POST[ $post_key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $post_key ] ) ) : '' ); } // Send UPDATED data back. $billing_fields = array( 'phone' => '_aimslms_billing_phone', 'country' => '_aimslms_billing_country', 'state' => '_aimslms_billing_state', 'city' => '_aimslms_billing_city', 'postcode' => '_aimslms_billing_postcode', 'address_1' => '_aimslms_billing_address_1', 'address_2' => '_aimslms_billing_address_2', 'company' => '_aimslms_billing_company', 'vat' => '_aimslms_billing_vat', ); $billing = array(); foreach ( $billing_fields as $key => $meta_key ) { $value = get_user_meta( $user_id, $meta_key, true ); $billing[ $key ] = $value ? $value : 'No Info'; } wp_send_json_success( array( 'profile' => array( 'first_name' => get_user_meta( $user_id, 'first_name', true ), 'last_name' => get_user_meta( $user_id, 'last_name', true ), 'email' => wp_get_current_user()->user_email, 'username' => wp_get_current_user()->user_login, ), 'billing' => $billing, ) ); } /** * Uploads and sets a new profile image for the current user. */ public function upload_profile_image() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( array( 'message' => __( 'Unauthorized request.', 'aims-infosoft-lms' ) ) ); } if ( empty( $_FILES['image'] ) ) { wp_send_json_error( array( 'message' => __( 'No image uploaded.', 'aims-infosoft-lms' ) ) ); } $allowed_types = array( 'image/jpeg', 'image/png', 'image/jpg' ); if ( ! isset( $_FILES['image']['type'] ) || ! in_array( $_FILES['image']['type'], $allowed_types, true ) ) { wp_send_json_error( array( 'message' => __( 'Only JPG and PNG images are allowed.', 'aims-infosoft-lms' ) ) ); } require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; add_filter( 'intermediate_image_sizes_advanced', '__return_empty_array' ); $attachment_id = media_handle_upload( 'image', 0 ); if ( is_wp_error( $attachment_id ) ) { wp_send_json_error( array( 'message' => $attachment_id->get_error_message() ) ); } $user_id = get_current_user_id(); $old_avatar = get_user_meta( $user_id, '_aimslms_profile_image', true ); if ( $old_avatar ) { add_action( 'shutdown', function () use ( $old_avatar ) { wp_delete_attachment( $old_avatar, true ); } ); } update_user_meta( $user_id, '_aimslms_profile_image', $attachment_id ); wp_send_json_success( array( 'url' => wp_get_attachment_image_url( $attachment_id, 'thumbnail' ), ) ); } /** * Removes the current user's profile image. */ public function remove_profile_image() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( array( 'message' => __( 'Unauthorized request.', 'aims-infosoft-lms' ) ) ); } $user_id = get_current_user_id(); $avatar_id = get_user_meta( $user_id, '_aimslms_profile_image', true ); if ( $avatar_id ) { delete_user_meta( $user_id, '_aimslms_profile_image' ); add_action( 'shutdown', function () use ( $avatar_id ) { wp_delete_attachment( $avatar_id, true ); } ); } wp_send_json_success( array( 'url' => get_avatar_url( $user_id, array( 'size' => 96 ) ), ) ); } /** * Logs out a single session identified by its token. */ public function aimslms_logout_session() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error(); } $token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; if ( ! $token ) { wp_send_json_error(); } $user_id = get_current_user_id(); $sessions = get_user_meta( $user_id, 'session_tokens', true ); if ( isset( $sessions[ $token ] ) ) { unset( $sessions[ $token ] ); update_user_meta( $user_id, 'session_tokens', $sessions ); } wp_send_json_success(); } /** * Forces a logout if the current session token no longer exists. */ public function aimslms_init_logout_session() { if ( is_user_logged_in() ) { $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); $sessions = $manager->get_all(); $current = wp_get_session_token(); if ( ! isset( $sessions[ $current ] ) ) { wp_logout(); wp_safe_redirect( wp_login_url() ); exit; } } } /** * Loads the enrolled-courses list for the student dashboard, applying search * and filter parameters submitted from the dashboard UI. */ public function aimslms_load_dashboard_courses() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); $user_id = get_current_user_id(); $course_ids = aimslms_get_all_enrolled_course_ids( $user_id ); if ( empty( $course_ids ) ) { wp_send_json_success( array( 'html' => $this->aimslms_dashboard_empty_state_html( 'no_enrollment' ), 'empty' => true, ) ); return; } $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : ''; $category = isset( $_POST['category'] ) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ) : ''; $pricing = isset( $_POST['pricing'] ) ? sanitize_text_field( wp_unslash( $_POST['pricing'] ) ) : ''; $levels = isset( $_POST['levels'] ) ? sanitize_text_field( wp_unslash( $_POST['levels'] ) ) : ''; $args = array( 'post_type' => 'aimslms_course', 'post__in' => $course_ids, 's' => $search, ); if ( ! empty( $category ) ) { $args['tax_query'][] = array( 'taxonomy' => 'aimslms_course_category', 'field' => 'slug', 'terms' => $category, ); } if ( 'free' === $pricing ) { $args['meta_query'][] = array( 'key' => '_aimslms_price', 'compare' => '=', 'value' => 0, ); } if ( 'paid' === $pricing ) { $args['meta_query'][] = array( 'key' => '_aimslms_price', 'compare' => '>', 'value' => 0, ); } if ( 'all' !== $levels ) { $args['meta_query'][] = array( 'key' => '_aimslms_level', 'compare' => '=', 'value' => $levels, ); } $query = new WP_Query( $args ); if ( ! $query->have_posts() ) { wp_send_json_success( array( 'html' => $this->aimslms_dashboard_empty_state_html( 'filtered' ), 'empty' => true, ) ); return; } ob_start(); while ( $query->have_posts() ) { $query->the_post(); require AIMSLMS_PLUGIN_DIR . 'public/templates/partials/course-card.php'; } wp_reset_postdata(); wp_send_json_success( array( 'html' => ob_get_clean(), 'empty' => false, ) ); } /** * Returns the current user's order history for the account dashboard. */ public function aimslms_get_order_history() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( 'Unauthorized' ); return; } global $wpdb; $user_id = get_current_user_id(); $user_meta = get_user_meta( $user_id ); $customer_firstname = get_user_meta( $user_id, 'first_name', true ); $customer_lastname = get_user_meta( $user_id, 'last_name', true ); $customer_name = trim( $customer_firstname . ' ' . $customer_lastname ); $table = $wpdb->prefix . 'aimslms_course_orders'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table, no WP API alternative. $orders = $wpdb->get_results( $wpdb->prepare( "SELECT o.*, pay.payment_gateway, pay.currency AS payment_currency FROM {$wpdb->prefix}aimslms_course_orders o LEFT JOIN {$wpdb->prefix}aimslms_course_payment pay ON pay.order_id = o.id WHERE o.user_id = %d AND o.order_status != 'trash' ORDER BY o.created_at DESC", $user_id ) ); if ( empty( $orders ) ) { wp_send_json_success( array() ); } $data = array(); foreach ( $orders as $order ) { $amount = (float) $order->order_total; $gateway = $order->payment_gateway ?? ''; $currency = $order->payment_currency ?? get_option( 'aimslms_currency', 'USD' ); if ( 'razorpay' === $gateway ) { $amount = $amount / 100; $currency = 'INR'; } $data[] = array( 'order_id' => $order->id, 'course' => get_the_title( $order->course_id ), 'student_name' => $customer_name, 'date' => mysql2date( 'd M Y', $order->created_at ), 'status' => ucfirst( $order->order_status ), 'status_key' => strtolower( $order->order_status ), 'total' => aimslms_format_price( $amount, array( 'currency' => $currency, ) ), 'invoice' => add_query_arg( array( 'aimslms_invoice' => 1, 'order_id' => $order->id, '_nonce' => wp_create_nonce( 'aimslms_invoice_' . $order->id ), ), home_url( '/' ) ), ); } wp_send_json_success( $data ); } /** * Builds the HTML shown when a dashboard/course listing query returns no results. * * @param string $type Empty-state type: 'no_enrollment' or 'filtered'. * @return string Rendered HTML markup. */ public function aimslms_dashboard_empty_state_html( $type = 'filtered' ) { ob_start(); ?>
'Please login to enroll.', ) ); } $user_id = get_current_user_id(); $course_id = isset( $_POST['course_id'] ) ? (int) $_POST['course_id'] : 0; if ( ! $course_id || get_post_type( $course_id ) !== 'aimslms_course' ) { wp_send_json_error( array( 'message' => 'Invalid course.', ) ); } $price = get_post_meta( $course_id, '_aimslms_price', true ); if ( (float) $price > 0 ) { wp_send_json_error( array( 'message' => 'Paid course cannot be auto-enrolled.', ) ); } if ( aimslms_get_course_enrollment( $course_id, $user_id ) ) { wp_send_json_success( array( 'redirect' => get_permalink( $course_id ), ) ); } global $wpdb; $orders_table = $wpdb->prefix . 'aimslms_course_orders'; $payments_table = $wpdb->prefix . 'aimslms_course_payment'; $enrollments_table = $wpdb->prefix . 'aimslms_course_enrollments'; $transaction_id = sprintf( 'free_%d_%d', $course_id, time() ); // Create order. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom table, no WP API alternative. $order_insert = $wpdb->insert( $orders_table, array( 'user_id' => $user_id, 'course_id' => $course_id, 'transaction_id' => $transaction_id, 'order_total' => 0, 'order_status' => 'completed', 'created_at' => current_time( 'mysql' ), 'updated_at' => current_time( 'mysql' ), ) ); if ( false === $order_insert ) { wp_send_json_error( array( 'message' => 'Order insert failed', 'db_error' => $wpdb->last_error, ) ); } $order_id = $wpdb->insert_id; // Create payment. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom table, no WP API alternative. $payment_insert = $wpdb->insert( $payments_table, array( 'order_id' => $order_id, 'user_id' => $user_id, 'course_id' => $course_id, 'payment_method' => 'free', 'payment_gateway' => 'free', 'transaction_id' => $transaction_id, 'amount' => 0, 'status' => 'completed', 'transaction_date' => current_time( 'mysql' ), ) ); if ( false === $payment_insert ) { wp_send_json_error( array( 'message' => 'Payment insert failed', 'db_error' => $wpdb->last_error, ) ); } // Enroll. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom table, no WP API alternative. $enroll_insert = $wpdb->insert( $enrollments_table, array( 'user_id' => $user_id, 'course_id' => $course_id, 'transaction_id' => $transaction_id, 'enrollment_date' => current_time( 'mysql' ), ) ); if ( false === $enroll_insert ) { wp_send_json_error( array( 'message' => 'Enrollment insert failed', 'db_error' => $wpdb->last_error, ) ); } wp_send_json_success( array( 'redirect' => get_permalink( $course_id ), ) ); } /** * Loads the public course listing, applying search, category, and * filter parameters submitted from the course listing UI. */ public function aimslms_load_public_courses() { check_ajax_referer( 'aimslms_auth_nonce', 'nonce' ); $paged = isset( $_POST['page'] ) ? max( 1, absint( wp_unslash( $_POST['page'] ) ) ) : 1; $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : ''; $category = isset( $_POST['category'] ) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ) : ''; $pricing = isset( $_POST['pricing'] ) ? sanitize_text_field( wp_unslash( $_POST['pricing'] ) ) : ''; $levels = isset( $_POST['levels'] ) ? sanitize_text_field( wp_unslash( $_POST['levels'] ) ) : ''; $args = array( 'post_type' => 'aimslms_course', 'post_status' => 'publish', 'posts_per_page' => 9, 'paged' => $paged, 's' => $search, ); if ( ! empty( $category ) ) { $args['tax_query'][] = array( 'taxonomy' => 'aimslms_course_category', 'field' => 'slug', 'terms' => $category, ); } if ( 'free' === $pricing ) { $args['meta_query'][] = array( 'key' => '_aimslms_price', 'compare' => '<=', 'value' => '0', ); } if ( 'paid' === $pricing ) { $args['meta_query'][] = array( 'key' => '_aimslms_price', 'compare' => '>', 'value' => 0, ); } if ( 'all' !== $levels ) { $args['meta_query'][] = array( 'key' => '_aimslms_level', 'compare' => '=', 'value' => $levels, ); } $q = new WP_Query( $args ); if ( ! $q->have_posts() ) { wp_send_json_success( array( 'html' => $this->aimslms_dashboard_empty_state_html( 'filtered' ), 'empty' => true, ) ); return; } ob_start(); if ( $q->have_posts() ) { while ( $q->have_posts() ) { $q->the_post(); require AIMSLMS_PLUGIN_DIR . 'public/templates/partials/main-course-card.php'; } } wp_reset_postdata(); wp_send_json_success( array( 'html' => ob_get_clean(), 'pages' => $q->max_num_pages, ) ); } /** * Clears the current checkout session and redirects back to the courses page. */ public function aimslms_remove_checkout_item() { check_ajax_referer( 'aimslms_checkout_nonce', 'nonce' ); if ( ! session_id() ) { session_start(); } // Unset checkout session. if ( isset( $_SESSION['aimslms_checkout'] ) ) { unset( $_SESSION['aimslms_checkout'] ); } $courses_page_id = get_option( 'aimslms_courses_page' ); $courses_page_url = get_permalink( $courses_page_id ); wp_send_json_success( array( 'redirect_url' => $courses_page_url, ) ); wp_die(); } }