hash('sha256', $site_url), // Anonymized site URL 'version' => A11Y_ENHANCER_VERSION, 'timestamp' => time(), ); wp_remote_post($ping_url, array( 'method' => 'POST', 'body' => $data, 'timeout' => 5, 'blocking' => false, // Non-blocking request )); error_log('A11y Enhancer: Activation ping sent for site ' . $site_url); } register_activation_hook(__FILE__, 'a11y_enhancer_activation_ping'); // AJAX handler for translations (frontend and logged-in) add_action('wp_ajax_a11y_translate', 'a11y_enhancer_ajax_translate'); add_action('wp_ajax_nopriv_a11y_translate', 'a11y_enhancer_ajax_translate'); function a11y_enhancer_ajax_translate() { $lang = sanitize_text_field($_POST['lang'] ?? 'en'); $cache_key = 'a11y_trans_' . $lang; // Bypass cache to ensure fresh translations $translations = a11y_enhancer_get_translations($lang); error_log('A11y Enhancer: AJAX translate for lang ' . $lang . ', keys: ' . implode(', ', array_keys($translations))); wp_send_json_success($translations); } // New AJAX for Joy Burst unlock via X API add_action('wp_ajax_joy_unlock_verify', 'a11y_enhancer_joy_unlock_verify'); add_action('wp_ajax_nopriv_joy_unlock_verify', 'a11y_enhancer_joy_unlock_verify'); function a11y_enhancer_joy_unlock_verify() { if (!wp_verify_nonce($_POST['nonce'] ?? '', 'a11y_joy_nonce')) { wp_send_json_error('Invalid nonce'); } $username = sanitize_text_field($_POST['username'] ?? ''); $bearer_token = get_option('a11y_enhancer_x_bearer_token', ''); if (empty($username) || empty($bearer_token)) { wp_send_json_error('Missing username or token'); } $query = urlencode('from:' . $username . ' "you-boom" @pluginjoy since:' . date('Y-m-d', strtotime('-1 day'))); $url = 'https://api.twitter.com/2/tweets/search/recent?query=' . $query . '&max_results=1&tweet.fields=created_at'; $response = wp_remote_get($url, array( 'headers' => array('Authorization' => 'Bearer ' . $bearer_token), 'timeout' => 10, )); if (is_wp_error($response)) { wp_send_json_error('API error: ' . $response->get_error_message()); } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if (isset($data['data']) && !empty($data['data'])) { update_option('a11y_enhancer_joy_unlocked', true); wp_send_json_success('Unlocked!'); } else { wp_send_json_error('No matching tweet found. Try tweeting again.'); } } // Enqueue assets function a11y_enhancer_enqueue_assets() { wp_enqueue_style( 'a11y-enhancer-css', A11Y_ENHANCER_URL . 'assets/css/accessibility.css', array(), A11Y_ENHANCER_VERSION ); wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css', array(), '6.6.0'); $primary_color = esc_attr(get_option('a11y_enhancer_primary_color', '#6952f4')); $darker_primary = a11y_enhancer_adjust_brightness($primary_color, -40); $lighter_primary = a11y_enhancer_adjust_brightness($primary_color, 60); $darker_hover = a11y_enhancer_adjust_brightness($darker_primary, -20); $dynamic_css = " #a11y-enhancer-widget .a11y-header, #a11y-enhancer-widget .a11y-footer .a11y-powered, #a11y-enhancer-toggle, #a11y-enhancer-widget .a11y-options button.active, #a11y-enhancer-widget .a11y-options button.hold-active, #a11y-enhancer-widget .a11y-footer .button, #a11y-enhancer-widget .a11y-footer, #a11y-onboarding-close { background: {$primary_color} !important; } #a11y-enhancer-widget .a11y-indicators span { width: 6px !important; height: 6px !important; border-radius: 50% !important; background: #ccc !important; } #a11y-enhancer-widget .a11y-indicators span.active { background: {$primary_color} !important; } #a11y-enhancer-widget .a11y-options button.active, #a11y-enhancer-widget .a11y-options button.hold-active { background: linear-gradient(135deg, {$primary_color}, {$darker_primary}) !important; } #a11y-enhancer-widget .a11y-options button.active:hover, #a11y-enhancer-widget .a11y-options button.hold-active:hover { background: linear-gradient(135deg, {$darker_primary}, {$darker_hover}) !important; } #a11y-enhancer-toggle:hover { background: {$darker_primary} !important; } #a11y-enhancer-widget { max-width: " . esc_attr(get_option('a11y_enhancer_widget_width', '500px')) . " !important; font-family: " . esc_attr(get_option('a11y_enhancer_widget_font_family', 'inherit')) . " !important; font-size: " . esc_attr(get_option('a11y_enhancer_widget_font_size', '20')) . "px !important; background: " . esc_attr(get_option('a11y_enhancer_widget_bg_color', '#ffffff')) . " !important; color: " . esc_attr(get_option('a11y_enhancer_widget_text_color', '#000000')) . " !important; box-shadow: " . esc_attr(get_option('a11y_enhancer_widget_shadow', '-4px 0 12px rgba(0,0,0,0.15)')) . " !important; } #a11y-enhancer-widget .a11y-options button { background: " . esc_attr(get_option('a11y_enhancer_widget_button_bg_color', 'transparent')) . " !important; border-radius: " . esc_attr(get_option('a11y_enhancer_widget_border_radius', '6px')) . " !important; color: " . esc_attr(get_option('a11y_enhancer_widget_text_color', '#000000')) . " !important; } #a11y-enhancer-widget .a11y-options button:hover { background: #ffffff !important; } #a11y-enhancer-widget .a11y-option, #a11y-enhancer-widget .a11y-option .fas, #a11y-enhancer-widget .a11y-action, #a11y-enhancer-widget .a11y-action i { color: " . esc_attr(get_option('a11y_enhancer_widget_button_color', '#000000')) . " !important; } #a11y-enhancer-widget .a11y-action { background: {$darker_primary} !important; } #a11y-enhancer-widget .a11y-action:hover { background: {$darker_hover} !important; } #a11y-enhancer-widget .a11y-footer p, #a11y-enhancer-widget .a11y-footer .a11y-powered { color: #fff !important; } #a11y-enhancer-widget .a11y-info { background: {$lighter_primary} !important; color: #333 !important; } #a11y-enhancer-widget .a11y-tooltip { background: linear-gradient(135deg, {$primary_color}, {$darker_primary}) !important; color: #fff !important; border-color: #fff !important; } #a11y-enhancer-widget .a11y-tooltip::after { border-top-color: {$primary_color} !important; } #a11y-enhancer-widget .a11y-pro-container { background: rgba(255,255,255,0.1) !important; } #a11y-enhancer-widget .a11y-pro-text { color: #fff !important; } "; wp_add_inline_style('a11y-enhancer-css', $dynamic_css); wp_enqueue_script( 'a11y-enhancer-js', A11Y_ENHANCER_URL . 'assets/js/accessibility.js', array('jquery'), A11Y_ENHANCER_VERSION, true ); wp_localize_script('a11y-enhancer-js', 'a11yEnhancer', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('a11y_license_nonce'), 'joy_nonce' => wp_create_nonce('a11y_joy_nonce'), 'position' => get_option('a11y_enhancer_position', 'bottom-right'), 'fontSize' => get_option('a11y_enhancer_widget_font_size', '20'), 'defaultLang' => 'en', 'flags' => a11y_enhancer_get_flag_mappings() )); error_log('A11y Enhancer: Assets enqueued successfully.'); } add_action('wp_enqueue_scripts', 'a11y_enhancer_enqueue_assets'); function a11y_enhancer_adjust_brightness($hex, $steps) { $hex = ltrim($hex, '#'); if ($hex === 'transparent') { return 'transparent'; } $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); $r = max(0, min(255, $r + $steps)); $g = max(0, min(255, $g + $steps)); $b = max(0, min(255, $b + $steps)); return sprintf('#%02x%02x%02x', $r, $g, $b); } // Add widget to footer function a11y_enhancer_add_widget() { if (is_admin()) { error_log('A11y Enhancer: Skipping widget rendering in admin.'); return; } $langs = a11y_enhancer_get_all_languages(); $flags = a11y_enhancer_get_flag_mappings(); $default_lang = 'en'; $current_lang = get_option('a11y_enhancer_current_lang', $default_lang); $flag_url_base = 'https://flagcdn.com/16x12/'; $flag_code = isset($flags[$current_lang]) ? $flags[$current_lang] : 'us'; $flag_url = $flag_url_base . $flag_code . '.png'; $joy_unlocked = get_option('a11y_enhancer_joy_unlocked', false); ?>
<?php echo esc_attr($names[$current_lang] ?? 'Language'); ?>
'Clarity', 'Focus' => 'Focus', 'Soothe' => 'Soothe', 'Superhero' => 'Superhero', 'Chill' => 'Chill', 'Joy' => 'Joy', 'Joy Burst' => 'Joy Burst', 'Joy Burst Locked' => 'Joy Burst Locked (Tweet to unlock!)', ); if (isset($new_keys[$key])) { return $new_keys[$key]; } $translation = $translations[$key] ?? $key; error_log('A11y Enhancer: Translation for key ' . $key . ' in lang ' . $lang . ': ' . $translation); return $translation; } if (!defined('WP_DEBUG') || !WP_DEBUG) { ob_start(); } if (!defined('WP_DEBUG') || !WP_DEBUG) { ob_end_clean(); } function a11y_enhancer_set_installation_date() { if (false === get_option('a11y_enhancer_install_date')) { update_option('a11y_enhancer_install_date', time()); error_log('A11y Enhancer: Installation date set.'); } } register_activation_hook(__FILE__, 'a11y_enhancer_set_installation_date'); function a11y_enhancer_review_notice() { if (!current_user_can('manage_options')) { return; } $install_date = get_option('a11y_enhancer_install_date', 0); $current_time = time(); $ten_days = 10 * DAY_IN_SECONDS; $four_days = 4 * DAY_IN_SECONDS; $dismissed = get_option('a11y_enhancer_review_dismissed', false); $reviewed = get_option('a11y_enhancer_review_submitted', false); $reminder_shown = get_option('a11y_enhancer_review_reminder_shown', false); if (!$dismissed && !$reviewed && ($current_time - $install_date) >= $ten_days) { if ($reminder_shown || ($current_time - $install_date) >= ($ten_days + $four_days)) { update_option('a11y_enhancer_review_reminder_shown', true); $message = __('We noticed you’ve been using A11y Accessibility Enhancer for a while. Your feedback means a lot! Please consider leaving a review to help us improve and support others in making their sites accessible.', 'a11y-enhancer'); } else { $message = __('Thank you for using A11y Accessibility Enhancer! If you’re finding it helpful, we’d greatly appreciate a review on WordPress.org to share your experience and support our mission to enhance accessibility.', 'a11y-enhancer'); } ?>