Changeset 56064
- Timestamp:
- 06/27/2023 11:26:12 AM (15 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r56044 r56064 373 373 if ( ! isset( $metadata['style'] ) ) { 374 374 $metadata['style'] = "wp-block-$block_name"; 375 } 376 if ( current_theme_supports( 'wp-block-styles' ) && wp_should_load_separate_core_block_assets() ) { 377 $metadata['style'] = (array) $metadata['style']; 378 $metadata['style'][] = "wp-block-{$block_name}-theme"; 375 379 } 376 380 if ( ! isset( $metadata['editorStyle'] ) ) { -
trunk/src/wp-includes/blocks/index.php
r56044 r56064 56 56 } 57 57 58 $register_style = static function( $name, $filename, $style_handle ) use ( $includes_path, $includes_url, $suffix, $wp_styles, $files ) { 59 $style_path = "blocks/{$name}/{$filename}{$suffix}.css"; 60 $path = $includes_path . $style_path; 61 62 if ( ! in_array( $path, $files, true ) ) { 63 $wp_styles->add( 64 $style_handle, 65 false 66 ); 67 return; 68 } 69 70 $wp_styles->add( $style_handle, $includes_url . $style_path ); 71 $wp_styles->add_data( $style_handle, 'path', $path ); 72 73 $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ); 74 if ( is_rtl() && in_array( $rtl_file, $files, true ) ) { 75 $wp_styles->add_data( $style_handle, 'rtl', 'replace' ); 76 $wp_styles->add_data( $style_handle, 'suffix', $suffix ); 77 $wp_styles->add_data( $style_handle, 'path', $rtl_file ); 78 } 79 }; 80 58 81 foreach ( $core_blocks_meta as $name => $schema ) { 59 82 /** This filter is documented in wp-includes/blocks.php */ … … 68 91 } 69 92 93 // Register block theme styles. 94 $register_style( $name, 'theme', "wp-block-{$name}-theme" ); 95 70 96 foreach ( $style_fields as $style_field => $filename ) { 71 97 $style_handle = $schema[ $style_field ]; … … 73 99 continue; 74 100 } 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 } 101 $register_style( $name, $filename, $style_handle ); 96 102 } 97 103 } -
trunk/src/wp-includes/script-loader.php
r56047 r56064 2373 2373 wp_enqueue_style( 'wp-block-library' ); 2374 2374 2375 if ( current_theme_supports( 'wp-block-styles' ) ) { 2376 if ( wp_should_load_separate_core_block_assets() ) { 2377 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'css' : 'min.css'; 2378 $files = glob( __DIR__ . "/blocks/**/theme.$suffix" ); 2379 foreach ( $files as $path ) { 2380 $block_name = basename( dirname( $path ) ); 2381 if ( is_rtl() && file_exists( __DIR__ . "/blocks/$block_name/theme-rtl.$suffix" ) ) { 2382 $path = __DIR__ . "/blocks/$block_name/theme-rtl.$suffix"; 2383 } 2384 wp_add_inline_style( "wp-block-{$block_name}", file_get_contents( $path ) ); 2385 } 2386 } else { 2387 wp_enqueue_style( 'wp-block-library-theme' ); 2388 } 2375 if ( current_theme_supports( 'wp-block-styles' ) && ! wp_should_load_separate_core_block_assets() ) { 2376 wp_enqueue_style( 'wp-block-library-theme' ); 2389 2377 } 2390 2378 -
trunk/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php
r56044 r56064 56 56 * 57 57 * @dataProvider data_block_data 58 * 59 * @param string $name The block name. 60 * @param array $schema The block's schema. 58 61 */ 59 62 public function test_wp_should_load_separate_core_block_assets_false( $name, $schema ) { … … 75 78 * 76 79 * @dataProvider data_block_data 80 * 81 * @param string $name The block name. 82 * @param array $schema The block's schema. 77 83 */ 78 84 public function test_wp_should_load_separate_core_block_assets_true( $name, $schema ) { … … 100 106 } 101 107 108 /** 109 * @ticket 58560 110 * 111 * @dataProvider data_block_data 112 * 113 * @param string $name The block name. 114 */ 115 public function test_wp_should_load_separate_core_block_assets_current_theme_supports( $name ) { 116 add_filter( 'should_load_separate_core_block_assets', '__return_true' ); 117 add_theme_support( 'wp-block-styles' ); 118 register_core_block_style_handles(); 119 120 $wp_styles = $GLOBALS['wp_styles']; 121 122 $style_handle = "wp-block-{$name}-theme"; 123 124 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' ); 125 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 126 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' ); 127 } else { 128 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' ); 129 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' ); 130 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' ); 131 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' ); 132 } 133 } 102 134 103 135 public function data_block_data() {
Note: See TracChangeset
for help on using the changeset viewer.