Version Description
- Added option to redirect to any url specified.
Download this release
Release Info
Developer | Collizo4sky |
Plugin | Peter’s Login Redirect |
Version | 2.9.7 |
Comparing to | |
See all releases |
Code changes from version 2.9.6 to 2.9.7
- readme.txt +7 -35
- wplogin_redirect.php +28 -20
readme.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
=== Peter's Login Redirect ===
|
2 |
-
Contributors: properfraction,
|
3 |
Donate link: https://profilepress.net/pricing
|
4 |
Tags: login, logout, redirect, admin, administration, dashboard, users, authentication
|
5 |
Requires at least: 4.0
|
6 |
-
Requires PHP: 5.
|
7 |
-
Tested up to: 5.
|
8 |
-
Stable tag: 2.9.
|
9 |
License: GPL-2.0+
|
10 |
|
11 |
Redirect users to different locations after logging in and logging out.
|
@@ -53,22 +53,6 @@ Also see the instructions at the bottom of the settings on the "Settings > Lo
|
|
53 |
|
54 |
You can write your own code logic before any of this plugin's checks for user-specific, role-specific, and capability-specific redirects, as well as before the fallback redirect URL.
|
55 |
|
56 |
-
Available filters are:
|
57 |
-
|
58 |
-
* rul_before_user
|
59 |
-
* rul_before_role
|
60 |
-
* rul_before_capability
|
61 |
-
* rul_before_fallback
|
62 |
-
|
63 |
-
Each takes the same 4 parameters:
|
64 |
-
|
65 |
-
* $custom_redirect_to: This is set as false in case you don't have any redirect URL to set. Return this instead of false in case you have multiple filters running.
|
66 |
-
* $redirect_to: Set by WordPress, usually the admin URL.
|
67 |
-
* $requested_redirect_to: Set by WordPress, usually an override set in a GET parameter.
|
68 |
-
* $user: A PHP object representing the current user.
|
69 |
-
|
70 |
-
Your return value in your own code logic should be the URL to redirect to, or $custom_redirect_to to continue the plugin's normal checks.
|
71 |
-
|
72 |
An example of plugin code to redirect users on first login. See http://www.theblog.ca/wordpress-redirect-first-login for standalone functionality:
|
73 |
|
74 |
`// Send new users to a special page
|
@@ -148,13 +132,6 @@ An example of plugin code to redirect to a specific URL for only a specific IP r
|
|
148 |
|
149 |
add_filter( 'rul_before_user', 'redirectByIP', 10, 4 );`
|
150 |
|
151 |
-
Note that the same extensibility is available for logout redirects with these filters:
|
152 |
-
|
153 |
-
* rul_before_user_logout
|
154 |
-
* rul_before_role_logout
|
155 |
-
* rul_before_capability_logout
|
156 |
-
* rul_before_fallback_logout
|
157 |
-
|
158 |
It takes 3 parameters:
|
159 |
|
160 |
* $custom_redirect_to: This is set as false in case you don't have any redirect URL to set. Return this instead of false in case you have multiple filters running.
|
@@ -181,16 +158,11 @@ add_filter( 'rul_replace_variable', 'customRULVariableMonth', 10, 3 );`
|
|
181 |
|
182 |
Be sure to rawurlencode the returned variable if necessary.
|
183 |
|
184 |
-
= Custom "My Portal" link =
|
185 |
-
|
186 |
-
A common need is to display the "redirect" link for a user in the site navigation or sidebar.
|
187 |
-
|
188 |
-
Look at the function rul_register() in the plugin file for inspiration; it makes use of the redirect_to_front_page() function to determine the URL and then provides the relevant output code.
|
189 |
-
|
190 |
-
For a deeper dive into this feature, please [see this video](https://drive.google.com/file/d/1MWSYlzd3r_BtJan2DH8XiFv2PCanuL_J/view?usp=sharing)
|
191 |
-
|
192 |
== Changelog ==
|
193 |
|
|
|
|
|
|
|
194 |
= 2.9.6 =
|
195 |
* Added back php file url base redirect.
|
196 |
|
1 |
=== Peter's Login Redirect ===
|
2 |
+
Contributors: properfraction, collizo4sky
|
3 |
Donate link: https://profilepress.net/pricing
|
4 |
Tags: login, logout, redirect, admin, administration, dashboard, users, authentication
|
5 |
Requires at least: 4.0
|
6 |
+
Requires PHP: 5.4
|
7 |
+
Tested up to: 5.4
|
8 |
+
Stable tag: 2.9.7
|
9 |
License: GPL-2.0+
|
10 |
|
11 |
Redirect users to different locations after logging in and logging out.
|
53 |
|
54 |
You can write your own code logic before any of this plugin's checks for user-specific, role-specific, and capability-specific redirects, as well as before the fallback redirect URL.
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
An example of plugin code to redirect users on first login. See http://www.theblog.ca/wordpress-redirect-first-login for standalone functionality:
|
57 |
|
58 |
`// Send new users to a special page
|
132 |
|
133 |
add_filter( 'rul_before_user', 'redirectByIP', 10, 4 );`
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
It takes 3 parameters:
|
136 |
|
137 |
* $custom_redirect_to: This is set as false in case you don't have any redirect URL to set. Return this instead of false in case you have multiple filters running.
|
158 |
|
159 |
Be sure to rawurlencode the returned variable if necessary.
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
== Changelog ==
|
162 |
|
163 |
+
= 2.9.7 =
|
164 |
+
* Added option to redirect to any url specified.
|
165 |
+
|
166 |
= 2.9.6 =
|
167 |
* Added back php file url base redirect.
|
168 |
|
wplogin_redirect.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.theblog.ca/wplogin-redirect
|
|
5 |
Description: Redirect users to different locations after logging in. Define a set of rules for specific users, user with specific roles, users with specific capabilities, and a blanket rule for all other users. This is all managed in Settings > Login/logout redirects.
|
6 |
Author: Peter Keung
|
7 |
Author URI: http://www.theblog.ca
|
8 |
-
Version: 2.9.
|
9 |
Text Domain: peters-login-redirect
|
10 |
Domain Path: /languages/
|
11 |
*/
|
@@ -23,7 +23,7 @@ global $rul_db_addresses;
|
|
23 |
global $rul_version;
|
24 |
// Name of the database table that will hold group information and moderator rules
|
25 |
$rul_db_addresses = $wpdb->prefix . 'login_redirects';
|
26 |
-
$rul_version = '2.9.
|
27 |
|
28 |
// doing this so we can pass current user logging out since it is no longer active after logout
|
29 |
if ( ! function_exists('wp_logout')) :
|
@@ -178,9 +178,9 @@ class rulRedirectFunctionCollection
|
|
178 |
return $variable_value;
|
179 |
}
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
static function rul_replace_variable($string, $user)
|
185 |
{
|
186 |
preg_match_all("/\[variable\](.*?)\[\/variable\]/is", $string, $out);
|
@@ -194,6 +194,17 @@ class rulRedirectFunctionCollection
|
|
194 |
|
195 |
return $string;
|
196 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
}
|
198 |
|
199 |
// Functions specific to logout redirecting
|
@@ -225,6 +236,7 @@ class rulLogoutFunctionCollection
|
|
225 |
$rul_url = rulLogoutFunctionCollection::get_redirect_url($current_user, $requested_redirect_to);
|
226 |
|
227 |
if ($rul_url) {
|
|
|
228 |
$redirect_to = $rul_url;
|
229 |
}
|
230 |
}
|
@@ -325,6 +337,7 @@ class rulRedirectPostRegistration
|
|
325 |
|
326 |
$rul_url = rulRedirectPostRegistration::get_redirect_url($requested_redirect_to);
|
327 |
if ($rul_url) {
|
|
|
328 |
return $rul_url;
|
329 |
}
|
330 |
|
@@ -352,19 +365,17 @@ class rulRedirectPostRegistration
|
|
352 |
}
|
353 |
}
|
354 |
|
355 |
-
// This function wraps around the main redirect function to determine whether or not to bypass the WordPress local URL limitation
|
356 |
function peters_redirect_wrapper($redirect_to, $requested_redirect_to, $user)
|
357 |
{
|
358 |
$rul_allow_post_redirect_override = rulRedirectFunctionCollection::get_settings('rul_allow_post_redirect_override');
|
359 |
|
360 |
-
|
361 |
-
if ( ! isset($user->user_login)) {
|
362 |
-
return $redirect_to;
|
363 |
-
}
|
364 |
|
365 |
if ((admin_url() == $redirect_to && $rul_allow_post_redirect_override) || ! $rul_allow_post_redirect_override) {
|
366 |
$rul_url = redirect_to_front_page($redirect_to, $requested_redirect_to, $user);
|
367 |
if ($rul_url) {
|
|
|
|
|
368 |
return $rul_url;
|
369 |
}
|
370 |
}
|
@@ -372,8 +383,6 @@ function peters_redirect_wrapper($redirect_to, $requested_redirect_to, $user)
|
|
372 |
return $redirect_to;
|
373 |
}
|
374 |
|
375 |
-
// This function sets the URL to redirect to
|
376 |
-
|
377 |
function redirect_to_front_page($redirect_to, $requested_redirect_to, $user)
|
378 |
{
|
379 |
global $wpdb, $rul_db_addresses;
|
@@ -468,7 +477,6 @@ function redirect_to_front_page($redirect_to, $requested_redirect_to, $user)
|
|
468 |
// If no user is logged in, it returns the "Register" link
|
469 |
// You can specify tags to go around the returned link (or wrap it with no tags); by default this is a list item
|
470 |
// You can also specify whether to print out the link or just return it
|
471 |
-
|
472 |
function rul_register($before = '<li>', $after = '</li>', $give_echo = true)
|
473 |
{
|
474 |
global $current_user;
|
@@ -667,13 +675,13 @@ if (is_admin()) {
|
|
667 |
|
668 |
$rul_update_rule = $wpdb->insert($rul_db_addresses,
|
669 |
array(
|
670 |
-
'rul_url'
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
)
|
676 |
-
|
677 |
);
|
678 |
|
679 |
if ( ! $rul_update_rule) {
|
5 |
Description: Redirect users to different locations after logging in. Define a set of rules for specific users, user with specific roles, users with specific capabilities, and a blanket rule for all other users. This is all managed in Settings > Login/logout redirects.
|
6 |
Author: Peter Keung
|
7 |
Author URI: http://www.theblog.ca
|
8 |
+
Version: 2.9.7
|
9 |
Text Domain: peters-login-redirect
|
10 |
Domain Path: /languages/
|
11 |
*/
|
23 |
global $rul_version;
|
24 |
// Name of the database table that will hold group information and moderator rules
|
25 |
$rul_db_addresses = $wpdb->prefix . 'login_redirects';
|
26 |
+
$rul_version = '2.9.7';
|
27 |
|
28 |
// doing this so we can pass current user logging out since it is no longer active after logout
|
29 |
if ( ! function_exists('wp_logout')) :
|
178 |
return $variable_value;
|
179 |
}
|
180 |
|
181 |
+
/**
|
182 |
+
* Replaces the syntax [variable]variable_name[/variable] with whatever has been mapped to the variable_name in the rul_get_variable function
|
183 |
+
*/
|
184 |
static function rul_replace_variable($string, $user)
|
185 |
{
|
186 |
preg_match_all("/\[variable\](.*?)\[\/variable\]/is", $string, $out);
|
194 |
|
195 |
return $string;
|
196 |
}
|
197 |
+
|
198 |
+
static function rul_trigger_allowed_host($url)
|
199 |
+
{
|
200 |
+
$url_parsed = parse_url($url);
|
201 |
+
if (isset($url_parsed['host'])) {
|
202 |
+
$rul_allowed_hosts[] = $url_parsed['host'];
|
203 |
+
add_filter('allowed_redirect_hosts', function ($hosts) use ($rul_allowed_hosts) {
|
204 |
+
return array_merge($hosts, $rul_allowed_hosts);
|
205 |
+
});
|
206 |
+
}
|
207 |
+
}
|
208 |
}
|
209 |
|
210 |
// Functions specific to logout redirecting
|
236 |
$rul_url = rulLogoutFunctionCollection::get_redirect_url($current_user, $requested_redirect_to);
|
237 |
|
238 |
if ($rul_url) {
|
239 |
+
rulRedirectFunctionCollection::rul_trigger_allowed_host($rul_url);
|
240 |
$redirect_to = $rul_url;
|
241 |
}
|
242 |
}
|
337 |
|
338 |
$rul_url = rulRedirectPostRegistration::get_redirect_url($requested_redirect_to);
|
339 |
if ($rul_url) {
|
340 |
+
rulRedirectFunctionCollection::rul_trigger_allowed_host($rul_url);
|
341 |
return $rul_url;
|
342 |
}
|
343 |
|
365 |
}
|
366 |
}
|
367 |
|
|
|
368 |
function peters_redirect_wrapper($redirect_to, $requested_redirect_to, $user)
|
369 |
{
|
370 |
$rul_allow_post_redirect_override = rulRedirectFunctionCollection::get_settings('rul_allow_post_redirect_override');
|
371 |
|
372 |
+
if ( ! isset($user->user_login)) return $redirect_to;
|
|
|
|
|
|
|
373 |
|
374 |
if ((admin_url() == $redirect_to && $rul_allow_post_redirect_override) || ! $rul_allow_post_redirect_override) {
|
375 |
$rul_url = redirect_to_front_page($redirect_to, $requested_redirect_to, $user);
|
376 |
if ($rul_url) {
|
377 |
+
rulRedirectFunctionCollection::rul_trigger_allowed_host($rul_url);
|
378 |
+
|
379 |
return $rul_url;
|
380 |
}
|
381 |
}
|
383 |
return $redirect_to;
|
384 |
}
|
385 |
|
|
|
|
|
386 |
function redirect_to_front_page($redirect_to, $requested_redirect_to, $user)
|
387 |
{
|
388 |
global $wpdb, $rul_db_addresses;
|
477 |
// If no user is logged in, it returns the "Register" link
|
478 |
// You can specify tags to go around the returned link (or wrap it with no tags); by default this is a list item
|
479 |
// You can also specify whether to print out the link or just return it
|
|
|
480 |
function rul_register($before = '<li>', $after = '</li>', $give_echo = true)
|
481 |
{
|
482 |
global $current_user;
|
675 |
|
676 |
$rul_update_rule = $wpdb->insert($rul_db_addresses,
|
677 |
array(
|
678 |
+
'rul_url' => $address,
|
679 |
+
'rul_url_logout' => $address_logout,
|
680 |
+
'rul_type' => $type,
|
681 |
+
'rul_value' => $typeValue,
|
682 |
+
'rul_order' => $order
|
683 |
+
),
|
684 |
+
array('%s', '%s', '%s', '%s', '%d')
|
685 |
);
|
686 |
|
687 |
if ( ! $rul_update_rule) {
|