wp/wp-includes/block-supports/spacing.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/block-supports/spacing.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/block-supports/spacing.php	Tue Sep 27 16:37:53 2022 +0200
@@ -1,6 +1,9 @@
 <?php
 /**
  * Spacing block support flag.
+
+ * For backwards compatibility, this remains separate to the dimensions.php
+ * block support despite both belonging under a single panel in the editor.
  *
  * @package WordPress
  * @since 5.8.0
@@ -38,53 +41,44 @@
  *
  * @param WP_Block_Type $block_type       Block Type.
  * @param array         $block_attributes Block attributes.
- *
  * @return array Block spacing CSS classes and inline styles.
  */
 function wp_apply_spacing_support( $block_type, $block_attributes ) {
-	$has_padding_support = wp_has_spacing_feature_support( $block_type, 'padding' );
-	$has_margin_support  = wp_has_spacing_feature_support( $block_type, 'margin' );
+	if ( wp_should_skip_block_supports_serialization( $block_type, 'spacing' ) ) {
+		return array();
+	}
+
+	$has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
+	$has_margin_support  = block_has_support( $block_type, array( 'spacing', 'margin' ), false );
+	$skip_padding        = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
+	$skip_margin         = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
 	$styles              = array();
 
-	if ( $has_padding_support ) {
+	if ( $has_padding_support && ! $skip_padding ) {
 		$padding_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'padding' ), null );
-		if ( null !== $padding_value ) {
+		if ( is_array( $padding_value ) ) {
 			foreach ( $padding_value as $key => $value ) {
 				$styles[] = sprintf( 'padding-%s: %s;', $key, $value );
 			}
+		} elseif ( null !== $padding_value ) {
+			$styles[] = sprintf( 'padding: %s;', $padding_value );
 		}
 	}
 
-	if ( $has_margin_support ) {
+	if ( $has_margin_support && ! $skip_margin ) {
 		$margin_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'margin' ), null );
-		if ( null !== $margin_value ) {
+		if ( is_array( $margin_value ) ) {
 			foreach ( $margin_value as $key => $value ) {
 				$styles[] = sprintf( 'margin-%s: %s;', $key, $value );
 			}
+		} elseif ( null !== $margin_value ) {
+			$styles[] = sprintf( 'margin: %s;', $margin_value );
 		}
 	}
 
 	return empty( $styles ) ? array() : array( 'style' => implode( ' ', $styles ) );
 }
 
-/**
- * Checks whether the current block type supports the spacing feature requested.
- *
- * @since 5.8.0
- * @access private
- *
- * @param WP_Block_Type $block_type Block type to check for support.
- * @param string        $feature    Name of the feature to check support for.
- * @param mixed         $default    Fallback value for feature support, defaults to false.
- *
- * @return boolean                  Whether or not the feature is supported.
- */
-function wp_has_spacing_feature_support( $block_type, $feature, $default = false ) {
-	// Check if the specific feature has been opted into individually
-	// via nested flag under `spacing`.
-	return block_has_support( $block_type, array( 'spacing', $feature ), $default );
-}
-
 // Register the block support.
 WP_Block_Supports::get_instance()->register(
 	'spacing',