[wp-trac] [WordPress Trac] #54797: Allow languages path in register_block_type

WordPress Trac noreply at wordpress.org
Wed Jun 18 14:18:41 UTC 2025


#54797: Allow languages path in register_block_type
------------------------------------------+-----------------------------
 Reporter:  Rahe                          |       Owner:  gziolo
     Type:  enhancement                   |      Status:  assigned
 Priority:  normal                        |   Milestone:  Future Release
Component:  I18N                          |     Version:  5.5
 Severity:  normal                        |  Resolution:
 Keywords:  needs-unit-tests needs-patch  |     Focuses:
------------------------------------------+-----------------------------

Comment (by iamadisingh):

 Building on #62244 , we can auto-detect domain paths for block scripts by
 reading plugin headers, eliminating the need for manual `domainpath`
 configuration.

 {{{#!php
 <?php
 // 1. Traverse up from block.json to find main plugin file
 $current_dir = dirname( $block_file );
 while ( $current_dir !== WP_CONTENT_DIR ) {
     // Look for files with "Plugin Name:" header
     // Use get_plugin_data() (now available thanks to #62244)
 }

 // 2. Extract domain path from plugin headers
 $plugin_data = get_plugin_data( $plugin_file );
 if ( $plugin_data['TextDomain'] === $textdomain ) {
     $domain_path = dirname( $plugin_file ) . $plugin_data['DomainPath'];
 }

 // 3. Update block script registration with fallback logic
 $domain_path = ! empty( $metadata['domainpath'] )
     ? $metadata['domainpath']                    // Explicit takes
 priority
     : auto_detect_from_plugin_headers();         // Auto-detect as
 fallback
 }}}

 Should we implement the directory traversal logic or is there a preferred
 WordPress pattern for locating a plugin's main file from a nested block
 file?
 This approach eliminates manual configuration while respecting existing
 workflows. Thoughts on the traversal strategy?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54797#comment:33>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list