Make WordPress Core


Ignore:
Timestamp:
07/24/2024 12:24:31 AM (2 years ago)
Author:
noisysocks
Message:

Block themes: Enable block-level background image styles

Allows defining background images for blocks in theme.json.

Syncs PHP changes from https://github.com/WordPress/gutenberg/pull/60100.

Props ramonopoly, aaronrobertshaw.
Fixes #61588.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/background.php

    r58222 r58797  
    6363        }
    6464
    65         $background_styles                    = array();
    66         $background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array();
     65        $background_styles                       = array();
     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;
    6770
    6871        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;
     72                $background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover';
    7273
    7374                // If the background size is set to `contain` and no position is set, set the position to `center`.
Note: See TracChangeset for help on using the changeset viewer.