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
|
4 |
|
public function init_settings() { |
26
|
4 |
|
register_setting( WP_Site_Monitor::OPTION_GROUP, WP_Site_Monitor::OPTION_NAME ); |
27
|
|
|
|
28
|
4 |
|
add_settings_section( |
29
|
4 |
|
WP_Site_Monitor::OPTION_NAME . '_section', |
30
|
4 |
|
__( 'Enable/Disable WP Site Monitor', 'wp-site-monitor' ), |
31
|
4 |
|
array( $this, 'setting_section_html' ), |
32
|
4 |
|
WP_Site_Monitor::OPTION_GROUP |
33
|
|
|
); |
34
|
|
|
|
35
|
4 |
|
add_settings_field( |
36
|
4 |
|
WP_Site_Monitor::OPTION_NAME, |
37
|
4 |
|
__( 'Enable WP Site Monitor', 'wp-site-monitor' ), |
38
|
4 |
|
array( $this, 'setting_input_html' ), |
39
|
4 |
|
WP_Site_Monitor::OPTION_GROUP, |
40
|
4 |
|
WP_Site_Monitor::OPTION_NAME . '_section' |
41
|
|
|
); |
42
|
4 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Display the admin settings page. |
46
|
|
|
* |
47
|
|
|
* @since 1.0.0 |
48
|
|
|
*/ |
49
|
1 |
|
public function display_settings_page() { |
50
|
1 |
|
add_options_page( |
51
|
1 |
|
__( 'WP Site Monitor Settings', 'wp-site-monitor' ), |
52
|
1 |
|
__( 'WP Site Monitor', 'wp-site-monitor' ), |
53
|
1 |
|
'manage_options', |
54
|
1 |
|
WP_Site_Monitor::OPTION_GROUP, |
55
|
1 |
|
array( $this, 'settings_page_html' ) |
56
|
|
|
); |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Settings page template. |
61
|
|
|
* |
62
|
|
|
* @since 1.0.0 |
63
|
|
|
*/ |
64
|
|
|
public function settings_page_html() { |
65
|
|
|
if ( ! current_user_can( 'manage_options' ) ) { |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
?> |
69
|
|
|
<div class="wrap"> |
70
|
|
|
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
71
|
|
|
<form action="options.php" method="POST"> |
72
|
|
|
<?php |
73
|
|
|
settings_fields( WP_Site_Monitor::OPTION_GROUP ); |
74
|
|
|
do_settings_sections( WP_Site_Monitor::OPTION_GROUP ); |
75
|
|
|
submit_button(); |
76
|
|
|
?> |
77
|
|
|
</form> |
78
|
|
|
</div> |
79
|
|
|
<?php |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Form text. |
84
|
|
|
* |
85
|
|
|
* @param array $args Arguments passed into add_settings_section. |
86
|
|
|
* |
87
|
|
|
* @since 1.0.0 |
88
|
|
|
*/ |
89
|
|
|
public function setting_section_html( $args ) { |
90
|
|
|
?> |
91
|
|
|
<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> |
92
|
|
|
<?php |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Form inputs. |
97
|
|
|
* |
98
|
|
|
* @since 1.0.0 |
99
|
|
|
*/ |
100
|
|
|
public function setting_input_html() { |
101
|
|
|
?> |
102
|
|
|
<input type="checkbox" |
103
|
|
|
id="<?php echo esc_attr( WP_Site_Monitor::OPTION_NAME ); ?>" |
104
|
|
|
name="<?php echo esc_attr( WP_Site_Monitor::OPTION_NAME ); ?>" |
105
|
|
|
<?php checked( get_option( WP_Site_Monitor::OPTION_NAME ), 1 ); ?> value="1"> |
106
|
|
|
|
107
|
|
|
<p class="description"> |
108
|
|
|
<?php esc_html_e( 'This checkbox enables/disables all plugin functionality.', 'wp-site-monitor' ); ?> |
109
|
|
|
</p> |
110
|
|
|
<?php |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|