Completed
Pull Request — master (#1454)
by Aristeides
06:19 queued 03:39
created

Kirki_Output_Field_Dimensions   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
C process_output() 0 26 7
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