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
|
|
|
* Initialise plugin settings. |
22
|
|
|
* |
23
|
|
|
* @since 1.0.0 |
24
|
|
|
*/ |
25
|
16 |
|
public function init_settings() { |
26
|
16 |
|
register_setting( WP_Site_Monitor::OPTION_GROUP, WP_Site_Monitor::OPTION_NAMES['enable'] ); |
27
|
16 |
|
register_setting( WP_Site_Monitor::OPTION_GROUP, WP_Site_Monitor::OPTION_NAMES['wp_version'] ); |
28
|
16 |
|
register_setting( WP_Site_Monitor::OPTION_GROUP, WP_Site_Monitor::OPTION_NAMES['plugins'] ); |
29
|
|
|
|
30
|
16 |
|
add_settings_section( |
31
|
16 |
|
WP_Site_Monitor::OPTION_NAMES['enable'] . '_section', |
32
|
16 |
|
__( 'Enable/Disable WP Site Monitor', 'wp-site-monitor' ), |
33
|
16 |
|
array( $this, 'setting_section_enable_html' ), |
34
|
16 |
|
WP_Site_Monitor::OPTION_GROUP |
35
|
|
|
); |
36
|
|
|
|
37
|
16 |
|
add_settings_section( |
38
|
16 |
|
WP_Site_Monitor::OPTION_GROUP . '_endpoints_section', |
39
|
16 |
|
__( 'API endpoints', 'wp-site-monitor' ), |
40
|
16 |
|
array( $this, 'setting_section_endpoints_html' ), |
41
|
16 |
|
WP_Site_Monitor::OPTION_GROUP |
42
|
|
|
); |
43
|
|
|
|
44
|
16 |
|
add_settings_field( |
45
|
16 |
|
WP_Site_Monitor::OPTION_NAMES['enable'], |
46
|
16 |
|
__( 'Enable WP Site Monitor', 'wp-site-monitor' ), |
47
|
16 |
|
array( $this, 'setting_enable_input_html' ), |
48
|
16 |
|
WP_Site_Monitor::OPTION_GROUP, |
49
|
16 |
|
WP_Site_Monitor::OPTION_NAMES['enable'] . '_section' |
50
|
|
|
); |
51
|
|
|
|
52
|
16 |
|
add_settings_field( |
53
|
16 |
|
WP_Site_Monitor::OPTION_NAMES['wp_version'], |
54
|
16 |
|
__( 'Enable wp_version endpoint', 'wp-site-monitor' ), |
55
|
16 |
|
array( $this, 'setting_wp_version_input_html' ), |
56
|
16 |
|
WP_Site_Monitor::OPTION_GROUP, |
57
|
16 |
|
WP_Site_Monitor::OPTION_GROUP . '_endpoints_section' |
58
|
|
|
); |
59
|
|
|
|
60
|
16 |
|
add_settings_field( |
61
|
16 |
|
WP_Site_Monitor::OPTION_NAMES['plugins'], |
62
|
16 |
|
__( 'Enable plugins endpoint', 'wp-site-monitor' ), |
63
|
16 |
|
array( $this, 'setting_plugins_input_html' ), |
64
|
16 |
|
WP_Site_Monitor::OPTION_GROUP, |
65
|
16 |
|
WP_Site_Monitor::OPTION_GROUP . '_endpoints_section' |
66
|
|
|
); |
67
|
16 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Display the admin settings page. |
71
|
|
|
* |
72
|
|
|
* @since 1.0.0 |
73
|
|
|
*/ |
74
|
1 |
|
public function display_settings_page() { |
75
|
1 |
|
add_options_page( |
76
|
1 |
|
__( 'WP Site Monitor Settings', 'wp-site-monitor' ), |
77
|
1 |
|
__( 'WP Site Monitor', 'wp-site-monitor' ), |
78
|
1 |
|
'manage_options', |
79
|
1 |
|
WP_Site_Monitor::OPTION_GROUP, |
80
|
1 |
|
array( $this, 'settings_page_html' ) |
81
|
|
|
); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Settings page template. |
86
|
|
|
* |
87
|
|
|
* @since 1.0.0 |
88
|
|
|
*/ |
89
|
3 |
|
public function settings_page_html() { |
90
|
3 |
|
if ( ! current_user_can( 'manage_options' ) ) { |
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
|
94
|
3 |
|
require_once WPSM_PATH . 'templates/settings-page.php'; |
95
|
3 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Enable setting form text. |
99
|
|
|
* |
100
|
|
|
* @param array $args Arguments passed into add_settings_section. |
101
|
|
|
* |
102
|
|
|
* @since 1.0.0 |
103
|
|
|
*/ |
104
|
2 |
|
public function setting_section_enable_html( $args ) { |
105
|
2 |
|
require_once WPSM_PATH . 'templates/setting-section-enable.php'; |
106
|
2 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Endpoints setting form text. |
110
|
|
|
* |
111
|
|
|
* @param array $args Arguments passed into add_settings_section. |
112
|
|
|
* |
113
|
|
|
* @since 1.0.0 |
114
|
|
|
*/ |
115
|
2 |
|
public function setting_section_endpoints_html( $args ) { |
116
|
2 |
|
require_once WPSM_PATH . 'templates/setting-section-endpoints.php'; |
117
|
2 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Enable setting form input. |
121
|
|
|
* |
122
|
|
|
* @since 1.0.0 |
123
|
|
|
*/ |
124
|
2 |
|
public function setting_enable_input_html() { |
125
|
2 |
|
require_once WPSM_PATH . 'templates/setting-input-enable.php'; |
126
|
2 |
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* WP_version setting form input. |
130
|
|
|
* |
131
|
|
|
* @since 1.0.0 |
132
|
|
|
*/ |
133
|
2 |
|
public function setting_wp_version_input_html() { |
134
|
2 |
|
require_once WPSM_PATH . 'templates/setting-input-wp-version.php'; |
135
|
2 |
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Plugins setting form input. |
139
|
|
|
* |
140
|
|
|
* @since 1.0.0 |
141
|
|
|
*/ |
142
|
2 |
|
public function setting_plugins_input_html() { |
143
|
2 |
|
require_once WPSM_PATH . 'templates/setting-input-plugins.php'; |
144
|
2 |
|
} |
145
|
|
|
} |
146
|
|
|
|