class-control-setting.php
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Control_Setting.
*
* @package Block_Lab
* @copyright Copyright(c) 2020, Block Lab
* @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0)
*/
namespace Block_Lab\Blocks\Controls;
/**
* Class Control_Setting
*/
class Control_Setting {
/**
* Setting name (slug).
*
* @var string
*/
public $name = '';
/**
* Setting label.
*
* @var string
*/
public $label = '';
/**
* Setting type.
*
* @var string
*/
public $type = '';
/**
* Default value.
*
* @var mixed
*/
public $default = '';
/**
* Help text.
*
* @var string
*/
public $help = '';
/**
* Sanitizing function.
*
* @var mixed
*/
public $sanitize = '';
/**
* Validating function.
*
* @var mixed
*/
public $validate = '';
/**
* Current value. Null for unset.
*
* @var mixed
*/
public $value = null;
/**
* Control_Setting constructor.
*
* @param array $args An associative array with keys corresponding to the Option's properties.
*
* @return void
*/
public function __construct( $args = [] ) {
if ( isset( $args['name'] ) ) {
$this->name = $args['name'];
}
if ( isset( $args['label'] ) ) {
$this->label = $args['label'];
}
if ( isset( $args['type'] ) ) {
$this->type = $args['type'];
}
if ( isset( $args['default'] ) ) {
$this->default = $args['default'];
}
if ( isset( $args['help'] ) ) {
$this->help = $args['help'];
}
if ( isset( $args['sanitize'] ) ) {
$this->sanitize = $args['sanitize'];
}
if ( isset( $args['validate'] ) ) {
$this->validate = $args['validate'];
}
if ( isset( $args['value'] ) ) {
$this->value = $args['value'];
}
}
/**
* Get the current value, using the default if there is none set.
*
* @return mixed
*/
public function get_value() {
if ( null === $this->value ) {
return $this->default;
}
return $this->value;
}
}