# DraftSEO.AI - WordPress Plugin

Publish AI-generated blogs from DraftSEO.AI platform directly to WordPress with automatic image import and SEO optimization.

## Installation

### From WordPress.org (Recommended)

1. Go to WordPress Admin → Plugins → Add New
2. Search for "DraftSEO.AI"
3. Click "Install Now" and then "Activate"

### Manual Installation

1. Download the plugin ZIP file
2. Go to WordPress Admin → Plugins → Add New → Upload Plugin
3. Choose the ZIP file and click "Install Now"
4. Activate the plugin

### From this Repository

1. Clone or download this repository
2. Copy the `draftseo-ai` directory to `wp-content/plugins/`
3. Go to WordPress Admin → Plugins
4. Find "DraftSEO.AI" and click "Activate"

## Configuration

1. Navigate to WordPress Admin → DraftSEO → Settings
2. Click "Connect with DraftSEO.AI" button
   - You'll be automatically redirected to DraftSEO.AI
   - Sign in if you're not already logged in
   - Connection completes automatically (OAuth-based, no API key needed)
3. Configure your content cleanup settings:
   - Remove inline styles
   - Remove CSS classes and IDs
   - Remove empty paragraphs
   - Remove HTML comments
   - Tag creation options
   - Content cleanup preferences
4. Click "Test Connection" to verify setup
5. Save settings

## Features

### Core Features
- ✅ One-click publishing from DraftSEO.AI to WordPress
- ✅ Automatic image import from Nebius CDN to WordPress Media Library
- ✅ SEO metadata preservation (keywords, meta descriptions)
- ✅ WordPress category sync
- ✅ Automatic tag creation from blog keywords
- ✅ Multiple post status options (draft, publish, schedule)
- ✅ Secure API key encryption

### Image Handling
The plugin intelligently handles images based on blog size:

- **1-5 images**: Direct import (10-20 seconds)
- **6+ images**: Hybrid approach
  - Featured image imported immediately
  - Remaining images processed in background via WordPress Cron

All images are downloaded directly from Nebius CDN to your WordPress Media Library.

### SEO Plugin Integration
Automatically integrates with popular SEO plugins:
- Yoast SEO
- Rank Math
- All in One SEO

### Content Processing
- HTML cleanup and sanitization
- Inline style removal (optional)
- Empty paragraph cleanup
- HTML comment removal
- CSS class/ID stripping (optional)

## Usage

### Publishing a Blog

1. **Generate Blog on DraftSEO.AI**
   - Create your blog using DraftSEO.AI platform
   - Configure SEO settings, categories, and tags

2. **Publish to WordPress**
   - Click "Publish to WordPress" button
   - Select your connected WordPress site
   - Choose publishing options (author, category, status, date)
   - Click "Publish"

3. **Review on WordPress**
   - Log in to your WordPress admin
   - Find your published post in Posts → All Posts
   - Review and make any final edits if needed

### API Endpoints

The plugin provides REST API endpoints for DraftSEO.AI integration:

- `GET /wp-json/draftseo/v1/users` - Get WordPress users
- `GET /wp-json/draftseo/v1/categories` - Get WordPress categories
- `POST /wp-json/draftseo/v1/publish` - Publish blog to WordPress
- `GET /wp-json/draftseo/v1/test-connection` - Test API connection

All endpoints require Bearer token authentication using your API key.

## Requirements

- **WordPress**: 5.8 or higher
- **PHP**: 7.4 or higher
- **MySQL**: 5.6 or higher
- **WordPress Cron**: Enabled (for background image processing)
- **DraftSEO.AI Account**: Active subscription

## File Structure

```
draftseo-ai/
├── admin/                          # Admin interface files
│   ├── css/
│   │   └── admin-styles.css       # Admin page styles
│   ├── js/
│   │   └── admin-scripts.js       # Admin page JavaScript
│   └── settings-page.php          # Settings page template
├── includes/                       # Core plugin classes
│   ├── class-api-client.php       # DraftSEO.AI API communication
│   ├── class-content-processor.php # HTML cleanup and formatting
│   ├── class-image-handler.php    # Image import strategies
│   ├── class-rest-api.php         # WordPress REST API endpoints
│   ├── class-seo-handler.php      # SEO metadata management
│   └── class-settings.php         # Settings and API key management
├── languages/                      # Translation files
├── draftseo-ai.php         # Main plugin file
├── LICENSE.txt                     # GPL v2 license
├── readme.txt                      # WordPress.org readme
├── uninstall.php                  # Uninstall handler
└── README.md                       # This file
```

## Development

### Coding Standards
- Follows WordPress Coding Standards (WPCS)
- PHPCS compliant
- Nonces for security
- Capability checks for permissions
- Input validation and sanitization

### Hooks and Filters

#### Actions
- `draftseo_process_images_background` - Background image processing
- `draftseo_before_publish` - Before publishing a blog
- `draftseo_after_publish` - After publishing a blog

#### Filters
- `draftseo_content_cleanup` - Modify content cleanup settings
- `draftseo_seo_metadata` - Modify SEO metadata before saving
- `draftseo_image_import_strategy` - Override automatic strategy selection

## Troubleshooting

### Connection Test Fails
- Verify API key is correct
- Check WordPress site URL is accessible from internet
- Ensure REST API is enabled on WordPress
- Check firewall/security plugins aren't blocking API requests

### Images Not Importing
- Check WordPress has write permissions to uploads directory
- Verify WordPress Cron is running (test with WP Crontrol plugin)
- Check PHP `max_execution_time` setting (should be 60+ seconds)
- Review WordPress error logs for image download errors

### Tags Not Created
- Ensure "Auto-create tags" is enabled in settings
- Check keywords are provided in the blog data
- Verify user has permission to create tags
- Check maximum tags limit in settings

## Support

- **Documentation**: [DraftSEO.AI Documentation](https://draftseo.ai/docs)
- **Support**: [Contact Support](https://draftseo.ai/support)
- **WordPress.org**: [Plugin Support Forum](https://wordpress.org/support/plugin/draftseo-ai)

## License

This plugin is licensed under the GNU General Public License v2 or later.

## Credits

Developed by [DraftSEO.AI](https://draftseo.ai)

## Changelog

### 1.0.0 (Initial Release)
- One-click blog publishing from DraftSEO.AI
- Automatic image import from Nebius CDN
- SEO metadata transfer
- WordPress category sync
- Auto-create tags from keywords
- Multiple post status options
- Content cleanup and formatting
- SEO plugin integration (Yoast, Rank Math, AIOSEO)
- Secure API key encryption
- Background image processing for large blogs
