Changeset 64238 for trunk/src/wp-includes/block-supports/layout.php
- Timestamp:
- 10/07/2026 10:53:31 PM (24 hours ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-supports/layout.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/layout.php
r63887 r64238 81 81 * @since 7.1.0 82 82 * 83 * @param string|array|null $gap_value Block gap value. 84 * @return string|array|null Sanitized block gap value. 83 * Numeric zero is converted to a string because it is valid CSS without a unit. 84 * Other non-string values are rejected. 85 * 86 * @param mixed $gap_value Block gap value. 87 * @return string|string[]|null Sanitized block gap value. 85 88 */ 86 89 function wp_sanitize_block_gap_value( $gap_value ) { 87 90 if ( is_array( $gap_value ) ) { 88 91 foreach ( $gap_value as $key => $value ) { 89 $gap_value[ $key ] = ! is_scalar( $value ) || ( $value && preg_match( '%[\\\(&=}]|/\*%', (string) $value ) ) ? null : $value; 90 } 91 92 return $gap_value; 92 $sanitized_value = wp_sanitize_block_gap_value( $value ); 93 if ( ! is_string( $sanitized_value ) ) { 94 unset( $gap_value[ $key ] ); 95 continue; 96 } 97 $gap_value[ $key ] = $sanitized_value; 98 } 99 100 return empty( $gap_value ) ? null : $gap_value; 101 } 102 103 if ( ( is_int( $gap_value ) || is_float( $gap_value ) ) && 0.0 === (float) $gap_value ) { 104 return '0'; 105 } 106 107 if ( ! is_string( $gap_value ) ) { 108 return null; 109 } 110 111 if ( '' === trim( $gap_value ) ) { 112 return null; 93 113 } 94 114 … … 491 511 * @access private 492 512 * 493 * @param string $selector CSS selector. 494 * @param array $layout Layout object. The one that is passed has already checked 495 * the existence of default block layout. 496 * @param bool $has_block_gap_support Optional. Whether the theme has support for the block gap. Default false. 497 * @param string|string[]|null $gap_value Optional. The block gap value to apply. Default null. 498 * @param bool $should_skip_gap_serialization Optional. Whether to skip applying the user-defined value set in the editor. Default false. 499 * @param string|array $fallback_gap_value Optional. The block gap value to apply. If it's an array expected properties are "top" and/or "left". Default '0.5em'. 500 * @param array|null $block_spacing Optional. Custom spacing set on the block. Default null. 501 * @param array $options { 513 * @param string $selector CSS selector. 514 * @param array $layout Layout object. The one that is passed has already checked 515 * the existence of default block layout. 516 * @param bool $has_block_gap_support Optional. Whether the theme has support for the block gap. Default false. 517 * @param string|string[]|int|float|null $gap_value Optional. The block gap value to apply. Only zero is accepted as a 518 * numeric value. Default null. 519 * @param bool $should_skip_gap_serialization Optional. Whether to skip applying the user-defined value set in the 520 * editor. Default false. 521 * @param string|string[]|int|float|null $fallback_gap_value Optional. The fallback block gap value to apply. Only zero is accepted 522 * as a numeric value. Default '0.5em'. 523 * @param array|null $block_spacing Optional. Custom spacing set on the block. Default null. 524 * @param array $options { 502 525 * Optional. Extra options for internal callers. Default empty array. 503 526 * … … 510 533 */ 511 534 function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false, $fallback_gap_value = '0.5em', $block_spacing = null, $options = array() ) { 535 // Normalize here as well as at external data boundaries because this function has direct callers. 536 $gap_value = wp_sanitize_block_gap_value( $gap_value ); 537 $fallback_gap_value = wp_sanitize_block_gap_value( $fallback_gap_value ) ?? '0.5em'; 538 512 539 $base_layout = is_array( $layout ) ? $layout : array(); 513 540 $viewport_overrides = $options['viewport_overrides'] ?? null; … … 858 885 859 886 /* 860 * If the gap value is an array, we use the "left" value because it represents the vertical gap, which887 * If the gap value is an array, we use the "left" value because it represents the horizontal gap, which 861 888 * is the relevant one for computation of responsive grid columns. 862 889 */ … … 887 914 $process_value = "var(--wp--preset--spacing--$slug)"; 888 915 } 916 if ( ! is_array( $gap_value ) || 'left' === $gap_side ) { 917 $responsive_gap_value = $process_value; 918 } 889 919 $combined_gap_value .= "$process_value "; 890 920 } 891 $gap_value = trim( $combined_gap_value ); 892 $responsive_gap_value = $gap_value; 921 $gap_value = trim( $combined_gap_value ); 893 922 } 894 923 … … 1197 1226 1198 1227 $gap_value = wp_sanitize_block_gap_value( $style_attr['spacing']['blockGap'] ?? null ); 1199 $fallback_gap_value = $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? '0.5em'; 1228 $fallback_gap_value = wp_sanitize_block_gap_value( 1229 $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? null 1230 ) ?? '0.5em'; 1200 1231 $block_spacing = $style_attr['spacing'] ?? null; 1201 1232 … … 1231 1262 } 1232 1263 1233 $global_block_gap_value = $variation_block_gap_value ?? $global_styles['blocks'][ $block_name ]['spacing']['blockGap'] ?? $global_styles['spacing']['blockGap'] ?? null; 1264 $global_block_gap_candidates = array( 1265 $variation_block_gap_value, 1266 $global_styles['blocks'][ $block_name ]['spacing']['blockGap'] ?? null, 1267 $global_styles['spacing']['blockGap'] ?? null, 1268 ); 1269 $global_block_gap_value = null; 1270 foreach ( $global_block_gap_candidates as $candidate_gap_value ) { 1271 $candidate_gap_value = wp_sanitize_block_gap_value( $candidate_gap_value ); 1272 if ( null !== $candidate_gap_value ) { 1273 $global_block_gap_value = $candidate_gap_value; 1274 break; 1275 } 1276 } 1234 1277 1235 1278 if ( null !== $global_block_gap_value ) {
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)