@@ -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,182 +36,182 @@ discard block |
||
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 | - $log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING); |
|
50 | + $log = filter_input(INPUT_POST, 'log', FILTER_SANITIZE_STRING); |
|
51 | 51 | |
52 | - $pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING); |
|
52 | + $pwd = filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING); |
|
53 | 53 | |
54 | - if (empty($log) && empty($pwd) ) { |
|
54 | + if (empty($log) && empty($pwd) ) { |
|
55 | 55 | |
56 | - $response['type'] = 'error'; |
|
56 | + $response['type'] = 'error'; |
|
57 | 57 | |
58 | - $response['message'] = esc_html__( |
|
59 | - 'Username and Password cannot be empty.', |
|
60 | - 'subway' |
|
61 | - ); |
|
58 | + $response['message'] = esc_html__( |
|
59 | + 'Username and Password cannot be empty.', |
|
60 | + 'subway' |
|
61 | + ); |
|
62 | 62 | |
63 | - } else { |
|
63 | + } else { |
|
64 | 64 | |
65 | - $is_signin = wp_signon(); |
|
65 | + $is_signin = wp_signon(); |
|
66 | 66 | |
67 | - $response = array(); |
|
67 | + $response = array(); |
|
68 | 68 | |
69 | - if (is_wp_error($is_signin) ) { |
|
69 | + if (is_wp_error($is_signin) ) { |
|
70 | 70 | |
71 | - $response['type'] = 'error'; |
|
71 | + $response['type'] = 'error'; |
|
72 | 72 | |
73 | - $response['message'] = $is_signin->get_error_message(); |
|
73 | + $response['message'] = $is_signin->get_error_message(); |
|
74 | 74 | |
75 | - } else { |
|
75 | + } else { |
|
76 | 76 | |
77 | - $response['type'] = 'success'; |
|
77 | + $response['type'] = 'success'; |
|
78 | 78 | |
79 | - $response['message'] = esc_html__( |
|
80 | - 'You have successfully logged-in. Redirecting you in few seconds...', |
|
81 | - 'subway' |
|
82 | - ); |
|
79 | + $response['message'] = esc_html__( |
|
80 | + 'You have successfully logged-in. Redirecting you in few seconds...', |
|
81 | + 'subway' |
|
82 | + ); |
|
83 | 83 | |
84 | - } |
|
85 | - } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - $subway_redirect_url = AuthRedirect::getLoginRedirectUrl('', $is_signin); |
|
87 | + $subway_redirect_url = AuthRedirect::getLoginRedirectUrl('', $is_signin); |
|
88 | 88 | |
89 | - $response['redirect_url'] = apply_filters( |
|
90 | - 'subway_login_redirect', |
|
91 | - $subway_redirect_url |
|
92 | - ); |
|
89 | + $response['redirect_url'] = apply_filters( |
|
90 | + 'subway_login_redirect', |
|
91 | + $subway_redirect_url |
|
92 | + ); |
|
93 | 93 | |
94 | - echo wp_json_encode($response); |
|
94 | + echo wp_json_encode($response); |
|
95 | 95 | |
96 | - wp_die(); |
|
96 | + wp_die(); |
|
97 | 97 | |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Returns the filtered redirect url for the current user. |
|
102 | - * |
|
103 | - * @param string $redirect_to The default redirect callback argument. |
|
104 | - * @param mixed $user This holds the meta info of currently logged-in user. |
|
105 | - * |
|
106 | - * @return string The final redirect url. |
|
107 | - */ |
|
108 | - public static function getLoginRedirectUrl( $redirect_to, $user ) |
|
109 | - { |
|
100 | + /** |
|
101 | + * Returns the filtered redirect url for the current user. |
|
102 | + * |
|
103 | + * @param string $redirect_to The default redirect callback argument. |
|
104 | + * @param mixed $user This holds the meta info of currently logged-in user. |
|
105 | + * |
|
106 | + * @return string The final redirect url. |
|
107 | + */ |
|
108 | + public static function getLoginRedirectUrl( $redirect_to, $user ) |
|
109 | + { |
|
110 | 110 | |
111 | - $subway_redirect_type = get_option('subway_redirect_type'); |
|
111 | + $subway_redirect_type = get_option('subway_redirect_type'); |
|
112 | 112 | |
113 | - // Redirect the user to default behaviour. |
|
114 | - // If there are no redirect type option saved. |
|
115 | - if (empty($subway_redirect_type) ) { |
|
113 | + // Redirect the user to default behaviour. |
|
114 | + // If there are no redirect type option saved. |
|
115 | + if (empty($subway_redirect_type) ) { |
|
116 | 116 | |
117 | - return $redirect_to; |
|
117 | + return $redirect_to; |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | - if ('default' === $subway_redirect_type ) { |
|
122 | - return $redirect_to; |
|
123 | - } |
|
121 | + if ('default' === $subway_redirect_type ) { |
|
122 | + return $redirect_to; |
|
123 | + } |
|
124 | 124 | |
125 | - if ('page' === $subway_redirect_type ) { |
|
125 | + if ('page' === $subway_redirect_type ) { |
|
126 | 126 | |
127 | - // Get the page url of the selected page. |
|
128 | - // If the admin selected 'Custom Page' in the redirect type settings. |
|
129 | - $selected_redirect_page = intval(get_option('subway_redirect_page_id')); |
|
127 | + // Get the page url of the selected page. |
|
128 | + // If the admin selected 'Custom Page' in the redirect type settings. |
|
129 | + $selected_redirect_page = intval(get_option('subway_redirect_page_id')); |
|
130 | 130 | |
131 | - // Redirect to default WordPress behaviour. |
|
132 | - // If the user did not select page. |
|
133 | - if (empty($selected_redirect_page) ) { |
|
131 | + // Redirect to default WordPress behaviour. |
|
132 | + // If the user did not select page. |
|
133 | + if (empty($selected_redirect_page) ) { |
|
134 | 134 | |
135 | - return $redirect_to; |
|
136 | - } |
|
135 | + return $redirect_to; |
|
136 | + } |
|
137 | 137 | |
138 | - // Otherwise, get the permalink of the saved page |
|
139 | - // and let the user go into that page. |
|
140 | - return get_permalink($selected_redirect_page); |
|
138 | + // Otherwise, get the permalink of the saved page |
|
139 | + // and let the user go into that page. |
|
140 | + return get_permalink($selected_redirect_page); |
|
141 | 141 | |
142 | - } elseif ('custom_url' === $subway_redirect_type ) { |
|
142 | + } elseif ('custom_url' === $subway_redirect_type ) { |
|
143 | 143 | |
144 | - // Get the custom url saved in the redirect type settings. |
|
145 | - $entered_custom_url = get_option('subway_redirect_custom_url'); |
|
144 | + // Get the custom url saved in the redirect type settings. |
|
145 | + $entered_custom_url = get_option('subway_redirect_custom_url'); |
|
146 | 146 | |
147 | - // Redirect to default WordPress behaviour |
|
148 | - // if the user did enter a custom url. |
|
149 | - if (empty($entered_custom_url) ) { |
|
147 | + // Redirect to default WordPress behaviour |
|
148 | + // if the user did enter a custom url. |
|
149 | + if (empty($entered_custom_url) ) { |
|
150 | 150 | |
151 | - return $redirect_to; |
|
151 | + return $redirect_to; |
|
152 | 152 | |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | - // Otherwise, get the custom url saved |
|
156 | - // and let the user go into that page. |
|
157 | - if (! empty($user->ID) ) { |
|
158 | - $entered_custom_url = str_replace( |
|
159 | - '%user_id%', $user->ID, |
|
160 | - $entered_custom_url |
|
161 | - ); |
|
162 | - } |
|
155 | + // Otherwise, get the custom url saved |
|
156 | + // and let the user go into that page. |
|
157 | + if (! empty($user->ID) ) { |
|
158 | + $entered_custom_url = str_replace( |
|
159 | + '%user_id%', $user->ID, |
|
160 | + $entered_custom_url |
|
161 | + ); |
|
162 | + } |
|
163 | 163 | |
164 | - if (! empty($user->user_login) ) { |
|
165 | - $entered_custom_url = str_replace( |
|
166 | - '%user_name%', $user->user_login, |
|
167 | - $entered_custom_url |
|
168 | - ); |
|
169 | - } |
|
164 | + if (! empty($user->user_login) ) { |
|
165 | + $entered_custom_url = str_replace( |
|
166 | + '%user_name%', $user->user_login, |
|
167 | + $entered_custom_url |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | - return $entered_custom_url; |
|
171 | + return $entered_custom_url; |
|
172 | 172 | |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - // Otherwise, quit and redirect the user back to default WordPress behaviour. |
|
176 | - return $redirect_to; |
|
177 | - } |
|
175 | + // Otherwise, quit and redirect the user back to default WordPress behaviour. |
|
176 | + return $redirect_to; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Callback function for the 'login_url' filter defined in Subway.php |
|
181 | - * |
|
182 | - * @param string $login_url The login url. |
|
183 | - * |
|
184 | - * @return string The final login url. |
|
185 | - */ |
|
186 | - public static function loginUrl( $login_url ) |
|
187 | - { |
|
179 | + /** |
|
180 | + * Callback function for the 'login_url' filter defined in Subway.php |
|
181 | + * |
|
182 | + * @param string $login_url The login url. |
|
183 | + * |
|
184 | + * @return string The final login url. |
|
185 | + */ |
|
186 | + public static function loginUrl( $login_url ) |
|
187 | + { |
|
188 | 188 | |
189 | - $subway_login_page = Options::getRedirectPageUrl(); |
|
189 | + $subway_login_page = Options::getRedirectPageUrl(); |
|
190 | 190 | |
191 | - // Return the default login url if there is no log-in page defined. |
|
192 | - if (empty($subway_login_page) ) { |
|
193 | - return $login_url; |
|
194 | - } |
|
191 | + // Return the default login url if there is no log-in page defined. |
|
192 | + if (empty($subway_login_page) ) { |
|
193 | + return $login_url; |
|
194 | + } |
|
195 | 195 | |
196 | - // Otherwise, return the Subway login page. |
|
197 | - return $subway_login_page; |
|
196 | + // Otherwise, return the Subway login page. |
|
197 | + return $subway_login_page; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * The callback function for our logout filter. |
|
203 | - * |
|
204 | - * @return void |
|
205 | - */ |
|
206 | - public static function logoutUrl() |
|
207 | - { |
|
201 | + /** |
|
202 | + * The callback function for our logout filter. |
|
203 | + * |
|
204 | + * @return void |
|
205 | + */ |
|
206 | + public static function logoutUrl() |
|
207 | + { |
|
208 | 208 | |
209 | - $subway_login_page = Options::getRedirectPageUrl(); |
|
209 | + $subway_login_page = Options::getRedirectPageUrl(); |
|
210 | 210 | |
211 | - wp_safe_redirect(esc_url($subway_login_page . '?loggedout=true')); |
|
211 | + wp_safe_redirect(esc_url($subway_login_page . '?loggedout=true')); |
|
212 | 212 | |
213 | - Helpers::close(); |
|
213 | + Helpers::close(); |
|
214 | 214 | |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | 217 | } |