WP_Theme_JSON::to_ruleset( string $selector, array $declarations ): string

In this article

Given a selector and a declaration list, creates the corresponding ruleset.

Parameters

$selectorstringrequired
CSS selector.
$declarationsarrayrequired
List of declarations.

Return

string The resulting CSS ruleset.

Source

protected static function to_ruleset( $selector, $declarations ) {
	if ( empty( $declarations ) ) {
		return '';
	}

	$declaration_block = array_reduce(
		$declarations,
		static function ( $carry, $element ) {
			$value = $element['value'];

			if ( is_numeric( $value ) ) {
				$value = (string) $value;
			}

			if ( ! is_string( $value ) ) {
				return $carry;
			}

			return $carry .= $element['name'] . ': ' . $value . ';';
		},
		''
	);

	return $selector . '{' . $declaration_block . '}';
}

Changelog

VersionDescription
7.1.0Skip declarations whose value is not a plain string (booleans, arrays, objects, etc.).
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.