1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The core plugin class. |
4
|
|
|
* |
5
|
|
|
* This is used to define internationalization, admin-specific hooks, and |
6
|
|
|
* public-facing site hooks. |
7
|
|
|
* |
8
|
|
|
* Also maintains the unique identifier of this plugin as well as the current |
9
|
|
|
* version of the plugin. |
10
|
|
|
* |
11
|
|
|
* @package WPSiteMonitor |
12
|
|
|
* @link https://github.com/BWibrew/WP-Site-Monitor/ |
13
|
|
|
* @author Benjamin Wibrew <[email protected]> |
14
|
|
|
* @since 1.0.0 |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace WPSiteMonitor; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class WP_Site_Monitor |
21
|
|
|
* |
22
|
|
|
* @package WPSiteMonitor |
23
|
|
|
*/ |
24
|
|
|
class WP_Site_Monitor { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The loader that's responsible for registering all hooks and filters. |
28
|
|
|
* |
29
|
|
|
* @var Hook_Loader $loader Maintains and registers all hooks for the plugin. |
30
|
|
|
* @since 1.0.0 |
31
|
|
|
*/ |
32
|
|
|
protected $loader; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Define the core functionality of the plugin. |
36
|
|
|
* |
37
|
|
|
* @since 1.0.0 |
38
|
|
|
*/ |
39
|
|
|
public function __construct() { |
40
|
|
|
$this->init(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Initialise plugin files. |
45
|
|
|
* |
46
|
|
|
* @since 1.0.0 |
47
|
|
|
*/ |
48
|
|
|
public function init() { |
49
|
|
|
require_once WPSM_PATH . 'src/class-hook-loader.php'; |
50
|
|
|
$this->loader = new Hook_Loader(); |
51
|
|
|
|
52
|
|
|
if ( is_admin() ) { |
|
|
|
|
53
|
|
|
$this->loader->add_action( 'admin_menu', $this, 'display_settings_page' ); |
54
|
|
|
$this->loader->add_action( 'admin_init', $this, 'init_settings' ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->loader->run(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Fired during plugin activation. |
62
|
|
|
* |
63
|
|
|
* @since 1.0.0 |
64
|
|
|
*/ |
65
|
|
|
public static function activate() { |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Fired during plugin deactivation, |
70
|
|
|
* |
71
|
|
|
* @since 1.0.0 |
72
|
|
|
*/ |
73
|
|
|
public static function deactivate() { |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Fired during plugin deletion. |
78
|
|
|
* |
79
|
|
|
* @since 1.0.0 |
80
|
|
|
*/ |
81
|
|
|
public static function uninstall() { |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Display the admin settings page. |
86
|
|
|
* |
87
|
|
|
* @since 1.0.0 |
88
|
|
|
*/ |
89
|
|
|
public function display_settings_page() { |
90
|
|
|
add_options_page( |
|
|
|
|
91
|
|
|
__( 'WP Site Monitor Settings', 'wp-site-monitor' ), |
|
|
|
|
92
|
|
|
__( 'WP Site Monitor', 'wp-site-monitor' ), |
93
|
|
|
'manage_options', |
94
|
|
|
'wp_site_monitor', |
95
|
|
|
array( $this, 'settings_page_html' ) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Settings page template. |
101
|
|
|
* |
102
|
|
|
* @since 1.0.0 |
103
|
|
|
*/ |
104
|
|
|
public function settings_page_html() { |
105
|
|
|
if ( ! current_user_can( 'manage_options' ) ) { |
|
|
|
|
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
?> |
109
|
|
|
<div class="wrap"> |
110
|
|
|
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
|
|
|
111
|
|
|
<form action="options.php" method="POST"> |
112
|
|
|
<?php |
113
|
|
|
settings_fields( 'wp_site_monitor_group' ); |
|
|
|
|
114
|
|
|
do_settings_sections( 'wp_site_monitor' ); |
|
|
|
|
115
|
|
|
submit_button( 'Save Settings' ); |
|
|
|
|
116
|
|
|
?> |
117
|
|
|
</form> |
118
|
|
|
</div> |
119
|
|
|
<?php |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Initialise plugin settings. |
124
|
|
|
* |
125
|
|
|
* @since 1.0.0 |
126
|
|
|
*/ |
127
|
|
|
public function init_settings() { |
128
|
|
|
register_setting( 'wp_site_monitor_group', 'wp_site_monitor_option', 'string' ); |
|
|
|
|
129
|
|
|
|
130
|
|
|
add_settings_section( |
|
|
|
|
131
|
|
|
'wp_site_monitor_section_id', |
132
|
|
|
__( 'WP Site Monitor Settings', 'wp-site-monitor' ), |
|
|
|
|
133
|
|
|
array( $this, 'setting_section_html' ), |
134
|
|
|
'wp_site_monitor' |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
add_settings_field( |
|
|
|
|
138
|
|
|
'wp_site_monitor_option_id', |
139
|
|
|
__( 'Some Input', 'wp-site-monitor' ), |
140
|
|
|
array( $this, 'setting_input_html' ), |
141
|
|
|
'wp_site_monitor', |
142
|
|
|
'wp_site_monitor_section_id', |
143
|
|
|
[ |
144
|
|
|
'label_for' => 'wporg_field_pill', |
145
|
|
|
'class' => 'wporg_row', |
146
|
|
|
'wporg_custom_data' => 'custom', |
147
|
|
|
] |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Form text. |
153
|
|
|
* |
154
|
|
|
* @param array $args Arguments passed into add_settings_section. |
155
|
|
|
* |
156
|
|
|
* @since 1.0.0 |
157
|
|
|
*/ |
158
|
|
|
public function setting_section_html( $args ) { |
159
|
|
|
?> |
160
|
|
|
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'WP Site Monitor settings text', 'wp-site-monitor' ); ?></p> |
|
|
|
|
161
|
|
|
<?php |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Form inputs. |
166
|
|
|
* |
167
|
|
|
* @param array $args Element parameters. |
168
|
|
|
* |
169
|
|
|
* @since 1.0.0 |
170
|
|
|
*/ |
171
|
|
|
public function setting_input_html( $args ) { |
172
|
|
|
$options = get_option( 'wp_site_monitor' ); |
|
|
|
|
173
|
|
|
?> |
174
|
|
|
<select id="<?php echo esc_attr( $args['label_for'] ); ?>" |
|
|
|
|
175
|
|
|
data-custom="<?php echo esc_attr( $args['wporg_custom_data'] ); ?>" |
176
|
|
|
name="wporg_options[<?php echo esc_attr( $args['label_for'] ); ?>]" |
177
|
|
|
> |
178
|
|
|
<option value="red" <?php echo isset( $options[ $args['label_for'] ] ) ? ( selected( $options[ $args['label_for'] ], 'red', false ) ) : ( '' ); ?>> |
|
|
|
|
179
|
|
|
<?php esc_html_e( 'red pill', 'wporg' ); ?> |
|
|
|
|
180
|
|
|
</option> |
181
|
|
|
<option value="blue" <?php echo isset( $options[ $args['label_for'] ] ) ? ( selected( $options[ $args['label_for'] ], 'blue', false ) ) : ( '' ); ?>> |
182
|
|
|
<?php esc_html_e( 'blue pill', 'wporg' ); ?> |
183
|
|
|
</option> |
184
|
|
|
</select> |
185
|
|
|
<p class="description"> |
186
|
|
|
<?php esc_html_e( 'You take the blue pill and the story ends. You wake in your bed and you believe whatever you want to believe.', 'wporg' ); ?> |
187
|
|
|
</p> |
188
|
|
|
<p class="description"> |
189
|
|
|
<?php esc_html_e( 'You take the red pill and you stay in Wonderland and I show you how deep the rabbit-hole goes.', 'wporg' ); ?> |
190
|
|
|
</p> |
191
|
|
|
<?php |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|