Changeset 61473 for trunk/src/wp-includes/class-wp-theme-json.php
- Timestamp:
- 01/12/2026 12:18:12 PM (10 months 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
r61431 r61473 1327 1327 * @since 6.6.0 Added boolean `skip_root_layout_styles` and `include_block_style_variations` options 1328 1328 * to control styles output as desired. 1329 * @since 7.0.0 Deprecated 'base-layout-styles' type; added `base_layout_styles` option for classic themes. 1329 1330 * 1330 1331 * @param string[] $types Types of styles to load. Will load all by default. It accepts: … … 1332 1333 * - `styles`: only the styles section in theme.json. 1333 1334 * - `presets`: only the classes for the presets. 1334 * - `base-layout-styles`: only the base layout styles. 1335 * - `base-layout-styles`: only the base layout styles. Deprecated in 7.0.0. 1335 1336 * - `custom-css`: only the custom CSS. 1336 1337 * @param string[] $origins A list of origins to include. By default it includes VALID_ORIGINS. … … 1341 1342 * @type string $root_selector Overwrites and forces a given selector to be used on the root node 1342 1343 * @type bool $skip_root_layout_styles Omits root layout styles from the generated stylesheet. Default false. 1344 * @type bool $base_layout_styles When true generates only base layout styles without alignment rules. Default false. 1343 1345 * @type bool $include_block_style_variations Includes styles for block style variations in the generated stylesheet. Default false. 1344 1346 * } … … 1396 1398 if ( in_array( 'styles', $types, true ) ) { 1397 1399 if ( false !== $root_style_key && empty( $options['skip_root_layout_styles'] ) ) { 1398 $stylesheet .= $this->get_root_layout_rules( $style_nodes[ $root_style_key ]['selector'], $style_nodes[ $root_style_key ] );1400 $stylesheet .= $this->get_root_layout_rules( $style_nodes[ $root_style_key ]['selector'], $style_nodes[ $root_style_key ], $options ); 1399 1401 } 1400 1402 $stylesheet .= $this->get_block_classes( $style_nodes ); 1401 } elseif ( in_array( 'base-layout-styles', $types, true ) ) {1402 $root_selector = static::ROOT_BLOCK_SELECTOR;1403 $columns_selector = '.wp-block-columns';1404 $post_template_selector = '.wp-block-post-template';1405 if ( ! empty( $options['scope'] ) ) {1406 $root_selector = static::scope_selector( $options['scope'], $root_selector );1407 $columns_selector = static::scope_selector( $options['scope'], $columns_selector );1408 $post_template_selector = static::scope_selector( $options['scope'], $post_template_selector );1409 }1410 if ( ! empty( $options['root_selector'] ) ) {1411 $root_selector = $options['root_selector'];1412 }1413 /*1414 * Base layout styles are provided as part of `styles`, so only output separately if explicitly requested.1415 * For backwards compatibility, the Columns block is explicitly included, to support a different default gap value.1416 */1417 $base_styles_nodes = array(1418 array(1419 'path' => array( 'styles' ),1420 'selector' => $root_selector,1421 ),1422 array(1423 'path' => array( 'styles', 'blocks', 'core/columns' ),1424 'selector' => $columns_selector,1425 'name' => 'core/columns',1426 ),1427 array(1428 'path' => array( 'styles', 'blocks', 'core/post-template' ),1429 'selector' => $post_template_selector,1430 'name' => 'core/post-template',1431 ),1432 );1433 1434 foreach ( $base_styles_nodes as $base_style_node ) {1435 $stylesheet .= $this->get_layout_styles( $base_style_node, $types );1436 }1437 1403 } 1438 1404 … … 1625 1591 * @since 6.5.3 Add types parameter to check if only base layout styles are needed. 1626 1592 * @since 6.6.0 Updated layout style specificity to be compatible with overall 0-1-0 specificity in global styles. 1593 * @since 7.0.0 Replaced `$types` parameter with `$options` array; base layout styles controlled via `base_layout_styles` option. 1627 1594 * 1628 1595 * @param array $block_metadata Metadata about the block to get styles for. 1629 * @param array $ types Optional. Types of styles to output. If empty, all styles will be output.1596 * @param array $options Optional. An array of options for now used for internal purposes only. 1630 1597 * @return string Layout styles for the block. 1631 1598 */ 1632 protected function get_layout_styles( $block_metadata, $ types = array() ) {1599 protected function get_layout_styles( $block_metadata, $options = array() ) { 1633 1600 $block_rules = ''; 1634 1601 $block_type = null; … … 1778 1745 $declarations = array(); 1779 1746 1780 // Skip outputting base styles for flow and constrained layout types if theme doesn't support theme.json. The 'base-layout-styles' type flags this. 1781 if ( in_array( 'base-layout-styles', $types, true ) && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) { 1747 // Skip outputting base styles for flow and constrained layout types when base_layout_styles is enabled. 1748 // These themes don't use .wp-site-blocks wrapper, so these layout-specific alignment styles aren't needed. 1749 if ( ! empty( $options['base_layout_styles'] ) && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) { 1782 1750 continue; 1783 1751 } … … 3056 3024 * @since 6.6.0 Use `ROOT_CSS_PROPERTIES_SELECTOR` for CSS custom properties and improved consistency of root padding rules. 3057 3025 * Updated specificity of body margin reset and first/last child selectors. 3026 * @since 7.0.0 Added `$options` parameter to control alignment styles output for classic themes. 3058 3027 * 3059 3028 * @param string $selector The root node selector. 3060 3029 * @param array $block_metadata The metadata for the root block. 3030 * @param array $options Optional. An array of options for now used for internal purposes only. 3061 3031 * @return string The additional root rules CSS. 3062 3032 */ 3063 public function get_root_layout_rules( $selector, $block_metadata ) {3033 public function get_root_layout_rules( $selector, $block_metadata, $options = array() ) { 3064 3034 $css = ''; 3065 3035 $settings = $this->theme_json['settings'] ?? array(); … … 3102 3072 } 3103 3073 3104 $css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }'; 3105 $css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; 3106 $css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }'; 3074 // Skip outputting alignment styles when base_layout_styles is enabled. 3075 // These styles target .wp-site-blocks which is only used by block themes. 3076 if ( empty( $options['base_layout_styles'] ) ) { 3077 $css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }'; 3078 $css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; 3079 $css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }'; 3080 } 3107 3081 3108 3082 // Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES. … … 3116 3090 $css .= static::ROOT_CSS_PROPERTIES_SELECTOR . " { --wp--style--block-gap: $block_gap_value; }"; 3117 3091 } 3118 $css .= $this->get_layout_styles( $block_metadata );3092 $css .= $this->get_layout_styles( $block_metadata, $options ); 3119 3093 3120 3094 return $css;
Note:
See TracChangeset
for help on using the changeset viewer.