-
Notifications
You must be signed in to change notification settings - Fork 1
/
alert-config.php
284 lines (243 loc) · 10.9 KB
/
alert-config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/*
* Will add network wide settings for Rave Alert.
*/
add_action( 'network_admin_menu', 'ravealert_network_menu_settings');
function ravealert_network_menu_settings(){
add_menu_page ('Rave Alert', 'Rave Alert', 'manage_network', 'ravealert-settings', 'ravealert_network_settings');
}
function ravealert_network_settings() {
if ( is_multisite() && current_user_can('manage_network' ) ) {
?>
<div class="wrap">
<h1><?php _e( 'Rave Alert Settings', 'rave-alert-notification') ?></h1>
<?php
if ( isset( $_POST['action'] ) && $_POST['action'] === 'update_ravealert_settings' ) {
if ( ! check_admin_referer( 'rave_save_network_settings', 'rave_settings_save' ) ) {
echo '<div id="error" class="error fade"><p><strong>Security check failed. Please try again.</strong></p></div>';
die;
}
//store option values in a variable
$bc_rave_network_settings = $_POST['network_settings'];
//if choose to archive, throw error if archive site not chosen
$submit_message = "";
if ( isset( $bc_rave_network_settings["ravealert_do_archive"] ) && $bc_rave_network_settings["ravealert_do_archive"] === "true" && (
empty( $bc_rave_network_settings["ravealert_archive_site"] ) &&
empty( $bc_rave_network_settings["ravealert_archive_type"] )
) ) {
//since archive site not chosen, change archive option back to false before saving options
$bc_rave_network_settings["ravealert_do_archive"] = "false";
$submit_message = '<div id="error" class="error fade"><p><strong>Select a site for the Rave Alert archive.</strong></p></div>';
} else {
//otherwise assume it all went according to plan
$submit_message = '<div id="message" class="updated fade"><p><strong>Rave Alert network settings updated!</strong></p></div>';
}
// Unset Archive Site if Archive Type is CPT
if ( 'cpt' === $bc_rave_network_settings['ravealert_archive_type'] && "" !== $bc_rave_network_settings['ravealert_archive_site'] ) {
$bc_rave_network_settings['ravealert_archive_site'] = '';
}
//use array map and WP function to sanitize option values
$open_message = wp_kses_post( $bc_rave_network_settings["ravealert_college_openmessage"] );
$bc_rave_network_settings = array_map( 'sanitize_text_field', $bc_rave_network_settings );
//reset the college open message since it was sanitized differently to allow HTML but strip anything not allowed in WP posts
$bc_rave_network_settings["ravealert_college_openmessage"] = $open_message;
//save option values
update_site_option( 'ravealert_network_settings', $bc_rave_network_settings );
echo $submit_message;
}
?>
<form method="post">
<input type="hidden" name="action" value="update_ravealert_settings" />
<?php
$bc_rave_network_settings = get_site_option( 'ravealert_network_settings' );
$high_alert = $bc_rave_network_settings['high_alert'];
if( $high_alert == "true" ) {
$trueSelected = "checked";
} else {
$falseSelected = "checked";
}
$ravealert_college_openmessage = stripslashes( $bc_rave_network_settings['ravealert_college_openmessage'] );
$ravealert_xml_feedurl = $bc_rave_network_settings['ravealert_xml_feedurl'];
$teams_error_webhook_url = $bc_rave_network_settings['teams_error_webhook_url'];
$archive_alert = $bc_rave_network_settings['ravealert_do_archive'];
if( $archive_alert == "true" ) {
$true_archive_selected = "checked";
} else {
$false_archive_selected = "checked";
}
$archive_type = $bc_rave_network_settings['ravealert_archive_type'];
if ( $archive_type === "post" ) {
$ravealert_archive_type_post = "checked";
} else if ( $archive_type === "cpt" ) {
$ravealert_archive_type_cpt = "checked";
} else if ( $archive_type === "oho" ) {
$ravealert_archive_type_oho = "checked";
}
wp_nonce_field( 'rave_save_network_settings', 'rave_settings_save' );
?>
<h2>Manual Alert</h2>
<table class="form-table">
<tr valign="top">
<th scope="row">
<label for="high_alert">
Display Manual Alert
</label>
</th>
<td>
<input type="radio" name="network_settings[high_alert]" value="true" <?php echo $trueSelected ?? ""; ?> /> True
<input type="radio" name="network_settings[high_alert]" value="false" <?php echo $falseSelected ?? ""; ?>/> False
<p><small>Displays a manual alert on all sites in the network. Incoming Rave Alerts will override this message.</small></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="ravealert_college_openmessage">
Manual Alert Message
</label>
</th>
<td>
<textarea name="network_settings[ravealert_college_openmessage]" cols="78" ><?php echo $ravealert_college_openmessage; ?></textarea>
<p><small>Accepts basic html. Message should be wrapped in a div with the class col-xs-12, or other Bootstrap formatting as needed.</small></p>
</td>
</tr>
</table>
<hr>
<h2>Automated Alert Settings</h2>
<table class="form-table">
<tr valign="top">
<th scope="row">
<label for="ravealert_xml_feedurl">
XML Feed URL
</label>
</th>
<td>
<input name="network_settings[ravealert_xml_feedurl]" type='url' value='<?php echo $ravealert_xml_feedurl; ?>' style="width:100%;">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="teams_error_webhook_url">
Teams Error Webhook URL
</label>
</th>
<td>
<input name="network_settings[teams_error_webhook_url]" type='url' value='<?php echo $teams_error_webhook_url; ?>' style="width:100%;">
<p><small>URL to Teams webhook to send error messages to (leave blank to skip notification if something has gone wrong)</small></p>
</td>
<tr valign="top">
<th scope="row">
Archive Rave Alerts?
</th>
<td>
<label for="ravealert_do_archive_yes"><input type="radio" id="ravealert_do_archive_yes" name="network_settings[ravealert_do_archive]" value="true" <?php echo $true_archive_selected ?? ""; ?> /> Yes</label>
<label for="ravealert_do_archive_no"><input type="radio" id="ravealert_do_archive_no" name="network_settings[ravealert_do_archive]" value="false" <?php echo $false_archive_selected ?? "";?>/> No</label>
<p><small>Incoming alerts will create Posts or CPTs if enabled.</small></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
Archive Type
</th>
<td>
<label for="ravealert_archive_type_post"><input type="radio" id="ravealert_archive_type_post" name="network_settings[ravealert_archive_type]" value="post" <?php echo $ravealert_archive_type_post ?? ""; ?> /> Create Posts on a Site in the Network</label><br>
<label for="ravealert_archive_type_cpt"><input type="radio" id="ravealert_archive_type_cpt" name="network_settings[ravealert_archive_type]" value="cpt" <?php echo $ravealert_archive_type_cpt ?? ""; ?>/> Enable CPT for Alerts on Root Site in Network</label><br>
<label for="ravealert_archive_type_oho"><input type="radio" id="ravealert_archive_type_oho" name="network_settings[ravealert_archive_type]" value="oho" <?php echo $ravealert_archive_type_oho ?? ""; ?>/> Post to News site in OHO Theme</label>
<p><small>If archiving is enabled, how do you want alerts to be archived?</small></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="archive_site">
Archive Site
</label>
</th>
<td>
<select name="network_settings[ravealert_archive_site]" id="archive_site">
<option value=""></option>
<?php $net_sites = get_sites();
foreach( $net_sites as $net_site ) {
$site_selected = "";
if ( (null !== $bc_rave_network_settings["ravealert_archive_site"]) && $net_site->blog_id === $bc_rave_network_settings["ravealert_archive_site"]) {
$site_selected = "selected";
}
$blog_detail = get_blog_details($net_site->blog_id);
$blog_name = $blog_detail->blogname;
?>
<option value="<?php echo $net_site->blog_id; ?>" <?php echo $site_selected; ?>><?php echo $blog_name; ?></option>
<?php } ?>
</select>
<p><small>If archiving to Posts is enabled, which site should they be sent to?</small></p>
</td>
</tr>
</table>
<h3>OHO News Site Configuration</h3>
<p>If you chose to post to the News site in the OHO theme, you will need to configure the following settings.</p>
<table class="form-table">
<tr valign="top">
<th scope="row">
<label for="ravealert_oho_news_cpt">
OHO News CPT
</label>
</th>
<td>
<select name="network_settings[ravealert_oho_news_cpt]" id="ravealert_oho_news_cpt">
<option value=""></option>
<?php
switch_to_blog(SITE_ID_CURRENT_SITE);
$cpts = get_post_types( array( 'public' => true, '_builtin' => false ), 'names', 'and' );
foreach ( $cpts as $cpt ) {
$site_selected = "";
if ( (null !== $bc_rave_network_settings["ravealert_oho_news_cpt"]) && $cpt === $bc_rave_network_settings["ravealert_oho_news_cpt"]) {
$site_selected = "selected";
}
?>
<option value="<?php echo $cpt; ?>" <?php echo $site_selected; ?>><?php echo $cpt; ?></option>
<?php
}
restore_current_blog();
?>
</select>
<p><small>Which CPT is the News CPT in the OHO theme?</small></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="ravealert_oho_news_term">
Alert Term
</label>
</th>
<td>
<select name="network_settings[ravealert_oho_news_term]" id="ravealert_oho_news_term">
<option value=""></option>
<?php
switch_to_blog(SITE_ID_CURRENT_SITE);
$terms = get_terms( array( 'taxonomy' => 'news_type', 'hide_empty' => false, 'fields' => 'id=>name' ) );
foreach ( $terms as $term_id => $term_name ) {
$term_selected = "";
if ( (null !== $bc_rave_network_settings["ravealert_oho_news_term"]) && (String)$term_id === $bc_rave_network_settings["ravealert_oho_news_term"]) {
$term_selected = "selected";
}
?>
<option value="<?php echo $term_id; ?>" <?php echo $term_selected; ?>><?php echo $term_name; ?></option>
<?php
}
restore_current_blog();
?>
</select>
<p><small>Which Term should be used in the News Type taxonomy?</small></p>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" name="update_ravealert_settings" value="Save Settings" />
</p>
</form>
<?php
} else {
echo '<p>Please configure WP Multisite before using these settings. In addition, this page can only be accessed by a super admin.</p>';
/*Note: if your plugin is meant to be used also by single wordpress installations you would configure the settings page here, perhaps by calling a function.*/
}
?>
</div>
<?php
}//settings page function