Changeset 56254 for trunk/src/wp-includes/global-styles-and-settings.php
- Timestamp:
- 07/18/2023 12:00:49 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/global-styles-and-settings.php
r56249 r56254 321 321 // The likes of block element styles from theme.json do not have $metadata['name'] set. 322 322 if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) { 323 $result = array_values( 324 array_filter( 325 $metadata['path'], 326 static function ( $item ) { 327 if ( str_contains( $item, 'core/' ) ) { 328 return true; 329 } 330 return false; 331 } 332 ) 333 ); 334 if ( isset( $result[0] ) ) { 335 if ( str_starts_with( $result[0], 'core/' ) ) { 336 $block_name = str_replace( 'core/', '', $result[0] ); 323 $block_name = wp_get_block_name_from_theme_json_path( $metadata['path'] ); 324 if ( $block_name ) { 325 if ( str_starts_with( $block_name, 'core/' ) ) { 326 $block_name = str_replace( 'core/', '', $block_name ); 337 327 $stylesheet_handle = 'wp-block-' . $block_name; 338 328 } … … 341 331 } 342 332 } 333 } 334 335 /** 336 * Gets the block name from a given theme.json path. 337 * 338 * @since 6.3.0 339 * @access private 340 * 341 * @param array $path An array of keys describing the path to a property in theme.json. 342 * @return string Identified block name, or empty string if none found. 343 */ 344 function wp_get_block_name_from_theme_json_path( $path ) { 345 // Block name is expected to be the third item after 'styles' and 'blocks'. 346 if ( 347 count( $path ) >= 3 348 && 'styles' === $path[0] 349 && 'blocks' === $path[1] 350 && str_contains( $path[2], '/' ) 351 ) { 352 return $path[2]; 353 } 354 355 /* 356 * As fallback and for backward compatibility, allow any core block to be 357 * at any position. 358 */ 359 $result = array_values( 360 array_filter( 361 $path, 362 static function ( $item ) { 363 if ( str_contains( $item, 'core/' ) ) { 364 return true; 365 } 366 return false; 367 } 368 ) 369 ); 370 if ( isset( $result[0] ) ) { 371 return $result[0]; 372 } 373 return ''; 343 374 } 344 375
Note: See TracChangeset
for help on using the changeset viewer.