Posted By

chrisaiv on 09/13/14


Tagged

wordpress


Versions (?)

Wordpress: UserPro Conditional Log-in


 / Published in: PHP
 

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

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

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

Report this snippet  

You need to login to post a comment.