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 setting option name. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
*/ |
26
|
|
|
const OPTION_NAME = 'wp_site_monitor_enable'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The loader that's responsible for registering all hooks and filters. |
30
|
|
|
* |
31
|
|
|
* @var Hook_Loader |
32
|
|
|
* @since 1.0.0 |
33
|
|
|
*/ |
34
|
|
|
protected $loader; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Settings page slug. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
* @since 1.0.0 |
41
|
|
|
*/ |
42
|
|
|
protected $settings_page; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Setting options group name. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
* @since 1.0.0 |
49
|
|
|
*/ |
50
|
|
|
protected $option_group; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Initialise the plugin settings and menus. |
54
|
|
|
* |
55
|
|
|
* @since 1.0.0 |
56
|
|
|
*/ |
57
|
4 |
|
public function __construct() { |
58
|
4 |
|
$this->settings_page = 'wp_site_monitor'; |
59
|
4 |
|
$this->option_group = $this->settings_page; |
60
|
|
|
|
61
|
4 |
|
$this->loader = new Hook_Loader(); |
62
|
|
|
|
63
|
4 |
|
$this->loader->add_action( 'admin_init', $this, 'init_settings' ); |
64
|
4 |
|
$this->loader->add_action( 'admin_menu', $this, 'display_settings_page' ); |
65
|
|
|
|
66
|
4 |
|
$this->loader->run(); |
67
|
4 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Initialise plugin settings. |
71
|
|
|
* |
72
|
|
|
* @since 1.0.0 |
73
|
|
|
*/ |
74
|
3 |
|
public function init_settings() { |
75
|
3 |
|
register_setting( $this->option_group, self::OPTION_NAME ); |
76
|
|
|
|
77
|
3 |
|
add_settings_section( |
78
|
3 |
|
self::OPTION_NAME . '_section', |
79
|
3 |
|
__( 'Enable/Disable WP Site Monitor', 'wp-site-monitor' ), |
80
|
3 |
|
array( $this, 'setting_section_html' ), |
81
|
3 |
|
$this->settings_page |
82
|
3 |
|
); |
83
|
|
|
|
84
|
3 |
|
add_settings_field( |
85
|
3 |
|
self::OPTION_NAME, |
86
|
3 |
|
__( 'Enable WP Site Monitor', 'wp-site-monitor' ), |
87
|
3 |
|
array( $this, 'setting_input_html' ), |
88
|
3 |
|
$this->settings_page, |
89
|
3 |
|
self::OPTION_NAME . '_section' |
90
|
3 |
|
); |
91
|
3 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Display the admin settings page. |
95
|
|
|
* |
96
|
|
|
* @since 1.0.0 |
97
|
|
|
*/ |
98
|
1 |
|
public function display_settings_page() { |
99
|
1 |
|
add_options_page( |
100
|
1 |
|
__( 'WP Site Monitor Settings', 'wp-site-monitor' ), |
101
|
1 |
|
__( 'WP Site Monitor', 'wp-site-monitor' ), |
102
|
1 |
|
'manage_options', |
103
|
1 |
|
$this->settings_page, |
104
|
1 |
|
array( $this, 'settings_page_html' ) |
105
|
1 |
|
); |
106
|
1 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Settings page template. |
110
|
|
|
* |
111
|
|
|
* @since 1.0.0 |
112
|
|
|
*/ |
113
|
|
|
public function settings_page_html() { |
114
|
|
|
if ( ! current_user_can( 'manage_options' ) ) { |
115
|
|
|
return; |
116
|
|
|
} |
117
|
|
|
?> |
118
|
|
|
<div class="wrap"> |
119
|
|
|
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
120
|
|
|
<form action="options.php" method="POST"> |
121
|
|
|
<?php |
122
|
|
|
settings_fields( $this->option_group ); |
123
|
|
|
do_settings_sections( $this->settings_page ); |
124
|
|
|
submit_button(); |
125
|
|
|
?> |
126
|
|
|
</form> |
127
|
|
|
</div> |
128
|
|
|
<?php |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Form text. |
133
|
|
|
* |
134
|
|
|
* @param array $args Arguments passed into add_settings_section. |
135
|
|
|
* |
136
|
|
|
* @since 1.0.0 |
137
|
|
|
*/ |
138
|
|
|
public function setting_section_html( $args ) { |
139
|
|
|
?> |
140
|
|
|
<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> |
|
|
|
|
141
|
|
|
<?php |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Form inputs. |
146
|
|
|
* |
147
|
|
|
* @since 1.0.0 |
148
|
|
|
*/ |
149
|
|
|
public function setting_input_html() { |
150
|
|
|
?> |
151
|
|
|
<input type="checkbox" |
152
|
|
|
name="<?php esc_attr( self::OPTION_NAME ); ?>" |
|
|
|
|
153
|
|
|
id=""<?php checked( get_option( self::OPTION_NAME ), 1 ); ?> value="1"> |
154
|
|
|
|
155
|
|
|
<p class="description"> |
156
|
|
|
<?php esc_html_e( 'This checkbox enables/disables all plugin functionality.', 'wp-site-monitor' ); ?> |
157
|
|
|
</p> |
158
|
|
|
<?php |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.