-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-settings-example
More file actions
65 lines (54 loc) · 1.76 KB
/
Copy pathsimple-settings-example
File metadata and controls
65 lines (54 loc) · 1.76 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
<?php
/**
* Plugin Name: Simple Settings Example
* Description: Minimal settings page with one text field.
* Version: 1.0
*/
if (!defined('ABSPATH')) {
exit;
}
class SimpleSettingsExample {
private $option_name = 'simple_settings_example_text';
public function __construct() {
add_action('admin_menu', [$this, 'register_settings_page']);
add_action('admin_init', [$this, 'register_settings']);
}
public function register_settings_page() {
add_options_page(
'Simple Settings',
'Simple Settings',
'manage_options',
'simple-settings-example',
[$this, 'render_settings_page']
);
}
public function register_settings() {
register_setting('simple_settings_group', $this->option_name);
}
public function render_settings_page() {
?>
<div class="wrap">
<h1>Simple Settings</h1>
<form method="post" action="options.php">
<?php
settings_fields('simple_settings_group');
$value = get_option($this->option_name, '');
?>
<table class="form-table">
<tr>
<th scope="row">Text option</th>
<td>
<input type="text"
name="<?php echo esc_attr($this->option_name); ?>"
value="<?php echo esc_attr($value); ?>"
class="regular-text">
</td>
</tr>
</table>
<?php submit_button('Save Settings'); ?>
</form>
</div>
<?php
}
}
new SimpleSettingsExample();