# Site ID and Sync Settings Fix ## Issues Addressed ### 1. ❌ "Site ID not set" Error in WordPress Plugin **Problem:** Plugin showed "X Site ID not set" error preventing sync operations **Root Cause:** - Plugin was taking the first site from `/system/sites/` API response - User has multiple sites (Home & Garden, Salman Sadiq, etc.) - Wrong site was being selected **Solution:** - Match site by domain name instead of taking first result - Added fallback to first site if no domain match - Added manual Site ID input field if auto-detection fails ### 2. ✅ Taxonomy Selection Impact Verified **Question:** Does the "Taxonomies to Sync" checkbox selection have actual impact? **Answer:** **YES!** The taxonomy selection is fully functional: **Code Reference: `data/site-collection.php` (lines 318-325)** ```php // Get enabled taxonomies from settings if (function_exists('igny8_get_enabled_taxonomies')) { $enabled_taxonomies = igny8_get_enabled_taxonomies(); if (!empty($enabled_taxonomies)) { $tracked_taxonomies = $enabled_taxonomies; } } foreach ($tracked_taxonomies as $taxonomy) { if (!taxonomy_exists($taxonomy)) { continue; } // Only syncs enabled taxonomies } ``` ✅ **Only checked taxonomies will be collected and synced** **When Selection Matters:** - ✅ "Collect & Send Site Data" button - respects selections - ✅ Cron jobs (automatic syncs) - respects selections - ✅ Manual syncs from WP Admin - respects selections ### 3. ✅ Post Type Selection Impact Verified **Question:** Does the "Post Types to Sync" checkbox selection have actual impact? **Answer:** **YES!** The post type selection is fully functional: **Code Reference: `data/site-collection.php` (lines 302-315)** ```php foreach ((array) $settings['post_types'] as $post_type) { if (!post_type_exists($post_type) || !igny8_is_post_type_enabled($post_type)) { continue; // Skips disabled post types } $posts = igny8_fetch_wordpress_posts($post_type, ...); // Only fetches enabled post types } ``` ✅ **Only checked post types will be collected and synced** **When Selection Matters:** - ✅ "Collect & Send Site Data" button - respects selections - ✅ Cron jobs (automatic syncs) - respects selections - ✅ Manual syncs from WP Admin - respects selections ### 4. ✅ App "Sync Now" Button Impact Verified **Question:** Does the "Sync Now" button on Content Types page respect plugin settings? **Answer:** **PARTIALLY** - It respects integration config, but uses backend-stored settings: **How It Works:** 1. Frontend calls: `/v1/integration/integrations/{id}/sync/` 2. Backend reads integration's `config_json.content_types` 3. Syncs based on what's **enabled in the integration record** **Important Notes:** - ✅ The "Sync Now" button syncs FROM WordPress TO IGNY8 - ✅ It uses the settings stored in the integration config (backend database) - ⚠️ If you change plugin settings, you need to send site structure first: - Click "Collect & Send Site Data" in plugin - This updates the integration config in the backend - Then "Sync Now" will use the new settings **Workflow:** ``` Plugin Settings Changed ↓ Click "Collect & Send Site Data" (updates backend config) ↓ Click "Sync Now" in App (uses updated config) ↓ Syncs with new settings ``` --- ## Changes Made ### File 1: `admin/class-admin.php` **Change 1: Site ID Detection by Domain** ```php // Before (line 278-283) $site_response = $api->get('/system/sites/'); if ($site_response['success'] && !empty($site_response['results'])) { $site = $site_response['results'][0]; // Takes first update_option('igny8_site_id', $site['id']); } // After (line 278-299) $site_response = $api->get('/system/sites/'); if ($site_response['success'] && !empty($site_response['results'])) { $current_site_url = get_site_url(); $current_domain = parse_url($current_site_url, PHP_URL_HOST); // Try to find matching site by domain $matched_site = null; foreach ($site_response['results'] as $site) { if (!empty($site['domain'])) { $site_domain = parse_url($site['domain'], PHP_URL_HOST); if ($site_domain === $current_domain) { $matched_site = $site; break; } } } // Use matched site or fallback to first if ($matched_site) { update_option('igny8_site_id', $matched_site['id']); error_log('IGNY8: Matched site by domain: ' . $matched_site['name']); } else { $site = $site_response['results'][0]; update_option('igny8_site_id', $site['id']); error_log('IGNY8: No domain match, using first site'); } } ``` **Change 2: Allow Manual Site ID (line 63-68)** ```php // Added sanitization for manual site ID entry register_setting('igny8_settings', 'igny8_site_id', array( 'type' => 'integer', 'sanitize_callback' => 'absint' )); ``` ### File 2: `admin/settings.php` **Change: Manual Site ID Input Field (line 210-232)** ```php