latest stable versions: v140409 (changelog)

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

How to remove s2member login redirect hook?

Home Forums Community Forum How to remove s2member login redirect hook?

This topic contains 6 replies, has 4 voices.
Last updated by  Viruthagiri Thirumavalavan 2 years ago.

Topic Author Topic
Posted: Sunday Mar 25th, 2012 at 4:40 pm #9060

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 at 10:20 am #9228
Staff Member

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 at 11:24 am #9234

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 at 2:52 pm #9264
Raam Dev
Username: Raam
Staff Member

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 at 6:57 pm #9304

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 at 3:29 am #9331
Staff Member

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 at 3:31 pm #9361

Thanks Cristián,

I’ll go with your method

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 WordPress.org. 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.