# Smart Schema Automation

![Version](https://img.shields.io/badge/version-1.2.3-blue) ![WordPress](https://img.shields.io/badge/WordPress-5.0%2B-blue) ![PHP](https://img.shields.io/badge/PHP-7.2%2B-blue) ![License](https://img.shields.io/badge/license-GPLv2-green)

A WordPress plugin for automated Schema.org structured data generation with modern OOP architecture.

## Features

- **LocalBusiness Schema** - Perfect for businesses with physical locations
- **Organization Schema** - Build brand identity and social presence
- **FAQ Schema** - Auto-detect FAQ sections from your content
- **Product Schema** - Automatic WooCommerce integration
- **Service Schema** - Showcase your services with structured data
- **Article Schema** - Automatic for blog posts
- **Video Schema** - Add video structured data to specific pages
- **Job Posting Schema** - Promote job openings in Google for Jobs
- **Breadcrumb Schema** - Automatic navigation breadcrumbs for all pages
- **Conflict Detection** - Detects and warns about duplicate schemas from other plugins

## Automatic Features

- **WooCommerce Integration** - Automatically generates product schema for all WooCommerce products
- **FAQ Auto-Detection** - Intelligently detects FAQ sections using multiple HTML patterns
- **Article Schema** - Automatically added to all blog posts
- **Breadcrumb Schema** - Automatically generates navigation breadcrumbs showing site hierarchy
- **Status Messages** - Shows which schemas are active on your site
- **Conflict Detection** - Warns about duplicate schemas from other sources

## Installation

1. Upload the `pichautari-schema-automation` folder to `/wp-content/plugins/`
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Go to 'Schema Hub' in the admin menu to configure your schemas
4. Enable the schema types you want to use
5. Fill in your information and save

## Configuration

### Admin Interface

Navigate to **Schema Hub** in your WordPress admin to access the modern tabbed interface:

- **LocalBusiness** - Configure business information (name, address, phone, ratings)
- **Organization** - Set up organization details (name, logo, social media)
- **FAQ** - Configure auto-detection settings
- **Product** - Automatic WooCommerce integration (no configuration needed)
- **Service** - Add services with bulk import feature
- **Article** - Automatic for blog posts (just enable)
- **Video** - Add videos and assign to specific pages
- **Job Posting** - Add job listings with detailed information
- **Breadcrumb** - Automatic navigation breadcrumbs (just enable)
- **Help** - Comprehensive documentation and tips

## Usage

### Automatic Schemas

Most schemas work automatically when enabled:

- **Article Schema** - Automatically added to all blog posts
- **Breadcrumb Schema** - Automatically generated for all pages based on site structure
- **Product Schema** - Automatically generated for WooCommerce products
- **FAQ Schema** - Automatically detected from page content using wrapper classes

### Manual Configuration

Some schemas require manual setup:

- **LocalBusiness** - Enter your business details in the admin
- **Organization** - Configure organization information and social profiles
- **Service** - Add services individually or use bulk import
- **Video** - Add videos and select which pages they appear on
- **Job Posting** - Add job listings with salary and location details

## Developer Functions

For theme developers, the plugin provides helper functions:

#### FAQ Schema
```php
<?php
$faqs = array(
    array(
        'question' => 'What are your business hours?',
        'answer' => 'We are open Monday-Friday 9am-5pm'
    ),
    array(
        'question' => 'Do you offer free shipping?',
        'answer' => 'Yes, free shipping on orders over $50'
    )
);
schema_output_faq($faqs);
?>
```

#### Product Schema
```php
<?php
$product = array(
    'name' => 'Premium Widget',
    'description' => 'High-quality widget for all your needs',
    'sku' => 'WIDGET-001',
    'brand' => 'Pichautari',
    'image' => array('https://example.com/widget.jpg'),
    'offers' => array(
        'price' => '29.99',
        'currency' => 'USD',
        'availability' => 'https://schema.org/InStock',
        'url' => 'https://example.com/product/widget'
    ),
    'rating' => array(
        'value' => 4.5,
        'count' => 89
    )
);
schema_output_product($product);
?>
```

#### Service Schema
```php
<?php
$service = array(
    'service_type' => 'Web Development',
    'description' => 'Professional WordPress development services',
    'provider' => array(
        'name' => 'Pichautari',
        'url' => 'https://pichautari.com'
    ),
    'area_served' => 'Worldwide',
    'offers' => array(
        'price' => '1000',
        'currency' => 'USD'
    )
);
schema_output_service($service);
?>
```

#### LocalBusiness Schema
```php
<?php
$business = array(
    'name' => 'Pichautari Coffee',
    'url' => 'https://pichautari.com',
    'telephone' => '+1-555-123-4567',
    'price_range' => '$$',
    'address' => array(
        'street' => '123 Main Street',
        'city' => 'Springfield',
        'region' => 'IL',
        'postal_code' => '62701',
        'country' => 'US'
    )
);
schema_output_local_business($business);
?>
```

## Architecture

The plugin uses a modern OOP architecture with:

- **Autoloader** - PSR-4 style class loading
- **Schema Base Class** - Abstract base for all schema types
- **Modular Schema Classes** - Each schema type in its own class
- **Admin Settings Class** - Handles all admin functionality
- **Schema Detector Class** - Detects existing schemas and conflicts
- **Separation of Concerns** - Clean, maintainable code structure

## Key Benefits

- Improve search engine visibility
- Get rich snippets in search results
- Increase click-through rates
- Better local SEO for businesses
- Enhanced product visibility
- Professional job listings
- Clear site navigation with breadcrumbs
- Automatic conflict detection prevents duplicate schemas

## Shortcodes

Coming soon!

## Requirements

- WordPress 5.0 or higher
- PHP 7.2 or higher

## Troubleshooting

### Schema Not Appearing or Wrong Schema Showing

If you're experiencing issues with schemas not appearing correctly:

1. **Clear Cache** - Click the "🔄 Clear Schema Cache" button at the top of Schema Hub
2. **Debug Output** - Click the "🔍 Debug Schema Output" button to see which schemas are active
3. **Check Conflicts** - Look for yellow warning messages on each schema tab
4. **Clear Browser Cache** - Press Ctrl+Shift+Delete and clear cached files
5. **Clear Plugin Cache** - If using WP Super Cache, W3 Total Cache, etc., clear their cache
6. **Test with Validator** - Use [Google's Rich Results Test](https://search.google.com/test/rich-results)

For detailed troubleshooting steps, see [TROUBLESHOOTING.md](TROUBLESHOOTING.md)

### Common Issues

- **Both LocalBusiness and Organization showing** - Only enable one, clear all caches
- **Schema not updating** - Clear browser cache and WordPress cache
- **Duplicate schemas detected** - Check for conflicts with other SEO plugins
- **Breadcrumbs not on homepage** - Enable "Add breadcrumb schema on homepage" in settings

## Support

For support, please visit [https://pichautari.com](https://pichautari.com)

## License

GPL v2 or later

## Changelog

### 1.2.3
- LocalBusiness schema: added latitude & longitude (GeoCoordinates)
- LocalBusiness schema: added opening hours with per-day Open / 24 Hours / Closed selector
- Opening hours UI redesigned — card-based layout with pill status selector and FROM → TO time pickers
- Fixed unescaped output in opening hours time fields

### 1.2.2
- Improved FAQ accordion detection — Pattern 0 now extracts question text from `<strong>` tag inside accordionBtn when present

### 1.2.1
- Searchable "Show on Pages" selector with Select All, Clear, and live count
- Show on Pages now lists all public post types
- Fixed unescaped `$uid` output in `render_page_selector()`
- Article schema disabled by default

### 1.2.0
- FAQ detection now works on all singular post types including custom post types
- FAQ detection uses output buffering to parse fully rendered page HTML
- Added accordion-item / accordionBtn / accordionBody pattern to FAQ extractor
- Added Settings link on plugin list page

### 1.1.0
- Added Custom Schema tab with raw JSON-LD support
- Per-page transient caching (12-hour TTL) with auto-clear on save

### 1.0.9
- Enhanced WooCommerce integration with automatic Product schema
- Breadcrumb schema automatically hidden on WooCommerce pages

### 1.0.8
- Major OOP refactoring with modular class architecture
- Added Breadcrumb schema with automatic generation
- Added conflict detection for duplicate schemas
