Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter wolfy02

    (@wolfy02)

    figured out what code was breaking it. not really entirely sure of what the class did in all honesty. I’m sure it was something important at one time, but as far as I can tell it fixed what I need this plugin for.

    I just commented out lines 38-112 of wordpress-access-control.php

    you can find it here, https://pastebin.com/3AMHGekh

    like i said, this works for me. take it as a band-aid approach, i’m sure this will take some type of functionality away from the full plugin. make sure you backup your original, or just remove the comments from this one.

    @wolfy02 Your suggestion is working pretty well. It was necessary to comment out lines 38-121 of wordpress-access-control.php to get it to work.

    Now, I have a dilemma. The styling for my secondary menu works. But, “items in the primary navigation menu ARE now being displayed to users that doesn’t have access to them. Items always show up for users with no access to them. Only valid users should be able to see private menu items. WPAC still refuses access to users that are not logged in, but I’d rather they not be exposed to the private menu at all.

    Any ideas?

    modiphier

    (@modiphier)

    Hello,
    Any progress with this?

    I’m having the same issue and can’t fix it at all! I’m being told I might have to change my theme!

    @lena DaCosta: If you require assistance then, as per the Forum Welcome, please post your own topic. This topic references an old version of WordPress.

    I originally commented out the code as suggested above, but I combined the WPAC_Nav_Menu_Walker class with the bootstrap nav walker I was using (see here https://github.com/twittem/wp-bootstrap-navwalker/tree/For-Bootstrap-2.3.2)

    I am using bootstrap 2.x and wordpress 3.6

    I used it to hide a menu item and its dropdown menu, so I’m not sure how it will work with individual links.

    In my wordpress-access-control.php is is lines 37 to 303.
    Replace with the following:

    // We check to see if the class exists because it isn't part of pre WordPress 3 systems
    if ( class_exists( 'Walker_Nav_Menu' ) ) {
    	add_filter( 'wp_nav_menu_args', array( 'WordPressAccessControl', 'wp_nav_menu_args' ) );
    
    	/**
    	 * A custom walker that checks our conditions to make sure the user has
    	 * permission to view the page linked to from the menu item
    	 *
    	 * @author Brandon Wamboldt
    	 * @package WordPress
    	 * @subpackage WordPressAccessControl
    	 */
    	class WPAC_Nav_Menu_Walker extends Walker_Nav_Menu
    	{
    		var $in_private = false;
    		var $private_lvl = 0;
    
    		function start_lvl( & $output, $depth )
    		{
    			if ( ! $this->in_private ) {
    				$indent = str_repeat( "\t", $depth );
    				$output	   .= "\n$indent<ul class=\"dropdown-menu\">\n";
    				//$indent = str_repeat( '    ', $depth );
    				//$output .= "\n$indent<ul class=\"sub-menu\"><li style='display:none;'></li>\n";
    			}
    		}
    
    		/*function end_lvl( & $output, $depth )
    		{
    			if ( ! $this->in_private ) {
    				$indent = str_repeat( '    ', $depth );
    				$output .= "$indent</ul>\n";
    			}
    		}*/
    
    		function start_el( & $output, $item, $depth=0, $args = array(), $id = 0  )
    		{
    			global $wp_query;
    
    			if ( WordPressAccessControl::check_conditions( $item->object_id ) || get_option( 'wpac_show_in_menus', 'with_access' ) == 'always' ) {
    				if ( ! $this->in_private ) {
    					$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    
    					if (strcasecmp($item->title, 'divider')) {
    
    					$class_names = $value = '';
    
    					$classes = empty( $item->classes ) ? array() : (array) $item->classes;
    
    					$classes[] = ($item->current) ? 'active' : '';
    
    					$classes[] = 'menu-item-' . $item->ID;
    
    					$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
    
    					if ($args->has_children && $depth > 0) {
    
    						$class_names .= ' dropdown-submenu';
    
    					} else if($args->has_children && $depth === 0) {
    
    						$class_names .= ' dropdown';
    
    					}
    
    					$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
    
    					$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
    
    					$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
    
    					$output .= $indent . '<li' . $id . $value . $class_names .'>';
    
    					$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
    
    					$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
    
    					$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
    
    					$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    
    					$attributes .= ($args->has_children) 	    ? ' data-toggle="dropdown" data-target="#" class="dropdown-toggle"' : '';
    
    					$item_output = $args->before;
    
    					$item_output .= '<a'. $attributes .'>';
    
    					$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    
    					$item_output .= ($args->has_children && $depth == 0) ? ' <b class="caret"></b></a>' : '</a>';
    
    					$item_output .= $args->after;
    
    					$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    
    				} else {
    
    					$output .= $indent . '<li class="divider">';
    
    				}
    				}
    			} else {
    				$this->in_private = true;
    				$this->private_lvl++;
    			}
    		}
    
    			/**
    
    	 * Traverse elements to create list from elements.
    
    	 *
    
    	 * Display one element if the element doesn't have any children otherwise,
    
    	 * display the element and its children. Will only traverse up to the max
    
    	 * depth and no ignore elements under that depth. 
    
    	 *
    
    	 * This method shouldn't be called directly, use the walk() method instead.
    
    	 *
    
    	 * @see Walker::start_el()
    
    	 * @since 2.5.0
    
    	 *
    
    	 * @param object $element Data object
    
    	 * @param array $children_elements List of elements to continue traversing.
    
    	 * @param int $max_depth Max depth to traverse.
    
    	 * @param int $depth Depth of current element.
    
    	 * @param array $args
    
    	 * @param string $output Passed by reference. Used to append additional content.
    
    	 * @return null Null on failure with no changes to parameters.
    
    	 */
    
    	function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
    
    		if ( !$element ) {
    
    			return;
    
    		}
    
    		$id_field = $this->db_fields['id'];
    
    		//display this element
    
    		if ( is_array( $args[0] ) ) 
    
    			$args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
    
    		else if ( is_object( $args[0] ) ) 
    
    			$args[0]->has_children = ! empty( $children_elements[$element->$id_field] ); 
    
    		$cb_args = array_merge( array(&$output, $element, $depth), $args);
    
    		call_user_func_array(array(&$this, 'start_el'), $cb_args);
    
    		$id = $element->$id_field;
    
    		// descend only when the depth is right and there are childrens for this element
    
    		if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
    
    			foreach( $children_elements[ $id ] as $child ){
    
    				if ( !isset($newlevel) ) {
    
    					$newlevel = true;
    
    					//start the child delimiter
    
    					$cb_args = array_merge( array(&$output, $depth), $args);
    
    					call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
    
    				}
    
    				$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
    
    			}
    
    				unset( $children_elements[ $id ] );
    
    		}
    
    		if ( isset($newlevel) && $newlevel ){
    
    			//end the child delimiter
    
    			$cb_args = array_merge( array(&$output, $depth), $args);
    
    			call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
    
    		}
    
    		//end this element
    
    		$cb_args = array_merge( array(&$output, $element, $depth), $args);
    
    		call_user_func_array(array(&$this, 'end_el'), $cb_args);
    
    	}
    
    		/*function end_el( & $output, $item, $depth )
    		{
    			if ( WordPressAccessControl::check_conditions( $item->object_id ) || get_option( 'wpac_show_in_menus', 'with_access' ) == 'always' ) {
    				if ( ! $this->in_private ) {
    					$output .= "</li>\n";
    				}
    			} else {
    				$this->private_lvl--;
    
    				if ( $this->private_lvl == 0 ) {
    					$this->in_private = false;
    				}
    			}
    		}*/
    	}
    }
    Plugin Author Brandon

    (@brandonwamboldt)

    FYI this has been fixed in the latest version (4.0.0).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘breaks sub menu items on bootstrap theme’ is closed to new replies.