$shopid, 'status' => 1, 'isUninstall' => 0, 'timestamp' => time(), 'name' => (get_bloginfo('name')), 'email' => (get_option('admin_email')), 'domain' => (get_bloginfo('url')), 'wordpress_version' => $plugin_version, ); error_log('[Accessibility Plugin] Sending install data: ' . json_encode($init_data)); $type = 'post'; $body = assistant_api_call('/install', $init_data, $type); error_log('[Accessibility Plugin] API response: ' . json_encode($body)); if ($body['status'] == 200 && count($body['data']) > 0) { $response = $body['data']; update_option('accessibility_shopid', sanitize_text_field($response['shopid'])); update_option('accessibility_tokken', sanitize_text_field($response['token'])); update_option('accessibility_primaryid', sanitize_text_field($response['id'])); update_option('accessibility_install', 1); } // Set default language on activation if (get_option('my_plugin_selected_language') === false) { $site_lang = get_locale(); $lang_map = my_plugin_get_language_map(); $normalized = isset($lang_map[$site_lang]) ? $lang_map[$site_lang] : ( isset($lang_map[substr($site_lang, 0, 2)]) ? $lang_map[substr($site_lang, 0, 2)] : $site_lang ); update_option('my_plugin_selected_language', $normalized); } } } // During Deactivatation register_deactivation_hook(__FILE__, 'accessibility_deactivation'); if (!function_exists('accessibility_deactivation')) { function accessibility_deactivation() { $shopid = get_option('accessibility_shopid'); $deactivate_reason = get_option('ada_uninstall_reason'); $deactive_data = array( 'shopid' => $shopid, 'deactivate_reason' => $deactivate_reason, ); $body = assistant_api_call('/uninstallShopData', $deactive_data, 'get'); update_option('accessibility_install', 0); delete_option('accessibility_plan'); delete_option('accessibility_primaryid'); delete_option('accessibility_url'); } } // Add Js And Style Sheet. add_action('admin_enqueue_scripts', 'accessibility_load_admin_styles'); function accessibility_load_admin_styles() { $shopid = get_option('accessibility_shopid'); wp_register_script('jquery', site_url('/wp-includes/js/jquery/jquery.min.js'), [], '3.7.1', true); wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); // Core jQuery UI wp_enqueue_script('jquery-ui-draggable'); // Ensure draggable is included wp_enqueue_style('admin_accesibility_css', plugin_dir_url(__FILE__) . 'assets/stylesheet.css', false, '1.0.0'); wp_enqueue_style('fonts_accesibility_css', plugin_dir_url(__FILE__) . 'assets/fonts/fonts.googleapis.css', false, '1.0.0'); wp_enqueue_style('fonts_awesome_accesibility_css', plugin_dir_url(__FILE__) . 'assets/fontawesome/css/all.min.css', false, '1.0.0'); wp_enqueue_style('accesibility_bootstrap_css', plugin_dir_url(__FILE__) . 'assets/bootstrap/css/bootstrap.min.css', false, '4.4.1'); wp_enqueue_style('slick_css', plugin_dir_url(__FILE__) . 'assets/css/slick.css', false, '1.0.0'); wp_enqueue_style('slick_theme_css', plugin_dir_url(__FILE__) . 'assets/css/slick-theme.css', false, '1.0.0'); wp_enqueue_script('admin_accesibility_js', plugin_dir_url(__FILE__) . 'assets/bootstrap/js/bootstrap.bundle.min.js', false, '4.4.1', true); wp_enqueue_style('swiper_css', plugin_dir_url(__FILE__) . 'assets/css/swiper-bundle.min.css', false, '1.0.0'); wp_enqueue_script('custom_js', plugins_url('assets/js/custom_js.js', __FILE__), array('jquery'), '1.0.0', true); wp_enqueue_script('dashboard_js', plugins_url('assets/js/dashboard_count.js', __FILE__), array('jquery'), '1.0.0', true); wp_enqueue_script('slick_js', plugins_url('assets/js/slick.min.js', __FILE__), array('jquery'), '1.0.0', true); wp_enqueue_script('swiper_js', plugins_url('assets/js/swiper.min.js', __FILE__), array('jquery'), '1.0.0', true); wp_enqueue_script('ada-feedback', plugin_dir_url(__FILE__) . 'assets/js/feedback.js', array('jquery'), '1.0.0', true); wp_localize_script('ada-feedback', 'ada_ajax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ada_nonce') ]); wp_enqueue_script( 'accessibility-scan', plugin_dir_url(__FILE__) . 'assets/js/scan.js', ['jquery'], null, true ); wp_localize_script('accessibility-scan', 'scan_ajax_obj', [ 'ajax_url' => admin_url('admin-ajax.php'), 'shopId' => $shopid, 'currentsiteUrl' => site_url(), 'sacnbtnString' => __('Scan Your site', 'accessibility-assistant'), ]); wp_localize_script('my-script', 'ajax_object', array('ajaxurl' => admin_url('admin-ajax.php'))); function getUserIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } else { return $_SERVER['REMOTE_ADDR']; } } $ipaddress = getUserIpAddr(); if ($ipaddress == "127.0.0.1" || $ipaddress == "::1") { $ipaddress = "8.8.8.8"; } $token = "d382bafd690271"; $url = "https://ipinfo.io/{$ipaddress}/json" . ($token ? "?token={$token}" : ""); $ipdat = @json_decode(file_get_contents($url)); $countryCodes = [ "AF" => "+93", "AL" => "+355", "DZ" => "+213", "AS" => "+1-684", "AD" => "+376", "AO" => "+244", "AI" => "+1-264", "AG" => "+1-268", "AR" => "+54", "AM" => "+374", "AW" => "+297", "AU" => "+61", "AT" => "+43", "AZ" => "+994", "BS" => "+1-242", "BH" => "+973", "BD" => "+880", "BB" => "+1-246", "BY" => "+375", "BE" => "+32", "BZ" => "+501", "BJ" => "+229", "BM" => "+1-441", "BT" => "+975", "BO" => "+591", "BA" => "+387", "BW" => "+267", "BR" => "+55", "BN" => "+673", "BG" => "+359", "BF" => "+226", "BI" => "+257", "KH" => "+855", "CM" => "+237", "CA" => "+1", "CV" => "+238", "KY" => "+1-345", "CF" => "+236", "TD" => "+235", "CL" => "+56", "CN" => "+86", "CO" => "+57", "KM" => "+269", "CG" => "+242", "CD" => "+243", "CR" => "+506", "CI" => "+225", "HR" => "+385", "CU" => "+53", "CY" => "+357", "CZ" => "+420", "DK" => "+45", "DJ" => "+253", "DM" => "+1-767", "DO" => "+1-809", "EC" => "+593", "EG" => "+20", "SV" => "+503", "GQ" => "+240", "ER" => "+291", "EE" => "+372", "ET" => "+251", "FJ" => "+679", "FI" => "+358", "FR" => "+33", "GF" => "+594", "GA" => "+241", "GM" => "+220", "GE" => "+995", "DE" => "+49", "GH" => "+233", "GR" => "+30", "GL" => "+299", "GD" => "+1-473", "GP" => "+590", "GU" => "+1-671", "GT" => "+502", "GN" => "+224", "GW" => "+245", "GY" => "+592", "HT" => "+509", "HN" => "+504", "HK" => "+852", "HU" => "+36", "IS" => "+354", "IN" => "+91", "ID" => "+62", "IR" => "+98", "IQ" => "+964", "IE" => "+353", "IL" => "+972", "IT" => "+39", "JM" => "+1-876", "JP" => "+81", "JO" => "+962", "KZ" => "+7", "KE" => "+254", "KI" => "+686", "KR" => "+82", "KW" => "+965", "KG" => "+996", "LA" => "+856", "LV" => "+371", "LB" => "+961", "LS" => "+266", "LR" => "+231", "LY" => "+218", "LI" => "+423", "LT" => "+370", "LU" => "+352", "MO" => "+853", "MK" => "+389", "MG" => "+261", "MW" => "+265", "MY" => "+60", "MV" => "+960", "ML" => "+223", "MT" => "+356", "MH" => "+692", "MQ" => "+596", "MR" => "+222", "MU" => "+230", "YT" => "+262", "MX" => "+52", "FM" => "+691", "MD" => "+373", "MC" => "+377", "MN" => "+976", "ME" => "+382", "MS" => "+1-664", "MA" => "+212", "MZ" => "+258", "MM" => "+95", "NA" => "+264", "NR" => "+674", "NP" => "+977", "NL" => "+31", "NC" => "+687", "NZ" => "+64", "NI" => "+505", "NE" => "+227", "NG" => "+234", "NO" => "+47", "OM" => "+968", "PK" => "+92", "PW" => "+680", "PS" => "+970", "PA" => "+507", "PG" => "+675", "PY" => "+595", "PE" => "+51", "PH" => "+63", "PL" => "+48", "PT" => "+351", "PR" => "+1-787", "QA" => "+974", "RE" => "+262", "RO" => "+40", "RU" => "+7", "RW" => "+250", "WS" => "+685", "SM" => "+378", "SA" => "+966", "SN" => "+221", "RS" => "+381", "SC" => "+248", "SL" => "+232", "SG" => "+65", "SK" => "+421", "SI" => "+386", "SB" => "+677", "SO" => "+252", "ZA" => "+27", "ES" => "+34", "LK" => "+94", "SD" => "+249", "SR" => "+597", "SZ" => "+268", "SE" => "+46", "CH" => "+41", "SY" => "+963", "TW" => "+886", "TJ" => "+992", "TZ" => "+255", "TH" => "+66", "TG" => "+228", "TO" => "+676", "TT" => "+1-868", "TN" => "+216", "TR" => "+90", "TM" => "+993", "TC" => "+1-649", "UG" => "+256", "UA" => "+380", "AE" => "+971", "GB" => "+44", "US" => "+1", "UY" => "+598", "UZ" => "+998", "VU" => "+678", "VE" => "+58", "VN" => "+84", "YE" => "+967", "ZM" => "+260", "ZW" => "+263" ]; // Default fallback $countryCode = "+91"; if (!empty($ipdat->country) && isset($countryCodes[$ipdat->country])) { $countryCode = $countryCodes[$ipdat->country]; } wp_localize_script('custom_js', 'myScript', array( 'tooltipText' => __('Upgrade your plan to enable this feature', 'accessibility-assistant'), 'ajax_url' => admin_url('admin-ajax.php'), 'pluginsUrl' => plugins_url(), 'editLanguagesUrl' => admin_url('admin.php?page=accessibility-laguages'), 'backtolanguages' => admin_url('admin.php?page=accessibility-submenu'), 'planlisting' => admin_url('admin.php?page=accessibility-plan'), 'accessibilitywidget' => admin_url('admin.php?page=accessibility-assistance'), 'assistantUrl' => ASSISTANT_URL, 'shopId' => $shopid, 'primaryId' => get_option('accessibility_primaryid'), 'country_code' => $countryCode )); wp_localize_script('dashboard_js', 'dashboardScript', array( 'ajax_url' => admin_url('admin-ajax.php'), 'pluginsUrl' => plugins_url(), 'editLanguagesUrl' => admin_url('admin.php?page=accessibility-laguages'), 'backtolanguages' => admin_url('admin.php?page=accessibility-submenu'), 'planlisting' => admin_url('admin.php?page=accessibility-plan'), 'accessibilitywidget' => admin_url('admin.php?page=accessibility-assistance'), 'assistantUrl' => ASSISTANT_URL, 'shopId' => $shopid, 'lastsevenDays' => __('Last 7 Days', 'accessibility-assistant'), 'lastthirtyDays' => __('Last 30 Days', 'accessibility-assistant'), 'thismonth' => __('This Month', 'accessibility-assistant'), 'lastmonth' => __('Last Month', 'accessibility-assistant'), 'nodataFound' => __('No Significant Most Features Usage Found', 'accessibility-assistant'), 'widgetOpens' => __('Widget Opens', 'accessibility-assistant'), 'eventsClicked' => __('Events Clicked', 'accessibility-assistant'), 'noGraphDatamessage' => __('No relevant data is available for the specified range', 'accessibility-assistant'), )); /***Live paypal sdk start */ wp_enqueue_script( 'paypal_sdk', 'https://www.paypal.com/sdk/js?client-id=AXA7-tKsHXdEM50A4J_-3-4NamNd6YIAgKShr_gWNQaQxCMgs9p3GtRRXZ_S20xMm0p_wKjctfI0OoHe&vault=true&intent=subscription', array(), null, true ); /***Live paypal sdk end */ // Define an array of page slugs where you want to load the script $plugin_pages = [ 'accessibility-assistance', // Main menu page 'accessibility-submenu', // Submenu page 1 'accessibility-laguages', // Submenu page 2 'accessibility-plan', // Submenu page 3 'user-guide', // Submenu page 4 'accessibility-menu-settings', //Submenu page 5 'accessibility-widget-settings', //Submenu page 6 'accessibility-scanner' ]; // Check if current admin page is part of the plugin if (isset($_GET['page']) && in_array($_GET['page'], $plugin_pages)) { wp_enqueue_script('tracking_js', plugins_url('assets/js/tracking.js', __FILE__), array('jquery'), '1.0.0', true); } $dashboard_page = [ // 'accessibility-dashboard' 'accessibility-assistance' ]; if (isset($_GET['page']) && in_array($_GET['page'], $dashboard_page)) { // wp_enqueue_script('dashboard-jquery', plugin_dir_url(__FILE__) . 'assets/js/jquery-3.7.1.min.js', array('jquery'), '1.0.0', true); wp_enqueue_style('daterangepicker_css', plugin_dir_url(__FILE__) . 'assets/css/daterangepicker.css', false, '1.0.0'); wp_enqueue_script('moment-js', plugin_dir_url(__FILE__) . 'assets/js/moment.min.js', array('jquery'), '1.0.0', true); wp_enqueue_script('daterangepicker_js', plugin_dir_url(__FILE__) . 'assets/js/daterangepicker.min.js', array('jquery'), '1.0.0', true); wp_enqueue_script('chart_js', plugin_dir_url(__FILE__) . 'assets/js/Chart.min.js', array('jquery'), '1.0.0', true); wp_enqueue_script('chartplugin_js', plugin_dir_url(__FILE__) . 'assets/js/chartjs-plugin-datalabels.min.js', array('jquery'), '1.0.0', true); } } //API Send function Call through path and data...... if (!function_exists('assistant_api_call')) { function assistant_api_call($path, $fields, $type) { $url = ASSISTANT_API_URL . $path; $apidata = array( 'body' => $fields, 'timeout' => '30', //'sslverify' => false, 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'cookies' => array() ); if ($type == 'post') { $response = wp_remote_post($url, $apidata); } else { $response = wp_remote_get($url, $apidata); } error_log("Making API call to: " . $url); error_log("Request Data: " . json_encode($apidata)); $body = wp_remote_retrieve_body($response); if (empty($body)) { error_log("API Response Body is empty or invalid."); } // Log the API response (body) for debugging purposes error_log("API Response Body: " . $body); return json_decode($body, true); } } /* Describe what the code snippet does so you can remember later on */ /* Describe what the code snippet does so you can remember later on */ add_action('wp_footer', 'accessibility_addjsfooter'); function accessibility_addjsfooter() { $base_url = ASSISTANT_API_URL . '/wordpress/script'; $site_id = sanitize_text_field(get_option('accessibility_shopid')); if (empty($site_id)) { return; } // Make API call to get widget settings $data = array('shopid' => $site_id); $api_response = assistant_api_call('/getShopData', $data, 'get'); // Extract widget settings from API response $widget_settings = null; if ($api_response && isset($api_response['data'])) { $widget_settings = $api_response['data']; } // Map desktop position function accessibility_getclassbyposition($position) { switch ($position) { case 1: return "aa-cc-top-left"; case 2: return "aa-cc-top-right"; case 3: return "aa-cc-center-left"; case 4: return "aa-cc-center-right"; case 5: return "aa-cc-bottom-left"; case 6: return "aa-cc-bottom-right"; default: return "aa-cc-bottom-right"; } } // Map mobile position function accessibility_getclassbymobileposition($position) { switch ($position) { case 1: return "aa-mm-cc-top-left"; case 2: return "aa-mm-cc-top-right"; case 3: return "aa-mm-cc-center-left"; case 4: return "aa-mm-cc-center-right"; case 5: return "aa-mm-cc-bottom-left"; case 6: return "aa-mm-cc-bottom-right"; default: return "aa-mm-cc-bottom-right"; } } $widgetSettings = [ "status" => !empty($widget_settings['status']) ? true : false, "show_loader" => isset($widget_settings['button_link_status']) && (int)$widget_settings['button_link_status'] === 1, "desktop_position" => accessibility_getclassbyposition($widget_settings['position'] ?? 6), "mobile_position" => accessibility_getclassbymobileposition($widget_settings['mobile_position'] ?? 6), "size" => (int)$widget_settings['shop_text']['widget_size'] ?? '', "bottom_padding" => $widget_settings['bottom_padding'] ?? 0, "widget_outercolor" => $widget_settings['widget_outer_color'] ?? '#000', "widget_innercolor" => $widget_settings['widget_inner_color'] ?? '#fff', "svg" => $widget_settings['widget_icon'] ?? '', "plan_name" => $widget_settings['plan'] ]; ?>
' . esc_html(__('Please uninstall this plugin and reinstall it.', 'accessibility-assistant')) . '
'; } } // Language Map function my_plugin_get_language_map() { return [ 'af' => 'af_ZA', 'am' => 'am_ET', 'ar' => 'ar_SA', 'az' => 'az_AZ', 'be' => 'be_BY', 'bg' => 'bg_BG', 'bn' => 'bn_BD', 'bo' => 'bo_CN', 'bs' => 'bs_BA', 'ca' => 'ca_ES', 'ceb' => 'ceb_PH', 'chk' => 'chk_FM', 'ckb' => 'ckb_IQ', 'cnh' => 'cnh_MM', 'cs' => 'cs_CZ', 'cy' => 'cy_GB', 'da' => 'da_DK', 'de' => 'de_DE', 'dv' => 'dv_MV', 'el' => 'el_GR', 'en' => 'en_US', 'en_GB' => 'en_GB', 'es' => 'es_ES', 'es_419' => 'es_419', 'es_MX' => 'es_MX', 'es_PR' => 'es_PR', 'et' => 'et_EE', 'eu' => 'eu_ES', 'fa' => 'fa_IR', 'ff' => 'ff_SN', 'fi' => 'fi_FI', 'fj' => 'fj_FJ', 'fr' => 'fr_FR', 'fr_CA' => 'fr_CA', 'ga' => 'ga_IE', 'gu' => 'gu_IN', 'hak' => 'hak_TW', 'ha' => 'ha_NG', 'haw' => 'haw_US', 'he' => 'he_IL', 'hi' => 'hi_IN', 'hil' => 'hil_PH', 'hmn' => 'hmn_US', 'hr' => 'hr_HR', 'ht' => 'ht_HT', 'hu' => 'hu_HU', 'hy' => 'hy_AM', 'id' => 'id_ID', 'ig' => 'ig_NG', 'ilo' => 'ilo_PH', 'is' => 'is_IS', 'it' => 'it_IT', 'ja' => 'ja_JP', 'jv' => 'jv_ID', 'ka' => 'ka_GE', 'kea' => 'kea_CV', 'kk' => 'kk_KZ', 'km' => 'km_KH', 'kn' => 'kn_IN', 'ko' => 'ko_KR', 'ksw' => 'ksw_MM', 'ku' => 'ku_TR', 'ky' => 'ky_KG', 'la' => 'la_VA', 'lo' => 'lo_LA', 'lt' => 'lt_LT', 'lv' => 'lv_LV', 'man' => 'man_GM', 'mh' => 'mh_MH', 'mi' => 'mi_NZ', 'mien' => 'mien_US', 'mk' => 'mk_MK', 'ml' => 'ml_IN', 'mn' => 'mn_MN', 'mr' => 'mr_IN', 'ms' => 'ms_MY', 'mt' => 'mt_MT', 'my' => 'my_MM', 'ne' => 'ne_NP', 'nl' => 'nl_NL', 'nl_BE' => 'nl_BE', 'no' => 'no_NO', 'nv' => 'nv_US', 'om' => 'om_ET', 'pa' => 'pa_IN', 'pl' => 'pl_PL', 'ps' => 'ps_AF', 'pt' => 'pt_PT', 'pt_BR' => 'pt_BR', 'qu' => 'qu_PE', 'rn' => 'rn_BI', 'ro' => 'ro_RO', 'rom' => 'rom_MD', 'ru' => 'ru_RU', 'rw' => 'rw_RW', 'sm' => 'sm_WS', 'smj' => 'smj_NO', 'sk' => 'sk_SK', 'sl' => 'sl_SI', 'so' => 'so_SO', 'sq' => 'sq_AL', 'sr' => 'sr_RS', 'sr_ME' => 'sr_ME', 'sv' => 'sv_SE', 'sw' => 'sw_TZ', 'ta' => 'ta_IN', 'te' => 'te_IN', 'th' => 'th_TH', 'ti' => 'ti_ER', 'tl' => 'tl_PH', 'to' => 'to_TO', 'tr' => 'tr_TR', 'tt' => 'tt_RU', 'uk' => 'uk_UA', 'ur' => 'ur_PK', 'uz' => 'uz_UZ', 'vi' => 'vi_VN', 'wo' => 'wo_SN', 'xh' => 'xh_ZA', 'yi' => 'yi_001', 'yo' => 'yo_NG', 'zh' => 'zh_CN', 'zh_Hant' => 'zh_TW' ]; } // Normalize selected language function my_plugin_get_selected_locale() { $site_lang = get_locale(); $lang_map = my_plugin_get_language_map(); $stored = get_option('my_plugin_selected_language'); if (!$stored) { $stored = $site_lang; } // Normalize to full locale if (isset($lang_map[$stored])) { return $lang_map[$stored]; } // Try short version if full code doesn’t exist $short = substr($stored, 0, 2); if (isset($lang_map[$short])) { return $lang_map[$short]; } return $stored; } // Load translation early function my_plugin_load_textdomain() { $domain = 'accessibility-assistant'; $locale = my_plugin_get_selected_locale(); $mofile = plugin_dir_path(__FILE__) . "languages/$locale/$domain.mo"; if (file_exists($mofile)) { load_textdomain($domain, $mofile); } else { load_plugin_textdomain($domain, false, basename(dirname(__FILE__)) . '/languages'); } } add_action('plugins_loaded', 'my_plugin_load_textdomain'); // Handle language switch via POST function my_plugin_handle_language_switch() { if (isset($_POST['plugin_language'])) { $input_lang = sanitize_text_field($_POST['plugin_language']); $lang_map = my_plugin_get_language_map(); $normalized = isset($lang_map[$input_lang]) ? $lang_map[$input_lang] : $input_lang; update_option('my_plugin_selected_language', $normalized); wp_redirect(esc_url_raw($_SERVER['REQUEST_URI'])); exit; } } add_action('init', 'my_plugin_handle_language_switch'); // Redirect to "Acessibiity assustance plugin main" page on plugin activation add_action('admin_init', 'accessibility_redirect_after_activation'); function accessibility_redirect_after_activation() { if (get_option('accessibility_do_redirect')) { delete_option('accessibility_do_redirect'); if (!isset($_GET['activate-multi'])) { wp_safe_redirect(admin_url('admin.php?page=accessibility-assistance')); exit; } } } // Handle AJAX request for deactivation feedback add_action('wp_ajax_ada_submit_reason', function () { check_ajax_referer('ada_nonce'); $reason = sanitize_text_field($_POST['reason'] ?? ''); update_option('ada_uninstall_reason', $reason); wp_send_json_success(); }); //Load plan popup add_action('wp_ajax_load_plan_popup', 'load_plan_popup_callback'); function load_plan_popup_callback() { require_once plugin_dir_path(__FILE__) . 'admin/plan-popup.php'; wp_die(); // Always call wp_die() in Ajax handlers } //cancel subscription start add_action('wp_ajax_ada_cancel_subscription', 'ada_cancel_subscription_callback'); function ada_cancel_subscription_callback() { check_ajax_referer('ada_nonce', '_ajax_nonce'); $shopid = get_option('accessibility_shopid'); if (!$shopid) { error_log("Cancel Subscription: Shop ID not found."); wp_send_json_error(['message' => 'Shop ID not found']); } error_log("Cancel Subscription: Making API call to /wordpress/cancel-subscription with shop_id = " . $shopid); $response = assistant_api_call('/wordpress/cancel-subscription', ['shop_id' => $shopid], 'post'); error_log("Cancel Subscription: API response = " . print_r($response, true)); if (is_array($response) && isset($response['status']) && $response['status'] == 200) { wp_send_json_success(); } else { wp_send_json_error(['message' => 'API error or cancellation failed']); } } add_shortcode('current_admin_name', function () { $user = wp_get_current_user(); return esc_html($user->display_name); }); /****scanner start */ function get_access_token() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://accessscanner.accessibilityassistant.com/generate-token', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => array( 'X-API-KEY: 2542342990af6dc61257b52ef1070a5ca04d9ded77989e9600f08f2d2fb032ec' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { error_log('cURL error in get_access_token: ' . curl_error($curl)); curl_close($curl); return new WP_Error('curl_error', curl_error($curl)); } $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($http_status !== 200) { error_log("API call failed with status $http_status and response: $response"); return new WP_Error('api_error', 'API returned status ' . $http_status); } $data = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { return new WP_Error('json_error', 'Invalid JSON response'); } if (empty($data['access_token'])) { return new WP_Error('no_token', 'Access token not found in API response'); } return $data['access_token']; } function getAccessibilityAudit($url) { // Use static token here, or fetch from a cache or config $token = get_access_token(); if (!$token) { return ['error' => 'Unable to retrieve token']; } $apiUrl = "https://accessscanner.accessibilityassistant.com/single-audit"; $payload = json_encode([ 'url' => $url ], JSON_UNESCAPED_SLASHES); $headers = [ "Authorization: Bearer $token", "Content-Type: application/json", "Content-Length: " . strlen($payload) ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // skip SSL verify if needed $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200 && $response) { return json_decode($response, true); } return ['error' => 'Audit API request failed', 'status' => $httpCode]; } // Register AJAX action add_action('wp_ajax_run_accessibility_audit', 'run_accessibility_audit_callback'); add_action('wp_ajax_nopriv_run_accessibility_audit', 'run_accessibility_audit_callback'); // if frontend use needed function run_accessibility_audit_callback() { // Get site url $siteUrl = site_url(); // Call the audit API $result = getAccessibilityAudit($siteUrl); wp_send_json($result); // return JSON response to JS } add_action('wp_ajax_render_audit_html', 'render_audit_html_callback'); add_action('wp_ajax_nopriv_render_audit_html', 'render_audit_html_callback'); function render_audit_html_callback() { if (!empty($_POST['audit_data'])) { $audit_data = json_decode(stripslashes($_POST['audit_data']), true); $data = $audit_data['data']; ob_start(); // start capturing HTML ?>