Completed
Pull Request — master (#1454)
by Aristeides
05:01 queued 02:16
created

Kirki_Output_Field_Dimensions::process_output()   C

Complexity

Conditions 7
Paths 11

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 11
nop 2
dl 0
loc 26
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * Handles CSS output for dimensions fields.
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       2.2.0
10
 */
11
12
/**
13
 * Output overrides.
14
 */
15
class Kirki_Output_Field_Dimensions extends Kirki_Output {
16
17
	/**
18
	 * Processes a single item from the `output` array.
19
	 *
20
	 * @access protected
21
	 * @param array $output The `output` item.
22
	 * @param array $value  The field's value.
23
	 */
24
	protected function process_output( $output, $value ) {
25
26
		$output = wp_parse_args( $output, array(
27
			'element'     => '',
28
			'property'    => '',
29
			'media_query' => 'global',
30
			'prefix'      => '',
31
			'suffix'      => '',
32
		) );
33
34
		foreach ( $value as $key => $sub_value ) {
35
36
			$property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key;
37
			if ( isset( $output['choice'] ) && $output['property'] ) {
38
				if ( $key === $output['choice'] ) {
39
					$property = $output['property'];
40
				} else {
41
					continue;
42
				}
43
			}
44
			if ( false !== strpos( $output['property'], '%%' ) ) {
45
				$property = str_replace( '%%', $key, $output['property'] );
46
			}
47
			$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix'];
48
		}
49
	}
50
}
51