Skip to content

Commit

Permalink
Add declarations to return value docs (#42453)
Browse files Browse the repository at this point in the history
Rename $style_rules to $css_declarations
Change self to static for future classes that may extend this one
  • Loading branch information
ramonjd authored Jul 15, 2022
1 parent 2ee09f0 commit 5a20ef3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ class WP_Style_Engine {
* @return WP_Style_Engine The main instance.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
if ( null === static::$instance ) {
static::$instance = new static();
}

return self::$instance;
return static::$instance;
}

/**
Expand Down Expand Up @@ -423,17 +423,17 @@ public function get_block_supports_styles( $block_styles, $options ) {
}

// Build CSS rules output.
$css_selector = isset( $options['selector'] ) ? $options['selector'] : null;
$style_rules = new WP_Style_Engine_CSS_Declarations( $css_declarations );
$css_selector = isset( $options['selector'] ) ? $options['selector'] : null;
$css_declarations = new WP_Style_Engine_CSS_Declarations( $css_declarations );

// The return object.
$styles_output = array();
$css = $style_rules->get_declarations_string();
$css = $css_declarations->get_declarations_string();

// Return css, if any.
if ( ! empty( $css ) ) {
$styles_output['css'] = $css;
$styles_output['declarations'] = $style_rules->get_declarations();
$styles_output['declarations'] = $css_declarations->get_declarations();
// Return an entire rule if there is a selector.
if ( $css_selector ) {
$styles_output['css'] = $css_selector . ' { ' . $css . ' }';
Expand Down Expand Up @@ -503,16 +503,17 @@ protected static function get_individual_property_css_declarations( $style_value
* Example usage:
*
* $styles = wp_style_engine_get_block_supports_styles( array( 'color' => array( 'text' => '#cccccc' ) ) );
* // Returns `array( 'css' => 'color: #cccccc', 'classnames' => 'has-color' )`.
* // Returns `array( 'css' => 'color: #cccccc', 'declarations' => array( 'color' => '#cccccc' ), 'classnames' => 'has-color' )`.
*
* @access public
*
* @param array $block_styles The value of a block's attributes.style.
* @param array<string> $options An array of options to determine the output.
*
* @return array<string>|null array(
* 'styles' => (string) A CSS ruleset formatted to be placed in an HTML `style` attribute or tag.
* 'classnames' => (string) Classnames separated by a space.
* 'styles' => (string) A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
* 'declarations' => (array) An array of property/value pairs representing parsed CSS declarations.
* 'classnames' => (string) Classnames separated by a space.
* );
*/
function wp_style_engine_get_block_supports_styles( $block_styles, $options = array() ) {
Expand Down

0 comments on commit 5a20ef3

Please sign in to comment.