Changeset 53091
- Timestamp:
- 04/07/2022 11:57:16 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 12 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r52939 r53091 109 109 // Path needs to be normalized to work in Windows env. 110 110 $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); 111 $theme_path_norm = wp_normalize_path( get_theme_file_path() ); 111 112 $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ); 112 113 $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); 113 114 $script_uri = $is_core_block ? 115 includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ) : 116 plugins_url( $script_path, $metadata['file'] ); 114 $is_theme_block = 0 === strpos( $script_path_norm, $theme_path_norm ); 115 116 $script_uri; 117 if ( $is_core_block ) { 118 $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ); 119 } elseif ( $is_theme_block ) { 120 $script_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $script_path_norm ) ); 121 } else { 122 $script_uri = plugins_url( $script_path, $metadata['file'] ); 123 } 124 117 125 $script_asset = require $script_asset_path; 118 126 $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); … … 151 159 } 152 160 $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); 161 $theme_path_norm = wp_normalize_path( get_theme_file_path() ); 153 162 $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); 154 163 if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) { … … 170 179 $style_path = "style$suffix.css"; 171 180 $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" ); 181 } 182 183 $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) ); 184 $is_theme_block = 0 === strpos( $style_path_norm, $theme_path_norm ); 185 186 if ( $is_theme_block ) { 187 $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) ); 172 188 } 173 189 … … 1316 1332 $args = array( 'handle' => $handle ); 1317 1333 if ( 0 === strpos( $handle, 'file:' ) && isset( $metadata['file'] ) ) { 1318 $style_path = remove_block_asset_path_prefix( $handle ); 1334 $style_path = remove_block_asset_path_prefix( $handle ); 1335 $theme_path_norm = wp_normalize_path( get_theme_file_path() ); 1336 $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) ); 1337 $is_theme_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $theme_path_norm ); 1338 1339 $style_uri = plugins_url( $style_path, $metadata['file'] ); 1340 1341 if ( $is_theme_block ) { 1342 $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) ); 1343 } 1344 1319 1345 $args = array( 1320 1346 'handle' => sanitize_key( "{$metadata['name']}-{$style_path}" ), 1321 'src' => plugins_url( $style_path, $metadata['file'] ),1347 'src' => $style_uri, 1322 1348 ); 1323 1349 } -
trunk/tests/phpunit/tests/blocks/register.php
r52699 r53091 254 254 255 255 /** 256 * @ticket 55513 257 */ 258 public function test_success_register_block_script_handle_in_theme() { 259 switch_theme( 'block-theme' ); 260 261 $metadata = array( 262 'file' => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ), 263 'name' => 'block-theme/example-block', 264 'viewScript' => 'file:./view.js', 265 ); 266 $result = register_block_script_handle( $metadata, 'viewScript' ); 267 268 $expected_script_handle = 'block-theme-example-block-view-script'; 269 $this->assertSame( $expected_script_handle, $result ); 270 } 271 272 /** 256 273 * @ticket 50263 257 274 */ … … 304 321 wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) ) 305 322 ); 323 } 324 325 /** 326 * @ticket 55513 327 */ 328 public function test_success_register_block_style_handle_in_theme() { 329 switch_theme( 'block-theme' ); 330 331 $metadata = array( 332 'file' => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ), 333 'name' => 'block-theme/example-block', 334 'editorStyle' => 'file:./editor-style.css', 335 ); 336 $result = register_block_style_handle( $metadata, 'editorStyle' ); 337 338 $expected_style_handle = 'block-theme-example-block-editor-style'; 339 $this->assertSame( $expected_style_handle, $result ); 340 $this->assertSame( 'replace', wp_styles()->get_data( $expected_style_handle, 'rtl' ) ); 306 341 } 307 342
Note: See TracChangeset
for help on using the changeset viewer.