Changeset 56524
- Timestamp:
- 09/06/2023 06:06:47 PM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/index.php
r56249 r56524 21 21 * 22 22 * @since 6.3.0 23 * 24 * @global string $wp_version The WordPress version string. 23 25 */ 24 26 function register_core_block_style_handles() { 27 global $wp_version; 28 25 29 if ( ! wp_should_load_separate_core_block_assets() ) { 26 30 return; 27 31 } 28 32 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( 33 $blocks_url = includes_url( 'blocks/' ); 34 $suffix = wp_scripts_get_suffix(); 35 $wp_styles = wp_styles(); 36 $style_fields = array( 39 37 'style' => 'style', 40 38 'editorStyle' => 'editor', 41 39 ); 40 41 static $core_blocks_meta; 42 if ( ! $core_blocks_meta ) { 43 $core_blocks_meta = require BLOCKS_PATH . 'blocks-json.php'; 44 } 45 46 $files = false; 47 $transient_name = 'wp_core_block_css_files'; 42 48 43 49 /* … … 45 51 * the core developer's workflow. 46 52 */ 47 if ( ! wp_is_development_mode( 'core' ) ) { 48 $transient_name = 'wp_core_block_css_files'; 49 $files = get_transient( $transient_name ); 50 if ( ! $files ) { 51 $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) ); 52 set_transient( $transient_name, $files ); 53 $can_use_cached = ! wp_is_development_mode( 'core' ); 54 55 if ( $can_use_cached ) { 56 $cached_files = get_transient( $transient_name ); 57 58 // Check the validity of cached values by checking against the current WordPress version. 59 if ( 60 is_array( $cached_files ) 61 && isset( $cached_files['version'] ) 62 && $cached_files['version'] === $wp_version 63 && isset( $cached_files['files'] ) 64 ) { 65 $files = $cached_files['files']; 53 66 } 54 } else {55 $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) );56 67 } 57 68 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 = wp_normalize_path( $includes_path . $style_path ); 69 if ( ! $files ) { 70 $files = glob( wp_normalize_path( BLOCKS_PATH . '**/**.css' ) ); 71 $files = array_map( 72 static function ( $file ) { 73 return str_replace( BLOCKS_PATH, '', $file ); 74 }, 75 $files 76 ); 61 77 62 if ( ! in_array( $path, $files, true ) ) { 78 // Save core block style paths in cache when not in development mode. 79 if ( $can_use_cached ) { 80 set_transient( 81 $transient_name, 82 array( 83 'version' => $wp_version, 84 'files' => $files, 85 ) 86 ); 87 } 88 } 89 90 $register_style = static function( $name, $filename, $style_handle ) use ( $blocks_url, $suffix, $wp_styles, $files ) { 91 $style_path = "{$name}/{$filename}{$suffix}.css"; 92 $path = wp_normalize_path( BLOCKS_PATH . $style_path ); 93 94 if ( ! in_array( $style_path, $files, true ) ) { 63 95 $wp_styles->add( 64 96 $style_handle, … … 68 100 } 69 101 70 $wp_styles->add( $style_handle, $ includes_url . $style_path );102 $wp_styles->add( $style_handle, $blocks_url . $style_path ); 71 103 $wp_styles->add_data( $style_handle, 'path', $path ); 72 104
Note: See TracChangeset
for help on using the changeset viewer.