Forums

[Plugin: SimpleModal Login] On log out goes back to standard WordPress log in (2 posts)

  1. borimrr
    Member
    Posted 1 year ago #

    So basically the plugin works great except one thing. When I click on the Log out link provided by the Meta widget on the sidebar the page goes to the standard WordPress log in screen.

    I don't know if I have to do something other than installing the plugin and changing settings to my liking. It would be nice if on Log out it would take you to the home page of the site or to the alst page you were viewing.

    Any ideas why this is happening? thanks in advance.

  2. Eric Martin
    Member
    Posted 1 year ago #

    That is the default behavior. If you want to override it, you need to pass in a redirect url to the wp_loginout() function. Since you are using the Meta widget, the easier thing to do is add the following code to your functions.php theme file:

    function my_loginout($link) {
    	if (strpos($link, 'redirect') === false) {
    		$parts = explode(" ", $link);
    		foreach ($parts as &$part) {
    			if (strpos($part, 'href') === 0) {
    				$redirect = sprintf('%sredirect_to=%s">',
    					strpos($part, '?') === false ? '?' : '&',
    					$_SERVER['REQUEST_URI']
    				);
    				$part = str_replace('">', $redirect, $part);
    			}
    		}
    		$link = implode(" ", $parts);
    	}
    
    	return $link;
    }
    add_filter('loginout', 'my_loginout');

    In short, that adds the necessary redirect_to parameter to the Log In/Out links. If you only want it for the Log Out link, you can use the following:

    function my_loginout($link) {
    	if (strpos($link, 'redirect') === false && strpos($link, 'action=logout') !== false) {
    		$parts = explode(" ", $link);
    		foreach ($parts as &$part) {
    			if (strpos($part, 'href') === 0) {
    				$redirect = sprintf('%sredirect_to=%s">',
    					strpos($part, '?') === false ? '?' : '&',
    					$_SERVER['REQUEST_URI']
    				);
    				$part = str_replace('">', $redirect, $part);
    			}
    		}
    		$link = implode(" ", $parts);
    	}
    
    	return $link;
    }
    add_filter('loginout', 'my_loginout');

Topic Closed

This topic has been closed to new replies.

About this Topic