W3cubDocs

/WordPress

WP_Style_Engine_CSS_Declarations::get_declarations_string( bool $should_prettify = false, int $indent_count ): string

Filters and compiles the CSS declarations.

Parameters

$should_prettifybooloptional
Whether to add spacing, new lines and indents.

Default:false

$indent_countintoptional
The number of tab indents to apply to the rule.
Applies if prettify is true. Default 0.

Return

string The CSS declarations.

Source

public function get_declarations_string( $should_prettify = false, $indent_count = 0 ) {
	$declarations_array  = $this->get_declarations();
	$declarations_output = '';
	$indent              = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
	$suffix              = $should_prettify ? ' ' : '';
	$suffix              = $should_prettify && $indent_count > 0 ? "\n" : $suffix;
	$spacer              = $should_prettify ? ' ' : '';

	foreach ( $declarations_array as $property => $value ) {
		$filtered_declaration = static::filter_declaration( $property, $value, $spacer );
		if ( $filtered_declaration ) {
			$declarations_output .= "{$indent}{$filtered_declaration};$suffix";
		}
	}

	return rtrim( $declarations_output );
}

Changelog

Version Description
6.1.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_style_engine_css_declarations/get_declarations_string