- Timestamp:
- 07/14/2026 05:06:03 AM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php
r61516 r62720 28 28 29 29 /** 30 * CSS declaration options keyed by property name. 31 * 32 * @since 7.1.0 33 * 34 * @var array 35 */ 36 protected $declaration_options = array(); 37 38 /** 30 39 * Constructor for this object. 31 40 * … … 47 56 * 48 57 * @since 6.1.0 58 * @since 7.1.0 Added the `$options` parameter. 49 59 * 50 60 * @param string $property The CSS property. 51 61 * @param string $value The CSS value. 52 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods. 53 */ 54 public function add_declaration( $property, $value ) { 62 * @param array $options { 63 * Optional. An array of options. Default empty array. 64 * 65 * @type bool $important Whether to output the declaration with !important. Default false. 66 * } 67 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods. 68 */ 69 public function add_declaration( $property, $value, $options = array() ) { 55 70 // Sanitizes the property. 56 71 $property = $this->sanitize_property( $property ); … … 71 86 } 72 87 88 $options = wp_parse_args( 89 $options, 90 array( 91 'important' => false, 92 ) 93 ); 94 $options = array_filter( $options ); 95 73 96 // Adds the declaration property/value pair. 74 97 $this->declarations[ $property ] = $value; 98 if ( $options ) { 99 $this->declaration_options[ $property ] = $options; 100 } else { 101 unset( $this->declaration_options[ $property ] ); 102 } 75 103 76 104 return $this; … … 87 115 public function remove_declaration( $property ) { 88 116 unset( $this->declarations[ $property ] ); 117 unset( $this->declaration_options[ $property ] ); 89 118 return $this; 90 119 } … … 132 161 133 162 /** 163 * Gets declaration options keyed by property name. 164 * 165 * @since 7.1.0 166 * 167 * @return array Declaration options keyed by property name. 168 */ 169 public function get_declaration_options() { 170 return $this->declaration_options; 171 } 172 173 /** 134 174 * Filters a CSS property + value pair. 135 175 * 136 176 * @since 6.1.0 177 * @since 7.1.0 Added the `$options` parameter. 137 178 * 138 179 * @param string $property The CSS property. … … 140 181 * @param string $spacer Optional. The spacer between the colon and the value. 141 182 * Default empty string. 183 * @param array $options { 184 * Optional. An array of options. Default empty array. 185 * 186 * @type bool $important Whether to output the declaration with !important. Default false. 187 * } 142 188 * @return string The filtered declaration or an empty string. 143 189 */ 144 protected static function filter_declaration( $property, $value, $spacer = '' ) {190 protected static function filter_declaration( $property, $value, $spacer = '', $options = array() ) { 145 191 $filtered_value = wp_strip_all_tags( $value, true ); 146 192 if ( '' !== $filtered_value ) { 147 return safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" ); 193 $options = wp_parse_args( 194 $options, 195 array( 196 'important' => false, 197 ) 198 ); 199 200 $filtered_declaration = safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" ); 201 202 // Only append !important in the presence of an option value and when sanitization returns a single declaration. 203 if ( true === $options['important'] && '' !== $filtered_declaration && ! str_contains( $filtered_declaration, ';' ) ) { 204 return "$filtered_declaration !important"; 205 } 206 207 return $filtered_declaration; 148 208 } 149 209 return ''; … … 170 230 171 231 foreach ( $declarations_array as $property => $value ) { 172 $filtered_declaration = static::filter_declaration( $property, $value, $spacer );232 $filtered_declaration = static::filter_declaration( $property, $value, $spacer, $this->declaration_options[ $property ] ?? array() ); 173 233 if ( $filtered_declaration ) { 174 234 $declarations_output .= "{$indent}{$filtered_declaration};$suffix";
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)