diff --git a/src/wp-includes/block-supports/background.php b/src/wp-includes/block-supports/background.php index c1b3d4d0940fa..e3873e9783373 100644 --- a/src/wp-includes/block-supports/background.php +++ b/src/wp-includes/block-supports/background.php @@ -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. @@ -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; diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 3aeec633da7a0..eca9ff971c5a5 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -303,7 +303,6 @@ class WP_Theme_JSON { ), 'background-image' => array( array( 'background', 'backgroundImage', 'url' ), - array( 'background', 'backgroundImage', 'source' ), ), ); diff --git a/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php b/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php index 83ea7cd47c972..4d2a6cd5b34f8 100644 --- a/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php +++ b/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php @@ -68,6 +68,7 @@ public function filter_set_theme_root() { * * @ticket 59357 * @ticket 60175 + * @ticket 61123 * * @covers ::wp_render_background_support * @@ -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' => '
Content
', @@ -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', @@ -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' => '
Content
', @@ -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' => '
Content
', @@ -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' => '
Content
', diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 2eefaf363ba1c..398207f52ad1c 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -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() { @@ -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',