Jump to content


Photo

Login/Logout button


  • Please log in to reply
8 replies to this topic

#1 cornell2

cornell2

    Super Member

  • Members
  • PipPipPipPip
  • 119 posts

Posted 26 December 2011 - 07:39 PM

This is sort of a two part question: 1. I am looking for a plugin (would rather not write the CSS) to display a login button (or link) on my navigation bar ... and a logout link (if they are already logged in). I know, it's probably 5 lines of css but I guess I am a little lazy today and really don't want to reinvent the wheel. The Meta widget is close, except I just want the login/out 2. For the above - any CSS tips for PlatformPro to easily place this login button/link on the nav bar next to the search box? I am sure this has been discussed on these boards, I just can't seem to find it in a simple search. Thanks and Happy Holidays!

#2 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 26 December 2011 - 08:38 PM

Cornell, I've looked and I cannot find any easy CSS that will alternate menu items between states. Specifically, I mean a login button when not logged in, and a logout when logged in. I understand your lack of desire to add CSS code, however, the alternative seems much more labor intensive: http://erisds.co.uk/...gin-logout-link As for the answer to No. 2 on your list, the last menu item in your menu should be next to the search box. There are however, custom login/logout plugins that would apply in the sidebar. Those are intuitive so they would change based on the state, as well as adding a registration link.

#3 cornell2

cornell2

    Super Member

  • Members
  • PipPipPipPip
  • 119 posts

Posted 26 December 2011 - 09:02 PM

To clarify - I wasn't looking for code that would "alternate menu items between states" - though that would be an interesting approach - now that you mentioned it. I am already using a sidebar widget that does what I want, but the problem is that I don't use sidebars on many of my pages. I'd rather have one consistent "Welcome: Mr. User / Logout" or "Login/Register" link on the upper right corner. I think I can do it completely with CSS (without PHP) inside the custom code section. Working on it now. I'll report back and post the code if I ever get it to work. But this little piece of functionality might be nice to include in upcoming versions of Platform pro. Thanks

#4 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 26 December 2011 - 09:16 PM

I understood from

"...a logout link (if they are already logged in)"

that you wanted it to be by state of login, but yes, it is a good way to do it. However, I do not know exactly how that could possibly be achieved with CSS unless it were coordinated with a function. CSS cannot determine states of login to my knowledge. However, if you need both, you could always create a login item in the main menu, and a drop down option for logout by creating a link back to your homepage, labeling it "Logout" and making it a child link under Login. At least that would be a temporary solution until you find a better one. I will alert the developers to your suggestion.

#5 cornell2

cornell2

    Super Member

  • Members
  • PipPipPipPip
  • 119 posts

Posted 26 December 2011 - 09:23 PM

Yes, I was toying with combining css with some well documented wordpress php ... but stopped ... I decided that I was about to pretty much write a new plugin, and I am sure one already exists. Instead, I am going to tweak one of the plugins I found ... Thanks!

#6 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 26 December 2011 - 09:38 PM

No problem.

#7 Jackey

Jackey

    Advocate

  • Members


  • 685 posts
  • LocationHelmond
  • Country: Country Flag

Posted 26 December 2011 - 11:15 PM

@cornell2

Add to style.css

 .icons .loginicon {background: url('../../icons/login.png') no-repeat 50% 0;}
	.icons .logout {background: url('../../icons/logout.png') no-repeat 50% 0;}
	.icons .goto_profile {background: url('../../icons/profile.png') no-repeat 50% 0;}


Add to functions.php

 add_action('pagelines_branding_icons_end', 'add_icons_to_branding');


 function add_icons_to_branding(){
			// This hook adds a icon to the header of your theme. The class referenced in the link can be seen in the style.css
			?>
			<?php if(!is_user_logged_in()):?>
				<a href="<?php echo get_site_url()?>/wp-login.php?redirect_to=<?php echo $_SERVER['REQUEST_URI']; ?>" class="loginicon" alt="Login" title="Login"></a>
			<?php endif;?>
			<?php if(is_user_logged_in()):?>
				<a href="<?php echo wp_logout_url( get_permalink() ); ?>" class="logout" alt="Logout" title="Logout"></a>
				<a href="http://**yourwebsite**/wp-admin/profile.php" class="goto_profile" alt="Profile" title="Profile"></a>
				<span><?php global $current_user;
	      							get_currentuserinfo();
	      							echo "Profile: " . $current_user->display_name . " ?»";?></span>
			<?php endif;?>
		<?php }

And add a login.png logout.png and profile.png to /wp-content/icons/

It should look like this : http://golfclub-stippelberg.nl

login with guest/guest (only temporary available)

#8 cornell2

cornell2

    Super Member

  • Members
  • PipPipPipPip
  • 119 posts

Posted 27 December 2011 - 01:44 AM

I'll try out the code you posted - but the site you gave as an example does not seem to show what I am looking for.

Actually, I already coded a simpler solution (the php, at least) - it's just that I am still having trouble figuring out how to display it inside the navigation bar.

here is the code that goes into functions.php

 function my_login_status() {
		global $user_login;
	        $siteurl = get_bloginfo('url');
		$logout = get_bloginfo('url')."/wp-login.php?action=logout&redirect_to=".get_bloginfo('url')."&_wpnonce=5b2c309ac6";
		$login = get_bloginfo('url')."/wp-login.php?redirect_to=".get_bloginfo('url')."%2Fblog%2F";
	        $useradmin = get_bloginfo('url')."/wp-admin/profile.php";
		if (is_user_logged_in()) {
			$wpmem_login_status = '
			<p>Welcome: <a href="'.$useradmin.'">'.$user_login.'</a> | <a href="'.$logout.'">logout</a></p>';
	
		} else {
			$wpmem_login_status = '
			<p>You are not logged in | <a href="'.$login.'">login</a></p>';
		}
		return $wpmem_login_status;
	}

and then at the end of header.php I put
 <div align="right" style="padding-right:20px;"><?php echo my_login_status(); ?></div>

this works perfect for me, except it is underneath the navigation bar, not inside of it.

you can see it at http://metapreneurship.net/

[begin rant]
And, with all due respect to whoever marked this as "answered" ... this is a pet peeve of many on these boards: perhaps we can leave it up to the person who actually asked the question to decide whether or not they got they answer they needed. Someone else summarily marking it as 'answered' not only blindsides the original questioner, it also discourages others (who might actually have something helpful to say - since the thread appears closed). It's simply not a good practice.
[end rant]

#9 Jackey

Jackey

    Advocate

  • Members


  • 685 posts
  • LocationHelmond
  • Country: Country Flag

Posted 27 December 2011 - 07:47 AM

No problem, as well... i'm not encouraged either.