PageRenderTime 298ms CodeModel.GetById 120ms app.highlight 132ms RepoModel.GetById 29ms app.codeStats 1ms

/wp-admin/includes/nav-menu.php

https://bitbucket.org/abnopanda/wordpress
PHP | 1162 lines | 876 code | 130 blank | 156 comment | 147 complexity | dddc9f1dcff6b427e282fa6cef9b9cfa MD5 | raw file
   1<?php
   2
   3/**
   4 * Create HTML list of nav menu input items.
   5 *
   6 * @package WordPress
   7 * @since 3.0.0
   8 * @uses Walker_Nav_Menu
   9 */
  10class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
  11	/**
  12	 * @see Walker_Nav_Menu::start_lvl()
  13	 * @since 3.0.0
  14	 *
  15	 * @param string $output Passed by reference.
  16	 */
  17	function start_lvl(&$output) {}
  18
  19	/**
  20	 * @see Walker_Nav_Menu::end_lvl()
  21	 * @since 3.0.0
  22	 *
  23	 * @param string $output Passed by reference.
  24	 */
  25	function end_lvl(&$output) {
  26	}
  27
  28	/**
  29	 * @see Walker::start_el()
  30	 * @since 3.0.0
  31	 *
  32	 * @param string $output Passed by reference. Used to append additional content.
  33	 * @param object $item Menu item data object.
  34	 * @param int $depth Depth of menu item. Used for padding.
  35	 * @param object $args
  36	 */
  37	function start_el(&$output, $item, $depth, $args) {
  38		global $_wp_nav_menu_max_depth;
  39		$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
  40
  41		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  42
  43		ob_start();
  44		$item_id = esc_attr( $item->ID );
  45		$removed_args = array(
  46			'action',
  47			'customlink-tab',
  48			'edit-menu-item',
  49			'menu-item',
  50			'page-tab',
  51			'_wpnonce',
  52		);
  53
  54		$original_title = '';
  55		if ( 'taxonomy' == $item->type ) {
  56			$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
  57			if ( is_wp_error( $original_title ) )
  58				$original_title = false;
  59		} elseif ( 'post_type' == $item->type ) {
  60			$original_object = get_post( $item->object_id );
  61			$original_title = $original_object->post_title;
  62		}
  63
  64		$classes = array(
  65			'menu-item menu-item-depth-' . $depth,
  66			'menu-item-' . esc_attr( $item->object ),
  67			'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
  68		);
  69
  70		$title = $item->title;
  71
  72		if ( ! empty( $item->_invalid ) ) {
  73			$classes[] = 'menu-item-invalid';
  74			/* translators: %s: title of menu item which is invalid */
  75			$title = sprintf( __( '%s (Invalid)' ), $item->title );
  76		} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
  77			$classes[] = 'pending';
  78			/* translators: %s: title of menu item in draft status */
  79			$title = sprintf( __('%s (Pending)'), $item->title );
  80		}
  81
  82		$title = empty( $item->label ) ? $title : $item->label;
  83
  84		?>
  85		<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
  86			<dl class="menu-item-bar">
  87				<dt class="menu-item-handle">
  88					<span class="item-title"><?php echo esc_html( $title ); ?></span>
  89					<span class="item-controls">
  90						<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
  91						<span class="item-order hide-if-js">
  92							<a href="<?php
  93								echo wp_nonce_url(
  94									add_query_arg(
  95										array(
  96											'action' => 'move-up-menu-item',
  97											'menu-item' => $item_id,
  98										),
  99										remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
 100									),
 101									'move-menu_item'
 102								);
 103							?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
 104							|
 105							<a href="<?php
 106								echo wp_nonce_url(
 107									add_query_arg(
 108										array(
 109											'action' => 'move-down-menu-item',
 110											'menu-item' => $item_id,
 111										),
 112										remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
 113									),
 114									'move-menu_item'
 115								);
 116							?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
 117						</span>
 118						<a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
 119							echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
 120						?>"><?php _e( 'Edit Menu Item' ); ?></a>
 121					</span>
 122				</dt>
 123			</dl>
 124
 125			<div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
 126				<?php if( 'custom' == $item->type ) : ?>
 127					<p class="field-url description description-wide">
 128						<label for="edit-menu-item-url-<?php echo $item_id; ?>">
 129							<?php _e( 'URL' ); ?><br />
 130							<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
 131						</label>
 132					</p>
 133				<?php endif; ?>
 134				<p class="description description-thin">
 135					<label for="edit-menu-item-title-<?php echo $item_id; ?>">
 136						<?php _e( 'Navigation Label' ); ?><br />
 137						<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
 138					</label>
 139				</p>
 140				<p class="description description-thin">
 141					<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
 142						<?php _e( 'Title Attribute' ); ?><br />
 143						<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
 144					</label>
 145				</p>
 146				<p class="field-link-target description">
 147					<label for="edit-menu-item-target-<?php echo $item_id; ?>">
 148						<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
 149						<?php _e( 'Open link in a new window/tab' ); ?>
 150					</label>
 151				</p>
 152				<p class="field-css-classes description description-thin">
 153					<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
 154						<?php _e( 'CSS Classes (optional)' ); ?><br />
 155						<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
 156					</label>
 157				</p>
 158				<p class="field-xfn description description-thin">
 159					<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
 160						<?php _e( 'Link Relationship (XFN)' ); ?><br />
 161						<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
 162					</label>
 163				</p>
 164				<p class="field-description description description-wide">
 165					<label for="edit-menu-item-description-<?php echo $item_id; ?>">
 166						<?php _e( 'Description' ); ?><br />
 167						<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
 168						<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
 169					</label>
 170				</p>
 171
 172				<div class="menu-item-actions description-wide submitbox">
 173					<?php if( 'custom' != $item->type && $original_title !== false ) : ?>
 174						<p class="link-to-original">
 175							<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
 176						</p>
 177					<?php endif; ?>
 178					<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
 179					echo wp_nonce_url(
 180						add_query_arg(
 181							array(
 182								'action' => 'delete-menu-item',
 183								'menu-item' => $item_id,
 184							),
 185							remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
 186						),
 187						'delete-menu_item_' . $item_id
 188					); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php	echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) );
 189						?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
 190				</div>
 191
 192				<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
 193				<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
 194				<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
 195				<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
 196				<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
 197				<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
 198			</div><!-- .menu-item-settings-->
 199			<ul class="menu-item-transport"></ul>
 200		<?php
 201		$output .= ob_get_clean();
 202	}
 203}
 204
 205/**
 206 * Create HTML list of nav menu input items.
 207 *
 208 * @package WordPress
 209 * @since 3.0.0
 210 * @uses Walker_Nav_Menu
 211 */
 212class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
 213	function __construct( $fields = false ) {
 214		if ( $fields ) {
 215			$this->db_fields = $fields;
 216		}
 217	}
 218
 219	function start_lvl( &$output, $depth ) {
 220		$indent = str_repeat( "\t", $depth );
 221		$output .= "\n$indent<ul class='children'>\n";
 222	}
 223
 224	function end_lvl( &$output, $depth ) {
 225		$indent = str_repeat( "\t", $depth );
 226		$output .= "\n$indent</ul>";
 227	}
 228
 229	/**
 230	 * @see Walker::start_el()
 231	 * @since 3.0.0
 232	 *
 233	 * @param string $output Passed by reference. Used to append additional content.
 234	 * @param object $item Menu item data object.
 235	 * @param int $depth Depth of menu item. Used for padding.
 236	 * @param object $args
 237	 */
 238	function start_el(&$output, $item, $depth, $args) {
 239		global $_nav_menu_placeholder;
 240
 241		$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
 242		$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
 243		$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
 244
 245		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
 246
 247		$output .= $indent . '<li>';
 248		$output .= '<label class="menu-item-title">';
 249		$output .= '<input type="checkbox" class="menu-item-checkbox';
 250		if ( property_exists( $item, 'front_or_home' ) && $item->front_or_home ) {
 251			$title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $item->post_title );
 252			$output .= ' add-to-top';
 253		}
 254		$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
 255		$output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
 256		$output .= '</label>';
 257
 258		// Menu item hidden fields
 259		$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
 260		$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
 261		$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />';
 262		$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />';
 263		$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
 264		$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
 265		$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
 266		$output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
 267		$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
 268		$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
 269	}
 270}
 271
 272/**
 273 * Prints the appropriate response to a menu quick search.
 274 *
 275 * @since 3.0.0
 276 *
 277 * @param array $request The unsanitized request values.
 278 */
 279function _wp_ajax_menu_quick_search( $request = array() ) {
 280	$args = array();
 281	$type = isset( $request['type'] ) ? $request['type'] : '';
 282	$object_type = isset( $request['object_type'] ) ? $request['object_type'] : '';
 283	$query = isset( $request['q'] ) ? $request['q'] : '';
 284	$response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json';
 285
 286	if ( 'markup' == $response_format ) {
 287		$args['walker'] = new Walker_Nav_Menu_Checklist;
 288	}
 289
 290	if ( 'get-post-item' == $type ) {
 291		if ( post_type_exists( $object_type ) ) {
 292			if ( isset( $request['ID'] ) ) {
 293				$object_id = (int) $request['ID'];
 294				if ( 'markup' == $response_format ) {
 295					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
 296				} elseif ( 'json' == $response_format ) {
 297					$post_obj = get_post( $object_id );
 298					echo json_encode(
 299						array(
 300							'ID' => $object_id,
 301							'post_title' => get_the_title( $object_id ),
 302							'post_type' => get_post_type( $object_id ),
 303						)
 304					);
 305					echo "\n";
 306				}
 307			}
 308		} elseif ( taxonomy_exists( $object_type ) ) {
 309			if ( isset( $request['ID'] ) ) {
 310				$object_id = (int) $request['ID'];
 311				if ( 'markup' == $response_format ) {
 312					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
 313				} elseif ( 'json' == $response_format ) {
 314					$post_obj = get_term( $object_id, $object_type );
 315					echo json_encode(
 316						array(
 317							'ID' => $object_id,
 318							'post_title' => $post_obj->name,
 319							'post_type' => $object_type,
 320						)
 321					);
 322					echo "\n";
 323				}
 324			}
 325
 326		}
 327
 328	} elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
 329		if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
 330			query_posts(array(
 331				'posts_per_page' => 10,
 332				'post_type' => $matches[2],
 333				's' => $query,
 334			));
 335			if ( ! have_posts() )
 336				return;
 337			while ( have_posts() ) {
 338				the_post();
 339				if ( 'markup' == $response_format ) {
 340					$var_by_ref = get_the_ID();
 341					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
 342				} elseif ( 'json' == $response_format ) {
 343					echo json_encode(
 344						array(
 345							'ID' => get_the_ID(),
 346							'post_title' => get_the_title(),
 347							'post_type' => get_post_type(),
 348						)
 349					);
 350					echo "\n";
 351				}
 352			}
 353		} elseif ( 'taxonomy' == $matches[1] ) {
 354			$terms = get_terms( $matches[2], array(
 355				'name__like' => $query,
 356				'number' => 10,
 357			));
 358			if ( empty( $terms ) || is_wp_error( $terms ) )
 359				return;
 360			foreach( (array) $terms as $term ) {
 361				if ( 'markup' == $response_format ) {
 362					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
 363				} elseif ( 'json' == $response_format ) {
 364					echo json_encode(
 365						array(
 366							'ID' => $term->term_id,
 367							'post_title' => $term->name,
 368							'post_type' => $matches[2],
 369						)
 370					);
 371					echo "\n";
 372				}
 373			}
 374		}
 375	}
 376}
 377
 378/**
 379 * Register nav menu metaboxes and advanced menu items
 380 *
 381 * @since 3.0.0
 382 **/
 383function wp_nav_menu_setup() {
 384	// Register meta boxes
 385	if ( wp_get_nav_menus() )
 386		add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' );
 387	add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
 388	wp_nav_menu_post_type_meta_boxes();
 389	wp_nav_menu_taxonomy_meta_boxes();
 390
 391	// Register advanced menu items (columns)
 392	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns');
 393
 394	// If first time editing, disable advanced items by default.
 395	if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
 396		$user = wp_get_current_user();
 397		update_user_option($user->ID, 'managenav-menuscolumnshidden',
 398			array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', ),
 399			true);
 400	}
 401}
 402
 403/**
 404 * Limit the amount of meta boxes to just links, pages and cats for first time users.
 405 *
 406 * @since 3.0.0
 407 **/
 408function wp_initial_nav_menu_meta_boxes() {
 409	global $wp_meta_boxes;
 410
 411	if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) )
 412		return;
 413
 414	$initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-custom-links', 'add-page', 'add-category' );
 415	$hidden_meta_boxes = array();
 416
 417	foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {
 418		foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) {
 419			foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) {
 420				if ( in_array( $box['id'], $initial_meta_boxes ) ) {
 421					unset( $box['id'] );
 422				} else {
 423					$hidden_meta_boxes[] = $box['id'];
 424				}
 425			}
 426		}
 427	}
 428
 429	$user = wp_get_current_user();
 430	update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
 431}
 432
 433/**
 434 * Creates metaboxes for any post type menu item.
 435 *
 436 * @since 3.0.0
 437 */
 438function wp_nav_menu_post_type_meta_boxes() {
 439	$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
 440
 441	if ( ! $post_types )
 442		return;
 443
 444	foreach ( $post_types as $post_type ) {
 445		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
 446		if ( $post_type ) {
 447			$id = $post_type->name;
 448			add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
 449		}
 450	}
 451}
 452
 453/**
 454 * Creates metaboxes for any taxonomy menu item.
 455 *
 456 * @since 3.0.0
 457 */
 458function wp_nav_menu_taxonomy_meta_boxes() {
 459	$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );
 460
 461	if ( !$taxonomies )
 462		return;
 463
 464	foreach ( $taxonomies as $tax ) {
 465		$tax = apply_filters( 'nav_menu_meta_box_object', $tax );
 466		if ( $tax ) {
 467			$id = $tax->name;
 468			add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
 469		}
 470	}
 471}
 472
 473/**
 474 * Displays a metabox for the nav menu theme locations.
 475 *
 476 * @since 3.0.0
 477 */
 478function wp_nav_menu_locations_meta_box() {
 479	global $nav_menu_selected_id;
 480
 481	if ( ! current_theme_supports( 'menus' ) ) {
 482		// We must only support widgets. Leave a message and bail.
 483		echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p>';
 484		return;
 485	}
 486
 487	$locations = get_registered_nav_menus();
 488	$menus = wp_get_nav_menus();
 489	$menu_locations = get_nav_menu_locations();
 490	$num_locations = count( array_keys($locations) );
 491
 492	echo '<p class="howto">' . sprintf( _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n($num_locations) ) . '</p>';
 493
 494	foreach ( $locations as $location => $description ) {
 495		?>
 496		<p>
 497			<label class="howto" for="locations-<?php echo $location; ?>">
 498				<span><?php echo $description; ?></span>
 499				<select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>">
 500					<option value="0"></option>
 501					<?php foreach ( $menus as $menu ) : ?>
 502					<option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
 503						value="<?php echo $menu->term_id; ?>"><?php
 504						$truncated_name = wp_html_excerpt( $menu->name, 40 );
 505						echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '&hellip;';
 506					?></option>
 507					<?php endforeach; ?>
 508				</select>
 509			</label>
 510		</p>
 511	<?php
 512	}
 513	?>
 514	<p class="button-controls">
 515		<?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, disabled( $nav_menu_selected_id, 0, false ) ); ?>
 516		<span class="spinner"></span>
 517	</p>
 518	<?php
 519}
 520
 521/**
 522 * Displays a metabox for the custom links menu item.
 523 *
 524 * @since 3.0.0
 525 */
 526function wp_nav_menu_item_link_meta_box() {
 527	global $_nav_menu_placeholder, $nav_menu_selected_id;
 528	$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
 529
 530	$current_tab = 'create';
 531	if ( isset( $_REQUEST['customlink-tab'] ) && in_array( $_REQUEST['customlink-tab'], array('create', 'all') ) ) {
 532		$current_tab = $_REQUEST['customlink-tab'];
 533	}
 534
 535	$removed_args = array(
 536		'action',
 537		'customlink-tab',
 538		'edit-menu-item',
 539		'menu-item',
 540		'page-tab',
 541		'_wpnonce',
 542	);
 543
 544	?>
 545	<div class="customlinkdiv" id="customlinkdiv">
 546
 547			<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
 548			<p id="menu-item-url-wrap">
 549				<label class="howto" for="custom-menu-item-url">
 550					<span><?php _e('URL'); ?></span>
 551					<input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
 552				</label>
 553			</p>
 554
 555			<p id="menu-item-name-wrap">
 556				<label class="howto" for="custom-menu-item-name">
 557					<span><?php _e('Label'); ?></span>
 558					<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" />
 559				</label>
 560			</p>
 561
 562		<p class="button-controls">
 563			<span class="add-to-menu">
 564				<input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
 565				<span class="spinner"></span>
 566			</span>
 567		</p>
 568
 569	</div><!-- /.customlinkdiv -->
 570	<?php
 571}
 572
 573/**
 574 * Displays a metabox for a post type menu item.
 575 *
 576 * @since 3.0.0
 577 *
 578 * @param string $object Not used.
 579 * @param string $post_type The post type object.
 580 */
 581function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
 582	global $_nav_menu_placeholder, $nav_menu_selected_id;
 583
 584	$post_type_name = $post_type['args']->name;
 585
 586	// paginate browsing for large numbers of post objects
 587	$per_page = 50;
 588	$pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
 589	$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
 590
 591	$args = array(
 592		'offset' => $offset,
 593		'order' => 'ASC',
 594		'orderby' => 'title',
 595		'posts_per_page' => $per_page,
 596		'post_type' => $post_type_name,
 597		'suppress_filters' => true,
 598		'update_post_term_cache' => false,
 599		'update_post_meta_cache' => false
 600	);
 601
 602	if ( isset( $post_type['args']->_default_query ) )
 603		$args = array_merge($args, (array) $post_type['args']->_default_query );
 604
 605	// @todo transient caching of these results with proper invalidation on updating of a post of this type
 606	$get_posts = new WP_Query;
 607	$posts = $get_posts->query( $args );
 608	if ( ! $get_posts->post_count ) {
 609		echo '<p>' . __( 'No items.' ) . '</p>';
 610		return;
 611	}
 612
 613	$post_type_object = get_post_type_object($post_type_name);
 614
 615	$num_pages = $get_posts->max_num_pages;
 616
 617	$page_links = paginate_links( array(
 618		'base' => add_query_arg(
 619			array(
 620				$post_type_name . '-tab' => 'all',
 621				'paged' => '%#%',
 622				'item-type' => 'post_type',
 623				'item-object' => $post_type_name,
 624			)
 625		),
 626		'format' => '',
 627		'prev_text' => __('&laquo;'),
 628		'next_text' => __('&raquo;'),
 629		'total' => $num_pages,
 630		'current' => $pagenum
 631	));
 632
 633	if ( !$posts )
 634		$error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>';
 635
 636	$db_fields = false;
 637	if ( is_post_type_hierarchical( $post_type_name ) ) {
 638		$db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
 639	}
 640
 641	$walker = new Walker_Nav_Menu_Checklist( $db_fields );
 642
 643	$current_tab = 'most-recent';
 644	if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) {
 645		$current_tab = $_REQUEST[$post_type_name . '-tab'];
 646	}
 647
 648	if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
 649		$current_tab = 'search';
 650	}
 651
 652	$removed_args = array(
 653		'action',
 654		'customlink-tab',
 655		'edit-menu-item',
 656		'menu-item',
 657		'page-tab',
 658		'_wpnonce',
 659	);
 660
 661	?>
 662	<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
 663		<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
 664			<li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent"><?php _e('Most Recent'); ?></a></li>
 665			<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li>
 666			<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li>
 667		</ul>
 668
 669		<div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php
 670			echo ( 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 671		?>">
 672			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
 673				<?php
 674				$recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) );
 675				$most_recent = $get_posts->query( $recent_args );
 676				$args['walker'] = $walker;
 677				echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args );
 678				?>
 679			</ul>
 680		</div><!-- /.tabs-panel -->
 681
 682		<div class="tabs-panel <?php
 683			echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 684		?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search">
 685			<?php
 686			if ( isset( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
 687				$searched = esc_attr( $_REQUEST['quick-search-posttype-' . $post_type_name] );
 688				$search_results = get_posts( array( 's' => $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) );
 689			} else {
 690				$searched = '';
 691				$search_results = array();
 692			}
 693			?>
 694			<p class="quick-search-wrap">
 695				<input type="search" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" />
 696				<span class="spinner"></span>
 697				<?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
 698			</p>
 699
 700			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear">
 701			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
 702				<?php
 703				$args['walker'] = $walker;
 704				echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args );
 705				?>
 706			<?php elseif ( is_wp_error( $search_results ) ) : ?>
 707				<li><?php echo $search_results->get_error_message(); ?></li>
 708			<?php elseif ( ! empty( $searched ) ) : ?>
 709				<li><?php _e('No results found.'); ?></li>
 710			<?php endif; ?>
 711			</ul>
 712		</div><!-- /.tabs-panel -->
 713
 714		<div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php
 715			echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 716		?>">
 717			<?php if ( ! empty( $page_links ) ) : ?>
 718				<div class="add-menu-item-pagelinks">
 719					<?php echo $page_links; ?>
 720				</div>
 721			<?php endif; ?>
 722			<ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear">
 723				<?php
 724				$args['walker'] = $walker;
 725
 726				// if we're dealing with pages, let's put a checkbox for the front page at the top of the list
 727				if ( 'page' == $post_type_name ) {
 728					$front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0;
 729					if ( ! empty( $front_page ) ) {
 730						$front_page_obj = get_post( $front_page );
 731						$front_page_obj->front_or_home = true;
 732						array_unshift( $posts, $front_page_obj );
 733					} else {
 734						$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
 735						array_unshift( $posts, (object) array(
 736							'front_or_home' => true,
 737							'ID' => 0,
 738							'object_id' => $_nav_menu_placeholder,
 739							'post_content' => '',
 740							'post_excerpt' => '',
 741							'post_parent' => '',
 742							'post_title' => _x('Home', 'nav menu home label'),
 743							'post_type' => 'nav_menu_item',
 744							'type' => 'custom',
 745							'url' => home_url('/'),
 746						) );
 747					}
 748				}
 749
 750				$posts = apply_filters( 'nav_menu_items_'.$post_type_name, $posts, $args, $post_type );
 751				$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
 752
 753				if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
 754					$checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items);
 755
 756				}
 757
 758				echo $checkbox_items;
 759				?>
 760			</ul>
 761			<?php if ( ! empty( $page_links ) ) : ?>
 762				<div class="add-menu-item-pagelinks">
 763					<?php echo $page_links; ?>
 764				</div>
 765			<?php endif; ?>
 766		</div><!-- /.tabs-panel -->
 767
 768		<p class="button-controls">
 769			<span class="list-controls">
 770				<a href="<?php
 771					echo esc_url(add_query_arg(
 772						array(
 773							$post_type_name . '-tab' => 'all',
 774							'selectall' => 1,
 775						),
 776						remove_query_arg($removed_args)
 777					));
 778				?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
 779			</span>
 780
 781			<span class="add-to-menu">
 782				<input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" id="submit-posttype-<?php echo $post_type_name; ?>" />
 783				<span class="spinner"></span>
 784			</span>
 785		</p>
 786
 787	</div><!-- /.posttypediv -->
 788	<?php
 789}
 790
 791/**
 792 * Displays a metabox for a taxonomy menu item.
 793 *
 794 * @since 3.0.0
 795 *
 796 * @param string $object Not used.
 797 * @param string $taxonomy The taxonomy object.
 798 */
 799function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
 800	global $nav_menu_selected_id;
 801	$taxonomy_name = $taxonomy['args']->name;
 802
 803	// paginate browsing for large numbers of objects
 804	$per_page = 50;
 805	$pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
 806	$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
 807
 808	$args = array(
 809		'child_of' => 0,
 810		'exclude' => '',
 811		'hide_empty' => false,
 812		'hierarchical' => 1,
 813		'include' => '',
 814		'number' => $per_page,
 815		'offset' => $offset,
 816		'order' => 'ASC',
 817		'orderby' => 'name',
 818		'pad_counts' => false,
 819	);
 820
 821	$terms = get_terms( $taxonomy_name, $args );
 822
 823	if ( ! $terms || is_wp_error($terms) ) {
 824		echo '<p>' . __( 'No items.' ) . '</p>';
 825		return;
 826	}
 827
 828	$num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page );
 829
 830	$page_links = paginate_links( array(
 831		'base' => add_query_arg(
 832			array(
 833				$taxonomy_name . '-tab' => 'all',
 834				'paged' => '%#%',
 835				'item-type' => 'taxonomy',
 836				'item-object' => $taxonomy_name,
 837			)
 838		),
 839		'format' => '',
 840		'prev_text' => __('&laquo;'),
 841		'next_text' => __('&raquo;'),
 842		'total' => $num_pages,
 843		'current' => $pagenum
 844	));
 845
 846	$db_fields = false;
 847	if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
 848		$db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
 849	}
 850
 851	$walker = new Walker_Nav_Menu_Checklist( $db_fields );
 852
 853	$current_tab = 'most-used';
 854	if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) {
 855		$current_tab = $_REQUEST[$taxonomy_name . '-tab'];
 856	}
 857
 858	if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) {
 859		$current_tab = 'search';
 860	}
 861
 862	$removed_args = array(
 863		'action',
 864		'customlink-tab',
 865		'edit-menu-item',
 866		'menu-item',
 867		'page-tab',
 868		'_wpnonce',
 869	);
 870
 871	?>
 872	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
 873		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
 874			<li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
 875			<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all"><?php _e('View All'); ?></a></li>
 876			<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"><?php _e('Search'); ?></a></li>
 877		</ul>
 878
 879		<div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php
 880			echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 881		?>">
 882			<ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
 883				<?php
 884				$popular_terms = get_terms( $taxonomy_name, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
 885				$args['walker'] = $walker;
 886				echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args );
 887				?>
 888			</ul>
 889		</div><!-- /.tabs-panel -->
 890
 891		<div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php
 892			echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 893		?>">
 894			<?php if ( ! empty( $page_links ) ) : ?>
 895				<div class="add-menu-item-pagelinks">
 896					<?php echo $page_links; ?>
 897				</div>
 898			<?php endif; ?>
 899			<ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear">
 900				<?php
 901				$args['walker'] = $walker;
 902				echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args );
 903				?>
 904			</ul>
 905			<?php if ( ! empty( $page_links ) ) : ?>
 906				<div class="add-menu-item-pagelinks">
 907					<?php echo $page_links; ?>
 908				</div>
 909			<?php endif; ?>
 910		</div><!-- /.tabs-panel -->
 911
 912		<div class="tabs-panel <?php
 913			echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 914		?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>">
 915			<?php
 916			if ( isset( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) {
 917				$searched = esc_attr( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] );
 918				$search_results = get_terms( $taxonomy_name, array( 'name__like' => $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) );
 919			} else {
 920				$searched = '';
 921				$search_results = array();
 922			}
 923			?>
 924			<p class="quick-search-wrap">
 925				<input type="search" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" />
 926				<span class="spinner"></span>
 927				<?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
 928			</p>
 929
 930			<ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear">
 931			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
 932				<?php
 933				$args['walker'] = $walker;
 934				echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args );
 935				?>
 936			<?php elseif ( is_wp_error( $search_results ) ) : ?>
 937				<li><?php echo $search_results->get_error_message(); ?></li>
 938			<?php elseif ( ! empty( $searched ) ) : ?>
 939				<li><?php _e('No results found.'); ?></li>
 940			<?php endif; ?>
 941			</ul>
 942		</div><!-- /.tabs-panel -->
 943
 944		<p class="button-controls">
 945			<span class="list-controls">
 946				<a href="<?php
 947					echo esc_url(add_query_arg(
 948						array(
 949							$taxonomy_name . '-tab' => 'all',
 950							'selectall' => 1,
 951						),
 952						remove_query_arg($removed_args)
 953					));
 954				?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
 955			</span>
 956
 957			<span class="add-to-menu">
 958				<input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-taxonomy-menu-item" id="submit-taxonomy-<?php echo $taxonomy_name; ?>" />
 959				<span class="spinner"></span>
 960			</span>
 961		</p>
 962
 963	</div><!-- /.taxonomydiv -->
 964	<?php
 965}
 966
 967/**
 968 * Save posted nav menu item data.
 969 *
 970 * @since 3.0.0
 971 *
 972 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
 973 * @param array $menu_data The unsanitized posted menu item data.
 974 * @return array The database IDs of the items saved
 975 */
 976function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
 977	$menu_id = (int) $menu_id;
 978	$items_saved = array();
 979
 980	if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
 981
 982		// Loop through all the menu items' POST values
 983		foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
 984			if (
 985				empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked
 986				(
 987					! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set
 988					in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default
 989					! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page)
 990					! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists
 991				)
 992			) {
 993				continue; // then this potential menu item is not getting added to this menu
 994			}
 995
 996			// if this possible menu item doesn't actually have a menu database ID yet
 997			if (
 998				empty( $_item_object_data['menu-item-db-id'] ) ||
 999				( 0 > $_possible_db_id ) ||
1000				$_possible_db_id != $_item_object_data['menu-item-db-id']
1001			) {
1002				$_actual_db_id = 0;
1003			} else {
1004				$_actual_db_id = (int) $_item_object_data['menu-item-db-id'];
1005			}
1006
1007			$args = array(
1008				'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ),
1009				'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ),
1010				'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ),
1011				'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ),
1012				'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ),
1013				'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ),
1014				'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ),
1015				'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ),
1016				'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ),
1017				'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ),
1018				'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ),
1019				'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ),
1020				'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ),
1021			);
1022
1023			$items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args );
1024
1025		}
1026	}
1027	return $items_saved;
1028}
1029
1030/**
1031 * Adds custom arguments to some of the meta box object types.
1032 *
1033 * @since 3.0.0
1034 *
1035 * @access private
1036 *
1037 * @param object $object The post type or taxonomy meta-object.
1038 * @return object The post type of taxonomy object.
1039 */
1040function _wp_nav_menu_meta_box_object( $object = null ) {
1041	if ( isset( $object->name ) ) {
1042
1043		if ( 'page' == $object->name ) {
1044			$object->_default_query = array(
1045				'orderby' => 'menu_order title',
1046				'post_status' => 'publish',
1047			);
1048
1049		// posts should show only published items
1050		} elseif ( 'post' == $object->name ) {
1051			$object->_default_query = array(
1052				'post_status' => 'publish',
1053			);
1054
1055		// cats should be in reverse chronological order
1056		} elseif ( 'category' == $object->name ) {
1057			$object->_default_query = array(
1058				'orderby' => 'id',
1059				'order' => 'DESC',
1060			);
1061
1062		// custom post types should show only published items
1063		} else {
1064			$object->_default_query = array(
1065				'post_status' => 'publish',
1066			);
1067		}
1068	}
1069
1070	return $object;
1071}
1072
1073/**
1074 * Returns the menu formatted to edit.
1075 *
1076 * @since 3.0.0
1077 *
1078 * @param string $menu_id The ID of the menu to format.
1079 * @return string|WP_Error $output The menu formatted to edit or error object on failure.
1080 */
1081function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
1082	$menu = wp_get_nav_menu_object( $menu_id );
1083
1084	// If the menu exists, get its items.
1085	if ( is_nav_menu( $menu ) ) {
1086		$menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') );
1087		$result = '<div id="menu-instructions" class="post-body-plain';
1088		$result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">';
1089		$result .= '<p>' . __('Select menu items (pages, categories, links) from the boxes at left to begin building your custom menu.') . '</p>';
1090		$result .= '</div>';
1091
1092		if( empty($menu_items) )
1093			return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
1094
1095		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
1096
1097		if ( class_exists( $walker_class_name ) )
1098			$walker = new $walker_class_name;
1099		else
1100			return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) );
1101
1102		$some_pending_menu_items = $some_invalid_menu_items = false;
1103		foreach( (array) $menu_items as $menu_item ) {
1104			if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
1105				$some_pending_menu_items = true;
1106			if ( ! empty( $menu_item->_invalid ) )
1107				$some_invalid_menu_items = true;
1108		}
1109
1110		if ( $some_pending_menu_items )
1111			$result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';
1112
1113		if ( $some_invalid_menu_items )
1114			$result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>';
1115
1116		$result .= '<ul class="menu" id="menu-to-edit"> ';
1117		$result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
1118		$result .= ' </ul> ';
1119		return $result;
1120	} elseif ( is_wp_error( $menu ) ) {
1121		return $menu;
1122	}
1123
1124}
1125
1126/**
1127 * Returns the columns for the nav menus page.
1128 *
1129 * @since 3.0.0
1130 *
1131 * @return string|WP_Error $output The menu formatted to edit or error object on failure.
1132 */
1133function wp_nav_menu_manage_columns() {
1134	return array(
1135		'_title' => __('Show advanced menu properties'),
1136		'cb' => '<input type="checkbox" />',
1137		'link-target' => __('Link Target'),
1138		'css-classes' => __('CSS Classes'),
1139		'xfn' => __('Link Relationship (XFN)'),
1140		'description' => __('Description'),
1141	);
1142}
1143
1144/**
1145 * Deletes orphaned draft menu items
1146 *
1147 * @access private
1148 * @since 3.0.0
1149 *
1150 */
1151function _wp_delete_orphaned_draft_menu_items() {
1152	global $wpdb;
1153	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
1154
1155	// delete orphaned draft menu items
1156	$menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
1157
1158	foreach( (array) $menu_items_to_delete as $menu_item_id )
1159		wp_delete_post( $menu_item_id, true );
1160}
1161
1162add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');