Passed
Push — master ( be3f72...430fe5 )
by Joseph
39s queued 10s
created
settings-fields/field-subway-is-public-form.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @package Subway
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	return;
15 15
 }
16 16
 
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
  */
22 22
 function subway_is_public_form() {
23 23
 
24
-	echo '<label for="subway_is_public"><input ' . checked( 1, get_option( 'subway_is_public' ), false ) . ' value="1" name="subway_is_public" id="subway_is_public" type="checkbox" class="code" /> Check to make all of your posts and pages visible to public.</label>';
25
-	echo '<p class="description">' . esc_html__( 'Check to ignore all private options and make your site return to its original state (public) without uninstalling Subway. All settings here and in the individual posts or pages will be ignored. Uncheck to make your site accessible to members only', 'subway' ) . '</p>';
24
+	echo '<label for="subway_is_public"><input ' . checked(1, get_option('subway_is_public'), false) . ' value="1" name="subway_is_public" id="subway_is_public" type="checkbox" class="code" /> Check to make all of your posts and pages visible to public.</label>';
25
+	echo '<p class="description">' . esc_html__('Check to ignore all private options and make your site return to its original state (public) without uninstalling Subway. All settings here and in the individual posts or pages will be ignored. Uncheck to make your site accessible to members only', 'subway') . '</p>';
26 26
 
27 27
 	return;
28 28
 }
Please login to merge, or discard this patch.
classes/subway-auth-redirect.php 2 patches
Indentation   +128 added lines, -128 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,185 +36,185 @@  discard block
 block discarded – undo
36 36
 final class AuthRedirect
37 37
 {
38 38
 
39
-    /**
40
-     * Handles our ajax authentication.
41
-     *
42
-     * @return void
43
-     */
44
-    public static function handleAuthentication()
45
-    {
39
+	/**
40
+	 * Handles our ajax authentication.
41
+	 *
42
+	 * @return void
43
+	 */
44
+	public static function handleAuthentication()
45
+	{
46 46
 
47
-        // Set the header type to json.
48
-        header('Content-Type: application/json');
47
+		// Set the header type to json.
48
+		header('Content-Type: application/json');
49 49
 
50
-        $is_signin = new \WP_Error( 'broke', __( 'Unable to authenticate user', "subway" ) );
50
+		$is_signin = new \WP_Error( 'broke', __( 'Unable to authenticate user', "subway" ) );
51 51
 
52
-        $log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING);
52
+		$log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING);
53 53
 
54
-        $pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING);
54
+		$pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING);
55 55
 
56
-        if (empty($log) && empty($pwd) ) {
56
+		if (empty($log) && empty($pwd) ) {
57 57
 
58
-            $response['type'] = 'error';
58
+			$response['type'] = 'error';
59 59
 
60
-            $response['message'] = esc_html__(
61
-                'Username and Password cannot be empty.',
62
-                'subway'
63
-            );
60
+			$response['message'] = esc_html__(
61
+				'Username and Password cannot be empty.',
62
+				'subway'
63
+			);
64 64
 
65
-        } else {
65
+		} else {
66 66
 
67
-            $is_signin = wp_signon();
67
+			$is_signin = wp_signon();
68 68
 
69
-            $response = array();
69
+			$response = array();
70 70
 
71
-            if (is_wp_error($is_signin) ) {
71
+			if (is_wp_error($is_signin) ) {
72 72
 
73
-                $response['type'] = 'error';
73
+				$response['type'] = 'error';
74 74
 
75
-                $response['message'] = $is_signin->get_error_message();
75
+				$response['message'] = $is_signin->get_error_message();
76 76
 
77
-            } else {
77
+			} else {
78 78
 
79
-                $response['type'] = 'success';
79
+				$response['type'] = 'success';
80 80
 
81
-                $response['message'] = esc_html__(
82
-                    'You have successfully logged-in. Redirecting you in few seconds...',
83
-                    'subway'
84
-                );
81
+				$response['message'] = esc_html__(
82
+					'You have successfully logged-in. Redirecting you in few seconds...',
83
+					'subway'
84
+				);
85 85
 
86
-            }
87
-        }
86
+			}
87
+		}
88 88
 
89
-        $subway_redirect_url = AuthRedirect::getLoginRedirectUrl('', $is_signin);
89
+		$subway_redirect_url = AuthRedirect::getLoginRedirectUrl('', $is_signin);
90 90
 
91
-        $response['redirect_url'] = apply_filters(
92
-            'subway_login_redirect',
93
-            $subway_redirect_url,
94
-            $is_signin
95
-        );
91
+		$response['redirect_url'] = apply_filters(
92
+			'subway_login_redirect',
93
+			$subway_redirect_url,
94
+			$is_signin
95
+		);
96 96
 
97
-        echo wp_json_encode($response);
97
+		echo wp_json_encode($response);
98 98
 
99
-        wp_die();
99
+		wp_die();
100 100
 
101
-    }
101
+	}
102 102
 
103
-    /**
104
-     * Returns the filtered redirect url for the current user.
105
-     *
106
-     * @param string $redirect_to The default redirect callback argument.
107
-     * @param mixed  $user        This holds the meta info of currently logged-in user.
108
-     *
109
-     * @return string             The final redirect url.
110
-     */
111
-    public static function getLoginRedirectUrl( $redirect_to, $user )
112
-    {
103
+	/**
104
+	 * Returns the filtered redirect url for the current user.
105
+	 *
106
+	 * @param string $redirect_to The default redirect callback argument.
107
+	 * @param mixed  $user        This holds the meta info of currently logged-in user.
108
+	 *
109
+	 * @return string             The final redirect url.
110
+	 */
111
+	public static function getLoginRedirectUrl( $redirect_to, $user )
112
+	{
113 113
 
114
-        $subway_redirect_type = get_option('subway_redirect_type');
114
+		$subway_redirect_type = get_option('subway_redirect_type');
115 115
 
116
-        // Redirect the user to default behaviour.
117
-        // If there are no redirect type option saved.
118
-        if (empty($subway_redirect_type) ) {
116
+		// Redirect the user to default behaviour.
117
+		// If there are no redirect type option saved.
118
+		if (empty($subway_redirect_type) ) {
119 119
 
120
-            return $redirect_to;
120
+			return $redirect_to;
121 121
 
122
-        }
122
+		}
123 123
 
124
-        if ('default' === $subway_redirect_type ) {
125
-            return $redirect_to;
126
-        }
124
+		if ('default' === $subway_redirect_type ) {
125
+			return $redirect_to;
126
+		}
127 127
 
128
-        if ('page' === $subway_redirect_type ) {
128
+		if ('page' === $subway_redirect_type ) {
129 129
 
130
-            // Get the page url of the selected page.
131
-            // If the admin selected 'Custom Page' in the redirect type settings.
132
-            $selected_redirect_page = intval(get_option('subway_redirect_page_id'));
130
+			// Get the page url of the selected page.
131
+			// If the admin selected 'Custom Page' in the redirect type settings.
132
+			$selected_redirect_page = intval(get_option('subway_redirect_page_id'));
133 133
 
134
-            // Redirect to default WordPress behaviour.
135
-            // If the user did not select page.
136
-            if (empty($selected_redirect_page) ) {
134
+			// Redirect to default WordPress behaviour.
135
+			// If the user did not select page.
136
+			if (empty($selected_redirect_page) ) {
137 137
 
138
-                return $redirect_to;
139
-            }
138
+				return $redirect_to;
139
+			}
140 140
 
141
-            // Otherwise, get the permalink of the saved page
142
-            // and let the user go into that page.
143
-            return get_permalink($selected_redirect_page);
141
+			// Otherwise, get the permalink of the saved page
142
+			// and let the user go into that page.
143
+			return get_permalink($selected_redirect_page);
144 144
 
145
-        } elseif ('custom_url' === $subway_redirect_type ) {
145
+		} elseif ('custom_url' === $subway_redirect_type ) {
146 146
 
147
-            // Get the custom url saved in the redirect type settings.
148
-            $entered_custom_url = get_option('subway_redirect_custom_url');
147
+			// Get the custom url saved in the redirect type settings.
148
+			$entered_custom_url = get_option('subway_redirect_custom_url');
149 149
 
150
-            // Redirect to default WordPress behaviour
151
-            // if the user did enter a custom url.
152
-            if (empty($entered_custom_url) ) {
150
+			// Redirect to default WordPress behaviour
151
+			// if the user did enter a custom url.
152
+			if (empty($entered_custom_url) ) {
153 153
 
154
-                return $redirect_to;
154
+				return $redirect_to;
155 155
 
156
-            }
156
+			}
157 157
 
158
-            // Otherwise, get the custom url saved
159
-            // and let the user go into that page.
160
-            if (! empty($user->ID) ) {
161
-                $entered_custom_url = str_replace(
162
-                    '%user_id%', $user->ID,
163
-                    $entered_custom_url
164
-                );
165
-            }
158
+			// Otherwise, get the custom url saved
159
+			// and let the user go into that page.
160
+			if (! empty($user->ID) ) {
161
+				$entered_custom_url = str_replace(
162
+					'%user_id%', $user->ID,
163
+					$entered_custom_url
164
+				);
165
+			}
166 166
 
167
-            if (! empty($user->user_login) ) {
168
-                $entered_custom_url = str_replace(
169
-                    '%user_name%', $user->user_login,
170
-                    $entered_custom_url
171
-                );
172
-            }
167
+			if (! empty($user->user_login) ) {
168
+				$entered_custom_url = str_replace(
169
+					'%user_name%', $user->user_login,
170
+					$entered_custom_url
171
+				);
172
+			}
173 173
 
174
-            return $entered_custom_url;
174
+			return $entered_custom_url;
175 175
 
176
-        }
176
+		}
177 177
 
178
-        // Otherwise, quit and redirect the user back to default WordPress behaviour.
179
-        return $redirect_to;
180
-    }
178
+		// Otherwise, quit and redirect the user back to default WordPress behaviour.
179
+		return $redirect_to;
180
+	}
181 181
 
182
-    /**
183
-     * Callback function for the 'login_url' filter defined in Subway.php
184
-     *
185
-     * @param string $login_url The login url.
186
-     *
187
-     * @return string            The final login url.
188
-     */
189
-    public static function loginUrl( $login_url  )
190
-    {
182
+	/**
183
+	 * Callback function for the 'login_url' filter defined in Subway.php
184
+	 *
185
+	 * @param string $login_url The login url.
186
+	 *
187
+	 * @return string            The final login url.
188
+	 */
189
+	public static function loginUrl( $login_url  )
190
+	{
191 191
 
192
-        $subway_login_page = Options::getRedirectPageUrl();
192
+		$subway_login_page = Options::getRedirectPageUrl();
193 193
 
194
-        // Return the default login url if there is no log-in page defined.
195
-        if (empty($subway_login_page) ) {
196
-            return $login_url;
197
-        }
194
+		// Return the default login url if there is no log-in page defined.
195
+		if (empty($subway_login_page) ) {
196
+			return $login_url;
197
+		}
198 198
 
199
-        // Otherwise, return the Subway login page.
200
-        return $subway_login_page;
199
+		// Otherwise, return the Subway login page.
200
+		return $subway_login_page;
201 201
 
202
-    }
202
+	}
203 203
 
204
-    /**
205
-     * The callback function for our logout filter.
206
-     *
207
-     * @return void
208
-     */
209
-    public static function logoutUrl()
210
-    {
204
+	/**
205
+	 * The callback function for our logout filter.
206
+	 *
207
+	 * @return void
208
+	 */
209
+	public static function logoutUrl()
210
+	{
211 211
 
212
-        $subway_login_page = Options::getRedirectPageUrl();
212
+		$subway_login_page = Options::getRedirectPageUrl();
213 213
 
214
-        wp_safe_redirect(esc_url($subway_login_page . '?loggedout=true'));
214
+		wp_safe_redirect(esc_url($subway_login_page . '?loggedout=true'));
215 215
 
216
-        Helpers::close();
216
+		Helpers::close();
217 217
 
218
-    }
218
+	}
219 219
 
220 220
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 namespace Subway;
21 21
 
22
-if (! defined('ABSPATH') ) {
22
+if ( ! defined('ABSPATH')) {
23 23
     return;
24 24
 }
25 25
 
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
         // Set the header type to json.
48 48
         header('Content-Type: application/json');
49 49
 
50
-        $is_signin = new \WP_Error( 'broke', __( 'Unable to authenticate user', "subway" ) );
50
+        $is_signin = new \WP_Error('broke', __('Unable to authenticate user', "subway"));
51 51
 
52 52
         $log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING);
53 53
 
54 54
         $pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING);
55 55
 
56
-        if (empty($log) && empty($pwd) ) {
56
+        if (empty($log) && empty($pwd)) {
57 57
 
58 58
             $response['type'] = 'error';
59 59
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
             $response = array();
70 70
 
71
-            if (is_wp_error($is_signin) ) {
71
+            if (is_wp_error($is_signin)) {
72 72
 
73 73
                 $response['type'] = 'error';
74 74
 
@@ -108,24 +108,24 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @return string             The final redirect url.
110 110
      */
111
-    public static function getLoginRedirectUrl( $redirect_to, $user )
111
+    public static function getLoginRedirectUrl($redirect_to, $user)
112 112
     {
113 113
 
114 114
         $subway_redirect_type = get_option('subway_redirect_type');
115 115
 
116 116
         // Redirect the user to default behaviour.
117 117
         // If there are no redirect type option saved.
118
-        if (empty($subway_redirect_type) ) {
118
+        if (empty($subway_redirect_type)) {
119 119
 
120 120
             return $redirect_to;
121 121
 
122 122
         }
123 123
 
124
-        if ('default' === $subway_redirect_type ) {
124
+        if ('default' === $subway_redirect_type) {
125 125
             return $redirect_to;
126 126
         }
127 127
 
128
-        if ('page' === $subway_redirect_type ) {
128
+        if ('page' === $subway_redirect_type) {
129 129
 
130 130
             // Get the page url of the selected page.
131 131
             // If the admin selected 'Custom Page' in the redirect type settings.
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 
134 134
             // Redirect to default WordPress behaviour.
135 135
             // If the user did not select page.
136
-            if (empty($selected_redirect_page) ) {
136
+            if (empty($selected_redirect_page)) {
137 137
 
138 138
                 return $redirect_to;
139 139
             }
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
             // and let the user go into that page.
143 143
             return get_permalink($selected_redirect_page);
144 144
 
145
-        } elseif ('custom_url' === $subway_redirect_type ) {
145
+        } elseif ('custom_url' === $subway_redirect_type) {
146 146
 
147 147
             // Get the custom url saved in the redirect type settings.
148 148
             $entered_custom_url = get_option('subway_redirect_custom_url');
149 149
 
150 150
             // Redirect to default WordPress behaviour
151 151
             // if the user did enter a custom url.
152
-            if (empty($entered_custom_url) ) {
152
+            if (empty($entered_custom_url)) {
153 153
 
154 154
                 return $redirect_to;
155 155
 
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 
158 158
             // Otherwise, get the custom url saved
159 159
             // and let the user go into that page.
160
-            if (! empty($user->ID) ) {
160
+            if ( ! empty($user->ID)) {
161 161
                 $entered_custom_url = str_replace(
162 162
                     '%user_id%', $user->ID,
163 163
                     $entered_custom_url
164 164
                 );
165 165
             }
166 166
 
167
-            if (! empty($user->user_login) ) {
167
+            if ( ! empty($user->user_login)) {
168 168
                 $entered_custom_url = str_replace(
169 169
                     '%user_name%', $user->user_login,
170 170
                     $entered_custom_url
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
      *
187 187
      * @return string            The final login url.
188 188
      */
189
-    public static function loginUrl( $login_url  )
189
+    public static function loginUrl($login_url)
190 190
     {
191 191
 
192 192
         $subway_login_page = Options::getRedirectPageUrl();
193 193
 
194 194
         // Return the default login url if there is no log-in page defined.
195
-        if (empty($subway_login_page) ) {
195
+        if (empty($subway_login_page)) {
196 196
             return $login_url;
197 197
         }
198 198
 
Please login to merge, or discard this patch.
classes/subway-page-redirect.php 2 patches
Indentation   +108 added lines, -108 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,120 +36,120 @@  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
-        }
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 59
         
60
-        $is_private = false;
60
+		$is_private = false;
61 61
 
62
-        $queried_id = get_queried_object_id();
62
+		$queried_id = get_queried_object_id();
63 63
 
64
-        $current_post = get_post(absint($queried_id));
64
+		$current_post = get_post(absint($queried_id));
65 65
 
66
-        $login_page_id = absint(get_option('subway_login_page'));
66
+		$login_page_id = absint(get_option('subway_login_page'));
67 67
 
68
-        $excluded_page = Options::getPublicPostsIdentifiers();
68
+		$excluded_page = Options::getPublicPostsIdentifiers();
69 69
 
70
-        // Already escaped inside 'subway_get_redirect_page_url'.
71
-        $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK.
70
+		// Already escaped inside 'subway_get_redirect_page_url'.
71
+		$redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK.
72 72
 
73
-        if ( !empty( $current_post ) ) {
73
+		if ( !empty( $current_post ) ) {
74 74
 		  $is_private = Metabox::isPostPrivate( $current_post->ID );
75
-        }
76
-
77
-        // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' );
78
-
79
-        // Turn off if is in 'wc-ajax' (woocommerce)
80
-        if ( function_exists( 'is_ajax') ) {
81
-            if ( is_ajax() ) {
82
-               return;
83
-            }
84
-        }
85
-
86
-        // Same for normal ajax requests.
87
-        if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX  ) {
88
-            return;
89
-        }
90
-
91
-        // Exit if site is public.
92
-        if ( Options::isPublicSite() ) {
93
-            return;
94
-        }
95
-
96
-        // Check if redirect page is empty or not.
97
-        if ( empty( $redirect_page ) ) {
98
-            return;
99
-        }
100
-
101
-        // Check if buddypress activate page.
102
-        if (function_exists('bp_is_activation_page') ) {
103
-            if (bp_is_activation_page() ) {
104
-                return;
105
-            }
106
-        }
107
-
108
-        // Check if buddypress registration page.
109
-        if (function_exists('bp_is_register_page') ) {
110
-            if (bp_is_register_page() ) {
111
-                return;
112
-            }
113
-        }
114
-
115
-        // Assign 0 value to empty $post->ID to prevent exception.
116
-        // This applies to custom WordPress pages such as BP Members Page and Groups.
117
-        if (empty($current_post) ) {
118
-            $current_post = new \stdclass;
119
-            $current_post->ID = 0;
120
-        }
121
-
122
-        $current_page_id = absint($current_post->ID);
123
-
124
-        // Check if $current_page_id && $selected_blog_id is equal to each other.
125
-        // Get the page ID instead of global $post->ID that the query returns.
126
-        // The ID of the first post object inside the loop is not correct.
127
-        $blog_id = absint(get_option('page_for_posts'));
128
-
129
-        if (is_home() ) {
130
-            if ($blog_id === $login_page_id ) {
131
-                $current_page_id = $blog_id;
132
-            }
133
-        }
134
-
135
-        // Only execute the script for non-loggedin visitors.
136
-        if ( ! is_user_logged_in() ) {
137
-
138
-            if ($current_page_id !== $login_page_id ) {
139
-
140
-                if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) {
141
-
142
-                    wp_safe_redirect(
143
-                        add_query_arg(
144
-                            array( '_redirected' => 'yes' ),
145
-                            $redirect_page
146
-                        )
147
-                    );
148
-
149
-                    Helpers::close();
150
-                }
151
-            }
152
-        }
153
-    }
75
+		}
76
+
77
+		// do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' );
78
+
79
+		// Turn off if is in 'wc-ajax' (woocommerce)
80
+		if ( function_exists( 'is_ajax') ) {
81
+			if ( is_ajax() ) {
82
+			   return;
83
+			}
84
+		}
85
+
86
+		// Same for normal ajax requests.
87
+		if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX  ) {
88
+			return;
89
+		}
90
+
91
+		// Exit if site is public.
92
+		if ( Options::isPublicSite() ) {
93
+			return;
94
+		}
95
+
96
+		// Check if redirect page is empty or not.
97
+		if ( empty( $redirect_page ) ) {
98
+			return;
99
+		}
100
+
101
+		// Check if buddypress activate page.
102
+		if (function_exists('bp_is_activation_page') ) {
103
+			if (bp_is_activation_page() ) {
104
+				return;
105
+			}
106
+		}
107
+
108
+		// Check if buddypress registration page.
109
+		if (function_exists('bp_is_register_page') ) {
110
+			if (bp_is_register_page() ) {
111
+				return;
112
+			}
113
+		}
114
+
115
+		// Assign 0 value to empty $post->ID to prevent exception.
116
+		// This applies to custom WordPress pages such as BP Members Page and Groups.
117
+		if (empty($current_post) ) {
118
+			$current_post = new \stdclass;
119
+			$current_post->ID = 0;
120
+		}
121
+
122
+		$current_page_id = absint($current_post->ID);
123
+
124
+		// Check if $current_page_id && $selected_blog_id is equal to each other.
125
+		// Get the page ID instead of global $post->ID that the query returns.
126
+		// The ID of the first post object inside the loop is not correct.
127
+		$blog_id = absint(get_option('page_for_posts'));
128
+
129
+		if (is_home() ) {
130
+			if ($blog_id === $login_page_id ) {
131
+				$current_page_id = $blog_id;
132
+			}
133
+		}
134
+
135
+		// Only execute the script for non-loggedin visitors.
136
+		if ( ! is_user_logged_in() ) {
137
+
138
+			if ($current_page_id !== $login_page_id ) {
139
+
140
+				if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) {
141
+
142
+					wp_safe_redirect(
143
+						add_query_arg(
144
+							array( '_redirected' => 'yes' ),
145
+							$redirect_page
146
+						)
147
+					);
148
+
149
+					Helpers::close();
150
+				}
151
+			}
152
+		}
153
+	}
154 154
 
155 155
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         
@@ -70,51 +70,51 @@  discard block
 block discarded – undo
70 70
         // Already escaped inside 'subway_get_redirect_page_url'.
71 71
         $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK.
72 72
 
73
-        if ( !empty( $current_post ) ) {
74
-		  $is_private = Metabox::isPostPrivate( $current_post->ID );
73
+        if ( ! empty($current_post)) {
74
+		  $is_private = Metabox::isPostPrivate($current_post->ID);
75 75
         }
76 76
 
77 77
         // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' );
78 78
 
79 79
         // Turn off if is in 'wc-ajax' (woocommerce)
80
-        if ( function_exists( 'is_ajax') ) {
81
-            if ( is_ajax() ) {
80
+        if (function_exists('is_ajax')) {
81
+            if (is_ajax()) {
82 82
                return;
83 83
             }
84 84
         }
85 85
 
86 86
         // Same for normal ajax requests.
87
-        if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX  ) {
87
+        if (is_admin() && defined('DOING_AJAX') && DOING_AJAX) {
88 88
             return;
89 89
         }
90 90
 
91 91
         // Exit if site is public.
92
-        if ( Options::isPublicSite() ) {
92
+        if (Options::isPublicSite()) {
93 93
             return;
94 94
         }
95 95
 
96 96
         // Check if redirect page is empty or not.
97
-        if ( empty( $redirect_page ) ) {
97
+        if (empty($redirect_page)) {
98 98
             return;
99 99
         }
100 100
 
101 101
         // Check if buddypress activate page.
102
-        if (function_exists('bp_is_activation_page') ) {
103
-            if (bp_is_activation_page() ) {
102
+        if (function_exists('bp_is_activation_page')) {
103
+            if (bp_is_activation_page()) {
104 104
                 return;
105 105
             }
106 106
         }
107 107
 
108 108
         // Check if buddypress registration page.
109
-        if (function_exists('bp_is_register_page') ) {
110
-            if (bp_is_register_page() ) {
109
+        if (function_exists('bp_is_register_page')) {
110
+            if (bp_is_register_page()) {
111 111
                 return;
112 112
             }
113 113
         }
114 114
 
115 115
         // Assign 0 value to empty $post->ID to prevent exception.
116 116
         // This applies to custom WordPress pages such as BP Members Page and Groups.
117
-        if (empty($current_post) ) {
117
+        if (empty($current_post)) {
118 118
             $current_post = new \stdclass;
119 119
             $current_post->ID = 0;
120 120
         }
@@ -126,22 +126,22 @@  discard block
 block discarded – undo
126 126
         // The ID of the first post object inside the loop is not correct.
127 127
         $blog_id = absint(get_option('page_for_posts'));
128 128
 
129
-        if (is_home() ) {
130
-            if ($blog_id === $login_page_id ) {
129
+        if (is_home()) {
130
+            if ($blog_id === $login_page_id) {
131 131
                 $current_page_id = $blog_id;
132 132
             }
133 133
         }
134 134
 
135 135
         // Only execute the script for non-loggedin visitors.
136
-        if ( ! is_user_logged_in() ) {
136
+        if ( ! is_user_logged_in()) {
137 137
 
138
-            if ($current_page_id !== $login_page_id ) {
138
+            if ($current_page_id !== $login_page_id) {
139 139
 
140
-                if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) {
140
+                if ( ! in_array($current_page_id, $excluded_page, true) || in_array($current_page_id, $excluded_page, true) && true === $is_private) {
141 141
 
142 142
                     wp_safe_redirect(
143 143
                         add_query_arg(
144
-                            array( '_redirected' => 'yes' ),
144
+                            array('_redirected' => 'yes'),
145 145
                             $redirect_page
146 146
                         )
147 147
                     );
Please login to merge, or discard this patch.
classes/subway-metabox.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * Registers and update metabox with its intended method below.
52 52
 	 *
53 53
 	 * @since  2.0.9
54
-	 * @return void
54
+	 * @return Metabox
55 55
 	 */
56 56
 	public function __construct() {
57 57
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 *
199 199
 	 * @since  2.0.9
200 200
 	 * @access public
201
-	 * @return boolean false Returns false if nonce is not valid.
201
+	 * @return boolean|null false Returns false if nonce is not valid.
202 202
 	 */
203 203
 	public function saveVisibilityMetabox( $post_id = '' ) {
204 204
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @since  2.0.9
274 274
 	 * @access public
275
-	 * @return boolean false Returns false if nonce is not valid.
275
+	 * @return boolean|null false Returns false if nonce is not valid.
276 276
 	 */
277 277
 	public function saveMetaboxValues( $post_id ) {
278 278
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 *
312 312
 	 * @since  2.0.9
313 313
 	 * @access public
314
-	 * @return boolean true Returns true if nonce is valid.
314
+	 * @return null|boolean true Returns true if nonce is valid.
315 315
 	 */
316 316
 	public function isNonceValid( $nonce ) {
317 317
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -182,10 +182,13 @@
 block discarded – undo
182 182
 				});
183 183
 			</script>
184 184
 			<p class="howto"><?php echo esc_html( $howto ); ?></p>
185
-		<?php else : ?>
185
+		<?php else {
186
+	: ?>
186 187
 			<?php // Site is public! Explain to them ?>
187 188
 			<p><em>
188
-				<?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway.  Subway visibility options will be turned off.', 'subway' ); ?>
189
+				<?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway.  Subway visibility options will be turned off.', 'subway' );
190
+}
191
+?>
189 192
 			</em>
190 193
 			</p>
191 194
 		<?php endif; ?>
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 namespace Subway;
24 24
 
25
-if ( ! defined( 'ABSPATH' ) ) {
25
+if ( ! defined('ABSPATH')) {
26 26
 	return;
27 27
 }
28 28
 
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 */
56 56
 	public function __construct() {
57 57
 
58
-		add_action( 'add_meta_boxes', array( $this, 'addMetabox' ) );
59
-		add_action( 'save_post', array( $this, 'saveMetaboxValues' ) );
60
-		add_filter( 'the_content', array( $this, 'showContentToAllowedRoles' ) );
58
+		add_action('add_meta_boxes', array($this, 'addMetabox'));
59
+		add_action('save_post', array($this, 'saveMetaboxValues'));
60
+		add_filter('the_content', array($this, 'showContentToAllowedRoles'));
61 61
 
62 62
 		return $this;
63 63
 	}
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
 
86 86
 		$post_types = $this->getPostTypes();
87 87
 
88
-		foreach ( $post_types as $post_type => $value ) {
88
+		foreach ($post_types as $post_type => $value) {
89 89
 			add_meta_box(
90 90
 				'subway_visibility_metabox',
91
-				esc_html__( 'Subway: Visibility Option', 'subway' ),
92
-				array( $this, 'visibilityMetabox' ),
91
+				esc_html__('Subway: Visibility Option', 'subway'),
92
+				array($this, 'visibilityMetabox'),
93 93
 				$post_type,
94 94
 				'side',
95 95
 				'high'
@@ -106,65 +106,65 @@  discard block
 block discarded – undo
106 106
 	 * @access public
107 107
 	 * @return void
108 108
 	 */
109
-	public function visibilityMetabox( $post ) {
109
+	public function visibilityMetabox($post) {
110 110
 
111 111
 		$howto = __(
112 112
 			'Choose the accessibility of this page from the options above.',
113 113
 			'subway'
114 114
 		);
115 115
 
116
-		$private_setting_label = __( 'Members Only', 'subway' );
116
+		$private_setting_label = __('Members Only', 'subway');
117 117
 
118
-		$is_post_private         = self::isPostPrivate( $post->ID );
118
+		$is_post_private = self::isPostPrivate($post->ID);
119 119
 
120 120
 		// Make sure the form request comes from WordPress
121
-		wp_nonce_field( basename( __FILE__ ),  'subway_post_visibility_nonce' );
121
+		wp_nonce_field(basename(__FILE__), 'subway_post_visibility_nonce');
122 122
 
123 123
 		// Disable the options (radio) when site is selected as public
124 124
 		?>
125 125
 		<input type="hidden" name="subway-visibility-form-submitted" value="1" />
126 126
 
127
-		<?php if ( ! Options::isPublicSite() ) :  ?>
127
+		<?php if ( ! Options::isPublicSite()) :  ?>
128 128
 		<?php // Site is private. Give them some Beer! ?>
129 129
 			<p>
130 130
 				<label class="subway-visibility-settings-checkbox-label" for="subway-visibility-public">
131
-					<input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-public" name="subway-visibility-settings" value="public" <?php echo checked( false, $is_post_private, false ); ?>>
132
-					<?php esc_html_e( 'Public', 'subway' ) ?>
131
+					<input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-public" name="subway-visibility-settings" value="public" <?php echo checked(false, $is_post_private, false); ?>>
132
+					<?php esc_html_e('Public', 'subway') ?>
133 133
 				</label>
134 134
 			</p>
135 135
 			<p>
136 136
 				<label class="subway-visibility-settings-checkbox-label" for="subway-visibility-private">
137 137
 					<input type="radio" class="subway-visibility-settings-radio" id="subway-visibility-private" name="subway-visibility-settings"
138
-					value="private" <?php echo checked( true, $is_post_private, false ); ?>>
139
-					<?php esc_html_e( 'Members Only', 'subway' ) ?>
138
+					value="private" <?php echo checked(true, $is_post_private, false); ?>>
139
+					<?php esc_html_e('Members Only', 'subway') ?>
140 140
 				 </label>
141 141
 			</p>
142 142
 			<div id="subway-roles-access-visibility-fields" class="hidden">
143 143
 				<dl>
144
-					<?php $post_allowed_user_roles = self::getAllowedUserRoles( $post->ID ); ?>
144
+					<?php $post_allowed_user_roles = self::getAllowedUserRoles($post->ID); ?>
145 145
 					<?php $editable_roles = get_editable_roles(); ?>
146 146
 					<?php // Remove administrator for editable roles. ?>
147
-					<?php unset( $editable_roles['administrator'] ); ?>
148
-					<?php foreach ( $editable_roles as $role_name => $role_info ) { ?>
147
+					<?php unset($editable_roles['administrator']); ?>
148
+					<?php foreach ($editable_roles as $role_name => $role_info) { ?>
149 149
 						<dt>
150
-							<?php $id = 'subway-visibility-settings-user-role-' . esc_html( $role_name ); ?>
151
-							<label for="<?php echo esc_attr( $id ); ?>">
152
-							<?php if ( is_array( $post_allowed_user_roles ) && in_array( $role_name, $post_allowed_user_roles ) ) { ?>
150
+							<?php $id = 'subway-visibility-settings-user-role-' . esc_html($role_name); ?>
151
+							<label for="<?php echo esc_attr($id); ?>">
152
+							<?php if (is_array($post_allowed_user_roles) && in_array($role_name, $post_allowed_user_roles)) { ?>
153 153
 								<?php $checked = 'checked'; ?>
154 154
 							<?php } else { ?>
155
-								<?php if ( false === $post_allowed_user_roles ) { ?>
155
+								<?php if (false === $post_allowed_user_roles) { ?>
156 156
 									<?php $checked = 'checked'; ?>
157 157
 								<?php } else { ?>
158 158
 										<?php $checked = ''; ?>
159 159
 								<?php } ?>
160 160
 							<?php } ?>
161
-							<input <?php echo esc_attr( $checked ); ?> id="<?php echo esc_attr( $id ); ?>" type="checkbox" 
162
-							name="subway-visibility-settings-user-role[]" class="subway-visibility-settings-role-access" value="<?php echo esc_attr( $role_name ); ?>" />
163
-								<?php echo esc_html( $role_info['name'] ); ?>
161
+							<input <?php echo esc_attr($checked); ?> id="<?php echo esc_attr($id); ?>" type="checkbox" 
162
+							name="subway-visibility-settings-user-role[]" class="subway-visibility-settings-role-access" value="<?php echo esc_attr($role_name); ?>" />
163
+								<?php echo esc_html($role_info['name']); ?>
164 164
 							</label>
165 165
 						</dt>
166 166
 					<?php } ?>
167
-					<p class="howto"><?php echo esc_html_e( 'Uncheck the user roles that you do not want to have access to this content','subway' ); ?></p>
167
+					<p class="howto"><?php echo esc_html_e('Uncheck the user roles that you do not want to have access to this content', 'subway'); ?></p>
168 168
 				</dl>
169 169
 			</div>
170 170
 			<script>
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 					});
182 182
 				});
183 183
 			</script>
184
-			<p class="howto"><?php echo esc_html( $howto ); ?></p>
184
+			<p class="howto"><?php echo esc_html($howto); ?></p>
185 185
 		<?php else : ?>
186 186
 			<?php // Site is public! Explain to them ?>
187 187
 			<p><em>
188
-				<?php esc_html_e( 'You have chosen to make your site public inside Settings > Subway.  Subway visibility options will be turned off.', 'subway' ); ?>
188
+				<?php esc_html_e('You have chosen to make your site public inside Settings > Subway.  Subway visibility options will be turned off.', 'subway'); ?>
189 189
 			</em>
190 190
 			</p>
191 191
 		<?php endif; ?>
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 	 * @access public
202 202
 	 * @return boolean false Returns false if nonce is not valid.
203 203
 	 */
204
-	public function saveVisibilityMetabox( $post_id = '' ) {
204
+	public function saveVisibilityMetabox($post_id = '') {
205 205
 
206
-		if ( wp_is_post_autosave( $post_id ) ) {
206
+		if (wp_is_post_autosave($post_id)) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		$is_form_submitted = filter_input( INPUT_POST, 'subway-visibility-form-submitted', FILTER_DEFAULT );
210
+		$is_form_submitted = filter_input(INPUT_POST, 'subway-visibility-form-submitted', FILTER_DEFAULT);
211 211
 
212
-		if ( ! $is_form_submitted ) {
212
+		if ( ! $is_form_submitted) {
213 213
 			return;
214 214
 		}
215 215
 
@@ -224,45 +224,45 @@  discard block
 block discarded – undo
224 224
 			FILTER_SANITIZE_STRING
225 225
 		);
226 226
 
227
-		$post_visibility = filter_input( INPUT_POST,  $visibility_field, FILTER_SANITIZE_STRING );
227
+		$post_visibility = filter_input(INPUT_POST, $visibility_field, FILTER_SANITIZE_STRING);
228 228
 
229
-		$is_valid_visibility_nonce = self::isNonceValid( $visibility_nonce );
229
+		$is_valid_visibility_nonce = self::isNonceValid($visibility_nonce);
230 230
 
231
-		$allowed_roles = filter_input( INPUT_POST, 'subway-visibility-settings-user-role', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
231
+		$allowed_roles = filter_input(INPUT_POST, 'subway-visibility-settings-user-role', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
232 232
 
233 233
 		// verify taxonomies meta box nonce
234
-		if ( false === $is_valid_visibility_nonce ) {
234
+		if (false === $is_valid_visibility_nonce) {
235 235
 			return;
236 236
 		}
237
-		if ( empty( $allowed_roles ) ) {
237
+		if (empty($allowed_roles)) {
238 238
 			$allowed_roles = array();
239 239
 		}
240 240
 
241 241
 		// Update user roles.
242
-		update_post_meta( $post_id, 'subway-visibility-settings-allowed-user-roles', $allowed_roles );
242
+		update_post_meta($post_id, 'subway-visibility-settings-allowed-user-roles', $allowed_roles);
243 243
 
244
-		if ( ! empty( $post_visibility ) ) {
245
-			if ( ! empty( $post_id ) ) {
246
-				if ( 'public' === $post_visibility ) {
247
-					if ( ! in_array( $post_id, $public_posts ) ) {
248
-						array_push( $public_posts, $post_id );
244
+		if ( ! empty($post_visibility)) {
245
+			if ( ! empty($post_id)) {
246
+				if ('public' === $post_visibility) {
247
+					if ( ! in_array($post_id, $public_posts)) {
248
+						array_push($public_posts, $post_id);
249 249
 					}
250 250
 				}
251
-				if ( 'private' === $post_visibility ) {
252
-					if ( in_array( $post_id, $public_posts ) ) {
253
-						unset( $public_posts[ array_search( $post_id, $public_posts ) ] );
251
+				if ('private' === $post_visibility) {
252
+					if (in_array($post_id, $public_posts)) {
253
+						unset($public_posts[array_search($post_id, $public_posts)]);
254 254
 					}
255 255
 				}
256 256
 			}
257 257
 		}
258 258
 
259
-		if ( ! empty( $post_id ) ) {
260
-			$posts_implode = implode( ', ', $public_posts );
259
+		if ( ! empty($post_id)) {
260
+			$posts_implode = implode(', ', $public_posts);
261 261
 
262
-			if ( 'inherit' !== get_post_status( $post_id ) ) {
262
+			if ('inherit' !== get_post_status($post_id)) {
263 263
 
264
-				if ( true === $is_valid_visibility_nonce ) {
265
-					update_option( 'subway_public_post', $posts_implode );
264
+				if (true === $is_valid_visibility_nonce) {
265
+					update_option('subway_public_post', $posts_implode);
266 266
 					update_post_meta(
267 267
 						$post_id,
268 268
 						self::VISIBILITY_METAKEY,
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 	 * @access public
283 283
 	 * @return boolean false Returns false if nonce is not valid.
284 284
 	 */
285
-	public function saveMetaboxValues( $post_id ) {
285
+	public function saveMetaboxValues($post_id) {
286 286
 
287
-		$this->saveVisibilityMetabox( $post_id );
287
+		$this->saveVisibilityMetabox($post_id);
288 288
 		return;
289 289
 	}
290 290
 
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 	 * @access public
299 299
 	 * @return void
300 300
 	 */
301
-	public static function getPostTypes( $args = '', $output = '' ) {
301
+	public static function getPostTypes($args = '', $output = '') {
302 302
 
303
-		if ( empty( $args ) ) {
303
+		if (empty($args)) {
304 304
 			$args = array(
305 305
 			'public'   => true,
306 306
 			);
307 307
 			$output = 'names';
308 308
 		}
309 309
 
310
-		$post_types = get_post_types( $args, $output );
310
+		$post_types = get_post_types($args, $output);
311 311
 
312 312
 		return $post_types;
313 313
 	}
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 	 * @access public
322 322
 	 * @return boolean true Returns true if nonce is valid.
323 323
 	 */
324
-	public function isNonceValid( $nonce ) {
324
+	public function isNonceValid($nonce) {
325 325
 
326
-		if ( ! isset( $nonce ) || ! wp_verify_nonce( $nonce, basename( __FILE__ ) ) ) {
326
+		if ( ! isset($nonce) || ! wp_verify_nonce($nonce, basename(__FILE__))) {
327 327
 			return;
328 328
 		}
329 329
 
@@ -339,23 +339,23 @@  discard block
 block discarded – undo
339 339
 	 * @access public
340 340
 	 * @return boolean true Returns true if post is private. Otherwise false.
341 341
 	 */
342
-	public static function isPostPrivate( $post_id ) {
342
+	public static function isPostPrivate($post_id) {
343 343
 
344 344
 		$meta_value = '';
345 345
 
346
-		if ( ! empty( $post_id ) ) {
347
-			$meta_value = get_post_meta( $post_id, self::VISIBILITY_METAKEY, true );
346
+		if ( ! empty($post_id)) {
347
+			$meta_value = get_post_meta($post_id, self::VISIBILITY_METAKEY, true);
348 348
 
349 349
 			// New page or old pages that don't have Subway'\ Visibility Options
350
-			if ( empty( $meta_value ) ) {
350
+			if (empty($meta_value)) {
351 351
 				// Get the value from the general settings (Settings > Subway)
352 352
 				$is_site_public = Options::isPublicSite();
353
-				if ( ! $is_site_public ) {
353
+				if ( ! $is_site_public) {
354 354
 					// It's private.
355 355
 					return true;
356 356
 				}
357 357
 			}
358
-			if ( 'private' === $meta_value ) {
358
+			if ('private' === $meta_value) {
359 359
 				return true;
360 360
 			}
361 361
 		}
@@ -372,12 +372,12 @@  discard block
 block discarded – undo
372 372
 	 * @access public
373 373
 	 * @return boolean true Returns true if post is public. Otherwise false.
374 374
 	 */
375
-	public static function isPostPublic( $post_id ) {
375
+	public static function isPostPublic($post_id) {
376 376
 
377 377
 		$public_post = Options::getPublicPostsIdentifiers();
378 378
 
379
-		if ( ! empty( $post_id ) ) {
380
-			if ( ! in_array( $post_id, $public_post, true ) ) {
379
+		if ( ! empty($post_id)) {
380
+			if ( ! in_array($post_id, $public_post, true)) {
381 381
 				return true;
382 382
 			}
383 383
 		}
@@ -391,17 +391,17 @@  discard block
 block discarded – undo
391 391
 	 * @param  integer $post_id The post ID.
392 392
 	 * @return mixed Boolean false if metadata does not exists. Otherwise, return the array value of meta.
393 393
 	 */
394
-	public static function getAllowedUserRoles( $post_id = 0 ) {
394
+	public static function getAllowedUserRoles($post_id = 0) {
395 395
 
396 396
 		$allowed_roles = array();
397 397
 
398
-		if ( ! empty( $post_id ) ) {
398
+		if ( ! empty($post_id)) {
399 399
 
400 400
 			// Check if metadata exists for the following post.
401
-			if ( metadata_exists( 'post', $post_id, 'subway-visibility-settings-allowed-user-roles' ) ) {
401
+			if (metadata_exists('post', $post_id, 'subway-visibility-settings-allowed-user-roles')) {
402 402
 
403
-				$allowed_roles = get_post_meta( $post_id, 'subway-visibility-settings-allowed-user-roles', true );
404
-				if ( ! is_null( $allowed_roles ) ) {
403
+				$allowed_roles = get_post_meta($post_id, 'subway-visibility-settings-allowed-user-roles', true);
404
+				if ( ! is_null($allowed_roles)) {
405 405
 					return $allowed_roles;
406 406
 				}
407 407
 				return false;
@@ -423,28 +423,28 @@  discard block
 block discarded – undo
423 423
 	 * @param  string $content The content of the post.
424 424
 	 * @return string The content of the post.
425 425
 	 */
426
-	public function showContentToAllowedRoles( $content ) {
426
+	public function showContentToAllowedRoles($content) {
427 427
 
428 428
 		$post_id = get_the_ID();
429
-		$allowed_user_roles = self::getAllowedUserRoles( $post_id );
429
+		$allowed_user_roles = self::getAllowedUserRoles($post_id);
430 430
 
431
-		if ( ! is_singular() && is_main_query() ) {
431
+		if ( ! is_singular() && is_main_query()) {
432 432
 			return $content;
433 433
 		}
434 434
 
435
-		if ( is_user_logged_in() ) {
435
+		if (is_user_logged_in()) {
436 436
 
437
-			$no_privilege = '<div class="subway-role-not-allowed"><p>' . apply_filters( 'subway-content-restricted-to-role', esc_html__( 'You do not have the right privilege or role to view this page.', 'subway' ) ) . '</p></div>';
437
+			$no_privilege = '<div class="subway-role-not-allowed"><p>' . apply_filters('subway-content-restricted-to-role', esc_html__('You do not have the right privilege or role to view this page.', 'subway')) . '</p></div>';
438 438
 
439 439
 			// Restrict access to non admins only.
440
-			if ( ! current_user_can( 'manage_options' ) ) {
441
-				if ( ! self::currentUserCanViewPage( $post_id ) ) {
440
+			if ( ! current_user_can('manage_options')) {
441
+				if ( ! self::currentUserCanViewPage($post_id)) {
442 442
 					return $no_privilege;
443 443
 				}	
444 444
 			}
445 445
 
446 446
 			// Return the content if the post is not yet saved.
447
-			if ( false === $allowed_user_roles ) {
447
+			if (false === $allowed_user_roles) {
448 448
 				return $content;
449 449
 			}
450 450
 		}
@@ -458,30 +458,30 @@  discard block
 block discarded – undo
458 458
 	 * 
459 459
 	 * @return boolean True on success. Otherwise, false.
460 460
 	 */
461
-	public function currentUserCanViewPage( $post_id = 0 ) {
461
+	public function currentUserCanViewPage($post_id = 0) {
462 462
 
463
-		$allowed_roles = self::getAllowedUserRoles( $post_id );
463
+		$allowed_roles = self::getAllowedUserRoles($post_id);
464 464
 		
465 465
 		// if $allowed_roles is not set, it means meta data is not yet available.
466 466
 		// Post roles are checked but are not yet save. So allow viewing.
467
-		if ( ! $allowed_roles ) {
467
+		if ( ! $allowed_roles) {
468 468
 			return true;
469 469
 		}
470 470
 
471 471
 		// Only check for logged-in users.
472
-		if ( is_user_logged_in() ) {
472
+		if (is_user_logged_in()) {
473 473
 			
474 474
 			$can_view = false;
475 475
 
476 476
 			$user = wp_get_current_user();
477 477
 
478
-			if ( ! is_array( $user->roles ) ) {
478
+			if ( ! is_array($user->roles)) {
479 479
 				$user->roles = (array) $user->roles;
480 480
 			}
481 481
 
482
-			if ( ! empty( $user->roles ) && is_array( $user->roles ) ) {
483
-				foreach( $user->roles as $current_user_role ) {
484
-					if ( in_array( $current_user_role, $allowed_roles ) ) {
482
+			if ( ! empty($user->roles) && is_array($user->roles)) {
483
+				foreach ($user->roles as $current_user_role) {
484
+					if (in_array($current_user_role, $allowed_roles)) {
485 485
 						$can_view = true;
486 486
 					}
487 487
 				}
Please login to merge, or discard this patch.
classes/subway-enqueue.php 2 patches
Indentation   +32 added lines, -32 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,47 +36,47 @@  discard block
 block discarded – undo
36 36
 final class Enqueue
37 37
 {
38 38
 
39
-    /**
40
-     * Registers our CSS and Javascript to WordPress Enqueue Handler.
41
-     *
42
-     * @return void
43
-     */
44
-    public static function registerJs() 
45
-    {
39
+	/**
40
+	 * Registers our CSS and Javascript to WordPress Enqueue Handler.
41
+	 *
42
+	 * @return void
43
+	 */
44
+	public static function registerJs() 
45
+	{
46 46
 
47
-        $post_id = absint(get_queried_object_id());
47
+		$post_id = absint(get_queried_object_id());
48 48
 
49
-        $signin_page = absint(get_option('subway_login_page'));
49
+		$signin_page = absint(get_option('subway_login_page'));
50 50
 
51
-        wp_enqueue_style('subway-style', SUBWAY_DIR_URL . 'assets/css/subway.css');
51
+		wp_enqueue_style('subway-style', SUBWAY_DIR_URL . 'assets/css/subway.css');
52 52
 
53
-        // Only load the stylesheet and javascript documents inside our sign-in page.
54
-        if ($post_id === $signin_page ) {
53
+		// Only load the stylesheet and javascript documents inside our sign-in page.
54
+		if ($post_id === $signin_page ) {
55 55
 
56
-            if (! is_user_logged_in() ) {
56
+			if (! is_user_logged_in() ) {
57 57
 
58
-                wp_enqueue_script(
59
-                    'subway-script', 
60
-                    SUBWAY_DIR_URL . 'assets/js/subway.js', 
61
-                    array( 'jquery' )
62
-                );
58
+				wp_enqueue_script(
59
+					'subway-script', 
60
+					SUBWAY_DIR_URL . 'assets/js/subway.js', 
61
+					array( 'jquery' )
62
+				);
63 63
 
64
-                wp_localize_script(
65
-                    'subway-script', 'subway_config', array(
66
-                    'ajax_url' => admin_url('admin-ajax.php'),
67
-                    'login_http_error' => esc_html__(
68
-                        'An error occured while 
64
+				wp_localize_script(
65
+					'subway-script', 'subway_config', array(
66
+					'ajax_url' => admin_url('admin-ajax.php'),
67
+					'login_http_error' => esc_html__(
68
+						'An error occured while 
69 69
                     	transmitting the data. Refresh the page and try again', 
70
-                        'subway'
71
-                    ),
72
-                    )
73
-                );
70
+						'subway'
71
+					),
72
+					)
73
+				);
74 74
 
75
-            }
76
-        }
75
+			}
76
+		}
77 77
 
78
-        return;
78
+		return;
79 79
 
80
-    }
80
+	}
81 81
 
82 82
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 namespace Subway;
21 21
 
22
-if (! defined('ABSPATH') ) {
22
+if ( ! defined('ABSPATH')) {
23 23
     return;
24 24
 }
25 25
 
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
         wp_enqueue_style('subway-style', SUBWAY_DIR_URL . 'assets/css/subway.css');
52 52
 
53 53
         // Only load the stylesheet and javascript documents inside our sign-in page.
54
-        if ($post_id === $signin_page ) {
54
+        if ($post_id === $signin_page) {
55 55
 
56
-            if (! is_user_logged_in() ) {
56
+            if ( ! is_user_logged_in()) {
57 57
 
58 58
                 wp_enqueue_script(
59 59
                     'subway-script', 
60 60
                     SUBWAY_DIR_URL . 'assets/js/subway.js', 
61
-                    array( 'jquery' )
61
+                    array('jquery')
62 62
                 );
63 63
 
64 64
                 wp_localize_script(
Please login to merge, or discard this patch.
templates/login-form.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  * @link     github.com/codehaiku/subway The Plugin Repository
18 18
  */
19 19
 
20
-if ( ! defined( 'ABSPATH' ) ) {
20
+if ( ! defined('ABSPATH')) {
21 21
 	return;
22 22
 }
23 23
 
@@ -25,100 +25,100 @@  discard block
 block discarded – undo
25 25
 
26 26
 $message_types = array();
27 27
 
28
-$http_request_login = filter_input( INPUT_GET, 'login', FILTER_SANITIZE_SPECIAL_CHARS );
28
+$http_request_login = filter_input(INPUT_GET, 'login', FILTER_SANITIZE_SPECIAL_CHARS);
29 29
 
30
-$http_request_type = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_SPECIAL_CHARS );
30
+$http_request_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_SPECIAL_CHARS);
31 31
 
32
-$http_request_logout = filter_input( INPUT_GET, 'loggedout', FILTER_SANITIZE_SPECIAL_CHARS );
32
+$http_request_logout = filter_input(INPUT_GET, 'loggedout', FILTER_SANITIZE_SPECIAL_CHARS);
33 33
 
34
-if ( isset( $http_request_login ) ) {
34
+if (isset($http_request_login)) {
35 35
 
36
-	if ( 'failed' === $http_request_login ) {
36
+	if ('failed' === $http_request_login) {
37 37
 
38
-		if ( isset( $http_request_type ) ) {
38
+		if (isset($http_request_type)) {
39 39
 
40 40
 			$message_types = array(
41 41
 
42 42
 				'default' => array(
43
-						'message' => __( 'There was an error trying to sign-in to your account. Make sure the credentials below are correct.', 'subway' ),
43
+						'message' => __('There was an error trying to sign-in to your account. Make sure the credentials below are correct.', 'subway'),
44 44
 					),
45 45
 				'__blank' => array(
46
-						'message' => __( 'Required: Username and Password cannot be empty.', 'subway' ),
46
+						'message' => __('Required: Username and Password cannot be empty.', 'subway'),
47 47
 					),
48 48
 				'__userempty' => array(
49
-						'message' => __( 'Required: Username cannot be empty.', 'subway' ),
49
+						'message' => __('Required: Username cannot be empty.', 'subway'),
50 50
 					),
51 51
 				'__passempty' => array(
52
-						'message' => __( 'Required: Password cannot be empty.', 'subway' ),
52
+						'message' => __('Required: Password cannot be empty.', 'subway'),
53 53
 					),
54 54
 				'fb_invalid_email' => array(
55
-						'message' => __( 'Facebook email address is invalid or is not yet verified.', 'subway' ),
55
+						'message' => __('Facebook email address is invalid or is not yet verified.', 'subway'),
56 56
 					),
57 57
 				'fb_error' => array(
58
-						'message' => __( 'Facebook Application Error. Misconfigured or App is rejected.', 'subway' ),
58
+						'message' => __('Facebook Application Error. Misconfigured or App is rejected.', 'subway'),
59 59
 					),
60 60
 				'app_not_live' => array(
61
-						'message' => __( 'Unable to fetch your Facebook Profile.', 'subway' ),
61
+						'message' => __('Unable to fetch your Facebook Profile.', 'subway'),
62 62
 					),
63 63
 				'gears_username_or_email_exists' => array(
64
-						'message' => __( 'Username or email address already exists', 'subway' ),
64
+						'message' => __('Username or email address already exists', 'subway'),
65 65
 					),
66 66
 				'gp_error_authentication' => array(
67
-						'message' => __( 'Google Plus Authentication Error. Invalid Client ID or Secret.', 'subway' ),
67
+						'message' => __('Google Plus Authentication Error. Invalid Client ID or Secret.', 'subway'),
68 68
 					),
69 69
 			);
70 70
 
71 71
 			$message = $message_types['default']['message'];
72 72
 
73
-			if ( array_key_exists( $http_request_type, $message_types ) ) {
73
+			if (array_key_exists($http_request_type, $message_types)) {
74 74
 
75
-				$message = $message_types[ $http_request_type ]['message'];
75
+				$message = $message_types[$http_request_type]['message'];
76 76
 
77 77
 			}
78 78
 
79
-			$error_login_message = '<div id="message" class="error">' . esc_html( $message ) . '</div>';
79
+			$error_login_message = '<div id="message" class="error">' . esc_html($message) . '</div>';
80 80
 
81 81
 		} else {
82 82
 
83
-			$error_login_message = '<div id="message" class="error">' . esc_html__( 'Error: Invalid username and password combination.', 'subway' ) . '</div>';
83
+			$error_login_message = '<div id="message" class="error">' . esc_html__('Error: Invalid username and password combination.', 'subway') . '</div>';
84 84
 
85 85
 		}
86 86
 	}
87 87
 }
88 88
 
89
-if ( isset( $http_request_logout ) ) {
90
-	$error_login_message = '<div id="message" class="success">' . esc_html__( 'You have logged out successfully.', 'subway' ) . '</div>';
89
+if (isset($http_request_logout)) {
90
+	$error_login_message = '<div id="message" class="success">' . esc_html__('You have logged out successfully.', 'subway') . '</div>';
91 91
 }
92 92
 
93
-$http_request_redirected = filter_input( INPUT_GET, '_redirected', FILTER_SANITIZE_SPECIAL_CHARS );
93
+$http_request_redirected = filter_input(INPUT_GET, '_redirected', FILTER_SANITIZE_SPECIAL_CHARS);
94 94
 
95
-if ( isset( $http_request_redirected ) ) {
96
-	$error_login_message = '<div id="message" class="success">' . esc_html__( 'Members only page. Please use the login form below to access the page.', 'subway' ) . '</div>';
95
+if (isset($http_request_redirected)) {
96
+	$error_login_message = '<div id="message" class="success">' . esc_html__('Members only page. Please use the login form below to access the page.', 'subway') . '</div>';
97 97
 }
98 98
 
99 99
 ?>
100
-<?php if ( ! is_user_logged_in() ) { ?>
100
+<?php if ( ! is_user_logged_in()) { ?>
101 101
 	<div class="mg-top-35 mg-bottom-35 subway-login-form">
102 102
 		<div class="subway-login-form-form">
103 103
 			<div class="subway-login-form__actions">
104 104
 				<h3>
105
-					<?php esc_html_e( 'Account Sign-in', 'subway' ); ?>
105
+					<?php esc_html_e('Account Sign-in', 'subway'); ?>
106 106
 				</h3>
107
-				<?php do_action( 'gears_login_form' ); ?>
107
+				<?php do_action('gears_login_form'); ?>
108 108
 			</div>
109 109
 			<div class="subway-login-form-message">
110
-				<?php echo wp_kses_post( $error_login_message ); ?>
110
+				<?php echo wp_kses_post($error_login_message); ?>
111 111
 			</div>
112 112
 			<div class="subway-login-form__form">
113
-				<?php echo wp_login_form( $atts ); ?>
113
+				<?php echo wp_login_form($atts); ?>
114 114
 			</div>
115 115
 		</div>
116 116
 	</div>
117 117
 <?php } else { ?>
118 118
 	<div class="mg-top-35 mg-bottom-35 subway-login-sucessfull">
119 119
 		<p style="margin-bottom: 0px;">
120
-			<?php $success_message = apply_filters( 'subway_login_message_success', esc_html__( 'You are currently logged-in.', 'subway' ) ); ?>
121
-			<?php echo esc_html( $success_message ); ?>
120
+			<?php $success_message = apply_filters('subway_login_message_success', esc_html__('You are currently logged-in.', 'subway')); ?>
121
+			<?php echo esc_html($success_message); ?>
122 122
 			
123 123
 		</p>
124 124
 	</div>
Please login to merge, or discard this patch.
settings-fields/field-subway-lock-wp-admin.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @package Subway
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	return;
15 15
 }
16 16
 
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
 
19 19
 	<p class="description">
20 20
 		<?php
21
-			echo sprintf( __( "In case you were locked out. Use the link below to bypass the log-in page and go directly
22
-			to your website's wp-login URL (http://yoursiteurl.com/wp-login.php): <strong class='subway-settings-text-notice'>%s</strong>", 'subway' ), site_url( 'wp-login.php?no_redirect=true' ) ); 
21
+			echo sprintf(__("In case you were locked out. Use the link below to bypass the log-in page and go directly
22
+			to your website's wp-login URL (http://yoursiteurl.com/wp-login.php): <strong class='subway-settings-text-notice'>%s</strong>", 'subway'), site_url('wp-login.php?no_redirect=true')); 
23 23
 		?>
24 24
 	</p>
25 25
 <?php
Please login to merge, or discard this patch.