| @@ -62,9 +62,9 @@ | ||
| 62 | 62 | ] |
| 63 | 63 | ]; |
| 64 | 64 | } |
| 65 | 65 | public static function get_css( $attribute_value, $property = '', $device = '' ) { |
| 66 | - $attribute_value = wp_parse_args( $attribute_value, self::get_attribute_default_value( (bool) $device ) ); | |
| 66 | + $attribute_value = wp_parse_args( $attribute_value, $device ? self::responsive_defaults() : self::get_attribute_default_value( false ) ); | |
| 67 | 67 | $css = []; |
| 68 | 68 | $unit = self::get_unit( $attribute_value, $device ); |
| 69 | 69 | |
| 70 | 70 | if ( (bool) $attribute_value[ 'isLinked' . $device ] ) { |
| @@ -71,19 +71,27 @@ | ||
| 71 | 71 | if ( '' !== $attribute_value[ 'common' . $device ] ) { |
| 72 | 72 | $css[ $property ] = $attribute_value[ 'common' . $device ] . $unit; |
| 73 | 73 | } |
| 74 | 74 | } else { |
| 75 | - if ( '' !== $attribute_value[ 'top' . $device ] ) { | |
| 76 | - $css[ $property . '-top' ] = $attribute_value[ 'top' . $device ] . $unit; | |
| 77 | - } | |
| 78 | - if ( '' !== $attribute_value[ 'right' . $device ] ) { | |
| 79 | - $css[ $property . '-right' ] = $attribute_value[ 'right' . $device ] . $unit; | |
| 80 | - } | |
| 81 | - if ( '' !== $attribute_value[ 'bottom' . $device ] ) { | |
| 82 | - $css[ $property . '-bottom' ] = $attribute_value[ 'bottom' . $device ] . $unit; | |
| 83 | - } | |
| 84 | - if ( '' !== $attribute_value[ 'left' . $device ] ) { | |
| 85 | - $css[ $property . '-left' ] = $attribute_value[ 'left' . $device ] . $unit; | |
| 75 | + /* | |
| 76 | + * A side may carry its own unit (`topUnit`, `rightUnit`, …), so an | |
| 77 | + * author can mix e.g. `padding-top: 2rem` with `padding-left: 10px`. | |
| 78 | + * Purely additive: a side that has never been given one falls back to | |
| 79 | + * the group unit, so anything saved before this compiles | |
| 80 | + * byte-for-byte as it did. | |
| 81 | + */ | |
| 82 | + foreach ( [ 'top', 'right', 'bottom', 'left' ] as $side ) { | |
| 83 | + if ( '' === $attribute_value[ $side . $device ] ) { | |
| 84 | + continue; | |
| 85 | + } | |
| 86 | + $side_unit = self::device_member( $attribute_value, $side . 'Unit', $device ); | |
| 87 | + if ( '' === $side_unit ) { | |
| 88 | + $side_unit = self::device_member( $attribute_value, $side . 'Unit' ); | |
| 89 | + } | |
| 90 | + if ( '' === $side_unit ) { | |
| 91 | + $side_unit = $unit; | |
| 92 | + } | |
| 93 | + $css[ $property . '-' . $side ] = $attribute_value[ $side . $device ] . $side_unit; | |
| 86 | 94 | } |
| 87 | 95 | } |
| 88 | 96 | return $css; |
| 89 | 97 | } |