|
2 | 2 |
|
3 | 3 | ## Description |
4 | 4 |
|
5 | | -Expert in validating and fixing WordPress block pattern files to ensure HTML output matches block comment attributes according to WordPress core rendering rules. Detects and corrects mismatches between block attributes (JSON in comments) and their corresponding HTML output. |
| 5 | +Expert in validating and fixing WordPress block pattern files to ensure HTML output matches block comment attributes according to WordPress core rendering rules. Detects and corrects mismatches between block attributes (JSON in comments) and their corresponding HTML output, including redundant fontFamily attributes and malformed font size classes that cause block validation errors. |
6 | 6 |
|
7 | 7 | ## Capabilities |
8 | 8 |
|
9 | 9 | - Parse WordPress block comments and extract JSON attributes |
10 | 10 | - Validate HTML output against WordPress core rendering rules |
11 | 11 | - Detect missing or incorrect CSS classes |
12 | 12 | - Detect missing or incorrect inline styles |
| 13 | +- **Detect redundant `fontFamily` attributes that WordPress strips on save** |
| 14 | +- **Detect malformed font size classes (e.g., `has-h-3-font-size` vs `has-h3-font-size`)** |
| 15 | +- **Detect and flag non-WordPress block comments (descriptive HTML comments)** |
13 | 16 | - Auto-fix common rendering errors in pattern files |
14 | 17 | - Scan multiple pattern files for validation errors |
15 | 18 | - Generate validation reports with line-by-line error details |
16 | 19 |
|
| 20 | +## Critical Block Validation Error Checks |
| 21 | + |
| 22 | +### Redundant Font Family Attributes |
| 23 | + |
| 24 | +WordPress optimizes saved content by stripping CSS properties that match theme defaults. This causes block validation errors when: |
| 25 | + |
| 26 | +**Problem:** |
| 27 | +- Block attributes include: `"style":{"typography":{"fontFamily":"var:preset|font-family|roboto-serif"}}` |
| 28 | +- WordPress renders it in the editor with: `style="font-family:var(--wp--preset--font-family--roboto-serif)"` |
| 29 | +- But the saved database content omits it (because it matches the theme default) |
| 30 | +- Result: **Block validation error** ❌ |
| 31 | + |
| 32 | +**Solution:** |
| 33 | +- Remove `fontFamily` from block attributes if it matches your `theme.json` default |
| 34 | +- The validator detects this pattern and warns you |
| 35 | + |
| 36 | +**Example:** |
| 37 | +```html |
| 38 | +<!-- BEFORE (causes validation error) --> |
| 39 | +<!-- wp:heading {"style":{"typography":{"fontFamily":"var:preset|font-family|roboto-serif"}}} --> |
| 40 | +<h3 class="wp-block-heading">Text</h3> |
| 41 | + |
| 42 | +<!-- AFTER (no validation error) --> |
| 43 | +<!-- wp:heading {} --> |
| 44 | +<h3 class="wp-block-heading">Text</h3> |
| 45 | +``` |
| 46 | + |
| 47 | +### Malformed Font Size Classes |
| 48 | + |
| 49 | +Typos in font size class names cause block validation mismatches. |
| 50 | + |
| 51 | +**Problem:** |
| 52 | +- Block attributes: `"fontSize":"h3"` |
| 53 | +- Expected HTML: `class="wp-block-heading has-h3-font-size"` |
| 54 | +- Actual HTML: `class="wp-block-heading has-h-3-font-size"` (extra dash) |
| 55 | +- Result: **Block validation error** ❌ |
| 56 | + |
| 57 | +**Solution:** |
| 58 | +- Ensure font size class matches the pattern: `has-{fontSize}-font-size` |
| 59 | +- No extra dashes or characters in the slug |
| 60 | + |
| 61 | +**Example:** |
| 62 | +```html |
| 63 | +<!-- WRONG (causes validation error) --> |
| 64 | +<!-- wp:heading {"fontSize":"h3"} --> |
| 65 | +<h3 class="wp-block-heading has-h-3-font-size">Text</h3> |
| 66 | + |
| 67 | +<!-- CORRECT (no validation error) --> |
| 68 | +<!-- wp:heading {"fontSize":"h3"} --> |
| 69 | +<h3 class="wp-block-heading has-h3-font-size">Text</h3> |
| 70 | +``` |
| 71 | + |
| 72 | +### Invalid HTML Comments (Non-WordPress Block Comments) |
| 73 | + |
| 74 | +WordPress block templates and patterns should **only** contain WordPress block comments. Descriptive HTML comments are not allowed and may interfere with block parsing. |
| 75 | + |
| 76 | +**Problem:** |
| 77 | +- Template contains descriptive comments like: `<!-- Social Media Icons -->`, `<!-- Top Navigation Links -->`, `<!-- Newsletter Section -->` |
| 78 | +- These are standard HTML comments, not WordPress block comments |
| 79 | +- WordPress block template parser expects only block-related comments |
| 80 | +- Result: **Potential parsing issues** ❌ and template pollution |
| 81 | + |
| 82 | +**Valid WordPress Block Comments:** |
| 83 | +- Opening block: `<!-- wp:blockname {...} -->` |
| 84 | +- Closing block: `<!-- /wp:blockname -->` |
| 85 | +- Third-party blocks: `<!-- wp:namespace/blockname {...} -->` (e.g., `<!-- wp:woocommerce/mini-cart -->`) |
| 86 | + |
| 87 | +**Invalid Comments (will be flagged):** |
| 88 | +- `<!-- Social Media Icons -->` ❌ |
| 89 | +- `<!-- Top Navigation Links -->` ❌ |
| 90 | +- `<!-- Newsletter CTA Section -->` ❌ |
| 91 | +- `<!-- Column 1: About Us -->` ❌ |
| 92 | + |
| 93 | +**Solution:** |
| 94 | +- Remove ALL descriptive HTML comments from block templates |
| 95 | +- WordPress block structure should be self-documenting through proper nesting and block types |
| 96 | +- Use meaningful class names instead of comments to identify sections |
| 97 | + |
| 98 | +**Example:** |
| 99 | +```html |
| 100 | +<!-- WRONG (validator will flag these) --> |
| 101 | +<!-- Social Media Icons --> |
| 102 | +<!-- wp:social-links {...} --> |
| 103 | +<ul class="wp-block-social-links">...</ul> |
| 104 | +<!-- /wp:social-links --> |
| 105 | + |
| 106 | +<!-- CORRECT (no descriptive comments) --> |
| 107 | +<!-- wp:social-links {...} --> |
| 108 | +<ul class="wp-block-social-links is-style-logos-only header-social">...</ul> |
| 109 | +<!-- /wp:social-links --> |
| 110 | +``` |
| 111 | + |
| 112 | +Note: The validator checks for any HTML comment that doesn't start with `wp:` or `/wp:` and flags it as an error. |
| 113 | + |
17 | 114 | ## Common WordPress Block Rendering Rules |
18 | 115 |
|
19 | 116 | ### Color Attributes |
|
0 commit comments