# GrowthOS WordPress Plugin

This is the WordPress connector for GrowthOS.

## Current Scope

- Activate a WordPress site with a cloud license code.
- Store the returned site token in WordPress options.
- Check cloud connection and quota status.
- Show plugin diagnostics including API base URL, last status check, last sync, latest update check and latest error.
- Sync public WordPress pages, posts, categories, WooCommerce products and product categories to the cloud with paged collection.
- Poll cloud jobs for SaaS-triggered content sync and article publishing.
- Create WordPress posts from approved SaaS manual/auto article tasks and report the final URL back to the cloud.
- Avoid duplicate article publishing by checking the SaaS overlay id before creating a post.
- Fetch approved SEO/GEO overlays from the cloud.
- Inject approved metadata, AI Summary meta and JSON-LD schema into the page head.
- Degrade gracefully when the cloud API is unavailable, with short frontend timeouts and cooldown diagnostics.
- Render an AI chat widget with theme presets/custom colors and proxy chat requests through WordPress REST, so the cloud site token is not exposed to visitors.
- Check cloud plugin update manifests through WordPress native update hooks.

## Not Included Yet

- Customer login inside WordPress.
- Full background sync cadence controls.
- Visual FAQ block rendering.
- Customer-side SEO/GEO review UI.
- Lead/contact notification controls.

## Local Test Flow

1. Configure the cloud app:

```env
SAAS_BOOTSTRAP_LICENSE_CODE=dev-license-change-me
```

2. Install this folder as a WordPress plugin:

```text
wp-content/plugins/guangergaozhi-ai-growth/
```

3. In WordPress admin, open:

```text
Settings -> GrowthOS
```

4. Set the cloud API base URL, for example:

```text
http://localhost:45005
```

5. Paste the license code and click `Activate / Reconnect`.

6. Click `Check Status`.

7. Click `Sync Content`.

For production, use the real SaaS HTTPS domain in `Cloud API Base URL`.
For local WSL testing, private-IP package updates such as `192.168.x.x:45011` are allowed only when the package host and port match the configured Cloud API host and port, and the path is the official plugin zip path.

## Cloud API Used

- `POST /api/connector/v1/auth/activate`
- `GET /api/connector/v1/site/status`
- `POST /api/connector/v1/content/sync`
- `POST /api/connector/v1/site/jobs/next`
- `POST /api/connector/v1/site/jobs/{id}/complete`
- `GET /api/connector/v1/seo/overlays`
- `GET /api/connector/v1/chat/config`
- `POST /api/connector/v1/chat/messages`

## Security Notes

- The license code is only used during activation.
- The plugin stores only the returned site token.
- The cloud stores only token hashes.
- Model provider keys never go to WordPress.
- Token revocation and tenant quota controls should be managed from the future SaaS admin console.
