WP_Style_Engine_CSS_Declarations::filter_declaration │ protected static │ WP 6.1.0

Filters a CSS property + value pair.

Метод класса: WP_Style_Engine_CSS_Declarations{}

Хуков нет.

Возвращает

string. The filtered declaration or an empty string.

Использование

$result = WP_Style_Engine_CSS_Declarations::filter_declaration( $property, $value, $spacer, $options );
$property(строка) (обязательный)
The CSS property.
$value(строка) (обязательный)
The value to be filtered.
$spacer(строка)
The spacer between the colon and the value.
По умолчанию: empty string
$options(массив)

An array of options.

По умолчанию: empty array

  • important(true|false)
    Whether to output the declaration with !important.
    По умолчанию: false

Список изменений

С версии 6.1.0 Введена.
С версии 7.1.0 Added the $options parameter.

Код WP_Style_Engine_CSS_Declarations::filter_declaration() WP 7.1.2

protected static function filter_declaration( $property, $value, $spacer = '', $options = array() ) {
	$filtered_value = wp_strip_all_tags( $value, true );
	if ( '' !== $filtered_value ) {
		$options = wp_parse_args(
			$options,
			array(
				'important' => false,
			)
		);

		$filtered_declaration = safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" );

		// Only append !important in the presence of an option value and when sanitization returns a single declaration.
		if ( true === $options['important'] && '' !== $filtered_declaration && ! str_contains( $filtered_declaration, ';' ) ) {
			return "$filtered_declaration !important";
		}

		return $filtered_declaration;
	}
	return '';
}