| @@ -39,47 +39,32 @@ | ||
| 39 | 39 | * @param array $block Block object. |
| 40 | 40 | * @return string Filtered block content. |
| 41 | 41 | */ |
| 42 | 42 | function gutenberg_render_background_support( $block_content, $block ) { |
| 43 | - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); | |
| 44 | - $block_attributes = ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) ? $block['attrs'] : array(); | |
| 45 | - $has_background_image_support = block_has_support( $block_type, array( 'background', 'backgroundImage' ), false ); | |
| 46 | - $has_background_gradient_support = block_has_support( $block_type, array( 'background', 'gradient' ), false ); | |
| 43 | + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); | |
| 44 | + $block_attributes = ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) ? $block['attrs'] : array(); | |
| 45 | + $has_background_image_support = block_has_support( $block_type, array( 'background', 'backgroundImage' ), false ); | |
| 47 | 46 | |
| 48 | 47 | if ( |
| 49 | - ( ! $has_background_image_support && ! $has_background_gradient_support ) || | |
| 48 | + ! $has_background_image_support || | |
| 49 | + wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ) || | |
| 50 | 50 | ! isset( $block_attributes['style']['background'] ) |
| 51 | 51 | ) { |
| 52 | 52 | return $block_content; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - // Check serialization skip for each feature individually. | |
| 56 | - $skip_background_image = ! $has_background_image_support || wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ); | |
| 57 | - $skip_background_gradient = ! $has_background_gradient_support || wp_should_skip_block_supports_serialization( $block_type, 'background', 'gradient' ); | |
| 58 | - | |
| 59 | - if ( $skip_background_image && $skip_background_gradient ) { | |
| 60 | - return $block_content; | |
| 61 | - } | |
| 62 | - | |
| 63 | - $background_styles = array(); | |
| 64 | - | |
| 65 | - if ( ! $skip_background_image ) { | |
| 66 | - $background_styles['backgroundImage'] = $block_attributes['style']['background']['backgroundImage'] ?? null; | |
| 67 | - $background_styles['backgroundSize'] = $block_attributes['style']['background']['backgroundSize'] ?? null; | |
| 68 | - $background_styles['backgroundPosition'] = $block_attributes['style']['background']['backgroundPosition'] ?? null; | |
| 69 | - $background_styles['backgroundRepeat'] = $block_attributes['style']['background']['backgroundRepeat'] ?? null; | |
| 70 | - $background_styles['backgroundAttachment'] = $block_attributes['style']['background']['backgroundAttachment'] ?? null; | |
| 71 | - if ( ! empty( $background_styles['backgroundImage'] ) ) { | |
| 72 | - $background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover'; | |
| 73 | - // If the background size is set to `contain` and no position is set, set the position to `center`. | |
| 74 | - if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) { | |
| 75 | - $background_styles['backgroundPosition'] = '50% 50%'; | |
| 76 | - } | |
| 55 | + $background_styles = array(); | |
| 56 | + $background_styles['backgroundImage'] = $block_attributes['style']['background']['backgroundImage'] ?? null; | |
| 57 | + $background_styles['backgroundSize'] = $block_attributes['style']['background']['backgroundSize'] ?? null; | |
| 58 | + $background_styles['backgroundPosition'] = $block_attributes['style']['background']['backgroundPosition'] ?? null; | |
| 59 | + $background_styles['backgroundRepeat'] = $block_attributes['style']['background']['backgroundRepeat'] ?? null; | |
| 60 | + $background_styles['backgroundAttachment'] = $block_attributes['style']['background']['backgroundAttachment'] ?? null; | |
| 61 | + if ( ! empty( $background_styles['backgroundImage'] ) ) { | |
| 62 | + $background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover'; | |
| 63 | + // If the background size is set to `contain` and no position is set, set the position to `center`. | |
| 64 | + if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) { | |
| 65 | + $background_styles['backgroundPosition'] = '50% 50%'; | |
| 77 | 66 | } |
| 78 | - } | |
| 79 | - | |
| 80 | - if ( ! $skip_background_gradient ) { | |
| 81 | - $background_styles['gradient'] = $block_attributes['style']['background']['gradient'] ?? null; | |
| 82 | 67 | } |
| 83 | 68 | |
| 84 | 69 | $styles = gutenberg_style_engine_get_styles( array( 'background' => $background_styles ) ); |
| 85 | 70 | |