1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The admin-specific fields 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 fields 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_Field |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The ID of this plugin. |
24
|
|
|
* |
25
|
|
|
* @since 1.0.0 |
26
|
|
|
* @access private |
27
|
|
|
* @var string $plugin_name The ID of this plugin. |
28
|
|
|
*/ |
29
|
|
|
private $plugin_name; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The version of this plugin. |
33
|
|
|
* |
34
|
|
|
* @since 1.0.0 |
35
|
|
|
* @access private |
36
|
|
|
* @var string $version The current version of this plugin. |
37
|
|
|
*/ |
38
|
|
|
private $version; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The field options. |
42
|
|
|
* |
43
|
|
|
* @since 1.0.0 |
44
|
|
|
* @access private |
45
|
|
|
* @var array $options The plugin options. |
46
|
|
|
*/ |
47
|
|
|
private $options; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The admin field builder class |
51
|
|
|
* |
52
|
|
|
* @since 1.0.0 |
53
|
|
|
* @access private |
54
|
|
|
* @var WordPress_Security_Txt_Field $builder Field builder of this plugin |
55
|
|
|
*/ |
56
|
|
|
private $builder; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The fields this class can build. |
60
|
|
|
* |
61
|
|
|
* @since 1.0.0 |
62
|
|
|
* @access private |
63
|
|
|
* @var array $available_fields The fields this class can build. |
64
|
|
|
*/ |
65
|
|
|
private static $available_fields = [ |
66
|
|
|
'enable', |
67
|
|
|
'menu', |
68
|
|
|
'redirect', |
69
|
|
|
'contact', |
70
|
|
|
'encryption', |
71
|
|
|
'disclosure', |
72
|
|
|
'acknowledgement', |
73
|
|
|
'cache', |
74
|
|
|
'credits', |
75
|
|
|
'statistics', |
76
|
|
|
'debug', |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Initialize the class and set its properties. |
81
|
|
|
* |
82
|
|
|
* @since 1.0.0 |
83
|
|
|
* |
84
|
|
|
* @param string $plugin_name The name of this plugin. |
85
|
|
|
* @param string $version The version of this plugin. |
86
|
|
|
* @param array $options The options of this plugin. |
87
|
|
|
*/ |
88
|
|
|
public function __construct($plugin_name, $version, $options) |
89
|
|
|
{ |
90
|
|
|
$this->plugin_name = $plugin_name; |
91
|
|
|
$this->version = $version; |
92
|
|
|
$this->options = $options; |
93
|
|
|
$this->builder = new WordPress_Security_Txt_Builder($this->plugin_name, $this->version, $this->options); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns all the fields available in this class. |
98
|
|
|
* |
99
|
|
|
* @return array |
100
|
|
|
*/ |
101
|
|
|
public static function available_fields() |
102
|
|
|
{ |
103
|
|
|
return self::$available_fields; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Determines if a field is available in this class. |
108
|
|
|
* |
109
|
|
|
* @param string $name |
110
|
|
|
* |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
|
public static function field_available($name) |
114
|
|
|
{ |
115
|
|
|
return in_array($name, self::$available_fields, true); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Registers a specific field. |
120
|
|
|
* |
121
|
|
|
* @param string $name |
122
|
|
|
* |
123
|
|
|
* @return void |
124
|
|
|
*/ |
125
|
|
|
public function register_field($name) |
126
|
|
|
{ |
127
|
|
|
$this->$name(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Registers all available fields. |
132
|
|
|
* |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
public function register_all() |
136
|
|
|
{ |
137
|
|
|
foreach (self::$available_fields as $available_field) { |
138
|
|
|
$this->register_field($available_field); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Render the enable field. |
144
|
|
|
* |
145
|
|
|
* @return void |
146
|
|
|
*/ |
147
|
|
|
public function enable() |
148
|
|
|
{ |
149
|
|
|
add_settings_field( |
|
|
|
|
150
|
|
|
'enable', |
151
|
|
|
apply_filters($this->plugin_name . 'label-enable', esc_html__('Enable', $this->plugin_name)), |
|
|
|
|
152
|
|
|
[$this->builder, 'checkbox'], |
153
|
|
|
$this->plugin_name, |
154
|
|
|
$this->plugin_name . '-general', |
155
|
|
|
[ |
156
|
|
|
'description' => 'Serve ' . get_site_url() . '/.well-known/security.txt on your WordPress site.', |
|
|
|
|
157
|
|
|
'id' => 'enable', |
158
|
|
|
'value' => isset($this->options['enable']) ? $this->options['enable'] : false, |
159
|
|
|
] |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Render the menu field. |
165
|
|
|
* |
166
|
|
|
* @return void |
167
|
|
|
*/ |
168
|
|
|
public function menu() |
169
|
|
|
{ |
170
|
|
|
add_settings_field( |
|
|
|
|
171
|
|
|
'menu', |
172
|
|
|
apply_filters($this->plugin_name . 'label-menu', esc_html__('Menu', $this->plugin_name)), |
|
|
|
|
173
|
|
|
[$this->builder, 'checkbox'], |
174
|
|
|
$this->plugin_name, |
175
|
|
|
$this->plugin_name . '-general', |
176
|
|
|
[ |
177
|
|
|
'description' => 'Show security.txt menu at the top of the WordPress admin interface. You should turn this off after you have the plugin configured.', |
178
|
|
|
'id' => 'menu', |
179
|
|
|
'value' => isset($this->options['menu']) ? $this->options['menu'] : false, |
180
|
|
|
] |
181
|
|
|
); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Render the redirect field. |
186
|
|
|
* |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function redirect() |
190
|
|
|
{ |
191
|
|
|
add_settings_field( |
|
|
|
|
192
|
|
|
'redirect', |
193
|
|
|
apply_filters($this->plugin_name . 'label-redirect', esc_html__('Redirect', $this->plugin_name)), |
|
|
|
|
194
|
|
|
[$this->builder, 'checkbox'], |
195
|
|
|
$this->plugin_name, |
196
|
|
|
$this->plugin_name . '-general', |
197
|
|
|
[ |
198
|
|
|
'description' => 'Redirect requests for ' . get_site_url() . '/security.txt to ' . get_site_url() . '/.well-known/security.txt.', |
|
|
|
|
199
|
|
|
'id' => 'redirect', |
200
|
|
|
'class' => 'hide-when-disabled', |
201
|
|
|
'value' => isset($this->options['redirect']) ? $this->options['redirect'] : false, |
202
|
|
|
] |
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Render the contact field. |
208
|
|
|
* |
209
|
|
|
* @return void |
210
|
|
|
*/ |
211
|
|
|
public function contact() |
212
|
|
|
{ |
213
|
|
|
add_settings_field( |
|
|
|
|
214
|
|
|
'contact', |
215
|
|
|
apply_filters($this->plugin_name . 'label-contact', esc_html__('Contact', $this->plugin_name)), |
|
|
|
|
216
|
|
|
[$this->builder, 'text'], |
217
|
|
|
$this->plugin_name, |
218
|
|
|
$this->plugin_name . '-directives', |
219
|
|
|
[ |
220
|
|
|
'description' => 'Your contact address. Valid formats: e-mail, URL, phone number. (Required)', |
221
|
|
|
'id' => 'contact', |
222
|
|
|
'class' => 'text widefat hide-when-disabled', |
223
|
|
|
'value' => isset($this->options['contact']) ? $this->options['contact'] : false, |
224
|
|
|
'placeholder' => get_bloginfo('admin_email'), |
|
|
|
|
225
|
|
|
] |
226
|
|
|
); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Render the encryption field. |
231
|
|
|
* |
232
|
|
|
* @return void |
233
|
|
|
*/ |
234
|
|
|
public function encryption() |
235
|
|
|
{ |
236
|
|
|
add_settings_field( |
|
|
|
|
237
|
|
|
'encryption', |
238
|
|
|
apply_filters($this->plugin_name . 'label-encryption', esc_html__('Encryption', $this->plugin_name)), |
|
|
|
|
239
|
|
|
[$this->builder, 'textarea'], |
240
|
|
|
$this->plugin_name, |
241
|
|
|
$this->plugin_name . '-directives', |
242
|
|
|
[ |
243
|
|
|
'description' => 'Your GPG public key. (Optional)', |
244
|
|
|
'id' => 'encryption', |
245
|
|
|
'class' => 'large-text hide-when-disabled', |
246
|
|
|
'value' => isset($this->options['encryption']) ? $this->options['encryption'] : false, |
247
|
|
|
'rows' => 5, |
248
|
|
|
] |
249
|
|
|
); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Render the disclosure field. |
254
|
|
|
* |
255
|
|
|
* @return void |
256
|
|
|
*/ |
257
|
|
|
public function disclosure() |
258
|
|
|
{ |
259
|
|
|
add_settings_field( |
|
|
|
|
260
|
|
|
'disclosure', |
261
|
|
|
apply_filters($this->plugin_name . 'label-disclosure', esc_html__('Disclosure', $this->plugin_name)), |
|
|
|
|
262
|
|
|
[$this->builder, 'select'], |
263
|
|
|
$this->plugin_name, |
264
|
|
|
$this->plugin_name . '-directives', |
265
|
|
|
[ |
266
|
|
|
'description' => 'Your disclosure policy. (Optional)', |
267
|
|
|
'id' => 'disclosure', |
268
|
|
|
'class' => 'widefat hide-when-disabled', |
269
|
|
|
'value' => isset($this->options['disclosure']) ? $this->options['disclosure'] : 'default', |
270
|
|
|
'selections' => [ |
271
|
|
|
['value' => 'default', |
272
|
|
|
'label' => 'Default — do not include the "Disclosure" directive'], |
273
|
|
|
['value' => 'full', |
274
|
|
|
'label' => 'Full — you will fully disclose reports after the issue has been resolved'], |
275
|
|
|
['value' => 'partial', |
276
|
|
|
'label' => 'Partial — you will partially disclose reports after the issue has been resolved'], |
277
|
|
|
['value' => 'none', |
278
|
|
|
'label' => 'None — you do not want to disclose reports after the issue has been resolved'], |
279
|
|
|
], |
280
|
|
|
] |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Render the acknowledgement field. |
286
|
|
|
* |
287
|
|
|
* @return void |
288
|
|
|
*/ |
289
|
|
|
public function acknowledgement() |
290
|
|
|
{ |
291
|
|
|
add_settings_field( |
|
|
|
|
292
|
|
|
'acknowledgement', |
293
|
|
|
apply_filters($this->plugin_name . 'label-acknowledgement', |
|
|
|
|
294
|
|
|
esc_html__('Acknowledgement', $this->plugin_name)), |
|
|
|
|
295
|
|
|
[$this->builder, 'text'], |
296
|
|
|
$this->plugin_name, |
297
|
|
|
$this->plugin_name . '-directives', |
298
|
|
|
[ |
299
|
|
|
'description' => 'Your acknowledgements URL. (Optional)', |
300
|
|
|
'id' => 'acknowledgement', |
301
|
|
|
'class' => 'text widefat hide-when-disabled', |
302
|
|
|
'value' => isset($this->options['acknowledgement']) ? $this->options['acknowledgement'] : false, |
303
|
|
|
'placeholder' => get_site_url() . '/security-hall-of-fame/', |
|
|
|
|
304
|
|
|
] |
305
|
|
|
); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Render the cache field. |
310
|
|
|
* |
311
|
|
|
* @return void |
312
|
|
|
*/ |
313
|
|
|
public function cache() |
314
|
|
|
{ |
315
|
|
|
add_settings_field( |
|
|
|
|
316
|
|
|
'cache', |
317
|
|
|
apply_filters($this->plugin_name . 'label-cache', esc_html__('Cache', $this->plugin_name)), |
|
|
|
|
318
|
|
|
[$this->builder, 'checkbox'], |
319
|
|
|
$this->plugin_name, |
320
|
|
|
$this->plugin_name . '-library', |
321
|
|
|
[ |
322
|
|
|
'description' => 'Enable cacheing of your security.txt file.', |
323
|
|
|
'id' => 'cache', |
324
|
|
|
'class' => 'hide-when-disabled', |
325
|
|
|
'value' => isset($this->options['cache']) ? $this->options['cache'] : false, |
326
|
|
|
] |
327
|
|
|
); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Render the credits field. |
332
|
|
|
* |
333
|
|
|
* @return void |
334
|
|
|
*/ |
335
|
|
|
public function credits() |
336
|
|
|
{ |
337
|
|
|
add_settings_field( |
|
|
|
|
338
|
|
|
'credits', |
339
|
|
|
apply_filters($this->plugin_name . 'label-credits', esc_html__('Credits', $this->plugin_name)), |
|
|
|
|
340
|
|
|
[$this->builder, 'checkbox'], |
341
|
|
|
$this->plugin_name, |
342
|
|
|
$this->plugin_name . '-library', |
343
|
|
|
[ |
344
|
|
|
'description' => 'Enable credits at the bottom of your security.txt file.', |
345
|
|
|
'id' => 'credits', |
346
|
|
|
'class' => 'hide-when-disabled', |
347
|
|
|
'value' => isset($this->options['credits']) ? $this->options['credits'] : false, |
348
|
|
|
] |
349
|
|
|
); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Render the statistics field. |
354
|
|
|
* |
355
|
|
|
* @return void |
356
|
|
|
*/ |
357
|
|
|
public function statistics() |
358
|
|
|
{ |
359
|
|
|
add_settings_field( |
|
|
|
|
360
|
|
|
'statistics', |
361
|
|
|
apply_filters($this->plugin_name . 'label-statistics', esc_html__('Statistics', $this->plugin_name)), |
|
|
|
|
362
|
|
|
[$this->builder, 'checkbox'], |
363
|
|
|
$this->plugin_name, |
364
|
|
|
$this->plugin_name . '-library', |
365
|
|
|
[ |
366
|
|
|
'description_raw' => 'Allow anonymous collection of plugin usage statistics. <a href="?page=wordpress-security-txt-help#statistics">Learn more</a> about what is collected and how the data is used.', |
367
|
|
|
'id' => 'statistics', |
368
|
|
|
'class' => 'hide-when-disabled', |
369
|
|
|
'value' => isset($this->options['statistics']) ? $this->options['statistics'] : false, |
370
|
|
|
] |
371
|
|
|
); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Render the debug field. |
376
|
|
|
* |
377
|
|
|
* @return void |
378
|
|
|
*/ |
379
|
|
|
public function debug() |
380
|
|
|
{ |
381
|
|
|
add_settings_field( |
|
|
|
|
382
|
|
|
'debug', |
383
|
|
|
apply_filters($this->plugin_name . 'label-debug', esc_html__('Debug', $this->plugin_name)), |
|
|
|
|
384
|
|
|
[$this->builder, 'checkbox'], |
385
|
|
|
$this->plugin_name, |
386
|
|
|
$this->plugin_name . '-library', |
387
|
|
|
[ |
388
|
|
|
'description' => 'Enable debug at the bottom of your security.txt file & this page.', |
389
|
|
|
'id' => 'debug', |
390
|
|
|
'class' => 'hide-when-disabled', |
391
|
|
|
'value' => isset($this->options['debug']) ? $this->options['debug'] : false, |
392
|
|
|
] |
393
|
|
|
); |
394
|
|
|
} |
395
|
|
|
} |
396
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..