1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The admin-specific UI builder of the plugin. |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/austinheap/wordpress-security-txt |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
* |
9
|
|
|
* @package WordPress_Security_Txt |
10
|
|
|
* @subpackage WordPress_Security_Txt/admin |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The admin-specific UI builder of the plugin. |
15
|
|
|
* |
16
|
|
|
* @package WordPress_Security_Txt |
17
|
|
|
* @subpackage WordPress_Security_Txt/admin |
18
|
|
|
* @author Austin Heap <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class WordPress_Security_Txt_Builder |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The ID of this plugin. |
25
|
|
|
* |
26
|
|
|
* @since 1.0.0 |
27
|
|
|
* @access private |
28
|
|
|
* @var string $plugin_name The ID of this plugin. |
29
|
|
|
*/ |
30
|
|
|
private $plugin_name; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The version of this plugin. |
34
|
|
|
* |
35
|
|
|
* @since 1.0.0 |
36
|
|
|
* @access private |
37
|
|
|
* @var string $version The current version of this plugin. |
38
|
|
|
*/ |
39
|
|
|
private $version; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The builder options. |
43
|
|
|
* |
44
|
|
|
* @since 1.0.0 |
45
|
|
|
* @access private |
46
|
|
|
* @var array $options The plugin options. |
47
|
|
|
*/ |
48
|
|
|
private $options; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Initialize the class and set its properties. |
52
|
|
|
* |
53
|
|
|
* @since 1.0.0 |
54
|
|
|
* |
55
|
|
|
* @param string $plugin_name The name of this plugin. |
56
|
|
|
* @param string $version The version of this plugin. |
57
|
|
|
* @param array $options The options of this plugin. |
58
|
|
|
*/ |
59
|
|
|
public function __construct($plugin_name, $version, $options) |
60
|
|
|
{ |
61
|
|
|
$this->plugin_name = $plugin_name; |
62
|
|
|
$this->version = $version; |
63
|
|
|
$this->options = $options; |
64
|
|
|
|
65
|
|
|
if ($this->version != WORDPRESS_SECURITY_TXT_VERSION) { |
66
|
|
|
throw new Exception('Internal version mismatch in plugin wordpress-security-txt; it needs to be reinstalled.'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Creates a checkbox field |
72
|
|
|
* |
73
|
|
|
* @param array $args The arguments for the field |
74
|
|
|
* |
75
|
|
|
* @return string The HTML field |
76
|
|
|
*/ |
77
|
|
|
public function checkbox($args) |
78
|
|
|
{ |
79
|
|
|
$defaults['class'] = $defaults['description'] = $defaults['label'] = ''; |
|
|
|
|
80
|
|
|
$defaults['name'] = $this->plugin_name . '-options[' . $args['id'] . ']'; |
81
|
|
|
$defaults['value'] = 0; |
82
|
|
|
|
83
|
|
|
apply_filters($this->plugin_name . '-field-checkbox-options-defaults', $defaults); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$atts = wp_parse_args($args, $defaults); |
|
|
|
|
86
|
|
|
|
87
|
|
|
if (! empty($this->options[$atts['id']])) { |
88
|
|
|
$atts['value'] = $this->options[$atts['id']]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-checkbox.php'; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Creates an editor field |
96
|
|
|
* |
97
|
|
|
* NOTE: ID must only be lowercase letter, no spaces, dashes, or underscores. |
98
|
|
|
* |
99
|
|
|
* @param array $args The arguments for the field |
100
|
|
|
* |
101
|
|
|
* @return string The HTML field |
102
|
|
|
*/ |
103
|
|
|
public function editor($args) |
104
|
|
|
{ |
105
|
|
|
$defaults['description'] = $defaults['value'] = ''; |
|
|
|
|
106
|
|
|
$defaults['settings'] = ['textarea_name' => $this->plugin_name . '-options[' . $args['id'] . ']']; |
107
|
|
|
|
108
|
|
|
apply_filters($this->plugin_name . '-field-editor-options-defaults', $defaults); |
|
|
|
|
109
|
|
|
|
110
|
|
|
$atts = wp_parse_args($args, $defaults); |
|
|
|
|
111
|
|
|
|
112
|
|
|
if (! empty($this->options[$atts['id']])) { |
113
|
|
|
$atts['value'] = $this->options[$atts['id']]; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-editor.php'; |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Creates a set of radios field |
121
|
|
|
* |
122
|
|
|
* @param array $args The arguments for the field |
123
|
|
|
* |
124
|
|
|
* @return string The HTML field |
125
|
|
|
*/ |
126
|
|
|
public function radios($args) |
127
|
|
|
{ |
128
|
|
|
$defaults['class'] = $defaults['label'] = $defaults['description'] = ''; |
|
|
|
|
129
|
|
|
$defaults['name'] = $this->plugin_name . '-options[' . $args['id'] . ']'; |
130
|
|
|
$defaults['value'] = 0; |
131
|
|
|
|
132
|
|
|
apply_filters($this->plugin_name . '-field-radios-options-defaults', $defaults); |
|
|
|
|
133
|
|
|
|
134
|
|
|
$atts = wp_parse_args($args, $defaults); |
|
|
|
|
135
|
|
|
|
136
|
|
|
if (! empty($this->options[$atts['id']])) { |
137
|
|
|
$atts['value'] = $this->options[$atts['id']]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-radios.php'; |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function repeater($args) |
144
|
|
|
{ |
145
|
|
|
$defaults['class'] = 'repeater'; |
|
|
|
|
146
|
|
|
$defaults['fields'] = []; |
147
|
|
|
$defaults['id'] = $defaults['title-field'] = ''; |
148
|
|
|
$defaults['label-add'] = 'Add Item'; |
149
|
|
|
$defaults['label-edit'] = 'Edit Item'; |
150
|
|
|
$defaults['label-header'] = 'Item Name'; |
151
|
|
|
$defaults['label-remove'] = 'Remove Item'; |
152
|
|
|
|
153
|
|
|
apply_filters($this->plugin_name . '-field-repeater-options-defaults', $defaults); |
|
|
|
|
154
|
|
|
|
155
|
|
|
$setatts = wp_parse_args($args, $defaults); |
|
|
|
|
156
|
|
|
$count = 1; |
157
|
|
|
$repeater = []; |
158
|
|
|
|
159
|
|
|
if (! empty($this->options[$setatts['id']])) { |
160
|
|
|
$repeater = maybe_unserialize($this->options[$setatts['id']][0]); |
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
if (! empty($repeater)) { |
164
|
|
|
$count = count($repeater); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-repeater.php'; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Creates a select field |
172
|
|
|
* |
173
|
|
|
* Note: label is blank since its created in the Settings API |
174
|
|
|
* |
175
|
|
|
* @param array $args The arguments for the field |
176
|
|
|
* |
177
|
|
|
* @return string The HTML field |
178
|
|
|
*/ |
179
|
|
|
public function select($args) |
180
|
|
|
{ |
181
|
|
|
$defaults['aria'] = $defaults['blank'] = $defaults['context'] = $defaults['description'] = $defaults['label'] = $defaults['value'] = ''; |
|
|
|
|
182
|
|
|
$defaults['class'] = 'widefat'; |
183
|
|
|
$defaults['name'] = $this->plugin_name . '-options[' . $args['id'] . ']'; |
184
|
|
|
$defaults['selections'] = []; |
185
|
|
|
|
186
|
|
|
apply_filters($this->plugin_name . '-field-select-options-defaults', $defaults); |
|
|
|
|
187
|
|
|
|
188
|
|
|
$atts = wp_parse_args($args, $defaults); |
|
|
|
|
189
|
|
|
|
190
|
|
|
if (! empty($this->options[$atts['id']])) { |
191
|
|
|
$atts['value'] = $this->options[$atts['id']]; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
if (empty($atts['aria']) && ! empty($atts['description'])) { |
195
|
|
|
$atts['aria'] = $atts['description']; |
196
|
|
|
} elseif (empty($atts['aria']) && ! empty($atts['label'])) { |
197
|
|
|
$atts['aria'] = $atts['label']; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-select.php'; |
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Creates a text field |
205
|
|
|
* |
206
|
|
|
* @param array $args The arguments for the field |
207
|
|
|
* |
208
|
|
|
* @return string The HTML field |
209
|
|
|
*/ |
210
|
|
|
public function text($args) |
211
|
|
|
{ |
212
|
|
|
$defaults['placeholder'] = $defaults['description'] = $defaults['label'] = ''; |
|
|
|
|
213
|
|
|
$defaults['class'] = 'text widefat'; |
214
|
|
|
$defaults['name'] = $this->plugin_name . '-options[' . $args['id'] . ']'; |
215
|
|
|
$defaults['type'] = 'text'; |
216
|
|
|
$defaults['value'] = isset($args['value']) && ! empty($args['value']) ? $args['value'] : ''; |
217
|
|
|
|
218
|
|
|
apply_filters($this->plugin_name . '-field-text-options-defaults', $defaults); |
|
|
|
|
219
|
|
|
|
220
|
|
|
$atts = wp_parse_args($args, $defaults); |
|
|
|
|
221
|
|
|
|
222
|
|
|
if (! empty($this->options[$atts['id']])) { |
223
|
|
|
$atts['value'] = $this->options[$atts['id']]; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-text.php'; |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Creates a textarea field |
231
|
|
|
* |
232
|
|
|
* @param array $args The arguments for the field |
233
|
|
|
* |
234
|
|
|
* @return string The HTML field |
235
|
|
|
*/ |
236
|
|
|
public function textarea($args) |
237
|
|
|
{ |
238
|
|
|
$defaults['context'] = $defaults['description'] = $defaults['label'] = $defaults['placeholder'] = ''; |
|
|
|
|
239
|
|
|
$defaults['class'] = 'large-text'; |
240
|
|
|
$defaults['cols'] = 50; |
241
|
|
|
$defaults['name'] = $this->plugin_name . '-options[' . $args['id'] . ']'; |
242
|
|
|
$defaults['rows'] = 10; |
243
|
|
|
$defaults['value'] = isset($args['value']) && ! empty($args['value']) ? $args['value'] : ''; |
244
|
|
|
|
245
|
|
|
apply_filters($this->plugin_name . '-field-textarea-options-defaults', $defaults); |
|
|
|
|
246
|
|
|
|
247
|
|
|
$atts = wp_parse_args($args, $defaults); |
|
|
|
|
248
|
|
|
|
249
|
|
|
if (! empty($this->options[$atts['id']])) { |
250
|
|
|
$atts['value'] = $this->options[$atts['id']]; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
require plugin_dir_path(__FILE__) . 'partials/' . $this->plugin_name . '-field-textarea.php'; |
|
|
|
|
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|