Skip to content

Commit 3ebd5d1

Browse files
Block Supports: Return early for non-array attributes in the background helper.
1 parent 3475ef6 commit 3ebd5d1

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/wp-includes/block-supports/background.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ function wp_register_background_support( $block_type ) {
4545
* @return array Array with `class` and `style` keys, each present only when non-empty.
4646
*/
4747
function wp_get_background_classes_and_styles( $block_attributes ) {
48+
if ( ! is_array( $block_attributes ) ) {
49+
return array();
50+
}
51+
4852
$background = $block_attributes['style']['background'] ?? null;
4953

5054
if ( ! is_array( $background ) ) {

‎tests/phpunit/tests/block-supports/wpGetBackgroundClassesAndStyles.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ public function data_get_background_classes_and_styles() {
167167
'block_attributes' => 'style',
168168
'expected' => array(),
169169
),
170+
'attributes are an object' => array(
171+
'block_attributes' => (object) array( 'style' => array() ),
172+
'expected' => array(),
173+
),
170174
);
171175
}
172176
}

0 commit comments

Comments
 (0)