Dimensions.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles CSS output for dimensions fields. |
| 4 | * |
| 5 | * @package Kirki |
| 6 | * @subpackage Controls |
| 7 | * @copyright Copyright (c) 2023, Themeum |
| 8 | * @license https://opensource.org/licenses/MIT |
| 9 | * @since 2.2.0 |
| 10 | */ |
| 11 | |
| 12 | namespace Kirki\Field\CSS; |
| 13 | |
| 14 | use Kirki\Module\CSS\Output; |
| 15 | |
| 16 | /** |
| 17 | * Output overrides. |
| 18 | */ |
| 19 | class Dimensions 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 | 'element' => '', |
| 33 | 'property' => '', |
| 34 | 'media_query' => 'global', |
| 35 | 'prefix' => '', |
| 36 | 'suffix' => '', |
| 37 | ] |
| 38 | ); |
| 39 | |
| 40 | if ( ! is_array( $value ) ) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | foreach ( array_keys( $value ) as $key ) { |
| 45 | |
| 46 | $property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key; |
| 47 | if ( isset( $output['choice'] ) && $output['property'] ) { |
| 48 | if ( $key === $output['choice'] ) { |
| 49 | $property = $output['property']; |
| 50 | } else { |
| 51 | continue; |
| 52 | } |
| 53 | } |
| 54 | if ( false !== strpos( $output['property'], '%%' ) ) { |
| 55 | $property = str_replace( '%%', $key, $output['property'] ); |
| 56 | } |
| 57 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix']; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |