Changeset 58222 for trunk/src/wp-includes/block-supports/background.php
- Timestamp:
- 05/28/2024 06:04:37 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/background.php
r57365 r58222 42 42 * @since 6.4.0 43 43 * @since 6.5.0 Added support for `backgroundPosition` and `backgroundRepeat` output. 44 * @since 6.6.0 Removed requirement for `backgroundImage.source`. A file/url is the default. 45 * 44 46 * @access private 45 47 * … … 55 57 if ( 56 58 ! $has_background_image_support || 57 wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ) 59 wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ) || 60 ! isset( $block_attributes['style']['background'] ) 58 61 ) { 59 62 return $block_content; 60 63 } 61 64 62 $background_image_source = isset( $block_attributes['style']['background']['backgroundImage']['source'] ) 63 ? $block_attributes['style']['background']['backgroundImage']['source'] 64 : null; 65 $background_image_url = isset( $block_attributes['style']['background']['backgroundImage']['url'] ) 66 ? $block_attributes['style']['background']['backgroundImage']['url'] 67 : null; 65 $background_styles = array(); 66 $background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array(); 68 67 69 if ( ! $background_image_source && ! $background_image_url ) { 70 return $block_content; 71 } 72 73 $background_size = isset( $block_attributes['style']['background']['backgroundSize'] ) 74 ? $block_attributes['style']['background']['backgroundSize'] 75 : 'cover'; 76 $background_position = isset( $block_attributes['style']['background']['backgroundPosition'] ) 77 ? $block_attributes['style']['background']['backgroundPosition'] 78 : null; 79 $background_repeat = isset( $block_attributes['style']['background']['backgroundRepeat'] ) 80 ? $block_attributes['style']['background']['backgroundRepeat'] 81 : null; 82 83 $background_block_styles = array(); 84 85 if ( 86 'file' === $background_image_source && 87 $background_image_url 88 ) { 89 // Set file based background URL. 90 $background_block_styles['backgroundImage']['url'] = $background_image_url; 91 // Only output the background size and repeat when an image url is set. 92 $background_block_styles['backgroundSize'] = $background_size; 93 $background_block_styles['backgroundRepeat'] = $background_repeat; 94 $background_block_styles['backgroundPosition'] = $background_position; 68 if ( ! empty( $background_styles['backgroundImage'] ) ) { 69 $background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover'; 70 $background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null; 71 $background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null; 95 72 96 73 // If the background size is set to `contain` and no position is set, set the position to `center`. 97 if ( 'contain' === $background_s ize && ! isset( $background_position )) {98 $background_ block_styles['backgroundPosition'] = 'center';74 if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) { 75 $background_styles['backgroundPosition'] = 'center'; 99 76 } 100 77 } 101 78 102 $styles = wp_style_engine_get_styles( array( 'background' => $background_ block_styles ) );79 $styles = wp_style_engine_get_styles( array( 'background' => $background_styles ) ); 103 80 104 81 if ( ! empty( $styles['css'] ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)