Changeset 54160 for trunk/src/wp-includes/class-wp-theme-json-resolver.php
- Timestamp:
- 09/14/2022 03:50:01 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r54159 r54160 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.0239 *240 * @return WP_Theme_JSON241 */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;281 233 } 282 234 … … 419 371 * @since 5.9.0 Added user data, removed the `$settings` parameter, 420 372 * added the `$origin` parameter. 421 * @since 6.1.0 Added block data.422 373 * 423 374 * @param string $origin Optional. To what level should we merge data. … … 432 383 $result = new WP_Theme_JSON(); 433 384 $result->merge( static::get_core_data() ); 434 $result->merge( static::get_block_data() );435 385 $result->merge( static::get_theme_data() ); 436 386
Note: See TracChangeset
for help on using the changeset viewer.