Changeset 19230 for trunk/wp-includes/class-wp-admin-bar.php
- Timestamp:
- 11/09/2011 07:12:48 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-admin-bar.php
r19207 r19230 13 13 14 14 $this->user = new stdClass; 15 $this->root = new stdClass; 16 $this->root->children = (object) array( 17 'primary' => array(), 18 'secondary' => array(), 19 ); 15 20 16 21 if ( is_user_logged_in() ) { … … 60 65 * 61 66 * @param array $args - The arguments for each node. 62 * - id - string - The ID of the item. 63 * - title - string - The title of the node. 64 * - parent - string - The ID of the parent node. Optional. 65 * - href - string - The link for the item. Optional. 66 * - meta - array - Meta data including the following keys: html, class, onclick, target, title. 67 * - id - string - The ID of the item. 68 * - title - string - The title of the node. 69 * - parent - string - The ID of the parent node. Optional. 70 * - href - string - The link for the item. Optional. 71 * - secondary - boolean - If the item should be part of a secondary menu. Optional. Default false. 72 * - meta - array - Meta data including the following keys: html, class, onclick, target, title. 67 73 */ 68 74 public function add_node( $args ) { … … 81 87 82 88 $defaults = array( 83 'id' => false, 84 'title' => false, 85 'parent' => false, 86 'href' => false, 87 'meta' => array(), 89 'id' => false, 90 'title' => false, 91 'parent' => false, 92 'href' => false, 93 'secondary' => false, 94 'meta' => array(), 88 95 ); 89 96 … … 93 100 94 101 $args = wp_parse_args( $args, $defaults ); 102 $args['children'] = (object) array( 103 'primary' => array(), 104 'secondary' => array(), 105 ); 95 106 96 107 $this->nodes[ $args['id'] ] = (object) $args; … … 107 118 // Handle root menu items 108 119 if ( empty( $node->parent ) ) { 109 $this->root[] = $node; 120 $parent = $this->root; 121 122 // If the parent node isn't registered, ignore the node. 123 } elseif ( ! isset( $this->nodes[ $node->parent ] ) ) { 110 124 continue; 125 126 } else { 127 $parent = $this->nodes[ $node->parent ]; 111 128 } 112 129 113 // If the parent node isn't registered, ignore the node. 114 if ( ! isset( $this->nodes[ $node->parent ] ) ) 115 continue; 116 117 $parent = $this->nodes[ $node->parent ]; 118 if ( ! isset( $parent->children ) ) 119 $parent->children = array(); 120 121 $parent->children[] = $node; 130 if ( $node->secondary ) 131 $parent->children->secondary[] = $node; 132 else 133 $parent->children->primary[] = $node; 122 134 } 123 135 … … 127 139 <ul class="ab-top-menu"><?php 128 140 129 foreach ( $this->root as $node ) {141 foreach ( $this->root->children->primary as $node ) { 130 142 $this->recursive_render( $node ); 131 143 } 132 144 145 if ( ! empty( $this->root->children->secondary ) ): 146 ?><ul class="top-secondary"><?php 147 148 foreach ( $this->root->children->secondary as $node ) { 149 $this->recursive_render( $node ); 150 } 151 152 ?></ul><?php 153 endif; 133 154 ?></ul> 134 155 </div> … … 139 160 140 161 function recursive_render( $node ) { 141 $is_parent = ! empty( $node->children );162 $is_parent = ! empty( $node->children->primary ); 142 163 143 164 $menuclass = $is_parent ? 'menupop' : ''; … … 174 195 ?></a> 175 196 176 <?php if ( $is_parent ) : ?> 177 <ul><?php 178 179 // Render children. 180 foreach ( $node->children as $child_node ) { 197 <?php 198 if ( $is_parent ) : 199 ?><ul><?php 200 foreach ( $node->children->primary as $child_node ) { 181 201 $this->recursive_render( $child_node ); 182 202 } 183 203 184 ?></ul> 185 <?php endif; 204 if ( ! empty( $node->children->secondary ) ): 205 ?><ul class="sub-secondary"><?php 206 foreach ( $node->children->secondary as $child_node ) { 207 $this->recursive_render( $child_node ); 208 } 209 ?></ul><?php 210 endif; 211 ?></ul><?php 212 endif; 186 213 187 214 if ( ! empty( $node->meta['html'] ) )
Note: See TracChangeset
for help on using the changeset viewer.