PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.2.2
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.2.2
4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Classes / ModifyRedirectDefaultLinks.php
wp-user-avatar / src / Classes Last commit date
Installer 5 years ago AdminNotices.php 4 years ago AjaxHandler.php 4 years ago Autologin.php 4 years ago BuddyPressBbPress.php 5 years ago EditUserProfile.php 4 years ago ExtensionManager.php 5 years ago FileUploader.php 4 years ago FormPreviewHandler.php 5 years ago FormRepository.php 4 years ago FormShortcodeDefaults.php 5 years ago GDPR.php 5 years ago GlobalSiteAccess.php 4 years ago ImageUploader.php 4 years ago LoginAuth.php 4 years ago Miscellaneous.php 5 years ago ModifyRedirectDefaultLinks.php 5 years ago PPRESS_Session.php 4 years ago PROFILEPRESS_sql.php 5 years ago PasswordReset.php 5 years ago ProfileUrlRewrite.php 4 years ago RegistrationAuth.php 4 years ago SendEmail.php 5 years ago ShortcodeThemeFactory.php 5 years ago UserAvatar.php 4 years ago UserSignupLocationListingPage.php 5 years ago UsernameEmailRestrictLogin.php 5 years ago WelcomeEmailAfterSignup.php 5 years ago default-email-template.php 5 years ago index.php 5 years ago
ModifyRedirectDefaultLinks.php
383 lines
1 <?php
2
3 namespace ProfilePress\Core\Classes;
4
5 /**
6 * Alter default login, registration, password_reset login and logout url
7 */
8 class ModifyRedirectDefaultLinks
9 {
10 public function __construct()
11 {
12 add_action('login_form_lostpassword', array($this, 'redirect_password_reset_page'));
13 add_filter('lostpassword_url', array($this, 'lost_password_url_func'), 999999999);
14
15 add_action('login_form_login', array($this, 'redirect_login_page'));
16 add_filter('login_url', array($this, 'set_login_url_func'), 999999999, 3);
17
18 add_action('login_form_register', array($this, 'redirect_reg_page'));
19 add_filter('register_url', array($this, 'register_url_func'), 999999999);
20
21 add_filter('logout_url', array($this, 'logout_url_func'), 999999999, 2);
22
23 add_filter('author_link', array($this, 'author_link_func'), 999999999, 2);
24
25 add_filter('get_comment_author_url', array($this, 'comment_author_url_to_profile'), 999999999, 3);
26
27 add_action('init', array($this, 'redirect_default_edit_profile_to_custom'));
28
29 // redirect buddypress registration to PP custom registration page or default WP registration url if not set
30 add_action('template_redirect', array($this, 'redirect_bp_registration_page'));
31 add_filter('bp_get_signup_page', array($this, 'rewrite_bp_registration_url'));
32
33 // redirect default logout page to blog homepage
34 add_action('init', array($this, 'redirect_logout_page'));
35
36 add_action('template_redirect', [$this, 'redirect_author_page']);
37 }
38
39 public function is_third_party_2fa_active()
40 {
41 global $pagenow;
42
43 if ('wp-login.php' == $pagenow) {
44
45 if (class_exists('Jetpack') && \Jetpack::is_module_active('sso')) {
46 return true;
47 }
48
49 if (function_exists('wd_di') && class_exists('\WP_Defender\Model\Setting\Two_Fa')) {
50 try {
51 if (wd_di()->get(\WP_Defender\Model\Setting\Two_Fa::class)->enabled) return true;
52 } catch (\Exception $e) {
53 }
54 }
55
56 if (defined('WORDFENCE_VERSION') || defined('WORDFENCE_LS_VERSION')) {
57 return true;
58 }
59
60 if (defined('WP_2FA_VERSION')) return true;
61
62 if (defined('SIMBA_TFA_PLUGIN_DIR')) return true;
63
64 if (class_exists('\SG_Security\Options_Service\Options_Service') && \SG_Security\Options_Service\Options_Service::is_enabled('sg2fa')) {
65 return true;
66 }
67 }
68
69 return false;
70 }
71
72 /**
73 * Modify the lost password url returned by wp_lostpassword_url() function.
74 *
75 * @param $val
76 *
77 * @return string
78 */
79 public function lost_password_url_func($val)
80 {
81 $page_id = ppress_get_setting('set_lost_password_url');
82
83 if ( ! empty($page_id) && 'publish' == get_post_status($page_id)) {
84 $val = get_permalink($page_id);
85 }
86
87 return apply_filters('ppress_password_reset_url', $val);
88 }
89
90 /**
91 * Force redirection of default password reset to the page with custom one.
92 */
93 public function redirect_password_reset_page()
94 {
95 if ( ! apply_filters('ppress_default_password_reset_redirect_enabled', true)) return;
96
97 $page_id = ppress_get_setting('set_lost_password_url');
98
99 if (empty($page_id) || 'publish' != get_post_status($page_id)) return;
100
101 wp_safe_redirect(get_permalink(absint($page_id)));
102 exit;
103 }
104
105 /**
106 * Modify the login url returned by wp_login_url()
107 *
108 * @param $url
109 * @param string $redirect
110 * @param bool $force_reauth
111 *
112 * @return string page with login shortcode
113 */
114 public function set_login_url_func($url, $redirect = '', $force_reauth = false)
115 {
116 if ( ! $this->is_third_party_2fa_active()) {
117 $login_page_id = ppress_get_setting('set_login_url');
118
119 if ( ! empty($login_page_id) && 'publish' == get_post_status($login_page_id)) {
120
121 $url = get_permalink($login_page_id);
122
123 if ( ! empty($redirect)) {
124 $url = add_query_arg('redirect_to', rawurlencode(wp_validate_redirect($redirect)), $url);
125 }
126
127 if ($force_reauth) {
128 $url = add_query_arg('reauth', '1', $url);
129 }
130
131 $url = esc_url_raw($url);
132 }
133 }
134
135 return apply_filters('ppress_login_url', $url, $redirect, $force_reauth);
136 }
137
138 /**
139 * Force redirect default login to page with login shortcode
140 */
141 public function redirect_login_page()
142 {
143 if ( ! apply_filters('ppress_default_login_redirect_enabled', true)) return;
144
145 if ($this->is_third_party_2fa_active()) return;
146
147 $login_page_id = ppress_get_setting('set_login_url');
148
149 if (empty($login_page_id) || ('publish' != get_post_status($login_page_id))) return;
150
151 $login_url = ppress_login_url();
152
153 // retrieve the query string if available.
154 $query_string = ! empty($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"] : parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
155
156 // if query string is available, append to login url.
157 if ( ! empty($query_string)) {
158 if (strpos($login_url, '?') !== false) {
159 $login_url .= "&$query_string";
160 } else {
161 $login_url .= "?$query_string";
162 }
163 }
164
165 wp_safe_redirect(esc_url_raw($login_url));
166 exit;
167 }
168
169 /**
170 * Modify the url returned by wp_registration_url().
171 *
172 * @return string page url with registration shortcode.
173 */
174 public function register_url_func($val)
175 {
176 $page_id = ppress_get_setting('set_registration_url');
177
178 if ( ! empty($page_id) && 'publish' == get_post_status($page_id)) {
179 $val = get_permalink($page_id);
180 }
181
182 return apply_filters('ppress_registration_url', $val);
183 }
184
185 /**
186 * force redirection of default registration to custom one
187 */
188 public function redirect_reg_page()
189 {
190 if ( ! apply_filters('ppress_default_registration_redirect_enabled', true)) return;
191
192 $page_id = ppress_get_setting('set_registration_url');
193
194 if (empty($page_id) || 'publish' != get_post_status($page_id)) return;
195
196 $reg_url = ppress_registration_url();
197
198 wp_safe_redirect(esc_url_raw($reg_url));
199 exit;
200 }
201
202 /**
203 * Add query string (url) to logout url which is url to redirect to after logout
204 *
205 * @param $logout_url string filter default login url to be modified
206 * @param $redirect string where to redirect to after logout
207 *
208 * @return string
209 */
210 public function logout_url_func($logout_url, $redirect)
211 {
212 $set_redirect = false;
213
214 $custom_logout_page_url = ppress_get_setting('custom_url_log_out');
215 $logout_page_id = ppress_get_setting('set_log_out_url');
216
217 if ( ! empty($custom_logout_page_url)) {
218 $set_redirect = $custom_logout_page_url;
219 } elseif ( ! empty($logout_page_id)) {
220
221 if ($logout_page_id != 'default') {
222
223 $db_logout_url = get_permalink(absint($logout_page_id));
224
225 $set_redirect = $db_logout_url;
226
227 if (empty($db_logout_url) || $logout_page_id == 'current_view_page') {
228 // make redirect currently viewed page
229 $set_redirect = get_permalink();
230 }
231 }
232 }
233
234 if ($set_redirect) {
235 $set_redirect = apply_filters('ppress_logout_redirect', $set_redirect);
236 $logout_url = esc_url_raw(add_query_arg('redirect_to', rawurlencode($set_redirect), $logout_url));
237 }
238
239 return $logout_url;
240 }
241
242 /**
243 * Redirect user edit profile (/wp-admin/profile.php) to "custom edit profile" page.
244 */
245 public function redirect_default_edit_profile_to_custom()
246 {
247 if (ppress_settings_by_key('redirect_default_edit_profile_to_custom') == 'yes') {
248
249 add_filter('edit_profile_url', function ($url) {
250 $page_id = ppress_settings_by_key('edit_user_profile_url');
251
252 if ( ! empty($page_id)) {
253 $url = esc_url_raw(get_permalink($page_id));
254 }
255
256 return $url;
257
258 }, 9999999999);
259
260 // Filter to disable edit profile redirect for administrator.
261 $disable = apply_filters('ppress_disable_admin_edit_profile_redirect', false);
262
263 if ($disable && current_user_can('delete_users')) return;
264
265 if ( ! empty(ppress_get_setting('edit_user_profile_url'))) {
266
267 $edit_user_profile_url = ppress_edit_profile_url();
268
269 $page_viewed = esc_url_raw($_SERVER['REQUEST_URI']);
270
271 if (isset($page_viewed) && strpos($page_viewed, 'wp-admin/profile.php') !== false) {
272 wp_safe_redirect(esc_url_raw($edit_user_profile_url));
273 exit;
274 }
275 }
276 }
277 }
278
279 public function author_link_func($url, $author_id)
280 {
281 if (ppress_settings_by_key('author_slug_to_profile') == 'on') {
282 $url = esc_url_raw(ppress_get_frontend_profile_url($author_id));
283 }
284
285 return $url;
286 }
287
288 /**
289 * @param $url
290 * @param int $id comment ID
291 * @param \WP_Comment $comment
292 *
293 * @return string|void
294 */
295 public function comment_author_url_to_profile($url, $id, $comment)
296 {
297 if (ppress_settings_by_key('comment_author_url_to_profile') == 'on') {
298 if (is_object($comment) && isset($comment->comment_author_email)) {
299 $email = $comment->comment_author_email;
300 $user = get_user_by('email', $email);
301 if (isset($user->user_login)) {
302 $url = esc_url_raw(ppress_get_frontend_profile_url($user->user_login));
303 }
304 }
305 }
306
307 return $url;
308 }
309
310 /**
311 * Redirect the default logout page (/wp-login.php?loggedout=true) to blog homepage
312 */
313 public function redirect_logout_page()
314 {
315 $page_viewed = basename(esc_url_raw($_SERVER['REQUEST_URI']));
316
317 if ($page_viewed == "wp-login.php?loggedout=true" && $_SERVER['REQUEST_METHOD'] == 'GET') {
318 wp_safe_redirect(home_url());
319 exit;
320 }
321 }
322
323 public function redirect_bp_registration_page()
324 {
325 if ( ! class_exists('BuddyPress') && ! function_exists('bp_has_custom_signup_page')) {
326 return;
327 }
328
329 if ( ! bp_has_custom_signup_page()) return;
330
331 if (ppress_get_setting('redirect_bp_registration_page') == 'yes') {
332 // ! bp_has_custom_signup_page()
333 $page = bp_get_root_domain() . '/' . bp_get_signup_slug();
334
335 if ($page == ppress_get_current_url()) {
336 wp_safe_redirect(ppress_registration_url());
337 exit;
338 }
339 }
340 }
341
342 /**
343 * Rewrite buddypress registration url to PP custom url or WP's if not set.
344 *
345 * @param string $page
346 *
347 * @return string
348 */
349 public function rewrite_bp_registration_url($page)
350 {
351 if (ppress_get_setting('redirect_bp_registration_page') == 'yes') {
352
353 if (apply_filters('ppress_bp_registration_url', true)) {
354 $page = ppress_registration_url();
355 }
356 }
357
358 return $page;
359 }
360
361 /**
362 * Redirect author page to user's profile
363 */
364 public function redirect_author_page()
365 {
366 if (ppress_settings_by_key('author_slug_to_profile') == 'on' && is_author()) {
367 $id = get_query_var('author');
368 wp_redirect(ppress_get_frontend_profile_url($id));
369 exit;
370 }
371 }
372
373 public static function get_instance()
374 {
375 static $instance = false;
376
377 if ( ! $instance) {
378 $instance = new self;
379 }
380
381 return $instance;
382 }
383 }