Changeset 56044
- Timestamp:
- 06/26/2023 09:15:21 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r55988 r56044 655 655 } 656 656 657 delete_transient( 'wp_core_block_css_files' ); 658 657 659 /** 658 660 * Fires after a site is fully upgraded. -
trunk/src/wp-includes/blocks.php
r56021 r56044 187 187 } 188 188 189 $style_handle = $metadata[ $field_name ]; 190 if ( is_array( $style_handle ) ) { 191 if ( empty( $style_handle[ $index ] ) ) { 192 return false; 193 } 194 $style_handle = $style_handle[ $index ]; 195 } 196 197 $style_handle_name = generate_block_asset_handle( $metadata['name'], $field_name, $index ); 198 // If the style handle is already registered, skip re-registering. 199 if ( wp_style_is( $style_handle_name, 'registered' ) ) { 200 return $style_handle_name; 201 } 202 189 203 static $wpinc_path_norm = ''; 190 204 if ( ! $wpinc_path_norm ) { … … 196 210 if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) { 197 211 return false; 198 }199 200 $style_handle = $metadata[ $field_name ];201 if ( is_array( $style_handle ) ) {202 if ( empty( $style_handle[ $index ] ) ) {203 return false;204 }205 $style_handle = $style_handle[ $index ];206 212 } 207 213 … … 247 253 } 248 254 249 $style_handle = generate_block_asset_handle( $metadata['name'], $field_name, $index ); 250 $version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false; 251 $result = wp_register_style( 252 $style_handle, 255 $version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false; 256 $result = wp_register_style( 257 $style_handle_name, 253 258 $style_uri, 254 259 array(), … … 260 265 261 266 if ( $has_style_file ) { 262 wp_style_add_data( $style_handle , 'path', $style_path_norm );267 wp_style_add_data( $style_handle_name, 'path', $style_path_norm ); 263 268 264 269 if ( $is_core_block ) { … … 269 274 270 275 if ( is_rtl() && file_exists( $rtl_file ) ) { 271 wp_style_add_data( $style_handle , 'rtl', 'replace' );272 wp_style_add_data( $style_handle , 'suffix', $suffix );273 wp_style_add_data( $style_handle , 'path', $rtl_file );274 } 275 } 276 277 return $style_handle ;276 wp_style_add_data( $style_handle_name, 'rtl', 'replace' ); 277 wp_style_add_data( $style_handle_name, 'suffix', $suffix ); 278 wp_style_add_data( $style_handle_name, 'path', $rtl_file ); 279 } 280 } 281 282 return $style_handle_name; 278 283 } 279 284 … … 321 326 static $core_blocks_meta; 322 327 if ( ! $core_blocks_meta ) { 323 $core_blocks_meta = require _onceABSPATH . WPINC . '/blocks/blocks-json.php';328 $core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php'; 324 329 } 325 330 -
trunk/src/wp-includes/blocks/index.php
r55879 r56044 12 12 require BLOCKS_PATH . 'widget-group.php'; 13 13 require BLOCKS_PATH . 'require-dynamic-blocks.php'; 14 15 /** 16 * Registers core block style handles. 17 * 18 * While {@see register_block_style_handle()} is typically used for that, the way it is 19 * implemented is inefficient for core block styles. Registering those style handles here 20 * avoids unnecessary logic and filesystem lookups in the other function. 21 * 22 * @since 6.3.0 23 */ 24 function register_core_block_style_handles() { 25 if ( ! wp_should_load_separate_core_block_assets() ) { 26 return; 27 } 28 29 static $core_blocks_meta; 30 if ( ! $core_blocks_meta ) { 31 $core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php'; 32 } 33 34 $includes_url = includes_url(); 35 $includes_path = ABSPATH . WPINC . '/'; 36 $suffix = wp_scripts_get_suffix(); 37 $wp_styles = wp_styles(); 38 $style_fields = array( 39 'style' => 'style', 40 'editorStyle' => 'editor', 41 ); 42 43 /* 44 * Ignore transient cache when the development mode is set to 'core'. Why? To avoid interfering with 45 * the core developer's workflow. 46 */ 47 if ( 'core' !== wp_get_development_mode() ) { 48 $transient_name = 'wp_core_block_css_files'; 49 $files = get_transient( $transient_name ); 50 if ( ! $files ) { 51 $files = glob( __DIR__ . '/**/**.css' ); 52 set_transient( $transient_name, $files ); 53 } 54 } else { 55 $files = glob( __DIR__ . '/**/**.css' ); 56 } 57 58 foreach ( $core_blocks_meta as $name => $schema ) { 59 /** This filter is documented in wp-includes/blocks.php */ 60 $schema = apply_filters( 'block_type_metadata', $schema ); 61 62 // Backfill these properties similar to `register_block_type_from_metadata()`. 63 if ( ! isset( $schema['style'] ) ) { 64 $schema['style'] = "wp-block-{$name}"; 65 } 66 if ( ! isset( $schema['editorStyle'] ) ) { 67 $schema['editorStyle'] = "wp-block-{$name}-editor"; 68 } 69 70 foreach ( $style_fields as $style_field => $filename ) { 71 $style_handle = $schema[ $style_field ]; 72 if ( is_array( $style_handle ) ) { 73 continue; 74 } 75 76 $style_path = "blocks/{$name}/{$filename}{$suffix}.css"; 77 $path = $includes_path . $style_path; 78 79 if ( ! in_array( $path, $files, true ) ) { 80 $wp_styles->add( 81 $style_handle, 82 false 83 ); 84 continue; 85 } 86 87 $wp_styles->add( $style_handle, $includes_url . $style_path ); 88 $wp_styles->add_data( $style_handle, 'path', $path ); 89 90 $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ); 91 if ( is_rtl() && in_array( $rtl_file, $files, true ) ) { 92 $wp_styles->add_data( $style_handle, 'rtl', 'replace' ); 93 $wp_styles->add_data( $style_handle, 'suffix', $suffix ); 94 $wp_styles->add_data( $style_handle, 'path', $rtl_file ); 95 } 96 } 97 } 98 } 99 add_action( 'init', 'register_core_block_style_handles', 9 ); 14 100 15 101 /** -
trunk/tests/phpunit/tests/blocks/register.php
r56005 r56044 398 398 public function test_handle_passed_register_block_style_handle() { 399 399 $metadata = array( 400 'name' => 'test-block', 400 401 'style' => 'test-style-handle', 401 402 ); … … 407 408 public function test_handles_passed_register_block_style_handles() { 408 409 $metadata = array( 410 'name' => 'test-block', 409 411 'style' => array( 'test-style-handle', 'test-style-handle-2' ), 410 412 ); … … 522 524 $this->assertSame( $expected_style_handle, $result ); 523 525 $this->assertFalse( wp_styles()->get_data( $expected_style_handle, 'rtl' ) ); 526 } 527 528 /** 529 * @ticket 58528 530 * 531 * @covers ::register_block_style_handle 532 */ 533 public function test_success_register_block_style_handle_exists() { 534 $expected_style_handle = 'block-theme-example-block-editor-style'; 535 wp_register_style( $expected_style_handle, false ); 536 switch_theme( 'block-theme' ); 537 538 $metadata = array( 539 'file' => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ), 540 'name' => 'block-theme/example-block', 541 'editorStyle' => 'file:./editor-style.css', 542 ); 543 $result = register_block_style_handle( $metadata, 'editorStyle' ); 544 545 $this->assertSame( $expected_style_handle, $result ); 524 546 } 525 547
Note: See TracChangeset
for help on using the changeset viewer.