← All changes
|
build/scripts/style-engine/class-wp-style-engine-css-declarations-gutenberg.php
+6
-66
23.6.2
→
22.7.0
View file →
| @@ -22,15 +22,8 @@ | ||
| 22 | 22 | */ |
| 23 | 23 | protected $declarations = array(); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * CSS declaration options keyed by property name. | |
| 27 | - * | |
| 28 | - * @var array | |
| 29 | - */ | |
| 30 | - protected $declaration_options = array(); | |
| 31 | - | |
| 32 | - /** | |
| 33 | 26 | * Constructor for this object. |
| 34 | 27 | * |
| 35 | 28 | * If a `$declarations` array is passed, it will be used to populate |
| 36 | 29 | * the initial $declarations prop of the object by calling add_declarations(). |
| @@ -45,17 +38,12 @@ | ||
| 45 | 38 | * Adds a single declaration. |
| 46 | 39 | * |
| 47 | 40 | * @param string $property The CSS property. |
| 48 | 41 | * @param string $value The CSS value. |
| 49 | - * @param array $options { | |
| 50 | - * Optional. An array of options. Default empty array. | |
| 51 | 42 | * |
| 52 | - * @type bool $important Whether to output the declaration with !important. Default false. | |
| 53 | - * } | |
| 54 | - * | |
| 55 | 43 | * @return WP_Style_Engine_CSS_Declarations_Gutenberg Returns the object to allow chaining methods. |
| 56 | 44 | */ |
| 57 | - public function add_declaration( $property, $value, $options = array() ) { | |
| 45 | + public function add_declaration( $property, $value ) { | |
| 58 | 46 | // Sanitizes the property. |
| 59 | 47 | $property = $this->sanitize_property( $property ); |
| 60 | 48 | // Bails early if the property is empty. |
| 61 | 49 | if ( empty( $property ) ) { |
| @@ -70,24 +58,10 @@ | ||
| 70 | 58 | if ( '' === $value ) { |
| 71 | 59 | return $this; |
| 72 | 60 | } |
| 73 | 61 | |
| 74 | - $options = wp_parse_args( | |
| 75 | - $options, | |
| 76 | - array( | |
| 77 | - 'important' => false, | |
| 78 | - ) | |
| 79 | - ); | |
| 80 | - | |
| 81 | - $options = array_filter( $options ); | |
| 82 | - | |
| 83 | 62 | // Adds the declaration property/value pair. |
| 84 | 63 | $this->declarations[ $property ] = $value; |
| 85 | - if ( $options ) { | |
| 86 | - $this->declaration_options[ $property ] = $options; | |
| 87 | - } else { | |
| 88 | - unset( $this->declaration_options[ $property ] ); | |
| 89 | - } | |
| 90 | 64 | |
| 91 | 65 | return $this; |
| 92 | 66 | } |
| 93 | 67 | |
| @@ -99,9 +73,8 @@ | ||
| 99 | 73 | * @return WP_Style_Engine_CSS_Declarations_Gutenberg Returns the object to allow chaining methods. |
| 100 | 74 | */ |
| 101 | 75 | public function remove_declaration( $property ) { |
| 102 | 76 | unset( $this->declarations[ $property ] ); |
| 103 | - unset( $this->declaration_options[ $property ] ); | |
| 104 | 77 | return $this; |
| 105 | 78 | } |
| 106 | 79 | |
| 107 | 80 | /** |
| @@ -141,49 +114,21 @@ | ||
| 141 | 114 | return $this->declarations; |
| 142 | 115 | } |
| 143 | 116 | |
| 144 | 117 | /** |
| 145 | - * Gets declaration options keyed by property name. | |
| 146 | - * | |
| 147 | - * @return array | |
| 148 | - */ | |
| 149 | - public function get_declaration_options() { | |
| 150 | - return $this->declaration_options; | |
| 151 | - } | |
| 152 | - | |
| 153 | - /** | |
| 154 | 118 | * Filters a CSS property + value pair. |
| 155 | 119 | * |
| 156 | 120 | * @param string $property The CSS property. |
| 157 | 121 | * @param string $value The value to be filtered. |
| 158 | 122 | * @param string $spacer The spacer between the colon and the value. Defaults to an empty string. |
| 159 | - * @param array $options { | |
| 160 | - * Optional. An array of options. Default empty array. | |
| 161 | 123 | * |
| 162 | - * @type bool $important Whether to output the declaration with !important. Default false. | |
| 163 | - * } | |
| 164 | - * | |
| 165 | 124 | * @return string The filtered declaration or an empty string. |
| 166 | 125 | */ |
| 167 | - protected static function filter_declaration( $property, $value, $spacer = '', $options = array() ) { | |
| 126 | + protected static function filter_declaration( $property, $value, $spacer = '' ) { | |
| 168 | 127 | $filtered_value = wp_strip_all_tags( $value, true ); |
| 169 | 128 | |
| 170 | 129 | if ( '' !== $filtered_value ) { |
| 171 | - $options = wp_parse_args( | |
| 172 | - $options, | |
| 173 | - array( | |
| 174 | - 'important' => false, | |
| 175 | - ) | |
| 176 | - ); | |
| 177 | - | |
| 178 | - $filtered_declaration = safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" ); | |
| 179 | - | |
| 180 | - // Only append !important in the presence of an option value and when sanitization returns a single declaration. | |
| 181 | - if ( true === $options['important'] && '' !== $filtered_declaration && ! str_contains( $filtered_declaration, ';' ) ) { | |
| 182 | - return "$filtered_declaration !important"; | |
| 183 | - } | |
| 184 | - | |
| 185 | - return $filtered_declaration; | |
| 130 | + return safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" ); | |
| 186 | 131 | } |
| 187 | 132 | return ''; |
| 188 | 133 | } |
| 189 | 134 | |
| @@ -189,10 +134,10 @@ | ||
| 189 | 134 | |
| 190 | 135 | /** |
| 191 | 136 | * Filters and compiles the CSS declarations. |
| 192 | 137 | * |
| 193 | - * @param bool $should_prettify Whether to add spacing, new lines and indents. | |
| 194 | - * @param int $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`. | |
| 138 | + * @param bool $should_prettify Whether to add spacing, new lines and indents. | |
| 139 | + * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`. | |
| 195 | 140 | * |
| 196 | 141 | * @return string The CSS declarations. |
| 197 | 142 | */ |
| 198 | 143 | public function get_declarations_string( $should_prettify = false, $indent_count = 0 ) { |
| @@ -203,14 +148,9 @@ | ||
| 203 | 148 | $suffix = $should_prettify && $indent_count > 0 ? "\n" : $suffix; |
| 204 | 149 | $spacer = $should_prettify ? ' ' : ''; |
| 205 | 150 | |
| 206 | 151 | foreach ( $declarations_array as $property => $value ) { |
| 207 | - $filtered_declaration = static::filter_declaration( | |
| 208 | - $property, | |
| 209 | - $value, | |
| 210 | - $spacer, | |
| 211 | - $this->declaration_options[ $property ] ?? array() | |
| 212 | - ); | |
| 152 | + $filtered_declaration = static::filter_declaration( $property, $value, $spacer ); | |
| 213 | 153 | if ( $filtered_declaration ) { |
| 214 | 154 | $declarations_output .= "{$indent}{$filtered_declaration};$suffix"; |
| 215 | 155 | } |
| 216 | 156 | } |