WordPress.org

Forums

SimpleModal Login
[resolved] How to add SimpleModal in a link in the menu (9 posts)

  1. Juan Quaglia
    Member
    Posted 3 years ago #

    I'm trying to use this plugin in a "members area" link in the top menu of my website, but I have no idea how to do it. I can't add a class when I create a custom link in the menu. Could you please help me?

    http://wordpress.org/extend/plugins/simplemodal-login/

  2. Juan Quaglia
    Member
    Posted 3 years ago #

    I tried adding "simplemodal-login" in the CSS class box, but it doesn't work. The link still redirects to the usual log-in page. The form works ok when activated by keystroke shortcut.

  3. RonStrilaeff
    Member
    Posted 3 years ago #

    Try (no quotes)

    - put '/wp-login.php' in the URL field
    - put 'Log-In' in the Navigation Label field (any label will do)
    - put 'simplemodal-login' in the css classes field

    Save Menu, refresh site, click on the new menu item.

    That worked for me on recent wp version and woothemes-canvas

  4. Juan Quaglia
    Member
    Posted 3 years ago #

    It works! Thanks a lot! Looks like the problem was that I had put the entire URL instead of just '/wp-login.php'.

  5. DesignsCheap
    Member
    Posted 3 years ago #

    Tried this and it works...but what I really need is for it to show Login when they aren't and "Logout" when they are logged in already.

    With the solution above it still shows login after they are already logged in.

  6. RonStrilaeff
    Member
    Posted 3 years ago #

    I just pulled this out of my child theme's functions.php file

    It's not perfect, but what it does is creates a login/logout menu item on the primary menu and builds in some redirect logic.

    As-Is ... no guarantees that it will work in your theme or environment. In fact in mine, the simple modal plugin gives an "ERROR: OK" message on successful logins and after that it will not refresh the page or redirect. I don't have time to try and fix it so I'm not even going to use this plugin, but I hope this login/logout menu snippet thing works for you.

    <?php
    function sv_get_logout_redirect_url() {
    	$badurls = array('submit-form', 'dashboard', 'profile', 'guidelines');
    	$current_url = get_permalink();
    	$isgood = true;
    	foreach ($badurls as $bad) {
    		$pos = strpos($current_url,$bad);
    		if (! $pos === false) {
    			$isgood = false;
    			break;  // no need to check any more "bads"
    		}
    	}
    	if ($isgood) {
    		return wp_logout_url(get_permalink());
    	} else {
    		return wp_logout_url(home_url());
    	}
    }
    
    add_filter( 'wp_nav_menu_items', 'sv_add_usermenu', 10, 2 );
    
    function sv_add_usermenu( $items, $args ) {
    	global $current_user;
    
    	if (is_user_logged_in() && $args->theme_location == 'primary-menu') {
    		// menu items for logged in user
    		$guidelines_url = site_url() . '/guidelines/';
    		$dashboard_url = site_url() . '/dashboard/' . $current_user->user_nicename;
    		$profile_url = site_url() . '/profile/' . $current_user->user_nicename;	
    
    		//	http://fortawesome.github.com/Font-Awesome/
    		//	some fontawesome names icon-arrow-down, icon-chevron-down, icon-caret-down
    		$items .= "<li class='menu-item'><a href='#'>$current_user->display_name <span class='icon-caret-down'> </span> </a>";
    		//$items .= "<li class='menu-item'><a href='#'>$current_user->display_name</a>";
    		$items .= "<ul>";
    		$items .= "<li class='sub-menu'><a href='$guidelines_url'>Usage Guidelines</a></li>";
    		$items .= "<li class='sub-menu'><a href='$dashboard_url'>My Dashboard</a></li>";
    		$items .= "<li class='sub-menu'><a href='$profile_url'>My Profile</a></li>";
    		$items .= "<li class='sub-menu'><a href='" . sv_get_logout_redirect_url()  . "'>Log Out</a></li>";
    		$items .= "</ul>";
    		$items .= "</li>";
        } elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
    		//menu items for NOT logged in user
    		//$login_url = site_url('/a-page-name/');		// get login url and redirect to a specific page
    		//$login_url = wp_login_url( home_url() );		// get login url and redirect to home page
    		$login_url = wp_login_url( get_permalink() );	// get login url and redirect to current page
    		//the contents of <a href""  must be a url
    		$items .= "<li class='sub-menu'> <a href='$login_url' class='simplemodal-login'>Log In</a></li>";
        }
        return $items;
    }
    ?>

    The second last line of code is the tie in to this plugin where it simply adds that class name to the link for the menu item. The plugin magically takes over from there and replaces the standard wordpress login page with its modal overlay.

  7. DesignsCheap
    Member
    Posted 3 years ago #

    Thanks Ron.

    I tried its not working. I did update the menu slug since mine isn't called primary-menu, and I removed a few bits like the /guidelines/ part since I don't have that, but nothing shows up.

    I'm not a coder so I'm not sure what I'm doing wrong. thanks though for trying.

  8. RonStrilaeff
    Member
    Posted 3 years ago #

    Here is a barebones example (which I just tested on my site):

    add_filter( 'wp_nav_menu_items', 'asv_add_usermenu', 10, 2 );
    
    function asv_add_usermenu( $items, $args ) {
      if (is_user_logged_in() && $args->theme_location == 'primary-menu') {
        $items .= "<li class='sub-menu'><a href='" . wp_logout_url()  . "'>Log Out</a></li>";
      } elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
        $items .= "<li class='sub-menu'> <a href='" . wp_login_url() . "'>Log In</a></li>";
      }
      return $items;
    }

    The 'primary-menu' text is from this admin page (whatever name the theme registered that menu as). http://yoursite.com/wp-admin/nav-menus.php It is one of the menu names in grey italics in the top left box.

    I gleaned the above from http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
    and http://codex.wordpress.org/Function_Reference/wp_nav_menu
    and I think the 'primary-menu' is the only thing environment specific.

  9. DesignsCheap
    Member
    Posted 3 years ago #

    I'll give it a shot in the morning and let you know. (It's 12:30am here I'm brain dead...been on the computer for 14 hours.)

    Thanks again for your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • SimpleModal Login
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic