# Pushrow for Google Sheets

Sync WordPress data to Google Sheets. Export Posts, Pages, Users, and Contact Form 7 submissions with one click.

## Requirements

- PHP 7.4+
- WordPress 6.0+
- Composer (for installing Google API dependencies)

## Installation

1. Upload the `pushrow-for-google-sheets` folder to `/wp-content/plugins/`
2. Run `composer install --no-dev` inside the plugin directory
3. Activate the plugin from the WordPress admin
4. Go to **Pushrow → Settings** and follow the connection wizard

### Reducing Vendor Size

The plugin uses `google/apiclient` but only loads Sheets and Drive services (~3-4MB instead of ~40MB). The `composer.json` is preconfigured with Google's cleanup script. Just run:

```bash
composer install --no-dev --optimize-autoloader
```

If your vendor folder is still large, run:

```bash
./build.sh
```

This creates an optimized distribution zip in `./dist/`.

## Google API Setup

### 1. Create a Google Cloud Project

1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Click **Select a project** → **New Project**
3. Enter a project name (e.g., "Pushrow") and click **Create**

### 2. Enable Required APIs

The plugin requires two Google APIs:

- **Google Sheets API** — For reading and writing spreadsheet data
- **Google Drive API** — For listing your spreadsheets (read-only metadata access)

To enable them:

1. Go to **APIs & Services** → **Library**
2. Search for **Google Sheets API**, click it, then click **Enable**
3. Search for **Google Drive API**, click it, then click **Enable**

### 3. Configure OAuth Consent Screen

1. Go to **APIs & Services** → **OAuth consent screen**
2. Select **External** user type (or Internal if using Google Workspace)
3. Fill in the required fields: App name, User support email, Developer contact email
4. On the **Scopes** step, add these scopes:
   - `https://www.googleapis.com/auth/spreadsheets` (read/write access to Sheets)
   - `https://www.googleapis.com/auth/drive.metadata.readonly` (list spreadsheets from Drive)
5. Save and continue

### 4. Create OAuth 2.0 Client ID

1. Go to **APIs & Services** → **Credentials**
2. Click **Create Credentials** → **OAuth client ID**
3. Set **Application type** to **Web application**
4. Under **Authorized redirect URIs**, add the redirect URI shown in **Pushrow → Settings** in your WordPress admin
5. Click **Create**
6. Copy the **Client ID** and **Client Secret**

### 5. Connect in WordPress

1. Go to **Pushrow → Settings** in your WordPress admin
2. Paste the Client ID and Client Secret
3. Click **Connect Google Account** and authorize access

## Supported Data Providers

### WordPress Core

| Provider | Export | Import | Real-time | Scheduled |
|----------|--------|--------|-----------|-----------|
| Posts & Pages | ✅ | ✅ | ✅ | ✅ |
| Custom Post Types + ACF | ✅ | ✅ | ✅ | ✅ |
| Users | ✅ | ❌ | ✅ | ✅ |

### WooCommerce

| Provider | Export | Import | Real-time | Scheduled |
|----------|--------|--------|-----------|-----------|
| WooCommerce Orders | ✅ | ✅ (status/notes) | ✅ | ✅ |
| WooCommerce Products | ✅ | ✅ | ✅ | ✅ |
| WooCommerce Customers | ✅ | ✅ (profile) | ✅ | ✅ |

### Easy Digital Downloads

| Provider | Export | Import | Real-time | Scheduled |
|----------|--------|--------|-----------|-----------|
| EDD Orders | ✅ | ❌ | ✅ | ✅ |
| EDD Customers | ✅ | ❌ | ✅ | ✅ |
| EDD Licenses | ✅ | ❌ | ✅ | ✅ |

### Form Plugins

| Provider | Export | Import | Real-time | Scheduled |
|----------|--------|--------|-----------|-----------|
| Contact Form 7 | ✅ | ❌ | ✅ | ✅ |
| Gravity Forms | ✅ | ❌ | ✅ | ✅ |
| WPForms | ✅ | ❌ | ✅ | ✅ |
| Elementor Forms | ✅ | ❌ | ✅ | ✅ |
| Ninja Forms | ✅ | ❌ | ✅ | ✅ |
| Fluent Forms | ✅ | ❌ | ✅ | ✅ |
| Formidable Forms | ✅ | ❌ | ✅ | ✅ |

### LMS & Booking

| Provider | Export | Import | Real-time | Scheduled |
|----------|--------|--------|-----------|-----------|
| LearnDash Enrollments | ✅ | ❌ | ✅ | ✅ |
| LearnDash Quiz Results | ✅ | ❌ | ✅ | ✅ |
| Amelia Bookings | ✅ | ❌ | ✅ | ✅ |

## REST API Endpoints

All endpoints are under `wp-json/pushrow/v1/` and require `manage_options` capability.

### Auth
- `GET /auth/status` — Connection status
- `POST /auth/credentials` — Save Google API credentials
- `GET /auth/url` — Get OAuth authorization URL
- `GET /auth/callback` — OAuth callback (Google redirects here)
- `POST /auth/disconnect` — Disconnect Google account
- `GET /auth/account` — Get connected account info

### Providers
- `GET /providers` — List available data providers
- `GET /providers/{id}/fields` — Get provider fields
- `GET /providers/{id}/filters` — Get provider filters
- `GET /providers/{id}/triggers` — Get available triggers

### Spreadsheets
- `GET /spreadsheets` — List user's Google Sheets
- `GET /spreadsheets/{id}/tabs` — List sheet tabs
- `GET /sheets/{spreadsheet_id}/headers/{tab}` — Get sheet column headers
- `POST /spreadsheets/create` — Create new spreadsheet
- `POST /spreadsheets/{id}/tabs` — Create new tab

### Jobs
- `GET /jobs` — List all sync jobs
- `POST /jobs` — Create a new job
- `GET /jobs/{id}` — Get job details
- `PUT /jobs/{id}` — Update a job
- `DELETE /jobs/{id}` — Delete a job
- `POST /jobs/{id}/run` — Run job immediately
- `POST /jobs/{id}/test-run` — Test run (10 rows)
- `POST /jobs/{id}/duplicate` — Duplicate a job
- `POST /jobs/{id}/pause` — Pause a job
- `POST /jobs/{id}/resume` — Resume a paused job

### Bulk Processing
- `POST /bulk/export` — Start bulk export
- `POST /bulk/import` — Start bulk import
- `GET /bulk/status/{job_id}` — Get bulk job status
- `POST /bulk/cancel/{job_id}` — Cancel bulk job

### Legacy Sync
- `POST /export` — Run an export
- `POST /import` — Run an import

### Scheduler
- `GET /scheduler/intervals` — Available schedule intervals

### Field Mapper
- `POST /field-mapper/auto-map` — Auto-detect field mapping
- `POST /field-mapper/validate` — Validate a field mapping

### CPT
- `GET /cpt/list` — List custom post types

### Logs
- `GET /logs` — Get sync logs
- `POST /logs/clear` — Clear all logs

### Debug
- `GET /debug-report` — Get system debug information

## Extending with Custom Providers

```php
add_action( 'pushrow_register_providers', function( $sync_engine ) {
    $sync_engine->register_provider( new My_Custom_Provider() );
});
```

Your provider must implement `Pushrow\Providers\Data_Provider`.

## License

GPL v2 or later
