search_groups( $search_term ); } if ( ! isset( $response['errors'] ) ) { foreach ( $response['groups'] as $value ) { array_push( $groups, array( 'value' => $value['id'], 'label' => $value['name'], ) ); } wp_send_json_success( $groups ); } else { wp_send_json_error(); } } /** * Get group by id. */ public static function get_group() { self::verify_admin_request(); $response = array(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_REQUEST['group_id'] ) && ! empty( $_REQUEST['group_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $group_id = sanitize_text_field( wp_unslash( $_REQUEST['group_id'] ) ); $api_client = new Accredible_Learndash_Api_V1_Client(); $response = $api_client->get_group( $group_id ); } if ( ! isset( $response['errors'] ) ) { $group = array( 'id' => $response['group']['id'], 'name' => $response['group']['name'], ); wp_send_json_success( $group ); } else { wp_send_json_error(); } } /** * Get lesson options. */ public static function get_lessons() { self::verify_admin_request(); $course_id = self::get_request_value( 'course_id', null ); if ( isset( $course_id ) ) { $utils = new Accredible_Learndash_Learndash_Utils(); $lessons = $utils->get_lesson_options( $course_id ); wp_send_json_success( $lessons ); } else { wp_send_json_error(); } } /** * Get issuer details html. */ public static function load_issuer_html() { self::verify_admin_request(); $issuer = null; $api_client = new Accredible_Learndash_Api_V1_Client(); $response = $api_client->organization_search(); if ( ! isset( $response['errors'] ) ) { $issuer = $response['issuer']; } // Capture html from display_issuer_info. ob_start(); Accredible_Learndash_Issuer_Helper::display_issuer_info( $issuer ); $issuer_html = ob_get_clean(); wp_send_json_success( $issuer_html ); } /** * Load auto issuances */ public static function load_auto_issuance_list_html() { self::verify_admin_request(); $current_page = self::get_request_value( 'page_num', 1 ); $page_size = 20; $page_results = Accredible_Learndash_Model_Auto_Issuance::get_paginated_results( $current_page, $page_size ); // Capture html from display_auto_issuance_list_info. ob_start(); Accredible_Learndash_Auto_Issuance_List_Helper::display_auto_issuance_list_info( $page_results, $current_page, $page_size ); $auto_issuance_list_html = ob_get_clean(); wp_send_json_success( $auto_issuance_list_html ); } /** * Triggers the appropriate action in Accredible_Learndash_Admin_Action_Handler */ public static function handle_auto_issuance_action() { self::verify_admin_request(); try { $results = Accredible_Learndash_Admin_Action_Handler::call(); wp_send_json_success( $results ); } catch ( \Exception $wp_exception ) { wp_send_json_error( $wp_exception->getMessage() ); } } /** * Get page html. */ public static function load_issuance_form_html() { self::verify_admin_request(); $accredible_learndash_issuance_id = self::get_request_value( 'id', null ); $accredible_learndash_issuance_current_page = self::get_request_value( 'page_num', null ); // Capture html from page. ob_start(); require plugin_dir_path( __DIR__ ) . 'templates/admin-auto-issuance-form.php'; $page_html = ob_get_clean(); wp_send_json_success( $page_html ); wp_die(); } /** * Stop the request with a 403 unless it comes from an administrator with a valid nonce. */ private static function verify_admin_request() { if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( self::NONCE_ACTION, 'nonce', false ) ) { wp_send_json_error( 'You are not allowed to perform this action.', 403 ); } } /** * Returns a resolved $_REQUEST value * * @param string $key the key to fetch the value. * @param mixed $default_value default value to return. * * @return mixed */ public static function get_request_value( $key, $default_value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_REQUEST[ $key ] ) && ! empty( $_REQUEST[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return sanitize_text_field( wp_unslash( $_REQUEST[ $key ] ) ); } else { return $default_value; } } } endif;