latest stable versions: v130513 (changelog)

s2Member® Forums

The Customers Forum is only for paying customers.
~ We also have a free/open Community Forum.

Troubleshooting Tips

Customer support for products by s2Member® is available only through your account at s2Member.com, which grants you access to our Customers Forum. We also have public Community Forum available to all site owners (no purchase required). For further details, please read our Support Policy, which includes a list of things that we will support, and also some things that we will NOT support. Please read this before posting.

We ask that you submit all pre-sale and/or technical support questions through the appropriate support forum at s2Member.com. If you are a paid customer, an s2Member® support representative will gladly address your question/concern within 24-48 hours; excluding all major holidays. Thank you!

For troubleshooting assistance, please read this article.

How to remove s2member login redirect hook?

Home Forums Pre-Sale Questions How to remove s2member login redirect hook?

This topic contains 6 replies, has 4 voices.
Last updated by  Viruthagiri Thirumavalavan 1 year, 1 month ago.

Topic Author Topic
Posted: Sunday Mar 25th, 2012 @ 4:40 pm #9060
Viruthagiri Thirumavalavan
Registered User (Free)
Registered User (Free)

I would like to redirect my users to change password page on first time login using wordpress generated credentials.

My redirect function code looks like this

wp_redirect(apply_filters('login_redirect', get_bloginfo('url') . '/my-account/','', $user));

But its not working since the login_redirect hook already used by s2member. Can anyone tell me how to remove existing s2member login redirect?

Thanks

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Tuesday Mar 27th, 2012 @ 10:20 am #9228
Jason (Lead Developer)
Official s2Member® Support Rep
Support Rep
HelpfulExperiencedCertified

Hi there. Thanks for your inquiry.

First, let me start by saying that s2Member Pro makes this much easier to accomplish, because it integrates One-Time-Offers upon login, where something like this could be easily configured from the Dashboard.

However, to answer your question. This is how you would accomplish this via Hooks/Filters.

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )

<?php
add_filter("ws_plugin__s2member_login_redirect", "my_custom_login_redirect", 10, 2);
function my_custom_login_redirect($redirect, $vars = array())
	{
		// If you want s2Member to perform the redirect, return true.
		// return true;
		
		// Or, if you do NOT want s2Member to perform the redirect, return false.
		// return false;
		
		// Or, if you want s2Member to redirect, but to a custom URL, return that URL.
		// return 'http://www.example.com/reset-password-please/';
		
		// Or, just return what s2Member already says about the matter.
		return $redirect;
	}
?>
Posted: Tuesday Mar 27th, 2012 @ 11:24 am #9234
Viruthagiri Thirumavalavan
Registered User (Free)
Registered User (Free)

Hello Jason,
Thank you very much.

But i still don’t understand. this is the code i’m using. Please correct me if i’m wrong.

This is my s2-hacks.php code

add_filter("ws_plugin__s2member_login_redirect", "redirect_password_login_redirect", 10, 2);
function redirect_password_login_redirect($redirect, $vars = array('user' => null)) {

    if( isset($user->ID) ) {
        $changed_password = get_metadata("user", $user->ID, "changed_password",true);
        if( $changed_password != true ) {
            return get_bloginfo('url') . "/change-password/";
        } else {
            return $redirect;
        }
    }
}

In functions.php i have function like this

// Log In User
function log_in_user($username, $password) {
	
	// Get the user based on the username from the POST
	$user = parse_user($username);

	// Remove html tags from the title and content fields
	$username_stripped = strip_tags($username);
	$password_stripped = strip_tags($password);
	
	// Validate the Form Data
	if(isEmptyString($username_stripped)) return new WP_Error('forgot_username', 'You forgot to enter your Username');
	if(isEmptyString($password_stripped)) return new WP_Error('incorrect_password', "You forgot to enter your Password.");
	if(!wp_check_password( $password_stripped, $user->user_pass ) ) return new WP_Error('incorrect_password', "You seem to have entered a wrong password.");
	
	wp_set_auth_cookie($user->ID, $remember);
	wp_login($username_stripped, $password_stripped);
	wp_redirect(apply_filters('ws_plugin__s2member_login_redirect', get_bloginfo('url') . '/my-account/', $user));
    exit;
	
}

Its supposed to redirect me to change-password page. Instead it still redirect me to my-account page.

Am i applying filter incorrectly? Thanks

Posted: Tuesday Mar 27th, 2012 @ 2:52 pm #9264
Raam (Support Rep)
Official s2Member® Support Rep
Support Rep
HelpfulExperiencedCertified

Hello Viruthagiri,

Unfortunately this kind of assistance is outside the scope of our support policy (see s2Member® » Support Policy » Outside Scope). You may want to post a thread on the WordPress Support Forum.

Posted: Tuesday Mar 27th, 2012 @ 6:57 pm #9304
Viruthagiri Thirumavalavan
Registered User (Free)
Registered User (Free)

Hello Raam, I tried other support forums. I couldn’t get support in stackoverflow, wordpress stackexchange. Thats why i opened this thread. I finished the whole site. The only problem i have is login redirection problem.When i disable s2member redirection working correctly. Last two days i’m browsing all s2member file to find and remove the hook. And to be honest its really frustrating to spend more than 48 hours for one line code.

All i’m just asking you guys, just to tell me how to remove your s2member redirect hook and make login_redirect hook work.

Here is my simple code

function log_in_user($username, $password) {
	$user = parse_user($username);
    ...................
    ...................
    wp_redirect(apply_filters('login_redirect', get_bloginfo('url') . '/my-account/','',$user)));
    exit;	
}
function redirect_passwort_login_redirect($redirect_to, $url_redirect_to = '', $user = null) {
    ...................
    ...................
}
add_filter('login_redirect', 'redirect_passwort_login_redirect',10,3);

I also modified the Jason’s code as per my needs. The only thing i have problem is in this line.

wp_redirect(apply_filters('login_redirect', get_bloginfo('url') . '/my-account/','',$user)));

Can you tell me what is the filter name i should apply in wp_redirect. ?
Ps: I really love s2member plugin. I’m not asking any custom coding here. I’m just asking the filter name.
Thanks

Posted: Wednesday Mar 28th, 2012 @ 3:29 am #9331
Cristián
Official s2Member® Support Rep
Support Rep
HelpfulExperiencedCertified

You could add a conditional to the Welcome page or a must-use plugin, check the login counter and based on that redirect the person to the profile page.
Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants -> S2MEMBER_CURRENT_USER_LOGIN_COUNTER

Posted: Wednesday Mar 28th, 2012 @ 3:31 pm #9361
Viruthagiri Thirumavalavan
Registered User (Free)
Registered User (Free)

Thanks Cristián,

I’ll go with your method

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

The topic ‘How to remove s2member login redirect hook?’ is closed to new replies.

If you're a paying customer, please use our Customers Forum. We also have a public Community Forum available to all site owners (no purchase required). You can register here (it's free). For further details, please read through our Support Policy.