Support » Plugin: WP-Members: Membership Framework » [Plugin: WP-Members] Login Status redirect

  • Resolved bushbird

    (@bushbird)


    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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    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.

    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

    Plugin Author Chad Butler

    (@cbutlerjr)

    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(); ?>

    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.

    Plugin Author Chad Butler

    (@cbutlerjr)

    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;
    }

    Thank you thank works now.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: WP-Members] Login Status redirect’ is closed to new replies.