PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | lib/class-wp-theme-json-gutenberg.php +140 -53 23.9.1 → 24.1.0 View file →
@@ -124,8 +124,9 @@
124 124 * `prevent_override` value for `color.duotone` to use `color.defaultDuotone`.
125 125 * @since 6.2.0 Added 'shadow' presets.
126 126 * @since 6.6.0 Updated the 'prevent_override' value for font size presets to use 'typography.defaultFontSizes' and spacing size presets to use `spacing.defaultSpacingSizes`.
127 127 * @since 6.6.0 Added `aspectRatios`.
128 + * @since 7.2.0 Added 'textShadow' presets.
128 129 * @var array
129 130 */
130 131 const PRESETS_METADATA = array(
131 132 array(
@@ -186,8 +187,17 @@
186 187 'classes' => array( '.has-$slug-font-family' => 'font-family' ),
187 188 'properties' => array( 'font-family' ),
188 189 ),
189 190 array(
191 + 'path' => array( 'typography', 'textShadowPresets' ),
192 + 'prevent_override' => array( 'typography', 'defaultTextShadowPresets' ),
193 + 'use_default_names' => false,
194 + 'value_key' => 'textShadow',
195 + 'css_vars' => '--wp--preset--text-shadow--$slug',
196 + 'classes' => array( '.has-$slug-text-shadow' => 'text-shadow' ),
197 + 'properties' => array( 'text-shadow' ),
198 + ),
199 + array(
190 200 'path' => array( 'spacing', 'spacingSizes' ),
191 201 'prevent_override' => array( 'spacing', 'defaultSpacingSizes' ),
192 202 'use_default_names' => true,
193 203 'value_key' => 'size',
@@ -392,8 +402,10 @@
392 402 * @since 7.0.0 Added type markers to the schema for boolean values.
393 403 * @since 7.0.0 Added `dimensions.width`, `dimensions.height`, and
394 404 * `typography.textIndent` properties.
395 405 * @since 7.1.0 Added `viewport` property.
406 + * @since 7.2.0 Added `typography.textShadow`, `typography.textShadowPresets`,
407 + * and `typography.defaultTextShadowPresets`.
396 408 * @var array
397 409 */
398 410 const VALID_SETTINGS = array(
399 411 'appearanceTools' => null,
@@ -469,24 +481,27 @@
469 481 'presets' => null,
470 482 'defaultPresets' => null,
471 483 ),
472 484 'typography' => array(
473 - 'fluid' => null,
474 - 'customFontSize' => null,
475 - 'defaultFontSizes' => null,
476 - 'dropCap' => null,
477 - 'fontFamilies' => null,
478 - 'fontSizes' => null,
479 - 'fontStyle' => null,
480 - 'fontWeight' => null,
481 - 'letterSpacing' => null,
482 - 'lineHeight' => null,
483 - 'textAlign' => null,
484 - 'textColumns' => null,
485 - 'textDecoration' => null,
486 - 'textIndent' => null,
487 - 'textTransform' => null,
488 - 'writingMode' => null,
485 + 'fluid' => null,
486 + 'customFontSize' => null,
487 + 'defaultFontSizes' => null,
488 + 'dropCap' => null,
489 + 'fontFamilies' => null,
490 + 'fontSizes' => null,
491 + 'fontStyle' => null,
492 + 'fontWeight' => null,
493 + 'letterSpacing' => null,
494 + 'lineHeight' => null,
495 + 'textAlign' => null,
496 + 'textColumns' => null,
497 + 'textDecoration' => null,
498 + 'textIndent' => null,
499 + 'textTransform' => null,
500 + 'textShadow' => null,
501 + 'defaultTextShadowPresets' => null,
502 + 'textShadowPresets' => null,
503 + 'writingMode' => null,
489 504 ),
490 505 'viewport' => array(
491 506 'mobile' => null,
492 507 'tablet' => null,
@@ -651,9 +666,9 @@
651 666 *
652 667 * @since 7.1.0
653 668 *
654 669 * @param mixed $viewport_settings Viewport settings from theme.json.
655 - * @param array $options {
670 + * @param array $options {
656 671 * Optional. Options for generating media queries.
657 672 *
658 673 * @type bool $include_desktop Whether to include the desktop media query. Default false.
659 674 * }
@@ -916,13 +931,15 @@
916 931
917 932 /**
918 933 * Processes pseudo-selectors for any node (block or variation).
919 934 *
920 - * @param array $node The node data (block or variation).
921 - * @param string $base_selector The base selector.
922 - * @param array $settings The theme settings.
923 - * @param string $block_name The block name.
924 - * @param array|null $block_metadata Metadata about the block to get styles for.
935 + * @since 7.0.0
936 + *
937 + * @param array $node The node data (block or variation).
938 + * @param string $base_selector The base selector.
939 + * @param array $settings The theme settings.
940 + * @param string $block_name The block name.
941 + * @param array|null $block_metadata Metadata about the block to get styles for.
925 942 * @param array|null $style_variation Style variation metadata.
926 943 * @return array Array of pseudo-selector declarations.
927 944 */
928 945 private function process_pseudo_selectors( $node, $base_selector, $settings, $block_name, $block_metadata = null, $style_variation = null ) {
@@ -1230,8 +1247,10 @@
1230 1247 *
1231 1248 * @since 5.8.0
1232 1249 * @since 5.9.0 Added the `$valid_block_names` and `$valid_element_name` parameters.
1233 1250 * @since 6.6.0 Extended schema definition to allow enhanced block style variations.
1251 + * @since 7.1.1 Updated schema to allow responsive breakpoint states and pseudo-selectors
1252 + * at the top level of `styles` for block style variation partials.
1234 1253 *
1235 1254 * @param array $input Structure to sanitize.
1236 1255 * @param array $valid_block_names List of valid block names.
1237 1256 * @param array $valid_element_names List of valid element names.
@@ -1295,9 +1314,17 @@
1295 1314 }
1296 1315
1297 1316 $schema_styles_blocks = array();
1298 1317 $schema_settings_blocks = array();
1318 + $breakpoint_states = array_keys( $responsive_media_queries );
1299 1319
1320 + $common_block_settings = static::VALID_SETTINGS;
1321 + // `viewport` and `blockVisibility` are global-only settings and cannot be set per block for now.
1322 + unset(
1323 + $common_block_settings['viewport'],
1324 + $common_block_settings['blockVisibility']
1325 + );
1326 +
1300 1327 /*
1301 1328 * Generate a schema for blocks.
1302 1329 * - Block styles can contain `elements`, `variations`, and responsive breakpoint state definitions.
1303 1330 * - Variations definitions cannot be nested.
@@ -1305,23 +1332,29 @@
1305 1332 * - Variation inner `blocks` styles can contain `elements` and responsive breakpoint states.
1306 1333 *
1307 1334 * As each variation needs both a `blocks` schema and responsive `blocks` schemas
1308 1335 * for further nested inner `blocks`, the overall schema is generated in multiple passes.
1336 + *
1337 + * All blocks start with the same style schema. Build that common schema
1338 + * once, then add block-specific pseudo and custom states below.
1309 1339 */
1340 + $responsive_block_schema = $styles_non_top_level;
1341 + $responsive_block_schema['elements'] = $schema_styles_elements;
1342 +
1343 + $common_block_schema = $styles_non_top_level;
1344 + $common_block_schema['elements'] = $schema_styles_elements;
1345 +
1346 + foreach ( $breakpoint_states as $breakpoint_state ) {
1347 + $common_block_schema[ $breakpoint_state ] = $responsive_block_schema;
1348 + }
1349 +
1310 1350 foreach ( $valid_block_names as $block ) {
1311 - $schema_settings_blocks[ $block ] = static::VALID_SETTINGS;
1312 - // `viewport` and `blockVisibility` are global-only settings and cannot be set per block for now.
1313 - unset( $schema_settings_blocks[ $block ]['viewport'] );
1314 - unset( $schema_settings_blocks[ $block ]['blockVisibility'] );
1315 - $schema_styles_blocks[ $block ] = $styles_non_top_level;
1316 - $schema_styles_blocks[ $block ]['elements'] = $schema_styles_elements;
1351 + $schema_settings_blocks[ $block ] = $common_block_settings;
1352 + $schema_styles_blocks[ $block ] = $common_block_schema;
1317 1353
1318 - // Add responsive breakpoint states for all blocks.
1319 - foreach ( array_keys( $responsive_media_queries ) as $breakpoint_state ) {
1320 - $schema_styles_blocks[ $block ][ $breakpoint_state ] = $styles_non_top_level;
1321 - $schema_styles_blocks[ $block ][ $breakpoint_state ]['elements'] = $schema_styles_elements;
1322 -
1323 - if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] ) ) {
1354 + // Add responsive pseudo-selectors only to blocks that support them.
1355 + if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] ) ) {
1356 + foreach ( $breakpoint_states as $breakpoint_state ) {
1324 1357 foreach ( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] as $pseudo_selector ) {
1325 1358 $schema_styles_blocks[ $block ][ $breakpoint_state ][ $pseudo_selector ] = $styles_non_top_level;
1326 1359 }
1327 1360 }
@@ -1376,9 +1409,8 @@
1376 1409 // Add responsive breakpoint states to block style variations.
1377 1410 foreach ( array_keys( $responsive_media_queries ) as $breakpoint_state ) {
1378 1411 $variation_schema[ $breakpoint_state ] = $styles_non_top_level;
1379 1412 $variation_schema[ $breakpoint_state ]['elements'] = $schema_styles_elements;
1380 - $variation_schema[ $breakpoint_state ]['blocks'] = $schema_styles_blocks;
1381 1413
1382 1414 if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] ) ) {
1383 1415 foreach ( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] as $pseudo_selector ) {
1384 1416 $variation_schema[ $breakpoint_state ][ $pseudo_selector ] = $styles_non_top_level;
@@ -1406,8 +1438,49 @@
1406 1438 $schema['settings'] = static::VALID_SETTINGS;
1407 1439 $schema['settings']['blocks'] = $schema_settings_blocks;
1408 1440 $schema['settings']['typography']['fontFamilies'] = static::schema_in_root_and_per_origin( static::FONT_FAMILY_SCHEMA );
1409 1441
1442 + /*
1443 + * Add block style variation states to the top-level styles schema.
1444 + *
1445 + * Block style variations defined in a standalone JSON partial within a
1446 + * theme's `styles` directory declare their styles at the root of the
1447 + * `styles` object, so they are sanitized against the top-level schema.
1448 + * It needs to allow the same states that are allowed for variations
1449 + * declared inline in theme.json, otherwise those states are silently
1450 + * removed as unknown keys.
1451 + *
1452 + * The `blockTypes` property is only present on block style variation
1453 + * partials, so it both identifies the config as a variation and
1454 + * determines which pseudo-selectors are valid for it. Regular
1455 + * theme.json files are unaffected.
1456 + */
1457 + if ( ! empty( $input['blockTypes'] ) && is_array( $input['blockTypes'] ) ) {
1458 + $variation_pseudo_selectors = array();
1459 + foreach ( $input['blockTypes'] as $variation_block_type ) {
1460 + if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $variation_block_type ] ) ) {
1461 + $variation_pseudo_selectors = array_merge(
1462 + $variation_pseudo_selectors,
1463 + static::VALID_BLOCK_PSEUDO_SELECTORS[ $variation_block_type ]
1464 + );
1465 + }
1466 + }
1467 + $variation_pseudo_selectors = array_unique( $variation_pseudo_selectors );
1468 +
1469 + foreach ( $breakpoint_states as $breakpoint_state ) {
1470 + $schema['styles'][ $breakpoint_state ] = $styles_non_top_level;
1471 + $schema['styles'][ $breakpoint_state ]['elements'] = $schema_styles_elements;
1472 +
1473 + foreach ( $variation_pseudo_selectors as $pseudo_selector ) {
1474 + $schema['styles'][ $breakpoint_state ][ $pseudo_selector ] = $styles_non_top_level;
1475 + }
1476 + }
1477 +
1478 + foreach ( $variation_pseudo_selectors as $pseudo_selector ) {
1479 + $schema['styles'][ $pseudo_selector ] = $styles_non_top_level;
1480 + }
1481 + }
1482 +
1410 1483 // Remove anything that's not present in the schema.
1411 1484 foreach ( array( 'styles', 'settings' ) as $subtree ) {
1412 1485 if ( ! isset( $input[ $subtree ] ) ) {
1413 1486 continue;
@@ -2110,9 +2183,9 @@
2110 2183 /**
2111 2184 * Returns the global styles custom CSS for a single block.
2112 2185 * This function is deprecated; please do not sync to core.
2113 2186 *
2114 - * @param array $css The block css node.
2187 + * @param array $css The block css node.
2115 2188 * @param string $selector The block selector.
2116 2189 *
2117 2190 * @return string The global styles custom CSS for the block.
2118 2191 */
@@ -3004,15 +3077,15 @@
3004 3077 * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set.
3005 3078 * @since 6.6.0 Passing current theme JSON settings to wp_get_typography_font_size_value(). Using style engine to correctly fetch background CSS values.
3006 3079 * @since 6.7.0 Allow ref resolution of background properties.
3007 3080 *
3008 - * @param array $styles Styles to process.
3009 - * @param array $settings Theme settings.
3010 - * @param array $properties Properties metadata.
3011 - * @param array $theme_json Theme JSON array.
3012 - * @param string $selector The style block selector.
3081 + * @param array $styles Styles to process.
3082 + * @param array $settings Theme settings.
3083 + * @param array $properties Properties metadata.
3084 + * @param array $theme_json Theme JSON array.
3085 + * @param string $selector The style block selector.
3013 3086 * @param boolean $use_root_padding Whether to add custom properties at root level.
3014 - * @return array Returns the modified $declarations.
3087 + * @return array Returns the modified $declarations.
3015 3088 */
3016 3089 protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) {
3017 3090 if ( empty( $styles ) ) {
3018 3091 return array();
@@ -3136,10 +3209,10 @@
3136 3209 * @since 5.9.0 Added support for values of array type, which are returned as is.
3137 3210 * @since 6.1.0 Added the `$theme_json` parameter.
3138 3211 * @since 6.7.0 Added support for background image refs
3139 3212 *
3140 - * @param array $styles Styles subtree.
3141 - * @param array $path Which property to process.
3213 + * @param array $styles Styles subtree.
3214 + * @param array $path Which property to process.
3142 3215 * @param array $theme_json Theme JSON array.
3143 3216 * @return string|array Style property value.
3144 3217 */
3145 3218 protected static function get_property_value( $styles, $path, $theme_json = null ) {
@@ -3511,9 +3584,9 @@
3511 3584 * @since 6.1.0
3512 3585 *
3513 3586 * @param array $theme_json The theme.json converted to an array.
3514 3587 * @param array $selectors Optional list of selectors per block.
3515 - * @param array $options {
3588 + * @param array $options {
3516 3589 * Optional. An array of options for now used for internal purposes only (may change without notice).
3517 3590 *
3518 3591 * @type bool $include_block_style_variations Includes nodes for block style variations. Default false.
3519 3592 * @type bool $include_node_paths_only Return only block nodes node paths. Default false.
@@ -3878,10 +3951,20 @@
3878 3951 // Store variation metadata and node for layout styles generation.
3879 3952 // Only store if the variation has blockGap defined.
3880 3953 if ( isset( $style_variation_node['spacing']['blockGap'] ) ) {
3881 3954 // Append block selector to the variation selector for proper targeting.
3882 - $variation_metadata_with_selector = $style_variation;
3883 - $variation_metadata_with_selector['selector'] = $style_variation['selector'] . $block_metadata['css'];
3955 + $variation_metadata_with_selector = $style_variation;
3956 + $variation_metadata_with_selector['selector'] = $style_variation['selector'] . $block_metadata['css'];
3957 +
3958 + /*
3959 + * `get_layout_styles()` reads `name` as a block name, to check that the block
3960 + * supports layout at all. A variation node's `name` is the variation slug,
3961 + * which is never a registered block, so the check fails and every variation
3962 + * gap rule is discarded. Pass the block the variation belongs to, so the
3963 + * support check answers the question it is actually asking.
3964 + */
3965 + $variation_metadata_with_selector['name'] = $block_name;
3966 +
3884 3967 $style_variation_layout_metadata[ $style_variation['selector'] ] = array(
3885 3968 'metadata' => $variation_metadata_with_selector,
3886 3969 'node' => $style_variation_node,
3887 3970 );
@@ -3935,9 +4018,13 @@
3935 4018 // Process blockGap responsive layout styles for this variation.
3936 4019 if ( isset( $breakpoint_node['spacing']['blockGap'] ) ) {
3937 4020 $variation_layout_metadata = $style_variation;
3938 4021 $variation_layout_metadata['selector'] = $style_variation['selector'] . $block_metadata['css'];
3939 - $variation_responsive_css .= $this->get_layout_styles(
4022 +
4023 + // The variation slug is not a block name here either. See above.
4024 + $variation_layout_metadata['name'] = $block_name;
4025 +
4026 + $variation_responsive_css .= $this->get_layout_styles(
3940 4027 $variation_layout_metadata,
3941 4028 array(
3942 4029 'node' => $breakpoint_node,
3943 4030 'media_query' => $breakpoint_media,
@@ -4600,9 +4687,9 @@
4600 4687 * Gets a `default`'s preset name by a provided slug.
4601 4688 *
4602 4689 * @since 5.9.0
4603 4690 *
4604 - * @param string $slug The slug we want to find a match from default presets.
4691 + * @param string $slug The slug we want to find a match from default presets.
4605 4692 * @param array $base_path The path to inspect. It's 'settings' by default.
4606 4693 * @return string|null
4607 4694 */
4608 4695 protected function get_name_from_defaults( $slug, $base_path ) {
@@ -4650,10 +4737,10 @@
4650 4737 * @since 5.9.0
4651 4738 * @since 6.6.0 Added support for block style variation element styles and $origin parameter.
4652 4739 *
4653 4740 * @param array $theme_json Structure to sanitize.
4654 - * @param string $origin Optional. What source of data this object represents.
4655 - * One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
4741 + * @param string $origin Optional. What source of data this object represents.
4742 + * One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
4656 4743 * @return array Sanitized structure.
4657 4744 */
4658 4745 public static function remove_insecure_properties( $theme_json, $origin = 'theme' ) {
4659 4746 if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) {
@@ -5740,9 +5827,9 @@
5740 5827 * Given a tree, converts the internal representation of variables to the CSS representation.
5741 5828 * It is recursive and modifies the input in-place.
5742 5829 *
5743 5830 * @since 6.3.0
5744 - * @param array $tree Input to process.
5831 + * @param array $tree Input to process.
5745 5832 * @return array The modified $tree.
5746 5833 */
5747 5834 private static function resolve_custom_css_format( $tree ) {
5748 5835 $prefix = 'var:';
@@ -5890,9 +5977,9 @@
5890 5977 * the variation class directly to the selector that will receive the
5891 5978 * declarations instead of deriving it by subtracting the root selector from
5892 5979 * the feature selector.
5893 5980 *
5894 - * @param array $style_variation Style variation metadata.
5981 + * @param array $style_variation Style variation metadata.
5895 5982 * @param string $feature_selector CSS selector for the feature.
5896 5983 * @return string Feature selector with block style variation selector added.
5897 5984 */
5898 5985 protected static function get_block_style_variation_feature_selector( $style_variation, $feature_selector ) {