Margin.php
73 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handle CSS output for margin control. |
| 4 | * |
| 5 | * @package Kirki |
| 6 | * @subpackage Controls |
| 7 | * @since 1.0.0 |
| 8 | */ |
| 9 | |
| 10 | namespace Kirki\Field\CSS; |
| 11 | |
| 12 | use Kirki\Module\CSS\Output; |
| 13 | |
| 14 | /** |
| 15 | * Output overrides. |
| 16 | */ |
| 17 | class Margin extends Output { |
| 18 | |
| 19 | /** |
| 20 | * The field type. |
| 21 | * |
| 22 | * @since 1.0 |
| 23 | * @access public |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $type = 'kirki-margin'; |
| 27 | |
| 28 | /** |
| 29 | * Process a single item from the `output` array. |
| 30 | * |
| 31 | * @since 1.0 |
| 32 | * @access protected |
| 33 | * |
| 34 | * @param array $output The `output` item. |
| 35 | * @param array|string $value The field's value. |
| 36 | */ |
| 37 | protected function process_output( $output, $value ) { |
| 38 | |
| 39 | $property = str_ireplace( 'kirki-', '', $this->type ); |
| 40 | $unit = isset( $this->field['choices'] ) && isset( $this->field['choices']['unit'] ) ? $this->field['choices']['unit'] : 'px'; |
| 41 | |
| 42 | $output = wp_parse_args( |
| 43 | $output, |
| 44 | array( |
| 45 | 'media_query' => 'global', |
| 46 | 'element' => '', |
| 47 | ) |
| 48 | ); |
| 49 | |
| 50 | // Stop if the value is not an array. |
| 51 | if ( ! is_array( $value ) ) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | foreach ( $value as $position => $value ) { |
| 56 | if ( '' !== $value ) { |
| 57 | $value = is_numeric( $value ) ? $value . $unit : $value; |
| 58 | $css_property = $property . '-' . $position; |
| 59 | |
| 60 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $css_property ] = $value; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if ( 'kirki_demo_responsive_margin[desktop]' === $this->field['settings'] ) { |
| 65 | // error_log( print_r( get_theme_mod( 'kirki_demo_responsive_margin[desktop]' ), true ) ); |
| 66 | // error_log( print_r( $this->styles, true ) ); |
| 67 | // error_log( print_r( $value, true ) ); |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |