Wordpress: UserPro Conditional Log-in


/ Published in: PHP
Save to your folder(s)

Add Login / Logout to your WordPress Menu. You must have UserPro


Copy this code and paste it in your HTML
  1. /** ******** ******** ******** ******** ******** ******** ******** ********
  2. * TITLE: UserPro: Conditional Log-in / Log-out
  3. * DESCRIPTION: Add Login / Logout to your WordPress Menu. You must have UserPro
  4. *
  5. * http://userproplugin.com/userpro/forums/topic/display-logout-link-after-login/
  6. * http://jsfiddle.net/HZscB/
  7. *
  8. */
  9. function userpro_add_loginout_navitem($items, $args ) {
  10. //Change "avia" to your theme's main menu location
  11. $theme_location = 'yoo_avenue_wp';
  12. $current_user = wp_get_current_user();
  13. if( $args->theme_location == $theme_location ) {
  14. if ( !(is_user_logged_in()) ) {
  15. //login display
  16. $login_item = '<li class="nav-login menu-item"><a href="/profile/#" class="popup-login">Log In</a></li>';
  17. //login display
  18. $login_item .= '<li class="nav-login menu-item"><a href="/profile/register">Register</a></li>';
  19. }
  20. else {
  21. //logout display
  22. //$login_item = '<li class="nav-login menu-item">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
  23. //logout display
  24. //$login_item = '<li class="nav-login menu-item">'.echo $current_user.'</li>';
  25. $login_item = '<nav>';
  26. $login_item .= '<ul>';
  27. $items .= '<li><a href="#">'.$current_user->user_firstname.' '.$current_user->user_lastname.'</a>';
  28. $items .= '<ul>';
  29. $items .= '<li><a href="/profile/">My Profile</a></li>';
  30. $items .= '<li class="nav-login menu-item">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
  31. $items .= '</ul>';
  32. $items .= '</li>';
  33. $items .= '</ul>';
  34. }
  35. $items .= $login_item;
  36. }
  37. return $items;
  38. }
  39. //add_filter('wp_nav_menu_items', 'userpro_add_loginout_navitem', 10, 2);

URL: http://jsfiddle.net/HZscB/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.