Changeset 50836 for trunk/src/wp-includes/blocks.php
- Timestamp:
- 05/11/2021 09:41:48 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r50761 r50836 158 158 return false; 159 159 } 160 $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC ); 161 if ( $is_core_block && ! should_load_separate_core_block_assets() ) { 162 return false; 163 } 164 165 // Check whether styles should have a ".min" suffix or not. 166 $suffix = SCRIPT_DEBUG ? '' : '.min'; 167 160 168 $style_handle = $metadata[ $field_name ]; 161 169 $style_path = remove_block_asset_path_prefix( $metadata[ $field_name ] ); 162 if ( $style_handle === $style_path ) { 170 171 if ( $style_handle === $style_path && ! $is_core_block ) { 163 172 return $style_handle; 173 } 174 175 $style_uri = plugins_url( $style_path, $metadata['file'] ); 176 if ( $is_core_block ) { 177 $style_path = "style$suffix.css"; 178 $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" ); 164 179 } 165 180 … … 167 182 $block_dir = dirname( $metadata['file'] ); 168 183 $style_file = realpath( "$block_dir/$style_path" ); 184 $version = file_exists( $style_file ) ? filemtime( $style_file ) : false; 169 185 $result = wp_register_style( 170 186 $style_handle, 171 plugins_url( $style_path, $metadata['file'] ),187 $style_uri, 172 188 array(), 173 filemtime( $style_file )189 $version 174 190 ); 175 191 if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) { 176 192 wp_style_add_data( $style_handle, 'rtl', 'replace' ); 193 } 194 if ( file_exists( $style_file ) ) { 195 wp_style_add_data( $style_handle, 'path', $style_file ); 196 } 197 198 $rtl_file = str_replace( "$suffix.css", "-rtl$suffix.css", $style_file ); 199 if ( is_rtl() && file_exists( $rtl_file ) ) { 200 wp_style_add_data( $style_handle, 'path', $rtl_file ); 177 201 } 178 202 … … 929 953 return true === $block_support || is_array( $block_support ); 930 954 } 955 956 /** 957 * Checks whether separate assets should be loaded for core blocks. 958 * 959 * @since 5.8 960 * 961 * @return bool 962 */ 963 function should_load_separate_core_block_assets() { 964 if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { 965 return false; 966 } 967 /** 968 * Determine if separate styles & scripts will be loaded for blocks on-render or not. 969 * 970 * @since 5.8.0 971 * 972 * @param bool $load_separate_styles Whether separate styles will be loaded or not. 973 * 974 * @return bool Whether separate styles will be loaded or not. 975 */ 976 return apply_filters( 'separate_core_block_assets', false ); 977 }
Note: See TracChangeset
for help on using the changeset viewer.