Jump to content


Photo
- - - - -

Theme_Location of Simple Nav Section


Best Answer dario , 14 May 2013 - 07:03 PM

Thanks to you both.

 

Rob,

Yes to the Dashboard access level settings in PageLines and yes to the s2Member plugin. I removed it awhile back though (for a long forgotten reason) but I'll give it another look.

 

Anthalis,

The simple_nav appears in my footer and I've had no luck targeting that, other than having it disappear. I 'think' the theme_location for the NavBar is 'main-nav' but I'm not having luck with that either.

 

I did, however, just succeed with the following. The source of the code is here and here.

What I had to do was create a regular wp menu, add the items I wanted to it and then attach it to the Primary Website Navigation theme location drop down.

That resulted in my main navigation bar functioning just like it did when all I was using was the PL fixed NavBar.

Then I added the following to the base theme's functions.php file:

 
if ( !class_exists('JMO_Custom_Nav')) {
    class JMO_Custom_Nav {
        public function add_nav_menu_meta_boxes() {
        	add_meta_box(
        		'wl_login_nav_link',
        		__('WishList Login'),
        		array( $this, 'nav_menu_link'),
        		'nav-menus',
        		'side',
        		'low'
        	);
        }
        
        public function nav_menu_link() {?>
        	<div id="posttype-wl-login" class="posttypediv">
        		<div id="tabs-panel-wishlist-login" class="tabs-panel tabs-panel-active">
        			<ul id ="wishlist-login-checklist" class="categorychecklist form-no-clear">
        				<li>
        					<label class="menu-item-title">
        						<input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1"> Login/Logout Link
        					</label>
        					<input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="custom">
        					<input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="Login">
        					<input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value="<?php bloginfo('wpurl'); ?>/wp-login.php">
        					<input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" value="wl-login-pop">
        				</li>
        			</ul>
        		</div>
        		<p class="button-controls">
        			<span class="list-controls">
        				<a href="/wordpress/wp-admin/nav-menus.php?page-tab=all&amp;selectall=1#posttype-page" class="select-all">Select All</a>
        			</span>
        			<span class="add-to-menu">
        				<input type="submit" class="button-secondary submit-add-to-menu right" value="Add to Menu" name="add-post-type-menu-item" id="submit-posttype-wl-login">
        				<span class="spinner"></span>
        			</span>
        		</p>
        	</div>
        <?php }
    }
}

$custom_nav = new JMO_Custom_Nav;

add_action('admin_init', array($custom_nav, 'add_nav_menu_meta_boxes'));

That code added a custom meta box to the WordPress navigation menu interface on the admin-side.

I added the new menu item (WishList Login/Logout link), created by the code above, to the menu.

I then had to allow CSS Classes in the Screen Options > Show Advanced Menu Properties slide down.

 

Then I added the following code to the bottom of the base theme's function.php file:

 
if ( !class_exists( 'HijackMe' ) ) {
    class HijackMe {
        public function hijack_menu($objects) {
    		/**
		 * If user isn't logged in, we return the link as normal
		 */
		if ( !is_user_logged_in() ) {
			return $objects;
		}
		/**
		 * If they are logged in, we search through the objects for items with the 
		 * class wl-login-pop and we change the text and url into a logout link
		 */
		foreach ( $objects as $k=>$object ) {
			if ( in_array( 'wl-login-pop', $object->classes ) ) {
				$objects[$k]->title = 'Logout';
				$objects[$k]->url = wp_logout_url();
				$remove_key = array_search( 'wl-login-pop', $object->classes );
				unset($objects[$k]->classes[$remove_key]);
			}
		}

		return $objects;
	}
    }
}

$hijackme = new HijackMe;

add_filter('wp_nav_menu_objects', array($hijackme, 'hijack_menu'), 10, 2);

This works great. Along with the Restricted Site Access plugin I have the site set to redirect to the login page upon the user logging out.

Go to the full post


  • Please log in to reply
5 replies to this topic

#1 dario

dario

    Super Member

  • Members

  • 112 posts
  • LocationMinneapolis
  • Framework Version:2.4.4
  • Country: Country Flag

Posted 13 May 2013 - 10:11 PM

I'm trying to add a login/logout conditional to my Standard NavBar.

 

I've created the menu via WP's menu system (though the menu showed just fine before I did that). Anyway, I've named the menu 'Main' and added it to the Simple Nav Section theme location. This seems to work fine, but loses my footer info though.

 

Then I added the following to my base functions file:

Please Login or Register to see this Hidden Content

No login/out menu item shows and it throws a LESS compile error on the theme_location == 'main'.

Please Login or Register to see this Hidden Content

I've tried various names for the menu (simplistic, I know), to no avail.

Using dev tools in Safari and also in Chrome does not show me what I need to reference (simple_nav, simple_nav_section, etc.).

I think I'm approaching this incorrectly but have reached a dead end.

 

May I have a hint please?  :pic:

 

Due to the footer issue I've removed the wp menu allocation for now and am relying on PL's NavBar.



#2 Rob

Rob

    One Smart Egg

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

Posted 13 May 2013 - 11:01 PM

Hi Dario,

 

I suspect this isn't going to be the easiest thing, and since I'm not a programmer, I wouldn't venture a guess about your code.  Obviously something, somewhere doesn't seem to agree with it.   The footer, being a unique section is probably missing a conditional that says that the login is for the whole site... so if you are successful in the Nav Classic, you're being logged in within the section, probably .content or some other element, but then the footer isn't tagging along for the ride. So as far as Simple Nav is concerned, no one has logged in via that menu, thus you can't see the footer. That being a coding problem, PageLines throws you a little error.

 

Forgive my simple perspective on this, but I think your prime goal is simply to make login to the site easy, simple and accessible to your visitors.  To do that, placing a login link in the menu usually works, but most people would simply make the link, rather than creating custom code. I see your point tho, and suggest, instead, using SideBar Login, a well-established, well-maintained plugin you can place anywhere that a sidebar goes.

 

I know this isn't the most ideal scenario, and definitely not what you'd like, but short of hiring a custom programmer, it's the fastest and easiest method. You could place the widget at the top of your primary sidebar, and if you were using the multi-column footer sidebar, you could add it to the footer.

 

Let me know if you need additional help with this.



#3 dario

dario

    Super Member

  • Members

  • 112 posts
  • LocationMinneapolis
  • Framework Version:2.4.4
  • Country: Country Flag

Posted 14 May 2013 - 12:29 AM

Interesting Rob. I'm holding onto your suggestions as a fallback in case nobody else comes up with a direct solution. I did the widget route for awhile but would prefer it in the menu. I'm not allowing users access to the WP dashboard/admin menu but they do need a logout.

 

Perhaps I should try what I'm attempting on a standard theme (2011 or another), just to rule out a PL issue. Not that it's a PL issue directly, rather, probably something I don't understand about how PL calls the page elements. The footer disappearing act shows my ignorance of that. I can almost always hack my way around but it would be nice to do things properly.

 

I still think that all I'm missing is the proper argument for the theme_location or the proper hook for the filter. One in the same perhaps?



#4 Rob

Rob

    One Smart Egg

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

Posted 14 May 2013 - 12:37 AM

Honestly,  I'm not sure.  I suspect there's a few missing conditionals as well.

 

Are you familiar with the Dashboard access level settings in PageLines? They're located at the bottom of Dashboard > PageLines > Site Options > Advanced. You'd use these to control who has access to different dashboard tabs.  There are also plugins that let you control which access levels use the different Dashboard components at different levels.

 

Also, have you tried s2Member plugin? I've used it with no problems (for membership management) and it integrates perfectly with PageLines. That might have some options for you.



#5 anthalis

anthalis

    Advanced Member

  • Members

  • 60 posts
  • Framework Version:Dev. Latest. Always.
  • Country: Country Flag

Posted 14 May 2013 - 06:28 PM

Hi,

 

Check out this article - it might point you in the right direction. It uses another method than what you posted here. You would have to find a way to incorporate the theme location AND/OR the specific menu class/id.

 

Please Login or Register to see this Hidden Content

 

The location of the menu is given in your-child-theme-folder/sections/simple_nav/section.php. 

Please Login or Register to see this Hidden Content

so: theme_location is simple_nav. 

 

Happy coding & good luck!



#6 dario

dario

    Super Member

  • Members

  • 112 posts
  • LocationMinneapolis
  • Framework Version:2.4.4
  • Country: Country Flag

Posted 14 May 2013 - 07:03 PM   Best Answer

Thanks to you both.

 

Rob,

Yes to the Dashboard access level settings in PageLines and yes to the s2Member plugin. I removed it awhile back though (for a long forgotten reason) but I'll give it another look.

 

Anthalis,

The simple_nav appears in my footer and I've had no luck targeting that, other than having it disappear. I 'think' the theme_location for the NavBar is 'main-nav' but I'm not having luck with that either.

 

I did, however, just succeed with the following. The source of the code is

Please Login or Register to see this Hidden Content

and

Please Login or Register to see this Hidden Content

.

What I had to do was create a regular wp menu, add the items I wanted to it and then attach it to the Primary Website Navigation theme location drop down.

That resulted in my main navigation bar functioning just like it did when all I was using was the PL fixed NavBar.

Then I added the following to the base theme's functions.php file:

Please Login or Register to see this Hidden Content

That code added a custom meta box to the WordPress navigation menu interface on the admin-side.

I added the new menu item (WishList Login/Logout link), created by the code above, to the menu.

I then had to allow CSS Classes in the Screen Options > Show Advanced Menu Properties slide down.

 

Then I added the following code to the bottom of the base theme's function.php file:

Please Login or Register to see this Hidden Content

This works great. Along with the Restricted Site Access plugin I have the site set to redirect to the login page upon the user logging out.


  • anthalis likes this