Completed
Push — develop ( e3988e...0aa98f )
by Aristeides
03:22 queued 49s
created

Kirki_Field_Background::set_transport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Override field methods
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       3.0.0
10
 */
11
12
/**
13
 * Field overrides.
14
 */
15
class Kirki_Field_Background extends Kirki_Field {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
24
		$this->type = 'kirki-background';
25
26
	}
27
28
	/**
29
	 * Sets the $transport
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_transport() {
34
35
		// Force using 'refresh' (WIP).
36
		$this->transport = 'refresh';
37
38
	}
39
40
	/**
41
	 * Sets the $sanitize_callback
42
	 *
43
	 * @access protected
44
	 */
45
	protected function set_sanitize_callback() {
46
47
		// If a custom sanitize_callback has been defined,
48
		// then we don't need to proceed any further.
49
		if ( ! empty( $this->sanitize_callback ) ) {
50
			return;
51
		}
52
		$this->sanitize_callback = array( $this, 'sanitize' );
53
54
	}
55
56
	/**
57
	 * Sanitizes typography controls
58
	 *
59
	 * @since 2.2.0
60
	 * @param array $value The value.
61
	 * @return array
62
	 */
63
	public static function sanitize( $value ) {
64
65
		if ( ! is_array( $value ) ) {
66
			return array();
67
		}
68
		return array(
69
			'background-color'      => ( isset( $value['background-color'] ) ) ? esc_attr( $value['background-color'] ) : '',
70
			'background-image'      => ( isset( $value['background-image'] ) ) ? esc_url_raw( $value['background-image'] ) : '',
71
			'background-repeat'     => ( isset( $value['background-repeat'] ) ) ? esc_attr( $value['background-repeat'] ) : '',
72
			'background-position'   => ( isset( $value['background-position'] ) ) ? esc_attr( $value['background-position'] ) : '',
73
			'background-size'       => ( isset( $value['background-size'] ) ) ? esc_attr( $value['background-size'] ) : '',
74
			'background-attachment' => ( isset( $value['background-attachment'] ) ) ? esc_attr( $value['background-attachment'] ) : '',
75
		);
76
	}
77
}
78