Passed
Pull Request — master (#36)
by
unknown
02:38
created
classes/subway-page-redirect.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.