latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Redirect problem

Home Forums Community Forum Redirect problem

This topic contains 6 replies, has 3 voices. Last updated by  Cristián Lávaque 4 years, 2 months ago.

Topic Author Topic
Posted: Sunday Oct 7th, 2012 at 9:48 am #27711

Got a strange problem. The url field in s2m backend cant use %%, need to keep this dynamic, so I got a function from this forum, with some problem :

1) The $username variable is stripped out in my custom function in browser. Below only returns: OR

But the string echoed (when testing) in the function works.

function ua_redirect_after_login($url){
$username = get_user_field(“user_login”);
if($la == “en”) $la = “”;
else $la = $la.”/”;
$url = $GLOBALS[‘INSTALL’].”/”.$la.”members/”.$username.”/”;
return $url;
add_filter( “ws_plugin__s2member_login_redirection_url” ,”ua_redirect_after_login”, 1 );

Do I maybe need to remove another filter first or ?

2) This function also ALWAYS parses 3 times, everywhere I go on the page. Is that normal?

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Monday Oct 8th, 2012 at 10:55 am #27800


Posted: Tuesday Oct 9th, 2012 at 3:32 am #27855
Raam Dev
Username: Raam
Staff Member

I tested your code and the problem is that the username is not available where you’re calling it (when you echo the $url you’re just seeing a cached version of the username… try clearing your browser cache and testing it again, you’ll see that it’s actually blank just like the redirect).

I’m not entirely clear what you’re trying to achieve here. Are you trying to create a custom Login Welcome Page URL for each user and redirect them to that URL when they login?

Posted: Tuesday Oct 9th, 2012 at 6:57 am #27880

Hi and thanks for a reply.

the login redirect welcome page is – in s2member backend – set to optional fileld and we used :

domain/members/profile/%%USERNAME and so on

Works fine.

But if a user changes a language before login, the user get redirected to the english version (default) profile home.

We shold need like domain/%%LANG%%/members/profile/%%USERNAME

But that not supportet by s2m.

So I nned a filter to squeeze this lang select in the url redirect.

So who´s caching this variable anyway? (s2m?) when the

get_user_field(“user_login”); is not set, but who calls the %%USERNAME%% ?
Can I use that or DELAY this filter OR $_GET the posted (succeded) username or?

Any suggestions here would be nice. I mean SOME FUNCTION is using login redirect welcome page – that works – and I just need to add / replace str_replace() call in that filter/ hook/ function.

Thanks anyaway for a asome plugin

Posted: Tuesday Oct 9th, 2012 at 7:48 am #27888

Jonas, another thing you could try with the hack, is to add parsing for your own language replacement code.

Try the [hilite mono]ws_plugin__s2member_fill_login_redirect_rc_vars[/hilite] hook to str_replace [hilite mono]%%language%%[/hilite] in your hack. s2member\includes\classes\

I hope it helps. :)

Posted: Wednesday Oct 10th, 2012 at 10:49 am #27991

Ok. Well it didnt work, but help me out to another solution (see end of this post). When placing

$m = $user_login;
if($la == “en”) $la = “”;
else $la = $la.”/”;
$url = $GLOBALS[‘INSTALL’].”/”.$la.”members/”.$m.”/”;

directly in core : ws_plugin__s2member_fill_login_redirect_rc_vars

It works. BUT in the hook, the member login name isnt there. I tried all theese solutions :

function ua_redirect_after_login($url){
$m = get_user_field(“user_login”); // nope
$id = bp_get_member_user_id(); // nope
$m = get_user_field(“user_login”, $id); // nope
$username = (!$username && is_object ($user = wp_get_current_user ()) && !empty ($user->user_login)) ? strtolower ($user->user_login) : strtolower ($username);

$user = ((is_object ($user) || is_object ($user = (is_user_logged_in ()) ? wp_get_current_user () : false)) && !empty ($user->ID)) ? $user : false;
$user_id = ($user) ? (string)$user->ID : “”;
$user_login = ($user) ? (string)strtolower ($user->user_login) : “”;

$m = $user_login; // or every try above
if($la == “en”) $la = “”;
else $la = $la.”/”;
$url = $GLOBALS[‘INSTALL’].”/”.$la.”members/”.$m.”/”;
return $url;

// tried both :
add_filter( “ws_plugin__s2member_login_redirection_url” ,”ua_redirect_after_login”, 1 );
//add_filter (“ws_plugin__s2member_fill_login_redirect_rc_vars”, “ua_redirect_after_login”, 1);


I don wanna manipulate in the core files so:

s2member => Login Welcome Page : “Or, you may configure a Special Redirection URL, if you prefer. You’ll need to type in the full URL, starting with: http://. A few Replacement Codes are also supported here. ” I SET :


Then in functions.php

function ua_redirect_after_login($url){
if($la == “en”) $la = “”;
else $la = ‘/’.$la;
$r = $GLOBALS[‘INSTALL’].$la;
$url = str_replace(‘_Q_’, $r, $url);
return $url;
add_filter( “ws_plugin__s2member_login_redirection_url” ,”ua_redirect_after_login”, 1 );

I Hate to not know why, so if someone can see why my solutions in the first place don work, please reply or comment. Otherwise this thread is closed from my part.


Posted: Friday Oct 12th, 2012 at 7:08 am #28209

You can look for other hooks in the file, if you want, to see if you find one that works for your hack. If the username is not available in any of them, the [hilite mono]%%current_user_login%%[/hilite] replacement code may be of help.

Ok. Well it didnt work

I think that adding a [hilite mono]%%language%%[/hilite] replacement code may be a good solution. Could you show me the code you tried for the hack, please?

Viewing 6 replies - 1 through 6 (of 6 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.