Background.php
52 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles CSS output for background fields. |
| 4 | * |
| 5 | * @package Kirki |
| 6 | * @subpackage Controls |
| 7 | * @copyright Copyright (c) 2023, Themeum |
| 8 | * @license https://opensource.org/licenses/MIT |
| 9 | * @since 3.0.0 |
| 10 | */ |
| 11 | |
| 12 | namespace Kirki\Field\CSS; |
| 13 | |
| 14 | use Kirki\Module\CSS\Output; |
| 15 | |
| 16 | /** |
| 17 | * Output overrides. |
| 18 | */ |
| 19 | class Background extends Output { |
| 20 | |
| 21 | /** |
| 22 | * Processes a single item from the `output` array. |
| 23 | * |
| 24 | * @access protected |
| 25 | * @param array $output The `output` item. |
| 26 | * @param array $value The field's value. |
| 27 | */ |
| 28 | protected function process_output( $output, $value ) { |
| 29 | $output = wp_parse_args( |
| 30 | $output, |
| 31 | [ |
| 32 | 'media_query' => 'global', |
| 33 | 'element' => 'body', |
| 34 | 'prefix' => '', |
| 35 | 'suffix' => '', |
| 36 | ] |
| 37 | ); |
| 38 | |
| 39 | foreach ( [ 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ] as $property ) { |
| 40 | |
| 41 | // See https://github.com/aristath/kirki/issues/1808. |
| 42 | if ( 'background-color' === $property && isset( $value['background-color'] ) && $value['background-color'] && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) { |
| 43 | $this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
| 44 | } |
| 45 | |
| 46 | if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) { |
| 47 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 |