Changeset 54159 for trunk/src/wp-includes/class-wp-theme-json-resolver.php
- Timestamp:
- 09/14/2022 02:19:16 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r54133 r54159 231 231 232 232 return $with_theme_supports; 233 } 234 235 /** 236 * Gets the styles for blocks from the block.json file. 237 * 238 * @since 6.1.0 239 * 240 * @return WP_Theme_JSON 241 */ 242 public static function get_block_data() { 243 $registry = WP_Block_Type_Registry::get_instance(); 244 $blocks = $registry->get_all_registered(); 245 $config = array( 'version' => 1 ); 246 foreach ( $blocks as $block_name => $block_type ) { 247 if ( isset( $block_type->supports['__experimentalStyle'] ) ) { 248 $config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] ); 249 } 250 251 if ( 252 isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) && 253 null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null ) 254 ) { 255 // Ensure an empty placeholder value exists for the block, if it provides a default blockGap value. 256 // The real blockGap value to be used will be determined when the styles are rendered for output. 257 $config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] = null; 258 } 259 } 260 261 // Core here means it's the lower level part of the styles chain. 262 // It can be a core or a third-party block. 263 return new WP_Theme_JSON( $config, 'core' ); 264 } 265 266 /** 267 * When given an array, this will remove any keys with the name `//`. 268 * 269 * @param array $array The array to filter. 270 * @return array The filtered array. 271 */ 272 private static function remove_json_comments( $array ) { 273 unset( $array['//'] ); 274 foreach ( $array as $k => $v ) { 275 if ( is_array( $v ) ) { 276 $array[ $k ] = static::remove_json_comments( $v ); 277 } 278 } 279 280 return $array; 233 281 } 234 282 … … 371 419 * @since 5.9.0 Added user data, removed the `$settings` parameter, 372 420 * added the `$origin` parameter. 421 * @since 6.1.0 Added block data. 373 422 * 374 423 * @param string $origin Optional. To what level should we merge data. … … 383 432 $result = new WP_Theme_JSON(); 384 433 $result->merge( static::get_core_data() ); 434 $result->merge( static::get_block_data() ); 385 435 $result->merge( static::get_theme_data() ); 386 436
Note: See TracChangeset
for help on using the changeset viewer.