wp/wp-admin/includes/nav-menu.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 
     2 /**
     3 /**
     3  * Core Navigation Menu API
     4  * Create HTML list of nav menu input items.
       
     5  *
     4  *
     6  * @package WordPress
     5  * @package WordPress
     7  * @since 3.0.0
     6  * @subpackage Nav_Menus
     8  * @uses Walker_Nav_Menu
     7  * @since 3.0.0
     9  */
     8  */
    10 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
     9 
    11 	/**
    10 /** Walker_Nav_Menu_Edit class */
    12 	 * Starts the list before the elements are added.
    11 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php' );
    13 	 *
    12 
    14 	 * @see Walker_Nav_Menu::start_lvl()
    13 /** Walker_Nav_Menu_Checklist class */
    15 	 *
    14 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php' );
    16 	 * @since 3.0.0
       
    17 	 *
       
    18 	 * @param string $output Passed by reference.
       
    19 	 * @param int    $depth  Depth of menu item. Used for padding.
       
    20 	 * @param array  $args   Not used.
       
    21 	 */
       
    22 	public function start_lvl( &$output, $depth = 0, $args = array() ) {}
       
    23 
       
    24 	/**
       
    25 	 * Ends the list of after the elements are added.
       
    26 	 *
       
    27 	 * @see Walker_Nav_Menu::end_lvl()
       
    28 	 *
       
    29 	 * @since 3.0.0
       
    30 	 *
       
    31 	 * @param string $output Passed by reference.
       
    32 	 * @param int    $depth  Depth of menu item. Used for padding.
       
    33 	 * @param array  $args   Not used.
       
    34 	 */
       
    35 	public function end_lvl( &$output, $depth = 0, $args = array() ) {}
       
    36 
       
    37 	/**
       
    38 	 * Start the element output.
       
    39 	 *
       
    40 	 * @see Walker_Nav_Menu::start_el()
       
    41 	 * @since 3.0.0
       
    42 	 *
       
    43 	 * @param string $output Passed by reference. Used to append additional content.
       
    44 	 * @param object $item   Menu item data object.
       
    45 	 * @param int    $depth  Depth of menu item. Used for padding.
       
    46 	 * @param array  $args   Not used.
       
    47 	 * @param int    $id     Not used.
       
    48 	 */
       
    49 	public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
       
    50 		global $_wp_nav_menu_max_depth;
       
    51 		$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
       
    52 
       
    53 		ob_start();
       
    54 		$item_id = esc_attr( $item->ID );
       
    55 		$removed_args = array(
       
    56 			'action',
       
    57 			'customlink-tab',
       
    58 			'edit-menu-item',
       
    59 			'menu-item',
       
    60 			'page-tab',
       
    61 			'_wpnonce',
       
    62 		);
       
    63 
       
    64 		$original_title = '';
       
    65 		if ( 'taxonomy' == $item->type ) {
       
    66 			$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
       
    67 			if ( is_wp_error( $original_title ) )
       
    68 				$original_title = false;
       
    69 		} elseif ( 'post_type' == $item->type ) {
       
    70 			$original_object = get_post( $item->object_id );
       
    71 			$original_title = get_the_title( $original_object->ID );
       
    72 		}
       
    73 
       
    74 		$classes = array(
       
    75 			'menu-item menu-item-depth-' . $depth,
       
    76 			'menu-item-' . esc_attr( $item->object ),
       
    77 			'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
       
    78 		);
       
    79 
       
    80 		$title = $item->title;
       
    81 
       
    82 		if ( ! empty( $item->_invalid ) ) {
       
    83 			$classes[] = 'menu-item-invalid';
       
    84 			/* translators: %s: title of menu item which is invalid */
       
    85 			$title = sprintf( __( '%s (Invalid)' ), $item->title );
       
    86 		} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
       
    87 			$classes[] = 'pending';
       
    88 			/* translators: %s: title of menu item in draft status */
       
    89 			$title = sprintf( __('%s (Pending)'), $item->title );
       
    90 		}
       
    91 
       
    92 		$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
       
    93 
       
    94 		$submenu_text = '';
       
    95 		if ( 0 == $depth )
       
    96 			$submenu_text = 'style="display: none;"';
       
    97 
       
    98 		?>
       
    99 		<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
       
   100 			<dl class="menu-item-bar">
       
   101 				<dt class="menu-item-handle">
       
   102 					<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
       
   103 					<span class="item-controls">
       
   104 						<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
       
   105 						<span class="item-order hide-if-js">
       
   106 							<a href="<?php
       
   107 								echo wp_nonce_url(
       
   108 									add_query_arg(
       
   109 										array(
       
   110 											'action' => 'move-up-menu-item',
       
   111 											'menu-item' => $item_id,
       
   112 										),
       
   113 										remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
       
   114 									),
       
   115 									'move-menu_item'
       
   116 								);
       
   117 							?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
       
   118 							|
       
   119 							<a href="<?php
       
   120 								echo wp_nonce_url(
       
   121 									add_query_arg(
       
   122 										array(
       
   123 											'action' => 'move-down-menu-item',
       
   124 											'menu-item' => $item_id,
       
   125 										),
       
   126 										remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
       
   127 									),
       
   128 									'move-menu_item'
       
   129 								);
       
   130 							?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
       
   131 						</span>
       
   132 						<a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
       
   133 							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 ) ) );
       
   134 						?>"><?php _e( 'Edit Menu Item' ); ?></a>
       
   135 					</span>
       
   136 				</dt>
       
   137 			</dl>
       
   138 
       
   139 			<div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
       
   140 				<?php if( 'custom' == $item->type ) : ?>
       
   141 					<p class="field-url description description-wide">
       
   142 						<label for="edit-menu-item-url-<?php echo $item_id; ?>">
       
   143 							<?php _e( 'URL' ); ?><br />
       
   144 							<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 ); ?>" />
       
   145 						</label>
       
   146 					</p>
       
   147 				<?php endif; ?>
       
   148 				<p class="description description-thin">
       
   149 					<label for="edit-menu-item-title-<?php echo $item_id; ?>">
       
   150 						<?php _e( 'Navigation Label' ); ?><br />
       
   151 						<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 ); ?>" />
       
   152 					</label>
       
   153 				</p>
       
   154 				<p class="description description-thin">
       
   155 					<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
       
   156 						<?php _e( 'Title Attribute' ); ?><br />
       
   157 						<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 ); ?>" />
       
   158 					</label>
       
   159 				</p>
       
   160 				<p class="field-link-target description">
       
   161 					<label for="edit-menu-item-target-<?php echo $item_id; ?>">
       
   162 						<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' ); ?> />
       
   163 						<?php _e( 'Open link in a new window/tab' ); ?>
       
   164 					</label>
       
   165 				</p>
       
   166 				<p class="field-css-classes description description-thin">
       
   167 					<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
       
   168 						<?php _e( 'CSS Classes (optional)' ); ?><br />
       
   169 						<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 ) ); ?>" />
       
   170 					</label>
       
   171 				</p>
       
   172 				<p class="field-xfn description description-thin">
       
   173 					<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
       
   174 						<?php _e( 'Link Relationship (XFN)' ); ?><br />
       
   175 						<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 ); ?>" />
       
   176 					</label>
       
   177 				</p>
       
   178 				<p class="field-description description description-wide">
       
   179 					<label for="edit-menu-item-description-<?php echo $item_id; ?>">
       
   180 						<?php _e( 'Description' ); ?><br />
       
   181 						<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>
       
   182 						<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
       
   183 					</label>
       
   184 				</p>
       
   185 
       
   186 				<p class="field-move hide-if-no-js description description-wide">
       
   187 					<label>
       
   188 						<span><?php _e( 'Move' ); ?></span>
       
   189 						<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a>
       
   190 						<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a>
       
   191 						<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
       
   192 						<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
       
   193 						<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a>
       
   194 					</label>
       
   195 				</p>
       
   196 
       
   197 				<div class="menu-item-actions description-wide submitbox">
       
   198 					<?php if( 'custom' != $item->type && $original_title !== false ) : ?>
       
   199 						<p class="link-to-original">
       
   200 							<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
       
   201 						</p>
       
   202 					<?php endif; ?>
       
   203 					<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
       
   204 					echo wp_nonce_url(
       
   205 						add_query_arg(
       
   206 							array(
       
   207 								'action' => 'delete-menu-item',
       
   208 								'menu-item' => $item_id,
       
   209 							),
       
   210 							admin_url( 'nav-menus.php' )
       
   211 						),
       
   212 						'delete-menu_item_' . $item_id
       
   213 					); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
       
   214 						?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
       
   215 				</div>
       
   216 
       
   217 				<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
       
   218 				<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 ); ?>" />
       
   219 				<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
       
   220 				<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 ); ?>" />
       
   221 				<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
       
   222 				<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
       
   223 			</div><!-- .menu-item-settings-->
       
   224 			<ul class="menu-item-transport"></ul>
       
   225 		<?php
       
   226 		$output .= ob_get_clean();
       
   227 	}
       
   228 
       
   229 } // Walker_Nav_Menu_Edit
       
   230 
       
   231 /**
       
   232  * Create HTML list of nav menu input items.
       
   233  *
       
   234  * @since 3.0.0
       
   235  * @uses Walker_Nav_Menu
       
   236  */
       
   237 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
       
   238 	public function __construct( $fields = false ) {
       
   239 		if ( $fields ) {
       
   240 			$this->db_fields = $fields;
       
   241 		}
       
   242 	}
       
   243 
       
   244 	/**
       
   245 	 * Starts the list before the elements are added.
       
   246 	 *
       
   247 	 * @see Walker_Nav_Menu::start_lvl()
       
   248 	 *
       
   249 	 * @since 3.0.0
       
   250 	 *
       
   251 	 * @param string $output Passed by reference. Used to append additional content.
       
   252 	 * @param int    $depth  Depth of page. Used for padding.
       
   253 	 * @param array  $args   Not used.
       
   254 	 */
       
   255 	public function start_lvl( &$output, $depth = 0, $args = array() ) {
       
   256 		$indent = str_repeat( "\t", $depth );
       
   257 		$output .= "\n$indent<ul class='children'>\n";
       
   258 	}
       
   259 
       
   260 	/**
       
   261 	 * Ends the list of after the elements are added.
       
   262 	 *
       
   263 	 * @see Walker_Nav_Menu::end_lvl()
       
   264 	 *
       
   265 	 * @since 3.0.0
       
   266 	 *
       
   267 	 * @param string $output Passed by reference. Used to append additional content.
       
   268 	 * @param int    $depth  Depth of page. Used for padding.
       
   269 	 * @param array  $args   Not used.
       
   270 	 */
       
   271 	public function end_lvl( &$output, $depth = 0, $args = array() ) {
       
   272 		$indent = str_repeat( "\t", $depth );
       
   273 		$output .= "\n$indent</ul>";
       
   274 	}
       
   275 
       
   276 	/**
       
   277 	 * Start the element output.
       
   278 	 *
       
   279 	 * @see Walker_Nav_Menu::start_el()
       
   280 	 *
       
   281 	 * @since 3.0.0
       
   282 	 *
       
   283 	 * @param string $output Passed by reference. Used to append additional content.
       
   284 	 * @param object $item   Menu item data object.
       
   285 	 * @param int    $depth  Depth of menu item. Used for padding.
       
   286 	 * @param array  $args   Not used.
       
   287 	 * @param int    $id     Not used.
       
   288 	 */
       
   289 	public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
       
   290 		global $_nav_menu_placeholder;
       
   291 
       
   292 		$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
       
   293 		$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
       
   294 		$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
       
   295 
       
   296 		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
       
   297 
       
   298 		$output .= $indent . '<li>';
       
   299 		$output .= '<label class="menu-item-title">';
       
   300 		$output .= '<input type="checkbox" class="menu-item-checkbox';
       
   301 
       
   302 		if ( ! empty( $item->front_or_home ) )
       
   303 			$output .= ' add-to-top';
       
   304 
       
   305 		$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
       
   306 
       
   307 		if ( ! empty( $item->label ) ) {
       
   308 			$title = $item->label;
       
   309 		} elseif ( isset( $item->post_type ) ) {
       
   310 			/** This filter is documented in wp-includes/post-template.php */
       
   311 			$title = apply_filters( 'the_title', $item->post_title, $item->ID );
       
   312 			if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title )
       
   313 				$title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title );
       
   314 		}
       
   315 
       
   316 		$output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
       
   317  		$output .= '</label>';
       
   318 
       
   319 		// Menu item hidden fields
       
   320 		$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
       
   321 		$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
       
   322 		$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 ) .'" />';
       
   323 		$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />';
       
   324 		$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
       
   325 		$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
       
   326 		$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
       
   327 		$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 ) .'" />';
       
   328 		$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
       
   329 		$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
       
   330 	}
       
   331 
       
   332 } // Walker_Nav_Menu_Checklist
       
   333 
    15 
   334 /**
    16 /**
   335  * Prints the appropriate response to a menu quick search.
    17  * Prints the appropriate response to a menu quick search.
   336  *
    18  *
   337  * @since 3.0.0
    19  * @since 3.0.0
   386 
    68 
   387 		}
    69 		}
   388 
    70 
   389 	} elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
    71 	} elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
   390 		if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
    72 		if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
   391 			query_posts(array(
    73 			$post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) );
   392 				'posts_per_page' => 10,
    74 			$args = array_merge(
   393 				'post_type' => $matches[2],
    75 				$args,
   394 				's' => $query,
    76 				array(
   395 			));
    77 					'no_found_rows'          => true,
   396 			if ( ! have_posts() )
    78 					'update_post_meta_cache' => false,
       
    79 					'update_post_term_cache' => false,
       
    80 					'posts_per_page'         => 10,
       
    81 					'post_type'              => $matches[2],
       
    82 					's'                      => $query,
       
    83 				)
       
    84 			);
       
    85 			if ( isset( $post_type_obj->_default_query ) ) {
       
    86 				$args = array_merge( $args, (array) $post_type_obj->_default_query );
       
    87 			}
       
    88 			$search_results_query = new WP_Query( $args );
       
    89 			if ( ! $search_results_query->have_posts() ) {
   397 				return;
    90 				return;
   398 			while ( have_posts() ) {
    91 			}
   399 				the_post();
    92 			while ( $search_results_query->have_posts() ) {
       
    93 				$post = $search_results_query->next_post();
   400 				if ( 'markup' == $response_format ) {
    94 				if ( 'markup' == $response_format ) {
   401 					$var_by_ref = get_the_ID();
    95 					$var_by_ref = $post->ID;
   402 					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
    96 					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
   403 				} elseif ( 'json' == $response_format ) {
    97 				} elseif ( 'json' == $response_format ) {
   404 					echo wp_json_encode(
    98 					echo wp_json_encode(
   405 						array(
    99 						array(
   406 							'ID' => get_the_ID(),
   100 							'ID' => $post->ID,
   407 							'post_title' => get_the_title(),
   101 							'post_title' => get_the_title( $post->ID ),
   408 							'post_type' => get_post_type(),
   102 							'post_type' => $matches[2],
   409 						)
   103 						)
   410 					);
   104 					);
   411 					echo "\n";
   105 					echo "\n";
   412 				}
   106 				}
   413 			}
   107 			}
   416 				'name__like' => $query,
   110 				'name__like' => $query,
   417 				'number' => 10,
   111 				'number' => 10,
   418 			));
   112 			));
   419 			if ( empty( $terms ) || is_wp_error( $terms ) )
   113 			if ( empty( $terms ) || is_wp_error( $terms ) )
   420 				return;
   114 				return;
   421 			foreach( (array) $terms as $term ) {
   115 			foreach ( (array) $terms as $term ) {
   422 				if ( 'markup' == $response_format ) {
   116 				if ( 'markup' == $response_format ) {
   423 					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
   117 					echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
   424 				} elseif ( 'json' == $response_format ) {
   118 				} elseif ( 'json' == $response_format ) {
   425 					echo wp_json_encode(
   119 					echo wp_json_encode(
   426 						array(
   120 						array(
   435 		}
   129 		}
   436 	}
   130 	}
   437 }
   131 }
   438 
   132 
   439 /**
   133 /**
   440  * Register nav menu metaboxes and advanced menu items
   134  * Register nav menu meta boxes and advanced menu items.
   441  *
   135  *
   442  * @since 3.0.0
   136  * @since 3.0.0
   443  **/
   137  **/
   444 function wp_nav_menu_setup() {
   138 function wp_nav_menu_setup() {
   445 	// Register meta boxes
   139 	// Register meta boxes
   449 
   143 
   450 	// Register advanced menu items (columns)
   144 	// Register advanced menu items (columns)
   451 	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
   145 	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
   452 
   146 
   453 	// If first time editing, disable advanced items by default.
   147 	// If first time editing, disable advanced items by default.
   454 	if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
   148 	if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
   455 		$user = wp_get_current_user();
   149 		$user = wp_get_current_user();
   456 		update_user_option($user->ID, 'managenav-menuscolumnshidden',
   150 		update_user_option($user->ID, 'managenav-menuscolumnshidden',
   457 			array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', ),
   151 			array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', 4 => 'title-attribute', ),
   458 			true);
   152 			true);
   459 	}
   153 	}
   460 }
   154 }
   461 
   155 
   462 /**
   156 /**
   463  * Limit the amount of meta boxes to just links, pages and cats for first time users.
   157  * Limit the amount of meta boxes to pages, posts, links, and categories for first time users.
   464  *
   158  *
   465  * @since 3.0.0
   159  * @since 3.0.0
       
   160  *
       
   161  * @global array $wp_meta_boxes
   466  **/
   162  **/
   467 function wp_initial_nav_menu_meta_boxes() {
   163 function wp_initial_nav_menu_meta_boxes() {
   468 	global $wp_meta_boxes;
   164 	global $wp_meta_boxes;
   469 
   165 
   470 	if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) )
   166 	if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) )
   471 		return;
   167 		return;
   472 
   168 
   473 	$initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category' );
   169 	$initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category' );
   474 	$hidden_meta_boxes = array();
   170 	$hidden_meta_boxes = array();
   475 
   171 
   476 	foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {
   172 	foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {
   477 		foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) {
   173 		foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) {
   478 			foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) {
   174 			foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) {
   488 	$user = wp_get_current_user();
   184 	$user = wp_get_current_user();
   489 	update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
   185 	update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
   490 }
   186 }
   491 
   187 
   492 /**
   188 /**
   493  * Creates metaboxes for any post type menu item.
   189  * Creates meta boxes for any post type menu item..
   494  *
   190  *
   495  * @since 3.0.0
   191  * @since 3.0.0
   496  */
   192  */
   497 function wp_nav_menu_post_type_meta_boxes() {
   193 function wp_nav_menu_post_type_meta_boxes() {
   498 	$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
   194 	$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
   500 	if ( ! $post_types )
   196 	if ( ! $post_types )
   501 		return;
   197 		return;
   502 
   198 
   503 	foreach ( $post_types as $post_type ) {
   199 	foreach ( $post_types as $post_type ) {
   504 		/**
   200 		/**
   505 		 * Filter whether a menu items meta box will be added for the current
   201 		 * Filters whether a menu items meta box will be added for the current
   506 		 * object type.
   202 		 * object type.
   507 		 *
   203 		 *
   508 		 * If a falsey value is returned instead of an object, the menu items
   204 		 * If a falsey value is returned instead of an object, the menu items
   509 		 * meta box for the current meta box object will not be added.
   205 		 * meta box for the current meta box object will not be added.
   510 		 *
   206 		 *
   516 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
   212 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
   517 		if ( $post_type ) {
   213 		if ( $post_type ) {
   518 			$id = $post_type->name;
   214 			$id = $post_type->name;
   519 			// Give pages a higher priority.
   215 			// Give pages a higher priority.
   520 			$priority = ( 'page' == $post_type->name ? 'core' : 'default' );
   216 			$priority = ( 'page' == $post_type->name ? 'core' : 'default' );
   521 			add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type );
   217 			add_meta_box( "add-post-type-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type );
   522 		}
   218 		}
   523 	}
   219 	}
   524 }
   220 }
   525 
   221 
   526 /**
   222 /**
   527  * Creates metaboxes for any taxonomy menu item.
   223  * Creates meta boxes for any taxonomy menu item.
   528  *
   224  *
   529  * @since 3.0.0
   225  * @since 3.0.0
   530  */
   226  */
   531 function wp_nav_menu_taxonomy_meta_boxes() {
   227 function wp_nav_menu_taxonomy_meta_boxes() {
   532 	$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );
   228 	$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );
   547 /**
   243 /**
   548  * Check whether to disable the Menu Locations meta box submit button
   244  * Check whether to disable the Menu Locations meta box submit button
   549  *
   245  *
   550  * @since 3.6.0
   246  * @since 3.6.0
   551  *
   247  *
   552  * @uses global $one_theme_location_no_menus to determine if no menus exist
   248  * @global bool $one_theme_location_no_menus to determine if no menus exist
   553  *
   249  *
   554  * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu
   250  * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu
   555  * @return string Disabled attribute if at least one menu exists, false if not
   251  * @return string Disabled attribute if at least one menu exists, false if not
   556 */
   252  */
   557 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) {
   253 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) {
   558 	global $one_theme_location_no_menus;
   254 	global $one_theme_location_no_menus;
   559 
   255 
   560 	if ( $one_theme_location_no_menus )
   256 	if ( $one_theme_location_no_menus )
   561 		return false;
   257 		return false;
   562 
   258 
   563 	return disabled( $nav_menu_selected_id, 0 );
   259 	return disabled( $nav_menu_selected_id, 0 );
   564 }
   260 }
   565 
   261 
   566 /**
   262 /**
   567  * Displays a metabox for the custom links menu item.
   263  * Displays a meta box for the custom links menu item.
   568  *
   264  *
   569  * @since 3.0.0
   265  * @since 3.0.0
       
   266  *
       
   267  * @global int        $_nav_menu_placeholder
       
   268  * @global int|string $nav_menu_selected_id
   570  */
   269  */
   571 function wp_nav_menu_item_link_meta_box() {
   270 function wp_nav_menu_item_link_meta_box() {
   572 	global $_nav_menu_placeholder, $nav_menu_selected_id;
   271 	global $_nav_menu_placeholder, $nav_menu_selected_id;
   573 
   272 
   574 	$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
   273 	$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
   575 
   274 
   576 	?>
   275 	?>
   577 	<div class="customlinkdiv" id="customlinkdiv">
   276 	<div class="customlinkdiv" id="customlinkdiv">
   578 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
   277 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
   579 		<p id="menu-item-url-wrap">
   278 		<p id="menu-item-url-wrap" class="wp-clearfix">
   580 			<label class="howto" for="custom-menu-item-url">
   279 			<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
   581 				<span><?php _e('URL'); ?></span>
   280 			<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://" />
   582 				<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://" />
       
   583 			</label>
       
   584 		</p>
   281 		</p>
   585 
   282 
   586 		<p id="menu-item-name-wrap">
   283 		<p id="menu-item-name-wrap" class="wp-clearfix">
   587 			<label class="howto" for="custom-menu-item-name">
   284 			<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
   588 				<span><?php _e( 'Link Text' ); ?></span>
   285 			<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" />
   589 				<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'); ?>" />
       
   590 			</label>
       
   591 		</p>
   286 		</p>
   592 
   287 
   593 		<p class="button-controls">
   288 		<p class="button-controls wp-clearfix">
   594 			<span class="add-to-menu">
   289 			<span class="add-to-menu">
   595 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
   290 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
   596 				<span class="spinner"></span>
   291 				<span class="spinner"></span>
   597 			</span>
   292 			</span>
   598 		</p>
   293 		</p>
   599 
   294 
   600 	</div><!-- /.customlinkdiv -->
   295 	</div><!-- /.customlinkdiv -->
   601 	<?php
   296 	<?php
   602 }
   297 }
   603 
   298 
   604 /**
   299 /**
   605  * Displays a metabox for a post type menu item.
   300  * Displays a meta box for a post type menu item.
   606  *
   301  *
   607  * @since 3.0.0
   302  * @since 3.0.0
       
   303  *
       
   304  * @global int        $_nav_menu_placeholder
       
   305  * @global int|string $nav_menu_selected_id
   608  *
   306  *
   609  * @param string $object Not used.
   307  * @param string $object Not used.
   610  * @param string $post_type The post type object.
   308  * @param array  $box {
   611  */
   309  *     Post type menu item meta box arguments.
   612 function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
   310  *
       
   311  *     @type string       $id       Meta box 'id' attribute.
       
   312  *     @type string       $title    Meta box title.
       
   313  *     @type string       $callback Meta box display callback.
       
   314  *     @type WP_Post_Type $args     Extra meta box arguments (the post type object for this meta box).
       
   315  * }
       
   316  */
       
   317 function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
   613 	global $_nav_menu_placeholder, $nav_menu_selected_id;
   318 	global $_nav_menu_placeholder, $nav_menu_selected_id;
   614 
   319 
   615 	$post_type_name = $post_type['args']->name;
   320 	$post_type_name = $box['args']->name;
   616 
   321 
   617 	// Paginate browsing for large numbers of post objects.
   322 	// Paginate browsing for large numbers of post objects.
   618 	$per_page = 50;
   323 	$per_page = 50;
   619 	$pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   324 	$pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   620 	$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   325 	$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   628 		'suppress_filters' => true,
   333 		'suppress_filters' => true,
   629 		'update_post_term_cache' => false,
   334 		'update_post_term_cache' => false,
   630 		'update_post_meta_cache' => false
   335 		'update_post_meta_cache' => false
   631 	);
   336 	);
   632 
   337 
   633 	if ( isset( $post_type['args']->_default_query ) )
   338 	if ( isset( $box['args']->_default_query ) )
   634 		$args = array_merge($args, (array) $post_type['args']->_default_query );
   339 		$args = array_merge($args, (array) $box['args']->_default_query );
   635 
   340 
   636 	// @todo transient caching of these results with proper invalidation on updating of a post of this type
   341 	// @todo transient caching of these results with proper invalidation on updating of a post of this type
   637 	$get_posts = new WP_Query;
   342 	$get_posts = new WP_Query;
   638 	$posts = $get_posts->query( $args );
   343 	$posts = $get_posts->query( $args );
   639 	if ( ! $get_posts->post_count ) {
   344 	if ( ! $get_posts->post_count ) {
   651 				'item-type' => 'post_type',
   356 				'item-type' => 'post_type',
   652 				'item-object' => $post_type_name,
   357 				'item-object' => $post_type_name,
   653 			)
   358 			)
   654 		),
   359 		),
   655 		'format' => '',
   360 		'format' => '',
   656 		'prev_text' => __('&laquo;'),
   361 		'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   657 		'next_text' => __('&raquo;'),
   362 		'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   658 		'total' => $num_pages,
   363 		'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
       
   364 		'total'   => $num_pages,
   659 		'current' => $pagenum
   365 		'current' => $pagenum
   660 	));
   366 	));
   661 
   367 
   662 	$db_fields = false;
   368 	$db_fields = false;
   663 	if ( is_post_type_hierarchical( $post_type_name ) ) {
   369 	if ( is_post_type_hierarchical( $post_type_name ) ) {
   710 			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
   416 			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
   711 				<?php
   417 				<?php
   712 				$recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) );
   418 				$recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) );
   713 				$most_recent = $get_posts->query( $recent_args );
   419 				$most_recent = $get_posts->query( $recent_args );
   714 				$args['walker'] = $walker;
   420 				$args['walker'] = $walker;
   715 				echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args );
   421 
       
   422 				/**
       
   423 				 * Filters the posts displayed in the 'Most Recent' tab of the current
       
   424 				 * post type's menu items meta box.
       
   425 				 *
       
   426 				 * The dynamic portion of the hook name, `$post_type_name`, refers to the post type name.
       
   427 				 *
       
   428 				 * @since 4.3.0
       
   429 				 * @since 4.9.0 Added the `$recent_args` parameter.
       
   430 				 *
       
   431 				 * @param array $most_recent An array of post objects being listed.
       
   432 				 * @param array $args        An array of WP_Query arguments for the meta box.
       
   433 				 * @param array $box         Arguments passed to wp_nav_menu_item_post_type_meta_box().
       
   434 				 * @param array $recent_args An array of WP_Query arguments for 'Most Recent' tab.
       
   435 				 */
       
   436 				$most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box, $recent_args );
       
   437 
       
   438 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args );
   716 				?>
   439 				?>
   717 			</ul>
   440 			</ul>
   718 		</div><!-- /.tabs-panel -->
   441 		</div><!-- /.tabs-panel -->
   719 
   442 
   720 		<div class="tabs-panel <?php
   443 		<div class="tabs-panel <?php
   728 				$searched = '';
   451 				$searched = '';
   729 				$search_results = array();
   452 				$search_results = array();
   730 			}
   453 			}
   731 			?>
   454 			?>
   732 			<p class="quick-search-wrap">
   455 			<p class="quick-search-wrap">
   733 				<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; ?>" />
   456 				<label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
       
   457 				<input type="search" class="quick-search" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" id="quick-search-posttype-<?php echo $post_type_name; ?>" />
   734 				<span class="spinner"></span>
   458 				<span class="spinner"></span>
   735 				<?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 ) ); ?>
   459 				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
   736 			</p>
   460 			</p>
   737 
   461 
   738 			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear">
   462 			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear">
   739 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
   463 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
   740 				<?php
   464 				<?php
   786 							'url' => home_url('/'),
   510 							'url' => home_url('/'),
   787 						) );
   511 						) );
   788 					}
   512 					}
   789 				}
   513 				}
   790 
   514 
       
   515 				$post_type = get_post_type_object( $post_type_name );
       
   516 
       
   517 				if ( $post_type->has_archive ) {
       
   518 					$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
       
   519 					array_unshift( $posts, (object) array(
       
   520 						'ID' => 0,
       
   521 						'object_id' => $_nav_menu_placeholder,
       
   522 						'object'     => $post_type_name,
       
   523 						'post_content' => '',
       
   524 						'post_excerpt' => '',
       
   525 						'post_title' => $post_type->labels->archives,
       
   526 						'post_type' => 'nav_menu_item',
       
   527 						'type' => 'post_type_archive',
       
   528 						'url' => get_post_type_archive_link( $post_type_name ),
       
   529 					) );
       
   530 				}
       
   531 
   791 				/**
   532 				/**
   792 				 * Filter the posts displayed in the 'View All' tab of the current
   533 				 * Filters the posts displayed in the 'View All' tab of the current
   793 				 * post type's menu items meta box.
   534 				 * post type's menu items meta box.
   794 				 *
   535 				 *
   795 				 * The dynamic portion of the hook name, `$post_type_name`, refers
   536 				 * The dynamic portion of the hook name, `$post_type_name`, refers
   796 				 * to the slug of the current post type.
   537 				 * to the slug of the current post type.
   797 				 *
   538 				 *
   798 				 * @since 3.2.0
   539 				 * @since 3.2.0
       
   540 				 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
   799 				 *
   541 				 *
   800 				 * @see WP_Query::query()
   542 				 * @see WP_Query::query()
   801 				 *
   543 				 *
   802 				 * @param array  $posts     The posts for the current post type.
   544 				 * @param array        $posts     The posts for the current post type.
   803 				 * @param array  $args      An array of WP_Query arguments.
   545 				 * @param array        $args      An array of WP_Query arguments.
   804 				 * @param object $post_type The current post type object for this menu item meta box.
   546 				 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
   805 				 */
   547 				 */
   806 				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
   548 				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
       
   549 
   807 				$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
   550 				$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
   808 
   551 
   809 				if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
   552 				if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
   810 					$checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items);
   553 					$checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items);
   811 
   554 
   819 					<?php echo $page_links; ?>
   562 					<?php echo $page_links; ?>
   820 				</div>
   563 				</div>
   821 			<?php endif; ?>
   564 			<?php endif; ?>
   822 		</div><!-- /.tabs-panel -->
   565 		</div><!-- /.tabs-panel -->
   823 
   566 
   824 		<p class="button-controls">
   567 		<p class="button-controls wp-clearfix">
   825 			<span class="list-controls">
   568 			<span class="list-controls">
   826 				<a href="<?php
   569 				<a href="<?php
   827 					echo esc_url( add_query_arg(
   570 					echo esc_url( add_query_arg(
   828 						array(
   571 						array(
   829 							$post_type_name . '-tab' => 'all',
   572 							$post_type_name . '-tab' => 'all',
   830 							'selectall' => 1,
   573 							'selectall' => 1,
   831 						),
   574 						),
   832 						remove_query_arg( $removed_args )
   575 						remove_query_arg( $removed_args )
   833 					));
   576 					));
   834 				?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
   577 				?>#posttype-<?php echo $post_type_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a>
   835 			</span>
   578 			</span>
   836 
   579 
   837 			<span class="add-to-menu">
   580 			<span class="add-to-menu">
   838 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="<?php echo esc_attr( 'submit-posttype-' . $post_type_name ); ?>" />
   581 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="<?php echo esc_attr( 'submit-posttype-' . $post_type_name ); ?>" />
   839 				<span class="spinner"></span>
   582 				<span class="spinner"></span>
   840 			</span>
   583 			</span>
   841 		</p>
   584 		</p>
   842 
   585 
   843 	</div><!-- /.posttypediv -->
   586 	</div><!-- /.posttypediv -->
   844 	<?php
   587 	<?php
   845 }
   588 }
   846 
   589 
   847 /**
   590 /**
   848  * Displays a metabox for a taxonomy menu item.
   591  * Displays a meta box for a taxonomy menu item.
   849  *
   592  *
   850  * @since 3.0.0
   593  * @since 3.0.0
       
   594  *
       
   595  * @global int|string $nav_menu_selected_id
   851  *
   596  *
   852  * @param string $object Not used.
   597  * @param string $object Not used.
   853  * @param string $taxonomy The taxonomy object.
   598  * @param array  $box {
   854  */
   599  *     Taxonomy menu item meta box arguments.
   855 function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
   600  *
       
   601  *     @type string $id       Meta box 'id' attribute.
       
   602  *     @type string $title    Meta box title.
       
   603  *     @type string $callback Meta box display callback.
       
   604  *     @type object $args     Extra meta box arguments (the taxonomy object for this meta box).
       
   605  * }
       
   606  */
       
   607 function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
   856 	global $nav_menu_selected_id;
   608 	global $nav_menu_selected_id;
   857 	$taxonomy_name = $taxonomy['args']->name;
   609 	$taxonomy_name = $box['args']->name;
       
   610 	$taxonomy = get_taxonomy( $taxonomy_name );
   858 
   611 
   859 	// Paginate browsing for large numbers of objects.
   612 	// Paginate browsing for large numbers of objects.
   860 	$per_page = 50;
   613 	$per_page = 50;
   861 	$pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   614 	$pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   862 	$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   615 	$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   891 				'item-type' => 'taxonomy',
   644 				'item-type' => 'taxonomy',
   892 				'item-object' => $taxonomy_name,
   645 				'item-object' => $taxonomy_name,
   893 			)
   646 			)
   894 		),
   647 		),
   895 		'format' => '',
   648 		'format' => '',
   896 		'prev_text' => __('&laquo;'),
   649 		'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   897 		'next_text' => __('&raquo;'),
   650 		'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   898 		'total' => $num_pages,
   651 		'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
       
   652 		'total'   => $num_pages,
   899 		'current' => $pagenum
   653 		'current' => $pagenum
   900 	));
   654 	));
   901 
   655 
   902 	$db_fields = false;
   656 	$db_fields = false;
   903 	if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
   657 	if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
   927 	?>
   681 	?>
   928 	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
   682 	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
   929 		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
   683 		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
   930 			<li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>>
   684 			<li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>>
   931 				<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-pop" 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">
   685 				<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-pop" 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">
   932 					<?php _e( 'Most Used' ); ?>
   686 					<?php echo esc_html( $taxonomy->labels->most_used ); ?>
   933 				</a>
   687 				</a>
   934 			</li>
   688 			</li>
   935 			<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
   689 			<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
   936 				<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-all" 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">
   690 				<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-all" 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">
   937 					<?php _e( 'View All' ); ?>
   691 					<?php _e( 'View All' ); ?>
   988 				$searched = '';
   742 				$searched = '';
   989 				$search_results = array();
   743 				$search_results = array();
   990 			}
   744 			}
   991 			?>
   745 			?>
   992 			<p class="quick-search-wrap">
   746 			<p class="quick-search-wrap">
   993 				<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; ?>" />
   747 				<label for="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
       
   748 				<input type="search" class="quick-search" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" id="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" />
   994 				<span class="spinner"></span>
   749 				<span class="spinner"></span>
   995 				<?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
   750 				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
   996 			</p>
   751 			</p>
   997 
   752 
   998 			<ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear">
   753 			<ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear">
   999 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
   754 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
  1000 				<?php
   755 				<?php
  1007 				<li><?php _e('No results found.'); ?></li>
   762 				<li><?php _e('No results found.'); ?></li>
  1008 			<?php endif; ?>
   763 			<?php endif; ?>
  1009 			</ul>
   764 			</ul>
  1010 		</div><!-- /.tabs-panel -->
   765 		</div><!-- /.tabs-panel -->
  1011 
   766 
  1012 		<p class="button-controls">
   767 		<p class="button-controls wp-clearfix">
  1013 			<span class="list-controls">
   768 			<span class="list-controls">
  1014 				<a href="<?php
   769 				<a href="<?php
  1015 					echo esc_url(add_query_arg(
   770 					echo esc_url(add_query_arg(
  1016 						array(
   771 						array(
  1017 							$taxonomy_name . '-tab' => 'all',
   772 							$taxonomy_name . '-tab' => 'all',
  1018 							'selectall' => 1,
   773 							'selectall' => 1,
  1019 						),
   774 						),
  1020 						remove_query_arg($removed_args)
   775 						remove_query_arg($removed_args)
  1021 					));
   776 					));
  1022 				?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
   777 				?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a>
  1023 			</span>
   778 			</span>
  1024 
   779 
  1025 			<span class="add-to-menu">
   780 			<span class="add-to-menu">
  1026 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-taxonomy-menu-item" id="<?php echo esc_attr( 'submit-taxonomy-' . $taxonomy_name ); ?>" />
   781 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-taxonomy-menu-item" id="<?php echo esc_attr( 'submit-taxonomy-' . $taxonomy_name ); ?>" />
  1027 				<span class="spinner"></span>
   782 				<span class="spinner"></span>
  1028 			</span>
   783 			</span>
  1029 		</p>
   784 		</p>
  1030 
   785 
  1031 	</div><!-- /.taxonomydiv -->
   786 	</div><!-- /.taxonomydiv -->
  1046 	$items_saved = array();
   801 	$items_saved = array();
  1047 
   802 
  1048 	if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
   803 	if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
  1049 
   804 
  1050 		// Loop through all the menu items' POST values.
   805 		// Loop through all the menu items' POST values.
  1051 		foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
   806 		foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
  1052 			if (
   807 			if (
  1053 				// Checkbox is not checked.
   808 				// Checkbox is not checked.
  1054 				empty( $_item_object_data['menu-item-object-id'] ) &&
   809 				empty( $_item_object_data['menu-item-object-id'] ) &&
  1055 				(
   810 				(
  1056 					// And item type either isn't set.
   811 					// And item type either isn't set.
  1160 		$result = '<div id="menu-instructions" class="post-body-plain';
   915 		$result = '<div id="menu-instructions" class="post-body-plain';
  1161 		$result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">';
   916 		$result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">';
  1162 		$result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>';
   917 		$result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>';
  1163 		$result .= '</div>';
   918 		$result .= '</div>';
  1164 
   919 
  1165 		if( empty($menu_items) )
   920 		if ( empty($menu_items) )
  1166 			return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
   921 			return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
  1167 
   922 
  1168 		/**
   923 		/**
  1169 		 * Filter the Walker class used when adding nav menu items.
   924 		 * Filters the Walker class used when adding nav menu items.
  1170 		 *
   925 		 *
  1171 		 * @since 3.0.0
   926 		 * @since 3.0.0
  1172 		 *
   927 		 *
  1173 		 * @param string $class   The walker class to use. Default 'Walker_Nav_Menu_Edit'.
   928 		 * @param string $class   The walker class to use. Default 'Walker_Nav_Menu_Edit'.
  1174 		 * @param int    $menu_id ID of the menu being rendered.
   929 		 * @param int    $menu_id ID of the menu being rendered.
  1175 		 */
   930 		 */
  1176 		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
   931 		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
  1177 
   932 
  1178 		if ( class_exists( $walker_class_name ) )
   933 		if ( class_exists( $walker_class_name ) ) {
  1179 			$walker = new $walker_class_name;
   934 			$walker = new $walker_class_name;
  1180 		else
   935 		} else {
  1181 			return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) );
   936 			return new WP_Error( 'menu_walker_not_exist',
       
   937 				/* translators: %s: walker class name */
       
   938 				sprintf( __( 'The Walker class named %s does not exist.' ),
       
   939 					'<strong>' . $walker_class_name . '</strong>'
       
   940 				)
       
   941 			);
       
   942 		}
  1182 
   943 
  1183 		$some_pending_menu_items = $some_invalid_menu_items = false;
   944 		$some_pending_menu_items = $some_invalid_menu_items = false;
  1184 		foreach( (array) $menu_items as $menu_item ) {
   945 		foreach ( (array) $menu_items as $menu_item ) {
  1185 			if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
   946 			if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
  1186 				$some_pending_menu_items = true;
   947 				$some_pending_menu_items = true;
  1187 			if ( ! empty( $menu_item->_invalid ) )
   948 			if ( ! empty( $menu_item->_invalid ) )
  1188 				$some_invalid_menu_items = true;
   949 				$some_invalid_menu_items = true;
  1189 		}
   950 		}
  1190 
   951 
  1191 		if ( $some_pending_menu_items )
   952 		if ( $some_pending_menu_items ) {
  1192 			$result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';
   953 			$result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>';
  1193 
   954 		}
  1194 		if ( $some_invalid_menu_items )
   955 
  1195 			$result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>';
   956 		if ( $some_invalid_menu_items ) {
       
   957 			$result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>';
       
   958 		}
  1196 
   959 
  1197 		$result .= '<ul class="menu" id="menu-to-edit"> ';
   960 		$result .= '<ul class="menu" id="menu-to-edit"> ';
  1198 		$result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
   961 		$result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
  1199 		$result .= ' </ul> ';
   962 		$result .= ' </ul> ';
  1200 		return $result;
   963 		return $result;
  1207 /**
   970 /**
  1208  * Returns the columns for the nav menus page.
   971  * Returns the columns for the nav menus page.
  1209  *
   972  *
  1210  * @since 3.0.0
   973  * @since 3.0.0
  1211  *
   974  *
  1212  * @return string|WP_Error $output The menu formatted to edit or error object on failure.
   975  * @return array Columns.
  1213  */
   976  */
  1214 function wp_nav_menu_manage_columns() {
   977 function wp_nav_menu_manage_columns() {
  1215 	return array(
   978 	return array(
  1216 		'_title' => __('Show advanced menu properties'),
   979 		'_title'          => __( 'Show advanced menu properties' ),
  1217 		'cb' => '<input type="checkbox" />',
   980 		'cb'              => '<input type="checkbox" />',
  1218 		'link-target' => __('Link Target'),
   981 		'link-target'     => __( 'Link Target' ),
  1219 		'css-classes' => __('CSS Classes'),
   982 		'title-attribute' => __( 'Title Attribute' ),
  1220 		'xfn' => __('Link Relationship (XFN)'),
   983 		'css-classes'     => __( 'CSS Classes' ),
  1221 		'description' => __('Description'),
   984 		'xfn'             => __( 'Link Relationship (XFN)' ),
       
   985 		'description'     => __( 'Description' ),
  1222 	);
   986 	);
  1223 }
   987 }
  1224 
   988 
  1225 /**
   989 /**
  1226  * Deletes orphaned draft menu items
   990  * Deletes orphaned draft menu items
  1227  *
   991  *
  1228  * @access private
   992  * @access private
  1229  * @since 3.0.0
   993  * @since 3.0.0
  1230  *
   994  *
       
   995  * @global wpdb $wpdb WordPress database abstraction object.
  1231  */
   996  */
  1232 function _wp_delete_orphaned_draft_menu_items() {
   997 function _wp_delete_orphaned_draft_menu_items() {
  1233 	global $wpdb;
   998 	global $wpdb;
  1234 	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
   999 	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
  1235 
  1000 
  1236 	// Delete orphaned draft menu items.
  1001 	// Delete orphaned draft menu items.
  1237 	$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 ) );
  1002 	$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 ) );
  1238 
  1003 
  1239 	foreach( (array) $menu_items_to_delete as $menu_item_id )
  1004 	foreach ( (array) $menu_items_to_delete as $menu_item_id )
  1240 		wp_delete_post( $menu_item_id, true );
  1005 		wp_delete_post( $menu_item_id, true );
  1241 }
  1006 }
  1242 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
       
  1243 
  1007 
  1244 /**
  1008 /**
  1245  * Saves nav menu items
  1009  * Saves nav menu items
  1246  *
  1010  *
  1247  * @since 3.6.0
  1011  * @since 3.6.0
  1266 	);
  1030 	);
  1267 
  1031 
  1268 	wp_defer_term_counting( true );
  1032 	wp_defer_term_counting( true );
  1269 	// Loop through all the menu items' POST variables
  1033 	// Loop through all the menu items' POST variables
  1270 	if ( ! empty( $_POST['menu-item-db-id'] ) ) {
  1034 	if ( ! empty( $_POST['menu-item-db-id'] ) ) {
  1271 		foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
  1035 		foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
  1272 
  1036 
  1273 			// Menu item title can't be blank
  1037 			// Menu item title can't be blank
  1274 			if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] )
  1038 			if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] )
  1275 				continue;
  1039 				continue;
  1276 
  1040 
  1278 			foreach ( $post_fields as $field )
  1042 			foreach ( $post_fields as $field )
  1279 				$args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : '';
  1043 				$args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : '';
  1280 
  1044 
  1281 			$menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );
  1045 			$menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );
  1282 
  1046 
  1283 			if ( is_wp_error( $menu_item_db_id ) )
  1047 			if ( is_wp_error( $menu_item_db_id ) ) {
  1284 				$messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
  1048 				$messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
  1285 			elseif ( isset( $menu_items[$menu_item_db_id] ) )
  1049 			} else {
  1286 				unset( $menu_items[$menu_item_db_id] );
  1050 				unset( $menu_items[ $menu_item_db_id ] );
       
  1051 			}
  1287 		}
  1052 		}
  1288 	}
  1053 	}
  1289 
  1054 
  1290 	// Remove menu items from the menu that weren't in $_POST
  1055 	// Remove menu items from the menu that weren't in $_POST
  1291 	if ( ! empty( $menu_items ) ) {
  1056 	if ( ! empty( $menu_items ) ) {
  1315 	wp_defer_term_counting( false );
  1080 	wp_defer_term_counting( false );
  1316 
  1081 
  1317 	/** This action is documented in wp-includes/nav-menu.php */
  1082 	/** This action is documented in wp-includes/nav-menu.php */
  1318 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
  1083 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
  1319 
  1084 
  1320 	$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>';
  1085 	$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' .
       
  1086 		/* translators: %s: nav menu title */
       
  1087 		sprintf( __( '%s has been updated.' ),
       
  1088 			'<strong>' . $nav_menu_selected_title . '</strong>'
       
  1089 		) . '</p></div>';
       
  1090 
  1321 	unset( $menu_items, $unsorted_menu_items );
  1091 	unset( $menu_items, $unsorted_menu_items );
  1322 
  1092 
  1323 	return $messages;
  1093 	return $messages;
  1324 }
  1094 }
       
  1095 
       
  1096 /**
       
  1097  * If a JSON blob of navigation menu data is in POST data, expand it and inject
       
  1098  * it into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
       
  1099  *
       
  1100  * @ignore
       
  1101  * @since 4.5.3
       
  1102  * @access private
       
  1103  */
       
  1104 function _wp_expand_nav_menu_post_data() {
       
  1105 	if ( ! isset( $_POST['nav-menu-data'] ) ) {
       
  1106 		return;
       
  1107 	}
       
  1108 
       
  1109 	$data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
       
  1110 
       
  1111 	if ( ! is_null( $data ) && $data ) {
       
  1112 		foreach ( $data as $post_input_data ) {
       
  1113 			// For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
       
  1114 			// derive the array path keys via regex and set the value in $_POST.
       
  1115 			preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
       
  1116 
       
  1117 			$array_bits = array( $matches[1] );
       
  1118 
       
  1119 			if ( isset( $matches[3] ) ) {
       
  1120 				$array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) );
       
  1121 			}
       
  1122 
       
  1123 			$new_post_data = array();
       
  1124 
       
  1125 			// Build the new array value from leaf to trunk.
       
  1126 			for ( $i = count( $array_bits ) - 1; $i >= 0; $i -- ) {
       
  1127 				if ( $i == count( $array_bits ) - 1 ) {
       
  1128 					$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
       
  1129 				} else {
       
  1130 					$new_post_data = array( $array_bits[ $i ] => $new_post_data );
       
  1131 				}
       
  1132 			}
       
  1133 
       
  1134 			$_POST = array_replace_recursive( $_POST, $new_post_data );
       
  1135 		}
       
  1136 	}
       
  1137 }