PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
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 4 years ago FileUploader.php 4 years ago FormPreviewHandler.php 5 years ago FormRepository.php 4 years ago FormShortcodeDefaults.php 5 years ago GDPR.php 4 years ago Geolocation.php 4 years ago GlobalSiteAccess.php 4 years ago ImageUploader.php 4 years ago LoginAuth.php 4 years ago Miscellaneous.php 4 years ago ModifyRedirectDefaultLinks.php 4 years ago PPRESS_Session.php 4 years ago PROFILEPRESS_sql.php 4 years ago PasswordReset.php 4 years ago ProfileUrlRewrite.php 4 years ago RegistrationAuth.php 4 years ago SendEmail.php 4 years ago ShortcodeThemeFactory.php 5 years ago UserAvatar.php 4 years ago UserSignupLocationListingPage.php 4 years ago UsernameEmailRestrictLogin.php 4 years ago WPProfileFieldParserTrait.php 4 years ago WelcomeEmailAfterSignup.php 4 years ago default-email-template.php 4 years ago index.php 5 years ago
ModifyRedirectDefaultLinks.php
389 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 if (apply_filters('ppress_logout_url_enable_redirect_get_query', false) && ! empty($redirect)) {
213 return $logout_url;
214 }
215
216 $set_redirect = false;
217
218 $custom_logout_page_url = ppress_get_setting('custom_url_log_out');
219 $logout_page_id = ppress_get_setting('set_log_out_url');
220
221 if (apply_filters('ppress_logout_url_enable_redirect_get_query', false) && ! empty($redirect)) {
222 $set_redirect = $redirect;
223 } elseif ( ! empty($custom_logout_page_url)) {
224 $set_redirect = $custom_logout_page_url;
225 } elseif ( ! empty($logout_page_id)) {
226
227 if ($logout_page_id != 'default') {
228
229 $db_logout_url = get_permalink(absint($logout_page_id));
230
231 $set_redirect = $db_logout_url;
232
233 if (empty($db_logout_url) || $logout_page_id == 'current_view_page') {
234 // make redirect currently viewed page
235 $set_redirect = get_permalink();
236 }
237 }
238 }
239
240 if ( ! empty($set_redirect)) {
241 $set_redirect = apply_filters('ppress_logout_redirect', $set_redirect);
242 $logout_url = esc_url_raw(add_query_arg('redirect_to', rawurlencode($set_redirect), $logout_url));
243 }
244
245 return $logout_url;
246 }
247
248 /**
249 * Redirect user edit profile (/wp-admin/profile.php) to "custom edit profile" page.
250 */
251 public function redirect_default_edit_profile_to_custom()
252 {
253 if (ppress_settings_by_key('redirect_default_edit_profile_to_custom') == 'yes') {
254
255 add_filter('edit_profile_url', function ($url) {
256 $page_id = ppress_settings_by_key('edit_user_profile_url');
257
258 if ( ! empty($page_id)) {
259 $url = esc_url_raw(get_permalink($page_id));
260 }
261
262 return $url;
263
264 }, 9999999999);
265
266 // Filter to disable edit profile redirect for administrator.
267 $disable = apply_filters('ppress_disable_admin_edit_profile_redirect', false);
268
269 if ($disable && current_user_can('delete_users')) return;
270
271 if ( ! empty(ppress_get_setting('edit_user_profile_url'))) {
272
273 $edit_user_profile_url = ppress_edit_profile_url();
274
275 $page_viewed = esc_url_raw($_SERVER['REQUEST_URI']);
276
277 if (isset($page_viewed) && strpos($page_viewed, 'wp-admin/profile.php') !== false) {
278 wp_safe_redirect(esc_url_raw($edit_user_profile_url));
279 exit;
280 }
281 }
282 }
283 }
284
285 public function author_link_func($url, $author_id)
286 {
287 if (ppress_settings_by_key('author_slug_to_profile') == 'on') {
288 $url = esc_url_raw(ppress_get_frontend_profile_url($author_id));
289 }
290
291 return $url;
292 }
293
294 /**
295 * @param $url
296 * @param int $id comment ID
297 * @param \WP_Comment $comment
298 *
299 * @return string|void
300 */
301 public function comment_author_url_to_profile($url, $id, $comment)
302 {
303 if (ppress_settings_by_key('comment_author_url_to_profile') == 'on') {
304 if (is_object($comment) && isset($comment->comment_author_email)) {
305 $email = $comment->comment_author_email;
306 $user = get_user_by('email', $email);
307 if (isset($user->user_login)) {
308 $url = esc_url_raw(ppress_get_frontend_profile_url($user->user_login));
309 }
310 }
311 }
312
313 return $url;
314 }
315
316 /**
317 * Redirect the default logout page (/wp-login.php?loggedout=true) to blog homepage
318 */
319 public function redirect_logout_page()
320 {
321 $page_viewed = basename(esc_url_raw($_SERVER['REQUEST_URI']));
322
323 if ($page_viewed == "wp-login.php?loggedout=true" && $_SERVER['REQUEST_METHOD'] == 'GET') {
324 wp_safe_redirect(home_url());
325 exit;
326 }
327 }
328
329 public function redirect_bp_registration_page()
330 {
331 if ( ! class_exists('BuddyPress') && ! function_exists('bp_has_custom_signup_page')) {
332 return;
333 }
334
335 if ( ! bp_has_custom_signup_page()) return;
336
337 if (ppress_get_setting('redirect_bp_registration_page') == 'yes') {
338 // ! bp_has_custom_signup_page()
339 $page = bp_get_root_domain() . '/' . bp_get_signup_slug();
340
341 if ($page == ppress_get_current_url()) {
342 wp_safe_redirect(ppress_registration_url());
343 exit;
344 }
345 }
346 }
347
348 /**
349 * Rewrite buddypress registration url to PP custom url or WP's if not set.
350 *
351 * @param string $page
352 *
353 * @return string
354 */
355 public function rewrite_bp_registration_url($page)
356 {
357 if (ppress_get_setting('redirect_bp_registration_page') == 'yes') {
358
359 if (apply_filters('ppress_bp_registration_url', true)) {
360 $page = ppress_registration_url();
361 }
362 }
363
364 return $page;
365 }
366
367 /**
368 * Redirect author page to user's profile
369 */
370 public function redirect_author_page()
371 {
372 if (ppress_settings_by_key('author_slug_to_profile') == 'on' && is_author()) {
373 $id = get_query_var('author');
374 wp_redirect(ppress_get_frontend_profile_url($id));
375 exit;
376 }
377 }
378
379 public static function get_instance()
380 {
381 static $instance = false;
382
383 if ( ! $instance) {
384 $instance = new self;
385 }
386
387 return $instance;
388 }
389 }