@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | namespace Subway; |
21 | 21 | |
22 | 22 | if (! defined('ABSPATH') ) { |
23 | - return; |
|
23 | + return; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -36,114 +36,114 @@ discard block |
||
36 | 36 | final class PageRedirect |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * Redirects pages into our login page. |
|
41 | - * |
|
42 | - * @return void. |
|
43 | - */ |
|
44 | - public static function index() |
|
45 | - { |
|
46 | - |
|
47 | - // Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
|
48 | - // Callback function/method must return true (boolean) to disable redirect. |
|
49 | - $should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
|
50 | - |
|
51 | - if ( $should_exit ) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - // Only execute for non logged in users. |
|
56 | - if (is_user_logged_in() ) { |
|
57 | - return; |
|
58 | - } |
|
59 | - |
|
60 | - $queried_id = get_queried_object_id(); |
|
61 | - |
|
62 | - $current_post = get_post(absint($queried_id)); |
|
63 | - |
|
64 | - $login_page_id = absint(get_option('subway_login_page')); |
|
65 | - |
|
66 | - $excluded_page = Options::getPublicPostsIdentifiers(); |
|
67 | - |
|
68 | - // Already escaped inside 'subway_get_redirect_page_url'. |
|
69 | - $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
|
70 | - |
|
71 | - // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
|
72 | - |
|
73 | - // Turn off if is in 'wc-ajax' (woocommerce) |
|
74 | - if ( function_exists( 'is_ajax') ) { |
|
75 | - if ( is_ajax() ) { |
|
76 | - return; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - // Same for normal ajax requests. |
|
81 | - if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
82 | - return; |
|
83 | - } |
|
84 | - |
|
85 | - // Exit if site is public. |
|
86 | - if (Options::isPublicSite() ) { |
|
87 | - return; |
|
88 | - } |
|
89 | - |
|
90 | - // Check if redirect page is empty or not. |
|
91 | - if (empty($redirect_page) ) { |
|
92 | - return; |
|
93 | - } |
|
94 | - |
|
95 | - // Check if buddypress activate page. |
|
96 | - if (function_exists('bp_is_activation_page') ) { |
|
97 | - if (bp_is_activation_page() ) { |
|
98 | - return; |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - // Check if buddypress registration page. |
|
103 | - if (function_exists('bp_is_register_page') ) { |
|
104 | - if (bp_is_register_page() ) { |
|
105 | - return; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - // Assign 0 value to empty $post->ID to prevent exception. |
|
110 | - // This applies to custom WordPress pages such as BP Members Page and Groups. |
|
111 | - if (empty($current_post) ) { |
|
112 | - $current_post = new \stdclass; |
|
113 | - $current_post->ID = 0; |
|
114 | - } |
|
115 | - |
|
116 | - $current_page_id = absint($current_post->ID); |
|
117 | - |
|
118 | - // Check if $current_page_id && $selected_blog_id is equal to each other. |
|
119 | - // Get the page ID instead of global $post->ID that the query returns. |
|
120 | - // The ID of the first post object inside the loop is not correct. |
|
121 | - $blog_id = absint(get_option('page_for_posts')); |
|
122 | - |
|
123 | - if (is_home() ) { |
|
124 | - if ($blog_id === $login_page_id ) { |
|
125 | - $current_page_id = $blog_id; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - // Only execute the script for non-loggedin visitors. |
|
130 | - if (! is_user_logged_in() ) { |
|
131 | - |
|
132 | - if ($current_page_id !== $login_page_id ) { |
|
133 | - |
|
134 | - if (! in_array($current_page_id, $excluded_page, true) ) { |
|
135 | - |
|
136 | - wp_safe_redirect( |
|
137 | - add_query_arg( |
|
138 | - array( '_redirected' => 'yes' ), |
|
139 | - $redirect_page |
|
140 | - ) |
|
141 | - ); |
|
142 | - |
|
143 | - Helpers::close(); |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
39 | + /** |
|
40 | + * Redirects pages into our login page. |
|
41 | + * |
|
42 | + * @return void. |
|
43 | + */ |
|
44 | + public static function index() |
|
45 | + { |
|
46 | + |
|
47 | + // Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
|
48 | + // Callback function/method must return true (boolean) to disable redirect. |
|
49 | + $should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
|
50 | + |
|
51 | + if ( $should_exit ) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + // Only execute for non logged in users. |
|
56 | + if (is_user_logged_in() ) { |
|
57 | + return; |
|
58 | + } |
|
59 | + |
|
60 | + $queried_id = get_queried_object_id(); |
|
61 | + |
|
62 | + $current_post = get_post(absint($queried_id)); |
|
63 | + |
|
64 | + $login_page_id = absint(get_option('subway_login_page')); |
|
65 | + |
|
66 | + $excluded_page = Options::getPublicPostsIdentifiers(); |
|
67 | + |
|
68 | + // Already escaped inside 'subway_get_redirect_page_url'. |
|
69 | + $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
|
70 | + |
|
71 | + // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
|
72 | + |
|
73 | + // Turn off if is in 'wc-ajax' (woocommerce) |
|
74 | + if ( function_exists( 'is_ajax') ) { |
|
75 | + if ( is_ajax() ) { |
|
76 | + return; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + // Same for normal ajax requests. |
|
81 | + if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
82 | + return; |
|
83 | + } |
|
84 | + |
|
85 | + // Exit if site is public. |
|
86 | + if (Options::isPublicSite() ) { |
|
87 | + return; |
|
88 | + } |
|
89 | + |
|
90 | + // Check if redirect page is empty or not. |
|
91 | + if (empty($redirect_page) ) { |
|
92 | + return; |
|
93 | + } |
|
94 | + |
|
95 | + // Check if buddypress activate page. |
|
96 | + if (function_exists('bp_is_activation_page') ) { |
|
97 | + if (bp_is_activation_page() ) { |
|
98 | + return; |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + // Check if buddypress registration page. |
|
103 | + if (function_exists('bp_is_register_page') ) { |
|
104 | + if (bp_is_register_page() ) { |
|
105 | + return; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + // Assign 0 value to empty $post->ID to prevent exception. |
|
110 | + // This applies to custom WordPress pages such as BP Members Page and Groups. |
|
111 | + if (empty($current_post) ) { |
|
112 | + $current_post = new \stdclass; |
|
113 | + $current_post->ID = 0; |
|
114 | + } |
|
115 | + |
|
116 | + $current_page_id = absint($current_post->ID); |
|
117 | + |
|
118 | + // Check if $current_page_id && $selected_blog_id is equal to each other. |
|
119 | + // Get the page ID instead of global $post->ID that the query returns. |
|
120 | + // The ID of the first post object inside the loop is not correct. |
|
121 | + $blog_id = absint(get_option('page_for_posts')); |
|
122 | + |
|
123 | + if (is_home() ) { |
|
124 | + if ($blog_id === $login_page_id ) { |
|
125 | + $current_page_id = $blog_id; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + // Only execute the script for non-loggedin visitors. |
|
130 | + if (! is_user_logged_in() ) { |
|
131 | + |
|
132 | + if ($current_page_id !== $login_page_id ) { |
|
133 | + |
|
134 | + if (! in_array($current_page_id, $excluded_page, true) ) { |
|
135 | + |
|
136 | + wp_safe_redirect( |
|
137 | + add_query_arg( |
|
138 | + array( '_redirected' => 'yes' ), |
|
139 | + $redirect_page |
|
140 | + ) |
|
141 | + ); |
|
142 | + |
|
143 | + Helpers::close(); |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | namespace Subway; |
21 | 21 | |
22 | -if (! defined('ABSPATH') ) { |
|
22 | +if ( ! defined('ABSPATH')) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | |
47 | 47 | // Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
48 | 48 | // Callback function/method must return true (boolean) to disable redirect. |
49 | - $should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
|
49 | + $should_exit = apply_filters('subway/classes/subway-page-redirect/index/before-page-redirect', false); |
|
50 | 50 | |
51 | - if ( $should_exit ) { |
|
51 | + if ($should_exit) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // Only execute for non logged in users. |
56 | - if (is_user_logged_in() ) { |
|
56 | + if (is_user_logged_in()) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
@@ -71,44 +71,44 @@ discard block |
||
71 | 71 | // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
72 | 72 | |
73 | 73 | // Turn off if is in 'wc-ajax' (woocommerce) |
74 | - if ( function_exists( 'is_ajax') ) { |
|
75 | - if ( is_ajax() ) { |
|
74 | + if (function_exists('is_ajax')) { |
|
75 | + if (is_ajax()) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Same for normal ajax requests. |
81 | - if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
81 | + if (is_admin() && defined('DOING_AJAX') && DOING_AJAX) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Exit if site is public. |
86 | - if (Options::isPublicSite() ) { |
|
86 | + if (Options::isPublicSite()) { |
|
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | 90 | // Check if redirect page is empty or not. |
91 | - if (empty($redirect_page) ) { |
|
91 | + if (empty($redirect_page)) { |
|
92 | 92 | return; |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Check if buddypress activate page. |
96 | - if (function_exists('bp_is_activation_page') ) { |
|
97 | - if (bp_is_activation_page() ) { |
|
96 | + if (function_exists('bp_is_activation_page')) { |
|
97 | + if (bp_is_activation_page()) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Check if buddypress registration page. |
103 | - if (function_exists('bp_is_register_page') ) { |
|
104 | - if (bp_is_register_page() ) { |
|
103 | + if (function_exists('bp_is_register_page')) { |
|
104 | + if (bp_is_register_page()) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Assign 0 value to empty $post->ID to prevent exception. |
110 | 110 | // This applies to custom WordPress pages such as BP Members Page and Groups. |
111 | - if (empty($current_post) ) { |
|
111 | + if (empty($current_post)) { |
|
112 | 112 | $current_post = new \stdclass; |
113 | 113 | $current_post->ID = 0; |
114 | 114 | } |
@@ -120,22 +120,22 @@ discard block |
||
120 | 120 | // The ID of the first post object inside the loop is not correct. |
121 | 121 | $blog_id = absint(get_option('page_for_posts')); |
122 | 122 | |
123 | - if (is_home() ) { |
|
124 | - if ($blog_id === $login_page_id ) { |
|
123 | + if (is_home()) { |
|
124 | + if ($blog_id === $login_page_id) { |
|
125 | 125 | $current_page_id = $blog_id; |
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Only execute the script for non-loggedin visitors. |
130 | - if (! is_user_logged_in() ) { |
|
130 | + if ( ! is_user_logged_in()) { |
|
131 | 131 | |
132 | - if ($current_page_id !== $login_page_id ) { |
|
132 | + if ($current_page_id !== $login_page_id) { |
|
133 | 133 | |
134 | - if (! in_array($current_page_id, $excluded_page, true) ) { |
|
134 | + if ( ! in_array($current_page_id, $excluded_page, true)) { |
|
135 | 135 | |
136 | 136 | wp_safe_redirect( |
137 | 137 | add_query_arg( |
138 | - array( '_redirected' => 'yes' ), |
|
138 | + array('_redirected' => 'yes'), |
|
139 | 139 | $redirect_page |
140 | 140 | ) |
141 | 141 | ); |