From 4053da333912c79f37bd0737eac1a0dbe8aae54d Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 2 May 2024 17:04:39 +1000 Subject: [PATCH 1/8] Initial commit: Syncing changes for Global styles: background UI controls #59454 Global styles: add background image to top-level theme.json styles #59354 Background block supports: move block support defaults to gutenberg_render_background_support and revert gutenberg_get_background_support_styles #59889 --- src/wp-includes/block-supports/background.php | 47 +++++-------------- src/wp-includes/class-wp-theme-json.php | 23 +++++++++ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/wp-includes/block-supports/background.php b/src/wp-includes/block-supports/background.php index 9b82e6a9d598d..c1b3d4d0940fa 100644 --- a/src/wp-includes/block-supports/background.php +++ b/src/wp-includes/block-supports/background.php @@ -54,52 +54,27 @@ function wp_render_background_support( $block_content, $block ) { if ( ! $has_background_image_support || - wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ) + wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ) || + ! isset( $block_attributes['style']['background'] ) ) { return $block_content; } - $background_image_source = isset( $block_attributes['style']['background']['backgroundImage']['source'] ) - ? $block_attributes['style']['background']['backgroundImage']['source'] - : null; - $background_image_url = isset( $block_attributes['style']['background']['backgroundImage']['url'] ) - ? $block_attributes['style']['background']['backgroundImage']['url'] - : null; + $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 ( ! $background_image_source && ! $background_image_url ) { - return $block_content; - } - - $background_size = isset( $block_attributes['style']['background']['backgroundSize'] ) - ? $block_attributes['style']['background']['backgroundSize'] - : 'cover'; - $background_position = isset( $block_attributes['style']['background']['backgroundPosition'] ) - ? $block_attributes['style']['background']['backgroundPosition'] - : null; - $background_repeat = isset( $block_attributes['style']['background']['backgroundRepeat'] ) - ? $block_attributes['style']['background']['backgroundRepeat'] - : null; - - $background_block_styles = array(); - - if ( - 'file' === $background_image_source && - $background_image_url - ) { - // Set file based background URL. - $background_block_styles['backgroundImage']['url'] = $background_image_url; - // Only output the background size and repeat when an image url is set. - $background_block_styles['backgroundSize'] = $background_size; - $background_block_styles['backgroundRepeat'] = $background_repeat; - $background_block_styles['backgroundPosition'] = $background_position; + if ( isset( $background_styles['backgroundImage']['source'] ) && 'file' === $background_styles['backgroundImage']['source'] && isset( $background_styles['backgroundImage']['url'] ) ) { + $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; // If the background size is set to `contain` and no position is set, set the position to `center`. - if ( 'contain' === $background_size && ! isset( $background_position ) ) { - $background_block_styles['backgroundPosition'] = 'center'; + if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) { + $background_styles['backgroundPosition'] = 'center'; } } - $styles = wp_style_engine_get_styles( array( 'background' => $background_block_styles ) ); + $styles = wp_style_engine_get_styles( array( 'background' => $background_styles ) ); if ( ! empty( $styles['css'] ) ) { // Inject background styles to the first element, presuming it's the wrapper, if it exists. diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index d1af7ab6e2591..8432cf62c86e5 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -213,6 +213,7 @@ class WP_Theme_JSON { * @since 6.3.0 Added `column-count` property. * @since 6.4.0 Added `writing-mode` property. * @since 6.5.0 Added `aspect-ratio` property. + * @since 6.6.0 Added `background-[image|position|repeat|size]` properties. * * @var array */ @@ -220,6 +221,10 @@ class WP_Theme_JSON { 'aspect-ratio' => array( 'dimensions', 'aspectRatio' ), 'background' => array( 'color', 'gradient' ), 'background-color' => array( 'color', 'background' ), + 'background-image' => array( 'background', 'backgroundImage' ), + 'background-position' => array( 'background', 'backgroundPosition' ), + 'background-repeat' => array( 'background', 'backgroundRepeat' ), + 'background-size' => array( 'background', 'backgroundSize' ), 'border-radius' => array( 'border', 'radius' ), 'border-top-left-radius' => array( 'border', 'radius', 'topLeft' ), 'border-top-right-radius' => array( 'border', 'radius', 'topRight' ), @@ -286,6 +291,7 @@ class WP_Theme_JSON { * property is used to validate whether or not a style value is allowed. * * @since 6.2.0 + * @since 6.6.0 Added background-image properties. * * @var array */ @@ -303,6 +309,10 @@ class WP_Theme_JSON { array( 'layout', 'contentSize' ), array( 'layout', 'wideSize' ), ), + 'background-image' => array( + array( 'background', 'backgroundImage', 'url' ), + array( 'background', 'backgroundImage', 'source' ), + ), ); /** @@ -482,10 +492,17 @@ class WP_Theme_JSON { * @since 6.2.0 Added `outline`, and `minHeight` properties. * @since 6.3.0 Added support for `typography.textColumns`. * @since 6.5.0 Added support for `dimensions.aspectRatio`. + * @since 6.6.0 Added `background` sub properties to top-level only. * * @var array */ const VALID_STYLES = array( + 'background' => array( + 'backgroundImage' => 'top', + 'backgroundPosition' => 'top', + 'backgroundRepeat' => 'top', + 'backgroundSize' => 'top', + ), 'border' => array( 'color' => null, 'radius' => null, @@ -2105,6 +2122,12 @@ protected static function compute_style_properties( $styles, $settings = array() } } + // Processes background styles. + if ( 'background' === $value_path[0] && isset( $styles['background'] ) ) { + $background_styles = wp_style_engine_get_styles( array( 'background' => $styles['background'] ) ); + $value = $background_styles['declarations'][ $css_property ] ?? $value; + } + // Skip if empty and not "0" or value represents array of longhand values. $has_missing_value = empty( $value ) && ! is_numeric( $value ); if ( $has_missing_value || is_array( $value ) ) { From 956899d9ddc22e2237144a923f993990b45ccad3 Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 2 May 2024 20:08:55 +1000 Subject: [PATCH 2/8] Syncing https://github.com/WordPress/gutenberg/pull/59809 --- src/wp-includes/class-wp-theme-json.php | 48 ++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 8432cf62c86e5..c2b9c9acc7b9d 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2507,6 +2507,7 @@ private static function get_block_nodes( $theme_json ) { * Gets the CSS rules for a particular block from theme.json. * * @since 6.1.0 + * @since 6.6.0 Setting a min-height of HTML when root styles have a background gradient or image. * * @param array $block_metadata Metadata about the block to get styles for. * @@ -2518,6 +2519,7 @@ public function get_styles_for_block( $block_metadata ) { $selector = $block_metadata['selector']; $settings = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array(); $feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node ); + $is_root_selector = static::ROOT_BLOCK_SELECTOR === $selector; // If there are style variations, generate the declarations for them, including any feature selectors the block may have. $style_variation_declarations = array(); @@ -2600,15 +2602,53 @@ static function ( $pseudo_selector ) use ( $selector ) { $block_rules = ''; /* - * 1. Separate the declarations that use the general selector + * 1. Bespoke declaration modifiers: + * - 'filter': Separate the declarations that use the general selector * from the ones using the duotone selector. + * - 'background|background-image': set the html min-height to 100% + * to ensure the background covers the entire viewport. */ - $declarations_duotone = array(); + $declarations_duotone = array(); + $should_set_root_min_height = false; + foreach ( $declarations as $index => $declaration ) { if ( 'filter' === $declaration['name'] ) { + /* + * 'unset' filters happen when a filter is unset + * in the site-editor UI. Because the 'unset' value + * in the user origin overrides the value in the + * theme origin, we can skip rendering anything + * here as no filter needs to be applied anymore. + * So only add declarations to with values other + * than 'unset'. + */ + if ( 'unset' !== $declaration['value'] ) { + $declarations_duotone[] = $declaration; + } unset( $declarations[ $index ] ); - $declarations_duotone[] = $declaration; } + + if ( $is_root_selector && ( 'background-image' === $declaration['name'] || 'background' === $declaration['name'] ) ) { + $should_set_root_min_height = true; + } + } + + /* + * If root styles has a background-image or a background (gradient) set, + * set the min-height to '100%'. Minus `--wp-admin--admin-bar--height` for logged-in view. + * Setting the CSS rule on the HTML tag ensures background gradients and images behave similarly, + * and matches the behavior of the site editor. + */ + if ( $should_set_root_min_height ) { + $block_rules .= static::to_ruleset( + 'html', + array( + array( + 'name' => 'min-height', + 'value' => 'calc(100% - var(--wp-admin--admin-bar--height, 0px))', + ), + ) + ); } // Update declarations if there are separators with only background color defined. @@ -2626,7 +2666,7 @@ static function ( $pseudo_selector ) use ( $selector ) { // 4. Generate Layout block gap styles. if ( - static::ROOT_BLOCK_SELECTOR !== $selector && + ! $is_root_selector && ! empty( $block_metadata['name'] ) ) { $block_rules .= $this->get_layout_styles( $block_metadata ); From e13fad22f426664002107b59d655bf27ee33e850 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 3 May 2024 14:32:24 +1000 Subject: [PATCH 3/8] unit tests --- tests/phpunit/tests/theme/wpThemeJson.php | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index a7269485c3bad..f129cbad1c127 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -4984,6 +4984,72 @@ public function test_get_shadow_styles_for_blocks() { $this->assertSame( $expected_styles, $theme_json->get_stylesheet() ); } + /** + * @ticket 61123 + */ + public function test_get_top_level_background_image_styles() { + $theme_json = new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'styles' => array( + 'background' => array( + 'backgroundImage' => array( + 'url' => 'http://example.org/image.png', + ), + 'backgroundSize' => 'contain', + 'backgroundRepeat' => 'no-repeat', + 'backgroundPosition' => 'center center', + ), + 'blocks' => array( + 'core/paragraph' => array( + 'background' => array( + 'backgroundImage' => array( + 'url' => 'http://example.org/image.png', + 'source' => 'file', + ), + 'backgroundSize' => 'cover', + 'backgroundRepeat' => 'no-repeat', + 'backgroundPosition' => 'center center', + ), + ), + ), + 'elements' => array( + 'button' => array( + 'background' => array( + 'backgroundImage' => array( + 'url' => 'http://example.org/image.png', + ), + 'backgroundSize' => 'cover', + 'backgroundRepeat' => 'no-repeat', + 'backgroundPosition' => 'center center', + ), + ), + ), + ), + ) + ); + + $expected_styles = "body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}"; + $this->assertSame( $expected_styles, $theme_json->get_stylesheet(), 'Styles returned from "::get_stylesheet()" with top-level background styles type does not match expectations' ); + + $theme_json = new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'styles' => array( + 'background' => array( + 'backgroundImage' => "url('http://example.org/image.png')", + 'backgroundSize' => 'contain', + 'backgroundRepeat' => 'no-repeat', + 'backgroundPosition' => 'center center', + ), + ), + ) + ); + + $expected_styles = "body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}"; + $this->assertSame( $expected_styles, $theme_json->get_stylesheet(), 'Styles returned from "::get_stylesheet()" with top-level background image as string type does not match expectations' ); + } + /** * @ticket 57536 */ From 8a7890eb3b3139bd75366ec21f0d17755ff720da Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 3 May 2024 14:45:32 +1000 Subject: [PATCH 4/8] Copy update --- src/wp-includes/class-wp-theme-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index c2b9c9acc7b9d..d5c7f48f249f2 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -288,7 +288,7 @@ class WP_Theme_JSON { * * Indirect properties are not output directly by `compute_style_properties`, * but are used elsewhere in the processing of global styles. The indirect - * property is used to validate whether or not a style value is allowed. + * property is used to validate whether a style value is allowed. * * @since 6.2.0 * @since 6.6.0 Added background-image properties. From 9ff4495a9ec38d8f104eacf5d55e6cd4a39771cb Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 8 May 2024 12:43:26 +1000 Subject: [PATCH 5/8] Rolling back source requirement. File/URL is assumed by default until a source is later required --- src/wp-includes/block-supports/background.php | 6 ++++-- src/wp-includes/class-wp-theme-json.php | 1 - .../block-supports/wpRenderBackgroundSupport.php | 16 ++++++---------- tests/phpunit/tests/theme/wpThemeJson.php | 5 +++-- 4 files changed, 13 insertions(+), 15 deletions(-) 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 d5c7f48f249f2..237204cb5c2c3 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -311,7 +311,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 08bf4974f9ef2..3fa7da28908a3 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 f129cbad1c127..d193101e0a64a 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -4985,6 +4985,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() { @@ -5004,8 +5006,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', From a0a496d2d170f21973d49684c2bbd69db08c2a42 Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 27 May 2024 08:41:36 +1000 Subject: [PATCH 6/8] Pulling change from https://github.com/WordPress/gutenberg/pull/61387 --- src/wp-includes/block-supports/background.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-supports/background.php b/src/wp-includes/block-supports/background.php index e3873e9783373..ff50be3206837 100644 --- a/src/wp-includes/block-supports/background.php +++ b/src/wp-includes/block-supports/background.php @@ -65,7 +65,7 @@ function wp_render_background_support( $block_content, $block ) { $background_styles = array(); $background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array(); - if ( isset( $background_styles['backgroundImage']['url'] ) ) { + if ( ! empty( $background_styles['backgroundImage'] ) ) { $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; From bc314e1a937d01f0b7ad0d25324261ed402af014 Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 28 May 2024 14:23:23 +1000 Subject: [PATCH 7/8] Add @since annotation and remove null coalescing operator --- src/wp-includes/class-wp-theme-json.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 237204cb5c2c3..b1bd65c62eff2 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2068,6 +2068,7 @@ protected static function flatten_tree( $tree, $prefix = '', $token = '--' ) { * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters. * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set. * @since 6.6.0 Passing current theme JSON settings to wp_get_typography_font_size_value(). + * Process background properties using the Style Engine. * * @param array $styles Styles to process. * @param array $settings Theme settings. @@ -2124,7 +2125,7 @@ protected static function compute_style_properties( $styles, $settings = array() // Processes background styles. if ( 'background' === $value_path[0] && isset( $styles['background'] ) ) { $background_styles = wp_style_engine_get_styles( array( 'background' => $styles['background'] ) ); - $value = $background_styles['declarations'][ $css_property ] ?? $value; + $value = isset( $background_styles['declarations'][ $css_property ] ) ? $background_styles['declarations'][ $css_property ] : $value; } // Skip if empty and not "0" or value represents array of longhand values. From a254de9d5707fa544c2da795d737c00d5d87754e Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 28 May 2024 14:39:36 +1000 Subject: [PATCH 8/8] Fix since annotation - remove line break. --- src/wp-includes/class-wp-theme-json.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index b1bd65c62eff2..f118f92c064b8 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2067,8 +2067,7 @@ protected static function flatten_tree( $tree, $prefix = '', $token = '--' ) { * @since 5.9.0 Added the `$settings` and `$properties` parameters. * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters. * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set. - * @since 6.6.0 Passing current theme JSON settings to wp_get_typography_font_size_value(). - * Process background properties using the Style Engine. + * @since 6.6.0 Pass current theme JSON settings to wp_get_typography_font_size_value(), and process background properties. * * @param array $styles Styles to process. * @param array $settings Theme settings.