Skip to content

Commit

Permalink
Set textdomain for blocks which don't have one #177
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Aug 30, 2021
1 parent bd5a25e commit 0e83e6c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions oik.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function oik_main_init() {
add_filter( "_sc__help", "oik_oik_sc__help", 10, 2 );
$bobbfunc = oik_require_lib_wrapper( "bobbfunc" );
if ( $bobbfunc && !is_wp_error( $bobbfunc ) ) {
bw_load_plugin_textdomain();
bw_load_plugin_textdomain();
/**
* Tell plugins that oik has been loaded.
*
Expand Down Expand Up @@ -571,6 +571,7 @@ function oik_is_shortcode_expansion_necessary() {
*/
function oik_register_dynamic_blocks() {
$library_file = oik_require_lib( 'oik-blocks');
add_filter( 'block_type_metadata', 'oik_block_type_metadata', 10 );

$args = [ 'render_callback' => 'oik_dynamic_block_address' ];
$registered = register_block_type_from_metadata( __DIR__ .'/src/oik-address', $args );
Expand Down Expand Up @@ -608,13 +609,31 @@ function oik_register_dynamic_blocks() {
* @return mixed
*/
function oik_load_script_textdomain_relative_path( $relative, $src ) {
//bw_trace2();
if ( false !== strrpos( $relative, './build/index.js' )) {
$relative = 'build/index.js';
}
//bw_trace2( $relative, "relative");
return $relative;
}

/**
* Implements block_type_metadata filter to set the textdomain if not set.
*
* Note: $metadata['name'] will be set for each block.
*
* @param $metadata
* @return mixed
*/
function oik_block_type_metadata( $metadata ) {
if ( !isset( $metadata['textdomain']) ) {
$name = $metadata['name'];
$name_parts = explode( '/', $name );
$textdomain = $name_parts[0];
$metadata['textdomain'] = $textdomain;
}
return $metadata;
}

/**
* Server rendering dynamic address block.
*
Expand Down

0 comments on commit 0e83e6c

Please sign in to comment.