Changeset 13704
- Timestamp:
- 03/15/2010 04:26:46 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/css/nav-menu.css
r13512 r13704 1 #menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{ color:#f00;text-decoration:underline;font-size:11px;float:left;margin-top:5px;}.submitdelete:hover{background-color:#F00;color:#fff;}.save{float:right;}.button-controls{float:left;}.add-to-menu{float:right;}#create-menu-name{width:159px;}#available-links{margin:15px 0 0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}#menu-item-url,#menu-item-name{float:right;width:220px;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .item-title{cursor:pointer;display:block;}.list li .item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .item-title{margin-left:14px;}.list li ul li ul li .item-title{margin-left:28px;}.list li ul li ul li ul li .item-title{margin-left:42px;}.list li ul li ul li ul li ul li .item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl dt{-webkit-border-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li dl dt:hover{cursor:move;}.menu li .item-title{background:url(../images/ico-arrow.png) no-repeat 4px 5px;background-position:center left;padding-left:15px;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}.hide{display:none;}1 #menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{font-size:11px;}#cancel-save{color:#f00;text-decoration:underline;font-size:11px;margin-left:20px;margin-top:5px;}#cancel-save:hover{background-color:#F00;color:#fff;}.button-controls{float:left;}.add-to-menu{float:right;}#manage-menu .inside{padding:0;}#create-menu-name{width:159px;}#available-links{margin:15px 0 0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}.menu-item-textbox{float:right;width:220px;}.howto span{margin-top:4px;display:block;float:left;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .menu-item-title{cursor:pointer;display:block;}.list li .menu-item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .menu-item-title{margin-left:14px;}.list li ul li ul li .menu-item-title{margin-left:28px;}.list li ul li ul li ul li .menu-item-title{margin-left:42px;}.list li ul li ul li ul li ul li .menu-item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .menu-item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl dt{-webkit-border-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li dl dt:hover{cursor:move;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .menu-item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;} -
trunk/wp-admin/css/nav-menu.dev.css
r13543 r13704 15 15 /* Button Primary Actions */ 16 16 #menu-container .submit { margin: 0px 0px 10px; padding: 0px; } 17 .submitdelete { color: #ff0000; text-decoration: underline; font-size: 11px; float: left; margin-top: 5px; } 18 .submitdelete:hover { background-color: #FF0000; color: #fff; } 19 .save { float: right; } 17 18 .submitdelete { font-size: 11px; } 19 #cancel-save { color: #ff0000; text-decoration: underline; font-size: 11px; margin-left: 20px; margin-top: 5px; } 20 #cancel-save:hover { background-color: #FF0000; color: #fff; } 20 21 21 22 /* Button Secondary Actions */ … … 23 24 .add-to-menu { float: right; } 24 25 25 /* CSS for switching the main columns *//* 26 #menu-settings-column { clear: none; float: left; } 27 #menu-management #post-body { float: right; margin-left: -340px; margin-right: 0px; } 28 #menu-management #post-body-content { margin-left: 300px; margin-right: 0px; } 29 */ 26 #manage-menu .inside { padding: 0px 0px; } 30 27 31 28 /* Create Menu */ … … 37 34 #add-custom-link .howto { font-size: 11px; } 38 35 #add-custom-link label span { display: block; float: left; margin-top: 5px; padding-right: 5px; } 39 #menu-item-url, #menu-item-name { float: right; width: 220px; } 36 .menu-item-textbox { float: right; width: 220px; } 37 .howto span { margin-top: 4px; display: block; float: left; } 40 38 41 39 /* Pages/Categories */ … … 51 49 .list li { display: none; margin: 0; margin-bottom: 5px; } 52 50 53 .list li . item-title { cursor: pointer; display: block; }54 .list li . item-title input { margin-right: 3px; margin-top: -3px; }51 .list li .menu-item-title { cursor: pointer; display: block; } 52 .list li .menu-item-title input { margin-right: 3px; margin-top: -3px; } 55 53 56 .list li ul li . item-title { margin-left: 14px; }57 .list li ul li ul li . item-title { margin-left: 28px; }58 .list li ul li ul li ul li . item-title { margin-left: 42px; }59 .list li ul li ul li ul li ul li . item-title { margin-left: 56px; }60 .list li ul li ul li ul li ul li ul li . item-title { margin-left: 70px; }61 .list li ul li ul li ul li ul li ul li ul li . item-title { margin-left: 84px; }62 .list li ul li ul li ul li ul li ul li ul li ul li . item-title { margin-left: 98px; }63 .list li ul li ul li ul li ul li ul li ul li ul li ul li . item-title { margin-left: 112px; }54 .list li ul li .menu-item-title { margin-left: 14px; } 55 .list li ul li ul li .menu-item-title { margin-left: 28px; } 56 .list li ul li ul li ul li .menu-item-title { margin-left: 42px; } 57 .list li ul li ul li ul li ul li .menu-item-title { margin-left: 56px; } 58 .list li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 70px; } 59 .list li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 84px; } 60 .list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 98px; } 61 .list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 112px; } 64 62 65 63 /* Menu */ … … 72 70 73 71 .menu li .item-title { } 74 .menu li ul li { margin-left: 20px; opacity: .7; }75 .menu li ul li ul li { opacity: .9; }76 .menu li ul li ul li ul li { opacity: .9; }72 .menu li ul li { margin-left: 20px; opacity: .7; } 73 .menu li ul li ul li { opacity: .9; } 74 .menu li ul li ul li ul li { opacity: .9; } 77 75 .menu li ul li ul li ul li ul li { opacity: .95; } 78 76 … … 86 84 .item-controls a { text-decoration: none; } 87 85 .item-controls a:hover { cursor: pointer; } 88 .item-controls . item-delete:hover { color: #ff0000; }86 .item-controls .menu-item-delete:hover { color: #ff0000; } 89 87 90 88 /* Thickbox */ … … 96 94 #update-menu-item:active, 97 95 #update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; } 98 99 /* Misc */100 .hide { display: none; } -
trunk/wp-admin/includes/nav-menu.php
r13512 r13704 1 1 <?php 2 2 3 /** 4 * Displays a list of links and thier sub items. 5 * 6 * @since 3.0.0 7 * 8 * @param string $counter 9 * @param string $context 10 */ 11 function wp_nav_menu_get_custom_links( $counter, $context ) { 12 $available_links = new WP_Query( ); 13 14 $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' ); 15 $link_objects = new WP_Query( $args ); 16 17 $items_counter = $counter; 18 19 if ( !$link_objects->posts ) { 20 _e('Not Found'); 21 return $items_counter; 22 } 23 24 // Display Loop 25 foreach ( $link_objects->posts as $item ) { 26 if ( 0 == $item->parent ) { 27 $item = wp_setup_nav_menu_item( $item, 'item', $items_counter ); 28 29 switch ( $context ) { 30 case 'menu': 31 ?> 32 <li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>"> 33 <?php 34 echo wp_get_nav_menu_item( $item, 'menu' ); 35 $parentli = $item->ID; 36 $items_counter++; 37 $items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'menu' ); 38 ?> 39 </li> 40 <?php 41 break; 42 43 case 'default': 44 ?> 45 <li> 46 <?php 47 echo wp_get_nav_menu_item( $item, 'default' ); 48 $parentli = $item->ID; 49 $items_counter++; 50 $items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' ); 51 ?> 52 </li> 53 <?php 54 break; 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(); 8 9 /** 10 * Creates metaboxes for any post type menu item. 11 * 12 * @since 3.0.0 13 */ 14 function wp_nav_menu_post_type_metaboxes() { 15 $post_types = get_post_types( array( 'public' => true ), 'object' ); 16 17 if ( !$post_types ) 18 return false; 19 20 foreach ( $post_types as $post_type ) { 21 $id = sanitize_title_with_dashes( $post_type->label ); 22 23 // delete_transient( "nav_menu_items_{$post_type->name}" ); 24 // delete_transient( "nav_menu_sub_items_{$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 ); 27 } 28 } 29 30 /** 31 * Creates metaboxes for any taxonomy menu item. 32 * 33 * @since 3.0.0 34 */ 35 function wp_nav_menu_taxonomy_metaboxes() { 36 $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' ); 37 38 if ( !$taxonomies ) 39 return false; 40 41 foreach ( $taxonomies as $tax ) { 42 $id = sanitize_title_with_dashes( $tax->label ); 43 44 // delete_transient( "nav_menu_items_{$tax->name}" ); 45 // delete_transient( "nav_menu_sub_items_{$tax->name}" ); 46 47 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'menus', 'side', 'default', $tax ); 48 } 49 } 50 51 /** 52 * Displays a metabox for managing the active menu being edited. 53 * 54 * @since 3.0.0 55 */ 56 function wp_nav_menu_manage_menu_metabox( $object, $menu ) { ?> 57 <div id="submitpost" class="submitbox"> 58 <div id="minor-publishing"> 59 <div class="misc-pub-section misc-pub-section-last"> 60 <label class="howto" for="menu-name"> 61 <span><?php _e('Name'); ?></span> 62 <input id="menu-name" name="menu-name" type="text" class="regular-text menu-item-textbox" value="<?php esc_attr_e( $menu['args'][1] ); ?>" /> 63 <br class="clear" /> 64 </label> 65 </div><!--END .misc-pub-section misc-pub-section-last--> 66 <br class="clear" /> 67 </div><!--END #misc-publishing-actions--> 68 <div id="major-publishing-actions"> 69 <div id="delete-action"> 70 <a class="submitdelete deletion" href="<?php echo wp_nonce_url( admin_url('nav-menus.php?action=delete&menu=' . $menu['args'][0]), 'delete-nav_menu-' . $menu['args'][0] ); ?>"><?php _e('Delete Menu'); ?></a> 71 </div><!--END #delete-action--> 72 73 <div id="publishing-action"> 74 <input class="button-primary" name="save_menu" type="submit" value="<?php esc_attr_e('Save Menu'); ?>" /> 75 </div><!--END #publishing-action--> 76 <br class="clear" /> 77 </div><!--END #major-publishing-actions--> 78 </div><!--END #submitpost .submitbox--> 79 <?php 80 } 81 82 /** 83 * Displays a metabox for creating a new menu. 84 * 85 * @since 3.0.0 86 */ 87 function wp_nav_menu_create_metabox() { ?> 88 <p> 89 <input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value="" /> 90 <input type="submit" name="create-menu" id="create-menu" class="button" value="<?php esc_attr_e('Create Menu'); ?>" /> 91 </p> 92 <?php 93 } 94 95 /** 96 * Displays a metabox for the custom links menu item. 97 * 98 * @since 3.0.0 99 */ 100 function wp_nav_menu_item_link_metabox() { 101 $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' ); 102 103 // Cache the query for a day. @todo: Make sure to flush transient when links are updated. 104 $query = get_transient( 'menu_item_query_custom_links' ); 105 if ( false == $query ) { 106 $query = new WP_Query( $args ); 107 set_transient( 'menu_item_query_custom_links', $query, 86400 ); 108 } 109 110 ?> 111 <p id="menu-item-url-wrap"> 112 <label class="howto" for="menu-item-url"> 113 <span><?php _e('URL'); ?></span> 114 <input id="custom-menu-item-url" name="custom-menu-item-url" type="text" class="code menu-item-textbox" value="http://" /> 115 </label> 116 </p> 117 <br class="clear" /> 118 <p id="menu-item-name-wrap"> 119 <label class="howto" for="custom-menu-item-name"> 120 <span><?php _e('Text'); ?></span> 121 <input id="custom-menu-item-name" name="custom-menu-item-name" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( __('Menu Item') ); ?>" /> 122 </label> 123 </p> 124 125 <p class="button-controls"> 126 <a class="show-all"><?php _e('View All'); ?></a> 127 <a class="hide-all"><?php _e('Hide All'); ?></a> 128 </p> 129 <div id="available-links" class="list-wrap"> 130 <div class="list-container"> 131 <ul class="list"> 132 <?php echo wp_nav_menu_get_items( $query->posts, 'custom' ); ?> 133 </ul> 134 </div><!-- /.list-container--> 135 </div><!-- /#available-links--> 136 <p class="add-to-menu"> 137 <a class="button"><?php _e('Add to Menu'); ?></a> 138 </p> 139 <div class="clear"></div> 140 <?php 141 } 142 143 /** 144 * Displays a metabox for a post type menu item. 145 * 146 * @since 3.0.0 147 * 148 * @param string $object Not used. 149 * @param string $post_type The post type object. 150 */ 151 function wp_nav_menu_item_post_type_metabox( $object, $post_type ) { 152 $args = array( 'post_type' => $post_type['args']->name, ); 153 154 if ( 'attachment' == $post_type['args']->name ) 155 $args['post_status'] = 'any'; 156 157 // Cache the query for a day. @todo: Make sure to flush transient when objects are updated. 158 $query = get_transient( "nav_menu_items_{$post_type['args']->name}" ); 159 if ( false == $query ) { 160 $query = new WP_Query( $args ); 161 set_transient( "nav_menu_items_{$post_type['args']->name}", $query, 86400 ); 162 } 163 164 if ( !$query->posts ) 165 $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>'; 166 167 $pt_names = ''; 168 if ( is_array($query->posts) ) { 169 foreach ( $query->posts as $post ) { 170 if ( $post->post_title ) { 171 $pt_names .= htmlentities( $post->post_title ) .'|'; 172 } else { 173 $pt_names = sprintf( __('No %s exists'), $post_type['args']->label ); 55 174 } 56 175 } 57 176 } 58 return $items_counter; 59 } 60 61 /** 62 * Displays a list of pages and thier sub items. 63 * 64 * @since 3.0.0 65 * 66 * @param string $counter 67 * @param string $context 68 */ 69 function wp_nav_menu_get_pages( $counter, $context ) { 70 $pages_args = array( 71 'child_of' => 0, 72 'sort_order' => 'ASC', 73 'sort_column' => 'post_title', 74 'hierarchical' => 1, 75 'exclude' => '', 76 'include' => '', 77 'meta_key' => '', 78 'meta_value' => '', 79 'authors' => '', 80 'parent' => -1, 81 'exclude_tree' => '', 82 'number' => '', 83 'offset' => 0 ); 84 85 // Get all pages 86 $pages_array = get_pages( $pages_args ); 87 88 $items_counter = $counter; 89 $parentli = $items_counter; 90 91 if ( !$pages_array ) { 92 echo __('Not Found'); 93 return $items_counter; 94 } 95 96 // Display Loop 97 foreach ( $pages_array as $post ) { 98 if ( $post->post_parent == 0 ) { 99 $post = wp_setup_nav_menu_item( $post, 'page', $items_counter ); 100 if ( $context == 'menu' ) { 101 ?> 102 <li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>"> 103 <?php 104 echo wp_get_nav_menu_item( $post, 'menu', $items_counter ); 105 $parentli = $post->ID; 106 $items_counter++; 107 $items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'menu' ); 108 ?> 109 </li> 110 <?php 111 } elseif ( $context == 'default' ) { 112 // Sidebar Menu 113 ?> 114 <li> 115 <?php 116 echo wp_get_nav_menu_item( $post, 'default' ); 117 $parentli = $post->ID; 118 $items_counter++; 119 $items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' ); 120 ?> 121 </li> 122 <?php 177 178 $id = sanitize_title_with_dashes( $post_type['args']->label ); 179 ?> 180 <p class="quick-search-wrap"> 181 <input type="text" class="quick-search regular-text" value="" /> 182 <a class="quick-search-submit button-secondary"><?php _e('Search'); ?></a> 183 </p> 184 185 <p class="button-controls"> 186 <a class="show-all"><?php _e('View All'); ?></a> 187 <a class="hide-all"><?php _e('Hide All'); ?></a> 188 </p> 189 190 <div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap"> 191 <div class="list-container"> 192 <ul class="list"> 193 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $query->posts, 'post_type', $post_type['args']->name ); ?> 194 </ul> 195 </div><!-- /.list-container--> 196 </div><!-- /#existing-categories--> 197 <p class="add-to-menu"> 198 <a class="button-secondary"><?php _e('Add to Menu'); ?></a> 199 </p> 200 <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr( $post_type['args']->name ); ?>-names" value="<?php echo esc_js( $pt_names ); ?>" /> 201 <br class="clear" /> 202 <script type="text/javascript" charset="utf-8"> 203 // <![CDATA[ 204 jQuery(document).ready(function(){ 205 wp_nav_menu_autocomplete('<?php echo esc_attr($id); ?>'); 206 }); 207 // ]]> 208 </script> 209 <?php 210 } 211 212 /** 213 * Displays a metabox for a taxonomy menu item. 214 * 215 * @since 3.0.0 216 * 217 * @param string $object Not used. 218 * @param string $taxonomy The taxonomy object. 219 */ 220 function wp_nav_menu_item_taxonomy_metabox( $object, $taxonomy ) { 221 $args = array( 222 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 223 'hide_empty' => false, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', 224 'include' => '', 'number' => '', 'pad_counts' => false 225 ); 226 227 // Cache the query for a day. @todo: Make sure to flush transient when terms are updated. 228 $terms = get_transient( "nav_menu_items_{$taxonomy['args']->name}" ); 229 if ( false == $terms ) { 230 $terms = get_terms( $taxonomy['args']->name, $args ); 231 set_transient( "nav_menu_items_{$taxonomy['args']->name}", $terms, 86400 ); 232 } 233 234 if ( !$terms ) 235 $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $taxonomy['args']->label ) .'</li>'; 236 237 $term_names = ''; 238 if ( is_array($terms) ) { 239 foreach ( $terms as $term ) { 240 if ( $term->name ) { 241 $term_names .= htmlentities( $term->name ) .'|'; 242 } else { 243 $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label ); 123 244 } 124 245 } 125 246 } 126 return $items_counter; 127 } 128 129 /** 130 * Displays a list of categories and thier sub items. 131 * 132 * @since 3.0.0 133 * 134 * @param string $counter 135 * @param string $context 136 */ 137 function wp_nav_menu_get_categories( $counter, $context ) { 138 $category_args = array( 139 'type' => 'post', 140 'child_of' => 0, 141 'orderby' => 'name', 142 'order' => 'ASC', 143 'hide_empty' => false, 144 'include_last_update_time' => false, 145 'hierarchical' => 1, 146 'exclude' => '', 147 'include' => '', 148 'number' => '', 149 'pad_counts' => false ); 150 151 $items_counter = $counter; 152 153 // Get all categories 154 $categories_array = get_categories( $category_args ); 155 156 if ( !$categories_array ) { 157 _e('Not Found'); 158 return $items_counter; 159 } 160 161 // Display Loop 162 foreach ( $categories_array as $cat_item ) { 163 if ( $cat_item->parent == 0 ) { 164 $cat_item = wp_setup_nav_menu_item( $cat_item, 'category', $items_counter ); 165 // Custom Menu 166 if ( $context == 'menu' ) { 167 ?> 168 <li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>"> 169 <?php 170 echo wp_get_nav_menu_item($cat_item, 'menu'); 171 $parentli = $cat_item->cat_ID; 172 $items_counter++; 173 $items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'menu' ); 174 ?> 175 </li> 176 <?php 177 } elseif ( $context == 'default' ) { 178 // Sidebar Menu 179 ?> 180 <li> 181 <?php 182 echo wp_get_nav_menu_item( $cat_item, 'default' ); 183 $parentli = $cat_item->cat_ID; 184 $items_counter++; 185 $items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' ); 186 ?> 187 </li> 188 <?php 247 248 $id = sanitize_title_with_dashes( $taxonomy['args']->label ); 249 ?> 250 <p class="quick-search-wrap"> 251 <input type="text" class="quick-search regular-text" value="" /> 252 <a class="quick-search-submit button-secondary"><?php _e('Search'); ?></a> 253 </p> 254 255 <p class="button-controls"> 256 <a class="show-all"><?php _e('View All'); ?></a> 257 <a class="hide-all"><?php _e('Hide All'); ?></a> 258 </p> 259 260 <div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap"> 261 <div class="list-container"> 262 <ul class="list"> 263 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $terms, 'taxonomy', $taxonomy['args']->name ); ?> 264 </ul> 265 </div><!-- /.list-container--> 266 </div><!-- /#existing-categories--> 267 <p class="add-to-menu"> 268 <a class="button-secondary"><?php _e('Add to Menu'); ?></a> 269 </p> 270 <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr($taxonomy['args']->name); ?>-names" value="<?php echo esc_js( $term_names ); ?>" /> 271 <br class="clear" /> 272 <script type="text/javascript" charset="utf-8"> 273 // <![CDATA[ 274 jQuery(document).ready(function(){ 275 wp_nav_menu_autocomplete('<?php echo esc_attr($id); ?>'); 276 }); 277 // ]]> 278 </script> 279 <?php 280 } 281 282 /** 283 * Abstract function for returning all menu items of a menu item type. 284 * 285 * @since 3.0.0 286 * 287 * @param string $menu_items Array of objects containing all menu items to be displayed. 288 * @param string $object_type Menu item type. 289 * @param string $object Optional. Menu item type name. 290 * @param string $context Optional. The context for how the menu items should be formatted. 291 * @return string $ouput Menu items. 292 */ 293 function wp_nav_menu_get_items( $menu_items, $object_type, $object = null, $context = 'frontend' ) { 294 if ( !$menu_items ) 295 return __( 'Not Found' ); 296 297 $output = ''; 298 $i = 1; 299 foreach ( $menu_items as $menu_item ) { 300 // convert the 'parent' taxonomy property to 'post_parent' 301 // so we don't have to duplicate this entire function. 302 if ( !isset($menu_item->post_parent) ) 303 $menu_item->post_parent = $menu_item->parent; 304 305 // Cleanest way to get all attachements 306 if ( 'attachment' == $object ) 307 $menu_item->post_parent = 0; 308 309 if ( 0 == $menu_item->post_parent ) { 310 // Setup the menu item 311 $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object ); 312 $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : ''; 313 314 $output .= '<li'. $attributes .'>'; 315 $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object ); 316 $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context ); 317 $output .= '</li>'; 318 319 ++$i; 320 } 321 } 322 323 return $output; 324 } 325 326 /** 327 * Recursive function to retrieve sub menu items. 328 * 329 * @since 3.0.0 330 * 331 * @param string $childof The Parent ID. 332 * @param string $object_type The object type. 333 * @param string $object The object name. 334 * @return string $output sub menu items. 335 */ 336 function wp_get_nav_menu_sub_items( $childof, $object_type, $object = null, $context = 'frontend' ) { 337 $args = array( 'child_of' => $childof, 'parent' => $childof, 'hide_empty' => false, ); 338 339 switch ( $object_type ) { 340 case 'post_type': 341 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); 342 if ( in_array( $object, $hierarchical_post_types ) ) { 343 $args['post_type'] = $object; 344 $sub_menu_items = get_pages( $args ); 345 } else { 346 $sub_menu_items = array(); 189 347 } 348 break; 349 350 case 'taxonomy': 351 if ( is_taxonomy_hierarchical( $object ) ) { 352 $sub_menu_items = get_terms( $object, $args ); 353 } else { 354 $sub_menu_items = array(); 355 } 356 break; 357 358 default: 359 $sub_menu_items = array(); 360 break; 361 } 362 363 $output = ''; 364 $i = 1; 365 if ( !empty($sub_menu_items) && !is_wp_error($sub_menu_items) ) { 366 $output .= '<ul class="sub-menu menu-item-type-'. $object_type .'">'; 367 foreach ( $sub_menu_items as $menu_item ) { 368 // Setup the menu item 369 $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object ); 370 $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : ''; 371 372 $output .= '<li'. $attributes .'>'; 373 $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object ); 374 $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object ); 375 $output .= '</li>'; 376 377 ++$i; 190 378 } 191 } 192 return $items_counter; 193 } 194 195 /** 196 * Recursive function that gets sub menu items. 197 * 198 * @since 3.0.0 199 * 200 * @param string $childof 201 * @param string $items_counter 202 * @param string $parentli 203 * @param string $context 204 * @param string $output_type 205 */ 206 function wp_nav_menu_sub_items( $childof, $items_counter, $parentli, $context, $output_type ) { 207 $counter = $items_counter; 208 209 // Custom Menu 210 if ( $output_type == 'menu' ) { 211 $sub_args = array( 212 'child_of' => $childof, 213 'hide_empty' => false, 214 'parent' => $childof); 215 } elseif ( $output_type == 'default' ) { 216 // Sidebar Menu 217 $sub_args = array( 218 'child_of' => $childof, 219 'hide_empty' => false, 220 'parent' => $childof); 221 } 222 223 if ( $context == 'categories' ) { 224 // Get Sub Category Items 225 $item_type = 'category'; 226 $sub_array = get_categories($sub_args); 227 } elseif ($context == 'pages') { 228 // Get Sub Page Items 229 $item_type = 'page'; 230 $sub_array = get_pages($sub_args); 231 } else { 232 $item_type = 'custom'; 233 $sub_array = array(); 234 } 235 236 if ( $sub_array ) { 237 ?> 238 <ul id="sub-menu-<?php echo $context ?>"> 239 <?php 240 // Display Loop 241 foreach ( $sub_array as $sub_item ) { 242 $sub_item = wp_setup_nav_menu_item( $sub_item, $item_type, $counter ); 243 if ( $output_type == 'menu' ) { 244 ?> 245 <li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>"> 246 <?php 247 echo wp_get_nav_menu_item( $sub_item, 'menu' ); 248 $counter++; 249 $counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'menu' ); 250 ?> 251 </li> 252 <?php 253 } elseif ( $output_type == 'default' ) { 254 // Sidebar Menu 255 ?> 256 <li> 257 <?php 258 echo wp_get_nav_menu_item( $sub_item, 'default' ); 259 //$counter++; 260 $counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'default' ); 261 ?> 262 </li> 263 264 <?php 265 } 266 } 267 ?> 268 </ul> 269 <?php 270 } 271 return $counter; 379 $output .= '</ul>'; 380 } 381 return $output; 272 382 } 273 383 ?> -
trunk/wp-admin/js/nav-menu-default-items.dev.js
r13685 r13704 16 16 wp_drag_and_drop(); 17 17 18 wp_update_post_data(); 18 // Delete AYS 19 $('#update-nav-menu .deletion').click(function(){ 20 if ( confirm( navMenuL10n.warnDelete ) ) { 21 return true; 22 } else { 23 return false; 24 }; 25 }); 19 26 20 27 // Handle Save Button Clicks … … 22 29 return wp_update_post_data(); 23 30 }); 24 31 32 // close postboxes that should be closed 33 $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); 34 35 // postboxes setup 36 postboxes.add_postbox_toggles('menus'); 37 25 38 // Clear the quick search textbox 26 39 $('.quick-search').click(function(){ … … 39 52 40 53 // Delete menu item 41 $('#menu-container .item-delete').live( 'click', function( ){54 $('#menu-container .item-delete').live( 'click', function(e){ 42 55 return wp_remove_menu_item( $(this).attr('value') ); 43 56 }); … … 46 59 $('#update-menu-item').click(function(){ 47 60 wp_update_menu_item(); 48 tb_remove(); 49 50 // Give feedback to the user 51 var id = $('#edit-item-id').val(); 52 $('#menu-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 61 return tb_remove(); 53 62 }); 54 63 … … 59 68 60 69 // Show All Button 61 $('.show-all').click(function(){ 62 $(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 10px;' ); 63 $(this).offsetParent().find('.list-wrap').css( 'display','block' ); 64 $(this).siblings('.quick-search').attr( 'value', '' ); 65 $(this).offsetParent().find('.list-wrap li').css( 'display', 'block' ); 66 $(this).hide(); 67 $(this).siblings('.hide-all').show(); 70 $('.show-all').click(function(e){ 71 jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'block' ); 72 jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'block' ); 73 jQuery(e.currentTarget).hide(); 74 jQuery(e.currentTarget).siblings('.hide-all').show(); 68 75 }); 69 76 70 77 // Hide All Button 71 $('.hide-all').click(function(){ 72 $(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 0px;' ); 73 $(this).offsetParent().find('.list-wrap').css( 'display','none' ); 74 $(this).siblings('.quick-search').attr( 'value', 'Search' ); 75 $(this).offsetParent().find('.list-wrap li').css( 'display', 'none' ); 76 $(this).hide(); 77 $(this).siblings('.show-all').show(); 78 $('.hide-all').click(function(e){ 79 jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'none' ); 80 jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'none' ); 81 jQuery(e.currentTarget).hide(); 82 jQuery(e.currentTarget).siblings('.show-all').show(); 78 83 }); 79 84 80 // Add menu item to queue 81 $('.list input').click(function(){ 82 83 var item_type = jQuery(this).parent().siblings('.item-type').val(); 84 var item_title = jQuery(this).parent().siblings('.item-title').val(); 85 var item_url = jQuery(this).parent().siblings('.item-url').val(); 86 var item_id = jQuery(this).parent().siblings('.item-dbid').val(); 87 var item_parent_id = jQuery(this).parent().siblings('.item-parent').val(); 88 var item_description = jQuery(this).parent().siblings('.item-description').val(); 89 90 return wp_update_queue( $(this), item_type, item_title, item_url, item_id, item_parent_id, item_description ); 85 // Add menu items into the menu 86 $('.add-to-menu').click(function(e){ 87 return wp_add_checked_items_to_menu(e.currentTarget); 91 88 }); 92 89 93 // Add queued menu items into the menu 94 $('.enqueue a').click(function(){ 95 return wp_add_queued_items_to_menu(this); 96 }); 97 98 // Create the link, add it to the menu + available links section 99 $('#add-custom-link .add-to-menu a').click(function(){ 100 var link_url = $(this).offsetParent().find('#menu-item-url').val(); 101 var link_name = $(this).offsetParent().find('#menu-item-name').val(); 90 // Create a new link then add it to the menu 91 $('#add-custom-links .add-to-menu a').click(function(e){ 92 var link_url = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-url').val(); 93 var link_name = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-name').val(); 102 94 103 wp_add_queued_items_to_menu( this ); 104 105 // Don't save the link if it was left with it's default settings 106 if ( 'http://' == link_url || 'Menu Item' == link_name ) 107 return; 108 109 // and update the Menu with the new link 110 wp_add_item_to_menu( 'custom', link_name, link_url, 0, 0, '' ); 95 // Add link to menu 96 wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_none', '', '' ); 111 97 }); 112 98 }); -
trunk/wp-admin/js/nav-menu-default-items.js
r13685 r13704 1 jQuery(document).ready(function(a){wp_drag_and_drop(); wp_update_post_data();a("#save_menu").click(function(){return wp_update_post_data()});a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();tb_remove();var b=a("#edit-item-id").val();a("#menu-"+b+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 10px;");a(this).offsetParent().find(".list-wrap").css("display","block");a(this).siblings(".quick-search").attr("value","");a(this).offsetParent().find(".list-wrap li").css("display","block");a(this).hide();a(this).siblings(".hide-all").show()});a(".hide-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 0px;");a(this).offsetParent().find(".list-wrap").css("display","none");a(this).siblings(".quick-search").attr("value","Search");a(this).offsetParent().find(".list-wrap li").css("display","none");a(this).hide();a(this).siblings(".show-all").show()});a(".list input").click(function(){var d=jQuery(this).parent().siblings(".item-type").val();var g=jQuery(this).parent().siblings(".item-title").val();var c=jQuery(this).parent().siblings(".item-url").val();var e=jQuery(this).parent().siblings(".item-dbid").val();var b=jQuery(this).parent().siblings(".item-parent").val();var f=jQuery(this).parent().siblings(".item-description").val();return wp_update_queue(a(this),d,g,c,e,b,f)});a(".enqueue a").click(function(){return wp_add_queued_items_to_menu(this)});a("#add-custom-link .add-to-menu a").click(function(){var b=a(this).offsetParent().find("#menu-item-url").val();var c=a(this).offsetParent().find("#menu-item-name").val();wp_add_queued_items_to_menu(this);if("http://"==b||"Menu Item"==c){return}wp_add_item_to_menu("custom",c,b,0,0,"")})});1 jQuery(document).ready(function(a){wp_drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#save_menu").click(function(){return wp_update_post_data()});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("menus");a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(b){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();return tb_remove()});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","block");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","block");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","none");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","none");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){return wp_add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(d){var b=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-url").val();var c=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-name").val();wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,c,b,"","","_none","","")})}); -
trunk/wp-admin/js/nav-menu-dynamic-functions.dev.js
r13512 r13704 9 9 */ 10 10 11 /** 12 * Adds a link to the available links section 13 * 14 * @param object e - An object recieved via ajax 15 */ 16 function wp_update_links_list(e) { 17 var link = '<li><dl><dt><label class="item-title"><input type="checkbox" id="link-'+ e.link_id +'" name="'+ e.link_name +'" value="'+ e.link_url +'" />'+ e.link_name +'</label></dt></dl></li>'; 18 19 // Prepend the link to the available links section 20 jQuery('#available-links .list').prepend( link ); 21 22 // Give feedback to the user 23 jQuery('#available-links .list #link-' + e.link_id).parent().animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 11 function wp_nav_menu_autocomplete( id ) { 12 jQuery('#add-'+ id +' .quick-search').autocomplete(jQuery( '#add-'+ id +' .autocomplete' ).val().split('|')); 13 14 jQuery('#add-'+ id +' .quick-search').result(function(event, data, formatted) { 15 jQuery('#add-'+ id +' .list-wrap').css( 'display', 'block' ); 16 jQuery("#add-"+ id +" .list-wrap li:contains('" + data + "')").css( 'display', 'block' ); 17 jQuery('#add-'+ id +' .show-all').hide(); 18 jQuery('#add-'+ id +' .hide-all').show(); 19 }); 24 20 } 25 21 … … 27 23 * Populate the thickbox window with the selected menu items 28 24 * 29 * @param int o- the id of the menu li to edit.25 * @param int id - the id of the menu li to edit. 30 26 */ 31 27 function wp_edit_menu_item( id ) { 32 var itemType = jQuery('#item-type' + id).val(); 33 var itemTitle = jQuery('#item-title' + id).val(); 34 var itemURL = jQuery('#item-url' + id).val(); 35 var itemAttrTitle = jQuery('#item-attr-title' + id).val(); 36 var itemTarget = jQuery('#item-target' + id).val(); 37 var itemDesc = jQuery('#item-description' + id).val(); 38 39 // Disable the ability to edit the url for page and category items 40 if ( 'page' == itemType || 'category' == itemType ) 41 jQuery( '#edit-item-url' ).attr('disabled', 'disabled' ); 28 var item_type = jQuery('#menu-item-type' + id).val(); 29 var item_title = jQuery('#menu-item-title' + id).val(); 30 var item_link = jQuery('#menu-item-url' + id).val(); 31 var item_attr_title = jQuery('#menu-item-attr-title' + id).val(); 32 var item_target = jQuery('#menu-item-target' + id).val(); 33 var item_description = jQuery('#menu-item-description' + id).val(); 34 var item_classes = jQuery('#menu-item-classes' + id).val(); 35 var item_xfn = jQuery('#menu-item-xfn' + id).val(); 36 37 // Only allow custom links to be editable. 38 if ( 'custom' != item_type ) 39 jQuery( '#edit-menu-item-url' ).attr('disabled', 'disabled' ); 42 40 43 41 // Populate the fields for thickbox 44 jQuery( '#edit-item-id' ).val(id); 45 jQuery( '#edit-item-title' ).val(itemTitle); 46 jQuery( '#edit-item-url' ).val(itemURL); 47 jQuery( '#edit-item-attr-title' ).val(itemAttrTitle); 48 jQuery( '#edit-item-target' ).val(itemTarget); 49 jQuery( "#edit-item-target option[value='" + itemTarget + "']" ).attr('selected', 'selected'); 50 jQuery( '#edit-item-description' ).val(itemDesc); 42 jQuery( '#edit-menu-item-id' ).val(id); 43 jQuery( '#edit-menu-item-title' ).val(item_title); 44 jQuery( '#edit-menu-item-url' ).val(item_link); 45 jQuery( '#edit-menu-item-attr-title' ).val(item_attr_title); 46 jQuery( '#edit-menu-item-target' ).val(item_target); 47 jQuery( "#edit-menu-item-target option[value='" + item_target + "']" ).attr('selected', 'selected'); 48 jQuery( '#edit-menu-item-description' ).val(item_description); 49 jQuery( '#edit-menu-item-classes' ).val(item_classes); 50 jQuery( '#edit-menu-item-xfn' ).val(item_xfn); 51 52 // focus 53 jQuery( '#edit-menu-item-title' ).focus(); 51 54 }; 52 55 … … 55 58 */ 56 59 function wp_update_menu_item() { 57 var id = jQuery('#edit-item-id').val(); 58 var itemTitle = jQuery('#edit-item-title').val(); 59 var itemURL = jQuery('#edit-item-url').val(); 60 var itemAttrTitle = jQuery('#edit-item-attr-title').val(); 61 var itemTarget = jQuery('#edit-item-target').val(); 62 var itemDesc = jQuery('#edit-item-description').val(); 63 64 // update menu item settings 65 jQuery('#menu-' + id).find('.item-title:first').html(itemTitle); 66 jQuery('#item-title' + id).val(itemTitle); 67 jQuery('#item-url' + id).val(itemURL); 68 jQuery('#item-attr-title' + id).val(itemAttrTitle); 69 jQuery('#item-target' + id).val(itemTarget); 70 jQuery('#item-description' + id).val(itemDesc); 60 var id = jQuery('#edit-menu-item-id').val(); 61 var item_title = jQuery('#edit-menu-item-title').val(); 62 var item_link = jQuery('#edit-menu-item-url').val(); 63 var item_attr_title = jQuery('#edit-menu-item-attr-title').val(); 64 var item_target = jQuery('#edit-menu-item-target').val(); 65 var item_description = jQuery('#edit-menu-item-description').val(); 66 var item_classes = jQuery('#edit-menu-item-classes').val(); 67 var item_xfn = jQuery('#edit-menu-item-xfn').val(); 68 69 // update menu item settings 70 jQuery('.menu #menu-item' + id).find('span.item-title').html(item_title); 71 jQuery('.menu #menu-item-title' + id).val(item_title); 72 jQuery('.menu #menu-item-url' + id).val(item_link); 73 jQuery('.menu #menu-item-attr-title' + id).val(item_attr_title); 74 jQuery('.menu #menu-item-target' + id).val(item_target); 75 jQuery('.menu #menu-item-description' + id).val(item_description); 76 jQuery('.menu #menu-item-classes' + id).val(item_classes); 77 jQuery('.menu #menu-item-xfn' + id).val(item_xfn); 78 79 jQuery('.menu #menu-item' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 71 80 } 72 81 … … 77 86 */ 78 87 function wp_remove_menu_item( o ) { 79 var todelete = document.getElementById('menu- ' + o);88 var todelete = document.getElementById('menu-item' + o); 80 89 81 90 if ( todelete ) { … … 84 93 jQuery(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { jQuery(this).parent().parent().remove() } } ); 85 94 }); 86 87 wp_update_post_data();88 95 } 89 96 }; 90 97 91 98 /** 92 * Prepares menu items for POST93 */94 function wp_update_post_data() {95 var i = 0;96 97 jQuery('.menu li').each(function(i) {98 i = i + 1;99 var j = jQuery(this).attr('value');100 101 jQuery(this).find('#item-position' + j).attr('value', i);102 jQuery(this).attr('id','menu-' + i);103 jQuery(this).attr('value', i);104 105 jQuery(this).find('#item-dbid' + j).attr('name','item-dbid' + i);106 jQuery(this).find('#item-dbid' + j).attr('id','item-dbid' + i);107 108 jQuery(this).find('#item-postmenu' + j).attr('name','item-postmenu' + i);109 jQuery(this).find('#item-postmenu' + j).attr('id','item-postmenu' + i);110 111 var p = jQuery(this).find('#item-parent' + j).parent().parent().parent().attr('value');112 113 jQuery(this).find('#item-parent' + j).attr('name','item-parent' + i);114 jQuery(this).find('#item-parent' + j).attr('id','item-parent' + i);115 116 if (p) {117 // Do nothing118 } else {119 // reset p to be top level120 p = 0;121 }122 123 jQuery(this).find('#item-parent' + j).attr('value', p);124 125 jQuery(this).find('#item-title' + j).attr('name','item-title' + i);126 jQuery(this).find('#item-title' + j).attr('id','item-title' + i);127 128 jQuery(this).find('#item-url' + j).attr('name','item-url' + i);129 jQuery(this).find('#item-url' + j).attr('id','item-url' + i);130 131 jQuery(this).find('#item-description' + j).attr('name','item-description' + i);132 jQuery(this).find('#item-description' + j).attr('id','item-description' + i);133 134 jQuery(this).find('#item-attr-title' + j).attr('name','item-attr-title' + i);135 jQuery(this).find('#item-attr-title' + j).attr('id','item-attr-title' + i);136 137 jQuery(this).find('#item-target' + j).attr('name','item-target' + i);138 jQuery(this).find('#item-target' + j).attr('id','item-target' + i);139 140 jQuery(this).find('#item-position' + j).attr('name', 'item-position' + i);141 jQuery(this).find('#item-position' + j).attr('id', 'item-position' + i);142 143 jQuery(this).find('#item-type' + j).attr('name', 'item-type' + i);144 jQuery(this).find('#item-type' + j).attr('id', 'item-type' + i);145 146 jQuery('#li-count').attr( 'value', i );147 });148 };149 150 /**151 99 * Adds the item to the menu 152 100 * 153 * @param string id - The menu item's id 154 * @param string additemtype - Page, Category, or Custom. 155 * @param string itemtext - menu text. 156 * @param string itemurl - url of the menu. 157 * @param int itemid - menu id. 158 * @param int itemparentid - default 0. 159 * @param string itemdescription - the description of the menu item. 160 */ 161 function wp_add_item_to_menu( item_type, item_title, item_url, item_id, item_parent_id, item_description ) { 101 * @param string item_db_id - The menu item's db id. 102 * @param string item_object_id - The menu item's object id. 103 * @param string item_type - The menu item's object type. 104 * @param string item_append - The menu item's nice name. 105 * @param string item_parent_id - The menu item's parent id. 106 * @param string item_title - The menu item title. 107 * @param string item_url - The menu item url 108 * @param string item_description - The menu item description. 109 * @param string item_attr_title - The title attribute. 110 * @param string item_target - The target attribute. 111 * @param string item_classes - Optional. Additional CSS classes for the menu item 112 * @param string item_xfn - Optional. The rel attribute. 113 */ 114 function wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) { 162 115 var randomnumber = wp_get_unique_menu_id(); 116 var hidden = wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ); 163 117 164 118 // Adds the item in the queue 165 jQuery('.menu').append('<li id="menu- ' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_type + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu' + randomnumber + '" id="item-postmenu' + randomnumber + '" value="' + item_id + '" /><input type="hidden" name="item-parent' + randomnumber + '" id="item-parent' + randomnumber + '" value="' + item_parent_id + '" /><input type="hidden" name="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + item_url + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + item_description + '" /><input type="hidden" name="item-position' + randomnumber + '" id="item-position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="item-type' + randomnumber + '" id="item-type' + randomnumber + '" value="' + item_type + '" /><input type="hidden" name="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /></li>');119 jQuery('.menu').append('<li id="menu-item' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_append + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl>' + hidden + '</li>'); 166 120 167 121 // Give some feedback to the user 168 jQuery( '.menu #menu- ' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});122 jQuery( '.menu #menu-item' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 169 123 170 124 // Enable drag-n-drop 171 125 wp_drag_and_drop(); 172 126 173 wp_update_post_data();174 175 127 // Reload thickbox 176 128 tb_init('a.thickbox, area.thickbox, input.thickbox'); 177 129 }; 178 130 179 /* 180 * Queues items in perperation for appendToList 181 * 182 * @param string type - Page, Category, or Custom. 183 * @param string link - menu text. 184 * @param string url - url of the menu. 185 * @param int id - menu id. 186 * @param int parent_id - default 0. 187 * @param string description - the description of the menu item. 188 */ 189 function wp_update_queue( e, item_type, item_title, item_url, item_id, item_parent_id, item_description ) { 190 var randomnumber = wp_get_unique_menu_id(); 191 var menu_item_id = jQuery(e).attr('id'); 192 193 if ( jQuery(e).attr('checked') ) { 194 // Add menu item to the queue 195 jQuery('#queue').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_type + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu' + randomnumber + '" id="item-postmenu' + randomnumber + '" value="' + item_id + '" /><input type="hidden" name="item-parent' + randomnumber + '" id="item-parent' + randomnumber + '" value="' + item_parent_id + '" /><input type="hidden" name="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + item_url + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + item_description + '" /><input type="hidden" name="item-position' + randomnumber + '" id="item-position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="item-type' + randomnumber + '" id="item-type' + randomnumber + '" value="' + item_type + '" /><input type="hidden" name="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /><input type="hidden" name="item-id' + randomnumber + '" id="item-id' + randomnumber + '" value="'+ menu_item_id +'" /></li>'); 196 197 } else { 198 // Remove the item from the queue 199 if ( menu_item_id == jQuery('#queue li input[name^="item-id"]' ).val() ) { 200 jQuery('#queue li input[name^="item-id"]' ).parent().remove() 131 /** 132 * Grabs items from the queue and adds them to the menu. 133 * 134 * @param string button - a reference to the button that was clicked 135 */ 136 function wp_add_checked_items_to_menu( button ) { 137 // Grab checked items 138 var items = jQuery(button).siblings('.list-wrap').find(':checked'); 139 140 // If nothing was checked, cancel 141 if ( 0 == items.length ) 142 return false; 143 144 // Loop through each item, grab it's hidden data and add it to the menu. 145 jQuery(items).each(function(){ 146 var item_type = jQuery(this).parent().siblings('.menu-item-type').val(); 147 148 if ( 'custom' == item_type ) { 149 var item_attr_title = jQuery(this).parent().siblings('.menu-item-attr-title').val(); 150 var item_target = jQuery(this).parent().siblings('.menu-item-target').val(); 151 var item_classes = jQuery(this).parent().siblings('.menu-item-classes').val(); 152 var item_xfn = jQuery(this).parent().siblings('.menu-item-xfn').val(); 153 } else { 154 var item_attr_title = ''; 155 var item_target = '_none'; 156 var item_classes = ''; 157 var item_xfn = ''; 201 158 }; 202 }; 203 }; 204 205 /** 206 * Grabs items from the queue and adds them to the menu. 207 * 208 * @param string button - a reference of the button that was clicked 209 */ 210 function wp_add_queued_items_to_menu( button ) { 211 // Grab items in queue 212 var items = jQuery('#queue').children(); 213 214 // Empty Queue 215 jQuery('#queue').empty(); 216 217 // Appends HTML to the menu 218 jQuery('.menu').append( items ); 219 220 // Give some feedback to the user 221 jQuery(items).each(function(){ 222 jQuery(this).find('dt').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 159 160 var item_db_id = jQuery(this).parent().siblings('.menu-item-db-id').val(); 161 var item_object_id = jQuery(this).parent().siblings('.menu-item-object-id').val(); 162 var item_append = jQuery(this).parent().siblings('.menu-item-append').val(); 163 var item_parent_id = jQuery(this).parent().siblings('.menu-item-parent-id').val(); 164 var item_title = jQuery(this).parent().siblings('.menu-item-title').val(); 165 var item_url = jQuery(this).parent().siblings('.menu-item-url').val(); 166 var item_description = jQuery(this).parent().siblings('.menu-item-description').val(); 167 168 if ( undefined == item_description ) { 169 item_description = ''; 170 }; 171 172 // Add the menu item to the menu 173 wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ); 174 175 // uncheck the menu item in the list 176 jQuery(this).attr( 'checked', false ); 223 177 }); 224 225 // Uncheck the checkboxes in the list 226 jQuery(button).offsetParent().find('.list-container input').attr('checked', false); 227 228 wp_update_post_data(); 229 230 // Enable drag-n-drop 231 wp_drag_and_drop(); 232 233 // Reload thickbox 234 tb_init('a.thickbox, area.thickbox, input.thickbox'); 235 }; 236 237 /** 238 * Allow the items in the Menu to be dragged and dropped. 178 }; 179 180 /** 181 * Makes the menu items drag and droppable. 239 182 */ 240 183 function wp_drag_and_drop() { … … 252 195 addClasses: false, 253 196 helper: 'clone', 254 zIndex: 100 ,197 zIndex: 100 255 198 }); 256 199 … … 308 251 309 252 /** 253 * Prepares menu items for POST. 254 */ 255 function wp_update_post_data() { 256 var i = 0; 257 258 jQuery('.menu li').each(function(i) { 259 i = i + 1; 260 var j = jQuery(this).attr('value'); 261 262 jQuery(this).find('#menu-item-position' + j).attr('value', i); 263 jQuery(this).attr('id','menu-item' + i); 264 jQuery(this).attr('value', i); 265 266 jQuery(this).find('#menu-item-db-id' + j).attr('id','menu-item-db-id' + i); 267 jQuery(this).find('#menu-item-object-id' + j).attr('id','menu-item-object-id' + i); 268 jQuery(this).find('#menu-item-append' + j).attr('id', 'menu-item-append' + i); 269 jQuery(this).find('#menu-item-type' + j).attr('id', 'menu-item-type' + i); 270 jQuery(this).find('#menu-item-position' + j).attr('id', 'menu-item-position' + i); 271 272 var p = jQuery(this).find('#menu-item-parent-id' + j).parent().parent().parent().attr('value'); 273 jQuery(this).find('#menu-item-parent-id' + j).attr('id','menu-item-parent-id' + i); 274 if (p) { 275 // Do nothing 276 } else { 277 // reset p to be top level 278 p = 0; 279 } 280 jQuery(this).find('#menu-item-parent-id' + j).attr('value', p); 281 282 jQuery(this).find('#menu-item-title' + j).attr('id','menu-item-title' + i); 283 jQuery(this).find('#menu-item-url' + j).attr('id','menu-item-url' + i); 284 jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i); 285 jQuery(this).find('#menu-item-classes' + j).attr('id','menu-item-classes' + i); 286 jQuery(this).find('#menu-item-xfn' + j).attr('id','menu-item-xfn' + i); 287 jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i); 288 jQuery(this).find('#menu-item-attr-title' + j).attr('id','menu-item-attr-title' + i); 289 jQuery(this).find('#menu-item-target' + j).attr('id','menu-item-target' + i); 290 291 jQuery('#li-count').attr( 'value', i ); 292 }); 293 }; 294 295 /** 310 296 * Gets a unique number based on how many items are in the menu 311 297 */ … … 333 319 return randomnumber; 334 320 } 321 322 /** 323 * Returns all the nessecary hidden inputs for each menu item. 324 * 325 * @param string item_db_id - The menu item's db id. 326 * @param string item_object_id - The menu item's object id. 327 * @param string item_type - The menu item's object type. 328 * @param string item_append - The menu item's nice name. 329 * @param string item_parent_id - The menu item's parent id. 330 * @param string item_title - The menu item title. 331 * @param string item_url - The menu item url 332 * @param string item_description - The menu item description. 333 * @param string item_attr_title - The title attribute. 334 * @param string item_target - The target attribute. 335 * @param string item_classes - Optional. Additional CSS classes for the menu item 336 * @param string item_xfn - Optional. The rel attribute. 337 */ 338 function wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) { 339 var hidden = ''; 340 341 hidden += '<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id' + randomnumber + '" value="' + item_db_id + '" />'; 342 hidden += '<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id' + randomnumber + '" value="' + item_object_id + '" />'; 343 hidden += '<input type="hidden" name="menu-item-type[]" id="menu-item-type' + randomnumber + '" value="' + item_type + '" />'; 344 hidden += '<input type="hidden" name="menu-item-append[]" id="menu-item-append' + randomnumber + '" value="' + item_append + '" />'; 345 hidden += '<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id' + randomnumber + '" value="' + item_parent_id + '" />'; 346 hidden += '<input type="hidden" name="menu-item-position[]" id="menu-item-position' + randomnumber + '" value="' + randomnumber + '" />'; 347 hidden += '<input type="hidden" name="menu-item-title[]" id="menu-item-title' + randomnumber + '" value="' + item_title + '" />'; 348 hidden += '<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title' + randomnumber + '" value="' + item_attr_title + '" />'; 349 hidden += '<input type="hidden" name="menu-item-url[]" id="menu-item-url' + randomnumber + '" value="' + item_url + '" />'; 350 hidden += '<input type="hidden" name="menu-item-target[]" id="menu-item-target' + randomnumber + '" value="' + item_target + '" />'; 351 hidden += '<input type="hidden" name="menu-item-description[]" id="menu-item-description' + randomnumber + '" value="' + item_description + '" />'; 352 hidden += '<input type="hidden" name="menu-item-classes[]" id="menu-item-classes' + randomnumber + '" value="' + item_classes + '" />'; 353 hidden += '<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn' + randomnumber + '" value="' + item_xfn + '" />'; 354 355 return hidden; 356 } -
trunk/wp-admin/js/nav-menu-dynamic-functions.js
r13512 r13704 1 function wp_ update_links_list(e){var link='<li><dl><dt><label class="item-title"><input type="checkbox" id="link-'+e.link_id+'" name="'+e.link_name+'" value="'+e.link_url+'" />'+e.link_name+"</label></dt></dl></li>";jQuery("#available-links .list").prepend(link);jQuery("#available-links .list #link-"+e.link_id).parent().animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_edit_menu_item(id){var itemType=jQuery("#item-type"+id).val();var itemTitle=jQuery("#item-title"+id).val();var itemURL=jQuery("#item-url"+id).val();var itemAttrTitle=jQuery("#item-attr-title"+id).val();var itemTarget=jQuery("#item-target"+id).val();var itemDesc=jQuery("#item-description"+id).val();if("page"==itemType||"category"==itemType){jQuery("#edit-item-url").attr("disabled","disabled")}jQuery("#edit-item-id").val(id);jQuery("#edit-item-title").val(itemTitle);jQuery("#edit-item-url").val(itemURL);jQuery("#edit-item-attr-title").val(itemAttrTitle);jQuery("#edit-item-target").val(itemTarget);jQuery("#edit-item-target option[value='"+itemTarget+"']").attr("selected","selected");jQuery("#edit-item-description").val(itemDesc)}function wp_update_menu_item(){var id=jQuery("#edit-item-id").val();var itemTitle=jQuery("#edit-item-title").val();var itemURL=jQuery("#edit-item-url").val();var itemAttrTitle=jQuery("#edit-item-attr-title").val();var itemTarget=jQuery("#edit-item-target").val();var itemDesc=jQuery("#edit-item-description").val();jQuery("#menu-"+id).find(".item-title:first").html(itemTitle);jQuery("#item-title"+id).val(itemTitle);jQuery("#item-url"+id).val(itemURL);jQuery("#item-attr-title"+id).val(itemAttrTitle);jQuery("#item-target"+id).val(itemTarget);jQuery("#item-description"+id).val(itemDesc)}function wp_remove_menu_item(o){var todelete=document.getElementById("menu-"+o);if(todelete){jQuery(todelete).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})});wp_update_post_data()}}function wp_update_post_data(){var i=0;jQuery(".menu li").each(function(i){i=i+1;var j=jQuery(this).attr("value");jQuery(this).find("#item-position"+j).attr("value",i);jQuery(this).attr("id","menu-"+i);jQuery(this).attr("value",i);jQuery(this).find("#item-dbid"+j).attr("name","item-dbid"+i);jQuery(this).find("#item-dbid"+j).attr("id","item-dbid"+i);jQuery(this).find("#item-postmenu"+j).attr("name","item-postmenu"+i);jQuery(this).find("#item-postmenu"+j).attr("id","item-postmenu"+i);var p=jQuery(this).find("#item-parent"+j).parent().parent().parent().attr("value");jQuery(this).find("#item-parent"+j).attr("name","item-parent"+i);jQuery(this).find("#item-parent"+j).attr("id","item-parent"+i);if(p){}else{p=0}jQuery(this).find("#item-parent"+j).attr("value",p);jQuery(this).find("#item-title"+j).attr("name","item-title"+i);jQuery(this).find("#item-title"+j).attr("id","item-title"+i);jQuery(this).find("#item-url"+j).attr("name","item-url"+i);jQuery(this).find("#item-url"+j).attr("id","item-url"+i);jQuery(this).find("#item-description"+j).attr("name","item-description"+i);jQuery(this).find("#item-description"+j).attr("id","item-description"+i);jQuery(this).find("#item-attr-title"+j).attr("name","item-attr-title"+i);jQuery(this).find("#item-attr-title"+j).attr("id","item-attr-title"+i);jQuery(this).find("#item-target"+j).attr("name","item-target"+i);jQuery(this).find("#item-target"+j).attr("id","item-target"+i);jQuery(this).find("#item-position"+j).attr("name","item-position"+i);jQuery(this).find("#item-position"+j).attr("id","item-position"+i);jQuery(this).find("#item-type"+j).attr("name","item-type"+i);jQuery(this).find("#item-type"+j).attr("id","item-type"+i);jQuery("#li-count").attr("value",i)})}function wp_add_item_to_menu(item_type,item_title,item_url,item_id,item_parent_id,item_description){var randomnumber=wp_get_unique_menu_id();jQuery(".menu").append('<li id="menu-'+randomnumber+'" value="'+randomnumber+'"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">'+item_title+'</span><span class="item-controls"><span class="item-type">'+item_type+'</span><a class="item-edit thickbox" id="edit'+randomnumber+'" value="'+randomnumber+'" onClick="wp_edit_menu_item('+randomnumber+')" title="'+navMenuL10n.thickbox+'" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">'+navMenuL10n.edit+'</a> | <a class="item-delete" id="delete'+randomnumber+'" value="'+randomnumber+'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu'+randomnumber+'" id="item-postmenu'+randomnumber+'" value="'+item_id+'" /><input type="hidden" name="item-parent'+randomnumber+'" id="item-parent'+randomnumber+'" value="'+item_parent_id+'" /><input type="hidden" name="item-title'+randomnumber+'" id="item-title'+randomnumber+'" value="'+item_title+'" /><input type="hidden" name="item-url'+randomnumber+'" id="item-url'+randomnumber+'" value="'+item_url+'" /><input type="hidden" name="item-description'+randomnumber+'" id="item-description'+randomnumber+'" value="'+item_description+'" /><input type="hidden" name="item-position'+randomnumber+'" id="item-position'+randomnumber+'" value="'+randomnumber+'" /><input type="hidden" name="item-type'+randomnumber+'" id="item-type'+randomnumber+'" value="'+item_type+'" /><input type="hidden" name="item-attr-title'+randomnumber+'" id="item-attr-title'+randomnumber+'" value="'+item_title+'" /><input type="hidden" name="item-target'+randomnumber+'" id="item-target'+randomnumber+'" value="0" /></li>');jQuery(".menu #menu-"+randomnumber+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();wp_update_post_data();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_update_queue(e,item_type,item_title,item_url,item_id,item_parent_id,item_description){var randomnumber=wp_get_unique_menu_id();var menu_item_id=jQuery(e).attr("id");if(jQuery(e).attr("checked")){jQuery("#queue").append('<li id="menu-'+randomnumber+'" value="'+randomnumber+'"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">'+item_title+'</span><span class="item-controls"><span class="item-type">'+item_type+'</span><a class="item-edit thickbox" id="edit'+randomnumber+'" value="'+randomnumber+'" onClick="wp_edit_menu_item('+randomnumber+')" title="'+navMenuL10n.thickbox+'" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">'+navMenuL10n.edit+'</a> | <a class="item-delete" id="delete'+randomnumber+'" value="'+randomnumber+'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu'+randomnumber+'" id="item-postmenu'+randomnumber+'" value="'+item_id+'" /><input type="hidden" name="item-parent'+randomnumber+'" id="item-parent'+randomnumber+'" value="'+item_parent_id+'" /><input type="hidden" name="item-title'+randomnumber+'" id="item-title'+randomnumber+'" value="'+item_title+'" /><input type="hidden" name="item-url'+randomnumber+'" id="item-url'+randomnumber+'" value="'+item_url+'" /><input type="hidden" name="item-description'+randomnumber+'" id="item-description'+randomnumber+'" value="'+item_description+'" /><input type="hidden" name="item-position'+randomnumber+'" id="item-position'+randomnumber+'" value="'+randomnumber+'" /><input type="hidden" name="item-type'+randomnumber+'" id="item-type'+randomnumber+'" value="'+item_type+'" /><input type="hidden" name="item-attr-title'+randomnumber+'" id="item-attr-title'+randomnumber+'" value="'+item_title+'" /><input type="hidden" name="item-target'+randomnumber+'" id="item-target'+randomnumber+'" value="0" /><input type="hidden" name="item-id'+randomnumber+'" id="item-id'+randomnumber+'" value="'+menu_item_id+'" /></li>')}else{if(menu_item_id==jQuery('#queue li input[name^="item-id"]').val()){jQuery('#queue li input[name^="item-id"]').parent().remove()}}}function wp_add_queued_items_to_menu(button){var items=jQuery("#queue").children();jQuery("#queue").empty();jQuery(".menu").append(items);jQuery(items).each(function(){jQuery(this).find("dt").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});jQuery(button).offsetParent().find(".list-container input").attr("checked",false);wp_update_post_data();wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('<div class="dropzone"></div>')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100,});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(e,ui){var li=jQuery(this).parent();var child=!jQuery(this).hasClass("dropzone");if(child&&li.children("ul").length==0){li.append('<ul class="sub-menu" />')}if(child){li.children("ul").append(ui.draggable)}else{li.before(ui.draggable)}li.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var draggablevalue=ui.draggable.attr("value");var droppablevalue=li.attr("value");li.find("#menu-"+draggablevalue).find("#parent"+draggablevalue).val(droppablevalue);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var parentid=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_get_unique_menu_id(){var count=jQuery(".menu li").length+1;var randomnumber=count;var validatetest=0;try{var test=document.getElementById("menu-"+randomnumber.toString()).value}catch(err){validatetest=1}while(validatetest==0){randomnumber=randomnumber+1;try{var test2=document.getElementById("menu-"+randomnumber.toString()).value}catch(err){validatetest=1}}return randomnumber};1 function wp_nav_menu_autocomplete(a){jQuery("#add-"+a+" .quick-search").autocomplete(jQuery("#add-"+a+" .autocomplete").val().split("|"));jQuery("#add-"+a+" .quick-search").result(function(b,d,c){jQuery("#add-"+a+" .list-wrap").css("display","block");jQuery("#add-"+a+" .list-wrap li:contains('"+d+"')").css("display","block");jQuery("#add-"+a+" .show-all").hide();jQuery("#add-"+a+" .hide-all").show()})}function wp_edit_menu_item(a){var f=jQuery("#menu-item-type"+a).val();var b=jQuery("#menu-item-title"+a).val();var g=jQuery("#menu-item-url"+a).val();var c=jQuery("#menu-item-attr-title"+a).val();var d=jQuery("#menu-item-target"+a).val();var h=jQuery("#menu-item-description"+a).val();var e=jQuery("#menu-item-classes"+a).val();var i=jQuery("#menu-item-xfn"+a).val();if("custom"!=f){jQuery("#edit-menu-item-url").attr("disabled","disabled")}jQuery("#edit-menu-item-id").val(a);jQuery("#edit-menu-item-title").val(b);jQuery("#edit-menu-item-url").val(g);jQuery("#edit-menu-item-attr-title").val(c);jQuery("#edit-menu-item-target").val(d);jQuery("#edit-menu-item-target option[value='"+d+"']").attr("selected","selected");jQuery("#edit-menu-item-description").val(h);jQuery("#edit-menu-item-classes").val(e);jQuery("#edit-menu-item-xfn").val(i);jQuery("#edit-menu-item-title").focus()}function wp_update_menu_item(){var h=jQuery("#edit-menu-item-id").val();var f=jQuery("#edit-menu-item-title").val();var b=jQuery("#edit-menu-item-url").val();var g=jQuery("#edit-menu-item-attr-title").val();var d=jQuery("#edit-menu-item-target").val();var c=jQuery("#edit-menu-item-description").val();var a=jQuery("#edit-menu-item-classes").val();var e=jQuery("#edit-menu-item-xfn").val();jQuery(".menu #menu-item"+h).find("span.item-title").html(f);jQuery(".menu #menu-item-title"+h).val(f);jQuery(".menu #menu-item-url"+h).val(b);jQuery(".menu #menu-item-attr-title"+h).val(g);jQuery(".menu #menu-item-target"+h).val(d);jQuery(".menu #menu-item-description"+h).val(c);jQuery(".menu #menu-item-classes"+h).val(a);jQuery(".menu #menu-item-xfn"+h).val(e);jQuery(".menu #menu-item"+h+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_remove_menu_item(b){var a=document.getElementById("menu-item"+b);if(a){jQuery(a).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})})}}function wp_add_item_to_menu(a,k,f,n,l,b,m,h,e,d,c,i){var j=wp_get_unique_menu_id();var g=wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i);jQuery(".menu").append('<li id="menu-item'+j+'" value="'+j+'"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">'+b+'</span><span class="item-controls"><span class="item-type">'+n+'</span><a class="item-edit thickbox" id="edit'+j+'" value="'+j+'" onClick="wp_edit_menu_item('+j+')" title="'+navMenuL10n.thickbox+'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'+navMenuL10n.edit+'</a> | <a class="item-delete" id="delete'+j+'" value="'+j+'">Delete</a></span></dt></dl>'+g+"</li>");jQuery(".menu #menu-item"+j+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_add_checked_items_to_menu(b){var a=jQuery(b).siblings(".list-wrap").find(":checked");if(0==a.length){return false}jQuery(a).each(function(){var h=jQuery(this).parent().siblings(".menu-item-type").val();if("custom"==h){var e=jQuery(this).parent().siblings(".menu-item-attr-title").val();var f=jQuery(this).parent().siblings(".menu-item-target").val();var g=jQuery(this).parent().siblings(".menu-item-classes").val();var j=jQuery(this).parent().siblings(".menu-item-xfn").val()}else{var e="";var f="_none";var g="";var j=""}var c=jQuery(this).parent().siblings(".menu-item-db-id").val();var k=jQuery(this).parent().siblings(".menu-item-object-id").val();var n=jQuery(this).parent().siblings(".menu-item-append").val();var l=jQuery(this).parent().siblings(".menu-item-parent-id").val();var d=jQuery(this).parent().siblings(".menu-item-title").val();var m=jQuery(this).parent().siblings(".menu-item-url").val();var i=jQuery(this).parent().siblings(".menu-item-description").val();if(undefined==i){i=""}wp_add_item_to_menu(c,k,h,n,l,d,m,i,e,f,g,j);jQuery(this).attr("checked",false)})}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('<div class="dropzone"></div>')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(f,d){var a=jQuery(this).parent();var g=!jQuery(this).hasClass("dropzone");if(g&&a.children("ul").length==0){a.append('<ul class="sub-menu" />')}if(g){a.children("ul").append(d.draggable)}else{a.before(d.draggable)}a.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var c=d.draggable.attr("value");var b=a.attr("value");a.find("#menu-"+c).find("#parent"+c).val(b);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var a=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_update_post_data(){var a=0;jQuery(".menu li").each(function(c){c=c+1;var b=jQuery(this).attr("value");jQuery(this).find("#menu-item-position"+b).attr("value",c);jQuery(this).attr("id","menu-item"+c);jQuery(this).attr("value",c);jQuery(this).find("#menu-item-db-id"+b).attr("id","menu-item-db-id"+c);jQuery(this).find("#menu-item-object-id"+b).attr("id","menu-item-object-id"+c);jQuery(this).find("#menu-item-append"+b).attr("id","menu-item-append"+c);jQuery(this).find("#menu-item-type"+b).attr("id","menu-item-type"+c);jQuery(this).find("#menu-item-position"+b).attr("id","menu-item-position"+c);var d=jQuery(this).find("#menu-item-parent-id"+b).parent().parent().parent().attr("value");jQuery(this).find("#menu-item-parent-id"+b).attr("id","menu-item-parent-id"+c);if(d){}else{d=0}jQuery(this).find("#menu-item-parent-id"+b).attr("value",d);jQuery(this).find("#menu-item-title"+b).attr("id","menu-item-title"+c);jQuery(this).find("#menu-item-url"+b).attr("id","menu-item-url"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-classes"+b).attr("id","menu-item-classes"+c);jQuery(this).find("#menu-item-xfn"+b).attr("id","menu-item-xfn"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-attr-title"+b).attr("id","menu-item-attr-title"+c);jQuery(this).find("#menu-item-target"+b).attr("id","menu-item-target"+c);jQuery("#li-count").attr("value",c)})}function wp_get_unique_menu_id(){var d=jQuery(".menu li").length+1;var e=d;var a=0;try{var f=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}while(a==0){e=e+1;try{var b=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}}return e}function wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i){var g="";g+='<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id'+j+'" value="'+a+'" />';g+='<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id'+j+'" value="'+k+'" />';g+='<input type="hidden" name="menu-item-type[]" id="menu-item-type'+j+'" value="'+f+'" />';g+='<input type="hidden" name="menu-item-append[]" id="menu-item-append'+j+'" value="'+n+'" />';g+='<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id'+j+'" value="'+l+'" />';g+='<input type="hidden" name="menu-item-position[]" id="menu-item-position'+j+'" value="'+j+'" />';g+='<input type="hidden" name="menu-item-title[]" id="menu-item-title'+j+'" value="'+b+'" />';g+='<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title'+j+'" value="'+e+'" />';g+='<input type="hidden" name="menu-item-url[]" id="menu-item-url'+j+'" value="'+m+'" />';g+='<input type="hidden" name="menu-item-target[]" id="menu-item-target'+j+'" value="'+d+'" />';g+='<input type="hidden" name="menu-item-description[]" id="menu-item-description'+j+'" value="'+h+'" />';g+='<input type="hidden" name="menu-item-classes[]" id="menu-item-classes'+j+'" value="'+c+'" />';g+='<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn'+j+'" value="'+i+'" />';return g}; -
trunk/wp-admin/nav-menus.php
r13685 r13704 10 10 */ 11 11 12 require_once('admin.php'); 13 14 /* 15 TODO 16 Add caps: edit_menus, delete_menus 17 */ 12 /** Load WordPress Administration Bootstrap */ 13 require_once( 'admin.php' ); 14 15 // Permissions Check 18 16 if ( ! current_user_can('switch_themes') ) 19 17 wp_die( __( 'Cheatin’ uh?' )); 20 18 19 // Nav Menu CSS 21 20 wp_admin_css( 'nav-menu' ); 21 22 // jQuery 22 23 wp_enqueue_script( 'jquery' ); 23 24 wp_enqueue_script( 'jquery-ui-draggable' ); 24 25 wp_enqueue_script( 'jquery-ui-droppable' ); 25 26 wp_enqueue_script( 'jquery-ui-sortable' ); 26 wp_enqueue_script( 'jquery-ui-dialog' ); 27 wp_enqueue_script( 'jquery-autocomplete' ); 28 29 // Nav Menu functions 27 30 wp_enqueue_script( 'nav-menu-dynamic-functions' ); 28 31 wp_enqueue_script( 'nav-menu-default-items' ); 29 wp_enqueue_script( 'jquery-autocomplete' );30 32 wp_enqueue_script( 'nav-menu-php-functions' ); 33 34 // Metaboxes 35 wp_enqueue_script( 'common' ); 36 wp_enqueue_script( 'wp-lists' ); 37 wp_enqueue_script( 'postbox' ); 38 39 // Thickbox 31 40 add_thickbox(); 32 41 42 // Load all the nav menu interface functions 43 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); 44 45 // Container for any messages displayed to the user 46 $messages_div = ''; 47 48 // Container that stores the name of the active menu 49 $nav_menu_selected_title = ''; 50 51 // The menu id of the current menu being edited 52 $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0; 53 54 // Allowed actions: add, update, delete 55 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit'; 56 57 switch ( $action ) { 58 case 'delete': 59 check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id ); 60 61 if ( is_nav_menu($nav_menu_selected_id) ) { 62 wp_delete_nav_menu( $nav_menu_selected_id ); 63 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('Menu successfully deleted.') . '</p></div>'; 64 $nav_menu_selected_id = 0; 65 } 66 break; 67 68 case 'update': 69 check_admin_referer( 'update-nav_menu' ); 70 71 // Add Menu 72 if ( isset($_POST['create-menu']) ) { 73 if ( current_theme_supports('nav-menus') ) { 74 $add_nav_menu = esc_html( $_POST['create-menu-name'] ); 75 76 if ( $add_nav_menu ) { 77 $add_nav_menu = wp_create_nav_menu( $add_nav_menu ); 78 79 if ( is_wp_error( $add_nav_menu ) ) { 80 $messages_div = '<div id="message" class="error fade below-h2"><p>' . $add_nav_menu->get_error_message() . '</p></div>'; 81 } else { 82 $nav_menu_selected_id = $add_nav_menu->term_id; 83 $nav_menu_selected_title = $add_nav_menu->name; 84 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), esc_html( $add_nav_menu->name ) ) . '</p></div>'; 85 } 86 } else { 87 $messages_div = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>'; 88 } 89 unset($add_nav_menu); 90 } 91 } 92 93 // Update menu name 94 if ( isset($_POST['menu-name']) ) { 95 $old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A ); 96 $args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], ); 97 $new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args ); 98 } 99 100 // Update menu items 101 $update_nav_items = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0; 102 $update_nav_menu = is_nav_menu( $nav_menu_selected_id ); 103 104 if ( !is_wp_error($update_nav_menu) ) { 105 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); 106 $parent_menu_ids = array(); 107 108 // Loop through all POST variables 109 for ( $k = 0; $k < $update_nav_items; $k++ ) { 110 111 $menu_item_db_id = isset( $_POST['menu-item-db-id'][$k] ) ? $_POST['menu-item-db-id'][$k] : 0; 112 $menu_item_object_id = isset( $_POST['menu-item-object-id'][$k] ) ? $_POST['menu-item-object-id'][$k] : 0; 113 $menu_item_parent_id = isset( $_POST['menu-item-parent-id'][$k] ) ? $_POST['menu-item-parent-id'][$k] : 0; 114 $menu_item_position = isset( $_POST['menu-item-position'][$k] ) ? $_POST['menu-item-position'][$k] : 0; 115 $menu_item_type = isset( $_POST['menu-item-type'][$k] ) ? $_POST['menu-item-type'][$k] : 'custom'; 116 $menu_item_append = isset( $_POST['menu-item-append'][$k] ) ? $_POST['menu-item-append'][$k] : 'custom'; 117 118 $menu_item_title = isset( $_POST['menu-item-title'][$k] ) ? $_POST['menu-item-title'][$k] : ''; 119 $menu_item_url = isset( $_POST['menu-item-url'][$k] ) ? $_POST['menu-item-url'][$k] : ''; 120 $menu_item_description = isset( $_POST['menu-item-description'][$k] ) ? $_POST['menu-item-description'][$k]: ''; 121 $menu_item_attr_title = isset( $_POST['menu-item-attr-title'][$k] ) ? $_POST['menu-item-attr-title'][$k] : ''; 122 $menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : 0; 123 $menu_item_classes = isset( $_POST['menu-item-classes'][$k] ) ? $_POST['menu-item-classes'][$k] : ''; 124 $menu_item_xfn = isset( $_POST['menu-item-xfn'][$k] ) ? $_POST['menu-item-xfn'][$k] : ''; 125 126 // Menu item title can't be blank 127 if ( '' == $menu_item_title ) 128 continue; 129 130 // Populate the menu item 131 $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID, 132 'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position, 133 'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ), 134 'post_content' => $menu_item_description, 'post_title' => $menu_item_title ); 135 136 // New menu item 137 if ( $menu_item_db_id == 0 ) { 138 $menu_item_db_id = wp_insert_post( $post ); 139 } elseif ( isset( $menu_items[$menu_item_db_id] ) ) { 140 $post['ID'] = $menu_item_db_id; 141 wp_update_post( $post ); 142 unset( $menu_items[$menu_item_db_id] ); 143 } 144 $parent_menu_ids[$k] = $menu_item_db_id; 145 146 update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type ); 147 update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append ); 148 update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id ); 149 update_post_meta( $menu_item_db_id, 'menu_item_target', esc_attr($menu_item_target) ); 150 update_post_meta( $menu_item_db_id, 'menu_item_classes', esc_attr($menu_item_classes) ); 151 update_post_meta( $menu_item_db_id, 'menu_item_xfn', esc_attr($menu_item_xfn) ); 152 153 // @todo: only save custom link urls. 154 update_post_meta( $menu_item_db_id, 'menu_item_url', esc_url_raw( $menu_item_url ) ); 155 } 156 157 // Remove menu items from the menu that weren't in $_POST 158 if ( !empty( $menu_items ) ) { 159 foreach ( array_keys( $menu_items ) as $menu_item_id ) { 160 wp_delete_post( $menu_item_id ); 161 } 162 } 163 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>'; 164 } 165 break; 166 } 167 168 // Get all nav menus 169 $nav_menus = wp_get_nav_menus(); 170 171 // Get recently edited nav menu 172 $recently_edited = get_user_option( 'nav_menu_recently_edited' ); 173 174 // If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu. 175 if ( !$recently_edited && is_nav_menu($nav_menu_selected_id) ) { 176 $recently_edited = $nav_menu_selected_id; 177 178 // Else if $nav_menu_selected_id is not a menu, but $recently_edited is, grab that one. 179 } elseif ( 0 == $nav_menu_selected_id && is_nav_menu($recently_edited) ) { 180 $nav_menu_selected_id = $recently_edited; 181 182 // Else try to grab the first menu from the menus list 183 } elseif ( 0 == $nav_menu_selected_id && ! empty($nav_menus) ) { 184 $nav_menu_selected_id = $nav_menus[0]->term_id; 185 } 186 187 // Update the user's setting 188 if ( $nav_menu_selected_id != $recently_edited && is_nav_menu($nav_menu_selected_id) ) 189 update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id ); 190 191 // If there's a menu, get it's name. 192 if ( !$nav_menu_selected_title && $nav_menu_selected_title = is_nav_menu( $nav_menu_selected_id ) ) { 193 $nav_menu_selected_title = $nav_menu_selected_title->name; 194 } 195 196 // The user has no menus. 197 if ( !is_nav_menu( $nav_menu_selected_id ) ) { 198 if ( current_theme_supports('nav-menus') ) { 199 $messages_div = '<div id="message" class="updated"><p>' . __('You haven\'t setup any menus yet. Create a new menu.') . '</p></div>'; 200 } else { 201 $messages_div = '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>'; 202 } 203 } else { 204 add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) ); 205 } 206 207 // Get the admin header 33 208 require_once( 'admin-header.php' ); 34 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );35 36 function wp_reset_nav_menu() {37 wp_nav_menu_setup( true );38 return true;39 }40 41 $messages_div = '';42 $menu_id_in_edit = 0;43 $updated = false;44 $advanced_option_descriptions = 'no';45 46 // Check which menu is selected and if menu is in edit already47 if ( isset( $_GET['edit-menu'] ) ) {48 $menu_selected_id = (int) $_GET['edit-menu'];49 $updated = true;50 } elseif ( isset( $_POST[ 'menu-id-in-edit' ] ) ) {51 $menu_selected_id = (int) $_POST[ 'menu-id-in-edit' ];52 } else {53 $menu_selected_id = 0;54 }55 56 // Delete a menu57 if ( isset($_GET['delete-menu']) && $_GET['delete-menu'] > 0 ) {58 // if ( ! current_user_can('delete_menus') )59 // wp_die( __( 'Cheatin’ uh?' ));60 61 $menu_id = (int) $_GET['delete-menu'];62 check_admin_referer( 'delete_menu-' . $menu_id );63 64 wp_delete_nav_menu( $menu_id );65 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('Menu successfully deleted.') . '</p></div>';66 $menu_selected_id = 0;67 $updated = true;68 }69 70 // Default Menu to show71 $menus = wp_get_nav_menus();72 73 if ( empty($menus) && empty($_POST) ) {74 wp_create_default_nav_menu();75 $menus = wp_get_nav_menus();76 }77 78 if ( ! $menu_selected_id && ! empty($menus) )79 $menu_selected_id = $menus[0]->term_id;80 81 // Get the name of the current Menu82 $menu_title = '';83 $valid_menu = false;84 if ( $menu_selected_id > 0 ) {85 foreach ( $menus as $menu ) {86 if ( $menu->term_id == $menu_selected_id ) {87 $menu_title = $menu->name;88 $valid_menu = true;89 break;90 }91 }92 }93 94 if ( isset( $_POST['li-count'] ) )95 $post_counter = $_POST['li-count'];96 else97 $post_counter = 0;98 99 // Create a new menu. Menus are stored as terms in the 'menu' taxonomy.100 if ( isset( $_POST['create-menu'] ) && ! $updated ) {101 $insert_menu_name = $_POST['create-menu-name'];102 103 if ( $insert_menu_name ) {104 $menu = wp_create_nav_menu( $insert_menu_name );105 if ( is_wp_error( $menu ) ) {106 $messages_div = '<div id="message" class="error fade below-h2"><p>' . $menu->get_error_message() . '</p></div>';107 } else {108 $menus[$menu->term_id] = $menu;109 $menu_selected_id = $menu->term_id;110 $menu_id_in_edit = $menu_selected_id;111 $menu_title = $menu->name;112 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . sprintf( __('“%s” menu has been created.'), esc_html( $menu->name ) ) . '</p></div>';113 $post_counter = 0;114 }115 } else {116 $messages_div = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>';117 }118 $updated = true;119 }120 121 if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {122 $menu_items = wp_get_nav_menu_items( $menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );123 $parent_menu_ids = array();124 125 // Loop through all POST variables126 for ( $k = 1; $k <= $post_counter; $k++ ) {127 $db_id = isset( $_POST['item-dbid'.$k] )? $_POST['item-dbid'.$k] : 0;128 $object_id = isset( $_POST['item-postmenu'.$k] )? $_POST['item-postmenu'.$k] : 0;129 $parent_id = isset( $_POST['item-parent'.$k] )? $_POST['item-parent'.$k] : 0;130 $custom_title = isset( $_POST['item-title'.$k] )? $_POST['item-title'.$k] : '';131 $custom_linkurl = ( isset( $_POST['item-url'.$k] ) && 'custom' == $_POST['item-type'.$k] ) ? $_POST['item-url'.$k] : '';132 $custom_description = isset( $_POST['item-description'.$k] )? $_POST['item-description'.$k] : '';133 134 // doesn't seem to be used by UI135 $position = isset( $_POST['item-position'.$k] )? $_POST['item-position'.$k] : 0;136 $linktype = isset( $_POST['item-type'.$k] )? $_POST['item-type'.$k] : 'custom';137 $custom_anchor_title = isset( $_POST['item-attr-title'.$k] )? $_POST['item-attr-title'.$k] : $custom_title;138 $new_window = isset( $_POST['item-target'.$k] )? $_POST['item-target'.$k] : 0;139 140 $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,141 'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position,142 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ),143 'post_content' => $custom_description, 'post_title' => $custom_title );144 145 if ( $parent_id > 0 && isset( $parent_menu_ids[$parent_id] ) )146 $post['post_parent'] = $parent_menu_ids[$parent_id];147 148 // New menu item149 if ( $db_id == 0 ) {150 $db_id = wp_insert_post( $post );151 } elseif ( isset( $menu_items[$db_id] ) ) {152 $post['ID'] = $db_id;153 wp_update_post( $post );154 unset( $menu_items[$db_id] );155 }156 $parent_menu_ids[ $k ] = $db_id;157 158 update_post_meta( $db_id, 'menu_type', $linktype );159 update_post_meta( $db_id, 'object_id', $object_id );160 if ( $new_window )161 update_post_meta( $db_id, 'menu_new_window', 1 );162 else163 update_post_meta( $db_id, 'menu_new_window', 0 );164 if ( $custom_linkurl )165 update_post_meta( $db_id, 'menu_link', esc_url_raw( $custom_linkurl ) );166 167 }168 if ( !empty( $menu_items ) ) {169 foreach ( array_keys( $menu_items ) as $menu_id ) {170 wp_delete_post( $menu_id );171 }172 }173 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';174 }175 176 209 ?> 177 210 <div class="wrap"> … … 181 214 <div class="hide-if-js error"><p><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></p></div> 182 215 183 <form onsubmit="wp_update_post_data();" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data"> 184 <?php if ( !empty($menus) && count($menus) > 1 ) : ?> 185 <ul class="subsubsub"> 186 <?php 187 foreach ( $menus as $menu ) { 188 $sep = end( $menus ) == $menu ? '' : ' | '; 189 if ( ( $menu_id_in_edit == $menu->term_id ) || ( $menu_selected_id == $menu->term_id ) ) { ?> 190 <li><a href='nav-menus.php?edit-menu=<?php echo esc_attr($menu->term_id); ?>' class="current"><?php echo esc_html( $menu->name ); ?></a><?php echo $sep; ?></li> 191 <?php } else { ?> 192 <li><a href='nav-menus.php?edit-menu=<?php echo esc_attr($menu->term_id); ?>'><?php echo esc_html( $menu->name ); ?></a><?php echo $sep; ?></li> 193 <?php } 194 } 195 ?> 196 </ul> 197 <?php endif; ?> 198 199 <div id="menu-management" class="metabox-holder has-right-sidebar"> 216 <?php if ( !empty($nav_menus) && count($nav_menus) > 1 ) : ?> 217 <ul class="subsubsub"> 218 <?php 219 foreach ( $nav_menus as $_nav_menu ) { 220 $sep = end( $nav_menus ) == $_nav_menu ? '' : ' | '; 221 222 if ( $nav_menu_selected_id == $_nav_menu->term_id ) 223 echo '<li><a href="'. admin_url( 'nav-menus.php?action=edit&menu=' . esc_attr($_nav_menu->term_id) ) .'" class="current">'. esc_html( $_nav_menu->name ) .'</a>'. $sep .'</li>'; 224 else 225 echo '<li><a href="'. admin_url( 'nav-menus.php?action=edit&menu=' . esc_attr($_nav_menu->term_id) ) .'">'. esc_html( $_nav_menu->name ) .'</a>'. $sep .'</li>'; 226 } 227 ?> 228 </ul> 229 <?php endif; ?> 230 231 <div id="menu-management" class="metabox-holder has-right-sidebar"> 232 <form id="update-nav-menu" onsubmit="wp_update_post_data();" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data"> 233 <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> 234 <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> 235 <?php wp_nonce_field( 'update-nav_menu' ); ?> 236 <input type="hidden" name="action" value="update" /> 237 <input type="hidden" name="li-count" id="li-count" value="0" /> 238 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 239 200 240 <div id="post-body"> 201 241 <div id="post-body-content"> 202 <div id="normal-sortables" class="meta-box-sortables ui-sortable"> 203 <?php if ( $valid_menu and ! empty( $menus ) ) : ?> 242 <?php if ( is_nav_menu($nav_menu_selected_id) ) : ?> 204 243 <div id="menu-container" class="postbox"> 205 <h3 class="hndle"><?php echo esc_html( $ menu_title ); ?></h3>244 <h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3> 206 245 <div class="inside"> 207 <input type="hidden" name="li-count" id="li-count" value="0" /> 208 <input type="hidden" name="menu-id-in-edit" id="menu-id-in-edit" value="<?php echo esc_attr( $menu_selected_id ); ?>" /> 209 <?php 210 if ( $menu_selected_id > 0 ) 211 echo wp_get_nav_menu( array( 'type' => 'backend', 'menu' => $menu_selected_id, 'ul_class' => 'menu' ) ); 212 ?> 213 214 <div id="queue" class="hide"> 215 </div><!--/#queue--> 246 247 <?php echo wp_get_nav_menu( array( 'context' => 'backend', 'menu' => $nav_menu_selected_id ) ); ?> 248 216 249 </div><!-- /.inside --> 217 250 <!-- /#nav-menu-canvas .postbox--> 218 251 </div> 219 <p> 220 <script type="text/javascript"> 221 wp_update_post_data(); 222 </script> 223 <a class="submitdelete deletion" href="<?php echo wp_nonce_url( admin_url('nav-menus.php?delete-menu=' . $menu_selected_id), 'delete_menu-' . $menu_selected_id ); ?>"><?php _e('Delete Menu'); ?></a> 224 <input class="button-primary save" name="save_menu" type="submit" value="<?php esc_attr_e('Save All Changes'); ?>" /> 225 <br class="clear" /> 226 </p> 252 <script type="text/javascript"> 253 wp_update_post_data(); 254 </script> 227 255 <?php endif; ?> 228 </div><!-- /#normal-sortables-->229 256 </div><!-- /#post-body-content--> 230 257 </div><!--- /#post-body --> 231 258 <div id="menu-settings-column" class="inner-sidebar"> 232 <div id="side-sortables" class="meta-box-sortables ui-sortable"> 233 234 <div id="create-menu" class="postbox"> 235 <h3 class="hndle"><?php esc_html_e('Create Menu'); ?></h3> 236 <div class="inside"> 237 <p> 238 <input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value="" /> 239 <input type="submit" name="create-menu" id="create-menu" class="button" value="<?php esc_attr_e('Create Menu'); ?>" /> 240 </p> 241 </div><!-- /.inside--> 242 </div><!--END #create-menu--> 243 244 <div id="add-custom-link" class="postbox"> 245 <h3 class="hndle"><?php esc_html_e('Add a Custom Link'); ?></h3> 246 <div class="inside"> 247 <p id="menu-item-url-wrap"> 248 <label class="howto" for="menu-item-url"> 249 <span><?php _e('URL'); ?></span> 250 <input id="menu-item-url" name="menu-item-url" type="text" class="code" value="http://" /> 251 </label> 252 </p> 253 <br class="clear" /> 254 <p id="menu-item-name-wrap"> 255 <label class="howto" for="custom-menu-item-name"> 256 <span><?php _e('Text'); ?></span> 257 <input id="menu-item-name" type="text" class="regular-text" value="<?php echo esc_attr( __('Menu Item') ); ?>" /> 258 </label> 259 </p> 260 261 <p class="button-controls"> 262 <a class="show-all"><?php _e('View All'); ?></a> 263 <a class="hide-all"><?php _e('Hide All'); ?></a> 264 </p> 265 <div id="available-links" class="list-wrap"> 266 <div class="list-container"> 267 <ul class="list"> 268 <?php $items_counter = wp_nav_menu_get_custom_links( 0, 'default' ); ?> 269 </ul> 270 </div><!-- /.list-container--> 271 </div><!-- /#available-links--> 272 <p class="add-to-menu"> 273 <a class="button"><?php _e('Add to Menu'); ?></a> 274 </p> 275 <br class="clear" /> 276 </div><!-- /.inside--> 277 </div><!-- /#add-custom-link--> 278 279 <div id="add-pages" class="postbox"> 280 <h3 class="hndle"><?php esc_html_e('Add an Existing Page'); ?></h3> 281 <div class="inside"> 282 <?php 283 $pages_args = array( 284 'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 285 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '', 286 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0 287 ); 288 $page_name = ''; 289 $pages_array = get_pages( $pages_args ); 290 if ( $pages_array ) { 291 foreach ( $pages_array as $post ) { 292 $page_name .= $post->post_title . '|'; 293 } 294 } else { 295 $page_name = __('No pages available'); 296 } 297 ?> 298 <script type="text/javascript" charset="<?php bloginfo('charset'); ?>"> 299 jQuery(document).ready(function(){ 300 var posts = "<?php echo esc_js( $page_name ); ?>".split('|'); 301 jQuery('#add-pages .quick-search').autocomplete(posts); 302 303 304 jQuery('#add-pages .quick-search').result(function(event, data, formatted) { 305 jQuery('#add-pages .list-wrap').css('display','block'); 306 jQuery("#add-pages .list-wrap li:contains('" + data + "')").css('display','block'); 307 jQuery('#add-pages .show-all').hide(); 308 jQuery('#add-pages .hide-all').show(); 309 }); 310 }); 311 </script> 312 <p> 313 <input type="text" class="quick-search regular-text" value="" /> 314 <a class="quick-search-submit button"><?php _e('Search'); ?></a> 315 </p> 316 317 <p class="button-controls"> 318 <a class="show-all"><?php _e('View All'); ?></a> 319 <a class="hide-all"><?php _e('Hide All'); ?></a> 320 </p> 321 322 <div id="existing-pages" class="list-wrap"> 323 <div class="list-container"> 324 <ul class="list"> 325 <?php $items_counter = wp_nav_menu_get_pages( $items_counter, 'default' ); ?> 326 </ul> 327 </div><!-- /.list-container--> 328 </div><!-- /#existing-pages--> 329 <p class="add-to-menu enqueue"> 330 <a class="button"><?php _e('Add to Menu'); ?></a> 331 </p> 332 <br class="clear" /> 333 </div><!-- /.inside--> 334 </div><!--END #add-pages--> 335 336 <div id="add-categories" class="postbox"> 337 <h3 class="hndle"><?php esc_html_e('Add an Existing Category'); ?></h3> 338 <div class="inside"> 339 <?php 340 // Custom GET categories query 341 // @todo Use API 342 $categories = $wpdb->get_results("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' ORDER BY term_id ASC"); 343 $cat_name = ''; 344 if ( $categories ) { 345 foreach ( $categories as $category ) { 346 $cat_id = $category->term_id; 347 $cat_args = array( 348 'orderby' => 'name', 349 'include' => $cat_id, 350 'hierarchical' => 1, 351 'order' => 'ASC', 352 ); 353 $category_names = get_categories( $cat_args ); 354 if ( isset( $category_names[0]->name ) ) { 355 $cat_name .= htmlentities( $category_names[0]->name ).'|'; 356 } 357 } 358 } else { 359 $cat_name = __('No categories available'); 360 } 361 ?> 362 <script type="text/javascript" charset="<?php bloginfo('charset'); ?>"> 363 jQuery(document).ready(function(){ 364 var categories = "<?php echo esc_js($cat_name); ?>".split('|'); 365 jQuery('#add-categories .quick-search').autocomplete(categories); 366 jQuery('#add-categories .quick-search').result(function(event, data, formatted) { 367 jQuery('#add-categories .list-wrap').css('display','block'); 368 jQuery("#add-categories .list-wrap li:contains('" + data + "')").css('display','block'); 369 jQuery('#add-categories .show-all').hide(); 370 jQuery('#add-categories .hide-all').show(); 371 }); 372 }); 373 </script> 374 <p> 375 <input type="text" class="quick-search regular-text" value="" /> 376 <a class="quick-search-submit button"><?php _e('Search'); ?></a> 377 </p> 378 379 <p class="button-controls"> 380 <a class="show-all"><?php _e('View All'); ?></a> 381 <a class="hide-all"><?php _e('Hide All'); ?></a> 382 </p> 383 384 <div id="existing-categories" class="list-wrap"> 385 <div class="list-container"> 386 <ul class="list"> 387 <?php $items_counter = wp_nav_menu_get_categories( $items_counter, 'default' ); ?> 388 </ul> 389 </div><!-- /.list-container--> 390 </div><!-- /#existing-categories--> 391 <p class="add-to-menu enqueue"> 392 <a class="button"><?php _e('Add to Menu'); ?></a> 393 </p> 394 <br class="clear" /> 395 </div><!-- /.inside--> 396 </div><!--END #add-categories--> 397 </div><!-- /#side-sortables--> 259 260 <?php do_meta_boxes( 'menus', 'side', null ); ?> 261 398 262 </div><!-- /#menu-settings-column --> 399 <br class="clear" />400 < /div><!-- /.metabox-holder has-right-sidebar-->401 </ form>263 </form><!--/#update-nav-menu--> 264 <br class="clear" /> 265 </div><!-- /.metabox-holder has-right-sidebar--> 402 266 </div><!-- /.wrap--> 403 267 404 268 <div id="menu-item-settings"> 405 269 <p class="description"> 406 <label for="edit- item-title">270 <label for="edit-menu-item-title"> 407 271 <?php _e( 'Menu Title' ); ?><br /> 408 <input type="text" id="edit- item-title" class="widefat" name="edit-item-title" value="" tabindex="1" />409 </label> 410 </p> 411 <p class="description"> 412 <label for="edit- item-url">272 <input type="text" id="edit-menu-item-title" class="widefat" name="edit-menu-item-title" value="" tabindex="1" /> 273 </label> 274 </p> 275 <p class="description"> 276 <label for="edit-menu-item-url"> 413 277 <?php _e( 'URL' ); ?><br /> 414 <input type="text" id="edit- item-url" class="widefat code" name="edit-item-url" value="" tabindex="2" />415 </label> 416 </p> 417 <p class="description"> 418 <label for="edit- item-attr-title">419 <?php _e( ' Attribute Title' ); ?><br />420 <input type="text" id="edit- item-attr-title" class="widefat" name="edit-item-attr-title" value="" tabindex="3" />421 </label> 422 </p> 423 <p class="description"> 424 <label for="edit- item-target">425 <?php _e( ' Open Link in a new window' ); ?><br />426 <select id="edit- item-target" class="widefat" name="edit-item-target">427 <option value=" 1">Yes</option>428 <option value=" 0">No</option>278 <input type="text" id="edit-menu-item-url" class="widefat code" name="edit-menu-item-url" value="" tabindex="2" /> 279 </label> 280 </p> 281 <p class="description"> 282 <label for="edit-menu-item-attr-title"> 283 <?php _e( 'Title Attribute' ); ?><br /> 284 <input type="text" id="edit-menu-item-attr-title" class="widefat" name="edit-menu-item-attr-title" value="" tabindex="3" /> 285 </label> 286 </p> 287 <p class="description"> 288 <label for="edit-menu-item-target"> 289 <?php _e( 'Link Target' ); ?><br /> 290 <select id="edit-menu-item-target" class="widefat" name="edit-menu-item-target" tabindex="4"> 291 <option value="_self">Same window or tab</option> 292 <option value="_blank">New window or tab</option> 429 293 </select> 430 294 </label> 431 295 </p> 432 296 <p class="description"> 433 <label for="edit-item-description"> 434 <?php _e( 'Description' ); ?><br /> 435 <textarea id="edit-item-description" class="widefat" rows="3" name="edit-item-description" tabindex="4" /></textarea> 297 <label for="edit-menu-item-classes"> 298 <?php _e( 'CSS Classes (optional)' ); ?><br /> 299 <input type="text" id="edit-menu-item-classes" class="widefat code" name="edit-menu-item-classes" value="" tabindex="5" /> 300 </label> 301 </p> 302 <p class="description"> 303 <label for="edit-menu-item-xfn"> 304 <?php _e( 'Link Relationship (XFN) (optional)' ); ?><br /> 305 <input type="text" id="edit-menu-item-xfn" class="widefat code" name="edit-menu-item-xfn" value="" tabindex="6" /> 306 </label> 307 </p> 308 <p class="description"> 309 <label for="edit-menu-item-description"> 310 <?php _e( 'Description (optional)' ); ?><br /> 311 <textarea id="edit-menu-item-description" class="widefat" rows="3" name="edit-menu-item-description" tabindex="7" /></textarea> 312 <span class="description">The description will be displayed in the menu if the current theme supports it.</span> 436 313 </label> 437 314 </p> 438 315 <p> 439 <a id=" cancel-save" class="submitdelete deletion"><?php _e('Cancel'); ?></a>440 <a id=" update-menu-item" class="save button-primary" tabindex="5"><?php _e('Save Changes'); ?></a>441 </p> 442 <input type="hidden" id="edit- item-id" name="edit-item-id" value="" />316 <a id="update-menu-item" class="save button-primary" tabindex="8"><?php _e('Save Changes'); ?></a> 317 <a id="cancel-save" class="submitdelete deletion" tabindex="9"><?php _e('Cancel'); ?></a> 318 </p> 319 <input type="hidden" id="edit-menu-item-id" name="edit-item-id" value="" /> 443 320 </div><!-- /#menu-item-settings--> 444 321 -
trunk/wp-content/themes/twentyten/header.php
r13566 r13704 44 44 <div id="access"> 45 45 <div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div> 46 <?php wp_nav_menu( 'sort_column=menu_order ' ); ?>46 <?php wp_nav_menu( 'sort_column=menu_order&container_class=menu-header' ); ?> 47 47 </div><!-- #access --> 48 48 </div><!-- #masthead --> -
trunk/wp-content/themes/twentyten/style.css
r13566 r13704 153 153 154 154 /* The main theme structure */ 155 #access .menu ,155 #access .menu-header, 156 156 #colophon, 157 157 #branding, … … 361 361 float:left; 362 362 } 363 #access .menu {363 #access .menu-header { 364 364 font-size: 13px; 365 365 margin-left: 12px; 366 366 } 367 #access .menu ul {367 #access .menu-header ul { 368 368 list-style: none; 369 369 margin: 0; 370 370 } 371 #access .menu li {371 #access .menu-header li { 372 372 float:left; 373 373 position: relative; -
trunk/wp-includes/nav-menu-template.php
r13694 r13704 24 24 */ 25 25 function wp_nav_menu( $args = array() ) { 26 $defaults = array( 'menu' => '', ' menu_class' => 'menu', 'format' => 'div', 'echo' => true,27 'fallback_cb' => 'wp_page_menu', ' link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );26 $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true, 27 'fallback_cb' => 'wp_page_menu', 'before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', ); 28 28 29 29 $args = wp_parse_args( $args, $defaults ); … … 46 46 } 47 47 48 if ( $menu)48 if ( !is_wp_error($menu) ) 49 49 $args->menu = $menu->term_id; 50 50 $nav_menu = ''; 51 51 52 if ( 'div' == $args->format ) { 53 if ( $menu ) 54 $nav_menu .= '<div id="menu-' . $menu->slug . '" class="' . esc_attr($args->menu_class) . '">'; 55 else 56 $nav_menu .= '<div id="menu-default">'; 52 if ( 'div' == $args->container ) { 53 $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ''; 54 55 if ( is_nav_menu($menu) ) { 56 $nav_menu .= '<div id="menu-' . $menu->slug . '"'. $class .'>'; 57 } else { 58 $nav_menu .= '<div'. $class .'>'; 59 } 57 60 } 58 61 59 62 $nav_menu .= wp_get_nav_menu( $args ); 60 63 61 if ( 'div' == $args-> format)64 if ( 'div' == $args->container ) 62 65 $nav_menu .= '</div>'; 63 64 $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu );66 67 $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); 65 68 66 69 if ( $args->echo ) … … 81 84 **/ 82 85 function wp_get_nav_menu( $args = array() ) { 83 $defaults = array( 'menu' => '', 'menu_class' => 'menu', ' ul_class' => '', 'format' => 'div', 'type' => 'frontend',84 'fallback_cb' => '', ' link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );86 $defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend', 87 'fallback_cb' => '', 'before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', ); 85 88 86 89 $args = wp_parse_args( $args, $defaults ); … … 88 91 $args = (object) $args; 89 92 93 // Variable setup 94 $nav_menu = ''; 95 $items = ''; 96 $current_parent = 0; 97 $parent_stack = array(); 98 $parent_menu_order = array(); 99 100 // Get the menu object 90 101 $menu = wp_get_nav_menu_object( $args->menu ); 91 102 92 // If no menu was found, call the fallback_cb 93 if ( !$menu || is_wp_error($menu) ) { 103 // If the menu exists, get it's items. 104 if ( $menu && !is_wp_error($menu) ) 105 $menu_items = wp_get_nav_menu_items( $menu->term_id, 'backend' ); 106 107 // If no menu was found or if the menu has no items, call the fallback_cb 108 if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) { 94 109 if ( function_exists($args->fallback_cb) ) { 95 110 $_args = array_merge( (array)$args, array('echo' => false) ); … … 98 113 } 99 114 100 $menu_items = wp_get_nav_menu_items( $menu->term_id ); 101 $nav_menu = ''; 102 $parent_stack = array(); 103 $current_parent = 0; 104 $parent_menu_order = array(); 105 106 // Setup parentage 107 foreach ( $menu_items as $menu_item ) 108 $parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order; 109 110 $ul_class = isset($args->ul_class) ? ' class="'. $args->ul_class .'"' : ''; 111 $nav_menu .= '<ul'. $ul_class .'>'; 112 113 // Display Loop 114 foreach ( $menu_items as $key => $menu_item ) : 115 foreach ( $menu_items as $key => $menu_item ) { 115 116 // Setup the $menu_item variables 116 $menu_item = wp_setup_nav_menu_item( $menu_item ); 117 118 $maybe_value = 'frontend' == $args->type ? '' : ' value="'. $menu_item->ID .'"'; 119 $classes = 'frontend' == $args->type ? ' class="menu-item-'. $menu_item->type . $menu_item->li_class .'"' : ''; 120 121 $nav_menu .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>'; 122 $nav_menu .= wp_get_nav_menu_item( $menu_item, $args->type, $args ); 117 $menu_item = wp_setup_nav_menu_item( $menu_item, 'frontend' ); 118 119 $type = sanitize_title_with_dashes( $menu_item->append ); 120 $maybe_value = 'frontend' == $args->context ? '' : ' value="'. $menu_item->ID .'"'; 121 $classes = 'frontend' == $args->context ? ' class="menu-item-type-'. $type . $menu_item->li_class .'"' : ''; 122 123 $items .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>'; 124 $items .= wp_get_nav_menu_item( $menu_item, $args->context, $args ); 123 125 124 126 // Indent children 125 127 $last_item = ( count( $menu_items ) == $menu_item->menu_order ); 126 if ( $last_item || $current_parent != $menu_items[ $key + 1]->post_parent ) {127 if ( $last_item || in_array( $menu_items[ $key + 1]->post_parent, $parent_stack ) ) {128 $ nav_menu.= '</li>';129 while ( !empty( $parent_stack ) && ($last_item || $menu_items[ $key + 1]->post_parent != $current_parent ) ) {130 $ nav_menu.= '</ul></li>';128 if ( $last_item || $current_parent != $menu_items[$key + 1]->post_parent ) { 129 if ( $last_item || in_array( $menu_items[$key + 1]->post_parent, $parent_stack ) ) { 130 $items .= '</li>'; 131 while ( !empty( $parent_stack ) && ($last_item || $menu_items[$key + 1]->post_parent != $current_parent ) ) { 132 $items .= '</ul></li>'; 131 133 $current_parent = array_pop( $parent_stack ); 132 134 } … … 134 136 array_push( $parent_stack, $current_parent ); 135 137 $current_parent = $menu_item->ID; 136 $ nav_menu .= '<ul>';138 $items .= '<ul class="sub-menu">'; 137 139 } 138 140 } else { 139 $nav_menu .= '</li>'; 140 } 141 142 endforeach; 141 $items .= '</li>'; 142 } 143 } 144 145 // CSS class 146 $ul_class = $args->menu_class ? ' class="'. $args->menu_class .'"' : ''; 147 $nav_menu .= '<ul'. $ul_class .'>'; 148 149 // Allow plugins to hook into the menu to add their own <li>'s 150 if ( 'frontend' == $args->context ) { 151 $items = apply_filters( 'wp_nav_menu_items', $items, $args ); 152 $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); 153 $nav_menu .= $items; 154 } else { 155 $nav_menu .= $items; 156 } 143 157 144 158 $nav_menu .= '</ul>'; … … 148 162 149 163 /** 150 * Returns a menu item.164 * Returns the menu item formatted based on it's context. 151 165 * 152 166 * @since 3.0.0 153 167 * 154 * @param object $menu_item The menu item 155 * @param string $context frontend|backend|default 156 * @param array $args See wp_get_nav_menu(). 157 **/ 158 function wp_get_nav_menu_item( $menu_item, $context, $args = array() ) { 159 $item = ''; 168 * @param string $menu_item The menu item to format. 169 * @param string $context The context to which the menu item will be formatted to. 170 * @param string $args Optional. Args used for the 'template' context. 171 * @return string $output The menu formatted menu item. 172 */ 173 function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array() ) { 174 $output = ''; 160 175 switch ( $context ) { 161 176 case 'frontend': 162 $attr_title = ( isset($menu_item->anchor_title) && '' != $menu_item->anchor_title ) ? ' title="'. esc_attr($menu_item->anchor_title) .'"' : ''; 163 $href = isset($menu_item->link) ? ' href="'. esc_url($menu_item->link) .'"' : ''; 164 165 $item .= '<a'. $attr_title . $href . $menu_item->target .'>'; 166 $item .= $args->before_link . esc_html( $menu_item->title ) . $args->after_link; 167 $item .= '</a>'; 177 $attributes = ( isset($menu_item->anchor_title) && '' != $menu_item->anchor_title ) ? ' title="'. esc_attr($menu_item->anchor_title) .'"' : ''; 178 $attributes .= ( isset($menu_item->target) && '' != $menu_item->target ) ? ' target="'. esc_attr($menu_item->target) .'"' : ''; 179 $attributes .= ( isset($menu_item->classes) && '' != $menu_item->classes ) ? ' class="'. esc_attr($menu_item->classes) .'"' : ''; 180 $attributes .= ( isset($menu_item->xfn) && '' != $menu_item->xfn ) ? ' rel="'. esc_attr($menu_item->xfn) .'"' : ''; 181 $attributes .= ( isset($menu_item->url) && '' != $menu_item->url ) ? ' href="'. esc_attr($menu_item->url) .'"' : ''; 182 183 $output .= esc_html( $args->before_link ); 184 $output .= '<a'. $attributes .'>'; 185 $output .= esc_html( $args->before_title . $menu_item->title . $args->after_title ); 186 $output .= '</a>'; 187 $output .= esc_html( $args->after_link ); 168 188 169 189 break; 170 190 171 191 case 'backend': 172 $ item.= '<dl><dt>';173 $ item.= '<span class="item-title">'. esc_html($menu_item->title) .'</span>';174 $ item.= '<span class="item-controls">';175 $ item .= '<span class="item-type">'. esc_html($menu_item->type) .'</span>';192 $output .= '<dl><dt>'; 193 $output .= '<span class="item-title">'. esc_html($menu_item->title) .'</span>'; 194 $output .= '<span class="item-controls">'; 195 $output .= '<span class="item-type">'. esc_html($menu_item->append) .'</span>'; 176 196 177 197 // Actions 178 $ item .= '<a class="item-edit thickbox" id="edit'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | ';179 $ item.= '<a class="item-delete" id="delete'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'">'. __('Delete') .'</a>';180 181 $ item.= '</dt></dl>';198 $output .= '<a class="item-edit thickbox" id="edit'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | '; 199 $output .= '<a class="item-delete" id="delete'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'">'. __('Delete') .'</a>'; 200 201 $output .= '</dt></dl>'; 182 202 183 203 // Menu Item Settings 184 $item .= '<input type="hidden" id="item-dbid'. esc_attr( $menu_item->menu_order ) .'" name="item-dbid'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->ID ) .'" />'; 185 $item .= '<input type="hidden" id="item-postmenu'. esc_attr( $menu_item->menu_order ) .'" name="item-postmenu'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'object_id', true ) ) .'" />'; 186 $item .= '<input type="hidden" id="item-parent'. esc_attr( $menu_item->menu_order ) .'" name="item-parent'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->parent_item ) .'" />'; 187 $item .= '<input type="hidden" id="item-position'. esc_attr( $menu_item->menu_order ) .'" name="item-position'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" />'; 188 $item .= '<input type="hidden" id="item-type'. esc_attr( $menu_item->menu_order ) .'" name="item-type'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'menu_type', true ) ) .'" />'; 189 $item .= '<input type="hidden" id="item-title'. esc_attr( $menu_item->menu_order ) .'" name="item-title'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->title ) .'" />'; 190 $item .= '<input type="hidden" id="item-url'. esc_attr( $menu_item->menu_order ) .'" name="item-url'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->link ) .'" />'; 191 $item .= '<input type="hidden" id="item-description'. esc_attr( $menu_item->menu_order ) .'" name="item-description'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->description ) .'" />'; 192 $item .= '<input type="hidden" id="item-attr-title'. esc_attr( $menu_item->menu_order ) .'" name="item-attr-title'. esc_attr( $menu_item->menu_order ) .'" value="'.esc_attr( $menu_item->post_excerpt ) .'" />'; 193 $item .= '<input type="hidden" id="item-target'. esc_attr( $menu_item->menu_order ) .'" name="item-target'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ? '1' : '0' ) .'" />'; 194 break; 195 196 case 'default': 197 $menu_id = 'menu-item-' . $menu_item->ID; 198 $item .= '<label class="item-title"><input type="checkbox" id="'. esc_attr($menu_id) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->link ) .'" />'. $menu_item->title .'</label>'; 199 200 // Menu Item Settings 201 $item .= '<input type="hidden" class="item-type" value="'. esc_attr( $menu_item->type ) .'" />'; 202 $item .= '<input type="hidden" class="item-title" value="'. esc_attr( $menu_item->title ) .'" />'; 203 $item .= '<input type="hidden" class="item-url" value="'. esc_attr( $menu_item->link ) .'" />'; 204 $item .= '<input type="hidden" class="item-dbid" value="'. esc_attr( $menu_item->ID ) .'" />'; 205 $item .= '<input type="hidden" class="item-parent" value="'. esc_attr( $menu_item->parent_item ) .'" />'; 206 $item .= '<input type="hidden" class="item-description" value="'. esc_attr( $menu_item->description ) .'" />'; 207 break; 208 } 209 return apply_filters( 'wp_get_nav_menu_item', $item ); 204 $output .= '<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->ID ) .'" />'; 205 $output .= '<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->object_id ) .'" />'; 206 $output .= '<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->post_parent ) .'" />'; 207 $output .= '<input type="hidden" name="menu-item-position[]" id="menu-item-position'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" />'; 208 $output .= '<input type="hidden" name="menu-item-type[]" id="menu-item-type'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->type ) .'" />'; 209 $output .= '<input type="hidden" name="menu-item-append[]" id="menu-item-append'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->append ) .'" />'; 210 $output .= '<input type="hidden" name="menu-item-title[]" id="menu-item-title'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->title ) .'" />'; 211 $output .= '<input type="hidden" name="menu-item-url[]" id="menu-item-url'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->url ) .'" />'; 212 $output .= '<input type="hidden" name="menu-item-description[]" id="menu-item-description'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->description ) .'" />'; 213 $output .= '<input type="hidden" name="menu-item-classes[]" id="menu-item-classes'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->classes ) .'" />'; 214 $output .= '<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->xfn ) .'" />'; 215 $output .= '<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title'. esc_attr( $menu_item->menu_order ) .'" value="'.esc_attr( $menu_item->post_excerpt ) .'" />'; 216 $output .= '<input type="hidden" name="menu-item-target[]" id="menu-item-target'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->target ) .'" />'; 217 break; 218 219 case 'custom': 220 $menu_id = 'menu-item-' . $menu_item->db_id; 221 $output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( $menu_id ) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>'; 222 223 // Menu item hidden fields 224 $output .= '<input type="hidden" class="menu-item-db-id" value="'. esc_attr( $menu_item->db_id ) .'" />'; 225 $output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />'; 226 $output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->parent_id ) .'" />'; 227 $output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />'; 228 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />'; 229 $output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />'; 230 $output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />'; 231 $output .= '<input type="hidden" class="menu-item-target" value="'. esc_attr( $menu_item->target ) .'" />'; 232 $output .= '<input type="hidden" class="menu-item-attr_title" value="'. esc_attr( $menu_item->attr_title ) .'" />'; 233 $output .= '<input type="hidden" class="menu-item-description" value="'. esc_attr( $menu_item->description ) .'" />'; 234 $output .= '<input type="hidden" class="menu-item-classes" value="'. esc_attr( $menu_item->classes ) .'" />'; 235 $output .= '<input type="hidden" class="menu-item-xfn" value="'. esc_attr( $menu_item->xfn ) .'" />'; 236 break; 237 238 case 'taxonomy': 239 case 'post_type': 240 $menu_id = 'menu-item-' . $menu_item->db_id; 241 $output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( $menu_id ) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>'; 242 243 // Menu item hidden fields 244 $output .= '<input type="hidden" class="menu-item-db-id" value="0" />'; 245 $output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />'; 246 $output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->parent_id ) .'" />'; 247 $output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />'; 248 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />'; 249 $output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />'; 250 $output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />'; 251 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />'; 252 break; 253 } 254 255 return $output; 210 256 } 211 257 ?> -
trunk/wp-includes/nav-menu.php
r13580 r13704 47 47 48 48 return $menu_obj; 49 }50 51 /**52 * Returns all Navigation Menu objects.53 *54 * @since 3.0.055 *56 * @return array menu objects57 */58 function wp_get_nav_menus() {59 return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );60 49 } 61 50 … … 114 103 115 104 /** 116 * Creates a nav menu named 'Menu 1'. 117 * 118 * This function is called if the user doesn't have any nav menus. 119 * It grabs the first 14 pages, and creates a new default menu. 120 * 121 * @since 3.0.0 122 */ 123 function wp_create_default_nav_menu() { 124 $menu = wp_create_nav_menu( __('Menu 1'), array('slug' => 'menu-1') ); 125 126 if ( is_wp_error($menu) ) 127 return; 128 129 $pages = get_pages( array('parent' => 0, 'number' => 15) ); 130 $counter = 1; 131 foreach ( $pages as $page ) { 132 $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) ); 133 $item_id = wp_insert_post($item, true); 134 update_post_meta( $item_id, 'menu_type', 'page' ); 135 update_post_meta( $item_id, 'object_id', $page->ID ); 136 update_post_meta( $item_id, 'menu_new_window', 0 ); 137 $counter++; 138 } 139 } 140 141 /** 142 * Returns the menu items of a navigation menu. 105 * Returns all Navigation Menu objects. 106 * 107 * @since 3.0.0 108 * 109 * @return array menu objects 110 */ 111 function wp_get_nav_menus() { 112 return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) ); 113 } 114 115 /** 116 * Returns all menu items of a navigation menu. 143 117 * 144 118 * @since 3.0.0 … … 180 154 181 155 /** 182 * Returns a menu item with all it's nessecary data populated. 183 * 184 * @since 3.0.0 185 * 186 * @param string $menu_item Menu item. 187 * @param string $type item|category|page. 188 * @param string $position position of the menu item. 189 * @return $menu_item 190 */ 191 function wp_setup_nav_menu_item( $menu_item, $type = 'item', $position = 0 ) { 192 global $parent_menu_order; 193 194 if ( 'item' == $type ) { 195 $menu_item->type = get_post_meta( $menu_item->ID, 'menu_type', true ); 196 $menu_item->object_id = get_post_meta( $menu_item->ID, 'object_id', true ); 197 $menu_item->target = ( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ) ? 'target="_blank"' : ''; 198 if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) ) 199 $menu_item->parent_item = $parent_menu_order[ $menu_item->post_parent ]; 200 else 201 $menu_item->parent_item = 0; 202 } elseif ( 'category' == $type ) { 203 $menu_item->type = $type; 204 $menu_item->object_id = $menu_item->term_id; 205 $menu_item->ID = $menu_item->term_id; 206 $menu_item->parent_item = $menu_item->parent; 207 $menu_item->menu_order = $position; 208 } elseif ( 'page' == $type ) { 209 $menu_item->type = $type; 210 $menu_item->object_id = $menu_item->ID; 211 $menu_item->parent_item = $menu_item->post_parent; 212 $menu_item->menu_order = $position; 213 } 214 215 switch ( $menu_item->type ) { 216 case 'page' : 217 $menu_item->link = get_page_link( $menu_item->object_id ); 218 219 if ( $menu_item->post_title == '' ) 220 $menu_item->title = get_the_title( $menu_item->object_id ); 221 else 222 $menu_item->title = $menu_item->post_title; 223 224 if ( $menu_item->post_content == '' ) 225 $menu_item->description = get_post_meta( $menu_item->ID, 'page-description', true ); 226 else 227 $menu_item->description = $menu_item->post_content; 228 $menu_item->append = _x('Page', 'menu nav item type'); 229 break; 230 case 'category' : 231 $menu_item->link = get_category_link( $menu_item->object_id ); 232 233 if ( empty($menu_item->post_title) ) { 234 $title_raw = get_category( $menu_item->object_id ); 235 $menu_item->title = $title_raw->cat_name; 236 } else { 237 $menu_item->title = $menu_item->post_title; 238 } 239 240 if ( empty($menu_item->post_content) ) 241 $menu_item->description = strip_tags( category_description( $menu_item->object_id ) ); 242 else 243 $menu_item->description = $menu_item->post_content; 244 $menu_item->append = _x('Category', 'menu nav item type'); 245 break; 246 case 'custom' : 247 default : 248 $menu_item->link = esc_url_raw( get_post_meta( $menu_item->ID, 'menu_link', true ) ); 249 $menu_item->title = $menu_item->post_title; 250 $menu_item->description = $menu_item->post_content; 251 $menu_item->append = _x('Custom', 'menu nav item type'); 252 break; 253 } 254 255 $menu_item->li_class = ''; 156 * Adds all the nav menu properties to the $menu_item. 157 * 158 * @since 3.0.0 159 * 160 * @param string $menu_item The menu item to modify 161 * @param string $menu_item_type The menu item type (template, custom, post_type, taxonomy). 162 * @param string $menu_item_object Optional. The menu item object type (post type or taxonomy). 163 * @return object $menu_item The modtified menu item. 164 */ 165 function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_object = '' ) { 256 166 global $wp_query; 257 167 258 if ( $menu_item->object_id == $wp_query->get_queried_object_id() ) 259 $menu_item->li_class = ' current_page_item'; 260 261 $menu_item->anchor_title = ''; 262 /* @todo: update to use tax/post data 263 264 //SET anchor title 265 if (isset($wp_custom_nav_menu_items->custom_anchor_title)) { 266 $anchor_title = $wp_custom_nav_menu_items->custom_anchor_title; 267 } 268 else { 269 $anchor_title = $title; 270 } 271 272 if ($queried_id == $wp_custom_nav_menu_items->post_id) { 273 $li_class = 'class="current_page_item"'; 274 } 275 276 if (isset($wp_custom_nav_menu_items->new_window)) { 277 if ($wp_custom_nav_menu_items->new_window > 0) { 278 $target = 'target="_blank"'; 279 } 280 else { 281 $target = ''; 282 } 283 } 284 */ 285 168 switch ( $menu_item_type ) { 169 case 'frontend': 170 $menu_item->db_id = (int) $menu_item->ID; 171 $menu_item->object_id = get_post_meta( $menu_item->ID, 'menu_item_object_id', true ); 172 $menu_item->parent_id = (int) $menu_item->post_parent; 173 $menu_item->type = get_post_meta( $menu_item->ID, 'menu_item_type', true ); 174 $menu_item->append = _x( get_post_meta( $menu_item->ID, 'menu_item_append', true ), 'nav menu item type' ); 175 176 $menu_item->title = $menu_item->post_title; 177 $menu_item->url = get_post_meta( $menu_item->ID, 'menu_item_url', true ); 178 $menu_item->target = get_post_meta( $menu_item->ID, 'menu_item_target', true ); 179 180 $menu_item->attr_title = strip_tags( $menu_item->post_excerpt ); 181 $menu_item->description = strip_tags( $menu_item->post_content ); 182 183 $menu_item->classes = get_post_meta( $menu_item->ID, 'menu_item_classes', true );; 184 $menu_item->xfn = get_post_meta( $menu_item->ID, 'menu_item_xfn', true ); 185 $menu_item->li_class = ( $menu_item->object_id == $wp_query->get_queried_object_id() ) ? ' current_page_item' : ''; 186 break; 187 188 case 'custom': 189 $menu_item->db_id = (int) $menu_item->ID; 190 $menu_item->object_id = (int) $menu_item->ID; 191 $menu_item->parent_id = (int) $menu_item->post_parent; 192 $menu_item->type = 'custom'; //$menu_item_type 193 $menu_item->append = _x( 'Custom', 'nav menu item type' ); 194 195 $menu_item->attr_title = strip_tags( $menu_item->post_excerpt ); 196 $menu_item->description = strip_tags( $menu_item->post_content ); 197 198 $menu_item->title = $menu_item->post_title; 199 $menu_item->url = get_post_meta( $menu_item->ID, 'menu_item_url', true ); 200 $menu_item->target = get_post_meta( $menu_item->ID, 'menu_item_target', true ); 201 break; 202 203 case 'post_type': 204 $menu_item->db_id = 0; 205 $menu_item->object_id = (int) $menu_item->ID; 206 $menu_item->parent_id = (int) $menu_item->post_parent; 207 $menu_item->type = $menu_item_type; 208 209 $object = get_post_type_object( $menu_item_object ); 210 $menu_item->append = _x( $object->singular_label, 'nav menu item type' ); 211 212 $menu_item->title = $menu_item->post_title; 213 $menu_item->url = get_post_permalink( $menu_item->ID ); 214 $menu_item->target = '_none'; 215 216 $menu_item->attr_title = ''; 217 $menu_item->description = strip_tags( $menu_item->post_content ); 218 break; 219 220 case 'taxonomy': 221 $menu_item->ID = $menu_item->term_id; 222 $menu_item->db_id = 0; 223 $menu_item->object_id = (int) $menu_item->term_id; 224 $menu_item->parent_id = (int) $menu_item->parent; 225 $menu_item->type = $menu_item_type; 226 227 $object = get_taxonomy( $menu_item_object ); 228 $menu_item->append = _x( $object->singular_label, 'nav menu item type' ); 229 230 $menu_item->title = $menu_item->name; 231 $menu_item->url = get_term_link( $menu_item, $menu_item_object ); 232 $menu_item->target = '_none'; 233 $menu_item->attr_title = ''; 234 $menu_item->description = strip_tags( $menu_item->description ); 235 break; 236 } 237 238 $menu_item->classes = get_post_meta( $menu_item->ID, 'menu_item_classes', true ); 239 $menu_item->xfn = get_post_meta( $menu_item->ID, 'menu_item_xfn', true ); 240 286 241 return $menu_item; 287 242 } -
trunk/wp-includes/script-loader.php
r13696 r13704 398 398 399 399 // Custom Navigation 400 $scripts->add( 'nav-menu-default-items', "/wp-admin/js/nav-menu-default-items$suffix.js", false, '20100 223' );401 $scripts->add( 'nav-menu-dynamic-functions', "/wp-admin/js/nav-menu-dynamic-functions$suffix.js", false, '20100 225b' );400 $scripts->add( 'nav-menu-default-items', "/wp-admin/js/nav-menu-default-items$suffix.js", false, '20100315' ); 401 $scripts->add( 'nav-menu-dynamic-functions', "/wp-admin/js/nav-menu-dynamic-functions$suffix.js", false, '20100315' ); 402 402 $scripts->localize( 'nav-menu-dynamic-functions', 'navMenuL10n', array( 403 403 'custom' => _x('Custom', 'menu nav item type'), … … 406 406 'thickbox' => _x('Edit Menu Item', 'Thickbox Title'), 407 407 'edit' => _x('Edit', 'menu item edit text'), 408 'warnDelete' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), 408 409 ) ); 409 410 -
trunk/wp-includes/taxonomy.php
r13626 r13704 161 161 function is_taxonomy( $taxonomy ) { 162 162 global $wp_taxonomies; 163 163 164 164 return isset($wp_taxonomies[$taxonomy]); 165 165 }
Note: See TracChangeset
for help on using the changeset viewer.