Skip to content

Commit 6d4e2c5

Browse files
committed
Initial commit - bringing across changes from WordPress/gutenberg#61382
1 parent dfd1de0 commit 6d4e2c5

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ function wp_render_background_support( $block_content, $block ) {
6262
return $block_content;
6363
}
6464

65-
$background_styles = array();
66-
$background_styles['backgroundImage'] = $block_attributes['style']['background']['backgroundImage'] ?? null;
67-
$background_styles['backgroundSize'] = $block_attributes['style']['background']['backgroundSize'] ?? null;
68-
$background_styles['backgroundPosition'] = $block_attributes['style']['background']['backgroundPosition'] ?? null;
69-
$background_styles['backgroundRepeat'] = $block_attributes['style']['background']['backgroundRepeat'] ?? null;
65+
$background_styles = array();
66+
$background_styles['backgroundImage'] = $block_attributes['style']['background']['backgroundImage'] ?? null;
67+
$background_styles['backgroundSize'] = $block_attributes['style']['background']['backgroundSize'] ?? null;
68+
$background_styles['backgroundPosition'] = $block_attributes['style']['background']['backgroundPosition'] ?? null;
69+
$background_styles['backgroundRepeat'] = $block_attributes['style']['background']['backgroundRepeat'] ?? null;
70+
$background_styles['backgroundAttachment'] = $block_attributes['style']['background']['backgroundAttachment'] ?? null;
7071

7172
if ( ! empty( $background_styles['backgroundImage'] ) ) {
7273
$background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover';

src/wp-includes/class-wp-theme-json.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class WP_Theme_JSON {
237237
'background-position' => array( 'background', 'backgroundPosition' ),
238238
'background-repeat' => array( 'background', 'backgroundRepeat' ),
239239
'background-size' => array( 'background', 'backgroundSize' ),
240+
'background-attachment' => array( 'background', 'backgroundAttachment' ),
240241
'border-radius' => array( 'border', 'radius' ),
241242
'border-top-left-radius' => array( 'border', 'radius', 'topLeft' ),
242243
'border-top-right-radius' => array( 'border', 'radius', 'topRight' ),
@@ -520,10 +521,11 @@ class WP_Theme_JSON {
520521
*/
521522
const VALID_STYLES = array(
522523
'background' => array(
523-
'backgroundImage' => null,
524-
'backgroundPosition' => null,
525-
'backgroundRepeat' => null,
526-
'backgroundSize' => null,
524+
'backgroundImage' => null,
525+
'backgroundPosition' => null,
526+
'backgroundRepeat' => null,
527+
'backgroundSize' => null,
528+
'backgroundAttachment' => null,
527529
),
528530
'border' => array(
529531
'color' => null,

tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,21 @@ public function data_background_block_support() {
139139
'expected_wrapper' => '<div class="has-background" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
140140
'wrapper' => '<div>Content</div>',
141141
),
142-
'background image style with contain, position, and repeat is applied' => array(
142+
'background image style with contain, position, attachment, and repeat is applied' => array(
143143
'theme_name' => 'block-theme-child-with-fluid-typography',
144144
'block_name' => 'test/background-rules-are-output',
145145
'background_settings' => array(
146146
'backgroundImage' => true,
147147
),
148148
'background_style' => array(
149-
'backgroundImage' => array(
149+
'backgroundImage' => array(
150150
'url' => 'https://example.com/image.jpg',
151151
),
152-
'backgroundRepeat' => 'no-repeat',
153-
'backgroundSize' => 'contain',
152+
'backgroundRepeat' => 'no-repeat',
153+
'backgroundSize' => 'contain',
154+
'backgroundAttachment' => 'fixed',
154155
),
155-
'expected_wrapper' => '<div class="has-background" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-position:center;background-repeat:no-repeat;background-size:contain;">Content</div>',
156+
'expected_wrapper' => '<div class="has-background" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-position:center;background-repeat:no-repeat;background-size:contain;background-attachment:fixed;">Content</div>',
156157
'wrapper' => '<div>Content</div>',
157158
),
158159
'background image style is appended if a style attribute already exists' => array(

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,12 +5004,13 @@ public function test_get_top_level_background_image_styles() {
50045004
'version' => WP_Theme_JSON::LATEST_SCHEMA,
50055005
'styles' => array(
50065006
'background' => array(
5007-
'backgroundImage' => array(
5007+
'backgroundImage' => array(
50085008
'url' => 'http://example.org/image.png',
50095009
),
5010-
'backgroundSize' => 'contain',
5011-
'backgroundRepeat' => 'no-repeat',
5012-
'backgroundPosition' => 'center center',
5010+
'backgroundSize' => 'contain',
5011+
'backgroundRepeat' => 'no-repeat',
5012+
'backgroundPosition' => 'center center',
5013+
'backgroundAttachment' => 'fixed',
50135014
),
50145015
),
50155016
)
@@ -5020,7 +5021,7 @@ public function test_get_top_level_background_image_styles() {
50205021
'selector' => 'body',
50215022
);
50225023

5023-
$expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
5024+
$expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;background-attachment: fixed;}";
50245025
$this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type do not match expectations' );
50255026

50265027
$theme_json = new WP_Theme_JSON(

0 commit comments

Comments
 (0)