Image.php
55 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles CSS output for image 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.10 |
| 10 | */ |
| 11 | |
| 12 | namespace Kirki\Field\CSS; |
| 13 | |
| 14 | use Kirki\Module\CSS\Output; |
| 15 | |
| 16 | /** |
| 17 | * Output overrides. |
| 18 | */ |
| 19 | class Image 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 | if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) { |
| 30 | return; |
| 31 | } |
| 32 | $output = wp_parse_args( |
| 33 | $output, |
| 34 | [ |
| 35 | 'media_query' => 'global', |
| 36 | 'prefix' => '', |
| 37 | 'units' => '', |
| 38 | 'suffix' => '', |
| 39 | ] |
| 40 | ); |
| 41 | if ( is_array( $value ) ) { |
| 42 | if ( isset( $output['choice'] ) && $output['choice'] ) { |
| 43 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value[ $output['choice'] ] ) . $output['units'] . $output['suffix']; |
| 44 | return; |
| 45 | } |
| 46 | if ( isset( $value['url'] ) ) { |
| 47 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value['url'] ) . $output['units'] . $output['suffix']; |
| 48 | return; |
| 49 | } |
| 50 | return; |
| 51 | } |
| 52 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix']; |
| 53 | } |
| 54 | } |
| 55 |