AdminNotices.php
5 years ago
AjaxHandler.php
5 years ago
Autologin.php
5 years ago
BuddyPressBbPress.php
5 years ago
EditUserProfile.php
5 years ago
ExtensionManager.php
5 years ago
FileUploader.php
5 years ago
FormPreviewHandler.php
5 years ago
FormRepository.php
5 years ago
FormShortcodeDefaults.php
5 years ago
GDPR.php
5 years ago
GlobalSiteAccess.php
5 years ago
ImageUploader.php
5 years ago
LoginAuth.php
5 years ago
Miscellaneous.php
5 years ago
ModifyRedirectDefaultLinks.php
5 years ago
PPRESS_Session.php
5 years ago
PROFILEPRESS_sql.php
5 years ago
PasswordReset.php
5 years ago
ProfileUrlRewrite.php
5 years ago
RegistrationAuth.php
5 years ago
SendEmail.php
5 years ago
ShortcodeThemeFactory.php
5 years ago
UserAvatar.php
5 years ago
UserSignupLocationListingPage.php
5 years ago
UsernameEmailRestrictLogin.php
5 years ago
WelcomeEmailAfterSignup.php
5 years ago
default-email-template.php
5 years ago
index.php
5 years ago
GlobalSiteAccess.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Classes; |
| 4 | |
| 5 | class GlobalSiteAccess |
| 6 | { |
| 7 | public static function init() |
| 8 | { |
| 9 | // using wp hook because it precedes template_redirect which is used by Content protection redirect rules. |
| 10 | add_action('wp', array(__CLASS__, 'global_redirect'), -1); |
| 11 | } |
| 12 | |
| 13 | public static function global_redirect() |
| 14 | { |
| 15 | if (is_admin()) return; |
| 16 | |
| 17 | $access = ppress_get_setting('global_site_access', 'everyone', true); |
| 18 | |
| 19 | if ('login' != $access) return; |
| 20 | |
| 21 | $redirect_url = ppress_get_setting('global_site_access_redirect_page'); |
| 22 | $custom_redirect_url = ppress_get_setting('global_site_access_custom_redirect_page'); |
| 23 | |
| 24 | $excluded_pages = ppress_get_setting('global_site_access_exclude_pages', [], true); |
| 25 | |
| 26 | $excluded_pages = array_map('absint', array_filter( |
| 27 | array_merge($excluded_pages, [ |
| 28 | ppress_get_setting('set_login_url', false, true), |
| 29 | ppress_get_setting('set_registration_url', false, true), |
| 30 | ppress_get_setting('set_lost_password_url', false, true), |
| 31 | ]) |
| 32 | ) |
| 33 | ); |
| 34 | |
| 35 | $allow_homepage = ppress_get_setting('global_site_access_allow_homepage'); |
| 36 | |
| 37 | if ( ! empty($redirect_url)) { |
| 38 | $redirect_url = get_permalink(absint($redirect_url)); |
| 39 | } |
| 40 | |
| 41 | if ( ! empty($custom_redirect_url)) { |
| 42 | $redirect_url = $custom_redirect_url; |
| 43 | } |
| 44 | |
| 45 | if (empty($redirect_url)) return; |
| 46 | |
| 47 | $current_url = ppress_get_current_url_query_string(); |
| 48 | |
| 49 | // skip all wp-login urls. |
| 50 | if (strpos($current_url, 'wp-login.php') !== false) return; |
| 51 | |
| 52 | /** |
| 53 | * Exclude the redirect URL. |
| 54 | * strtok() remove all query strings and trailing slash. @see https://stackoverflow.com/a/6975045/2648410 |
| 55 | */ |
| 56 | if (strpos($current_url, untrailingslashit(strtok($redirect_url, '?'))) !== false) return; |
| 57 | |
| 58 | if ($allow_homepage == 'yes' && is_front_page()) return; |
| 59 | |
| 60 | if ( ! empty($excluded_pages) && is_page($excluded_pages)) return; |
| 61 | |
| 62 | if ( ! is_user_logged_in()) { |
| 63 | wp_safe_redirect($redirect_url); |
| 64 | exit; |
| 65 | } |
| 66 | } |
| 67 | } |