40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
if (!defined('ABSPATH')) exit;
|
|
|
|
if (!class_exists('Pausera')) return;
|
|
|
|
if (!method_exists('Pausera', 'handle_redirect')) {
|
|
Pausera::add_method('handle_redirect', function () {
|
|
$options = $this->options;
|
|
|
|
if (empty($options['enable_maintenance'])) return;
|
|
|
|
if (is_user_logged_in()) {
|
|
$user = wp_get_current_user();
|
|
foreach ($user->roles as $role) {
|
|
if (in_array($role, $options['excluded_roles'])) return;
|
|
}
|
|
}
|
|
|
|
if (in_array($_SERVER['REMOTE_ADDR'], $options['excluded_ips'])) return;
|
|
|
|
global $wp_query;
|
|
if (!$options['enable_maintenance'] && $wp_query->is_404()) return;
|
|
|
|
$current_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
|
|
$redirect_path = trim($options['redirect_url'], '/');
|
|
|
|
if ($current_path === $redirect_path) return;
|
|
|
|
foreach ($options['excluded_slugs'] as $slug) {
|
|
if (stripos($current_path, $slug) !== false) return;
|
|
}
|
|
|
|
if (!is_admin()) {
|
|
wp_redirect(home_url($options['redirect_url']));
|
|
exit;
|
|
}
|
|
});
|
|
}
|