Changeset 57590 for trunk/src/wp-includes/blocks.php
- Timestamp:
- 02/12/2024 11:40:49 AM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r57565 r57590 192 192 * @since 5.5.0 193 193 * @since 6.1.0 Added `$index` parameter. 194 * @since 6.5.0 The asset file is optional. 194 * @since 6.5.0 The asset file is optional. Added script handle support in the asset file. 195 195 * 196 196 * @param array $metadata Block metadata. … … 206 206 } 207 207 208 $script_handle = $metadata[ $field_name ];209 if ( is_array( $script_handle ) ) {210 if ( empty( $script_handle [ $index ] ) ) {208 $script_handle_or_path = $metadata[ $field_name ]; 209 if ( is_array( $script_handle_or_path ) ) { 210 if ( empty( $script_handle_or_path[ $index ] ) ) { 211 211 return false; 212 212 } 213 $script_handle = $script_handle[ $index ];214 } 215 216 $script_path = remove_block_asset_path_prefix( $script_handle );217 if ( $script_handle === $script_path ) {218 return $script_handle ;213 $script_handle_or_path = $script_handle_or_path[ $index ]; 214 } 215 216 $script_path = remove_block_asset_path_prefix( $script_handle_or_path ); 217 if ( $script_handle_or_path === $script_path ) { 218 return $script_handle_or_path; 219 219 } 220 220 221 221 $path = dirname( $metadata['file'] ); 222 222 $script_asset_raw_path = $path . '/' . substr_replace( $script_path, '.asset.php', - strlen( '.js' ) ); 223 $script_handle = generate_block_asset_handle( $metadata['name'], $field_name, $index );224 223 $script_asset_path = wp_normalize_path( 225 224 realpath( $script_asset_raw_path ) 226 225 ); 227 226 228 $script_path_norm = wp_normalize_path( realpath( $path . '/' . $script_path ) ); 229 $script_uri = get_block_asset_url( $script_path_norm ); 230 231 $script_args = array(); 227 // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460. 228 $script_asset = ! empty( $script_asset_path ) ? require $script_asset_path : array(); 229 $script_handle = isset( $script_asset['handle'] ) ? 230 $script_asset['handle'] : 231 generate_block_asset_handle( $metadata['name'], $field_name, $index ); 232 if ( wp_script_is( $script_handle, 'registered' ) ) { 233 return $script_handle; 234 } 235 236 $script_path_norm = wp_normalize_path( realpath( $path . '/' . $script_path ) ); 237 $script_uri = get_block_asset_url( $script_path_norm ); 238 $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); 239 $block_version = isset( $metadata['version'] ) ? $metadata['version'] : false; 240 $script_version = isset( $script_asset['version'] ) ? $script_asset['version'] : $block_version; 241 $script_args = array(); 232 242 if ( 'viewScript' === $field_name && $script_uri ) { 233 243 $script_args['strategy'] = 'defer'; 234 244 } 235 245 236 // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460. 237 $script_asset = ! empty( $script_asset_path ) ? require $script_asset_path : array(); 238 $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); 239 $result = wp_register_script( 246 $result = wp_register_script( 240 247 $script_handle, 241 248 $script_uri, 242 249 $script_dependencies, 243 isset( $script_asset['version'] ) ? $script_asset['version'] : false,250 $script_version, 244 251 $script_args 245 252 );
Note: See TracChangeset
for help on using the changeset viewer.