WordPress.org

Ready to get started?Download WordPress

Forums

WP-Members
[resolved] Login Status redirect (7 posts)

  1. bushbird
    Member
    Posted 3 years ago #

    Hi I have a login status in the header of my theme. Works fine but i would like to have a redirect to members login page or have a link appear in the place of "You are logged in as Joe | Logout"

    When logged out have "Login" appear with link to members url

    cheers

  2. Chad Butler
    Member
    Plugin Author

    Posted 3 years ago #

    I can understand that in some situations this might be useful. However, for the plugin at large it's not really a scalable solution for a number of reasons, the primary being that for users that don't use real permalinks, it's impossible to automagically find the members page.

    But... there is a solution.

    I think the best way to approach something like this is to utilize the theme's functions.php file. (If your theme does not include a functions.php file, you can create one and WP will load it.) I would do it this way rather than customize the existing function since that would not be scalable with any upgrades of the plugin.

    Working from the framework of the original wpmem_inc_status function (which is in wp-members-sidebar.php), call it something like my_login_status and customize it as needed. Here is an example of what you could do:


    function my_login_status()
    {
    global $user_login;
    $logout = get_bloginfo('url')."/?a=logout";
    $login = get_bloginfo('url')."/members-area/";

    if (is_user_logged_in()) {

    $wpmem_login_status = "
    <p>".__('You are logged in as')." $user_login | ".__('click here to logout')."</p>";

    } else {

    $wpmem_login_status = "
    <p>You are not logged in | click here to login</p>";

    }

    return $wpmem_login_status;
    }

    Putting this in your theme's functions.php file, you could then call it from your theme as follows:

    <?php echo my_login_status(); ?>

    Hope this gives you some ideas.

  3. globaltimoto
    Member
    Posted 2 years ago #

    Hello Chad

    I'd like to use this, but I'm confused by this example.

    Is it possible to show the complete example within backticks please ?

    Thanks

  4. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    With the exception of indents, that is a complete example.

    function my_login_status() {
    	global $user_login;
    	$logout = get_bloginfo('url')."/?a=logout";
    	$login = get_bloginfo('url')."/members-area/";
    	if (is_user_logged_in()) {
    		$wpmem_login_status = "
    		<p>".__('You are logged in as')." $user_login | ".__('click here to logout')."</p>";
    	} else {
    		$wpmem_login_status = "
    		<p>You are not logged in | click here to login</p>";
    	}
    	return $wpmem_login_status;
    }

    Put that in functions.php and call it with:

    <?php echo my_login_status(); ?>

  5. globaltimoto
    Member
    Posted 2 years ago #

    Hello Chad

    This prints to the screen
    "You are not logged in | click here to login"

    But how do I get the "click here to login" to be a clickable link ?

    I thought adding an anchor tag would do it, but no luck.

  6. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    I guess in the original (which I just copy/pasted) the anchors were rendered as html...

    try this...

    function my_login_status() {
    	global $user_login;
    	$logout = get_bloginfo('url')."/?a=logout";
    	$login = get_bloginfo('url')."/members-area/";
    	if (is_user_logged_in()) {
    		$wpmem_login_status = '
    		<p>You are logged in as '.$user_login.' | <a href="'.$logout.'">click here to logout</a></p>';
    	} else {
    		$wpmem_login_status = '
    		<p>You are not logged in | <a href="'.$login.'">click here to login</a></p>';
    	}
    	return $wpmem_login_status;
    }
  7. globaltimoto
    Member
    Posted 2 years ago #

    Thank you thank works now.

    Sorry I couldn't figure out the correct php syntax myself.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags