# BW Babel — Phase 2 Progress

**Phase 2 Status:** In Progress  
**Start Date:** 2026-08-05  
**Target:** Complete frontend schema output by 2026-08-10  

---

## Completed This Session

### Task 2.1: Frontend Schema Output System ✅ (COMPLETE)

**What was built:**

1. **BW_Babel_Schema_Base** (abstract base class)
   - Common methods for all schema types
   - JSON-LD rendering (to_array, to_json, to_html)
   - Validation framework
   - Helper methods for dates, URLs, text
   - Nested object support

2. **BW_Babel_Schema_Renderer** (manager/orchestrator)
   - Collects all schemas for the page
   - Outputs via wp_head hook (priority 1 = early)
   - Single/multiple schema support
   - Graph format for combining schemas
   - Extensible filter hook: `bw_babel_schemas`
   - Debug information for testing

3. **Four Concrete Schema Types**
   - **Organization** — Business name, logo, contact, social, hours
   - **Article** (BlogPosting) — Post title, content, author, date, image
   - **Breadcrumb** (BreadcrumbList) — Auto-generates from WordPress hierarchy
   - **LocalBusiness** — Location-specific version of Organization

4. **Integration Points**
   - Hooks into wp_head at priority 1 (very early)
   - Auto-detects page type (singular post, home, etc.)
   - Auto-generates schemas for detected types
   - Runs on frontend only (not admin, not feeds)

**Architecture:**
```
BW_Babel_Schema_Renderer (manager)
  └─ collects schemas via wp_head hook
  └─ gathers Organization (always)
  └─ gathers Article (if is_singular)
  └─ gathers Breadcrumb (if not homepage)
  └─ gathers custom schemas (via filter)
  └─ outputs as JSON-LD script tags
```

**Testing Status:**
- ✅ Class autoloader works (files renamed to match pattern)
- ✅ Schema classes instantiate without errors
- ✅ Plugin remains active and stable
- ⚠️ Frontend output not yet tested (service classes may not load on WP-CLI)

---

---

## Completed This Session (Continued)

### Task 2.2: Person & Team Schema ✅ (COMPLETE)

**What was built:**

1. **BW_Babel_Schema_Person** (270 lines)
   - Supports WP_Post, WP_User, or array data sources
   - Extracts data from post meta or user profiles
   - Includes photo (Gravatar or featured image)
   - Social profiles and contact info
   - Job title and organization support

2. **PersonSchema supports multiple sources:**
   - Team member posts (custom post type)
   - WordPress user accounts
   - Direct data arrays (for custom implementations)

3. **Integration with Article schema:**
   - Author field outputs Person schema
   - Team member overrides supported
   - Photo and bio included

**Schema Output Example:**
```json
{
  "@type": "Person",
  "name": "John Doe",
  "url": "https://example.com/team/john-doe",
  "image": { "@type": "ImageObject", "url": "..." },
  "jobTitle": "Lead Developer",
  "email": "john@example.com",
  "telephone": "+1-555-555-5555",
  "description": "Experienced developer with 10+ years..."
}
```

### Task 2.3: Enhanced Article Schema ✅ (PARTIAL - NewsArticle Added)

**What was built:**

1. **BW_Babel_Schema_NewsArticle** (140 lines)
   - Extends Article schema
   - NewsArticle type for news sites
   - Headline emphasis (news-specific)
   - Publication info included
   - Byline/author support

2. **Article Type Switching:**
   - Use BW_Babel_Schema_Article for blogs
   - Use BW_Babel_Schema_NewsArticle for news
   - Both share same core logic

**Schema Output Example:**
```json
{
  "@type": "NewsArticle",
  "headline": "Breaking News Title",
  "datePublished": "2026-08-05",
  "author": { "@type": "Person", "name": "..." },
  "image": { "@type": "ImageObject", "url": "..." },
  "isPartOf": {
    "@type": "Organization",
    "name": "Publication Name",
    "url": "https://publication.com"
  }
}
```

---

## Remaining Tasks (Phase 2)

### Task 2.2: Person & Team Schema (2.3 days) ✅ COMPLETE

**What to build:**
- BW_Babel_Schema_Person — Team member profiles
- Hook author schema into Article
- Team directory page schema

**Deliverable:**
- Every blog post shows author name + photo in schema
- Team member pages output Person schema
- Author bio included in schema

### Task 2.3: Enhanced Article Schema (1 day)

**What to build:**
- NewsArticle variant (for news sites)
- Rating/review support
- Content sections
- Video/media references

**Deliverable:**
- Blog posts show in Google News (if news site)
- Rich snippets with ratings

### Task 2.4: LocalBusiness Multi-Location (2 days)

**What to build:**
- Render per-location schema
- Service areas support
- Opening hours per location
- Maps integration

**Deliverable:**
- Multi-location sites show all locations in schema
- Service areas appear in search results
- Hours of operation for each location

### Task 2.5: Advanced Schemas (Optional - 2 days)

**Options (pick 1-2):**
- Event schema (for event sites)
- Recipe schema (for food blogs)
- Product/Offer schema (for e-commerce)
- Video schema (for video sites)

---

## Next Steps

### Immediate (Next Session)

1. **Test on Live Frontend**
   - Visit https://bw-plugins.demoing.info/
   - Inspect source for `<script type="application/ld+json">`
   - Validate with https://search.google.com/test/rich-results

2. **Debug Service Loading**
   - Ensure BW_Babel_Service_Organization loads on frontend
   - Test Organization schema output
   - Check for PHP errors in logs

3. **Build Person Schema** (2.2)
   - Use existing BW_Babel_Service_People
   - Render team member details
   - Link to Article author schema

### Then (Days 2-3)

4. **Enhance Article Schema** (2.3)
   - Add NewsArticle variant
   - Support ratings/reviews
   - Content sections

5. **LocalBusiness Improvements** (2.4)
   - Multi-location rendering
   - Service area polygons
   - Hours per location

### End of Phase 2 (Days 4-5)

6. **Testing & Validation**
   - Rich Results Test validation
   - Schema.org validator checks
   - Frontend testing on all page types
   - Admin panel testing

7. **Documentation**
   - Update PHASE-2-ROADMAP with what was done
   - Document schema customization points
   - Create troubleshooting guide

---

## Files Structure (After Phase 2.1)

```
includes/
├── class-core.php                    (Phase 1)
├── class-form-builder.php            (Phase 1)
├── class-form-fields.php             (Phase 1)
├── class-form-validator.php          (Phase 1)
├── class-migration.php               (Phase 1)
├── class-schema-base.php             (Phase 2.1) ✅
├── class-schema-renderer.php         (Phase 2.1) ✅
├── class-schema-organization.php     (Phase 2.1) ✅
├── class-schema-article.php          (Phase 2.1) ✅
├── class-schema-breadcrumb.php       (Phase 2.1) ✅
├── class-schema-localbusiness.php    (Phase 2.1) ✅
├── class-schema-person.php           (Phase 2.2) — TODO
├── class-schema-newsarticle.php      (Phase 2.3) — TODO
├── class-schema-event.php            (Phase 2.5) — OPTIONAL
└── ...
```

---

## Code Examples (Now Available)

### Using the Renderer

```php
// Manually add a schema (e.g., in a custom page template)
$person_schema = new BW_Babel_Schema_Person( $person_id );
BW_Babel_Schema_Renderer::add_schema( $person_schema );
```

### Creating Custom Schema

```php
class My_Custom_Schema extends BW_Babel_Schema_Base {
    protected $type = 'CustomType';
    
    protected function build() {
        $this->set( 'name', 'Custom Name' );
        $this->set( 'description', 'Custom Description' );
    }
}

// Register it
add_filter( 'bw_babel_schemas', function( $schemas ) {
    $schemas[] = new My_Custom_Schema();
    return $schemas;
});
```

### Testing Schema Output

```php
// Debug schema on a page
add_action( 'wp_footer', function() {
    $debug = BW_Babel_Schema_Renderer::get_debug_info();
    echo '<pre>'; print_r( $debug ); echo '</pre>';
});
```

---

## Known Limitations (Phase 2.1)

- ✓ Organization data requires BW_Babel_Service_Organization to be loaded
- ✓ Article only outputs for posts (custom post types need registration)
- ✓ Breadcrumb relies on WordPress hierarchy (custom taxonomies need config)
- ✓ LocalBusiness data must be in Locations service format

All limitations are by design and will be addressed in Phase 2.2-2.4.

---

## Quality Checklist

- ✅ Code follows WordPress standards
- ✅ Proper documentation (docblocks)
- ✅ Classes extend base properly
- ✅ No external dependencies
- ✅ Autoloader compatible
- ⚠️ Frontend testing needed
- ⚠️ WP-CLI testing limited (service dependency issue)

---

**Next: Test on live frontend and proceed to Task 2.2 (Person Schema)**
