Changeset 56183
- Timestamp:
- 07/10/2023 06:34:37 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r56109 r56183 135 135 } 136 136 137 $theme_path_norm = wp_normalize_path( get_theme_file_path() ); 137 // Cache $template_path_norm and $stylesheet_path_norm to avoid unnecessary additional calls. 138 static $template_path_norm = ''; 139 static $stylesheet_path_norm = ''; 140 if ( ! $template_path_norm || ! $stylesheet_path_norm ) { 141 $template_path_norm = wp_normalize_path( get_template_directory() ); 142 $stylesheet_path_norm = wp_normalize_path( get_stylesheet_directory() ); 143 } 144 138 145 $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ); 139 146 140 $is_core_block = isset( $metadata['file'] ) && str_starts_with( $metadata['file'], $wpinc_path_norm ); 141 $is_theme_block = str_starts_with( $script_path_norm, $theme_path_norm ); 147 $is_core_block = isset( $metadata['file'] ) && str_starts_with( $metadata['file'], $wpinc_path_norm ); 148 149 /* 150 * Determine if the block script was registered in a theme, by checking if the script path starts with either 151 * the parent (template) or child (stylesheet) directory path. 152 */ 153 $is_parent_theme_block = str_starts_with( $script_path_norm, $template_path_norm ); 154 $is_child_theme_block = str_starts_with( $script_path_norm, $stylesheet_path_norm ); 155 $is_theme_block = ( $is_parent_theme_block || $is_child_theme_block ); 142 156 143 157 $script_uri = plugins_url( $script_path, $metadata['file'] ); … … 145 159 $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ); 146 160 } elseif ( $is_theme_block ) { 147 $script_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $script_path_norm ) ); 161 // Get the script path deterministically based on whether or not it was registered in a parent or child theme. 162 $script_uri = $is_parent_theme_block 163 ? get_theme_file_uri( str_replace( $template_path_norm, '', $script_path_norm ) ) 164 : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) ); 148 165 } 149 166 … … 235 252 $style_uri = plugins_url( $style_path, $metadata['file'] ); 236 253 237 // Cache $theme_path_norm to avoid calling get_theme_file_path() multiple times. 238 static $theme_path_norm = ''; 239 if ( ! $theme_path_norm ) { 240 $theme_path_norm = wp_normalize_path( get_theme_file_path() ); 241 } 242 243 $is_theme_block = str_starts_with( $style_path_norm, $theme_path_norm ); 244 245 if ( $is_theme_block ) { 246 $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) ); 247 } elseif ( $is_core_block ) { 254 // Cache $template_path_norm and $stylesheet_path_norm to avoid unnecessary additional calls. 255 static $template_path_norm = ''; 256 static $stylesheet_path_norm = ''; 257 if ( ! $template_path_norm || ! $stylesheet_path_norm ) { 258 $template_path_norm = wp_normalize_path( get_template_directory() ); 259 $stylesheet_path_norm = wp_normalize_path( get_stylesheet_directory() ); 260 } 261 262 // Determine if the block style was registered in a theme, by checking if the script path starts with either 263 // the parent (template) or child (stylesheet) directory path. 264 $is_parent_theme_block = str_starts_with( $style_path_norm, $template_path_norm ); 265 $is_child_theme_block = str_starts_with( $style_path_norm, $stylesheet_path_norm ); 266 $is_theme_block = ( $is_parent_theme_block || $is_child_theme_block ); 267 268 if ( $is_core_block ) { 248 269 // All possible $style_path variants for core blocks are hard-coded above. 249 270 $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . '/' . $style_path ); 271 } elseif ( $is_theme_block ) { 272 // Get the script path deterministically based on whether or not it was registered in a parent or child theme. 273 $style_uri = $is_parent_theme_block 274 ? get_theme_file_uri( str_replace( $template_path_norm, '', $style_path_norm ) ) 275 : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $style_path_norm ) ); 250 276 } 251 277 } else {
Note: See TracChangeset
for help on using the changeset viewer.