asd
This commit is contained in:
396
igy8-wp-plugin/docs/README.md
Normal file
396
igy8-wp-plugin/docs/README.md
Normal file
@@ -0,0 +1,396 @@
|
||||
# IGNY8 WordPress Bridge Plugin
|
||||
|
||||
**Version**: 1.0.0
|
||||
**Last Updated**: 2025-10-17
|
||||
**Requires**: WordPress 5.0+, PHP 7.4+
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The IGNY8 WordPress Bridge Plugin is a **lightweight synchronization interface** that connects WordPress sites to the IGNY8 API. This plugin acts as a bridge, not a content management system, using WordPress native structures (taxonomies, post meta) to sync data bidirectionally with IGNY8.
|
||||
|
||||
### Key Principles
|
||||
|
||||
- ✅ **No Custom Database Tables** - Uses WordPress native taxonomies and post meta
|
||||
- ✅ **Lightweight Bridge** - Minimal code, maximum efficiency
|
||||
- ✅ **Two-Way Sync** - WordPress ↔ IGNY8 API synchronization
|
||||
- ✅ **WordPress Native** - Leverages existing WordPress structures
|
||||
- ✅ **API-First** - IGNY8 API is the source of truth
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
### Core Functionality
|
||||
|
||||
1. **API Authentication**
|
||||
- Secure token management
|
||||
- Automatic token refresh
|
||||
- Encrypted credential storage
|
||||
|
||||
2. **Two-Way Synchronization**
|
||||
- WordPress → IGNY8: Post status changes sync to IGNY8 tasks
|
||||
- IGNY8 → WordPress: Content published from IGNY8 creates WordPress posts
|
||||
|
||||
3. **Taxonomy Mapping**
|
||||
- WordPress taxonomies → IGNY8 Sectors/Clusters
|
||||
- Hierarchical taxonomies map to IGNY8 Sectors
|
||||
- Taxonomy terms map to IGNY8 Clusters
|
||||
|
||||
4. **Post Meta Integration**
|
||||
- `_igny8_task_id` - Links WordPress posts to IGNY8 tasks
|
||||
- `_igny8_cluster_id` - Links posts to IGNY8 clusters
|
||||
- `_igny8_sector_id` - Links posts to IGNY8 sectors
|
||||
- `_igny8_keyword_ids` - Links posts to IGNY8 keywords
|
||||
|
||||
5. **Site Data Collection**
|
||||
- Automatic collection of WordPress posts, taxonomies, products
|
||||
- Semantic mapping to IGNY8 structure
|
||||
- WooCommerce integration support
|
||||
|
||||
6. **Status Mapping**
|
||||
- WordPress post status → IGNY8 task status
|
||||
- Automatic sync on post save/publish/status change
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
### Requirements
|
||||
|
||||
- WordPress 5.0 or higher
|
||||
- PHP 7.4 or higher
|
||||
- WordPress REST API enabled
|
||||
- IGNY8 API account credentials
|
||||
|
||||
### Installation Steps
|
||||
|
||||
1. **Download/Clone Plugin**
|
||||
```bash
|
||||
git clone [repository-url]
|
||||
cd igny8-ai-os
|
||||
```
|
||||
|
||||
2. **Install in WordPress**
|
||||
- Copy the `igny8-ai-os` folder to `/wp-content/plugins/`
|
||||
- Or create a symlink for development
|
||||
|
||||
3. **Activate Plugin**
|
||||
- Go to WordPress Admin → Plugins
|
||||
- Activate "IGNY8 WordPress Bridge"
|
||||
|
||||
4. **Configure API Connection**
|
||||
- Go to Settings → IGNY8 API
|
||||
- Enter your IGNY8 email and password
|
||||
- Click "Connect to IGNY8"
|
||||
|
||||
---
|
||||
|
||||
## Configuration
|
||||
|
||||
### API Settings
|
||||
|
||||
Navigate to **Settings → IGNY8 API** to configure:
|
||||
|
||||
- **Email**: Your IGNY8 account email
|
||||
- **Password**: Your IGNY8 account password
|
||||
- **Site ID**: Your IGNY8 site ID (auto-detected after connection)
|
||||
|
||||
### WordPress Integration
|
||||
|
||||
The plugin automatically:
|
||||
|
||||
1. **Registers Taxonomies** (if needed):
|
||||
- `sectors` - Maps to IGNY8 Sectors
|
||||
- `clusters` - Maps to IGNY8 Clusters
|
||||
|
||||
2. **Registers Post Meta Fields**:
|
||||
- `_igny8_task_id`
|
||||
- `_igny8_cluster_id`
|
||||
- `_igny8_sector_id`
|
||||
- `_igny8_keyword_ids`
|
||||
- `_igny8_content_id`
|
||||
|
||||
3. **Sets Up WordPress Hooks**:
|
||||
- `save_post` - Syncs post changes to IGNY8
|
||||
- `publish_post` - Updates keywords on publish
|
||||
- `transition_post_status` - Handles status changes
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Workflow
|
||||
|
||||
#### 1. Connect to IGNY8 API
|
||||
|
||||
```php
|
||||
// Automatically handled via Settings page
|
||||
// Or programmatically:
|
||||
$api = new Igny8API();
|
||||
$api->login('your@email.com', 'password');
|
||||
```
|
||||
|
||||
#### 2. Sync WordPress Site Data
|
||||
|
||||
```php
|
||||
// Collect and send site data to IGNY8
|
||||
$site_id = get_option('igny8_site_id');
|
||||
igny8_send_site_data_to_igny8($site_id);
|
||||
```
|
||||
|
||||
#### 3. WordPress → IGNY8 Sync
|
||||
|
||||
When you save/publish a WordPress post:
|
||||
|
||||
1. Plugin checks for `_igny8_task_id` in post meta
|
||||
2. If found, syncs post status to IGNY8 task
|
||||
3. If published, updates related keywords to 'mapped' status
|
||||
|
||||
#### 4. IGNY8 → WordPress Sync
|
||||
|
||||
When content is published from IGNY8:
|
||||
|
||||
1. IGNY8 triggers webhook (or scheduled sync)
|
||||
2. Plugin creates WordPress post via `wp_insert_post()`
|
||||
3. Post meta saved with `_igny8_task_id`
|
||||
4. IGNY8 task updated with WordPress post ID
|
||||
|
||||
---
|
||||
|
||||
## WordPress Structures Used
|
||||
|
||||
### Taxonomies
|
||||
|
||||
- **`sectors`** (hierarchical)
|
||||
- Maps to IGNY8 Sectors
|
||||
- Can be created manually or synced from IGNY8
|
||||
|
||||
- **`clusters`** (hierarchical)
|
||||
- Maps to IGNY8 Clusters
|
||||
- Can be created manually or synced from IGNY8
|
||||
|
||||
- **Native Taxonomies**
|
||||
- `category` - Can map to IGNY8 Sectors
|
||||
- `post_tag` - Can be used for keyword extraction
|
||||
|
||||
### Post Meta Fields
|
||||
|
||||
All stored in WordPress `wp_postmeta` table:
|
||||
|
||||
- `_igny8_task_id` (integer) - IGNY8 task ID
|
||||
- `_igny8_cluster_id` (integer) - IGNY8 cluster ID
|
||||
- `_igny8_sector_id` (integer) - IGNY8 sector ID
|
||||
- `_igny8_keyword_ids` (array) - Array of IGNY8 keyword IDs
|
||||
- `_igny8_content_id` (integer) - IGNY8 content ID
|
||||
- `_igny8_last_synced` (datetime) - Last sync timestamp
|
||||
|
||||
### Post Status Mapping
|
||||
|
||||
| WordPress Status | IGNY8 Task Status |
|
||||
|------------------|-------------------|
|
||||
| `publish` | `completed` |
|
||||
| `draft` | `draft` |
|
||||
| `pending` | `pending` |
|
||||
| `private` | `completed` |
|
||||
| `trash` | `archived` |
|
||||
| `future` | `scheduled` |
|
||||
|
||||
---
|
||||
|
||||
## API Reference
|
||||
|
||||
### Main Classes
|
||||
|
||||
#### `Igny8API`
|
||||
|
||||
Main API client class for all IGNY8 API interactions.
|
||||
|
||||
```php
|
||||
$api = new Igny8API();
|
||||
|
||||
// Login
|
||||
$api->login('email@example.com', 'password');
|
||||
|
||||
// Get keywords
|
||||
$response = $api->get('/planner/keywords/');
|
||||
|
||||
// Create task
|
||||
$response = $api->post('/writer/tasks/', $data);
|
||||
|
||||
// Update task
|
||||
$response = $api->put('/writer/tasks/123/', $data);
|
||||
```
|
||||
|
||||
#### `Igny8WordPressSync`
|
||||
|
||||
Handles two-way synchronization between WordPress and IGNY8.
|
||||
|
||||
```php
|
||||
$sync = new Igny8WordPressSync();
|
||||
// Automatically hooks into WordPress post actions
|
||||
```
|
||||
|
||||
#### `Igny8SiteIntegration`
|
||||
|
||||
Manages site data collection and semantic mapping.
|
||||
|
||||
```php
|
||||
$integration = new Igny8SiteIntegration($site_id);
|
||||
$result = $integration->full_site_scan();
|
||||
```
|
||||
|
||||
### Main Functions
|
||||
|
||||
- `igny8_login($email, $password)` - Authenticate with IGNY8
|
||||
- `igny8_sync_post_status_to_igny8($post_id, $post, $update)` - Sync post to IGNY8
|
||||
- `igny8_collect_site_data()` - Collect all WordPress site data
|
||||
- `igny8_send_site_data_to_igny8($site_id)` - Send site data to IGNY8
|
||||
- `igny8_map_site_to_semantic_strategy($site_id, $site_data)` - Map to semantic structure
|
||||
|
||||
### Site Metadata Endpoint (Plugin)
|
||||
|
||||
The plugin exposes a discovery endpoint that your IGNY8 app can call to learn which WordPress post types and taxonomies exist and how many items each contains.
|
||||
|
||||
- Endpoint: `GET /wp-json/igny8/v1/site-metadata/`
|
||||
- Auth: Plugin-level connection must be enabled and authenticated (plugin accepts stored API key or access token)
|
||||
- Response: IGNY8 unified response format (`success`, `data`, `message`, `request_id`)
|
||||
|
||||
Example response:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"post_types": {
|
||||
"post": { "label": "Posts", "count": 123 },
|
||||
"page": { "label": "Pages", "count": 12 }
|
||||
},
|
||||
"taxonomies": {
|
||||
"category": { "label": "Categories", "count": 25 },
|
||||
"post_tag": { "label": "Tags", "count": 102 }
|
||||
},
|
||||
"generated_at": 1700553600
|
||||
},
|
||||
"message": "Site metadata retrieved",
|
||||
"request_id": "550e8400-e29b-41d4-a716-446655440000"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
igny8-ai-os/
|
||||
├── igny8-bridge.php # Main plugin file
|
||||
├── README.md # This file
|
||||
├── docs/ # Documentation hub
|
||||
│ ├── README.md # Index of available docs
|
||||
│ ├── WORDPRESS-PLUGIN-INTEGRATION.md
|
||||
│ ├── wp-bridge-implementation-plan.md
|
||||
│ ├── missing-saas-api-endpoints.md
|
||||
│ ├── STATUS_SYNC_DOCUMENTATION.md
|
||||
│ └── STYLE_GUIDE.md
|
||||
├── includes/
|
||||
│ ├── class-igny8-api.php # API client class
|
||||
│ ├── class-igny8-sync.php # Sync handler class
|
||||
│ ├── class-igny8-site.php # Site integration class
|
||||
│ └── functions.php # Helper functions
|
||||
├── admin/
|
||||
│ ├── class-admin.php # Admin interface
|
||||
│ ├── settings.php # Settings page
|
||||
│ └── assets/
|
||||
│ ├── css/
|
||||
│ └── js/
|
||||
├── sync/
|
||||
│ ├── hooks.php # WordPress hooks
|
||||
│ ├── post-sync.php # Post synchronization
|
||||
│ └── taxonomy-sync.php # Taxonomy synchronization
|
||||
├── data/
|
||||
│ ├── site-collection.php # Site data collection
|
||||
│ └── semantic-mapping.php # Semantic mapping
|
||||
└── uninstall.php # Uninstall handler
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Development
|
||||
|
||||
### Code Standards
|
||||
|
||||
- Follow WordPress Coding Standards
|
||||
- Use WordPress native functions
|
||||
- No custom database tables
|
||||
- All data in WordPress native structures
|
||||
|
||||
### Testing
|
||||
|
||||
```bash
|
||||
# Run WordPress unit tests
|
||||
phpunit
|
||||
|
||||
# Test API connection
|
||||
wp eval 'var_dump((new Igny8API())->login("test@example.com", "password"));'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Authentication Issues
|
||||
|
||||
**Problem**: Cannot connect to IGNY8 API
|
||||
|
||||
**Solutions**:
|
||||
1. Verify email and password are correct
|
||||
2. Check API endpoint is accessible
|
||||
3. Check WordPress REST API is enabled
|
||||
4. Review error logs in WordPress debug log
|
||||
|
||||
### Sync Issues
|
||||
|
||||
**Problem**: Posts not syncing to IGNY8
|
||||
|
||||
**Solutions**:
|
||||
1. Verify `_igny8_task_id` exists in post meta
|
||||
2. Check API token is valid (not expired)
|
||||
3. Review WordPress hooks are firing
|
||||
4. Check error logs
|
||||
|
||||
### Token Expiration
|
||||
|
||||
**Problem**: Token expires frequently
|
||||
|
||||
**Solution**: Plugin automatically refreshes tokens. If issues persist, check token refresh logic.
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
- **Documentation**: See `WORDPRESS-PLUGIN-INTEGRATION.md`
|
||||
- **API Documentation**: https://api.igny8.com/docs
|
||||
- **Issues**: [GitHub Issues](repository-url/issues)
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
[Your License Here]
|
||||
|
||||
---
|
||||
|
||||
## Changelog
|
||||
|
||||
### 1.0.0 - 2025-10-17
|
||||
- Initial release
|
||||
- API authentication
|
||||
- Two-way sync
|
||||
- Site data collection
|
||||
- Semantic mapping
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-10-17
|
||||
|
||||
356
igy8-wp-plugin/docs/SYNC-DATA-FLOW-DIAGRAM.md
Normal file
356
igy8-wp-plugin/docs/SYNC-DATA-FLOW-DIAGRAM.md
Normal file
@@ -0,0 +1,356 @@
|
||||
# WordPress Plugin ↔ IGNY8 Backend Sync - Data Flow Diagram
|
||||
|
||||
## Complete Sync Journey
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ WORDPRESS ADMIN - Connection Setup │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ User Input: │
|
||||
│ ┌───────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Email: dev@igny8.com │ │
|
||||
│ │ Password: **** │ │
|
||||
│ │ API Key: **** │ │
|
||||
│ └───────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ WORDPRESS PLUGIN - Authentication (class-admin.php handle_connection()) │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ 1. POST /auth/login/ (with email + password) │
|
||||
│ ↓ │
|
||||
│ 2. Store: access_token, refresh_token │
|
||||
│ ↓ │
|
||||
│ 3. GET /system/sites/ (authenticated) │
|
||||
│ ↓ │
|
||||
│ 4. Store: site_id (extracted from first site) │
|
||||
│ ↓ │
|
||||
│ ✅ Connection complete! User sees success message │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ WORDPRESS PLUGIN - Gather Site Structure (igny8_sync_site_structure_to_backend)
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ Step 1: Query for Integration ID │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ GET /v1/integration/integrations/ │ │
|
||||
│ │ ?site={site_id} │ │
|
||||
│ │ &platform=wordpress ← NEW: Platform filter │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ ↓ │
|
||||
│ Step 2: Extract Integration ID (handle multiple response formats) │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Response Format Handling: │ │
|
||||
│ │ • Paginated: data.results[0] ← Django REST Framework │ │
|
||||
│ │ • Array: data[0] ← Alternative format │ │
|
||||
│ │ • Object: data ← Direct single object │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ ↓ │
|
||||
│ Step 3: Gather WordPress Content Structure │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Post Types (igny8_get_site_structure): │ │
|
||||
│ │ ├─ post → "Posts" (count: 50) │ │
|
||||
│ │ ├─ page → "Pages" (count: 10) │ │
|
||||
│ │ └─ product → "Products" (count: 100) │ │
|
||||
│ │ │ │
|
||||
│ │ Taxonomies: │ │
|
||||
│ │ ├─ category → "Categories" (count: 12) │ │
|
||||
│ │ ├─ post_tag → "Tags" (count: 89) │ │
|
||||
│ │ └─ product_cat → "Product Categories" (count: 15) │ │
|
||||
│ │ │ │
|
||||
│ │ Metadata: │ │
|
||||
│ │ ├─ timestamp (ISO 8601 format) ← NEW │ │
|
||||
│ │ ├─ site_url (WordPress domain) ← NEW │ │
|
||||
│ │ └─ wordpress_version (e.g., 6.4) ← NEW │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ With Enhanced Debug Logging (if WP_DEBUG or IGNY8_DEBUG enabled): │
|
||||
│ • Log: Integration ID retrieved │
|
||||
│ • Log: Structure gathered successfully │
|
||||
│ • Log: Ready to sync │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ WORDPRESS → IGNY8 BACKEND - Push Structure (class-igny8-api.php post()) │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ POST /v1/integration/integrations/{integration_id}/update-structure/ │
|
||||
│ │
|
||||
│ Headers: │
|
||||
│ ├─ Authorization: Bearer {access_token} │
|
||||
│ └─ Content-Type: application/json │
|
||||
│ │
|
||||
│ Request Body: │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ { │ │
|
||||
│ │ "post_types": { │ │
|
||||
│ │ "post": { │ │
|
||||
│ │ "label": "Posts", │ │
|
||||
│ │ "count": 50, │ │
|
||||
│ │ "enabled": true, │ │
|
||||
│ │ "fetch_limit": 100 │ │
|
||||
│ │ }, │ │
|
||||
│ │ "page": {...}, │ │
|
||||
│ │ "product": {...} │ │
|
||||
│ │ }, │ │
|
||||
│ │ "taxonomies": { │ │
|
||||
│ │ "category": { │ │
|
||||
│ │ "label": "Categories", │ │
|
||||
│ │ "count": 12, │ │
|
||||
│ │ "enabled": true, │ │
|
||||
│ │ "fetch_limit": 100 │ │
|
||||
│ │ }, │ │
|
||||
│ │ "post_tag": {...}, │ │
|
||||
│ │ "product_cat": {...} │ │
|
||||
│ │ }, │ │
|
||||
│ │ "timestamp": "2025-11-22T10:15:30+00:00", │ │
|
||||
│ │ "plugin_connection_enabled": true, │ │
|
||||
│ │ "two_way_sync_enabled": true │ │
|
||||
│ │ } │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ Debug Logging (NEW - Post Request Logging): │
|
||||
│ ├─ Log: Request URL │
|
||||
│ ├─ Log: Request payload (sanitized) │
|
||||
│ ├─ Log: Response status code │
|
||||
│ ├─ Log: Response body (first 500 chars) │
|
||||
│ └─ Log: Success/error with integration ID │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ IGNY8 BACKEND - Store Structure (modules/integration/views.py │
|
||||
│ update_site_structure action) │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ 1. Authenticate request │
|
||||
│ ├─ Check Bearer token │
|
||||
│ └─ Verify user owns this integration │
|
||||
│ │
|
||||
│ 2. Extract payload │
|
||||
│ ├─ post_types │
|
||||
│ ├─ taxonomies │
|
||||
│ ├─ timestamp (optional, defaults to now) │
|
||||
│ ├─ plugin_connection_enabled │
|
||||
│ └─ two_way_sync_enabled │
|
||||
│ │
|
||||
│ 3. Store in SiteIntegration.config_json │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ config_json = { │ │
|
||||
│ │ "content_types": { │ │
|
||||
│ │ "post_types": {...}, │ │
|
||||
│ │ "taxonomies": {...}, │ │
|
||||
│ │ "last_structure_fetch": "2025-11-22T10:15:30+00:00" │ │
|
||||
│ │ }, │ │
|
||||
│ │ "plugin_connection_enabled": true, │ │
|
||||
│ │ "two_way_sync_enabled": true, │ │
|
||||
│ │ ... other config fields ... │ │
|
||||
│ │ } │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ 4. Return Success Response │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ { │ │
|
||||
│ │ "success": true, │ │
|
||||
│ │ "data": { │ │
|
||||
│ │ "message": "Site structure updated successfully", │ │
|
||||
│ │ "post_types_count": 3, │ │
|
||||
│ │ "taxonomies_count": 3, │ │
|
||||
│ │ "last_structure_fetch": "2025-11-22T10:15:30+00:00" │ │
|
||||
│ │ } │ │
|
||||
│ │ } │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ 5. Database save │
|
||||
│ └─ SiteIntegration record updated │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ WORDPRESS PLUGIN - Confirm Success & Update Options │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ 1. Response Received (success == true) │
|
||||
│ ├─ Show success message to user │
|
||||
│ ├─ Log: "Site structure synced successfully" │
|
||||
│ └─ Update option: igny8_last_structure_sync = timestamp │
|
||||
│ │
|
||||
│ 2. New Options Created: │
|
||||
│ ├─ igny8_structure_synced = 1 (flag for status checking) │
|
||||
│ └─ igny8_last_structure_sync = unix timestamp │
|
||||
│ │
|
||||
│ 3. User Feedback: │
|
||||
│ ├─ "Successfully connected to IGNY8 API" │
|
||||
│ ├─ "Site structure synced successfully" ← NEW MESSAGE │
|
||||
│ └─ Or: "Connected but structure sync will be retried" (non-blocking) │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ IGNY8 FRONTEND - Fetch & Display Content Types │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ 1. User navigates to Site Settings → Content Types Tab │
|
||||
│ │
|
||||
│ 2. Frontend queries backend: │
|
||||
│ GET /v1/integration/integrations/{integration_id}/content-types/ │
|
||||
│ │
|
||||
│ 3. Backend processes request (content_types_summary action): │
|
||||
│ ├─ Get stored content_types from config_json │
|
||||
│ ├─ Count synced items in Content model │
|
||||
│ ├─ Count synced items in ContentTaxonomy model │
|
||||
│ ├─ Compute synced_count for each post type │
|
||||
│ └─ Compute synced_count for each taxonomy │
|
||||
│ │
|
||||
│ 4. Backend Response: │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ { │ │
|
||||
│ │ "success": true, │ │
|
||||
│ │ "data": { │ │
|
||||
│ │ "post_types": { │ │
|
||||
│ │ "post": { │ │
|
||||
│ │ "label": "Posts", │ │
|
||||
│ │ "count": 50, ← Total in WordPress │ │
|
||||
│ │ "synced_count": 30, ← Synced to IGNY8 │ │
|
||||
│ │ "enabled": true, │ │
|
||||
│ │ "fetch_limit": 100 │ │
|
||||
│ │ }, │ │
|
||||
│ │ "page": {...}, │ │
|
||||
│ │ "product": {...} │ │
|
||||
│ │ }, │ │
|
||||
│ │ "taxonomies": { │ │
|
||||
│ │ "category": { │ │
|
||||
│ │ "label": "Categories", │ │
|
||||
│ │ "count": 12, ← Total in WordPress │ │
|
||||
│ │ "synced_count": 12, ← Synced to IGNY8 │ │
|
||||
│ │ "enabled": true, │ │
|
||||
│ │ "fetch_limit": 100 │ │
|
||||
│ │ }, │ │
|
||||
│ │ "post_tag": {...}, │ │
|
||||
│ │ "product_cat": {...} │ │
|
||||
│ │ }, │ │
|
||||
│ │ "last_structure_fetch": "2025-11-22T10:15:30+00:00", │ │
|
||||
│ │ "plugin_connection_enabled": true, │ │
|
||||
│ │ "two_way_sync_enabled": true │ │
|
||||
│ │ } │ │
|
||||
│ │ } │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ 5. Frontend Renders: │
|
||||
│ ┌────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ Content Types │ │
|
||||
│ │ ┌──────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ Post Types │ │ │
|
||||
│ │ │ ┌────────────────────────────────────────────────────┐ │ │ │
|
||||
│ │ │ │ Posts 50 total · 30 synced │ │ │ │
|
||||
│ │ │ │ Enabled Limit: 100 │ │ │ │
|
||||
│ │ │ └────────────────────────────────────────────────────┘ │ │ │
|
||||
│ │ │ ┌────────────────────────────────────────────────────┐ │ │ │
|
||||
│ │ │ │ Pages 10 total · 8 synced │ │ │ │
|
||||
│ │ │ │ Enabled Limit: 100 │ │ │ │
|
||||
│ │ │ └────────────────────────────────────────────────────┘ │ │ │
|
||||
│ │ │ ┌────────────────────────────────────────────────────┐ │ │ │
|
||||
│ │ │ │ Products 100 total · 45 synced │ │ │ │
|
||||
│ │ │ │ Enabled Limit: 100 │ │ │ │
|
||||
│ │ │ └────────────────────────────────────────────────────┘ │ │ │
|
||||
│ │ └──────────────────────────────────────────────────────────┘ │ │
|
||||
│ │ │ │
|
||||
│ │ ┌──────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ Taxonomies │ │ │
|
||||
│ │ │ ┌────────────────────────────────────────────────────┐ │ │ │
|
||||
│ │ │ │ Categories 12 total · 12 synced │ │ │ │
|
||||
│ │ │ │ Enabled Limit: 100 │ │ │ │
|
||||
│ │ │ └────────────────────────────────────────────────────┘ │ │ │
|
||||
│ │ │ ┌────────────────────────────────────────────────────┐ │ │ │
|
||||
│ │ │ │ Tags 89 total · 60 synced │ │ │ │
|
||||
│ │ │ │ Enabled Limit: 100 │ │ │ │
|
||||
│ │ │ └────────────────────────────────────────────────────┘ │ │ │
|
||||
│ │ └──────────────────────────────────────────────────────────┘ │ │
|
||||
│ │ │ │
|
||||
│ │ Structure last fetched: 2025-11-22 10:15:30 UTC │ │
|
||||
│ └────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Daily Cron Job - Automatic Updates
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ WordPress Cron - Daily Schedule (igny8_sync_site_structure) │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ Every 24 hours: │
|
||||
│ ├─ Trigger: do_action('igny8_sync_site_structure') │
|
||||
│ ├─ Call: igny8_sync_site_structure_to_backend() │
|
||||
│ ├─ Same flow as above (Get structure → Push to backend) │
|
||||
│ ├─ Updates counts and structure if changed │
|
||||
│ └─ Ensures frontend always has current data │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Handling & Logging Flow
|
||||
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────────────────────┐
|
||||
│ Error Detection & Logging │
|
||||
├──────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ If query fails: │
|
||||
│ ├─ Log: "Failed to fetch integrations. Error: [details]" │
|
||||
│ └─ Return: false (non-blocking) │
|
||||
│ │
|
||||
│ If integration not found: │
|
||||
│ ├─ Log: "Could not find valid WordPress integration for site {id}" │
|
||||
│ ├─ Log: "Response data: [full response]" │
|
||||
│ └─ Return: false (non-blocking) │
|
||||
│ │
|
||||
│ If POST fails: │
|
||||
│ ├─ Log: "Failed to sync site structure to integration {id}" │
|
||||
│ ├─ Log: "Error: [error message]" │
|
||||
│ ├─ Log: "Full response: [response JSON]" │
|
||||
│ └─ Return: false (non-blocking) │
|
||||
│ │
|
||||
│ If successful: │
|
||||
│ ├─ Log: "Site structure synced successfully to integration {id}" │
|
||||
│ ├─ Update: igny8_structure_synced option │
|
||||
│ ├─ Update: igny8_last_structure_sync timestamp │
|
||||
│ └─ Return: true │
|
||||
│ │
|
||||
│ All logs go to: wp-content/debug.log │
|
||||
│ To enable: define('WP_DEBUG_LOG', true) in wp-config.php │
|
||||
│ │
|
||||
└──────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
✅ **Reliable bidirectional data flow**
|
||||
- WordPress → Backend: Structure pushed on connection and daily
|
||||
- Backend → Frontend: Structure retrieved and displayed with sync counts
|
||||
- All steps logged and error-handled
|
||||
- Non-blocking approach ensures connection always succeeds
|
||||
|
||||
✅ **User visibility**
|
||||
- Clear success/failure messages
|
||||
- Debug logs provide troubleshooting info
|
||||
- Frontend shows current status and counts
|
||||
|
||||
✅ **Maintenance**
|
||||
- Automatic daily updates keep data fresh
|
||||
- Error handling prevents sync failures from breaking the system
|
||||
- Complete audit trail in logs
|
||||
|
||||
2135
igy8-wp-plugin/docs/WORDPRESS-PLUGIN-INTEGRATION.md
Normal file
2135
igy8-wp-plugin/docs/WORDPRESS-PLUGIN-INTEGRATION.md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user