Skip to content

Commit 9c18fef

Browse files
ashleyshawclaude
andcommitted
fix(phase6): Update WordPress 6.5+ standards and standardize text domains
## Critical Issues Fixed ### Issue #4: WordPress 6.5+ Block Rendering Standards - **block-json.instructions.md**: Enhanced dynamic block rendering documentation - Added "WordPress 6.5+ File-based Rendering (RECOMMENDED)" section - Positioned `"render": "file:./render.php"` as PRIMARY method - Documented automatic variables ($attributes, $content, $block) - Added proper mustache placeholder example with {{namespace}} and {{slug}} - Created "Legacy PHP Callback" section for pre-6.5 compatibility - Added Version Compatibility Matrix (6.5+, 6.0-6.4, <6.0) - Clarified scaffold standard: Always use file-based rendering ### Issue #5: Text Domain Standardization - **wpcs-php.instructions.md**: Standardized all text domain examples - Changed 'textdomain' to '{{textdomain}}' in all i18n examples (8 instances) - Changed 'lsx-theme' to '{{textdomain}}' in translation guidance (line 390) - Added explanatory note about placeholder vs production usage - Ensures AI agents copy correct mustache placeholders ## Changes Made ### block-json.instructions.md - Lines 305-367: Complete rewrite of "Render Callback" section - Added 3 subsections: Recommended, Legacy, Version Compatibility - Enhanced render.php example with proper @var annotations - Included WP_Block context usage example - Clear deprecation warning for render_callback approach ### wpcs-php.instructions.md - Lines 121-122: Updated wp_die() text domains - Lines 297-300: Updated core i18n function examples - Lines 307-308: Updated wp_localize_script() string examples - Line 390: Updated translation guidance with placeholder explanation - Line 295: Added note explaining {{textdomain}} placeholder convention ## Impact ### Before: - Unclear if file-based rendering or PHP callbacks were preferred - Text domain examples used inconsistent values ('textdomain', 'lsx-theme', 'plugin') - AI agents might copy wrong text domain into scaffold templates ### After: - Clear WordPress 6.5+ standard with file-based rendering as PRIMARY method - All examples consistently use '{{textdomain}}' placeholder - Explicit note explaining placeholder vs production usage - Version compatibility matrix guides decision-making ## Validation ✅ File-based rendering positioned as WordPress 6.5+ standard ✅ All text domain examples now use {{textdomain}} placeholder ✅ Backward compatibility documented for legacy WordPress versions ✅ Clear guidance prevents text domain mistakes in scaffold 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 12ac0f7 commit 9c18fef

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

.github/instructions/block-json.instructions.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,34 +304,68 @@ The `block.json` file is the canonical way to register blocks in WordPress. This
304304

305305
## Render Callback (Dynamic Blocks)
306306

307-
### PHP Rendering
307+
### WordPress 6.5+ File-based Rendering (RECOMMENDED)
308+
309+
**This is the PRIMARY method** for dynamic blocks in WordPress 6.5+. Use `render` property in block.json:
308310

309311
```json
310312
{
311313
"render": "file:./render.php"
312314
}
313315
```
314316

317+
**render.php** receives these variables automatically:
318+
- `$attributes` - Block attributes array
319+
- `$content` - Block inner content (for dynamic InnerBlocks)
320+
- `$block` - WP_Block instance with context and metadata
321+
315322
```php
316323
<?php
317324
/**
318-
* Render callback for dynamic block
325+
* Dynamic block rendering template
319326
*
320-
* @param array $attributes Block attributes
321-
* @param string $content Block content
322-
* @param WP_Block $block Block instance
327+
* @package {{namespace}}
328+
* @var array $attributes Block attributes
329+
* @var string $content Block inner content
330+
* @var WP_Block $block Block instance
323331
*/
324-
function render_callback( $attributes, $content, $block ) {
325-
$alignment = $attributes['alignment'] ?? 'left';
326332

333+
$alignment = $attributes['alignment'] ?? 'left';
334+
$post_id = $block->context['postId'] ?? get_the_ID();
335+
336+
?>
337+
<div class="wp-block-{{namespace}}-{{slug}}-card align<?php echo esc_attr( $alignment ); ?>">
338+
<?php echo wp_kses_post( $content ); ?>
339+
</div>
340+
```
341+
342+
### Legacy PHP Callback (WordPress < 6.5 - DEPRECATED)
343+
344+
**Only use if you need to support WordPress versions before 6.5.** Register callback in PHP:
345+
346+
```php
347+
register_block_type( 'namespace/block-name', array(
348+
'render_callback' => 'namespace_render_block_callback',
349+
) );
350+
351+
function namespace_render_block_callback( $attributes, $content, $block ) {
327352
return sprintf(
328-
'<div class="wp-block-namespace-block align%s">%s</div>',
329-
esc_attr( $alignment ),
353+
'<div class="wp-block-namespace-block">%s</div>',
330354
wp_kses_post( $content )
331355
);
332356
}
333357
```
334358

359+
### Version Compatibility Matrix
360+
361+
| WordPress Version | Render Method | Support Status |
362+
|-------------------|---------------|----------------|
363+
| **6.5+** | `"render": "file:./render.php"` | ✅ Recommended |
364+
| **6.0 - 6.4** | `render_callback` in PHP | ⚠️ Legacy support |
365+
| **< 6.0** | `render_callback` in PHP | ❌ Not scaffold target |
366+
367+
**Scaffold Standard:** Always use `"render": "file:./render.php"` in block.json. This is cleaner, more maintainable, and aligns with WordPress core direction.
368+
335369
### Dynamic Block Best Practices
336370

337371
- Validate and sanitize attributes

.github/instructions/wpcs-php.instructions.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ if ( WP_DEBUG ) {
118118

119119
// User-friendly error messages
120120
wp_die(
121-
__( 'Something went wrong. Please try again later.', 'textdomain' ),
122-
__( 'Error', 'textdomain' ),
121+
__( 'Something went wrong. Please try again later.', '{{textdomain}}' ),
122+
__( 'Error', '{{textdomain}}' ),
123123
array( 'response' => 500 )
124124
);
125125
```
@@ -292,20 +292,22 @@ function my_plugin_render_custom_block( $attributes, $content, $block ) {
292292

293293
### Internationalization (i18n) Examples
294294

295+
> **Note:** In examples, `'{{textdomain}}'` represents your plugin's actual text domain placeholder. When writing code for the scaffold, always use `'{{textdomain}}'` so the generator can replace it. In production plugin code, use your actual text domain (e.g., `'my-plugin'`).
296+
295297
```php
296298
// Use proper text domain consistently
297-
__( 'Text to translate', 'textdomain' );
298-
_e( 'Text to echo', 'textdomain' );
299-
_x( 'Text', 'Context for translators', 'textdomain' );
300-
_n( 'Singular', 'Plural', $count, 'textdomain' );
299+
__( 'Text to translate', '{{textdomain}}' );
300+
_e( 'Text to echo', '{{textdomain}}' );
301+
_x( 'Text', 'Context for translators', '{{textdomain}}' );
302+
_n( 'Singular', 'Plural', $count, '{{textdomain}}' );
301303

302304
// For JavaScript strings
303305
wp_localize_script( 'my-script', 'myL10n', array(
304306
'ajaxurl' => admin_url( 'admin-ajax.php' ),
305307
'nonce' => wp_create_nonce( 'my_ajax_nonce' ),
306308
'strings' => array(
307-
'loading' => __( 'Loading...', 'textdomain' ),
308-
'error' => __( 'An error occurred', 'textdomain' ),
309+
'loading' => __( 'Loading...', '{{textdomain}}' ),
310+
'error' => __( 'An error occurred', '{{textdomain}}' ),
309311
)
310312
) );
311313
```
@@ -387,7 +389,7 @@ function my_plugin_rest_permission_check() {
387389

388390
## Translation & Internationalization
389391

390-
- Use correct text domain for all translations: `__('text', 'lsx-theme')`.
392+
- Use correct text domain for all translations: `__( 'text', '{{textdomain}}' )` (use your plugin's actual text domain, represented here as `{{textdomain}}` placeholder).
391393
- Ensure all user-visible strings are translatable.
392394
- Use proper escaping functions with translations: `esc_html__()`, `esc_attr__()`.
393395
- For HTML with translations, use `esc_html_e()` or appropriate alternatives.

0 commit comments

Comments
 (0)