summaryrefslogtreecommitdiffstats
path: root/wp-includes/block-supports/background.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:51:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:51:18 +0000
commit0e41b5d52fdc6af6442816b5f465c9db9f84e126 (patch)
treee139a90049b158d4eed892d1662ee7f5c358fa31 /wp-includes/block-supports/background.php
parentAdding upstream version 6.5.5+dfsg1. (diff)
downloadwordpress-upstream.tar.xz
wordpress-upstream.zip
Adding upstream version 6.6.1+dfsg1.upstream/6.6.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/block-supports/background.php')
-rw-r--r--wp-includes/block-supports/background.php49
1 files changed, 13 insertions, 36 deletions
diff --git a/wp-includes/block-supports/background.php b/wp-includes/block-supports/background.php
index 9b82e6a..ff50be3 100644
--- a/wp-includes/block-supports/background.php
+++ b/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.
@@ -54,52 +56,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;
-
- 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();
+ $background_styles = array();
+ $background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : 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 ( ! 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;
// 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.