Skip to content

Commit

Permalink
Merge pull request #282 from websharks/feature/119
Browse files Browse the repository at this point in the history
`redirect_to_automatic`: #119
  • Loading branch information
JasWSInc committed Aug 7, 2014
2 parents d86261f + 69f8d2c commit 7afba41
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions s2member/includes/classes/#-redirects.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function login_redirect($username = '', $user = NULL)
{
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
do_action('ws_plugin__s2member_before_login_redirect', get_defined_vars());
unset($__refs, $__v);
unset($__refs, $__v); // Housekeeping.

if(is_string($username) && $username && is_object($user) && !empty($user->ID) && ($user_id = $user->ID))
{
Expand Down Expand Up @@ -77,13 +77,20 @@ public static function login_redirect($username = '', $user = NULL)
}
if(($redirect = apply_filters('ws_plugin__s2member_login_redirect', (($user->has_cap('edit_posts')) ? FALSE : TRUE), get_defined_vars())))
{
$obey_redirect_to = apply_filters('ws_plugin__s2member_obey_login_redirect_to', TRUE, get_defined_vars()); // By default, we obey this.
$obey_redirect_to = apply_filters('ws_plugin__s2member_obey_login_redirect_to', TRUE, get_defined_vars());

if(!$obey_redirect_to || empty($_REQUEST['redirect_to']) || !is_string($_REQUEST['redirect_to']) || $_REQUEST['redirect_to'] === admin_url() || preg_match('/^\/?wp-admin\/?$/', $_REQUEST['redirect_to']))
if($obey_redirect_to && (empty($_REQUEST['redirect_to']) || !is_string($_REQUEST['redirect_to']) || $_REQUEST['redirect_to'] === admin_url() || preg_match('/^\/?wp-admin\/?$/', $_REQUEST['redirect_to'])))
$obey_redirect_to = FALSE; // Do not obey default redirect_to locations; like those inside the default admin area.

else if($obey_redirect_to && !empty($_REQUEST['redirect_to_automatic']) && is_string($redirect))
$obey_redirect_to = FALSE; // Do not obey automatic redirects when a custom redirection filter applies.
// ↑ NOTE: this will apply to s2Member Pro's One-Time-Offers (Upon Login) also.

if(!$obey_redirect_to) // Only if we are NOT obeying the `redirect_to` variable.
{
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
do_action('ws_plugin__s2member_during_login_redirect', get_defined_vars());
unset($__refs, $__v);
unset($__refs, $__v); // Housekeeping.

if($redirect && is_string($redirect)) $redirect = $redirect;

Expand Down Expand Up @@ -112,7 +119,7 @@ public static function login_redirect($username = '', $user = NULL)
}
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
do_action('ws_plugin__s2member_after_login_redirect', get_defined_vars());
unset($__refs, $__v);
unset($__refs, $__v); // Housekeeping.
}

/**
Expand All @@ -130,7 +137,7 @@ public static function login_redirection_url($user = NULL, $root_returns_false =
{
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
do_action('ws_plugin__s2member_before_login_redirection_url', get_defined_vars());
unset($__refs, $__v);
unset($__refs, $__v); // Housekeeping.

$url = $GLOBALS['WS_PLUGIN__']['s2member']['o']['login_redirection_override'];
$url = c_ws_plugin__s2member_login_redirects::fill_login_redirect_rc_vars($url, $user, $root_returns_false);
Expand All @@ -153,7 +160,7 @@ public static function login_redirection_uri($user = NULL, $root_returns_false =
{
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
do_action('ws_plugin__s2member_before_login_redirection_uri', get_defined_vars());
unset($__refs, $__v);
unset($__refs, $__v); // Housekeeping.

if(($url = c_ws_plugin__s2member_login_redirects::login_redirection_url($user, $root_returns_false)))
$uri = c_ws_plugin__s2member_utils_urls::parse_uri($url);
Expand All @@ -177,7 +184,7 @@ public static function fill_login_redirect_rc_vars($url = '', $user = NULL, $roo
{
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
do_action('ws_plugin__s2member_before_fill_login_redirect_rc_vars', get_defined_vars());
unset($__refs, $__v);
unset($__refs, $__v); // Housekeeping.

$url = (string)$url; // Force ``$url`` to a string value.
$orig_url = $url; // Record the original URL that was passed in.
Expand Down

0 comments on commit 7afba41

Please # to comment.