PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.1
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
AdminNotices.php 5 years ago AjaxHandler.php 5 years ago Autologin.php 5 years ago BuddyPressBbPress.php 5 years ago EditUserProfile.php 5 years ago ExtensionManager.php 5 years ago FileUploader.php 5 years ago FormPreviewHandler.php 5 years ago FormRepository.php 5 years ago FormShortcodeDefaults.php 5 years ago GDPR.php 5 years ago GlobalSiteAccess.php 5 years ago ImageUploader.php 5 years ago LoginAuth.php 5 years ago Miscellaneous.php 5 years ago ModifyRedirectDefaultLinks.php 5 years ago PPRESS_Session.php 5 years ago PROFILEPRESS_sql.php 5 years ago PasswordReset.php 5 years ago ProfileUrlRewrite.php 5 years ago RegistrationAuth.php 5 years ago SendEmail.php 5 years ago ShortcodeThemeFactory.php 5 years ago UserAvatar.php 5 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
339 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 /**
40 * Modify the lost password url returned by wp_lostpassword_url() function.
41 *
42 * @param $val
43 *
44 * @return string
45 */
46 public function lost_password_url_func($val)
47 {
48 $page_id = ppress_get_setting('set_lost_password_url');
49
50 if ( ! empty($page_id)) {
51 $val = get_permalink($page_id);
52 }
53
54 return apply_filters('ppress_password_reset_url', $val);
55 }
56
57 /**
58 * Force redirection of default password reset to the page with custom one.
59 */
60 public function redirect_password_reset_page()
61 {
62 if ( ! apply_filters('ppress_default_password_reset_redirect_enabled', true)) return;
63
64 $page_id = ppress_get_setting('set_lost_password_url');
65
66 if (empty($page_id)) return;
67
68 $password_reset_url = get_permalink(absint($page_id));
69
70 wp_safe_redirect($password_reset_url);
71 exit;
72 }
73
74 /**
75 * Modify the login url returned by wp_login_url()
76 *
77 * @param $url
78 * @param string $redirect
79 * @param bool $force_reauth
80 *
81 * @return string page with login shortcode
82 */
83 public function set_login_url_func($url, $redirect = '', $force_reauth = false)
84 {
85 $login_page_id = ppress_get_setting('set_login_url');
86
87 if ( ! empty($login_page_id)) {
88
89 $url = get_permalink($login_page_id);
90
91 if ( ! empty($redirect)) {
92 $url = add_query_arg('redirect_to', rawurlencode($redirect), $url);
93 }
94
95 if ($force_reauth) {
96 $url = add_query_arg('reauth', '1', $url);
97 }
98 }
99
100 return apply_filters('ppress_login_url', $url, $redirect, $force_reauth);
101 }
102
103
104 /**
105 * Force redirect default login to page with login shortcode
106 */
107 function redirect_login_page()
108 {
109 if ( ! apply_filters('ppress_default_login_redirect_enabled', true)) return;
110
111 if (empty(ppress_get_setting('set_login_url'))) return;
112
113 $login_url = ppress_login_url();
114
115 // retrieve the query string if available.
116 $query_string = ! empty($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"] : parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
117
118 // if query string is available, append to login url.
119 if ( ! empty($query_string)) {
120 if (strpos($login_url, '?') !== false) {
121 $login_url .= "&$query_string";
122 } else {
123 $login_url .= "?$query_string";
124 }
125 }
126
127 wp_safe_redirect($login_url);
128 exit;
129 }
130
131 /**
132 * Modify the url returned by wp_registration_url().
133 *
134 * @return string page url with registration shortcode.
135 */
136 function register_url_func($val)
137 {
138 $page_id = ppress_get_setting('set_registration_url');
139
140 if ( ! empty($page_id)) {
141 $val = get_permalink($page_id);
142 }
143
144 return apply_filters('ppress_registration_url', $val);
145 }
146
147 /**
148 * force redirection of default registration to custom one
149 */
150 function redirect_reg_page()
151 {
152 if ( ! apply_filters('ppress_default_registration_redirect_enabled', true)) return;
153
154 if (empty(ppress_get_setting('set_registration_url'))) return;
155
156 $reg_url = ppress_registration_url();
157
158 wp_safe_redirect($reg_url);
159 exit;
160 }
161
162 /**
163 * Add query string (url) to logout url which is url to redirect to after logout
164 *
165 * @param $logout_url string filter default login url to be modified
166 * @param $redirect string where to redirect to after logout
167 *
168 * @return string
169 */
170 public function logout_url_func($logout_url, $redirect)
171 {
172 $set_redirect = false;
173
174 $custom_logout_page_url = ppress_get_setting('custom_url_log_out');
175 $logout_page_id = ppress_get_setting('set_log_out_url');
176
177 if ( ! empty($custom_logout_page_url)) {
178 $set_redirect = $custom_logout_page_url;
179 } elseif ( ! empty($logout_page_id)) {
180
181 if ($logout_page_id != 'default') {
182
183 $db_logout_url = get_permalink(absint($logout_page_id));
184
185 $set_redirect = $db_logout_url;
186
187 if (empty($db_logout_url) || $logout_page_id == 'current_view_page') {
188 // make redirect currently viewed page
189 $set_redirect = get_permalink();
190 }
191 }
192 }
193
194 if ($set_redirect) {
195 $set_redirect = apply_filters('ppress_logout_redirect', esc_url_raw($set_redirect));
196 $logout_url = add_query_arg('redirect_to', urlencode($set_redirect), $logout_url);
197 }
198
199 return $logout_url;
200 }
201
202 /**
203 * Redirect user edit profile (/wp-admin/profile.php) to "custom edit profile" page.
204 */
205 function redirect_default_edit_profile_to_custom()
206 {
207 if (ppress_settings_by_key('redirect_default_edit_profile_to_custom') == 'yes') {
208
209 add_filter('edit_profile_url', function ($url) {
210 $page_id = ppress_settings_by_key('edit_user_profile_url');
211
212 if ( ! empty($page_id)) {
213 $url = get_permalink($page_id);
214 }
215
216 return $url;
217 }, 9999999999);
218
219 // Filter to disable edit profile redirect for administrator.
220 $disable = apply_filters('ppress_disable_admin_edit_profile_redirect', false);
221 if ($disable && current_user_can('delete_users')) return;
222
223 if ( ! empty(ppress_get_setting('edit_user_profile_url'))) {
224 $edit_user_profile_url = ppress_edit_profile_url();
225
226 $page_viewed = esc_url($_SERVER['REQUEST_URI']);
227
228 if (isset($page_viewed) && strpos($page_viewed, 'wp-admin/profile.php') !== false) {
229 wp_safe_redirect($edit_user_profile_url);
230 exit;
231 }
232 }
233 }
234 }
235
236 public function author_link_func($url, $author_id)
237 {
238 if (ppress_settings_by_key('author_slug_to_profile') == 'on') {
239 $url = ppress_get_frontend_profile_url($author_id);
240 }
241
242 return $url;
243 }
244
245 /**
246 * @param $url
247 * @param int $id comment ID
248 * @param \WP_Comment $comment
249 *
250 * @return string|void
251 */
252 public function comment_author_url_to_profile($url, $id, $comment)
253 {
254 if (ppress_settings_by_key('comment_author_url_to_profile') == 'on') {
255 if (is_object($comment) && isset($comment->comment_author_email)) {
256 $email = $comment->comment_author_email;
257 $user = get_user_by('email', $email);
258 if (isset($user->user_login)) {
259 $url = ppress_get_frontend_profile_url($user->user_login);
260 }
261 }
262 }
263
264 return $url;
265 }
266
267 /**
268 * Redirect the default logout page (/wp-login.php?loggedout=true) to blog homepage
269 */
270 public function redirect_logout_page()
271 {
272 $page_viewed = basename(esc_url($_SERVER['REQUEST_URI']));
273
274 if ($page_viewed == "wp-login.php?loggedout=true" && $_SERVER['REQUEST_METHOD'] == 'GET') {
275 wp_safe_redirect(home_url());
276 exit;
277 }
278 }
279
280 public function redirect_bp_registration_page()
281 {
282 if ( ! class_exists('BuddyPress') && ! function_exists('bp_has_custom_signup_page')) {
283 return;
284 }
285
286 if ( ! bp_has_custom_signup_page()) return;
287
288 if (ppress_get_setting('redirect_bp_registration_page') == 'yes') {
289 // ! bp_has_custom_signup_page()
290 $page = bp_get_root_domain() . '/' . bp_get_signup_slug();
291
292 if ($page == ppress_get_current_url()) {
293 wp_safe_redirect(ppress_registration_url());
294 exit;
295 }
296 }
297 }
298
299 /**
300 * Rewrite buddypress registration url to PP custom url or WP's if not set.
301 *
302 * @param string $page
303 *
304 * @return string
305 */
306 public function rewrite_bp_registration_url($page)
307 {
308 if (ppress_get_setting('redirect_bp_registration_page') == 'yes') {
309 if (apply_filters('ppress_bp_registration_url', true)) {
310 $page = ppress_registration_url();
311 }
312 }
313
314 return $page;
315 }
316
317 /**
318 * Redirect author page to user's profile
319 */
320 public function redirect_author_page()
321 {
322 if (ppress_settings_by_key('author_slug_to_profile') == 'on' && is_author()) {
323 $id = get_query_var('author');
324 wp_redirect(ppress_get_frontend_profile_url($id));
325 exit;
326 }
327 }
328
329 public static function get_instance()
330 {
331 static $instance = false;
332
333 if ( ! $instance) {
334 $instance = new self;
335 }
336
337 return $instance;
338 }
339 }