Installer
3 years ago
AdminNotices.php
1 month ago
AjaxHandler.php
1 year ago
Autologin.php
9 months ago
BlockRegistrations.php
10 months ago
BuddyPressBbPress.php
3 years ago
DisableConcurrentLogins.php
2 years ago
EditUserProfile.php
5 months ago
ExtensionManager.php
1 month ago
FileUploader.php
3 months ago
FormPreviewHandler.php
5 months ago
FormRepository.php
1 year ago
FormShortcodeDefaults.php
1 month ago
GDPR.php
3 years ago
Geolocation.php
3 years ago
GlobalSiteAccess.php
3 years ago
ImageUploader.php
1 year ago
LoginAuth.php
1 year ago
Miscellaneous.php
3 years ago
ModifyRedirectDefaultLinks.php
5 months ago
PPRESS_Session.php
1 year ago
PROFILEPRESS_sql.php
1 year ago
PasswordReset.php
1 year ago
ProfileUrlRewrite.php
4 years ago
RegistrationAuth.php
1 week ago
SendEmail.php
3 years ago
ShortcodeThemeFactory.php
5 years ago
UserAvatar.php
1 year ago
UserSignupLocationListingPage.php
3 years ago
UsernameEmailRestrictLogin.php
4 years ago
WPProfileFieldParserTrait.php
1 year ago
WelcomeEmailAfterSignup.php
1 year ago
default-email-template.php
1 year ago
index.php
3 years ago
GlobalSiteAccess.php
82 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 | /** |
| 14 | * Exclude the redirect URL. |
| 15 | * strtok() remove all query strings and trailing slash. @see https://stackoverflow.com/a/6975045/2648410 |
| 16 | * |
| 17 | * @param $val |
| 18 | * |
| 19 | * @return string |
| 20 | */ |
| 21 | public static function remove_query_string_trailing_slash($val) |
| 22 | { |
| 23 | return untrailingslashit(strtok($val, '?')); |
| 24 | } |
| 25 | |
| 26 | public static function global_redirect() |
| 27 | { |
| 28 | if (is_admin()) return; |
| 29 | |
| 30 | $access = ppress_get_setting('global_site_access', 'everyone', true); |
| 31 | |
| 32 | if ('login' != $access) return; |
| 33 | |
| 34 | $redirect_url = $redirect_url_page_id = ppress_get_setting('global_site_access_redirect_page'); |
| 35 | $custom_redirect_url = ppress_get_setting('global_site_access_custom_redirect_page'); |
| 36 | |
| 37 | $excluded_pages = ppress_get_setting('global_site_access_exclude_pages', [], true); |
| 38 | |
| 39 | $excluded_pages = array_map('absint', array_filter( |
| 40 | array_merge($excluded_pages, [ |
| 41 | ppress_get_setting('set_login_url', false, true), |
| 42 | ppress_get_setting('set_registration_url', false, true), |
| 43 | ppress_get_setting('set_lost_password_url', false, true), |
| 44 | ]) |
| 45 | ) |
| 46 | ); |
| 47 | |
| 48 | $allow_homepage = ppress_get_setting('global_site_access_allow_homepage'); |
| 49 | |
| 50 | if ( ! empty($redirect_url)) { |
| 51 | |
| 52 | $redirect_url = get_permalink(absint($redirect_url)); |
| 53 | |
| 54 | if (ppress_get_setting('set_login_url') == $redirect_url_page_id) { |
| 55 | $redirect_url = add_query_arg('redirect_to', ppress_get_current_url_query_string(), $redirect_url); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if ( ! empty($custom_redirect_url)) { |
| 60 | $redirect_url = $custom_redirect_url; |
| 61 | } |
| 62 | |
| 63 | if (empty($redirect_url)) return; |
| 64 | |
| 65 | $current_url = ppress_get_current_url_query_string(); |
| 66 | |
| 67 | // skip all wp-login urls. |
| 68 | if (strpos($current_url, 'wp-login.php') !== false) return; |
| 69 | |
| 70 | if (self::remove_query_string_trailing_slash($current_url) == self::remove_query_string_trailing_slash($redirect_url)) return; |
| 71 | |
| 72 | if ($allow_homepage == 'yes' && is_front_page()) return; |
| 73 | |
| 74 | if ( ! empty($excluded_pages) && is_page($excluded_pages)) return; |
| 75 | |
| 76 | if ( ! is_user_logged_in()) { |
| 77 | nocache_headers(); |
| 78 | wp_safe_redirect($redirect_url); |
| 79 | exit; |
| 80 | } |
| 81 | } |
| 82 | } |