Ticket #11817: menus_awesomesauce_patch.diff
File menus_awesomesauce_patch.diff, 127.7 KB (added by , 15 years ago) |
---|
-
wp-includes/nav-menu-template.php
9 9 * menu_class - CSS class to use for the div container of the menu list. Defaults to 'menu'. 10 10 * format - Whether to format the ul. Defaults to 'div'. 11 11 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'. 12 * before _link - Output text before the link.13 * after _link - Output text after the link.14 * before_title - Output text before the link text.15 * before_title - Output text after the link text.12 * before - Text before the link text. 13 * after - Text after the link text. 14 * link_before - Text before the link. 15 * link_after - Text after the link. 16 16 * echo - Whether to echo the menu or return it. Defaults to echo. 17 *18 * TODO:19 17 * show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link. 20 18 * 21 19 * @since 3.0.0 … … 24 22 */ 25 23 function wp_nav_menu( $args = array() ) { 26 24 $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' => '', ); 25 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 26 'depth' => 0, 'walker' => '' ); 28 27 29 28 $args = wp_parse_args( $args, $defaults ); 30 29 $args = apply_filters( 'wp_nav_menu_args', $args ); … … 83 82 * @return mixed $output False if menu doesn't exists, else, returns the menu. 84 83 **/ 85 84 function wp_get_nav_menu( $args = array() ) { 86 $defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend', 87 'fallback_cb' => '', ' before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', );85 $defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend', 'depth' => 0, 86 'fallback_cb' => '', 'walker' => '', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', ); 88 87 89 88 $args = wp_parse_args( $args, $defaults ); 90 89 $args = apply_filters( 'wp_get_nav_menu_args', $args ); … … 93 92 // Variable setup 94 93 $nav_menu = ''; 95 94 $items = ''; 96 $current_parent = 0;97 $parent_stack = array();98 $parent_menu_order = array();99 95 100 96 // Get the menu object 101 97 $menu = wp_get_nav_menu_object( $args->menu ); 102 98 103 99 // If the menu exists, get it's items. 104 100 if ( $menu && !is_wp_error($menu) ) 105 $menu_items = wp_get_nav_menu_items( $menu->term_id, 'backend');101 $menu_items = wp_get_nav_menu_items( $menu->term_id, $args->context ); 106 102 107 103 // If no menu was found or if the menu has no items, call the fallback_cb 108 104 if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) { 109 if ( function_exists($args->fallback_cb) ) {110 $_args = array_merge( (array) $args, array('echo' => false) );105 if ( function_exists($args->fallback_cb) || is_callable( $args->fallback_cb ) ) { 106 $_args = array_merge( (array) $args, array('echo' => false) ); 111 107 return call_user_func( $args->fallback_cb, $_args ); 112 108 } 113 109 } 114 115 foreach ( $menu_items as $key => $menu_item ) {116 // Set up the $menu_item variables117 $menu_item = wp_setup_nav_menu_item( $menu_item, 'frontend' );118 119 $type = $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 110 123 $items .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>'; 124 $items .= wp_get_nav_menu_item( $menu_item, $args->context, $args ); 125 126 // Indent children 127 $last_item = ( count( $menu_items ) == $menu_item->menu_order ); 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>'; 133 $current_parent = array_pop( $parent_stack ); 134 } 135 } else { 136 array_push( $parent_stack, $current_parent ); 137 $current_parent = $menu_item->ID; 138 $items .= '<ul class="sub-menu">'; 139 } 140 } else { 141 $items .= '</li>'; 142 } 143 } 111 // Set up the $menu_item variables 112 foreach ( (array) $menu_items as $key => $menu_item ) 113 $menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item( $menu_item, 'frontend' ); 144 114 115 $items .= walk_nav_menu_tree( $menu_items, $args->depth, $args ); 116 145 117 // CSS class 146 118 $ul_class = $args->menu_class ? ' class="'. $args->menu_class .'"' : ''; 147 119 $nav_menu .= '<ul'. $ul_class .'>'; … … 174 146 $output = ''; 175 147 switch ( $context ) { 176 148 case 'frontend': 177 $attributes = ( isset($menu_item->a nchor_title) && '' != $menu_item->anchor_title ) ? ' title="'. esc_attr($menu_item->anchor_title) .'"' : '';149 $attributes = ( isset($menu_item->attr_title) && '' != $menu_item->attr_title ) ? ' title="'. esc_attr($menu_item->attr_title) .'"' : ''; 178 150 $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 151 $attributes .= ( isset($menu_item->xfn) && '' != $menu_item->xfn ) ? ' rel="'. esc_attr($menu_item->xfn) .'"' : ''; 181 152 $attributes .= ( isset($menu_item->url) && '' != $menu_item->url ) ? ' href="'. esc_attr($menu_item->url) .'"' : ''; 182 153 183 $output .= esc_html( $args->before _link);154 $output .= esc_html( $args->before ); 184 155 $output .= '<a'. $attributes .'>'; 185 $output .= esc_html( $args-> before_title . $menu_item->title . $args->after_title);156 $output .= esc_html( $args->link_before . apply_filters('the_title', $menu_item->title) . $args->link_after ); 186 157 $output .= '</a>'; 187 $output .= esc_html( $args->after _link);158 $output .= esc_html( $args->after ); 188 159 189 160 break; 190 161 191 162 case 'backend': 192 163 $output .= '<dl><dt>'; 193 $output .= '<span class="item-title">'. esc_html( $menu_item->title) .'</span>';164 $output .= '<span class="item-title">'. esc_html( $menu_item->title ) .'</span>'; 194 165 $output .= '<span class="item-controls">'; 195 if ( 'custom' == $menu_item->type ) { 196 $label = __('Custom'); 197 } elseif ( 'post_type' == $menu_item->type ) { 198 $type_obj = get_post_type_object($menu_item->append); 199 $label = $type_obj->singular_label; 200 } elseif ( 'taxonomy' == $menu_item->type ) { 201 $taxonomy = get_taxonomy($menu_item->append); 202 $label = $taxonomy->singular_label; 203 } else { 204 $label = $menu_item->append; 205 } 206 $output .= '<span class="item-type">'. esc_html($label) .'</span>'; 166 $output .= '<span class="item-type">'. esc_html( $menu_item->append ) .'</span>'; 207 167 208 168 // Actions 209 $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> | ';210 $output .= '<a class="item-delete" id="delete '. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order) .'">'. __('Delete') .'</a>';169 $output .= '<a class="item-edit thickbox" id="edit-'. esc_attr( $menu_item->ID ) .'" value="'. esc_attr( $menu_item->ID ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | '; 170 $output .= '<a class="item-delete" id="delete-'. esc_attr( $menu_item->ID ) .'" value="'. esc_attr( $menu_item->ID ) .'">'. __('Delete') .'</a>'; 211 171 212 $output .= '</ dt></dl>';172 $output .= '</span></dt></dl>'; 213 173 214 174 // Menu Item Settings 215 $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 ) .'" />';216 $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 ) .'" />';217 $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 ) .'" />';218 $output .= '<input type="hidden" name="menu-item-p osition[]" id="menu-item-position'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order) .'" />';219 $output .= '<input type="hidden" name="menu-item- type[]" id="menu-item-type'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->type) .'" />';220 $output .= '<input type="hidden" name="menu-item- append[]" id="menu-item-append'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->append) .'" />';221 $output .= '<input type="hidden" name="menu-item-title[]" id="menu-item-title'. esc_attr( $menu_item->menu_order ) .'"value="'. esc_attr( $menu_item->title ) .'" />';222 $output .= '<input type="hidden" name="menu-item-url[]" id="menu-item-url'. esc_attr( $menu_item->menu_order ) .'"value="'. esc_attr( $menu_item->url ) .'" />';223 $output .= '<input type="hidden" name="menu-item-description[]" id="menu-item-description'. esc_attr( $menu_item->menu_order ) .'"value="'. esc_attr( $menu_item->description ) .'" />';224 $output .= '<input type="hidden" name="menu-item-classes[]" id="menu-item-classes'. esc_attr( $menu_item->menu_order ) .'"value="'. esc_attr( $menu_item->classes ) .'" />';225 $output .= '<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn'. esc_attr( $menu_item->menu_order ) .'"value="'. esc_attr( $menu_item->xfn ) .'" />';226 $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 ) .'" />';227 $output .= '<input type="hidden" name="menu-item-target[]" id="menu-item-target'. esc_attr( $menu_item->menu_order ) .'"value="'. esc_attr( $menu_item->target ) .'" />';175 $output .= '<input type="hidden" name="menu-item-db-id[]" value="'. esc_attr( $menu_item->ID ) .'" />'; 176 $output .= '<input type="hidden" name="menu-item-object-id[]" value="'. esc_attr( $menu_item->object_id ) .'" />'; 177 $output .= '<input type="hidden" name="menu-item-object[]" value="'. esc_attr( $menu_item->object ) .'" />'; 178 $output .= '<input type="hidden" name="menu-item-parent-id[]" value="'. esc_attr( $menu_item->post_parent ) .'" />'; 179 $output .= '<input type="hidden" name="menu-item-position[]" value="'. esc_attr( $menu_item->menu_order ) .'" />'; 180 $output .= '<input type="hidden" name="menu-item-type[]" value="'. esc_attr( $menu_item->type ) .'" />'; 181 $output .= '<input type="hidden" name="menu-item-title[]" value="'. esc_attr( $menu_item->title ) .'" />'; 182 $output .= '<input type="hidden" name="menu-item-url[]" value="'. esc_attr( $menu_item->url ) .'" />'; 183 $output .= '<input type="hidden" name="menu-item-description[]" value="'. esc_attr( $menu_item->description ) .'" />'; 184 $output .= '<input type="hidden" name="menu-item-classes[]" value="'. esc_attr( $menu_item->classes ) .'" />'; 185 $output .= '<input type="hidden" name="menu-item-xfn[]" value="'. esc_attr( $menu_item->xfn ) .'" />'; 186 $output .= '<input type="hidden" name="menu-item-attr-title[]" value="'.esc_attr( $menu_item->post_excerpt ) .'" />'; 187 $output .= '<input type="hidden" name="menu-item-target[]" value="'. esc_attr( $menu_item->target ) .'" />'; 228 188 break; 229 189 230 190 case 'custom': 231 $menu_id = 'menu-item-' . $menu_item->db_id; 232 $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>'; 191 case 'taxonomy': 192 case 'post_type': 193 $output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( 'menu-item-' . $menu_item->object_id ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>'; 233 194 234 195 // Menu item hidden fields 235 $output .= '<input type="hidden" class="menu-item-db-id" value=" '. esc_attr( $menu_item->db_id ) .'" />';196 $output .= '<input type="hidden" class="menu-item-db-id" value="0" />'; 236 197 $output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />'; 237 $output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->parent_id ) .'" />'; 198 $output .= '<input type="hidden" class="menu-item-object" value="'. esc_attr( $menu_item->object ) .'" />'; 199 $output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->post_parent ) .'" />'; 238 200 $output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />'; 239 201 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />'; 240 202 $output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />'; 241 203 $output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />'; 204 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />'; 242 205 $output .= '<input type="hidden" class="menu-item-target" value="'. esc_attr( $menu_item->target ) .'" />'; 243 206 $output .= '<input type="hidden" class="menu-item-attr_title" value="'. esc_attr( $menu_item->attr_title ) .'" />'; 244 207 $output .= '<input type="hidden" class="menu-item-description" value="'. esc_attr( $menu_item->description ) .'" />'; 245 208 $output .= '<input type="hidden" class="menu-item-classes" value="'. esc_attr( $menu_item->classes ) .'" />'; 246 209 $output .= '<input type="hidden" class="menu-item-xfn" value="'. esc_attr( $menu_item->xfn ) .'" />'; 247 210 break; 248 249 case 'taxonomy':250 case 'post_type':251 $menu_id = 'menu-item-' . $menu_item->db_id;252 $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>';253 254 // Menu item hidden fields255 $output .= '<input type="hidden" class="menu-item-db-id" value="0" />';256 $output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />';257 $output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->parent_id ) .'" />';258 $output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />';259 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';260 $output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />';261 $output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />';262 $output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';263 break;264 211 } 265 212 266 213 return $output; -
wp-includes/taxonomy.php
39 39 ) ) ; 40 40 41 41 register_taxonomy( 'nav_menu', 'nav_menu_item', array( 'hierarchical' => false, 42 'label' => __('Navigation Menus'), 43 'singular_label' => __('Navigation Menu'), 42 44 'query_var' => false, 43 45 'rewrite' => false, 44 46 'show_ui' => false, -
wp-includes/post.php
63 63 'query_var' => false, 64 64 ) ); 65 65 66 register_post_type( 'nav_menu_item', array( 'public' => false, 66 register_post_type( 'nav_menu_item', array( 'label' => __('Navigation Menu Items'), 67 'singular_label' => __('Navigation Menu Item'), 68 'public' => false, 67 69 'show_ui' => false, 68 70 '_builtin' => true, 69 71 'capability_type' => 'post', -
wp-includes/version.php
15 15 * 16 16 * @global int $wp_db_version 17 17 */ 18 $wp_db_version = 1357 6;18 $wp_db_version = 13578; 19 19 20 20 /** 21 21 * Holds the TinyMCE version -
wp-includes/classes.php
934 934 else 935 935 $children_elements[ $e->$parent_field ][] = $e; 936 936 } 937 937 938 938 /* 939 939 * when none of the elements is top level 940 940 * assume the first one must be root of the sub elements … … 1124 1124 } 1125 1125 1126 1126 /** 1127 * Create HTML list of nav menu items. 1128 * 1129 * @package WordPress 1130 * @since 3.0.0 1131 * @uses Walker 1132 */ 1133 class Walker_Nav_Menu extends Walker { 1134 /** 1135 * @see Walker::$tree_type 1136 * @since 3.0.0 1137 * @var string 1138 */ 1139 var $tree_type = array( 'post_type', 'taxonomy', 'custom' ); 1140 1141 /** 1142 * @see Walker::$db_fields 1143 * @since 3.0.0 1144 * @todo Decouple this. 1145 * @var array 1146 */ 1147 var $db_fields = array( 'parent' => 'post_parent', 'id' => 'object_id' ); 1148 1149 /** 1150 * @see Walker::start_lvl() 1151 * @since 3.0.0 1152 * 1153 * @param string $output Passed by reference. Used to append additional content. 1154 * @param int $depth Depth of page. Used for padding. 1155 */ 1156 function start_lvl(&$output, $depth) { 1157 $indent = str_repeat("\t", $depth); 1158 $output .= "\n$indent<ul class=\"sub-menu\">\n"; 1159 } 1160 1161 /** 1162 * @see Walker::end_lvl() 1163 * @since 3.0.0 1164 * 1165 * @param string $output Passed by reference. Used to append additional content. 1166 * @param int $depth Depth of page. Used for padding. 1167 */ 1168 function end_lvl(&$output, $depth) { 1169 $indent = str_repeat("\t", $depth); 1170 $output .= "$indent</ul>\n"; 1171 } 1172 1173 /** 1174 * @see Walker::start_el() 1175 * @since 3.0.0 1176 * 1177 * @param string $output Passed by reference. Used to append additional content. 1178 * @param object $item Menu item data object. 1179 * @param int $depth Depth of menu item. Used for padding. 1180 * @param int $current_page Menu item ID. 1181 * @param array $args 1182 */ 1183 function start_el(&$output, $item, $depth, $args) { 1184 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 1185 1186 if ( 'frontend' == $args->context ) { 1187 global $wp_query; 1188 1189 $css_class = array( 'menu-item', 'menu-item-type-'. $item->type, $item->classes ); 1190 1191 if ( 'custom' != $item->object ) 1192 $css_class[] = 'menu-item-object-'. $item->object; 1193 1194 if ( $item->object_id == $wp_query->get_queried_object_id() ) 1195 $css_class[] = 'current-menu-item'; 1196 1197 // @todo add classes for parent/child relationships 1198 1199 $css_class = join( ' ', apply_filters('nav_menu_css_class', $css_class, $item) ); 1200 } 1201 1202 $maybe_value = ( 'backend' == $args->context ) ? ' value="'. $item->ID .'"' : ''; 1203 $maybe_classes = ( 'frontend' == $args->context ) ? ' class="'. $css_class .'"' : ''; 1204 1205 $output .= $indent . '<li id="menu-item-'. $item->ID .'"'. $maybe_value . $maybe_classes .'>' . wp_get_nav_menu_item( $item, $args->context, $args ); 1206 } 1207 1208 /** 1209 * @see Walker::end_el() 1210 * @since 3.0.0 1211 * 1212 * @param string $output Passed by reference. Used to append additional content. 1213 * @param object $item Page data object. Not used. 1214 * @param int $depth Depth of page. Not Used. 1215 */ 1216 function end_el(&$output, $item, $depth) { 1217 $output .= "</li>\n"; 1218 } 1219 1220 } 1221 1222 /** 1127 1223 * Create HTML list of pages. 1128 1224 * 1129 1225 * @package WordPress -
wp-includes/script-loader.php
397 397 ) ); 398 398 399 399 // Custom Navigation 400 $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '201003 17b' );400 $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100321' ); 401 401 $scripts->localize( 'nav-menu', 'navMenuL10n', array( 402 402 'custom' => _x('Custom', 'menu nav item type'), 403 'page' => _x('Page', 'menu nav item type'),404 'category' => _x('Category', 'menu nav item type'),405 403 'thickbox' => _x('Edit Menu Item', 'Thickbox Title'), 406 404 'edit' => _x('Edit', 'menu item edit text'), 407 405 'warnDelete' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), … … 410 408 $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100321' ); 411 409 $scripts->add_data( 'custom-background', 'group', 1 ); 412 410 // See wp_just_in_time_script_localization() for translation data for this object 413 414 411 } 415 412 } 416 413 -
wp-includes/nav-menu.php
8 8 */ 9 9 10 10 /** 11 * Returns a Navigation Menu object11 * Returns a navigation menu object. 12 12 * 13 13 * @since 3.0.0 14 14 * 15 15 * @param string $menu Menu id 16 * @return mixed $menu|false 16 * @return mixed $menu|false Or WP_Error 17 17 */ 18 18 function wp_get_nav_menu_object( $menu ) { 19 19 return is_nav_menu( $menu ); 20 20 } 21 21 22 22 /** 23 * Check if Menu exists.23 * Check if navigation menu exists. 24 24 * 25 25 * Returns the menu object, or false if the term doesn't exist. 26 26 * 27 27 * @since 3.0.0 28 28 * 29 29 * @param int|string $menu The menu to check 30 * @return mixed Menu Object, if exists.30 * @return mixed Menu Object, if it exists. Else, false or WP_Error 31 31 */ 32 32 function is_nav_menu( $menu ) { 33 33 if ( !$menu ) … … 49 49 } 50 50 51 51 /** 52 * Create s a navigation menu.52 * Create a Navigation Menu. 53 53 * 54 54 * Optional args: 55 55 * slug - the url friendly version of the nav menu. … … 58 58 * 59 59 * @param string $menu_name Menu Name 60 60 * @param string $args Optional. 61 * @return mixed Menu object |WP_Error61 * @return mixed Menu object on sucess|WP_Error on failure 62 62 */ 63 63 function wp_create_nav_menu( $menu_name, $args = array() ) { 64 64 $menu_exists = get_term_by( 'name', $menu_name, 'nav_menu' ); 65 65 66 66 if ( $menu_exists ) 67 return new WP_Error( 'menu_exists', sprintf( __('A menu named “%s”already exists; please try another name.'), esc_html( $menu_exists->name ) ) );67 return new WP_Error( 'menu_exists', sprintf( __('A menu named <strong>%s</strong> already exists; please try another name.'), esc_html( $menu_exists->name ) ) ); 68 68 69 69 if ( isset($args['slug']) ) 70 70 $slug = $args['slug']; … … 76 76 if ( is_wp_error($menu) ) 77 77 return $menu; 78 78 79 return get_term( $menu['term_id'], 'nav_menu') ; 79 $result = get_term( $menu['term_id'], 'nav_menu' ); 80 81 if ( $result && !is_wp_error($result) ) { 82 do_action( 'wp_create_nav_menu', $menu['term_id'] ); 83 return $result; 84 } else { 85 return $result; 86 } 80 87 } 81 88 82 89 /** 83 * Delete s a navigation menu.90 * Delete a Navigation Menu. 84 91 * 85 92 * @since 3.0.0 86 93 * 87 94 * @param string $menu name|id|slug 88 * @return bool true on success, else false.95 * @return mixed Menu object on sucess|WP_Error on failure 89 96 */ 90 97 function wp_delete_nav_menu( $menu ) { 91 98 $menu = wp_get_nav_menu_object( $menu ); … … 98 105 wp_delete_post( $item ); 99 106 } 100 107 } 101 wp_delete_term( $menu->term_id, 'nav_menu' ); 108 109 $result = wp_delete_term( $menu->term_id, 'nav_menu' ); 110 111 if ( $result && !is_wp_error($result) ) { 112 do_action( 'wp_delete_nav_menu', $menu->term_id ); 113 return $result; 114 } else { 115 return $result; 116 } 102 117 } 103 118 104 119 /** 105 * Returns all Navigation Menu objects.120 * Returns all navigation menu objects. 106 121 * 107 122 * @since 3.0.0 108 123 * … … 153 168 } 154 169 155 170 /** 156 * Adds all the nav menu properties to the $menu_item.171 * Retrieve the HTML list content for nav menu items. 157 172 * 173 * @uses Walker_Nav_Menu to create HTML list content. 174 * @since 2.1.0 175 * @see Walker::walk() for parameters and return description. 176 */ 177 function walk_nav_menu_tree( $items, $depth, $r ) { 178 $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; 179 $args = array( $items, $depth, $r ); 180 181 return call_user_func_array(array(&$walker, 'walk'), $args); 182 } 183 184 /** 185 * Adds all the navigation menu properties to the menu item. 186 * 158 187 * @since 3.0.0 159 188 * 160 189 * @param string $menu_item The menu item to modify 161 * @param string $menu_item_type The menu item type ( template, custom, post_type, taxonomy).190 * @param string $menu_item_type The menu item type (frontend, custom, post_type, taxonomy). 162 191 * @param string $menu_item_object Optional. The menu item object type (post type or taxonomy). 163 * @return object $menu_item The mod tified menu item.192 * @return object $menu_item The modified menu item. 164 193 */ 165 194 function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_object = '' ) { 166 global $wp_query;167 168 195 switch ( $menu_item_type ) { 169 196 case 'frontend': 170 197 $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 175 $menu_item->append = get_post_meta( $menu_item->ID, 'menu_item_append', true ); 176 198 $menu_item->object_id = get_post_meta( $menu_item->ID, '_menu_item_object_id', true ); 199 $menu_item->object = get_post_meta( $menu_item->ID, '_menu_item_object', true ); 200 $menu_item->type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); 201 202 if ( 'post_type' == $menu_item->type ) { 203 $object = get_post_type_object( $menu_item->object ); 204 $menu_item->append = $object->singular_label; 205 206 } elseif ( 'taxonomy' == $menu_item->type ) { 207 $object = get_taxonomy( $menu_item->object ); 208 $menu_item->append = $object->singular_label; 209 210 } else { 211 $menu_item->append = __('Custom'); 212 } 213 177 214 $menu_item->title = $menu_item->post_title; 178 $menu_item->url = get_post_meta( $menu_item->ID, ' menu_item_url', true );179 $menu_item->target = get_post_meta( $menu_item->ID, ' menu_item_target', true );215 $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); 216 $menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true ); 180 217 181 218 $menu_item->attr_title = strip_tags( $menu_item->post_excerpt ); 182 219 $menu_item->description = strip_tags( $menu_item->post_content ); 183 220 184 $menu_item->classes = get_post_meta( $menu_item->ID, 'menu_item_classes', true );; 185 $menu_item->xfn = get_post_meta( $menu_item->ID, 'menu_item_xfn', true ); 186 $menu_item->li_class = ( $menu_item->object_id == $wp_query->get_queried_object_id() ) ? ' current_page_item' : ''; 221 $menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true );; 222 $menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true ); 187 223 break; 188 224 189 225 case 'custom': 190 $menu_item->db_id = (int) $menu_item->ID;226 $menu_item->db_id = 0; 191 227 $menu_item->object_id = (int) $menu_item->ID; 192 $menu_item-> parent_id = (int) $menu_item->post_parent;193 $menu_item->type = 'custom'; //$menu_item_type194 $menu_item->append = 'custom';228 $menu_item->object = 'custom'; 229 $menu_item->type = 'custom'; 230 $menu_item->append = __('custom'); 195 231 196 232 $menu_item->attr_title = strip_tags( $menu_item->post_excerpt ); 197 233 $menu_item->description = strip_tags( $menu_item->post_content ); 198 234 199 235 $menu_item->title = $menu_item->post_title; 200 $menu_item->url = get_post_meta( $menu_item->ID, 'menu_item_url', true ); 201 $menu_item->target = get_post_meta( $menu_item->ID, 'menu_item_target', true ); 236 $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); 237 $menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true ); 238 $menu_item->classes = ''; 239 $menu_item->xfn = ''; 202 240 break; 203 241 204 242 case 'post_type': 205 243 $menu_item->db_id = 0; 206 244 $menu_item->object_id = (int) $menu_item->ID; 207 $menu_item->parent_id = (int) $menu_item->post_parent;208 245 $menu_item->type = $menu_item_type; 209 246 210 247 $object = get_post_type_object( $menu_item_object ); 211 $menu_item->append = $object->name; 248 $menu_item->object = $object->name; 249 $menu_item->append = strtolower( $object->singular_label ); 212 250 213 251 $menu_item->title = $menu_item->post_title; 214 252 $menu_item->url = get_permalink( $menu_item->ID ); … … 216 254 217 255 $menu_item->attr_title = ''; 218 256 $menu_item->description = strip_tags( $menu_item->post_content ); 257 $menu_item->classes = ''; 258 $menu_item->xfn = ''; 219 259 break; 220 260 221 261 case 'taxonomy': 222 262 $menu_item->ID = $menu_item->term_id; 223 263 $menu_item->db_id = 0; 224 264 $menu_item->object_id = (int) $menu_item->term_id; 225 $menu_item->p arent_id= (int) $menu_item->parent;265 $menu_item->post_parent = (int) $menu_item->parent; 226 266 $menu_item->type = $menu_item_type; 227 267 228 268 $object = get_taxonomy( $menu_item_object ); 229 $menu_item->append = $object->name; 269 $menu_item->object = $object->name; 270 $menu_item->append = strtolower( $object->singular_label ); 230 271 231 272 $menu_item->title = $menu_item->name; 232 273 $menu_item->url = get_term_link( $menu_item, $menu_item_object ); 233 274 $menu_item->target = '_self'; 234 275 $menu_item->attr_title = ''; 235 276 $menu_item->description = strip_tags( $menu_item->description ); 277 $menu_item->classes = ''; 278 $menu_item->xfn = ''; 236 279 break; 237 } 238 239 $menu_item->classes = get_post_meta( $menu_item->ID, 'menu_item_classes', true ); 240 $menu_item->xfn = get_post_meta( $menu_item->ID, 'menu_item_xfn', true ); 241 280 } 242 281 return $menu_item; 243 282 } 244 283 ?> 284 No newline at end of file -
wp-admin/admin-ajax.php
1004 1004 update_user_option($user->ID, "closedpostboxes_$page", $closed); 1005 1005 1006 1006 if ( is_array($hidden) ) { 1007 $hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv' ) ); // postboxes that are always shown1007 $hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu') ); // postboxes that are always shown 1008 1008 update_user_option($user->ID, "meta-box-hidden_$page", $hidden); 1009 1009 } 1010 1010 … … 1395 1395 } 1396 1396 } 1397 1397 die( '0' ); 1398 case 'save-custom-link': 1399 if ( ! current_user_can('manage_links') ) 1400 die('-1'); 1401 1402 $link_name = isset( $_POST['link_name'] ) ? esc_html($_POST['link_name']) : null; 1403 $link_url = isset( $_POST['link_url'] ) ? esc_url_raw($_POST['link_url']) : null; 1404 1405 if ( !$link_name || !$link_url ) 1406 die('-1'); 1407 1408 $post = array( 1409 'post_status' => 'draft', 'post_type' => 'nav_menu_item', 'ping_status' => 0, 1410 'post_author' => $user_ID, 'post_title' => $link_name, 'post_excerpt' => '', 1411 'post_parent' => 0, 'menu_order' => 0, 'post_content' => '', 1412 ); 1413 1414 $link_id = wp_insert_post( $post ); 1415 1416 update_post_meta( $link_id, '_menu_item_type', 'custom' ); 1417 update_post_meta( $link_id, '_menu_item_object_id', (int) $link_id ); 1418 update_post_meta( $link_id, '_menu_item_object', 'custom' ); 1419 update_post_meta( $link_id, '_menu_item_target', '_self' ); 1420 update_post_meta( $link_id, '_menu_item_classes', '' ); 1421 update_post_meta( $link_id, '_menu_item_xfn', '' ); 1422 update_post_meta( $link_id, '_menu_item_url', $link_url ); 1423 1424 die( json_encode($link_id) ); 1398 1425 default : 1399 1426 do_action( 'wp_ajax_' . $_POST['action'] ); 1400 1427 die('0'); -
wp-admin/includes/upgrade.php
1105 1105 * @since 3.0.0 1106 1106 */ 1107 1107 function upgrade_300() { 1108 global $wp_current_db_version ;1108 global $wp_current_db_version, $wpdb; 1109 1109 1110 1110 if ( $wp_current_db_version < 12751 ) { 1111 1111 populate_roles_300(); 1112 1112 if ( is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) 1113 1113 add_site_option( 'siteurl', '' ); 1114 1114 } 1115 1116 if ( $wp_current_db_version < 13577 ) { 1117 // remove old nav menu post meta keys 1118 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key IN( 'menu_type', 'object_id', 'menu_new_window', 'menu_link', '_menu_item_append', 'menu_item_append' )" ) ); 1119 1120 // update nav menu post meta keys to underscore prefixes 1121 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_menu_item_type' WHERE meta_key = 'menu_item_type'" ) ); 1122 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_menu_item_object_id' WHERE meta_key = 'menu_item_object_id'" ) ); 1123 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_menu_item_target' WHERE meta_key = 'menu_item_target'" ) ); 1124 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_menu_item_classes' WHERE meta_key = 'menu_item_classes'" ) ); 1125 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_menu_item_xfn' WHERE meta_key = 'menu_item_xfn'" ) ); 1126 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_menu_item_url' WHERE meta_key = 'menu_item_url'" ) ); 1127 } 1115 1128 } 1116 1129 1117 1130 /** -
wp-admin/includes/nav-menu.php
1 1 <?php 2 /** 3 * Register nav menu metaboxes 4 * 5 * @since 3.0.0 6 **/ 7 function wp_nav_menu_metaboxes_setup() { 8 add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_metabox', 'nav-menus', 'side', 'default' ); 9 wp_nav_menu_post_type_metaboxes(); 10 wp_nav_menu_taxonomy_metaboxes(); 11 } 2 12 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(); 13 /** 14 * Limit the amount of meta boxes to just links, pages and cats for first time users. 15 * 16 * @since 3.0.0 17 **/ 18 function wp_initial_nav_menu_meta_boxes() { 19 global $wp_meta_boxes; 20 21 if ( !get_user_option( 'meta-box-hidden_nav-menus' ) && is_array($wp_meta_boxes) ) { 22 23 $initial_meta_boxes = array( 'manage-menu', 'create-menu', 'add-custom-links', 'add-page', 'add-category' ); 24 $hidden_meta_boxes = array(); 25 26 foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) { 27 foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) { 28 foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) { 29 if ( in_array( $box['id'], $initial_meta_boxes ) ) { 30 unset( $box['id'] ); 31 } else { 32 $hidden_meta_boxes[] = $box['id']; 33 } 34 } 35 } 36 } 37 $user = wp_get_current_user(); 38 update_user_meta( $user->ID, 'meta-box-hidden_nav-menus', $hidden_meta_boxes ); 39 40 // returns all the hidden metaboxes to the js function: wpNavMenu.initial_meta_boxes() 41 return join( ',', $hidden_meta_boxes ); 42 } 43 } 8 44 9 45 /** 10 46 * Creates metaboxes for any post type menu item. … … 15 51 $post_types = get_post_types( array( 'public' => true ), 'object' ); 16 52 17 53 if ( !$post_types ) 18 return false;54 return; 19 55 20 $allowed_types = apply_filters('post_types_allowed_in_menus', array('page'));21 56 foreach ( $post_types as $post_type ) { 22 if ( !in_array($post_type->name, $allowed_types) )23 continue;24 57 $id = $post_type->name; 25 26 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'menus', 'side', 'default', $post_type ); 58 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type ); 27 59 } 28 60 } 29 61 … … 36 68 $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' ); 37 69 38 70 if ( !$taxonomies ) 39 return false;71 return; 40 72 41 $allowed_types = apply_filters('taxonomies_allowed_in_menus', array('category'));42 73 foreach ( $taxonomies as $tax ) { 43 if ( !in_array($tax->name, $allowed_types) )44 continue;45 74 $id = $tax->name; 46 75 47 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', ' menus', 'side', 'default', $tax );76 add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax ); 48 77 } 49 78 } 50 79 … … 98 127 * @since 3.0.0 99 128 */ 100 129 function wp_nav_menu_item_link_metabox() { 101 $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom', 'showposts' => -1 ); 130 // @note: hacky query, see #12660 131 $args = array( 'post_type' => 'nav_menu_item', 'post_status' => 'any', 'meta_key' => '_menu_item_type', 'numberposts' => -1, 'orderby' => 'title', ); 102 132 103 133 // @todo transient caching of these results with proper invalidation on updating links 104 $query = new WP_Query( $args ); 105 134 $links = get_posts( $args ); 106 135 ?> 107 136 <p id="menu-item-url-wrap"> 108 137 <label class="howto" for="menu-item-url"> … … 110 139 <input id="custom-menu-item-url" name="custom-menu-item-url" type="text" class="code menu-item-textbox" value="http://" /> 111 140 </label> 112 141 </p> 113 <br class="clear" />114 142 <p id="menu-item-name-wrap"> 115 143 <label class="howto" for="custom-menu-item-name"> 116 144 <span><?php _e('Text'); ?></span> … … 119 147 </p> 120 148 121 149 <p class="button-controls"> 122 <a class="show-all"><?php _e('View All'); ?></a> 123 <a class="hide-all"><?php _e('Hide All'); ?></a> 150 <span class="lists-controls"> 151 <a class="show-all"><?php _e('View All'); ?></a> 152 <a class="hide-all"><?php _e('Hide All'); ?></a> 153 </span> 154 155 <span class="add-to-menu"> 156 <a class="button"><?php _e('Add to Menu'); ?></a> 157 </span> 124 158 </p> 125 159 <div id="available-links" class="list-wrap"> 126 160 <div class="list-container"> 127 161 <ul class="list"> 128 <?php echo wp_nav_menu_get_items( $ query->posts, 'custom' ); ?>162 <?php echo wp_nav_menu_get_items( $links, 'custom', 'custom' ); ?> 129 163 </ul> 130 164 </div><!-- /.list-container--> 131 165 </div><!-- /#available-links--> 132 <p class="add-to-menu">133 <a class="button"><?php _e('Add to Menu'); ?></a>134 </p>135 166 <div class="clear"></div> 136 167 <?php 137 168 } … … 145 176 * @param string $post_type The post type object. 146 177 */ 147 178 function wp_nav_menu_item_post_type_metabox( $object, $post_type ) { 148 $args = array( 'post_type' => $post_type['args']->name, ' post_status' => 'publish', 'showposts' => -1);179 $args = array( 'post_type' => $post_type['args']->name, 'numberposts' => -1, 'orderby' => 'title', ); 149 180 150 if ( 'attachment' == $post_type['args']->name )151 $args['post_status'] = 'any';152 153 181 // @todo transient caching of these results with proper invalidation on updating of a post of this type 154 $ query = new WP_Query( $args );182 $posts = get_posts( $args ); 155 183 156 if ( !$ query->posts )184 if ( !$posts ) 157 185 $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>'; 158 186 159 187 $pt_names = ''; 160 if ( is_array($ query->posts) ) {161 foreach ( $ query->posts as $post ) {188 if ( is_array($posts) ) { 189 foreach ( $posts as $post ) { 162 190 if ( $post->post_title ) { 163 191 $pt_names .= htmlentities( $post->post_title ) .'|'; 164 } else {165 $pt_names = sprintf( __('No %s exists'), $post_type['args']->label );166 192 } 167 193 } 168 194 } … … 175 201 </p> 176 202 177 203 <p class="button-controls"> 178 <a class="show-all"><?php _e('View All'); ?></a> 179 <a class="hide-all"><?php _e('Hide All'); ?></a> 204 <span class="lists-controls"> 205 <a class="show-all"><?php _e('View All'); ?></a> 206 <a class="hide-all"><?php _e('Hide All'); ?></a> 207 </span> 208 209 <span class="add-to-menu"> 210 <a class="button"><?php _e('Add to Menu'); ?></a> 211 </span> 180 212 </p> 181 213 182 214 <div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap"> 183 215 <div class="list-container"> 184 216 <ul class="list"> 185 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $ query->posts, 'post_type', $id ); ?>217 <?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $posts, 'post_type', $id ); ?> 186 218 </ul> 187 219 </div><!-- /.list-container--> 188 220 </div><!-- /#existing-categories--> 189 <p class="add-to-menu">190 <a class="button-secondary"><?php _e('Add to Menu'); ?></a>191 </p>192 221 <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr( $id ); ?>-names" value="<?php echo esc_js( $pt_names ); ?>" /> 193 222 <br class="clear" /> 194 223 <script type="text/javascript" charset="utf-8"> 195 224 // <![CDATA[ 196 225 jQuery(document).ready(function(){ 197 wp _nav_menu_autocomplete('<?php echo esc_attr($id); ?>');226 wpNavMenu.autocomplete('<?php echo esc_attr($id); ?>'); 198 227 }); 199 228 // ]]> 200 229 </script> … … 227 256 foreach ( $terms as $term ) { 228 257 if ( $term->name ) { 229 258 $term_names .= htmlentities( $term->name ) .'|'; 230 } else {231 $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label );232 259 } 233 260 } 234 261 } … … 241 268 </p> 242 269 243 270 <p class="button-controls"> 244 <a class="show-all"><?php _e('View All'); ?></a> 245 <a class="hide-all"><?php _e('Hide All'); ?></a> 271 <span class="lists-controls"> 272 <a class="show-all"><?php _e('View All'); ?></a> 273 <a class="hide-all"><?php _e('Hide All'); ?></a> 274 </span> 275 276 <span class="add-to-menu"> 277 <a class="button"><?php _e('Add to Menu'); ?></a> 278 </span> 246 279 </p> 247 280 248 281 <div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap"> … … 252 285 </ul> 253 286 </div><!-- /.list-container--> 254 287 </div><!-- /#existing-categories--> 255 <p class="add-to-menu">256 <a class="button-secondary"><?php _e('Add to Menu'); ?></a>257 </p>258 288 <input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr($id); ?>-names" value="<?php echo esc_js( $term_names ); ?>" /> 259 289 <br class="clear" /> 260 290 <script type="text/javascript" charset="utf-8"> 261 291 // <![CDATA[ 262 292 jQuery(document).ready(function(){ 263 wp _nav_menu_autocomplete('<?php echo esc_attr($id); ?>');293 wpNavMenu.autocomplete('<?php echo esc_attr($id); ?>'); 264 294 }); 265 295 // ]]> 266 296 </script> … … 290 320 if ( !isset($menu_item->post_parent) ) 291 321 $menu_item->post_parent = $menu_item->parent; 292 322 293 // Cleanest way to get all attachements294 if ( 'attachment' == $object)323 // Get all attachements and links 324 if ( in_array($object, array( 'attachment', 'custom' )) ) 295 325 $menu_item->post_parent = 0; 296 326 297 327 if ( 0 == $menu_item->post_parent ) { 298 328 // Set up the menu item 299 329 $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object ); 330 331 // No blank titles 332 if ( empty($menu_item->title) ) 333 continue; 334 300 335 $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : ''; 301 336 302 337 $output .= '<li'. $attributes .'>'; 303 338 $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object ); 304 339 $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context ); -
wp-admin/js/nav-menu.dev.js
1 1 /** 2 * WordPress Administration Custom Navigation2 * WordPress Administration Navigation Menu 3 3 * Interface JS functions 4 4 * 5 * @version 1.1.05 * @version 2.0.0 6 6 * 7 7 * @package WordPress 8 8 * @subpackage Administration 9 9 */ 10 10 11 function wp_nav_menu_autocomplete( id ) { 12 jQuery('#add-'+ id +' .quick-search').autocomplete(jQuery( '#add-'+ id +' .autocomplete' ).val().split('|')); 11 var wpNavMenu; 13 12 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 }); 20 } 13 (function($) { 14 15 wpNavMenu = { 16 17 // Functions that run on init. 18 init : function() { 19 20 wpNavMenu.initial_meta_boxes(); 21 22 wpNavMenu.drag_and_drop(); 23 24 // Delete AYS 25 $('#update-nav-menu .deletion').click(function(){ 26 if ( confirm( navMenuL10n.warnDelete ) ) { 27 return true; 28 } else { 29 return false; 30 }; 31 }); 21 32 22 /** 23 * Populate the thickbox window with the selected menu items 24 * 25 * @param int id - the id of the menu li to edit. 26 */ 27 function wp_edit_menu_item( id ) { 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(); 33 // Handle Save Button Clicks 34 $('#update-nav-menu').submit(function(){ 35 wpNavMenu.update_post_data(); 36 }); 36 37 37 // Only allow custom links to be editable. 38 if ( 'custom' != item_type ) 39 jQuery( '#edit-menu-item-url' ).attr('disabled', 'disabled' ); 38 // Handle some return keypresses 39 $('#create-menu-name').keypress(function(e){ 40 if ( 13 == e.keyCode ) { 41 $('#create-menu-button').click(); 42 return false; 43 } 44 }); 40 45 41 // Populate the fields for thickbox 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); 46 $('#custom-menu-item-url, #custom-menu-item-name').keypress(function(e){ 47 if ( 13 == e.keyCode ) { 48 $('#add-custom-links a.button').click(); 49 return false; 50 } 51 }).focus(function(){ 52 if ( $(this).val() == $(this).attr('defaultValue') && $(this).attr('id') != 'custom-menu-item-url' ) { 53 $(this).val(''); 54 } 55 }).blur(function(){ 56 if ( $(this).val() == '' ) { 57 $(this).val($(this).attr('defaultValue')); 58 } 59 }); 51 60 52 // focus 53 jQuery( '#edit-menu-item-title' ).focus(); 54 }; 61 $('#create-menu-name').focus(function(){ 62 if ( $(this).val() == $(this).attr('defaultValue') ) { 63 $(this).val(''); 64 } 65 }).blur(function(){ 66 if ( $(this).val() == '' ) { 67 $(this).val($(this).attr('defaultValue')); 68 } 69 }); 55 70 56 /** 57 * Update the values for the menu item being editing 58 */ 59 function wp_update_menu_item() { 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(); 71 // close postboxes that should be closed 72 $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); 68 73 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); 74 // postboxes setup 75 postboxes.add_postbox_toggles('nav-menus'); 78 76 79 jQuery('.menu #menu-item' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 80 } 77 // Clear the quick search textbox 78 $('.quick-search').click(function(){ 79 $(this).attr( 'value', '' ); 80 }); 81 81 82 /** 83 * Removes a menu item from current menu 84 * 85 * @param int o - the id of the menu li to remove. 86 */ 87 function wp_remove_menu_item( o ) { 88 var todelete = document.getElementById('menu-item' + o); 82 // Quick Search submit 83 $('.quick-search-submit').click(function(){ 84 $(this).siblings('.quick-search').search(); 85 }); 89 86 90 if ( todelete ) { 91 // Give some feedback to the user 92 jQuery( todelete ).find('dt').each(function(){ 93 jQuery(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { jQuery(this).parent().parent().remove() } } ); 94 }); 95 } 96 }; 87 // Edit menu item 88 $('#menu-container .item-edit').click(function(){ 89 wpNavMenu.edit_menu_item( $(this).attr('value') ); 90 }); 97 91 98 /** 99 * Adds the item to the menu 100 * 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 ) { 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 ); 92 // Delete menu item 93 $('#menu-container .item-delete').click(function(){ 94 wpNavMenu.remove_menu_item( $(this).attr('value') ); 95 }); 117 96 118 // Adds the item in the queue 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>'); 97 // Update menu item settings (thickbox) 98 $('#update-menu-item').click(function(){ 99 wpNavMenu.update_menu_item(); 100 tb_remove(); 101 }); 120 102 121 // Give some feedback to the user 122 jQuery( '.menu #menu-item' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); 103 // Close thickbox 104 $('#cancel-save').click(function(){ 105 tb_remove(); 106 }); 123 107 124 // Enable drag-n-drop 125 wp_drag_and_drop(); 108 // Show All Button 109 $('.show-all').click(function(e){ 110 $(e.currentTarget).parent().parent().siblings('.list-wrap').css( 'display', 'block' ); 111 $(e.currentTarget).parent().parent().siblings('.list-wrap').find('li').css( 'display', 'block' ); 112 $(e.currentTarget).hide(); 113 $(e.currentTarget).siblings('.hide-all').show(); 114 }); 126 115 127 // Reload thickbox 128 tb_init('a.thickbox, area.thickbox, input.thickbox'); 129 }; 116 // Hide All Button 117 $('.hide-all').click(function(e){ 118 $(e.currentTarget).parent().parent().siblings('.list-wrap').css( 'display', 'none' ); 119 $(e.currentTarget).parent().parent().siblings('.list-wrap').find('li').css( 'display', 'none' ); 120 $(e.currentTarget).hide(); 121 $(e.currentTarget).siblings('.show-all').show(); 122 }); 130 123 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'); 124 // Add menu items into the menu 125 $('.add-to-menu').click(function(e){ 126 wpNavMenu.add_checked_items_to_menu(e.currentTarget); 127 }); 139 128 140 // If nothing was checked, cancel 141 if ( 0 == items.length ) 142 return false; 129 // Create a new link then add it to the menu 130 $('#add-custom-links .add-to-menu a').click(function(e){ 131 // Add link to menu 132 if ( $('#custom-menu-item-url').val() == $('#custom-menu-item-url').attr('defaultValue') ) 133 return; // Do not allow "http://" submissions to go through 143 134 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(); 135 wpNavMenu.add_custom_link( $('#custom-menu-item-name').val(), $('#custom-menu-item-url').val() ); 136 137 // Reset the fields back to their defaults 138 $('#custom-menu-item-name').val($('#custom-menu-item-name').attr('defaultValue')); 139 $('#custom-menu-item-url' ).val($('#custom-menu-item-url' ).attr('defaultValue')).focus(); 140 }); 141 }, 142 143 add_custom_link : function( link_name, link_url ) { 144 var params = { 145 action: 'save-custom-link', 146 link_name: link_name, 147 link_url: link_url 148 } 149 150 $.post( ajaxurl, params, function(link_id) { 151 if ( '-1' == link_id ) 152 return; 147 153 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 = '_self'; 156 var item_classes = ''; 157 var item_xfn = ''; 158 }; 154 wpNavMenu.add_to_menu( link_id, link_id, 'custom', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_self', '', '' ); 155 }, 'json'); 156 }, 157 158 /** 159 * In combination with the php function wp_initial_nav_menu_meta_boxes(), 160 * this function limits the metaboxes for first time users to just links, pages and cats. 161 */ 162 initial_meta_boxes : function() { 163 var hidden = $('#hidden-metaboxes').val().split( ',' ); 159 164 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(); 165 if ( '' != hidden ) { 166 for ( var i = 0; i < hidden.length; i++ ) { 167 $( '#' + hidden[i] ).attr( 'style', 'display: none;' ); 168 $( '#' + hidden[i] + '-hide' ).attr( 'checked', false ); 169 }; 170 }; 171 }, 172 173 // Makes the menu items drag and droppable. 174 drag_and_drop : function() { 175 // Make sure all li's have dropzones 176 $('.menu li').each(function(){ 177 if ( !$(this).children('.dropzone').attr('class') ) { 178 $(this).prepend('<div class="dropzone"></div>'); 179 }; 180 }); 167 181 168 if ( undefined == item_description ) { 169 item_description = ''; 170 }; 182 // make menu item draggable 183 $('.menu li').draggable({ 184 handle: ' > dl', 185 opacity: .8, 186 addClasses: false, 187 helper: 'clone', 188 zIndex: 100 189 }); 171 190 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 ); 191 // make menu item droppable 192 $('.menu li dl, .menu li .dropzone').droppable({ 193 accept: '.menu li', 194 tolerance: 'pointer', 195 drop: function(e, ui) { 196 var li = $(this).parent(); 197 var child = !$(this).hasClass('dropzone'); 174 198 175 // uncheck the menu item in the list 176 jQuery(this).attr( 'checked', false ); 177 }); 178 }; 199 // Append UL to first child 200 if ( child && li.children('ul').length == 0 ) { 201 li.append( '<ul class="sub-menu" />' ); 202 } 203 // Make it draggable 204 if ( child ) { 205 li.children('ul').append( ui.draggable ); 206 } else { 207 li.before( ui.draggable ); 208 } 179 209 180 /** 181 * Makes the menu items drag and droppable. 182 */ 183 function wp_drag_and_drop() { 184 // Make sure all li's have dropzones 185 jQuery('.menu li').each(function(){ 186 if ( !jQuery(this).children('.dropzone').attr('class') ) { 187 jQuery(this).prepend('<div class="dropzone"></div>'); 188 }; 189 }); 210 li.find('dl,.dropzone').css({ backgroundColor: '', borderColor: '' }); 190 211 191 // make menu item draggable 192 jQuery('.menu li').draggable({ 193 handle: ' > dl', 194 opacity: .8, 195 addClasses: false, 196 helper: 'clone', 197 zIndex: 100 198 }); 212 var draggablevalue = ui.draggable.attr('value'); 213 var droppablevalue = li.attr('value'); 199 214 200 // make menu item droppable 201 jQuery('.menu li dl, .menu li .dropzone').droppable({ 202 accept: '.menu li', 203 tolerance: 'pointer', 204 drop: function(e, ui) { 205 var li = jQuery(this).parent(); 206 var child = !jQuery(this).hasClass('dropzone'); 215 li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue); 216 $(this).parent().find('dt').removeAttr('style'); 217 $(this).parent().find('div:first').removeAttr('style'); 207 218 208 // Append UL to first child 209 if ( child && li.children('ul').length == 0 ) { 210 li.append( '<ul class="sub-menu" />' ); 211 } 212 // Make it draggable 213 if ( child ) { 214 li.children('ul').append( ui.draggable ); 215 } else { 216 li.before( ui.draggable ); 217 } 218 219 li.find('dl,.dropzone').css({ backgroundColor: '', borderColor: '' }); 220 221 var draggablevalue = ui.draggable.attr('value'); 222 var droppablevalue = li.attr('value'); 223 224 li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue); 225 jQuery(this).parent().find('dt').removeAttr('style'); 226 jQuery(this).parent().find('div:first').removeAttr('style'); 227 219 }, 220 over: function(e) { 221 // Add child 222 if ( $(this).attr('class') == 'dropzone ui-droppable' ) { 223 $(this).parent().find('div:first').css({ background: '#f5f5f5', border: '1px dashed #bbb', margin: '10px 0px', height: '40px' }); 224 } 225 // Add above 226 else if ( $(this).attr('class') == 'ui-droppable' ) { 227 $(this).parent().find('dt:first').css('background', '#d8d8d8'); 228 } else { 229 // Do nothing 230 } 231 }, 232 out: function() { 233 $(this).parent().find('dt').removeAttr('style'); 234 $(this).parent().find('div:first').removeAttr('style'); 235 $(this).filter('.dropzone').css({ borderColor: '' }); 236 } 237 }); 228 238 }, 229 over: function() { 230 // Add child 231 if ( jQuery(this).attr('class') == 'dropzone ui-droppable' ) { 232 jQuery(this).parent().find('div:first').css('background', 'none').css('height', '50px'); 233 } 234 // Add above 235 else if ( jQuery(this).attr('class') == 'ui-droppable' ) { 236 jQuery(this).parent().find('dt:first').css('background', '#d8d8d8'); 237 } else { 238 // do nothing 239 } 240 var parentid = jQuery(this).parent().attr('id'); 239 240 // Prepares menu items for POST. 241 update_post_data : function() { 242 var i = 0; // counter 241 243 242 }, 243 out: function() { 244 jQuery(this).parent().find('dt').removeAttr('style'); 245 jQuery(this).parent().find('div:first').removeAttr('style'); 246 jQuery(this).filter('.dropzone').css({ borderColor: '' }); 247 } 248 } 249 ); 250 } 244 $('.menu li').each(function(){ 245 i = i + 1; // the menu order for each item 251 246 252 /** 253 * Prepares menu items for POST. 254 */ 255 function wp_update_post_data() { 256 var i = 0; 247 var j = $(this).attr('value'); // reference to the current menu item (e.g. li#menu-item + j) 257 248 258 jQuery('.menu li').each(function(i) { 259 i = i + 1; 260 var j = jQuery(this).attr('value'); 249 // Grab the menu item id 250 var id = $(this).children('input[name=menu-item-db-id[]]').val(); 261 251 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); 252 // Update the li value to equal the menu order 253 $(this).attr('value', i); 265 254 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); 255 // Update the position 256 $(this).children('input[name=menu-item-position[]]').attr( 'value', i ); 271 257 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); 258 // Update the parent id 259 var pid = $(this).parent('.sub-menu').siblings('input[name=menu-item-object-id[]]').val(); 260 261 if ( undefined == pid ) { 262 pid = 0; 263 }; 281 264 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); 265 $(this).children('input[name=menu-item-parent-id[]]').attr( 'value', pid ); 290 266 291 jQuery('#li-count').attr( 'value', i ); 292 }); 293 }; 267 // Update the menu item count 268 $('#li-count').attr( 'value', i ); 269 }); 270 }, 271 272 /** 273 * Enables autocomplete for nav menu types. 274 * 275 * @param int id - the id of the menu item type. 276 */ 277 autocomplete : function( id ) { 278 $('#add-'+ id +' .quick-search').autocomplete( $( '#add-'+ id +' .autocomplete' ).val().split('|') ); 294 279 295 /** 296 * Gets a unique number based on how many items are in the menu 297 */ 298 function wp_get_unique_menu_id() { 299 var count = jQuery('.menu li').length + 1; 300 var randomnumber = count; 301 var validatetest = 0; 280 $('#add-'+ id +' .quick-search').result(function( event, data, formatted ) { 281 $('#add-'+ id +' .list-wrap').css( 'display', 'block' ); 282 $("#add-"+ id +" .list-wrap li:contains('" + data + "')").css( 'display', 'block' ); 283 $('#add-'+ id +' .show-all').hide(); 284 $('#add-'+ id +' .hide-all').show(); 285 }); 286 }, 287 288 /** 289 * Populate the thickbox window with the selected menu items 290 * 291 * @param int id - the id of the menu item to edit. 292 */ 293 edit_menu_item : function( id ) { 294 var item_type = $('#menu-item-' + id).children('input[name=menu-item-type[]]').val(); 295 var item_title = $('#menu-item-' + id).children('input[name=menu-item-title[]]').val(); 296 var item_link = $('#menu-item-' + id).children('input[name=menu-item-url[]]').val(); 297 var item_attr_title = $('#menu-item-' + id).children('input[name=menu-item-attr-title[]]').val(); 298 var item_target = $('#menu-item-' + id).children('input[name=menu-item-target[]]').val(); 299 var item_description = $('#menu-item-' + id).children('input[name=menu-item-description[]]').val(); 300 var item_classes = $('#menu-item-' + id).children('input[name=menu-item-classes[]]').val(); 301 var item_xfn = $('#menu-item-' + id).children('input[name=menu-item-xfn[]]').val(); 302 302 303 try { 304 var test = document.getElementById( 'menu-' + randomnumber.toString() ).value; 305 } 306 catch ( err ) { 307 validatetest = 1; 308 } 303 // Only allow custom links to be editable. 304 if ( 'custom' != item_type ) 305 $( '#edit-menu-item-url' ).attr('disabled', 'disabled' ); 309 306 310 while ( validatetest == 0 ) { 311 randomnumber = randomnumber + 1; 312 try { 313 var test2 = document.getElementById( 'menu-' + randomnumber.toString() ).value; 314 } 315 catch ( err ) { 316 validatetest = 1; 317 } 318 } 319 return randomnumber; 320 } 307 // Populate the fields for thickbox 308 $( '#edit-menu-item-id' ).val(id); 309 $( '#edit-menu-item-title' ).val(item_title); 310 $( '#edit-menu-item-url' ).val(item_link); 311 $( '#edit-menu-item-attr-title' ).val(item_attr_title); 312 $( '#edit-menu-item-target' ).val(item_target); 313 $( "#edit-menu-item-target option[value='" + item_target + "']" ).attr('selected', 'selected'); 314 $( '#edit-menu-item-description' ).val(item_description); 315 $( '#edit-menu-item-classes' ).val(item_classes); 316 $( '#edit-menu-item-xfn' ).val(item_xfn); 321 317 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 = ''; 318 // @todo: focus on #edit-menu-item-title 319 }, 320 321 /** 322 * Update the values for the menu item being editing 323 */ 324 update_menu_item : function() { 325 var id = $('#edit-menu-item-id').val(); 326 var item_title = $('#edit-menu-item-title').val(); 327 var item_link = $('#edit-menu-item-url').val(); 328 var item_attr_title = $('#edit-menu-item-attr-title').val(); 329 var item_target = $('#edit-menu-item-target').val(); 330 var item_description = $('#edit-menu-item-description').val(); 331 var item_classes = $('#edit-menu-item-classes').val(); 332 var item_xfn = $('#edit-menu-item-xfn').val(); 340 333 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 + '" />'; 334 // update menu item settings 335 $('.menu #menu-item-' + id).find('span.item-title:first').html(item_title); 354 336 355 return hidden; 356 } 337 $('#menu-item-' + id).children('input[name=menu-item-title[]]').val(item_title); 338 $('#menu-item-' + id).children('input[name=menu-item-url[]]').val(item_link); 339 $('#menu-item-' + id).children('input[name=menu-item-attr-title[]]').val(item_attr_title); 340 $('#menu-item-' + id).children('input[name=menu-item-target[]]').val(item_target); 341 $('#menu-item-' + id).children('input[name=menu-item-description[]]').val(item_description); 342 $('#menu-item-' + id).children('input[name=menu-item-classes[]]').val(item_classes); 343 $('#menu-item-' + id).children('input[name=menu-item-xfn[]]').val(item_xfn); 357 344 358 /** 359 * WordPress Administration Custom Navigation 360 * Interface $ functions 361 * 362 * @version 2.0.0 363 * 364 * @package WordPress 365 * @subpackage Administration 366 */ 345 $('.menu #menu-item-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { $(this).css( 'backgroundColor', '' ); }}); 346 }, 347 348 /** 349 * Removes a menu item from current menu 350 * 351 * @param int id - the id of the menu item to remove. 352 */ 353 remove_menu_item : function( id ) { 354 var todelete = $('#menu-item-' + id); 367 355 368 /** 369 * Init Functions 370 */ 371 jQuery(document).ready(function($){ 356 if ( todelete ) { 357 // Give some feedback to the user 358 $( todelete ).find('dt').each(function(){ 359 $(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { $(this).parent().parent().remove() } } ); 360 }); 361 } 362 }, 363 364 /** 365 * Adds the item to the menu 366 * 367 * @param string item_db_id - The menu item's db id. 368 * @param string item_object_id - The menu item's object id. 369 * @param string item_object - The menu item's object name. 370 * @param string item_type - The menu item's object type. 371 * @param string item_append - The menu item's nice name. 372 * @param string item_parent_id - The menu item's parent id. 373 * @param string item_title - The menu item title. 374 * @param string item_url - The menu item url 375 * @param string item_description - The menu item description. 376 * @param string item_attr_title - The title attribute. 377 * @param string item_target - The target attribute. 378 * @param string item_classes - Optional. Additional CSS classes for the menu item 379 * @param string item_xfn - Optional. The rel attribute. 380 */ 381 add_to_menu : function( item_db_id, item_object_id, item_object, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) { 382 var randomnumber = $('.menu li').length + 1; 383 var hidden = wpNavMenu.get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_object, item_type, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ); 384 385 // Adds the item to the menu 386 $('.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="wpNavMenu.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 +'" onclick="wpNavMenu.remove_menu_item('+ randomnumber +');">Delete</a></span></dt></dl>' + hidden + '</li>'); 372 387 373 wp_drag_and_drop(); 388 // Give some feedback to the user 389 $( '.menu #menu-item-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { $(this).css( 'backgroundColor', '' ); }}); 374 390 375 // Delete AYS 376 $('#update-nav-menu .deletion').click(function(){ 377 if ( confirm( navMenuL10n.warnDelete ) ) { 378 return true; 379 } else { 380 return false; 381 }; 382 }); 391 // Enable drag-n-drop 392 wpNavMenu.drag_and_drop(); 383 393 384 // Handle Save Button Clicks 385 $('#save_menu').click(function(){ 386 return wp_update_post_data(); 387 }); 394 // Reload thickbox 395 tb_init('a.thickbox, area.thickbox, input.thickbox'); 396 }, 397 398 /** 399 * Grabs items from the queue and adds them to the menu. 400 * 401 * @param string button - a reference to the button that was clicked 402 */ 403 add_checked_items_to_menu : function( button ) { 404 // Grab checked items 405 var items = $(button).parent().siblings('.list-wrap').find(':checked'); 388 406 389 // Handle some return keypresses 390 $('#create-menu-name').keypress(function(e){ 391 if ( 13 == e.keyCode ) { 392 $('#create-menu-button').click(); 393 return false; 394 } 395 }); 407 // If nothing was checked, cancel 408 if ( 0 == items.length ) 409 return false; 396 410 397 $('#custom-menu-item-url, #custom-menu-item-name').keypress(function(e){ 398 if ( 13 == e.keyCode ) { 399 $('#add-custom-links a.button').click(); 400 return false; 401 } 402 }).focus(function(){ 403 if ( $(this).val() == $(this).attr('defaultValue') && $(this).attr('id') != 'custom-menu-item-url' ) { 404 $(this).val(''); 405 } 406 }).blur(function(){ 407 if ( $(this).val() == '' ) { 408 $(this).val($(this).attr('defaultValue')); 409 } 410 }); 411 // Loop through each item, grab it's hidden data and add it to the menu. 412 $(items).each(function(){ 413 var item_type = $(this).parent().siblings('.menu-item-type').val(); 411 414 412 $('#create-menu-name').focus(function(){ 413 if ( $(this).val() == $(this).attr('defaultValue') ) { 414 $(this).val(''); 415 } 416 }).blur(function(){ 417 if ( $(this).val() == '' ) { 418 $(this).val($(this).attr('defaultValue')); 419 } 420 }); 415 if ( 'custom' == item_type ) { 416 var item_attr_title = $(this).parent().siblings('.menu-item-attr-title').val(); 417 var item_target = $(this).parent().siblings('.menu-item-target').val(); 418 var item_classes = $(this).parent().siblings('.menu-item-classes').val(); 419 var item_xfn = $(this).parent().siblings('.menu-item-xfn').val(); 420 } else { 421 var item_attr_title = ''; 422 var item_target = '_self'; 423 var item_classes = ''; 424 var item_xfn = ''; 425 }; 421 426 422 // close postboxes that should be closed 423 $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); 427 var item_db_id = $(this).parent().siblings('.menu-item-db-id').val(); 428 var item_object_id = $(this).parent().siblings('.menu-item-object-id').val(); 429 var item_object = $(this).parent().siblings('.menu-item-object').val(); 430 var item_append = $(this).parent().siblings('.menu-item-append').val(); 431 var item_parent_id = $(this).parent().siblings('.menu-item-parent-id').val(); 432 var item_title = $(this).parent().siblings('.menu-item-title').val(); 433 var item_url = $(this).parent().siblings('.menu-item-url').val(); 434 var item_description = $(this).parent().siblings('.menu-item-description').val(); 424 435 425 // postboxes setup 426 postboxes.add_postbox_toggles('menus'); 436 if ( undefined == item_description ) { 437 item_description = ''; 438 }; 427 439 428 // Clear the quick search textbox 429 $('.quick-search').click(function(){ 430 $(this).attr( 'value', '' ); 431 }); 440 if ( undefined == item_attr_title ) { 441 item_attr_title = ''; 442 }; 432 443 433 // Quick Search submit 434 $('.quick-search-submit').click(function(){ 435 $(this).siblings('.quick-search').search(); 436 }); 444 // Add the menu item to the menu 445 wpNavMenu.add_to_menu( item_db_id, item_object_id, item_object, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ); 437 446 438 // Edit menu item 439 $('#menu-container .item-edit').click(function(){ 440 return wp_edit_menu_item( $(this).attr('value') ); 441 }); 447 // uncheck the menu item in the list 448 $(this).attr( 'checked', false ); 449 }); 450 }, 451 452 /** 453 * Returns all the nessecary hidden inputs for each menu item. 454 * 455 * @param string item_db_id - The menu item's db id. 456 * @param string item_object_id - The menu item's object id. 457 * @param string item_object - The menu item's object name. 458 * @param string item_type - The menu item's object type. 459 * @param string item_append - The menu item's nice name. 460 * @param string item_parent_id - The menu item's parent id. 461 * @param string item_title - The menu item title. 462 * @param string item_url - The menu item url 463 * @param string item_description - The menu item description. 464 * @param string item_attr_title - The title attribute. 465 * @param string item_target - The target attribute. 466 * @param string item_classes - Optional. Additional CSS classes for the menu item 467 * @param string item_xfn - Optional. The rel attribute. 468 */ 469 get_hidden_inputs : function( randomnumber, item_db_id, item_object_id, item_object, item_type, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) { 470 var hidden = ''; 442 471 443 // Delete menu item 444 $('#menu-container .item-delete').live( 'click', function(e){ 445 return wp_remove_menu_item( $(this).attr('value') ); 446 }); 472 hidden += '<input type="hidden" name="menu-item-db-id[]" value="' + item_db_id + '" />'; 473 hidden += '<input type="hidden" name="menu-item-object-id[]" value="' + item_object_id + '" />'; 474 hidden += '<input type="hidden" name="menu-item-object[]" value="' + item_object + '" />'; 475 hidden += '<input type="hidden" name="menu-item-type[]" value="' + item_type + '" />'; 476 hidden += '<input type="hidden" name="menu-item-parent-id[]" value="' + item_parent_id + '" />'; 477 hidden += '<input type="hidden" name="menu-item-position[]" value="' + randomnumber + '" />'; 478 hidden += '<input type="hidden" name="menu-item-title[]" value="' + item_title + '" />'; 479 hidden += '<input type="hidden" name="menu-item-attr-title[]" value="' + item_attr_title + '" />'; 480 hidden += '<input type="hidden" name="menu-item-url[]" value="' + item_url + '" />'; 481 hidden += '<input type="hidden" name="menu-item-target[]" value="' + item_target + '" />'; 482 hidden += '<input type="hidden" name="menu-item-description[]" value="' + item_description + '" />'; 483 hidden += '<input type="hidden" name="menu-item-classes[]" value="' + item_classes + '" />'; 484 hidden += '<input type="hidden" name="menu-item-xfn[]" value="' + item_xfn + '" />'; 447 485 448 // Update menu item settings (thickbox) 449 $('#update-menu-item').click(function(){ 450 wp_update_menu_item(); 451 return tb_remove(); 452 }); 453 454 // Close thickbox 455 $('#cancel-save').click(function(){ 456 return tb_remove(); 457 }); 458 459 // Show All Button 460 $('.show-all').click(function(e){ 461 jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'block' ); 462 jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'block' ); 463 jQuery(e.currentTarget).hide(); 464 jQuery(e.currentTarget).siblings('.hide-all').show(); 465 }); 466 467 // Hide All Button 468 $('.hide-all').click(function(e){ 469 jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'none' ); 470 jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'none' ); 471 jQuery(e.currentTarget).hide(); 472 jQuery(e.currentTarget).siblings('.show-all').show(); 473 }); 474 475 // Add menu items into the menu 476 $('.add-to-menu').click(function(e){ 477 return wp_add_checked_items_to_menu(e.currentTarget); 478 }); 479 480 // Create a new link then add it to the menu 481 $('#add-custom-links .add-to-menu a').click(function(e){ 482 // Add link to menu 483 if ( $('#custom-menu-item-url').val() == $('#custom-menu-item-url').attr('defaultValue') ) 484 return; // Do not allow "http://" submissions to go through 485 wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, $('#custom-menu-item-name').val(), $('#custom-menu-item-url').val(), '', '', '_self', '', '' ); 486 $('#custom-menu-item-name').val($('#custom-menu-item-name').attr('defaultValue')); 487 $('#custom-menu-item-url' ).val($('#custom-menu-item-url' ).attr('defaultValue')).focus(); 488 }); 489 }); 490 No newline at end of file 486 return hidden; 487 } 488 } 489 490 $(document).ready(function($){ wpNavMenu.init(); }); 491 })(jQuery); 492 No newline at end of file -
wp-admin/js/nav-menu.js
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="_self";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}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("#create-menu-name").keypress(function(b){if(13==b.keyCode){a("#create-menu-button").click();return false}});a("#custom-menu-item-url, #custom-menu-item-name").keypress(function(b){if(13==b.keyCode){a("#add-custom-links a.button").click();return false}}).focus(function(){if(a(this).val()==a(this).attr("defaultValue")&&a(this).attr("id")!="custom-menu-item-url"){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a("#create-menu-name").focus(function(){if(a(this).val()==a(this).attr("defaultValue")){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});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(b){if(a("#custom-menu-item-url").val()==a("#custom-menu-item-url").attr("defaultValue")){return}wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,a("#custom-menu-item-name").val(),a("#custom-menu-item-url").val(),"","","_self","","");a("#custom-menu-item-name").val(a("#custom-menu-item-name").attr("defaultValue"));a("#custom-menu-item-url").val(a("#custom-menu-item-url").attr("defaultValue")).focus()})});2 No newline at end of file 1 var wpNavMenu;(function($){wpNavMenu={init:function(){wpNavMenu.initial_meta_boxes();wpNavMenu.drag_and_drop();$("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});$("#update-nav-menu").submit(function(){wpNavMenu.update_post_data()});$("#create-menu-name").keypress(function(e){if(13==e.keyCode){$("#create-menu-button").click();return false}});$("#custom-menu-item-url, #custom-menu-item-name").keypress(function(e){if(13==e.keyCode){$("#add-custom-links a.button").click();return false}}).focus(function(){if($(this).val()==$(this).attr("defaultValue")&&$(this).attr("id")!="custom-menu-item-url"){$(this).val("")}}).blur(function(){if($(this).val()==""){$(this).val($(this).attr("defaultValue"))}});$("#create-menu-name").focus(function(){if($(this).val()==$(this).attr("defaultValue")){$(this).val("")}}).blur(function(){if($(this).val()==""){$(this).val($(this).attr("defaultValue"))}});$(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("nav-menus");$(".quick-search").click(function(){$(this).attr("value","")});$(".quick-search-submit").click(function(){$(this).siblings(".quick-search").search()});$("#menu-container .item-edit").click(function(){wpNavMenu.edit_menu_item($(this).attr("value"))});$("#menu-container .item-delete").click(function(){wpNavMenu.remove_menu_item($(this).attr("value"))});$("#update-menu-item").click(function(){wpNavMenu.update_menu_item();tb_remove()});$("#cancel-save").click(function(){tb_remove()});$(".show-all").click(function(e){$(e.currentTarget).parent().parent().siblings(".list-wrap").css("display","block");$(e.currentTarget).parent().parent().siblings(".list-wrap").find("li").css("display","block");$(e.currentTarget).hide();$(e.currentTarget).siblings(".hide-all").show()});$(".hide-all").click(function(e){$(e.currentTarget).parent().parent().siblings(".list-wrap").css("display","none");$(e.currentTarget).parent().parent().siblings(".list-wrap").find("li").css("display","none");$(e.currentTarget).hide();$(e.currentTarget).siblings(".show-all").show()});$(".add-to-menu").click(function(e){wpNavMenu.add_checked_items_to_menu(e.currentTarget)});$("#add-custom-links .add-to-menu a").click(function(e){if($("#custom-menu-item-url").val()==$("#custom-menu-item-url").attr("defaultValue")){return}wpNavMenu.add_custom_link($("#custom-menu-item-name").val(),$("#custom-menu-item-url").val());$("#custom-menu-item-name").val($("#custom-menu-item-name").attr("defaultValue"));$("#custom-menu-item-url").val($("#custom-menu-item-url").attr("defaultValue")).focus()})},add_custom_link:function(link_name,link_url){var params={action:"save-custom-link",link_name:link_name,link_url:link_url};$.post(ajaxurl,params,function(link_id){if("-1"==link_id){return}wpNavMenu.add_to_menu(link_id,link_id,"custom","custom",navMenuL10n.custom,0,link_name,link_url,"","","_self","","")},"json")},initial_meta_boxes:function(){var hidden=$("#hidden-metaboxes").val().split(",");if(""!=hidden){for(var i=0;i<hidden.length;i++){$("#"+hidden[i]).attr("style","display: none;");$("#"+hidden[i]+"-hide").attr("checked",false)}}},drag_and_drop:function(){$(".menu li").each(function(){if(!$(this).children(".dropzone").attr("class")){$(this).prepend('<div class="dropzone"></div>')}});$(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});$(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(e,ui){var li=$(this).parent();var child=!$(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);$(this).parent().find("dt").removeAttr("style");$(this).parent().find("div:first").removeAttr("style")},over:function(e){if($(this).attr("class")=="dropzone ui-droppable"){$(this).parent().find("div:first").css({background:"#f5f5f5",border:"1px dashed #bbb",margin:"10px 0px",height:"40px"})}else{if($(this).attr("class")=="ui-droppable"){$(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}},out:function(){$(this).parent().find("dt").removeAttr("style");$(this).parent().find("div:first").removeAttr("style");$(this).filter(".dropzone").css({borderColor:""})}})},update_post_data:function(){var i=0;$(".menu li").each(function(){i=i+1;var j=$(this).attr("value");var id=$(this).children("input[name=menu-item-db-id[]]").val();$(this).attr("value",i);$(this).children("input[name=menu-item-position[]]").attr("value",i);var pid=$(this).parent(".sub-menu").siblings("input[name=menu-item-object-id[]]").val();if(undefined==pid){pid=0}$(this).children("input[name=menu-item-parent-id[]]").attr("value",pid);$("#li-count").attr("value",i)})},autocomplete:function(id){$("#add-"+id+" .quick-search").autocomplete($("#add-"+id+" .autocomplete").val().split("|"));$("#add-"+id+" .quick-search").result(function(event,data,formatted){$("#add-"+id+" .list-wrap").css("display","block");$("#add-"+id+" .list-wrap li:contains('"+data+"')").css("display","block");$("#add-"+id+" .show-all").hide();$("#add-"+id+" .hide-all").show()})},edit_menu_item:function(id){var item_type=$("#menu-item-"+id).children("input[name=menu-item-type[]]").val();var item_title=$("#menu-item-"+id).children("input[name=menu-item-title[]]").val();var item_link=$("#menu-item-"+id).children("input[name=menu-item-url[]]").val();var item_attr_title=$("#menu-item-"+id).children("input[name=menu-item-attr-title[]]").val();var item_target=$("#menu-item-"+id).children("input[name=menu-item-target[]]").val();var item_description=$("#menu-item-"+id).children("input[name=menu-item-description[]]").val();var item_classes=$("#menu-item-"+id).children("input[name=menu-item-classes[]]").val();var item_xfn=$("#menu-item-"+id).children("input[name=menu-item-xfn[]]").val();if("custom"!=item_type){$("#edit-menu-item-url").attr("disabled","disabled")}$("#edit-menu-item-id").val(id);$("#edit-menu-item-title").val(item_title);$("#edit-menu-item-url").val(item_link);$("#edit-menu-item-attr-title").val(item_attr_title);$("#edit-menu-item-target").val(item_target);$("#edit-menu-item-target option[value='"+item_target+"']").attr("selected","selected");$("#edit-menu-item-description").val(item_description);$("#edit-menu-item-classes").val(item_classes);$("#edit-menu-item-xfn").val(item_xfn)},update_menu_item:function(){var id=$("#edit-menu-item-id").val();var item_title=$("#edit-menu-item-title").val();var item_link=$("#edit-menu-item-url").val();var item_attr_title=$("#edit-menu-item-attr-title").val();var item_target=$("#edit-menu-item-target").val();var item_description=$("#edit-menu-item-description").val();var item_classes=$("#edit-menu-item-classes").val();var item_xfn=$("#edit-menu-item-xfn").val();$(".menu #menu-item-"+id).find("span.item-title:first").html(item_title);$("#menu-item-"+id).children("input[name=menu-item-title[]]").val(item_title);$("#menu-item-"+id).children("input[name=menu-item-url[]]").val(item_link);$("#menu-item-"+id).children("input[name=menu-item-attr-title[]]").val(item_attr_title);$("#menu-item-"+id).children("input[name=menu-item-target[]]").val(item_target);$("#menu-item-"+id).children("input[name=menu-item-description[]]").val(item_description);$("#menu-item-"+id).children("input[name=menu-item-classes[]]").val(item_classes);$("#menu-item-"+id).children("input[name=menu-item-xfn[]]").val(item_xfn);$(".menu #menu-item-"+id+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){$(this).css("backgroundColor","")}})},remove_menu_item:function(id){var todelete=$("#menu-item-"+id);if(todelete){$(todelete).find("dt").each(function(){$(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){$(this).parent().parent().remove()}})})}},add_to_menu:function(item_db_id,item_object_id,item_object,item_type,item_append,item_parent_id,item_title,item_url,item_description,item_attr_title,item_target,item_classes,item_xfn){var randomnumber=$(".menu li").length+1;var hidden=wpNavMenu.get_hidden_inputs(randomnumber,item_db_id,item_object_id,item_object,item_type,item_parent_id,item_title,item_url,item_description,item_attr_title,item_target,item_classes,item_xfn);$(".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="wpNavMenu.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+'" onclick="wpNavMenu.remove_menu_item('+randomnumber+');">Delete</a></span></dt></dl>'+hidden+"</li>");$(".menu #menu-item-"+randomnumber+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){$(this).css("backgroundColor","")}});wpNavMenu.drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")},add_checked_items_to_menu:function(button){var items=$(button).parent().siblings(".list-wrap").find(":checked");if(0==items.length){return false}$(items).each(function(){var item_type=$(this).parent().siblings(".menu-item-type").val();if("custom"==item_type){var item_attr_title=$(this).parent().siblings(".menu-item-attr-title").val();var item_target=$(this).parent().siblings(".menu-item-target").val();var item_classes=$(this).parent().siblings(".menu-item-classes").val();var item_xfn=$(this).parent().siblings(".menu-item-xfn").val()}else{var item_attr_title="";var item_target="_self";var item_classes="";var item_xfn=""}var item_db_id=$(this).parent().siblings(".menu-item-db-id").val();var item_object_id=$(this).parent().siblings(".menu-item-object-id").val();var item_object=$(this).parent().siblings(".menu-item-object").val();var item_append=$(this).parent().siblings(".menu-item-append").val();var item_parent_id=$(this).parent().siblings(".menu-item-parent-id").val();var item_title=$(this).parent().siblings(".menu-item-title").val();var item_url=$(this).parent().siblings(".menu-item-url").val();var item_description=$(this).parent().siblings(".menu-item-description").val();if(undefined==item_description){item_description=""}if(undefined==item_attr_title){item_attr_title=""}wpNavMenu.add_to_menu(item_db_id,item_object_id,item_object,item_type,item_append,item_parent_id,item_title,item_url,item_description,item_attr_title,item_target,item_classes,item_xfn);$(this).attr("checked",false)})},get_hidden_inputs:function(randomnumber,item_db_id,item_object_id,item_object,item_type,item_parent_id,item_title,item_url,item_description,item_attr_title,item_target,item_classes,item_xfn){var hidden="";hidden+='<input type="hidden" name="menu-item-db-id[]" value="'+item_db_id+'" />';hidden+='<input type="hidden" name="menu-item-object-id[]" value="'+item_object_id+'" />';hidden+='<input type="hidden" name="menu-item-object[]" value="'+item_object+'" />';hidden+='<input type="hidden" name="menu-item-type[]" value="'+item_type+'" />';hidden+='<input type="hidden" name="menu-item-parent-id[]" value="'+item_parent_id+'" />';hidden+='<input type="hidden" name="menu-item-position[]" value="'+randomnumber+'" />';hidden+='<input type="hidden" name="menu-item-title[]" value="'+item_title+'" />';hidden+='<input type="hidden" name="menu-item-attr-title[]" value="'+item_attr_title+'" />';hidden+='<input type="hidden" name="menu-item-url[]" value="'+item_url+'" />';hidden+='<input type="hidden" name="menu-item-target[]" value="'+item_target+'" />';hidden+='<input type="hidden" name="menu-item-description[]" value="'+item_description+'" />';hidden+='<input type="hidden" name="menu-item-classes[]" value="'+item_classes+'" />';hidden+='<input type="hidden" name="menu-item-xfn[]" value="'+item_xfn+'" />';return hidden}};$(document).ready(function($){wpNavMenu.init()})})(jQuery); 2 No newline at end of file -
wp-admin/nav-menus.php
12 12 /** Load WordPress Administration Bootstrap */ 13 13 require_once( 'admin.php' ); 14 14 15 // Load all the nav menu interface functions 16 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); 17 15 18 // Permissions Check 16 19 if ( ! current_user_can('switch_themes') ) 17 20 wp_die( __( 'Cheatin’ uh?' )); … … 37 40 // Thickbox 38 41 add_thickbox(); 39 42 40 // Load all the nav menu interface functions41 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );42 43 43 // Container for any messages displayed to the user 44 44 $messages_div = ''; 45 45 … … 57 57 check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id ); 58 58 59 59 if ( is_nav_menu($nav_menu_selected_id) ) { 60 wp_delete_nav_menu( $nav_menu_selected_id ); 61 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('Menu successfully deleted.') . '</p></div>'; 62 $nav_menu_selected_id = 0; 60 $delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id ); 61 62 if ( is_wp_error($delete_nav_menu) ) { 63 $messages_div = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>'; 64 } else { 65 $messages_div = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>'; 66 $nav_menu_selected_id = 0; // Reset the selected menu 67 } 68 unset( $delete_nav_menu ); 63 69 } 64 70 break; 65 71 … … 75 81 $add_nav_menu = wp_create_nav_menu( $add_nav_menu ); 76 82 77 83 if ( is_wp_error( $add_nav_menu ) ) { 78 $messages_div = '<div id="message" class="error fade below-h2"><p>' . $add_nav_menu->get_error_message() . '</p></div>';84 $messages_div = '<div id="message" class="error"><p>' . $add_nav_menu->get_error_message() . '</p></div>'; 79 85 } else { 80 86 $nav_menu_selected_id = $add_nav_menu->term_id; 81 87 $nav_menu_selected_title = $add_nav_menu->name; 82 $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>';88 $messages_div = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $add_nav_menu->name ) . '</p></div>'; 83 89 } 84 90 } else { 85 $messages_div = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>';91 $messages_div = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; 86 92 } 87 unset( $add_nav_menu);93 unset( $add_nav_menu ); 88 94 } 89 95 } else { 96 97 // @todo wrap this into wp_update_nav_menu_object(); 90 98 if ( isset($_POST['menu-name']) ) { 91 99 $old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A ); 92 100 $args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], ); 93 101 $new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args ); 94 102 } 95 103 96 104 // Update menu items 97 $update_nav_items = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0; 105 106 // @todo: wrap update logic into wp_update_nav_menu(); 107 $update_count = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0; 98 108 $update_nav_menu = is_nav_menu( $nav_menu_selected_id ); 99 109 100 110 if ( !is_wp_error($update_nav_menu) ) { 101 111 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); 102 $parent_menu_ids = array(); 103 112 104 113 // Loop through all POST variables 105 for ( $k = 0; $k < $update_nav_items; $k++ ) { 114 for ( $k = 0; $k < $update_count; $k++ ) { 115 116 // Menu item title can't be blank 117 if ( '' == $_POST['menu-item-title'][$k] ) 118 continue; 119 106 120 $menu_item_db_id = isset( $_POST['menu-item-db-id'][$k] ) ? $_POST['menu-item-db-id'][$k] : 0; 107 121 $menu_item_object_id = isset( $_POST['menu-item-object-id'][$k] ) ? $_POST['menu-item-object-id'][$k] : 0; 122 $menu_item_object = isset( $_POST['menu-item-object'][$k] ) ? $_POST['menu-item-object'][$k] : ''; 108 123 $menu_item_parent_id = isset( $_POST['menu-item-parent-id'][$k] ) ? $_POST['menu-item-parent-id'][$k] : 0; 109 124 $menu_item_position = isset( $_POST['menu-item-position'][$k] ) ? $_POST['menu-item-position'][$k] : 0; 110 125 $menu_item_type = isset( $_POST['menu-item-type'][$k] ) ? $_POST['menu-item-type'][$k] : 'custom'; … … 113 128 $menu_item_url = isset( $_POST['menu-item-url'][$k] ) ? $_POST['menu-item-url'][$k] : ''; 114 129 $menu_item_description = isset( $_POST['menu-item-description'][$k] ) ? $_POST['menu-item-description'][$k] : ''; 115 130 $menu_item_attr_title = isset( $_POST['menu-item-attr-title'][$k] ) ? $_POST['menu-item-attr-title'][$k] : ''; 116 $menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : 0;131 $menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : '_self'; 117 132 $menu_item_classes = isset( $_POST['menu-item-classes'][$k] ) ? $_POST['menu-item-classes'][$k] : ''; 118 133 $menu_item_xfn = isset( $_POST['menu-item-xfn'][$k] ) ? $_POST['menu-item-xfn'][$k] : ''; 119 134 120 // Menu item title can't be blank 121 if ( '' == $menu_item_title ) 122 continue; 123 124 // Populate the menu item 125 $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID, 126 'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position, 127 'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ), 128 'post_content' => $menu_item_description, 'post_title' => $menu_item_title ); 129 135 // Populate the menu item object 136 $post = array( 137 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'ping_status' => 0, 138 'post_author' => $user_ID, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ), 139 'post_title' => $menu_item_title, 'post_excerpt' => $menu_item_attr_title, 140 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position, 141 'post_content' => $menu_item_description, 142 ); 143 130 144 // New menu item 131 145 if ( $menu_item_db_id == 0 ) { 132 146 $menu_item_db_id = wp_insert_post( $post ); 133 } elseif ( isset( $menu_items[$menu_item_db_id] ) ) { 147 148 // Update existing menu item 149 } elseif ( isset($menu_items[$menu_item_db_id]) || ( 'custom' == $menu_item_type && 0 != $menu_item_db_id ) ) { 134 150 $post['ID'] = $menu_item_db_id; 135 151 wp_update_post( $post ); 136 152 unset( $menu_items[$menu_item_db_id] ); 137 153 } 138 $parent_menu_ids[$k] = $menu_item_db_id;139 154 140 // @todo sanitize type append and ID. 141 update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type ); 142 update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append ); 143 update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id ); 144 update_post_meta( $menu_item_db_id, 'menu_item_target', sanitize_key($menu_item_target) ); 155 update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($menu_item_type) ); 156 update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $menu_item_object_id ); 157 update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($menu_item_object) ); 158 update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($menu_item_target) ); 145 159 // @todo handle sanitizing multiple classes separated by whitespace. 146 update_post_meta( $menu_item_db_id, ' menu_item_classes', sanitize_html_class($menu_item_classes) );147 update_post_meta( $menu_item_db_id, ' menu_item_xfn', sanitize_html_class($menu_item_xfn) );160 update_post_meta( $menu_item_db_id, '_menu_item_classes', sanitize_html_class($menu_item_classes) ); 161 update_post_meta( $menu_item_db_id, '_menu_item_xfn', sanitize_html_class($menu_item_xfn) ); 148 162 149 163 // @todo: only save custom link urls. 150 update_post_meta( $menu_item_db_id, ' menu_item_url', esc_url_raw( $menu_item_url) );164 update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($menu_item_url) ); 151 165 } 152 166 153 167 // Remove menu items from the menu that weren't in $_POST … … 156 170 wp_delete_post( $menu_item_id ); 157 171 } 158 172 } 159 $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>'; 173 174 do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); 175 176 $messages_div = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $update_nav_menu->name ) . '</p></div>'; 177 unset( $update_nav_menu, $update_count, $menu_items ); 160 178 } 161 179 } 162 180 break; … … 192 210 193 211 // The user has no menus. 194 212 if ( !is_nav_menu( $nav_menu_selected_id ) ) { 195 if ( current_theme_supports('nav-menus') ) { 196 $messages_div = '<div id="message" class="updated"><p>' . __('You do not have any menus. Create a new menu.') . '</p></div>'; 197 } else { 198 $messages_div = '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>'; 199 } 213 $messages_div = '<div id="message" class="updated"><p>' . __('You do not have any menus. Create a new menu.') . '</p></div>'; 214 215 // The theme supports menus 216 } elseif ( current_theme_supports('nav-menus') ) { 217 218 // Register nav menu metaboxes 219 add_meta_box( 'create-menu', __('Create Menu'), 'wp_nav_menu_create_metabox', 'nav-menus', 'side', 'core' ); 220 add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'nav-menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) ); 221 wp_nav_menu_metaboxes_setup(); 222 223 // The theme does not support menus 200 224 } else { 201 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 ) );225 $messages_div = '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>'; 202 226 } 203 227 204 228 // Get the admin header … … 210 234 <?php echo $messages_div; ?> 211 235 <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> 212 236 213 <?php if ( !empty($nav_menus) && count($nav_menus) > 1 ) : ?>237 <?php if ( !empty($nav_menus) && count($nav_menus) > 1 && current_theme_supports('nav-menus') ) : ?> 214 238 <ul class="subsubsub"> 215 239 <?php 216 240 foreach ( $nav_menus as $_nav_menu ) { … … 226 250 <?php endif; ?> 227 251 228 252 <div id="menu-management" class="metabox-holder has-right-sidebar"> 229 <form id="update-nav-menu" onsubmit="wp_update_post_data();"action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data">253 <form id="update-nav-menu" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data"> 230 254 <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> 231 255 <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> 232 256 <?php wp_nonce_field( 'update-nav_menu' ); ?> 233 257 <input type="hidden" name="action" value="update" /> 234 <input type="hidden" name="li-count" id="li-count" value=" 0" />258 <input type="hidden" name="li-count" id="li-count" value="-1" /> 235 259 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 236 260 <input type="hidden" id="hidden-metaboxes" value="<?php echo wp_initial_nav_menu_meta_boxes(); ?>" /> 237 261 <div id="post-body"> 238 262 <div id="post-body-content"> 239 <?php if ( is_nav_menu($nav_menu_selected_id) ) : ?>263 <?php if ( is_nav_menu($nav_menu_selected_id) && current_theme_supports('nav-menus') ) : ?> 240 264 <div id="menu-container" class="postbox"> 241 265 <h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3> 242 266 <div class="inside"> 243 244 267 <?php echo wp_get_nav_menu( array( 'context' => 'backend', 'menu' => $nav_menu_selected_id ) ); ?> 245 246 268 </div><!-- /.inside --> 247 269 <!-- /#nav-menu-canvas .postbox--> 248 270 </div> 249 <script type="text/javascript">250 wp_update_post_data();251 </script>252 271 <?php endif; ?> 253 272 </div><!-- /#post-body-content--> 254 273 </div><!--- /#post-body --> 255 274 <div id="menu-settings-column" class="inner-sidebar"> 256 275 257 <?php do_meta_boxes( ' menus', 'side', null ); ?>276 <?php do_meta_boxes( 'nav-menus', 'side', null ); ?> 258 277 259 278 </div><!-- /#menu-settings-column --> 260 279 </form><!--/#update-nav-menu--> -
wp-admin/css/nav-menu.css
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
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;}2 No newline at end of file 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;}.list-controls{float:left;}.add-to-menu{float:right;}.button-controls{margin:10px 0;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}#create-menu-name{width:159px;}#manage-menu .inside{padding: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;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;margin-bottom:10px;}.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-radius:6px;border-radius:6px;-moz-border-radius: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;}.button-controls:after,#menu-item-url-wrap:after,#menu-item-name-wrap:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.button-controls,#menu-item-url-wrap,#menu-item-name-wrap{display:block;} 2 No newline at end of file -
wp-admin/css/nav-menu.dev.css
20 20 #cancel-save:hover { background-color: #FF0000; color: #fff; } 21 21 22 22 /* Button Secondary Actions */ 23 . button-controls { float: left; }23 .list-controls { float: left; } 24 24 .add-to-menu { float: right; } 25 .button-controls { margin: 10px 0; } 26 .show-all, .hide-all { cursor: pointer; } 27 .hide-all { display: none; } 25 28 26 #manage-menu .inside { padding: 0px 0px; }27 28 29 /* Create Menu */ 29 30 #create-menu-name { width: 159px; } 31 #manage-menu .inside { padding: 0px 0px; } 30 32 31 33 /* Custom Links */ 32 #available-links { margin: 15px 0px 0px; }33 34 #available-links dt { display: block; } 34 35 #add-custom-link .howto { font-size: 11px; } 35 36 #add-custom-link label span { display: block; float: left; margin-top: 5px; padding-right: 5px; } 36 37 .menu-item-textbox { float: right; width: 220px; } 37 38 .howto span { margin-top: 4px; display: block; float: left; } 38 39 39 /* Pages/Categories */ 40 .show-all, .hide-all { cursor: pointer; } 41 .hide-all { display: none; } 42 40 /* Menu item types */ 43 41 .quick-search { width: 190px; } 44 .list-wrap { display: none; clear: both; }42 .list-wrap { display: none; clear: both; margin-bottom: 10px; } 45 43 .list-container { max-height: 200px; overflow-y: auto; padding: 10px 10px 5px; border: 1px solid #DFDFDF; -moz-border-radius: 4px; } 46 44 .postbox p.submit { margin-bottom: 0; } 47 45 … … 60 58 .list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 98px; } 61 59 .list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 112px; } 62 60 63 /* Menu */61 /* Nav Menu */ 64 62 #menu-container .inside { padding-bottom: 10px; } 65 63 66 64 .menu ul { width: 100%; } 67 65 .menu li { margin: 0; } 68 .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; }66 .menu li dl dt { -webkit-border-radius: 6px; border-radius: 6px; -moz-border-radius: 6px; border: 1px solid #E6E6E6; position: relative; padding-left: 10px; background-color: #f1f1f1; height: 35px; line-height: 35px; } 69 67 .menu li dl dt:hover { cursor: move; } 70 68 71 69 .menu li .item-title { } … … 78 76 .dropzone { height: 7px; margin: 3px 0 3px 0; } 79 77 .ui-draggable-dragging { width: 600px; } 80 78 81 /* Menu Controls */79 /* Menu item controls */ 82 80 .item-type { text-transform: uppercase; font-size: 11px; color: #999999; padding-right: 10px; } 83 81 .item-controls { font-size: 11px; position: absolute; right: 15px; top: -1px; } 84 82 .item-controls a { text-decoration: none; } … … 92 90 #update-menu-item { color: #fff !important; } 93 91 #update-menu-item:hover, 94 92 #update-menu-item:active, 95 #update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; } 96 No newline at end of file 93 #update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; } 94 95 /* Clearfix */ 96 .button-controls:after, #menu-item-url-wrap:after, #menu-item-name-wrap:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } 97 .button-controls, #menu-item-url-wrap, #menu-item-name-wrap { display: block; } 98 No newline at end of file