WP_Style_Engine_Processor::get_css()publicWP 6.1.0

Gets the CSS rules as a string.

Method of the class: WP_Style_Engine_Processor{}

No Hooks.

Return

String. The computed CSS.

Usage

$WP_Style_Engine_Processor = new WP_Style_Engine_Processor();
$WP_Style_Engine_Processor->get_css( $options );
$options(array)

An array of options.

Default: empty array

  • optimize(true|false)
    Whether to optimize the CSS output, e.g. combine rules.
    Default: false

  • prettify(true|false)
    Whether to add new lines and indents to output.
    Default: whether the SCRIPT_DEBUG constant is defined

Changelog

Since 6.1.0 Introduced.
Since 6.4.0 The Optimization is no longer the default.

WP_Style_Engine_Processor::get_css() code WP 6.4.3

public function get_css( $options = array() ) {
	$defaults = array(
		'optimize' => false,
		'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
	);
	$options  = wp_parse_args( $options, $defaults );

	// If we have stores, get the rules from them.
	foreach ( $this->stores as $store ) {
		$this->add_rules( $store->get_all_rules() );
	}

	// Combine CSS selectors that have identical declarations.
	if ( true === $options['optimize'] ) {
		$this->combine_rules_selectors();
	}

	// Build the CSS.
	$css = '';
	foreach ( $this->css_rules as $rule ) {
		$css .= $rule->get_css( $options['prettify'] );
		$css .= $options['prettify'] ? "\n" : '';
	}
	return $css;
}