Overview
  • Namespace
  • Class

Namespaces

  • nk2580
    • wordsmith
      • Actions
      • Endpoints
      • Environment
      • Filters
      • Inputs
        • Fields
      • Menus
      • MetaBoxes
      • PostTypes
      • Routes
      • Scripts
      • SettingsPages
      • Taxonomies
        • Hierarchical
        • NonHierarchical
      • UserCapabilities
      • UserRoles
      • Utillities
        • NavWalkers

Classes

  • nk2580\wordsmith\Actions\Action
  • nk2580\wordsmith\Actions\AJAXAction
  • nk2580\wordsmith\Endpoints\Endpoint
  • nk2580\wordsmith\Endpoints\EndpointHandler
  • nk2580\wordsmith\Environment\Instance
  • nk2580\wordsmith\Environment\Plugin
  • nk2580\wordsmith\Environment\Theme
  • nk2580\wordsmith\Filters\Filter
  • nk2580\wordsmith\Inputs\Fields\AddressField
  • nk2580\wordsmith\Inputs\Fields\CheckBoxField
  • nk2580\wordsmith\Inputs\Fields\EmailField
  • nk2580\wordsmith\Inputs\Fields\FileUploadField
  • nk2580\wordsmith\Inputs\Fields\GalleryField
  • nk2580\wordsmith\Inputs\Fields\HiddenField
  • nk2580\wordsmith\Inputs\Fields\ImageUploadField
  • nk2580\wordsmith\Inputs\Fields\PasswordField
  • nk2580\wordsmith\Inputs\Fields\RadioButtonField
  • nk2580\wordsmith\Inputs\Fields\SelectBoxField
  • nk2580\wordsmith\Inputs\Fields\TextAreaField
  • nk2580\wordsmith\Inputs\Fields\TextField
  • nk2580\wordsmith\Inputs\Fields\UrlField
  • nk2580\wordsmith\Inputs\Input
  • nk2580\wordsmith\Inputs\Repeater
  • nk2580\wordsmith\Menus\Menu
  • nk2580\wordsmith\MetaBoxes\MetaBox
  • nk2580\wordsmith\PostTypes\PostType
  • nk2580\wordsmith\Routes\Route
  • nk2580\wordsmith\Routes\RouteFactory
  • nk2580\wordsmith\Routes\RouteGroup
  • nk2580\wordsmith\Scripts\AdminScript
  • nk2580\wordsmith\Scripts\PublicScript
  • nk2580\wordsmith\SettingsPages\SettingsPage
  • nk2580\wordsmith\Taxonomies\Hierarchical\HierarchicalTaxonomy
  • nk2580\wordsmith\Taxonomies\NonHierarchical\NonHierarchicalTaxonomy
  • nk2580\wordsmith\Taxonomies\Taxonomy
  • nk2580\wordsmith\UserCapabilities\UserCapability
  • nk2580\wordsmith\UserRoles\UserRole
  • nk2580\wordsmith\Utillities\Cypher
  • nk2580\wordsmith\Utillities\JsonResponse
  • nk2580\wordsmith\Utillities\NavWalkers\Bootstrap
  • nk2580\wordsmith\Utillities\PDF
  1 <?php
  2 
  3 /*
  4  * CLASS BASED ON:
  5  * Class Name: wp_bootstrap_navwalker
  6  * GitHub URI: https://github.com/twittem/wp-bootstrap-navwalker
  7  */
  8 
  9 namespace nk2580\wordsmith\Utillities\NavWalkers;
 10 
 11 /**
 12  * Description of Cypher
 13  *
 14  * @author accounts
 15  */
 16 class Bootstrap extends \Walker_Nav_Menu {
 17 
 18     /**
 19      * @see Walker::start_lvl()
 20      * @since 3.0.0
 21      *
 22      * @param string $output Passed by reference. Used to append additional content.
 23      * @param int $depth Depth of page. Used for padding.
 24      */
 25     public function start_lvl( &$output, $depth = 0, $args = array() ) {
 26         $indent = str_repeat( "\t", $depth );
 27         $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n";
 28     }
 29 
 30     /**
 31      * @see Walker::start_el()
 32      * @since 3.0.0
 33      *
 34      * @param string $output Passed by reference. Used to append additional content.
 35      * @param object $item Menu item data object.
 36      * @param int $depth Depth of menu item. Used for padding.
 37      * @param int $current_page Menu item ID.
 38      * @param object $args
 39      */
 40     public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
 41         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
 42 
 43         /**
 44          * Dividers, Headers or Disabled
 45          * =============================
 46          * Determine whether the item is a Divider, Header, Disabled or regular
 47          * menu item. To prevent errors we use the strcasecmp() function to so a
 48          * comparison that is not case sensitive. The strcasecmp() function returns
 49          * a 0 if the strings are equal.
 50          */
 51         if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) {
 52             $output .= $indent . '<li role="presentation" class="divider">';
 53         } else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) {
 54             $output .= $indent . '<li role="presentation" class="divider">';
 55         } else if ( strcasecmp( $item->attr_title, 'dropdown-header') == 0 && $depth === 1 ) {
 56             $output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title );
 57         } else if ( strcasecmp($item->attr_title, 'disabled' ) == 0 ) {
 58             $output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>';
 59         } else {
 60 
 61             $class_names = $value = '';
 62 
 63             $classes = empty( $item->classes ) ? array() : (array) $item->classes;
 64             $classes[] = 'menu-item-' . $item->ID;
 65 
 66             $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
 67 
 68             if ( $args->has_children )
 69                 $class_names .= ' dropdown';
 70 
 71             if ( in_array( 'current-menu-item', $classes ) )
 72                 $class_names .= ' active';
 73 
 74             $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
 75 
 76             $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
 77             $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
 78 
 79             $output .= $indent . '<li' . $id . $value . $class_names .'>';
 80 
 81             $atts = array();
 82             $atts['title']  = ! empty( $item->title )   ? $item->title  : '';
 83             $atts['target'] = ! empty( $item->target )  ? $item->target : '';
 84             $atts['rel']    = ! empty( $item->xfn )     ? $item->xfn    : '';
 85 
 86             // If item has_children add atts to a.
 87             if ( $args->has_children && $depth === 0 ) {
 88                 $atts['href']           = '#';
 89                 $atts['data-toggle']    = 'dropdown';
 90                 $atts['class']          = 'dropdown-toggle';
 91                 $atts['aria-haspopup']  = 'true';
 92             } else {
 93                 $atts['href'] = ! empty( $item->url ) ? $item->url : '';
 94             }
 95 
 96             $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
 97 
 98             $attributes = '';
 99             foreach ( $atts as $attr => $value ) {
100                 if ( ! empty( $value ) ) {
101                     $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
102                     $attributes .= ' ' . $attr . '="' . $value . '"';
103                 }
104             }
105 
106             $item_output = $args->before;
107 
108             /*
109              * Glyphicons
110              * ===========
111              * Since the the menu item is NOT a Divider or Header we check the see
112              * if there is a value in the attr_title property. If the attr_title
113              * property is NOT null we apply it as the class name for the glyphicon.
114              */
115             if ( ! empty( $item->attr_title ) )
116                 $item_output .= '<a'. $attributes .'><span class="glyphicon ' . esc_attr( $item->attr_title ) . '"></span>&nbsp;';
117             else
118                 $item_output .= '<a'. $attributes .'>';
119 
120             $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
121             $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>';
122             $item_output .= $args->after;
123 
124             $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
125         }
126     }
127 
128     /**
129      * Traverse elements to create list from elements.
130      *
131      * Display one element if the element doesn't have any children otherwise,
132      * display the element and its children. Will only traverse up to the max
133      * depth and no ignore elements under that depth.
134      *
135      * This method shouldn't be called directly, use the walk() method instead.
136      *
137      * @see Walker::start_el()
138      * @since 2.5.0
139      *
140      * @param object $element Data object
141      * @param array $children_elements List of elements to continue traversing.
142      * @param int $max_depth Max depth to traverse.
143      * @param int $depth Depth of current element.
144      * @param array $args
145      * @param string $output Passed by reference. Used to append additional content.
146      * @return null Null on failure with no changes to parameters.
147      */
148     public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
149         if ( ! $element )
150             return;
151 
152         $id_field = $this->db_fields['id'];
153 
154         // Display this element.
155         if ( is_object( $args[0] ) )
156            $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] );
157 
158         parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
159     }
160 
161     /**
162      * Menu Fallback
163      * =============
164      * If this function is assigned to the wp_nav_menu's fallback_cb variable
165      * and a manu has not been assigned to the theme location in the WordPress
166      * menu manager the function with display nothing to a non-logged in user,
167      * and will add a link to the WordPress menu manager if logged in as an admin.
168      *
169      * @param array $args passed from the wp_nav_menu function.
170      *
171      */
172     public static function fallback( $args ) {
173         if ( current_user_can( 'manage_options' ) ) {
174 
175             extract( $args );
176 
177             $fb_output = null;
178 
179             if ( $container ) {
180                 $fb_output = '<' . $container;
181 
182                 if ( $container_id )
183                     $fb_output .= ' id="' . $container_id . '"';
184 
185                 if ( $container_class )
186                     $fb_output .= ' class="' . $container_class . '"';
187 
188                 $fb_output .= '>';
189             }
190 
191             $fb_output .= '<ul';
192 
193             if ( $menu_id )
194                 $fb_output .= ' id="' . $menu_id . '"';
195 
196             if ( $menu_class )
197                 $fb_output .= ' class="' . $menu_class . '"';
198 
199             $fb_output .= '>';
200             $fb_output .= '<li><a href="' . admin_url( 'nav-menus.php' ) . '">Add a menu</a></li>';
201             $fb_output .= '</ul>';
202 
203             if ( $container )
204                 $fb_output .= '</' . $container . '>';
205 
206             echo $fb_output;
207         }
208     }
209 
210 }
211 
API documentation generated by ApiGen