WP_Theme_JSON::to_ruleset() WordPress Method

The WP_Theme_JSON::to_ruleset() method is used to convert a theme JSON file into a set of theme rules. These theme rules can be used to determine whether a theme is valid or not, and to automatically generate a theme.

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

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


Parameters

$selector

(string)(Required)CSS selector.

$declarations

(array)(Required)List of declarations.


Top ↑

Return

(string) CSS ruleset.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

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

		$declaration_block = array_reduce(
			$declarations,
			static function ( $carry, $element ) {
				return $carry .= $element['name'] . ': ' . $element['value'] . ';'; },
			''
		);

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

Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.