Completed
Push — develop ( dab269...0efd22 )
by Aristeides
08:51 queued 04:51
created

Kirki_Setting_Site_Option::get_root_value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * WordPress Customize Setting classes
4
 *
5
 * @package Kirki
6
 * @subpackage Modules
7
 * @since 3.0.0
8
 */
9
10
/**
11
 * Handles saving and sanitizing of user-meta.
12
 *
13
 * @since 3.0.0
14
 * @see WP_Customize_Setting
15
 */
16
class Kirki_Setting_Site_Option extends WP_Customize_Setting {
17
18
	/**
19
	 * Type of customize settings.
20
	 *
21
	 * @access public
22
	 * @since 3.0.0
23
	 * @var string
24
	 */
25
	public $type = 'site_option';
26
27
	/**
28
	 * Get the root value for a setting, especially for multidimensional ones.
29
	 *
30
	 * @access protected
31
	 * @since 3.0.0
32
	 * @param mixed $default Value to return if root does not exist.
33
	 * @return mixed
34
	 */
35
	protected function get_root_value( $default = null ) {
36
		return get_site_option( $this->id_data['base'], $default );
37
	}
38
39
	/**
40
	 * Set the root value for a setting, especially for multidimensional ones.
41
	 *
42
	 * @access protected
43
	 * @since 3.0.0
44
	 * @param mixed $value Value to set as root of multidimensional setting.
45
	 * @return bool Whether the multidimensional root was updated successfully.
46
	 */
47
	protected function set_root_value( $value ) {
48
		return update_site_option( $this->id_data['base'], $value );
49
	}
50
51
	/**
52
	 * Save the value of the setting, using the related API.
53
	 *
54
	 * @access protected
55
	 * @since 3.0.0
56
	 * @param mixed $value The value to update.
57
	 * @return bool The result of saving the value.
58
	 */
59
	protected function update( $value ) {
60
		return $this->set_root_value( $value );
61
	}
62
63
	/**
64
	 * Fetch the value of the setting.
65
	 *
66
	 * @access protected
67
	 * @since 3.0.0
68
	 * @return mixed The value.
69
	 */
70
	public function value() {
71
		return $this->get_root_value( $this->default );
72
	}
73
}
74