Completed
Push — develop ( fe9689...674c42 )
by Aristeides
02:41
created

Kirki_Output_Field_Gradient::process_output()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 6
nop 2
dl 0
loc 28
rs 8.5806
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_Gradient 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
		// Make sure we've got everything by defining some defaults.
26
		$value = wp_parse_args( $value, array(
27
			'angle' => 0,
28
			'start' => array(
29
				'color'    => 'rgba(0,0,0,0)',
30
				'position' => 0,
31
			),
32
			'end' => array(
33
				'color'    => 'rgba(0,0,0,0)',
34
				'position' => 100,
35
			),
36
			'mode' => 'linear',
37
		) );
38
39
		$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
40
41
		$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $value['start']['color'];
42
		switch ( $value['mode'] ) {
43
44
			case 'linear':
45
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = 'linear-gradient(' . intval( $value['angle'] ) . 'deg, ' . $value['start']['color'] . ' ' . $value['start']['position'] . '%,' . $value['end']['color'] . ' ' . $value['end']['position'] . '%)';
46
				break;
47
			case 'radial':
48
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = 'radial-gradient(ellipse at center,' . $value['start']['color'] . ' ' . $value['start']['position'] . '%,' . $value['end']['color'] . ' ' . $value['end']['position'] . '%)';
49
				break;
50
		}
51
	}
52
}
53