Skip to content

Commit 57d81bc

Browse files
committed
Grammar, formatting, removing class_exists checks
1 parent 26cd739 commit 57d81bc

11 files changed

+163
-107
lines changed

src/wp-includes/style-engine.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@
3737
* }
3838
*
3939
* @return array {
40-
* @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
41-
* @type array<string, string> $declarations An array of property/value pairs representing parsed CSS declarations.
42-
* @type string $classnames Classnames separated by a space.
40+
* @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
41+
* @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
42+
* @type string $classnames Classnames separated by a space.
4343
* }
4444
*/
4545
function wp_style_engine_get_styles( $block_styles, $options = array() ) {
46-
if ( ! class_exists( 'WP_Style_Engine' ) ) {
47-
return array();
48-
}
49-
5046
$options = wp_parse_args(
5147
$options,
5248
array(
@@ -85,15 +81,14 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
8581
* $css = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
8682
* // Returns `.elephant-are-cool{color:gray;width:3em}`.
8783
*
88-
* @access public
8984
* @since 6.1.0
9085
*
9186
* @param array $css_rules {
9287
* Required. A collection of CSS rules.
9388
*
9489
* @type array ...$0 {
95-
* @type string $selector A CSS selector.
96-
* @type array<string, string> $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
90+
* @type string $selector A CSS selector.
91+
* @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
9792
* }
9893
* }
9994
* @param array $options {
@@ -105,10 +100,10 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
105100
* @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
106101
* }
107102
*
108-
* @return string A compiled CSS string.
103+
* @return string A string of compiled CSS declarations, or empty string.
109104
*/
110105
function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = array() ) {
111-
if ( ! class_exists( 'WP_Style_Engine' ) || empty( $css_rules ) ) {
106+
if ( empty( $css_rules ) ) {
112107
return '';
113108
}
114109

@@ -142,7 +137,6 @@ function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = a
142137
/**
143138
* Returns compiled CSS from a store, if found.
144139
*
145-
* @access public
146140
* @since 6.1.0
147141
*
148142
* @param string $context A valid context name, corresponding to an existing store key.
@@ -156,9 +150,5 @@ function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = a
156150
* @return string A compiled CSS string.
157151
*/
158152
function wp_style_engine_get_stylesheet_from_context( $context, $options = array() ) {
159-
if ( ! class_exists( 'WP_Style_Engine' ) || empty( $context ) ) {
160-
return '';
161-
}
162-
163153
return WP_Style_Engine::compile_stylesheet_from_css_rules( WP_Style_Engine::get_store( $context )->get_all_rules(), $options );
164154
}

src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class WP_Style_Engine_CSS_Declarations {
3636
*
3737
* @since 6.1.0
3838
*
39-
* @param array $declarations An array of declarations (property => value pairs).
39+
* @param string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
4040
*/
4141
public function __construct( $declarations = array() ) {
4242
$this->add_declarations( $declarations );
4343
}
4444

4545
/**
46-
* Add a single declaration.
46+
* Adds a single declaration.
4747
*
4848
* @since 6.1.0
4949
*
@@ -53,28 +53,27 @@ public function __construct( $declarations = array() ) {
5353
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
5454
*/
5555
public function add_declaration( $property, $value ) {
56-
57-
// Sanitize the property.
56+
// Sanitizes the property.
5857
$property = $this->sanitize_property( $property );
59-
// Bail early if the property is empty.
58+
// Bails early if the property is empty.
6059
if ( empty( $property ) ) {
6160
return $this;
6261
}
6362

64-
// Trim the value. If empty, bail early.
63+
// Trims the value. If empty, bail early.
6564
$value = trim( $value );
6665
if ( '' === $value ) {
6766
return $this;
6867
}
6968

70-
// Add the declaration property/value pair.
69+
// Adds the declaration property/value pair.
7170
$this->declarations[ $property ] = $value;
7271

7372
return $this;
7473
}
7574

7675
/**
77-
* Remove a single declaration.
76+
* Removes a single declaration.
7877
*
7978
* @since 6.1.0
8079
*
@@ -88,7 +87,7 @@ public function remove_declaration( $property ) {
8887
}
8988

9089
/**
91-
* Add multiple declarations.
90+
* Adds multiple declarations.
9291
*
9392
* @since 6.1.0
9493
*
@@ -104,7 +103,7 @@ public function add_declarations( $declarations ) {
104103
}
105104

106105
/**
107-
* Remove multiple declarations.
106+
* Removes multiple declarations.
108107
*
109108
* @since 6.1.0
110109
*
@@ -120,7 +119,7 @@ public function remove_declarations( $properties = array() ) {
120119
}
121120

122121
/**
123-
* Get the declarations array.
122+
* Gets the declarations array.
124123
*
125124
* @since 6.1.0
126125
*
@@ -139,7 +138,7 @@ public function get_declarations() {
139138
* @param string $value The value to be filtered.
140139
* @param string $spacer The spacer between the colon and the value. Defaults to an empty string.
141140
*
142-
* @return string The filtered declaration as a single string.
141+
* @return string The filtered declaration or an empty string.
143142
*/
144143
protected static function filter_declaration( $property, $value, $spacer = '' ) {
145144
$filtered_value = wp_strip_all_tags( $value, true );
@@ -177,7 +176,7 @@ public function get_declarations_string( $should_prettify = false, $indent_count
177176
}
178177

179178
/**
180-
* Sanitize property names.
179+
* Sanitizes property names.
181180
*
182181
* @since 6.1.0
183182
*

src/wp-includes/style-engine/class-wp-style-engine-css-rule.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ class WP_Style_Engine_CSS_Rule {
4242
*
4343
* @since 6.1.0
4444
*
45-
* @param string $selector The CSS selector.
46-
* @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs),
47-
* or a WP_Style_Engine_CSS_Declarations object.
45+
* @param string $selector The CSS selector.
46+
* @param string[]|WP_Style_Engine_CSS_Declarations $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ),
47+
* or a WP_Style_Engine_CSS_Declarations object.
4848
*/
4949
public function __construct( $selector = '', $declarations = array() ) {
5050
$this->set_selector( $selector );
5151
$this->add_declarations( $declarations );
5252
}
5353

5454
/**
55-
* Set the selector.
55+
* Sets the selector.
5656
*
5757
* @since 6.1.0
5858
*
@@ -66,7 +66,7 @@ public function set_selector( $selector ) {
6666
}
6767

6868
/**
69-
* Set the declarations.
69+
* Sets the declarations.
7070
*
7171
* @since 6.1.0
7272
*
@@ -92,18 +92,18 @@ public function add_declarations( $declarations ) {
9292
}
9393

9494
/**
95-
* Get the declarations object.
95+
* Gets the declarations object.
9696
*
9797
* @since 6.1.0
9898
*
99-
* @return WP_Style_Engine_CSS_Declarations
99+
* @return WP_Style_Engine_CSS_Declarations The declarations object.
100100
*/
101101
public function get_declarations() {
102102
return $this->declarations;
103103
}
104104

105105
/**
106-
* Get the full selector.
106+
* Gets the full selector.
107107
*
108108
* @since 6.1.0
109109
*
@@ -114,7 +114,7 @@ public function get_selector() {
114114
}
115115

116116
/**
117-
* Get the CSS.
117+
* Gets the CSS.
118118
*
119119
* @since 6.1.0
120120
*
@@ -126,15 +126,15 @@ public function get_selector() {
126126
public function get_css( $should_prettify = false, $indent_count = 0 ) {
127127
$rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
128128
$declarations_indent = $should_prettify ? $indent_count + 1 : 0;
129-
$new_line = $should_prettify ? "\n" : '';
130-
$space = $should_prettify ? ' ' : '';
129+
$suffix = $should_prettify ? "\n" : '';
130+
$spacer = $should_prettify ? ' ' : '';
131131
$selector = $should_prettify ? str_replace( ',', ",\n", $this->get_selector() ) : $this->get_selector();
132132
$css_declarations = $this->declarations->get_declarations_string( $should_prettify, $declarations_indent );
133133

134134
if ( empty( $css_declarations ) ) {
135135
return '';
136136
}
137137

138-
return "{$rule_indent}{$selector}{$space}{{$new_line}{$css_declarations}{$new_line}{$rule_indent}}";
138+
return "{$rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$rule_indent}}";
139139
}
140140
}

src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class WP_Style_Engine_CSS_Rules_Store {
4646
protected $rules = array();
4747

4848
/**
49-
* Get an instance of the store.
49+
* Gets an instance of the store.
5050
*
5151
* @since 6.1.0
5252
*
@@ -67,7 +67,7 @@ public static function get_store( $store_name = 'default' ) {
6767
}
6868

6969
/**
70-
* Get an array of all available stores.
70+
* Gets an array of all available stores.
7171
*
7272
* @since 6.1.0
7373
*
@@ -89,7 +89,7 @@ public static function remove_all_stores() {
8989
}
9090

9191
/**
92-
* Set the store name.
92+
* Sets the store name.
9393
*
9494
* @since 6.1.0
9595
*
@@ -102,7 +102,7 @@ public function set_name( $name ) {
102102
}
103103

104104
/**
105-
* Get the store name.
105+
* Gets the store name.
106106
*
107107
* @since 6.1.0
108108
*
@@ -113,7 +113,7 @@ public function get_name() {
113113
}
114114

115115
/**
116-
* Get an array of all rules.
116+
* Gets an array of all rules.
117117
*
118118
* @since 6.1.0
119119
*
@@ -124,7 +124,7 @@ public function get_all_rules() {
124124
}
125125

126126
/**
127-
* Get a WP_Style_Engine_CSS_Rule object by its selector.
127+
* Gets a WP_Style_Engine_CSS_Rule object by its selector.
128128
* If the rule does not exist, it will be created.
129129
*
130130
* @since 6.1.0
@@ -150,7 +150,7 @@ public function add_rule( $selector ) {
150150
}
151151

152152
/**
153-
* Remove a selector from the store.
153+
* Removes a selector from the store.
154154
*
155155
* @since 6.1.0
156156
*

src/wp-includes/style-engine/class-wp-style-engine-processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function add_store( $store ) {
6262
/**
6363
* Adds rules to be processed.
6464
*
65-
* @since 6.1.0 a store to t
65+
* @since 6.1.0
6666
*
6767
* @param WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules A single, or an array of, WP_Style_Engine_CSS_Rule objects from a store or otherwise.
6868
*

0 commit comments

Comments
 (0)