1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Register all settings and menus for the plugin. |
4
|
|
|
* |
5
|
|
|
* @package WPSiteMonitor |
6
|
|
|
* @link https://github.com/BWibrew/WP-Site-Monitor/ |
7
|
|
|
* @author Benjamin Wibrew <[email protected]> |
8
|
|
|
* @since 1.0.0 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace WPSiteMonitor; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Settings_Menu |
15
|
|
|
* |
16
|
|
|
* @package WPSiteMonitor |
17
|
|
|
*/ |
18
|
|
|
class Settings_Menu { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The loader that's responsible for registering all hooks and filters. |
22
|
|
|
* |
23
|
|
|
* @var Hook_Loader |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
*/ |
26
|
|
|
protected $loader; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Settings page slug. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
* @since 1.0.0 |
33
|
|
|
*/ |
34
|
|
|
protected $settings_page; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Setting options group name. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
* @since 1.0.0 |
41
|
|
|
*/ |
42
|
|
|
protected $option_group; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Initialise the plugin settings and menus. |
46
|
|
|
* |
47
|
|
|
* @since 1.0.0 |
48
|
|
|
*/ |
49
|
|
|
public function __construct() { |
50
|
|
|
$this->settings_page = 'wp_site_monitor'; |
51
|
|
|
$this->option_group = $this->settings_page; |
52
|
|
|
|
53
|
|
|
require_once WPSM_PATH . 'src/class-hook-loader.php'; |
54
|
|
|
$this->loader = new Hook_Loader(); |
55
|
|
|
|
56
|
|
|
$this->loader->add_action( 'admin_init', $this, 'init_settings' ); |
57
|
|
|
$this->loader->add_action( 'admin_menu', $this, 'display_settings_page' ); |
58
|
|
|
|
59
|
|
|
$this->loader->run(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initialise plugin settings. |
64
|
|
|
* |
65
|
|
|
* @since 1.0.0 |
66
|
|
|
*/ |
67
|
|
|
public function init_settings() { |
68
|
|
|
register_setting( $this->option_group, 'wp_site_monitor_test_option' ); |
69
|
|
|
|
70
|
|
|
add_settings_section( |
71
|
|
|
'wp_site_monitor', |
72
|
|
|
__( 'Available API data', 'wp-site-monitor' ), |
73
|
|
|
array( $this, 'setting_section_html' ), |
74
|
|
|
$this->settings_page |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
add_settings_field( |
78
|
|
|
'wp_site_monitor_test_option', |
79
|
|
|
__( 'Test Input', 'wp-site-monitor' ), |
80
|
|
|
array( $this, 'setting_input_html' ), |
81
|
|
|
$this->settings_page, |
82
|
|
|
'wp_site_monitor', |
83
|
|
|
[ |
84
|
|
|
'label_for' => 'wporg_field_pill', |
85
|
|
|
'class' => 'wporg_row', |
86
|
|
|
'wporg_custom_data' => 'custom', |
87
|
|
|
] |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Display the admin settings page. |
93
|
|
|
* |
94
|
|
|
* @since 1.0.0 |
95
|
|
|
*/ |
96
|
|
|
public function display_settings_page() { |
97
|
|
|
add_options_page( |
98
|
|
|
__( 'WP Site Monitor Settings', 'wp-site-monitor' ), |
99
|
|
|
__( 'WP Site Monitor', 'wp-site-monitor' ), |
100
|
|
|
'manage_options', |
101
|
|
|
$this->settings_page, |
102
|
|
|
array( $this, 'settings_page_html' ) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Settings page template. |
108
|
|
|
* |
109
|
|
|
* @since 1.0.0 |
110
|
|
|
*/ |
111
|
|
|
public function settings_page_html() { |
112
|
|
|
if ( ! current_user_can( 'manage_options' ) ) { |
113
|
|
|
return; |
114
|
|
|
} |
115
|
|
|
?> |
116
|
|
|
<div class="wrap"> |
117
|
|
|
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
118
|
|
|
<form action="options.php" method="POST"> |
119
|
|
|
<?php |
120
|
|
|
settings_fields( $this->option_group ); |
121
|
|
|
do_settings_sections( $this->settings_page ); |
122
|
|
|
submit_button(); |
123
|
|
|
?> |
124
|
|
|
</form> |
125
|
|
|
</div> |
126
|
|
|
<?php |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Form text. |
131
|
|
|
* |
132
|
|
|
* @param array $args Arguments passed into add_settings_section. |
133
|
|
|
* |
134
|
|
|
* @since 1.0.0 |
135
|
|
|
*/ |
136
|
|
|
public function setting_section_html( $args ) { |
137
|
|
|
?> |
138
|
|
|
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Use these options to control which extra data is available over the REST API.', 'wp-site-monitor' ); ?></p> |
139
|
|
|
<?php |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Form inputs. |
144
|
|
|
* |
145
|
|
|
* @param array $args Element parameters. |
146
|
|
|
* |
147
|
|
|
* @since 1.0.0 |
148
|
|
|
*/ |
149
|
|
|
public function setting_input_html( $args ) { |
|
|
|
|
150
|
|
|
?> |
151
|
|
|
<input type="text" |
152
|
|
|
name="wp_site_monitor_test_option" |
153
|
|
|
id="wp_site_monitor_test_option" |
154
|
|
|
value="<?php echo get_option( 'wp_site_monitor_test_option' ) ? esc_attr( get_option( 'wp_site_monitor_test_option' ) ) : ''; ?>" /> |
155
|
|
|
|
156
|
|
|
<p class="description"> |
157
|
|
|
<?php esc_html_e( 'This is a test setting', 'wp-site-monitor' ); ?> |
158
|
|
|
</p> |
159
|
|
|
<?php |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.