Skip to content

Commit

Permalink
Rolling back source requirement. File/URL is assumed by default until…
Browse files Browse the repository at this point in the history
… a source is later required
  • Loading branch information
ramonjd committed May 8, 2024
1 parent c7a2c1e commit 84b6c19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/wp-includes/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function wp_register_background_support( $block_type ) {
*
* @since 6.4.0
* @since 6.5.0 Added support for `backgroundPosition` and `backgroundRepeat` output.
* @since 6.6.0 Removed requirement for `backgroundImage.source`. A file/url is the default.
*
* @access private
*
* @param string $block_content Rendered block content.
Expand All @@ -61,10 +63,10 @@ function wp_render_background_support( $block_content, $block ) {
}

$background_styles = array();
$background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover';
$background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array();

if ( isset( $background_styles['backgroundImage']['source'] ) && 'file' === $background_styles['backgroundImage']['source'] && isset( $background_styles['backgroundImage']['url'] ) ) {
if ( isset( $background_styles['backgroundImage']['url'] ) ) {
$background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover';
$background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null;
$background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null;

Expand Down
1 change: 0 additions & 1 deletion src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class WP_Theme_JSON {
),
'background-image' => array(
array( 'background', 'backgroundImage', 'url' ),
array( 'background', 'backgroundImage', 'source' ),
),
);

Expand Down
16 changes: 6 additions & 10 deletions tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function filter_set_theme_root() {
*
* @ticket 59357
* @ticket 60175
* @ticket 61123
*
* @covers ::wp_render_background_support
*
Expand Down Expand Up @@ -132,8 +133,7 @@ public function data_background_block_support() {
),
'background_style' => array(
'backgroundImage' => array(
'url' => 'https://example.com/image.jpg',
'source' => 'file',
'url' => 'https://example.com/image.jpg',
),
),
'expected_wrapper' => '<div class="has-background" style="background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
Expand All @@ -147,8 +147,7 @@ public function data_background_block_support() {
),
'background_style' => array(
'backgroundImage' => array(
'url' => 'https://example.com/image.jpg',
'source' => 'file',
'url' => 'https://example.com/image.jpg',
),
'backgroundRepeat' => 'no-repeat',
'backgroundSize' => 'contain',
Expand All @@ -164,8 +163,7 @@ public function data_background_block_support() {
),
'background_style' => array(
'backgroundImage' => array(
'url' => 'https://example.com/image.jpg',
'source' => 'file',
'url' => 'https://example.com/image.jpg',
),
),
'expected_wrapper' => '<div class="wp-block-test has-background" style="color: red;background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
Expand All @@ -179,8 +177,7 @@ public function data_background_block_support() {
),
'background_style' => array(
'backgroundImage' => array(
'url' => 'https://example.com/image.jpg',
'source' => 'file',
'url' => 'https://example.com/image.jpg',
),
),
'expected_wrapper' => '<div class="wp-block-test has-background" style="color: red;font-size: 15px;background-image:url(&#039;https://example.com/image.jpg&#039;);background-size:cover;">Content</div>',
Expand All @@ -194,8 +191,7 @@ public function data_background_block_support() {
),
'background_style' => array(
'backgroundImage' => array(
'url' => 'https://example.com/image.jpg',
'source' => 'file',
'url' => 'https://example.com/image.jpg',
),
),
'expected_wrapper' => '<div>Content</div>',
Expand Down
5 changes: 3 additions & 2 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4921,6 +4921,8 @@ public function test_get_shadow_styles_for_blocks() {
}

/**
* Tests that theme background image styles are correctly generated.
*
* @ticket 61123
*/
public function test_get_top_level_background_image_styles() {
Expand All @@ -4940,8 +4942,7 @@ public function test_get_top_level_background_image_styles() {
'core/paragraph' => array(
'background' => array(
'backgroundImage' => array(
'url' => 'http://example.org/image.png',
'source' => 'file',
'url' => 'http://example.org/image.png',
),
'backgroundSize' => 'cover',
'backgroundRepeat' => 'no-repeat',
Expand Down

0 comments on commit 84b6c19

Please sign in to comment.