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

Kirki_Setting_Site_Option   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get_root_value() 0 3 1
A set_root_value() 0 3 1
A update() 0 3 1
A value() 0 3 1
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