Changeset 13406
- Timestamp:
- 02/25/2010 09:06:44 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/nav-menus.php
r13402 r13406 57 57 // Default Menu to show 58 58 $custom_menus = wp_get_nav_menus(); 59 60 if ( empty($custom_menus) && empty($_POST) ) { 61 wp_create_default_nav_menu(); 62 $custom_menus = wp_get_nav_menus(); 63 } 64 59 65 if ( ! $menu_selected_id && ! empty( $custom_menus ) ) 60 66 $menu_selected_id = $custom_menus[0]->term_id; -
trunk/wp-includes/nav-menu.php
r13397 r13406 22 22 } 23 23 24 function wp_create_nav_menu( $menu_name ) {24 function wp_create_nav_menu( $menu_name, $args = array() ) { 25 25 $menu_exists = get_term_by( 'name', $menu_name, 'nav_menu' ); 26 26 … … 28 28 return new WP_Error('menu_exists', sprintf( __('A menu named “%s” already exists; please try another name.'), esc_html( $menu_exists->name ) ) ); 29 29 30 $menu = wp_insert_term( $menu_name, 'nav_menu' ); 30 if ( isset($args['slug']) ) 31 $slug = $args['slug']; 32 else 33 $slug = $menu_name; 34 35 $menu = wp_insert_term( $menu_name, 'nav_menu', array('slug' => $slug) ); 36 31 37 if ( is_wp_error($menu) ) 32 38 return $menu; 33 39 34 40 return get_term( $menu['term_id'], 'nav_menu'); 41 } 42 43 function wp_create_default_nav_menu() { 44 $menu = wp_create_nav_menu(__('Main'), array('slug' => 'main')); 45 46 if ( is_wp_error($menu) ) 47 return; 48 49 $pages = get_pages( array('parent' => 0, 'number' => 15) ); 50 $counter = 1; 51 foreach ( $pages as $page ) { 52 $item = array('post_status' => 'publish', 'post_type' => 'nav_menu_item', 'menu_order' => $counter, 'tax_input' => array( 'nav_menu' => $menu->name), 'post_title' => addslashes($page->post_title) ); 53 $item_id = wp_insert_post($item, true); 54 update_post_meta( $item_id, 'menu_type', 'page' ); 55 update_post_meta( $item_id, 'object_id', $page->ID ); 56 update_post_meta( $item_id, 'menu_new_window', 0 ); 57 $counter++; 58 } 35 59 } 36 60
Note: See TracChangeset
for help on using the changeset viewer.