WP_Theme_JSON::to_ruleset
Given a selector and a declaration list, creates the corresponding ruleset.
Метод класса: WP_Theme_JSON{}
Хуков нет.
Возвращает
string. The resulting CSS ruleset.
Использование
$result = WP_Theme_JSON::to_ruleset( $selector, $declarations );
- $selector(строка) (обязательный)
- CSS selector.
- $declarations(массив) (обязательный)
- List of declarations.
Список изменений
| С версии 5.8.0 | Введена. |
| С версии 7.1.0 | Skip declarations whose value is not a plain string (booleans, arrays, objects, etc.). |
Код WP_Theme_JSON::to_ruleset() WP Theme JSON::to ruleset WP 7.1.1
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 . '}';
}