full_scan(); $score = $scanner->calculate_score($results); update_option('sitefix_last_scan', array( 'date' => current_time('mysql'), 'results' => $results, 'score' => $score, )); wp_send_json_success(array('results' => $results, 'score' => $score)); } public function toggle_fix() { check_ajax_referer('sitefix_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized'); } $fix = sanitize_text_field($_POST['fix'] ?? ''); $valid_fixes = array( 'enable_images', 'enable_headings', 'enable_focus', 'enable_links', 'enable_forms', 'enable_tables', 'enable_aria', 'enable_lang' ); if (!in_array($fix, $valid_fixes, true)) { wp_send_json_error('Invalid fix'); } $settings = get_option('sitefix_settings', array()); $settings[$fix] = empty($settings[$fix]); update_option('sitefix_settings', $settings); sitebirds_wizard()->build_snapshot(); wp_send_json_success(array( 'fix' => $fix, 'enabled' => !empty($settings[$fix]), 'message' => !empty($settings[$fix]) ? 'Enabled' : 'Disabled', )); } public function get_score() { check_ajax_referer('sitefix_nonce', 'nonce'); $last_scan = get_option('sitefix_last_scan', array()); $score = isset($last_scan['score']) ? $last_scan['score'] : 0; wp_send_json_success(array('score' => $score)); } public function sitebirds_run_wizard_scan() { check_ajax_referer('sitefix_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized'); } $snapshot = sitebirds_wizard()->build_snapshot(); $priority = (array) ($snapshot['sitebirds_scan']['priority_issues'] ?? []); $plugin_scan = sitebirds_plugin_scanner()->get_cache(); $score = (int) ($snapshot['sitebirds_scan']['score'] ?? 0); update_option('sitefix_last_scan', array( 'date' => current_time('mysql'), 'results' => array(), 'score' => $score, )); $opportunities = array(); $opportunities[] = !empty($snapshot['features']['contact_forms']) ? 'Forms detected: SiteBirds can structure and forward requests.' : 'No major form plugin found: SiteBirds can improve first-contact capture.'; $opportunities[] = !empty($snapshot['features']['booking_tools']) ? 'Booking plugin detected: good candidate for after-hours capture.' : 'No booking plugin found: SiteBirds can capture appointment intent first.'; $opportunities[] = !empty($snapshot['features']['woocommerce']) ? 'WooCommerce detected: product and support questions matter.' : 'Business site mode: focus on leads, quote requests and calls.'; wp_send_json_success(array( 'score' => $score, 'score_class' => $score >= 80 ? 'good' : ($score >= 55 ? 'mid' : 'low'), 'priority_issues' => $priority, 'replaceable_count' => (int) ($plugin_scan['replaceable_count'] ?? 0), 'estimated_size_kb' => (int) ($plugin_scan['estimated_size_kb'] ?? 0), 'matches' => array_values((array) ($plugin_scan['matches'] ?? [])), 'active_fixes' => (int) ($snapshot['fixes']['active_count'] ?? 0), 'opportunities' => $opportunities, 'wizard_url' => sitebirds_wizard()->get_wizard_url(), )); } } new SiteFix_Ajax();