plugin_name = $plugin_name; $this->version = $version; $this->api = $api; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { $css_url = plugin_dir_url(__FILE__) . 'css/'; $assets_url = plugin_dir_url(__FILE__) . 'assets/'; // Main admin CSS wp_enqueue_style( 'aa-admin-style', $css_url . 'accessibility-assistant-admin.css', array(), filemtime( plugin_dir_path( __FILE__ ) . 'css/accessibility-assistant-admin.css' ), 'all' ); //Fonts CSS wp_enqueue_style( 'aa-fonts-style', $assets_url . 'fonts/fonts.googleapis.css', array(), $this->version, '1.0.0', 'all' ); //Fonts awesome CSS wp_enqueue_style( 'aa-fonts-awesome-style', $assets_url . 'fontawesome/css/all.min.css', array(), '1.0.0', 'all' ); //Bootstrap min CSS wp_enqueue_style( 'aa-fonts-awesome-styles', $assets_url . 'bootstrap/css/bootstrap.min.css', array(), '4.4.1', 'all' ); // Swiper CSS wp_enqueue_style( 'aa-swiper-style', $css_url . 'swiper-bundle.min.css', array(), '1.0.0', 'all' ); // Slick CSS wp_enqueue_style( 'aa-slick-style', $css_url . 'slick.css', array(), '1.0.0', 'all' ); // Slick theme CSS wp_enqueue_style( 'aa-slick-theme-style', $css_url . 'slick-theme.css', array(), '1.0.0', 'all' ); // Date Range Picker CSS wp_enqueue_style( 'aa-daterangepicker-style', $css_url . 'daterangepicker.css', array(), '1.0.0', 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { $js_url = plugin_dir_url(__FILE__) . 'js/'; $assets_url = plugin_dir_url(__FILE__) . 'assets/'; $shopid = get_option('accessibility_shopid'); // Main admin JS (always loaded in admin when plugin is active) wp_enqueue_script( 'aa-admin-main', $js_url . 'accessibility-assistant-admin.js', array('jquery'), $this->version, true ); // All plugin-related admin pages $plugin_pages = array( 'accessibility-assistance', 'accessibility-submenu', 'accessibility-laguages', 'accessibility-plan', 'accessibility-menu-settings', 'accessibility-widget-settings', 'accessibility-scanner', 'accessibility-scanner-result', 'accessibility-analytics-overview', ); /** * Extra assets only on plugin pages */ if (isset($_GET['page']) && in_array($_GET['page'], $plugin_pages, true)) { // Ensure jQuery + UI are available wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-draggable'); // Custom admin behaviour wp_enqueue_script( 'aa-custom-js', $js_url . 'custom_js.js', array('jquery'), '1.0.0', true ); /** * IP → country code logic (unchanged except placement) */ if (!function_exists('getUserIpAddr')) { 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}" : ""); // Avoid blocking admin page loads on slow/unreliable external calls. $ipdat = null; $ip_response = wp_remote_get( $url, array( 'timeout' => 2, ) ); if ( ! is_wp_error( $ip_response ) ) { $ip_body = wp_remote_retrieve_body( $ip_response ); if ( ! empty( $ip_body ) ) { $ipdat = json_decode( $ip_body ); } } // === your big $countryCodes array (unchanged) === $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" ]; $countryCode = '+91'; if (!empty($ipdat->country) && isset($countryCodes[$ipdat->country])) { $countryCode = $countryCodes[$ipdat->country]; } // Localize main custom script wp_localize_script('aa-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, )); // Simple ajax helper wp_localize_script('aa-custom-js', 'ajax_object', array( 'ajaxurl' => admin_url('admin-ajax.php'), )); wp_enqueue_script( 'aa-tracking-js', $js_url . 'tracking.js', array('jquery'), '1.0.0', true ); } /** * Global scripts (loaded for any admin page) */ // Slick wp_enqueue_script( 'aa-slick-js', $js_url . 'slick.min.js', array('jquery'), '1.0.0', true ); // Swiper wp_enqueue_script( 'aa-swiper-js', $js_url . 'swiper.min.js', array('jquery'), '1.0.0', true ); // bootstrap wp_enqueue_script( 'aa-swiper-js', $assets_url . 'bootstrap/js/bootstrap.bundle.min.js', array('jquery'), '4.4.1', true ); // Feedback wp_enqueue_script( 'aa-feedback', $js_url . 'feedback.js', array('jquery'), '1.0.0', true ); wp_localize_script('aa-feedback', 'ada_ajax', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ada_nonce'), )); // Scan script wp_enqueue_script( 'aa-scan', $js_url . 'scan.js', array('jquery'), '1.0.0', true ); wp_localize_script('aa-scan', 'scan_ajax_obj', array( 'ajax_url' => admin_url('admin-ajax.php'), 'shopId' => $shopid, 'currentsiteUrl' => site_url(), 'sacnbtnString' => __('Scan Your site', 'accessibility-assistant'), 'scannerResultUrl' => admin_url('admin.php?page=accessibility-scanner-result'), )); /*** 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 ***/ /** * Dashboard-specific assets (only accessibility-assistance page) */ $dashboard_pages = array('accessibility-assistance', 'accessibility-analytics-overview'); if (isset($_GET['page']) && in_array($_GET['page'], $dashboard_pages, true)) { // Moment.js wp_enqueue_script( 'aa-moment-js', $js_url . 'moment.min.js', array('jquery'), '1.0.0', true ); // DateRangePicker wp_enqueue_script( 'aa-daterangepicker-js', $js_url . 'daterangepicker.min.js', array('jquery', 'aa-moment-js'), '1.0.0', true ); // Chart.js wp_enqueue_script( 'aa-chart-js', $js_url . 'Chart.min.js', array('jquery'), '1.0.0', true ); // Chart.js datalabels plugin wp_enqueue_script( 'aa-chart-datalabels-js', $js_url . 'chartjs-plugin-datalabels.min.js', array('aa-chart-js'), '1.0.0', true ); // Dashboard logic wp_enqueue_script( 'aa-dashboard-js', $js_url . 'dashboard_count.js', array('jquery', 'aa-chart-js', 'aa-chart-datalabels-js'), '1.0.0', true ); wp_localize_script('aa-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'), )); } } public function show_install_admin_notice() { $shop_id = get_option('accessibility_shopid'); // Old behavior: only complain if shop id is completely missing. if (empty($shop_id)) { echo '

' . esc_html__('Please uninstall this plugin and reinstall it.', 'accessibility-assistant') . '

'; } } /** * Handle manual retry of the remote install/connection handshake. * * Triggered via admin URL param: ?aa_retry_install=1&_wpnonce=... * * @return void */ public function handle_retry_install_connection() { if ( ! is_admin() ) { return; } if ( empty( $_GET['aa_retry_install'] ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'aa_retry_install' ) ) { update_option( 'accessibility_install_error', 'Security check failed. Please try again.' ); return; } $plugin_version = defined( 'ACCESSIBILITY_ASSISTANT_VERSION' ) ? ACCESSIBILITY_ASSISTANT_VERSION : '1.0.0'; // Generate or reuse shop id / token $rand = time() * wp_rand(); $shopid = $rand . gmdate('m', time()) . substr(gmdate('Y', time()), 2); if ( get_option( 'accessibility_shopid' ) && get_option( 'accessibility_tokken' ) ) { $shopid = get_option( 'accessibility_shopid' ); } // Build payload using activator helper so logic stays consistent. require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-accessibility-assistant-activator.php'; $payload = Accessibility_Assistant_Activator::build_install_payload( $shopid, $plugin_version ); $body = $this->api->call( '/install', $payload, 'post' ); if ( is_array( $body ) && isset( $body['status'] ) && (int) $body['status'] === 200 && ! empty( $body['data'] ) && is_array( $body['data'] ) ) { $response = $body['data']; if ( ! empty( $response['shopid'] ) && ! empty( $response['token'] ) && ! empty( $response['id'] ) ) { 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 ); delete_option( 'accessibility_install_error' ); } else { update_option( 'accessibility_install', 0 ); update_option( 'accessibility_install_error', 'Install API returned success but missing required fields (shopid/token/id).' ); } } else { $err = 'Unable to connect to Accessibility Assistant service.'; if ( is_array( $body ) ) { if ( ! empty( $body['error'] ) && is_string( $body['error'] ) ) { $err = $body['error']; } elseif ( isset( $body['status'] ) ) { $err = 'Install API call failed (status ' . (string) $body['status'] . ').'; } } update_option( 'accessibility_install', 0 ); update_option( 'accessibility_install_error', $err ); } // Redirect to plugin dashboard so the notice updates immediately. wp_safe_redirect( admin_url( 'admin.php?page=accessibility-assistance' ) ); exit; } public function handle_language_switch() { if (isset($_POST['plugin_language'])) { //check_admin_referer('my_plugin_language_nonce', 'my_plugin_language_nonce'); // optional $input_lang = sanitize_text_field(wp_unslash($_POST['plugin_language'])); $map = (new Accessibility_Assistant_i18n())->get_language_map(); // or duplicate small helper $normalized = isset($map[$input_lang]) ? $map[$input_lang] : $input_lang; update_option('my_plugin_selected_language', $normalized); // Clear cache so language change reflects on frontend widget if applicable $this->clear_widget_cache(); // Reload the same page safely $redirect_url = wp_get_referer(); if (!$redirect_url) { $redirect_url = admin_url(); // fallback } wp_safe_redirect($redirect_url); exit; } } public function 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; } } } public function ajax_submit_uninstall_reason() { check_ajax_referer('ada_nonce'); $reason = sanitize_text_field($_POST['reason'] ?? ''); update_option('ada_uninstall_reason', $reason); wp_send_json_success(); } public function ajax_load_plan_popup() { require_once plugin_dir_path(dirname(__FILE__)) . 'admin/partials/popups/plan-popup.php'; wp_die(); } public function ajax_cancel_subscription() { 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: API call with shop_id = $shopid"); $response = $this->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']) && (int)$response['status'] === 200) { wp_send_json_success(); } wp_send_json_error(['message' => 'API error or cancellation failed']); } public function ajax_run_accessibility_audit() { $target_url = isset($_POST['target_url']) ? sanitize_text_field(wp_unslash($_POST['target_url'])) : ''; $site_url = !empty($target_url) ? $target_url : site_url(); // Basic sanity check: API expects a real URL string. $site_url = esc_url_raw($site_url); if (empty($site_url)) { wp_send_json(['error' => 'Missing URL']); } $result = $this->api->get_accessibility_audit($site_url); wp_send_json($result); } public function ajax_render_audit_html() { if (empty($_POST['audit_data'])) { wp_die(); } $audit_data = json_decode(stripslashes($_POST['audit_data']), true); $data = $audit_data['data'] ?? null; if (empty($data) || !is_array($data)) { echo '

' . esc_html__('Unable to render audit result.', 'accessibility-assistant') . '

'; wp_die(); } $score = isset($data['compliance_score']) ? (float) $data['compliance_score'] : 0.0; $totalFailed = isset($data['total_failed']) ? (float) $data['total_failed'] : 0.0; $screenshotPath = isset($data['screenshot']) ? (string) $data['screenshot'] : ''; $screenshotUrl = !empty($screenshotPath) ? 'https://accessscanner.accessibilityassistant.com/' . ltrim($screenshotPath, '/') : ''; // Scanner ring: our CSS uses `--deg` directly in a conic-gradient. $scoreDeg = ($score / 100) * 360; $failedDeg = ($totalFailed / 100) * 360; ?>
<?php esc_attr_e('result', 'accessibility-assistant'); ?>

<?php esc_attr_e('Website screenshot', 'accessibility-assistant'); ?>

%

A AA AAA

mark_quickstart_step_visited('widget_content'); require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-widget.php'; } public function menu_settings_page() { $this->mark_quickstart_step_visited('widget_settings'); require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-menu.php'; } public function languages_list_page() { $this->mark_quickstart_step_visited('language_settings'); require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-languages.php'; } public function language_edit_page() { $this->mark_quickstart_step_visited('language_settings'); require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-edit-language.php'; } public function analytics_overview_page() { require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-analytics-overview.php'; } public function plan_page() { require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-plans.php'; } public function scanner_page() { $this->mark_quickstart_step_visited('accessibility_scanner'); require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-scanner.php'; } public function scanner_history_page() { require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-scanner-history.php'; } public function scanner_result_page() { require_once plugin_dir_path(__FILE__) . 'partials/accessibility-assistant-admin-display-scanner-result.php'; } /** * Track quickstart progress by marking a step as visited. * * @param string $step_key Step identifier. * @return void */ private function mark_quickstart_step_visited($step_key) { $allowed_steps = array( 'widget_content', 'widget_settings', 'language_settings', 'accessibility_scanner', ); if (!in_array($step_key, $allowed_steps, true)) { return; } $quickstart_steps = get_option('accessibility_quickstart_steps', array()); $quickstart_steps = is_array($quickstart_steps) ? $quickstart_steps : array(); if (empty($quickstart_steps[$step_key])) { $quickstart_steps[$step_key] = current_time('mysql'); update_option('accessibility_quickstart_steps', $quickstart_steps); } } public function maybe_load_tawkto_script() { if (!isset($_GET['page'])) return; $allowed_pages = [ 'accessibility-submenu', 'accessibility-assistance', 'accessibility-plan', 'accessibility-widget-settings', 'accessibility-menu-settings', 'accessibility-scanner', 'accessibility-scanner-result', 'accessibility-analytics-overview' ]; if (!in_array($_GET['page'], $allowed_pages)) return; ?>