On this page
WP_Style_Engine_Processor::get_css( array $options = array() ): string
Gets the CSS rules as a string.
Parameters
$optionsarray Optional-
An array of options.
optimizeboolWhether to optimize the CSS output, e.g., combine rules. Default isfalse.prettifyboolWhether to add new lines and indents to output. Default is the test of whether the global constantSCRIPT_DEBUGis defined.
Default:
array()
Return
string The computed CSS.
Source
File: wp-includes/style-engine/class-wp-style-engine-processor.php. View all references
public function get_css( $options = array() ) {
$defaults = array(
'optimize' => true,
'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;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Style_Engine_Processor::combine_rules_selectors() wp-includes/style-engine/class-wp-style-engine-processor.php | Combines selectors from the rules store when they have the same styles. |
| WP_Style_Engine_Processor::add_rules() wp-includes/style-engine/class-wp-style-engine-processor.php | Adds rules to be processed. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_style_engine_processor/get_css