Changeset 13802 for trunk/wp-admin/includes/nav-menu.php
- Timestamp:
- 03/22/2010 07:56:16 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/nav-menu.php
r13739 r13802 1 1 <?php 2 3 /* Register Metaboxes */ 4 add_meta_box( 'create-menu', __('Create Menu'), 'wp_nav_menu_create_metabox', 'menus', 'side', 'core' ); 5 add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_metabox', 'menus', 'side', 'default' ); 6 wp_nav_menu_post_type_metaboxes(); 7 wp_nav_menu_taxonomy_metaboxes(); 2 /** 3 * Register nav menu metaboxes 4 * 5 * @since 3.0.0 6 **/ 7 function wp_nav_menu_metaboxes_setup() { 8 add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_metabox', 'nav-menus', 'side', 'default' ); 9 wp_nav_menu_post_type_metaboxes(); 10 wp_nav_menu_taxonomy_metaboxes(); 11 } 12 13 /** 14 * Limit the amount of meta boxes to just links, pages and cats for first time users. 15 * 16 * @since 3.0.0 17 **/ 18 function wp_initial_nav_menu_meta_boxes() { 19 global $wp_meta_boxes; 20 21 if ( !get_user_option( 'meta-box-hidden_nav-menus' ) && is_array($wp_meta_boxes) ) { 22 23 $initial_meta_boxes = array( 'manage-menu', 'create-menu', 'add-custom-links', 'add-page', 'add-category' ); 24 $hidden_meta_boxes = array(); 25 26 foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) { 27 foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) { 28 foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) { 29 if ( in_array( $box['id'], $initial_meta_boxes ) ) { 30 unset( $box['id'] ); 31 } else { 32 $hidden_meta_boxes[] = $box['id']; 33 } 34 } 35 } 36 } 37 $user = wp_get_current_user(); 38 update_user_meta( $user->ID, 'meta-box-hidden_nav-menus', $hidden_meta_boxes ); 39 40 // returns all the hidden metaboxes to the js function: wpNavMenu.initial_meta_boxes() 41 return join( ',', $hidden_meta_boxes ); 42 } 43 } 8 44 9 45 /** … … 16 52 17 53 if ( !$post_types ) 18 return false; 19 20 $allowed_types = apply_filters('post_types_allowed_in_menus', array('page')); 54 return; 55 21 56 foreach ( $post_types as $post_type ) { 22 if ( !in_array($post_type->name, $allowed_types) )23 continue;24 57 $id = $post_type->name; 25 26 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'menus', 'side', 'default', $post_type ); 58 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type ); 27 59 } 28 60 } … … 37 69 38 70 if ( !$taxonomies ) 39 return false; 40 41 $allowed_types = apply_filters('taxonomies_allowed_in_menus', array('category')); 71 return; 72 42 73 foreach ( $taxonomies as $tax ) { 43 if ( !in_array($tax->name, $allowed_types) )44 continue;45 74 $id = $tax->name; 46 75 47 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', ' menus', 'side', 'default', $tax );76 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax ); 48 77 } 49 78 } … … 99 128 */ 100 129 function wp_nav_menu_item_link_metabox() { 101 $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom', 'showposts' => -1 ); 130 // @note: hacky query, see #12660 131 $args = array( 'post_type' => 'nav_menu_item', 'post_status' => 'any', 'meta_key' => '_menu_item_type', 'numberposts' => -1, 'orderby' => 'title', ); 102 132 103 133 // @todo transient caching of these results with proper invalidation on updating links 104 $query = new WP_Query( $args ); 105 134 $links = get_posts( $args ); 106 135 ?> 107 136 <p id="menu-item-url-wrap"> … … 111 140 </label> 112 141 </p> 113 <br class="clear" />114 142 <p id="menu-item-name-wrap"> 115 143 <label class="howto" for="custom-menu-item-name"> … … 120 148 121 149 <p class="button-controls"> 122 <a class="show-all"><?php _e('View All'); ?></a> 123 <a class="hide-all"><?php _e('Hide All'); ?></a> 150 <span class="lists-controls"> 151 <a class="show-all"><?php _e('View All'); ?></a> 152 <a class="hide-all"><?php _e('Hide All'); ?></a> 153 </span> 154 155 <span class="add-to-menu"> 156 <a class="button"><?php _e('Add to Menu'); ?></a> 157 </span> 124 158 </p> 125 159 <div id="available-links" class="list-wrap"> 126 160 <div class="list-container"> 127 161 <ul class="list"> 128 <?php echo wp_nav_menu_get_items( $ query->posts, 'custom' ); ?>162 <?php echo wp_nav_menu_get_items( $links, 'custom', 'custom' ); ?> 129 163 </ul> 130 164 </div><!-- /.list-container--> 131 165 </div><!-- /#available-links--> 132 <p class="add-to-menu">133 <a class="button"><?php _e('Add to Menu'); ?></a>134 </p>135 166 <div class="clear"></div> 136 167 <?php … … 146 177 */ 147 178 function wp_nav_menu_item_post_type_metabox( $object, $post_type ) { 148 $args = array( 'post_type' => $post_type['args']->name, 'post_status' => 'publish', 'showposts' => -1 ); 149 150 if ( 'attachment' == $post_type['args']->name ) 151 $args['post_status'] = 'any'; 179 $args = array( 'post_type' => $post_type['args']->name, 'numberposts' => -1, 'orderby' => 'title', ); 152 180 153 181 // @todo transient caching of these results with proper invalidation on updating of a post of this type 154 $ query = new WP_Query( $args );155 156 if ( !$ query->posts )182 $posts = get_posts( $args ); 183 184 if ( !$posts ) 157 185 $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>'; 158 186 159 187 $pt_names = ''; 160 if ( is_array($ query->posts) ) {161 foreach ( $ query->posts as $post ) {188 if ( is_array($posts) ) { 189 foreach ( $posts as $post ) { 162 190 if ( $post->post_title ) { 163 191 $pt_names .= htmlentities( $post->post_title ) .'|'; 164 } else {165 $pt_names = sprintf( __('No %s exists'), $post_type['args']->label );166 192 } 167 193 } … … 176 202 177 203 <p class="button-controls"> 178 <a class="show-all"><?php _e('View All'); ?></a> 179 <a class="hide-all"><?php _e('Hide All'); ?></a> 204 <span class="lists-controls"> 205 <a class="show-all"><?php _e('View All'); ?></a> 206 <a class="hide-all"><?php _e('Hide All'); ?></a> 207 </span> 208 209 <span class="add-to-menu"> 210 <a class="button"><?php _e('Add to Menu'); ?></a> 211 </span> 180 212 </p> 181 213 … … 183 215 <div class="list-container"> 184 216 <ul class="list"> 185 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $ query->posts, 'post_type', $id ); ?>217 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $posts, 'post_type', $id ); ?> 186 218 </ul> 187 219 </div><!-- /.list-container--> 188 220 </div><!-- /#existing-categories--> 189 <p class="add-to-menu">190 <a class="button-secondary"><?php _e('Add to Menu'); ?></a>191 </p>192 221 <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr( $id ); ?>-names" value="<?php echo esc_js( $pt_names ); ?>" /> 193 222 <br class="clear" /> … … 195 224 // <![CDATA[ 196 225 jQuery(document).ready(function(){ 197 wp _nav_menu_autocomplete('<?php echo esc_attr($id); ?>');226 wpNavMenu.autocomplete('<?php echo esc_attr($id); ?>'); 198 227 }); 199 228 // ]]> … … 228 257 if ( $term->name ) { 229 258 $term_names .= htmlentities( $term->name ) .'|'; 230 } else {231 $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label );232 259 } 233 260 } … … 242 269 243 270 <p class="button-controls"> 244 <a class="show-all"><?php _e('View All'); ?></a> 245 <a class="hide-all"><?php _e('Hide All'); ?></a> 271 <span class="lists-controls"> 272 <a class="show-all"><?php _e('View All'); ?></a> 273 <a class="hide-all"><?php _e('Hide All'); ?></a> 274 </span> 275 276 <span class="add-to-menu"> 277 <a class="button"><?php _e('Add to Menu'); ?></a> 278 </span> 246 279 </p> 247 280 … … 253 286 </div><!-- /.list-container--> 254 287 </div><!-- /#existing-categories--> 255 <p class="add-to-menu">256 <a class="button-secondary"><?php _e('Add to Menu'); ?></a>257 </p>258 288 <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr($id); ?>-names" value="<?php echo esc_js( $term_names ); ?>" /> 259 289 <br class="clear" /> … … 261 291 // <![CDATA[ 262 292 jQuery(document).ready(function(){ 263 wp _nav_menu_autocomplete('<?php echo esc_attr($id); ?>');293 wpNavMenu.autocomplete('<?php echo esc_attr($id); ?>'); 264 294 }); 265 295 // ]]> … … 291 321 $menu_item->post_parent = $menu_item->parent; 292 322 293 // Cleanest way to get all attachements294 if ( 'attachment' == $object)323 // Get all attachements and links 324 if ( in_array($object, array( 'attachment', 'custom' )) ) 295 325 $menu_item->post_parent = 0; 296 326 … … 298 328 // Set up the menu item 299 329 $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object ); 330 331 // No blank titles 332 if ( empty($menu_item->title) ) 333 continue; 334 300 335 $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : ''; 301 336 302 337 $output .= '<li'. $attributes .'>'; 303 338 $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
Note: See TracChangeset
for help on using the changeset viewer.