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.

Logout Redirect?

Home Forums Community Forum Logout Redirect?

This topic contains 11 replies, has 5 voices. Last updated by  GaperVille 4 years, 9 months ago.

Topic Author Topic
Posted: Sunday Mar 11th, 2012 at 1:44 pm #7860

I know there are settings to offer a Welcome page and a Sign-up page when someone tries to access content they are not allowed to access but is there a way to redirect the user to another page, one of my choosing, when a Member logs out, such as a Goodbye page?

thanks

List Of Topic Replies

Viewing 11 replies - 1 through 11 (of 11 total)
Author Replies
Author Replies
Posted: Tuesday Mar 13th, 2012 at 8:38 pm #8068
David Welch
Username: dwbiz05

To my knowledge, this is not a built in function of s2member. However, wordpress itself has a function that is supposed to do this:

http://codex.wordpress.org/Function_Reference/wp_logout_url

Basically, if your wp_logout_url() has a valid link, the user should be re-direced to that page when they logout.

<a href="<?php echo wp_logout_url('http://yoursite.com/goodbyepage'); ?>" title="Logout">Logout</a>

Hope that helps,

Dave

Posted: Tuesday Mar 27th, 2012 at 3:43 pm #9277
VJ Ante
Username: vjante

Whew good to see this logout redirect. I’m very to wordpress & s2members. I have seen this suggested function but don’t know how to use it. I do have a test page i’m developing that I want the logout redirector. We want the user who logout to go to the home page instead of the login page. Could you please tell me where to append the above function.

Below is what I have on my page:
[s2If is_user_logged_in()]
LOGGED-IN
Content for anyone that is logged in, regardless of their Membership Level.
[/s2If]

[s2If !is_user_logged_in()]
NOT LOGGED IN
Some public content. They’re NOT logged in.
A leading !exclamation means false.
http://localhost:40628/wp-login.php;

window.location = ‘http://localhost:40628/wp-login.php?redirect_to=http://localhost:40628/?page_id=436&#8217;;
<a href="” title=”Logout”>Logout
[/s2If]

Any is greatly appreciated. H E L P!

Posted: Thursday Apr 12th, 2012 at 12:48 pm #10673

Hi
I am trying to control the logout behavior also.

I have a line in functions.php that adds logout the the membership menu.

No matter what I do, the system redirects to the membership options page on logout.

This URL query string seems to append to the home page link despite anything I do.

http://example.com/membership-options-2?_s2member_seeking[type]=page&_s2member_seeking[page]=821&_s2member_seeking[_uri]=L2ZvcnVt&_s2member_req[type]=level&_s2member_req[level]=0&_s2member_res[type]=page&s2member_seeking=page-821&s2member_level_req=0

Any suggestions?

Posted: Thursday Apr 12th, 2012 at 1:05 pm #10675
David Welch
Username: dwbiz05

What is the function in your menu look like?

Dave

Posted: Thursday Apr 12th, 2012 at 1:30 pm #10676

Here it is — thanks for asking.

Around line 67, the code sets the logout_link to $wpurl (which is ‘index.php’). This gets overwritten to become the membership options page (and a buch of MOP variables) no matter what I do:

function wps_add_loginlogout_link($items, $args)
{
	//defaults; change this as you see fit
	$defaults = array(
		'loginlout_position' => 999, //enter 0 for front, 999 for end
		'menu_id' => 'menu-item', //custom CSS
		'menu_class' => 'menu-item menu-item-type-custom menu-item-object-custom', //custom CSS
		'menu_location' =>'primary-public', //enter primary, secondary, or topnav for News
		'loginredirect' => false //enter true for redirect to wp-admin dashboard
	);

	//do nothing if not proper menu location
	if( $args->theme_location != $defaults['menu_location'] )
		return $items;

	//set redirect URL
	if( $defaults['loginredirect'] )
		$wpurl = 'wp-admin/index.php';
	else
		$wpurl = 'index.php';

	// split the menu items into an array using the ending <li> tag
	if ( $defaults['loginlout_position'] != 0 && $defaults['loginlout_position'] != 1 && $defaults['loginlout_position'] != 999 ) {
		$items = explode('</li>',$items);
	}

	if(is_user_logged_in())
	{
		$newitem = '<li id="'.$defaults['menu_id'].'" class="'.$defaults['menu_class'].'"><a title="Logout" href="'. wp_logout_url($wpurl) .'">Logout</a></li>';
		if ( $defaults['loginlout_position'] == 0 || $defaults['loginlout_position'] == 1 )
			$newitems = $newitem.$items;
		elseif ( $defaults['loginlout_position'] == 999 )
			$newitems = $items.$newitem;
		else
			$newitem = '<li id="'.$defaults['menu_id'].'" class="'.$defaults['menu_class'].'">' . $args->before . '<a title="Logout" href="'. wp_logout_url('index.php') .'">' . $args->link_before . 'Logout' . $args->link_after . '</a>' . $args->after; // no </li> needed this is added later
	}
	else
	{
		$newitem = '<li id="'.$defaults['menu_id'].'" class="'.$defaults['menu_class'].'"><a title="Login" href="'. wp_login_url($wpurl) .'">Login</a></li>';
		if ( $defaults['loginlout_position'] == 0 || $defaults['loginlout_position'] == 1 )
			$newitems = $newitem.$items;
		elseif ( $defaults['loginlout_position'] == 999 )
			$newitems = $items.$newitem;
		else
			$newitem = '<li id="'.$defaults['menu_id'].'" class="'.$defaults['menu_class'].'">' . $args->before . '<a title="Login" href="'. wp_login_url('index.php') .'">' . $args->link_before . 'Login' . $args->link_after . '</a>' . $args->after; // no </li> needed this is added later
	}

	if ( $defaults['loginlout_position'] != 0 && $defaults['loginlout_position'] != 1 && $defaults['loginlout_position'] != 999 ) {
		$newitems = array();

		// loop through the menu items, and add the new link at the right position
		foreach($items as $index => $item)
		{
		// array indexes are always one less than the position (1st item is index 0)
			if($index == $defaults['loginlout_position']-1)
			{
				$newitems[] = $newitem;
			}
			$newitems[] = $item;
		}

		// finally put all the menu items back together into a string using the ending <li> tag and return
		$newitems = implode('</li>',$newitems);
	}

	return $newitems;
}
add_filter('wp_nav_menu_items', 'wps_add_loginlogout_link', 10, 2);
Posted: Thursday Apr 12th, 2012 at 1:44 pm #10678
David Welch
Username: dwbiz05

Try replacing this:

wp_logout_url('index.php')

with this:

wp_logout_url( home_url() )

See if that works.

Dave

Posted: Thursday Apr 12th, 2012 at 1:58 pm #10679

Dave,
Thanks for your replies.

I have tride using home_url() in place of index.php.

No matter what I put there, a query string gets added.

It looks like a set of MOP variables.

Can I tell S2Member not to add them on logout?

Here is the link generated by home_url():

http://expertvatraining.com/wp-login.php?action=logout&redirect_to=http%3A%2F%2Fexpertvatraining.com&_wpnonce=78dfc02e78

And here is how the system resolves the link. There’s a query string in the URL that shows up as a result:

http://expertvatraining.com/membership-options-2?_s2member_seeking[type]=page&_s2member_seeking[page]=821&_s2member_seeking[_uri]=L2ZvcnVt&_s2member_req[type]=level&_s2member_req[level]=0&_s2member_res[type]=page&s2member_seeking=page-821&s2member_level_req=0
Posted: Thursday Apr 12th, 2012 at 2:16 pm #10680
David Welch
Username: dwbiz05

hm… that first url is what shows if you hover over the logout link on your menu too?

Dave

Posted: Thursday Apr 12th, 2012 at 2:34 pm #10681

Yes —
This is also the link generated by either ‘index.php’ or home_url() — anything I put in the code to create the logout link gets appended with the query string.

There are several places to logout (menu, forum).

All logouts get redirected to the membership options page, instead of home.

Posted: Thursday Apr 12th, 2012 at 3:52 pm #10689
David Welch
Username: dwbiz05

hm. I have to admit it’s got me stumped. Maybe someone else can chime in!

Dave

Posted: Thursday Apr 12th, 2012 at 5:53 pm #10699

This plugin seems to be what your looking for or @ least you can view to function code and make it better. It has a high rating and may be a worthy time saver.

http://wordpress.org/extend/plugins/peters-login-redirect/

Whatever its worth, I use a Forum Plugin that comes with this feature because by default your logout redirect goes to the forum login and had to find the settings to omit the redirect all together. This forum plugin also comes w/ a Login redirect & Registration redirect: It will also has a 4th option for a, Login URL in new user email: I don’t know how these work w/ s2 other than I know it effects the logout for sure.

http://simple-press.com/

Hope this helps! ;-)

Viewing 11 replies - 1 through 11 (of 11 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.