Changeset 58422 for trunk/src/wp-includes/class-wp-theme-json.php
- Timestamp:
- 06/17/2024 09:42:57 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-theme-json.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r58421 r58422 751 751 * One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'. 752 752 */ 753 public function __construct( $theme_json = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ), $origin = 'theme' ) {753 public function __construct( $theme_json = array( 'version' => self::LATEST_SCHEMA ), $origin = 'theme' ) { 754 754 if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) { 755 755 $origin = 'theme'; … … 1248 1248 * @since 5.9.0 Removed the `$type` parameter, added the `$types` and `$origins` parameters. 1249 1249 * @since 6.3.0 Add fallback layout styles for Post Template when block gap support isn't available. 1250 * @since 6.6.0 Added `skip_root_layout_styles` option to omit layout styles if desired. 1250 * @since 6.6.0 Added boolean `skip_root_layout_styles` and `include_block_style_variations` options 1251 * to control styles output as desired. 1251 1252 * 1252 1253 * @param string[] $types Types of styles to load. Will load all by default. It accepts: … … 1258 1259 * Optional. An array of options for now used for internal purposes only (may change without notice). 1259 1260 * 1260 * @type string $scope Makes sure all style are scoped to a given selector 1261 * @type string $root_selector Overwrites and forces a given selector to be used on the root node 1262 * @type bool $skip_root_layout_styles Omits root layout styles from the generated stylesheet. Default false. 1261 * @type string $scope Makes sure all style are scoped to a given selector 1262 * @type string $root_selector Overwrites and forces a given selector to be used on the root node 1263 * @type bool $skip_root_layout_styles Omits root layout styles from the generated stylesheet. Default false. 1264 * @type bool $include_block_style_variations Includes styles for block style variations in the generated stylesheet. Default false. 1263 1265 * } 1264 1266 * @return string The resulting stylesheet. … … 1282 1284 1283 1285 $blocks_metadata = static::get_blocks_metadata(); 1284 $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata );1286 $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata, $options ); 1285 1287 $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); 1286 1288 … … 2447 2449 * 2448 2450 * @since 5.8.0 2451 * @since 6.6.0 Added options array for modifying generated nodes. 2449 2452 * 2450 2453 * @param array $theme_json The tree to extract style nodes from. 2451 2454 * @param array $selectors List of selectors per block. 2455 * @param array $options { 2456 * Optional. An array of options for now used for internal purposes only (may change without notice). 2457 * 2458 * @type bool $include_block_style_variations Includes style nodes for block style variations. Default false. 2459 * } 2452 2460 * @return array An array of style nodes metadata. 2453 2461 */ 2454 protected static function get_style_nodes( $theme_json, $selectors = array() ) {2462 protected static function get_style_nodes( $theme_json, $selectors = array(), $options = array() ) { 2455 2463 $nodes = array(); 2456 2464 if ( ! isset( $theme_json['styles'] ) ) { … … 2494 2502 } 2495 2503 2496 $block_nodes = static::get_block_nodes( $theme_json );2504 $block_nodes = static::get_block_nodes( $theme_json, $selectors, $options ); 2497 2505 foreach ( $block_nodes as $block_node ) { 2498 2506 $nodes[] = $block_node; … … 2565 2573 * @since 6.1.0 2566 2574 * @since 6.3.0 Refactored and stabilized selectors API. 2575 * @since 6.6.0 Added optional selectors and options for generating block nodes. 2567 2576 * 2568 2577 * @param array $theme_json The theme.json converted to an array. 2578 * @param array $selectors Optional list of selectors per block. 2579 * @param array $options { 2580 * Optional. An array of options for now used for internal purposes only (may change without notice). 2581 * 2582 * @type bool $include_block_style_variations Includes nodes for block style variations. Default false. 2583 * } 2569 2584 * @return array The block nodes in theme.json. 2570 2585 */ 2571 private static function get_block_nodes( $theme_json ) {2572 $selectors = static::get_blocks_metadata();2586 private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) { 2587 $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; 2573 2588 $nodes = array(); 2574 2589 if ( ! isset( $theme_json['styles'] ) ) { … … 2598 2613 2599 2614 $variation_selectors = array(); 2600 if ( isset( $node['variations'] ) ) { 2615 $include_variations = $options['include_block_style_variations'] ?? false; 2616 if ( $include_variations && isset( $node['variations'] ) ) { 2601 2617 foreach ( $node['variations'] as $variation => $node ) { 2602 2618 $variation_selectors[] = array( … … 3281 3297 3282 3298 $blocks_metadata = static::get_blocks_metadata(); 3283 $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata ); 3299 $style_options = array( 'include_block_style_variations' => true ); // Allow variations data. 3300 $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata, $style_options ); 3284 3301 3285 3302 foreach ( $style_nodes as $metadata ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)