Skip to content

Commit

Permalink
Use module_id(s) instead of _handle(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jan 11, 2024
1 parent 91eb8e9 commit 440b5eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
30 changes: 15 additions & 15 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,27 @@ function get_block_asset_url( $path ) {
* @return string|false Script handle provided directly or created through
* script's registration, or false on failure.
*/
function register_block_module_handle( $metadata, $field_name, $index = 0 ) {
function register_block_module_id( $metadata, $field_name, $index = 0 ) {
if ( empty( $metadata[ $field_name ] ) ) {
return false;
}

$module_handle = $metadata[ $field_name ];
if ( is_array( $module_handle ) ) {
if ( empty( $module_handle[ $index ] ) ) {
$module_id = $metadata[ $field_name ];
if ( is_array( $module_id ) ) {
if ( empty( $module_id[ $index ] ) ) {
return false;
}
$module_handle = $module_handle[ $index ];
$module_id = $module_id[ $index ];
}

$module_path = remove_block_asset_path_prefix( $module_handle );
if ( $module_handle === $module_path ) {
return $module_handle;
$module_path = remove_block_asset_path_prefix( $module_id );
if ( $module_id === $module_path ) {
return $module_id;
}

$path = dirname( $metadata['file'] );
$module_asset_raw_path = $path . '/' . substr_replace( $module_path, '.asset.php', - strlen( '.js' ) );
$module_handle = generate_block_asset_handle( $metadata['name'], $field_name, $index );
$module_id = generate_block_asset_handle( $metadata['name'], $field_name, $index );
$module_asset_path = wp_normalize_path(
realpath( $module_asset_raw_path )
);
Expand All @@ -184,18 +184,18 @@ function register_block_module_handle( $metadata, $field_name, $index = 0 ) {
$module_asset = require $module_asset_path;
$module_dependencies = isset( $module_asset['dependencies'] ) ? $module_asset['dependencies'] : array();
$result = wp_register_module(
$module_handle,
$module_id,
$module_uri,
$module_dependencies,
isset( $module_asset['version'] ) ? $module_asset['version'] : false,

Check failure on line 190 in src/wp-includes/blocks.php

View workflow job for this annotation

GitHub Actions / Check PHP compatibility

Trailing comma's are not allowed in function calls in PHP 7.2 or earlier
);

if ( ! empty( $metadata['textdomain'] ) && in_array( 'wp-i18n', $module_dependencies, true ) ) {
// script translations?
wp_set_script_translations( $module_handle, $metadata['textdomain'] );
wp_set_script_translations( $module_id, $metadata['textdomain'] );
}

return $module_handle;
return $module_id;
}

/**
Expand Down Expand Up @@ -578,7 +578,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
}

$module_fields = array(
'viewModule' => 'view_module_handles',
'viewModule' => 'view_module_ids',
);
foreach ( $module_fields as $metadata_field_name => $settings_field_name ) {

Expand All @@ -590,7 +590,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
$processed_modules = array();
if ( is_array( $modules ) ) {
for ( $index = 0; $index < count( $modules ); $index++ ) {
$result = register_block_module_handle(
$result = register_block_module_id(
$metadata,
$metadata_field_name,
$index
Expand All @@ -600,7 +600,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
}
}
} else {
$result = register_block_module_handle(
$result = register_block_module_id(
$metadata,
$metadata_field_name
);
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ class WP_Block_Type {
public $view_script_handles = array();

/**
* Block type front end only module handles.
* Block type front end only module IDs.
*
* @since 6.5.0
* @var string[]
*/
public $view_module_handles = array();
public $view_module_ids = array();

/**
* Block type editor only style handles.
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ public function render( $options = array() ) {
}
}

if ( ! empty( $this->block_type->view_module_handles ) ) {
foreach ( $this->block_type->view_module_handles as $view_module_handle ) {
wp_enqueue_module( $view_module_handle );
if ( ! empty( $this->block_type->view_module_ids ) ) {
foreach ( $this->block_type->view_module_ids as $view_module_id ) {
wp_enqueue_module( $view_module_id );
}
}

Expand Down

0 comments on commit 440b5eb

Please sign in to comment.