public function toggle_check()
{
// Bail if current user doesn't have cap.
if (!current_user_can('manage_options')) {
return;
}
// Set a sanitized variable of our potential nonce and request.
$nonce = isset($_GET['airmde_nonce']) ? sanitize_key($_GET['airmde_nonce']) : '';
$switch = isset($_REQUEST['airplane-mode']) ? sanitize_key($_REQUEST['airplane-mode']) : '';
// Check for our nonce.
if (empty($nonce) || !wp_verify_nonce($nonce, 'airmde_nonce')) {
return;
}
// Now check for our query string.
if (empty($switch) || !in_array($switch, array('on', 'off'))) {
return;
}
// Delete old per-site option.
delete_option('airplane-mode');
// Update the setting.
update_site_option('airplane-mode', sanitize_key($_REQUEST['airplane-mode']));
// Fire action to allow for functions to run on status change.
do_action('airplane_mode_status_change', $switch);
// And go about our business.
wp_redirect(self::get_redirect());
exit;
}