wp/wp-admin/includes/nav-menu.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    30 	if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) {
    30 	if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) {
    31 		$response_format = 'json';
    31 		$response_format = 'json';
    32 	}
    32 	}
    33 
    33 
    34 	if ( 'markup' === $response_format ) {
    34 	if ( 'markup' === $response_format ) {
    35 		$args['walker'] = new Walker_Nav_Menu_Checklist;
    35 		$args['walker'] = new Walker_Nav_Menu_Checklist();
    36 	}
    36 	}
    37 
    37 
    38 	if ( 'get-post-item' === $type ) {
    38 	if ( 'get-post-item' === $type ) {
    39 		if ( post_type_exists( $object_type ) ) {
    39 		if ( post_type_exists( $object_type ) ) {
    40 			if ( isset( $request['ID'] ) ) {
    40 			if ( isset( $request['ID'] ) ) {
    41 				$object_id = (int) $request['ID'];
    41 				$object_id = (int) $request['ID'];
       
    42 
    42 				if ( 'markup' === $response_format ) {
    43 				if ( 'markup' === $response_format ) {
    43 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
    44 					echo walk_nav_menu_tree(
       
    45 						array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ),
       
    46 						0,
       
    47 						(object) $args
       
    48 					);
    44 				} elseif ( 'json' === $response_format ) {
    49 				} elseif ( 'json' === $response_format ) {
    45 					echo wp_json_encode(
    50 					echo wp_json_encode(
    46 						array(
    51 						array(
    47 							'ID'         => $object_id,
    52 							'ID'         => $object_id,
    48 							'post_title' => get_the_title( $object_id ),
    53 							'post_title' => get_the_title( $object_id ),
    53 				}
    58 				}
    54 			}
    59 			}
    55 		} elseif ( taxonomy_exists( $object_type ) ) {
    60 		} elseif ( taxonomy_exists( $object_type ) ) {
    56 			if ( isset( $request['ID'] ) ) {
    61 			if ( isset( $request['ID'] ) ) {
    57 				$object_id = (int) $request['ID'];
    62 				$object_id = (int) $request['ID'];
       
    63 
    58 				if ( 'markup' === $response_format ) {
    64 				if ( 'markup' === $response_format ) {
    59 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
    65 					echo walk_nav_menu_tree(
       
    66 						array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ),
       
    67 						0,
       
    68 						(object) $args
       
    69 					);
    60 				} elseif ( 'json' === $response_format ) {
    70 				} elseif ( 'json' === $response_format ) {
    61 					$post_obj = get_term( $object_id, $object_type );
    71 					$post_obj = get_term( $object_id, $object_type );
    62 					echo wp_json_encode(
    72 					echo wp_json_encode(
    63 						array(
    73 						array(
    64 							'ID'         => $object_id,
    74 							'ID'         => $object_id,
    82 					'posts_per_page'         => 10,
    92 					'posts_per_page'         => 10,
    83 					'post_type'              => $matches[2],
    93 					'post_type'              => $matches[2],
    84 					's'                      => $query,
    94 					's'                      => $query,
    85 				)
    95 				)
    86 			);
    96 			);
       
    97 
    87 			if ( isset( $post_type_obj->_default_query ) ) {
    98 			if ( isset( $post_type_obj->_default_query ) ) {
    88 				$args = array_merge( $args, (array) $post_type_obj->_default_query );
    99 				$args = array_merge( $args, (array) $post_type_obj->_default_query );
    89 			}
   100 			}
       
   101 
    90 			$search_results_query = new WP_Query( $args );
   102 			$search_results_query = new WP_Query( $args );
    91 			if ( ! $search_results_query->have_posts() ) {
   103 			if ( ! $search_results_query->have_posts() ) {
    92 				return;
   104 				return;
    93 			}
   105 			}
       
   106 
    94 			while ( $search_results_query->have_posts() ) {
   107 			while ( $search_results_query->have_posts() ) {
    95 				$post = $search_results_query->next_post();
   108 				$post = $search_results_query->next_post();
       
   109 
    96 				if ( 'markup' === $response_format ) {
   110 				if ( 'markup' === $response_format ) {
    97 					$var_by_ref = $post->ID;
   111 					$var_by_ref = $post->ID;
    98 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
   112 					echo walk_nav_menu_tree(
       
   113 						array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ),
       
   114 						0,
       
   115 						(object) $args
       
   116 					);
    99 				} elseif ( 'json' === $response_format ) {
   117 				} elseif ( 'json' === $response_format ) {
   100 					echo wp_json_encode(
   118 					echo wp_json_encode(
   101 						array(
   119 						array(
   102 							'ID'         => $post->ID,
   120 							'ID'         => $post->ID,
   103 							'post_title' => get_the_title( $post->ID ),
   121 							'post_title' => get_the_title( $post->ID ),
   114 					'name__like' => $query,
   132 					'name__like' => $query,
   115 					'number'     => 10,
   133 					'number'     => 10,
   116 					'hide_empty' => false,
   134 					'hide_empty' => false,
   117 				)
   135 				)
   118 			);
   136 			);
       
   137 
   119 			if ( empty( $terms ) || is_wp_error( $terms ) ) {
   138 			if ( empty( $terms ) || is_wp_error( $terms ) ) {
   120 				return;
   139 				return;
   121 			}
   140 			}
       
   141 
   122 			foreach ( (array) $terms as $term ) {
   142 			foreach ( (array) $terms as $term ) {
   123 				if ( 'markup' === $response_format ) {
   143 				if ( 'markup' === $response_format ) {
   124 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
   144 					echo walk_nav_menu_tree(
       
   145 						array_map( 'wp_setup_nav_menu_item', array( $term ) ),
       
   146 						0,
       
   147 						(object) $args
       
   148 					);
   125 				} elseif ( 'json' === $response_format ) {
   149 				} elseif ( 'json' === $response_format ) {
   126 					echo wp_json_encode(
   150 					echo wp_json_encode(
   127 						array(
   151 						array(
   128 							'ID'         => $term->term_id,
   152 							'ID'         => $term->term_id,
   129 							'post_title' => $term->name,
   153 							'post_title' => $term->name,
   143  * @since 3.0.0
   167  * @since 3.0.0
   144  */
   168  */
   145 function wp_nav_menu_setup() {
   169 function wp_nav_menu_setup() {
   146 	// Register meta boxes.
   170 	// Register meta boxes.
   147 	wp_nav_menu_post_type_meta_boxes();
   171 	wp_nav_menu_post_type_meta_boxes();
   148 	add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
   172 	add_meta_box(
       
   173 		'add-custom-links',
       
   174 		__( 'Custom Links' ),
       
   175 		'wp_nav_menu_item_link_meta_box',
       
   176 		'nav-menus',
       
   177 		'side',
       
   178 		'default'
       
   179 	);
   149 	wp_nav_menu_taxonomy_meta_boxes();
   180 	wp_nav_menu_taxonomy_meta_boxes();
   150 
   181 
   151 	// Register advanced menu items (columns).
   182 	// Register advanced menu items (columns).
   152 	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
   183 	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
   153 
   184 
   171 /**
   202 /**
   172  * Limit the amount of meta boxes to pages, posts, links, and categories for first time users.
   203  * Limit the amount of meta boxes to pages, posts, links, and categories for first time users.
   173  *
   204  *
   174  * @since 3.0.0
   205  * @since 3.0.0
   175  *
   206  *
   176  * @global array $wp_meta_boxes
   207  * @global array $wp_meta_boxes Global meta box state.
   177  */
   208  */
   178 function wp_initial_nav_menu_meta_boxes() {
   209 function wp_initial_nav_menu_meta_boxes() {
   179 	global $wp_meta_boxes;
   210 	global $wp_meta_boxes;
   180 
   211 
   181 	if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) {
   212 	if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) {
   225 		 *
   256 		 *
   226 		 * @param WP_Post_Type|false $post_type The current object to add a menu items
   257 		 * @param WP_Post_Type|false $post_type The current object to add a menu items
   227 		 *                                      meta box for.
   258 		 *                                      meta box for.
   228 		 */
   259 		 */
   229 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
   260 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
       
   261 
   230 		if ( $post_type ) {
   262 		if ( $post_type ) {
   231 			$id = $post_type->name;
   263 			$id = $post_type->name;
   232 			// Give pages a higher priority.
   264 			// Give pages a higher priority.
   233 			$priority = ( 'page' === $post_type->name ? 'core' : 'default' );
   265 			$priority = ( 'page' === $post_type->name ? 'core' : 'default' );
   234 			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 );
   266 			add_meta_box(
       
   267 				"add-post-type-{$id}",
       
   268 				$post_type->labels->name,
       
   269 				'wp_nav_menu_item_post_type_meta_box',
       
   270 				'nav-menus',
       
   271 				'side',
       
   272 				$priority,
       
   273 				$post_type
       
   274 			);
   235 		}
   275 		}
   236 	}
   276 	}
   237 }
   277 }
   238 
   278 
   239 /**
   279 /**
   249 	}
   289 	}
   250 
   290 
   251 	foreach ( $taxonomies as $tax ) {
   291 	foreach ( $taxonomies as $tax ) {
   252 		/** This filter is documented in wp-admin/includes/nav-menu.php */
   292 		/** This filter is documented in wp-admin/includes/nav-menu.php */
   253 		$tax = apply_filters( 'nav_menu_meta_box_object', $tax );
   293 		$tax = apply_filters( 'nav_menu_meta_box_object', $tax );
       
   294 
   254 		if ( $tax ) {
   295 		if ( $tax ) {
   255 			$id = $tax->name;
   296 			$id = $tax->name;
   256 			add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
   297 			add_meta_box(
       
   298 				"add-{$id}",
       
   299 				$tax->labels->name,
       
   300 				'wp_nav_menu_item_taxonomy_meta_box',
       
   301 				'nav-menus',
       
   302 				'side',
       
   303 				'default',
       
   304 				$tax
       
   305 			);
   257 		}
   306 		}
   258 	}
   307 	}
   259 }
   308 }
   260 
   309 
   261 /**
   310 /**
   296 	?>
   345 	?>
   297 	<div class="customlinkdiv" id="customlinkdiv">
   346 	<div class="customlinkdiv" id="customlinkdiv">
   298 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
   347 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
   299 		<p id="menu-item-url-wrap" class="wp-clearfix">
   348 		<p id="menu-item-url-wrap" class="wp-clearfix">
   300 			<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
   349 			<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
   301 			<input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="code menu-item-textbox form-required" placeholder="https://" />
   350 			<input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]"
       
   351 				type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
   352 				class="code menu-item-textbox form-required" placeholder="https://"
       
   353 			/>
   302 		</p>
   354 		</p>
   303 
   355 
   304 		<p id="menu-item-name-wrap" class="wp-clearfix">
   356 		<p id="menu-item-name-wrap" class="wp-clearfix">
   305 			<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
   357 			<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
   306 			<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="regular-text menu-item-textbox" />
   358 			<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]"
       
   359 				type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
   360 				class="regular-text menu-item-textbox"
       
   361 			/>
   307 		</p>
   362 		</p>
   308 
   363 
   309 		<p class="button-controls wp-clearfix">
   364 		<p class="button-controls wp-clearfix">
   310 			<span class="add-to-menu">
   365 			<span class="add-to-menu">
   311 				<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" />
   366 				<input id="submit-customlinkdiv" name="add-custom-menu-item"
       
   367 					type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
   368 					class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>"
       
   369 				/>
   312 				<span class="spinner"></span>
   370 				<span class="spinner"></span>
   313 			</span>
   371 			</span>
   314 		</p>
   372 		</p>
   315 
   373 
   316 	</div><!-- /.customlinkdiv -->
   374 	</div><!-- /.customlinkdiv -->
   372 
   430 
   373 		// Insert Front Page or custom Home link.
   431 		// Insert Front Page or custom Home link.
   374 		$front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
   432 		$front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
   375 
   433 
   376 		$front_page_obj = null;
   434 		$front_page_obj = null;
       
   435 
   377 		if ( ! empty( $front_page ) ) {
   436 		if ( ! empty( $front_page ) ) {
   378 			$front_page_obj                = get_post( $front_page );
   437 			$front_page_obj = get_post( $front_page );
       
   438 		}
       
   439 
       
   440 		if ( $front_page_obj ) {
   379 			$front_page_obj->front_or_home = true;
   441 			$front_page_obj->front_or_home = true;
   380 
   442 
   381 			$important_pages[]   = $front_page_obj;
   443 			$important_pages[]   = $front_page_obj;
   382 			$suppress_page_ids[] = $front_page_obj->ID;
   444 			$suppress_page_ids[] = $front_page_obj->ID;
   383 		} else {
   445 		} else {
   400 
   462 
   401 		// Insert Posts Page.
   463 		// Insert Posts Page.
   402 		$posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0;
   464 		$posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0;
   403 
   465 
   404 		if ( ! empty( $posts_page ) ) {
   466 		if ( ! empty( $posts_page ) ) {
   405 			$posts_page_obj             = get_post( $posts_page );
   467 			$posts_page_obj = get_post( $posts_page );
   406 			$posts_page_obj->posts_page = true;
   468 
   407 
   469 			if ( $posts_page_obj ) {
   408 			$important_pages[]   = $posts_page_obj;
   470 				$front_page_obj->posts_page = true;
   409 			$suppress_page_ids[] = $posts_page_obj->ID;
   471 
       
   472 				$important_pages[]   = $posts_page_obj;
       
   473 				$suppress_page_ids[] = $posts_page_obj->ID;
       
   474 			}
   410 		}
   475 		}
   411 
   476 
   412 		// Insert Privacy Policy Page.
   477 		// Insert Privacy Policy Page.
   413 		$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
   478 		$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
   414 
   479 
   415 		if ( ! empty( $privacy_policy_page_id ) ) {
   480 		if ( ! empty( $privacy_policy_page_id ) ) {
   416 			$privacy_policy_page = get_post( $privacy_policy_page_id );
   481 			$privacy_policy_page = get_post( $privacy_policy_page_id );
       
   482 
   417 			if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) {
   483 			if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) {
   418 				$privacy_policy_page->privacy_policy_page = true;
   484 				$privacy_policy_page->privacy_policy_page = true;
   419 
   485 
   420 				$important_pages[]   = $privacy_policy_page;
   486 				$important_pages[]   = $privacy_policy_page;
   421 				$suppress_page_ids[] = $privacy_policy_page->ID;
   487 				$suppress_page_ids[] = $privacy_policy_page->ID;
   427 			$args['post__not_in'] = $suppress_page_ids;
   493 			$args['post__not_in'] = $suppress_page_ids;
   428 		}
   494 		}
   429 	}
   495 	}
   430 
   496 
   431 	// @todo Transient caching of these results with proper invalidation on updating of a post of this type.
   497 	// @todo Transient caching of these results with proper invalidation on updating of a post of this type.
   432 	$get_posts = new WP_Query;
   498 	$get_posts = new WP_Query();
   433 	$posts     = $get_posts->query( $args );
   499 	$posts     = $get_posts->query( $args );
   434 
   500 
   435 	// Only suppress and insert when more than just suppression pages available.
   501 	// Only suppress and insert when more than just suppression pages available.
   436 	if ( ! $get_posts->post_count ) {
   502 	if ( ! $get_posts->post_count ) {
   437 		if ( ! empty( $suppress_page_ids ) ) {
   503 		if ( ! empty( $suppress_page_ids ) ) {
   438 			unset( $args['post__not_in'] );
   504 			unset( $args['post__not_in'] );
   439 			$get_posts = new WP_Query;
   505 			$get_posts = new WP_Query();
   440 			$posts     = $get_posts->query( $args );
   506 			$posts     = $get_posts->query( $args );
   441 		} else {
   507 		} else {
   442 			echo '<p>' . __( 'No items.' ) . '</p>';
   508 			echo '<p>' . __( 'No items.' ) . '</p>';
   443 			return;
   509 			return;
   444 		}
   510 		}
   459 				)
   525 				)
   460 			),
   526 			),
   461 			'format'             => '',
   527 			'format'             => '',
   462 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   528 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   463 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   529 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
       
   530 			/* translators: Hidden accessibility text. */
   464 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
   531 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
   465 			'total'              => $num_pages,
   532 			'total'              => $num_pages,
   466 			'current'            => $pagenum,
   533 			'current'            => $pagenum,
   467 		)
   534 		)
   468 	);
   535 	);
   481 
   548 
   482 	if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) {
   549 	if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) {
   483 		$current_tab = $_REQUEST[ $tab_name ];
   550 		$current_tab = $_REQUEST[ $tab_name ];
   484 	}
   551 	}
   485 
   552 
   486 	if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
   553 	if ( ! empty( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) {
   487 		$current_tab = 'search';
   554 		$current_tab = 'search';
   488 	}
   555 	}
   489 
   556 
   490 	$removed_args = array(
   557 	$removed_args = array(
   491 		'action',
   558 		'action',
   497 	);
   564 	);
   498 
   565 
   499 	$most_recent_url = '';
   566 	$most_recent_url = '';
   500 	$view_all_url    = '';
   567 	$view_all_url    = '';
   501 	$search_url      = '';
   568 	$search_url      = '';
       
   569 
   502 	if ( $nav_menu_selected_id ) {
   570 	if ( $nav_menu_selected_id ) {
   503 		$most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) );
   571 		$most_recent_url = add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) );
   504 		$view_all_url    = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
   572 		$view_all_url    = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) );
   505 		$search_url      = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
   573 		$search_url      = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) );
   506 	}
   574 	}
   507 	?>
   575 	?>
   508 	<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
   576 	<div id="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>" class="posttypediv">
   509 		<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
   577 		<ul id="<?php echo esc_attr( "posttype-{$post_type_name}-tabs" ); ?>" class="posttype-tabs add-menu-item-tabs">
   510 			<li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>>
   578 			<li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>>
   511 				<a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-most-recent" href="<?php echo $most_recent_url; ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent">
   579 				<a class="nav-tab-link"
       
   580 					data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
       
   581 					href="<?php echo esc_url( $most_recent_url . "#tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
       
   582 				>
   512 					<?php _e( 'Most Recent' ); ?>
   583 					<?php _e( 'Most Recent' ); ?>
   513 				</a>
   584 				</a>
   514 			</li>
   585 			</li>
   515 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
   586 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
   516 				<a class="nav-tab-link" data-type="<?php echo esc_attr( $post_type_name ); ?>-all" href="<?php echo $view_all_url; ?>#<?php echo $post_type_name; ?>-all">
   587 				<a class="nav-tab-link"
       
   588 					data-type="<?php echo esc_attr( "{$post_type_name}-all" ); ?>"
       
   589 					href="<?php echo esc_url( $view_all_url . "#{$post_type_name}-all" ); ?>"
       
   590 				>
   517 					<?php _e( 'View All' ); ?>
   591 					<?php _e( 'View All' ); ?>
   518 				</a>
   592 				</a>
   519 			</li>
   593 			</li>
   520 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
   594 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
   521 				<a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-search" href="<?php echo $search_url; ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search">
   595 				<a class="nav-tab-link"
       
   596 					data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>"
       
   597 					href="<?php echo esc_url( $search_url . "#tabs-panel-posttype-{$post_type_name}-search" ); ?>"
       
   598 				>
   522 					<?php _e( 'Search' ); ?>
   599 					<?php _e( 'Search' ); ?>
   523 				</a>
   600 				</a>
   524 			</li>
   601 			</li>
   525 		</ul><!-- .posttype-tabs -->
   602 		</ul><!-- .posttype-tabs -->
   526 
   603 
   527 		<div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php echo ( 'most-recent' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" role="region" aria-label="<?php _e( 'Most Recent' ); ?>" tabindex="0">
   604 		<div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
   528 			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
   605 			class="tabs-panel <?php echo ( 'most-recent' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
       
   606 			role="region" aria-label="<?php esc_attr_e( 'Most Recent' ); ?>" tabindex="0"
       
   607 		>
       
   608 			<ul id="<?php echo esc_attr( "{$post_type_name}checklist-most-recent" ); ?>"
       
   609 				class="categorychecklist form-no-clear"
       
   610 			>
   529 				<?php
   611 				<?php
   530 				$recent_args    = array_merge(
   612 				$recent_args = array_merge(
   531 					$args,
   613 					$args,
   532 					array(
   614 					array(
   533 						'orderby'        => 'post_date',
   615 						'orderby'        => 'post_date',
   534 						'order'          => 'DESC',
   616 						'order'          => 'DESC',
   535 						'posts_per_page' => 15,
   617 						'posts_per_page' => 15,
   536 					)
   618 					)
   537 				);
   619 				);
   538 				$most_recent    = $get_posts->query( $recent_args );
   620 				$most_recent = $get_posts->query( $recent_args );
       
   621 
   539 				$args['walker'] = $walker;
   622 				$args['walker'] = $walker;
   540 
   623 
   541 				/**
   624 				/**
   542 				 * Filters the posts displayed in the 'Most Recent' tab of the current
   625 				 * Filters the posts displayed in the 'Most Recent' tab of the current
   543 				 * post type's menu items meta box.
   626 				 * post type's menu items meta box.
   555 				 * @param WP_Post[] $most_recent An array of post objects being listed.
   638 				 * @param WP_Post[] $most_recent An array of post objects being listed.
   556 				 * @param array     $args        An array of `WP_Query` arguments for the meta box.
   639 				 * @param array     $args        An array of `WP_Query` arguments for the meta box.
   557 				 * @param array     $box         Arguments passed to `wp_nav_menu_item_post_type_meta_box()`.
   640 				 * @param array     $box         Arguments passed to `wp_nav_menu_item_post_type_meta_box()`.
   558 				 * @param array     $recent_args An array of `WP_Query` arguments for 'Most Recent' tab.
   641 				 * @param array     $recent_args An array of `WP_Query` arguments for 'Most Recent' tab.
   559 				 */
   642 				 */
   560 				$most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box, $recent_args );
   643 				$most_recent = apply_filters(
   561 
   644 					"nav_menu_items_{$post_type_name}_recent",
   562 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args );
   645 					$most_recent,
       
   646 					$args,
       
   647 					$box,
       
   648 					$recent_args
       
   649 				);
       
   650 
       
   651 				echo walk_nav_menu_tree(
       
   652 					array_map( 'wp_setup_nav_menu_item', $most_recent ),
       
   653 					0,
       
   654 					(object) $args
       
   655 				);
   563 				?>
   656 				?>
   564 			</ul>
   657 			</ul>
   565 		</div><!-- /.tabs-panel -->
   658 		</div><!-- /.tabs-panel -->
   566 
   659 
   567 		<div class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search" role="region" aria-label="<?php echo $post_type->labels->search_items; ?>" tabindex="0">
   660 		<div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>"
       
   661 			class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
       
   662 			role="region" aria-label="<?php echo esc_attr( $post_type->labels->search_items ); ?>" tabindex="0"
       
   663 		>
   568 			<?php
   664 			<?php
   569 			if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
   665 			if ( isset( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) {
   570 				$searched       = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] );
   666 				$searched       = esc_attr( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] );
   571 				$search_results = get_posts(
   667 				$search_results = get_posts(
   572 					array(
   668 					array(
   573 						's'         => $searched,
   669 						's'         => $searched,
   574 						'post_type' => $post_type_name,
   670 						'post_type' => $post_type_name,
   575 						'fields'    => 'all',
   671 						'fields'    => 'all',
   580 				$searched       = '';
   676 				$searched       = '';
   581 				$search_results = array();
   677 				$search_results = array();
   582 			}
   678 			}
   583 			?>
   679 			?>
   584 			<p class="quick-search-wrap">
   680 			<p class="quick-search-wrap">
   585 				<label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
   681 				<label for="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>" class="screen-reader-text">
   586 				<input type="search"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> 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; ?>" />
   682 					<?php
       
   683 					/* translators: Hidden accessibility text. */
       
   684 					_e( 'Search' );
       
   685 					?>
       
   686 				</label>
       
   687 				<input type="search"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
   688 					class="quick-search" value="<?php echo $searched; ?>"
       
   689 					name="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>"
       
   690 					id="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>"
       
   691 				/>
   587 				<span class="spinner"></span>
   692 				<span class="spinner"></span>
   588 				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
   693 				<?php
       
   694 				submit_button(
       
   695 					__( 'Search' ),
       
   696 					'small quick-search-submit hide-if-js',
       
   697 					'submit',
       
   698 					false,
       
   699 					array( 'id' => "submit-quick-search-posttype-{$post_type_name}" )
       
   700 				);
       
   701 				?>
   589 			</p>
   702 			</p>
   590 
   703 
   591 			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
   704 			<ul id="<?php echo esc_attr( "{$post_type_name}-search-checklist" ); ?>"
       
   705 				data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>"
       
   706 				class="categorychecklist form-no-clear"
       
   707 			>
   592 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
   708 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
   593 				<?php
   709 				<?php
   594 				$args['walker'] = $walker;
   710 				$args['walker'] = $walker;
   595 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args );
   711 				echo walk_nav_menu_tree(
       
   712 					array_map( 'wp_setup_nav_menu_item', $search_results ),
       
   713 					0,
       
   714 					(object) $args
       
   715 				);
   596 				?>
   716 				?>
   597 			<?php elseif ( is_wp_error( $search_results ) ) : ?>
   717 			<?php elseif ( is_wp_error( $search_results ) ) : ?>
   598 				<li><?php echo $search_results->get_error_message(); ?></li>
   718 				<li><?php echo $search_results->get_error_message(); ?></li>
   599 			<?php elseif ( ! empty( $searched ) ) : ?>
   719 			<?php elseif ( ! empty( $searched ) ) : ?>
   600 				<li><?php _e( 'No results found.' ); ?></li>
   720 				<li><?php _e( 'No results found.' ); ?></li>
   601 			<?php endif; ?>
   721 			<?php endif; ?>
   602 			</ul>
   722 			</ul>
   603 		</div><!-- /.tabs-panel -->
   723 		</div><!-- /.tabs-panel -->
   604 
   724 
   605 		<div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" role="region" aria-label="<?php echo $post_type->labels->all_items; ?>" tabindex="0">
   725 		<div id="<?php echo esc_attr( "{$post_type_name}-all" ); ?>"
       
   726 			class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
       
   727 			role="region" aria-label="<?php echo esc_attr( $post_type->labels->all_items ); ?>" tabindex="0"
       
   728 		>
   606 			<?php if ( ! empty( $page_links ) ) : ?>
   729 			<?php if ( ! empty( $page_links ) ) : ?>
   607 				<div class="add-menu-item-pagelinks">
   730 				<div class="add-menu-item-pagelinks">
   608 					<?php echo $page_links; ?>
   731 					<?php echo $page_links; ?>
   609 				</div>
   732 				</div>
   610 			<?php endif; ?>
   733 			<?php endif; ?>
   611 			<ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
   734 
       
   735 			<ul id="<?php echo esc_attr( "{$post_type_name}checklist" ); ?>"
       
   736 				data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>"
       
   737 				class="categorychecklist form-no-clear"
       
   738 			>
   612 				<?php
   739 				<?php
   613 				$args['walker'] = $walker;
   740 				$args['walker'] = $walker;
   614 
   741 
   615 				if ( $post_type->has_archive ) {
   742 				if ( $post_type->has_archive ) {
   616 					$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1;
   743 					$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1;
   650 				 * @param object[]     $posts     The posts for the current post type. Mostly `WP_Post` objects, but
   777 				 * @param object[]     $posts     The posts for the current post type. Mostly `WP_Post` objects, but
   651 				 *                                can also contain "fake" post objects to represent other menu items.
   778 				 *                                can also contain "fake" post objects to represent other menu items.
   652 				 * @param array        $args      An array of `WP_Query` arguments.
   779 				 * @param array        $args      An array of `WP_Query` arguments.
   653 				 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
   780 				 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
   654 				 */
   781 				 */
   655 				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
   782 				$posts = apply_filters(
   656 
   783 					"nav_menu_items_{$post_type_name}",
   657 				$checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args );
   784 					$posts,
       
   785 					$args,
       
   786 					$post_type
       
   787 				);
       
   788 
       
   789 				$checkbox_items = walk_nav_menu_tree(
       
   790 					array_map( 'wp_setup_nav_menu_item', $posts ),
       
   791 					0,
       
   792 					(object) $args
       
   793 				);
   658 
   794 
   659 				echo $checkbox_items;
   795 				echo $checkbox_items;
   660 				?>
   796 				?>
   661 			</ul>
   797 			</ul>
       
   798 
   662 			<?php if ( ! empty( $page_links ) ) : ?>
   799 			<?php if ( ! empty( $page_links ) ) : ?>
   663 				<div class="add-menu-item-pagelinks">
   800 				<div class="add-menu-item-pagelinks">
   664 					<?php echo $page_links; ?>
   801 					<?php echo $page_links; ?>
   665 				</div>
   802 				</div>
   666 			<?php endif; ?>
   803 			<?php endif; ?>
   667 		</div><!-- /.tabs-panel -->
   804 		</div><!-- /.tabs-panel -->
   668 
   805 
   669 		<p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
   806 		<p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>">
   670 			<span class="list-controls hide-if-no-js">
   807 			<span class="list-controls hide-if-no-js">
   671 				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
   808 				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
   809 					id="<?php echo esc_attr( $tab_name ); ?>" class="select-all"
       
   810 				/>
   672 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
   811 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
   673 			</span>
   812 			</span>
   674 
   813 
   675 			<span class="add-to-menu">
   814 			<span class="add-to-menu">
   676 				<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 ); ?>" />
   815 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
   816 					class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>"
       
   817 					name="add-post-type-menu-item" id="<?php echo esc_attr( "submit-posttype-{$post_type_name}" ); ?>"
       
   818 				/>
   677 				<span class="spinner"></span>
   819 				<span class="spinner"></span>
   678 			</span>
   820 			</span>
   679 		</p>
   821 		</p>
   680 
   822 
   681 	</div><!-- /.posttypediv -->
   823 	</div><!-- /.posttypediv -->
   730 	if ( ! $terms || is_wp_error( $terms ) ) {
   872 	if ( ! $terms || is_wp_error( $terms ) ) {
   731 		echo '<p>' . __( 'No items.' ) . '</p>';
   873 		echo '<p>' . __( 'No items.' ) . '</p>';
   732 		return;
   874 		return;
   733 	}
   875 	}
   734 
   876 
   735 	$num_pages = ceil(
   877 	$num_pages = (int) ceil(
   736 		wp_count_terms(
   878 		wp_count_terms(
   737 			array_merge(
   879 			array_merge(
   738 				$args,
   880 				$args,
   739 				array(
   881 				array(
   740 					'number' => '',
   882 					'number' => '',
   755 				)
   897 				)
   756 			),
   898 			),
   757 			'format'             => '',
   899 			'format'             => '',
   758 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   900 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   759 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   901 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
       
   902 			/* translators: Hidden accessibility text. */
   760 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
   903 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
   761 			'total'              => $num_pages,
   904 			'total'              => $num_pages,
   762 			'current'            => $pagenum,
   905 			'current'            => $pagenum,
   763 		)
   906 		)
   764 	);
   907 	);
   777 
   920 
   778 	if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) {
   921 	if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) {
   779 		$current_tab = $_REQUEST[ $tab_name ];
   922 		$current_tab = $_REQUEST[ $tab_name ];
   780 	}
   923 	}
   781 
   924 
   782 	if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
   925 	if ( ! empty( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) {
   783 		$current_tab = 'search';
   926 		$current_tab = 'search';
   784 	}
   927 	}
   785 
   928 
   786 	$removed_args = array(
   929 	$removed_args = array(
   787 		'action',
   930 		'action',
   793 	);
   936 	);
   794 
   937 
   795 	$most_used_url = '';
   938 	$most_used_url = '';
   796 	$view_all_url  = '';
   939 	$view_all_url  = '';
   797 	$search_url    = '';
   940 	$search_url    = '';
       
   941 
   798 	if ( $nav_menu_selected_id ) {
   942 	if ( $nav_menu_selected_id ) {
   799 		$most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) );
   943 		$most_used_url = add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) );
   800 		$view_all_url  = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
   944 		$view_all_url  = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) );
   801 		$search_url    = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
   945 		$search_url    = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) );
   802 	}
   946 	}
   803 	?>
   947 	?>
   804 	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
   948 	<div id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>" class="taxonomydiv">
   805 		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
   949 		<ul id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}-tabs" ); ?>" class="taxonomy-tabs add-menu-item-tabs">
   806 			<li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>>
   950 			<li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>>
   807 				<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-pop" href="<?php echo $most_used_url; ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop">
   951 				<a class="nav-tab-link"
       
   952 					data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>"
       
   953 					href="<?php echo esc_url( $most_used_url . "#tabs-panel-{$taxonomy_name}-pop" ); ?>"
       
   954 				>
   808 					<?php echo esc_html( $taxonomy->labels->most_used ); ?>
   955 					<?php echo esc_html( $taxonomy->labels->most_used ); ?>
   809 				</a>
   956 				</a>
   810 			</li>
   957 			</li>
   811 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
   958 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
   812 				<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-all" href="<?php echo $view_all_url; ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all">
   959 				<a class="nav-tab-link"
       
   960 					data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>"
       
   961 					href="<?php echo esc_url( $view_all_url . "#tabs-panel-{$taxonomy_name}-all" ); ?>"
       
   962 				>
   813 					<?php _e( 'View All' ); ?>
   963 					<?php _e( 'View All' ); ?>
   814 				</a>
   964 				</a>
   815 			</li>
   965 			</li>
   816 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
   966 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
   817 				<a class="nav-tab-link" data-type="tabs-panel-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" href="<?php echo $search_url; ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>">
   967 				<a class="nav-tab-link"
       
   968 					data-type="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
       
   969 					href="<?php echo esc_url( $search_url . "#tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
       
   970 				>
   818 					<?php _e( 'Search' ); ?>
   971 					<?php _e( 'Search' ); ?>
   819 				</a>
   972 				</a>
   820 			</li>
   973 			</li>
   821 		</ul><!-- .taxonomy-tabs -->
   974 		</ul><!-- .taxonomy-tabs -->
   822 
   975 
   823 		<div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php echo ( 'most-used' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" role="region" aria-label="<?php echo $taxonomy->labels->most_used; ?>" tabindex="0">
   976 		<div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>"
   824 			<ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
   977 			class="tabs-panel <?php echo ( 'most-used' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
       
   978 			role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->most_used ); ?>" tabindex="0"
       
   979 		>
       
   980 			<ul id="<?php echo esc_attr( "{$taxonomy_name}checklist-pop" ); ?>"
       
   981 				class="categorychecklist form-no-clear"
       
   982 			>
   825 				<?php
   983 				<?php
   826 				$popular_terms  = get_terms(
   984 				$popular_terms = get_terms(
   827 					array(
   985 					array(
   828 						'taxonomy'     => $taxonomy_name,
   986 						'taxonomy'     => $taxonomy_name,
   829 						'orderby'      => 'count',
   987 						'orderby'      => 'count',
   830 						'order'        => 'DESC',
   988 						'order'        => 'DESC',
   831 						'number'       => 10,
   989 						'number'       => 10,
   832 						'hierarchical' => false,
   990 						'hierarchical' => false,
   833 					)
   991 					)
   834 				);
   992 				);
       
   993 
   835 				$args['walker'] = $walker;
   994 				$args['walker'] = $walker;
   836 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args );
   995 				echo walk_nav_menu_tree(
       
   996 					array_map( 'wp_setup_nav_menu_item', $popular_terms ),
       
   997 					0,
       
   998 					(object) $args
       
   999 				);
   837 				?>
  1000 				?>
   838 			</ul>
  1001 			</ul>
   839 		</div><!-- /.tabs-panel -->
  1002 		</div><!-- /.tabs-panel -->
   840 
  1003 
   841 		<div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" role="region" aria-label="<?php echo $taxonomy->labels->all_items; ?>" tabindex="0">
  1004 		<div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>"
       
  1005 			class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
       
  1006 			role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->all_items ); ?>" tabindex="0"
       
  1007 		>
   842 			<?php if ( ! empty( $page_links ) ) : ?>
  1008 			<?php if ( ! empty( $page_links ) ) : ?>
   843 				<div class="add-menu-item-pagelinks">
  1009 				<div class="add-menu-item-pagelinks">
   844 					<?php echo $page_links; ?>
  1010 					<?php echo $page_links; ?>
   845 				</div>
  1011 				</div>
   846 			<?php endif; ?>
  1012 			<?php endif; ?>
   847 			<ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name; ?>" class="categorychecklist form-no-clear">
  1013 
       
  1014 			<ul id="<?php echo esc_attr( "{$taxonomy_name}checklist" ); ?>"
       
  1015 				data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>"
       
  1016 				class="categorychecklist form-no-clear"
       
  1017 			>
   848 				<?php
  1018 				<?php
   849 				$args['walker'] = $walker;
  1019 				$args['walker'] = $walker;
   850 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args );
  1020 				echo walk_nav_menu_tree(
       
  1021 					array_map( 'wp_setup_nav_menu_item', $terms ),
       
  1022 					0,
       
  1023 					(object) $args
       
  1024 				);
   851 				?>
  1025 				?>
   852 			</ul>
  1026 			</ul>
       
  1027 
   853 			<?php if ( ! empty( $page_links ) ) : ?>
  1028 			<?php if ( ! empty( $page_links ) ) : ?>
   854 				<div class="add-menu-item-pagelinks">
  1029 				<div class="add-menu-item-pagelinks">
   855 					<?php echo $page_links; ?>
  1030 					<?php echo $page_links; ?>
   856 				</div>
  1031 				</div>
   857 			<?php endif; ?>
  1032 			<?php endif; ?>
   858 		</div><!-- /.tabs-panel -->
  1033 		</div><!-- /.tabs-panel -->
   859 
  1034 
   860 		<div class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>" role="region" aria-label="<?php echo $taxonomy->labels->search_items; ?>" tabindex="0">
  1035 		<div id="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
       
  1036 			class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
       
  1037 			role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->search_items ); ?>" tabindex="0">
   861 			<?php
  1038 			<?php
   862 			if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
  1039 			if ( isset( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) {
   863 				$searched       = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] );
  1040 				$searched       = esc_attr( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] );
   864 				$search_results = get_terms(
  1041 				$search_results = get_terms(
   865 					array(
  1042 					array(
   866 						'taxonomy'     => $taxonomy_name,
  1043 						'taxonomy'     => $taxonomy_name,
   867 						'name__like'   => $searched,
  1044 						'name__like'   => $searched,
   868 						'fields'       => 'all',
  1045 						'fields'       => 'all',
   875 				$searched       = '';
  1052 				$searched       = '';
   876 				$search_results = array();
  1053 				$search_results = array();
   877 			}
  1054 			}
   878 			?>
  1055 			?>
   879 			<p class="quick-search-wrap">
  1056 			<p class="quick-search-wrap">
   880 				<label for="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
  1057 				<label for="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>" class="screen-reader-text">
   881 				<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; ?>" />
  1058 					<?php
       
  1059 					/* translators: Hidden accessibility text. */
       
  1060 					_e( 'Search' );
       
  1061 					?>
       
  1062 				</label>
       
  1063 				<input type="search"
       
  1064 					class="quick-search" value="<?php echo $searched; ?>"
       
  1065 					name="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>"
       
  1066 					id="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>"
       
  1067 				/>
   882 				<span class="spinner"></span>
  1068 				<span class="spinner"></span>
   883 				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
  1069 				<?php
       
  1070 				submit_button(
       
  1071 					__( 'Search' ),
       
  1072 					'small quick-search-submit hide-if-js',
       
  1073 					'submit',
       
  1074 					false,
       
  1075 					array( 'id' => "submit-quick-search-taxonomy-{$taxonomy_name}" )
       
  1076 				);
       
  1077 				?>
   884 			</p>
  1078 			</p>
   885 
  1079 
   886 			<ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name; ?>" class="categorychecklist form-no-clear">
  1080 			<ul id="<?php echo esc_attr( "{$taxonomy_name}-search-checklist" ); ?>"
       
  1081 				data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>"
       
  1082 				class="categorychecklist form-no-clear"
       
  1083 			>
   887 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
  1084 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
   888 				<?php
  1085 				<?php
   889 				$args['walker'] = $walker;
  1086 				$args['walker'] = $walker;
   890 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args );
  1087 				echo walk_nav_menu_tree(
       
  1088 					array_map( 'wp_setup_nav_menu_item', $search_results ),
       
  1089 					0,
       
  1090 					(object) $args
       
  1091 				);
   891 				?>
  1092 				?>
   892 			<?php elseif ( is_wp_error( $search_results ) ) : ?>
  1093 			<?php elseif ( is_wp_error( $search_results ) ) : ?>
   893 				<li><?php echo $search_results->get_error_message(); ?></li>
  1094 				<li><?php echo $search_results->get_error_message(); ?></li>
   894 			<?php elseif ( ! empty( $searched ) ) : ?>
  1095 			<?php elseif ( ! empty( $searched ) ) : ?>
   895 				<li><?php _e( 'No results found.' ); ?></li>
  1096 				<li><?php _e( 'No results found.' ); ?></li>
   896 			<?php endif; ?>
  1097 			<?php endif; ?>
   897 			</ul>
  1098 			</ul>
   898 		</div><!-- /.tabs-panel -->
  1099 		</div><!-- /.tabs-panel -->
   899 
  1100 
   900 		<p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
  1101 		<p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>">
   901 			<span class="list-controls hide-if-no-js">
  1102 			<span class="list-controls hide-if-no-js">
   902 				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
  1103 				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
  1104 					id="<?php echo esc_attr( $tab_name ); ?>" class="select-all"
       
  1105 				/>
   903 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
  1106 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
   904 			</span>
  1107 			</span>
   905 
  1108 
   906 			<span class="add-to-menu">
  1109 			<span class="add-to-menu">
   907 				<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 ); ?>" />
  1110 				<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
       
  1111 					class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>"
       
  1112 					name="add-taxonomy-menu-item" id="<?php echo esc_attr( "submit-taxonomy-{$taxonomy_name}" ); ?>"
       
  1113 				/>
   908 				<span class="spinner"></span>
  1114 				<span class="spinner"></span>
   909 			</span>
  1115 			</span>
   910 		</p>
  1116 		</p>
   911 
  1117 
   912 	</div><!-- /.taxonomydiv -->
  1118 	</div><!-- /.taxonomydiv -->
   924  */
  1130  */
   925 function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
  1131 function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
   926 	$menu_id     = (int) $menu_id;
  1132 	$menu_id     = (int) $menu_id;
   927 	$items_saved = array();
  1133 	$items_saved = array();
   928 
  1134 
   929 	if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
  1135 	if ( 0 === $menu_id || is_nav_menu( $menu_id ) ) {
   930 
  1136 
   931 		// Loop through all the menu items' POST values.
  1137 		// Loop through all the menu items' POST values.
   932 		foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
  1138 		foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
   933 			if (
  1139 			if (
   934 				// Checkbox is not checked.
  1140 				// Checkbox is not checked.
   950 
  1156 
   951 			// If this possible menu item doesn't actually have a menu database ID yet.
  1157 			// If this possible menu item doesn't actually have a menu database ID yet.
   952 			if (
  1158 			if (
   953 				empty( $_item_object_data['menu-item-db-id'] ) ||
  1159 				empty( $_item_object_data['menu-item-db-id'] ) ||
   954 				( 0 > $_possible_db_id ) ||
  1160 				( 0 > $_possible_db_id ) ||
   955 				$_possible_db_id != $_item_object_data['menu-item-db-id']
  1161 				$_possible_db_id !== (int) $_item_object_data['menu-item-db-id']
   956 			) {
  1162 			) {
   957 				$_actual_db_id = 0;
  1163 				$_actual_db_id = 0;
   958 			} else {
  1164 			} else {
   959 				$_actual_db_id = (int) $_item_object_data['menu-item-db-id'];
  1165 				$_actual_db_id = (int) $_item_object_data['menu-item-db-id'];
   960 			}
  1166 			}
   977 
  1183 
   978 			$items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args );
  1184 			$items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args );
   979 
  1185 
   980 		}
  1186 		}
   981 	}
  1187 	}
       
  1188 
   982 	return $items_saved;
  1189 	return $items_saved;
   983 }
  1190 }
   984 
  1191 
   985 /**
  1192 /**
   986  * Adds custom arguments to some of the meta box object types.
  1193  * Adds custom arguments to some of the meta box object types.
  1057 		 * @param int    $menu_id ID of the menu being rendered.
  1264 		 * @param int    $menu_id ID of the menu being rendered.
  1058 		 */
  1265 		 */
  1059 		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
  1266 		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
  1060 
  1267 
  1061 		if ( class_exists( $walker_class_name ) ) {
  1268 		if ( class_exists( $walker_class_name ) ) {
  1062 			$walker = new $walker_class_name;
  1269 			$walker = new $walker_class_name();
  1063 		} else {
  1270 		} else {
  1064 			return new WP_Error(
  1271 			return new WP_Error(
  1065 				'menu_walker_not_exist',
  1272 				'menu_walker_not_exist',
  1066 				sprintf(
  1273 				sprintf(
  1067 					/* translators: %s: Walker class name. */
  1274 					/* translators: %s: Walker class name. */
  1071 			);
  1278 			);
  1072 		}
  1279 		}
  1073 
  1280 
  1074 		$some_pending_menu_items = false;
  1281 		$some_pending_menu_items = false;
  1075 		$some_invalid_menu_items = false;
  1282 		$some_invalid_menu_items = false;
       
  1283 
  1076 		foreach ( (array) $menu_items as $menu_item ) {
  1284 		foreach ( (array) $menu_items as $menu_item ) {
  1077 			if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
  1285 			if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
  1078 				$some_pending_menu_items = true;
  1286 				$some_pending_menu_items = true;
  1079 			}
  1287 			}
  1080 			if ( ! empty( $menu_item->_invalid ) ) {
  1288 			if ( ! empty( $menu_item->_invalid ) ) {
  1081 				$some_invalid_menu_items = true;
  1289 				$some_invalid_menu_items = true;
  1082 			}
  1290 			}
  1083 		}
  1291 		}
  1084 
  1292 
  1085 		if ( $some_pending_menu_items ) {
  1293 		if ( $some_pending_menu_items ) {
  1086 			$result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>';
  1294 			$message     = __( 'Click Save Menu to make pending menu items public.' );
       
  1295 			$notice_args = array(
       
  1296 				'type'               => 'info',
       
  1297 				'additional_classes' => array( 'notice-alt', 'inline' ),
       
  1298 			);
       
  1299 			$result     .= wp_get_admin_notice( $message, $notice_args );
  1087 		}
  1300 		}
  1088 
  1301 
  1089 		if ( $some_invalid_menu_items ) {
  1302 		if ( $some_invalid_menu_items ) {
  1090 			$result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>';
  1303 			$message     = __( 'There are some invalid menu items. Please check or delete them.' );
       
  1304 			$notice_args = array(
       
  1305 				'type'               => 'error',
       
  1306 				'additional_classes' => array( 'notice-alt', 'inline' ),
       
  1307 			);
       
  1308 			$result     .= wp_get_admin_notice( $message, $notice_args );
  1091 		}
  1309 		}
  1092 
  1310 
  1093 		$result .= '<ul class="menu" id="menu-to-edit"> ';
  1311 		$result .= '<ul class="menu" id="menu-to-edit"> ';
  1094 		$result .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items ), 0, (object) array( 'walker' => $walker ) );
  1312 		$result .= walk_nav_menu_tree(
       
  1313 			array_map( 'wp_setup_nav_menu_item', $menu_items ),
       
  1314 			0,
       
  1315 			(object) array( 'walker' => $walker )
       
  1316 		);
  1095 		$result .= ' </ul> ';
  1317 		$result .= ' </ul> ';
       
  1318 
  1096 		return $result;
  1319 		return $result;
  1097 	} elseif ( is_wp_error( $menu ) ) {
  1320 	} elseif ( is_wp_error( $menu ) ) {
  1098 		return $menu;
  1321 		return $menu;
  1099 	}
  1322 	}
  1100 
       
  1101 }
  1323 }
  1102 
  1324 
  1103 /**
  1325 /**
  1104  * Returns the columns for the nav menus page.
  1326  * Returns the columns for the nav menus page.
  1105  *
  1327  *
  1127  *
  1349  *
  1128  * @global wpdb $wpdb WordPress database abstraction object.
  1350  * @global wpdb $wpdb WordPress database abstraction object.
  1129  */
  1351  */
  1130 function _wp_delete_orphaned_draft_menu_items() {
  1352 function _wp_delete_orphaned_draft_menu_items() {
  1131 	global $wpdb;
  1353 	global $wpdb;
       
  1354 
  1132 	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
  1355 	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
  1133 
  1356 
  1134 	// Delete orphaned draft menu items.
  1357 	// Delete orphaned draft menu items.
  1135 	$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 ) );
  1358 	$menu_items_to_delete = $wpdb->get_col(
       
  1359 		$wpdb->prepare(
       
  1360 			"SELECT ID FROM $wpdb->posts AS p
       
  1361 			LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
       
  1362 			WHERE post_type = 'nav_menu_item' AND post_status = 'draft'
       
  1363 			AND meta_key = '_menu_item_orphaned' AND meta_value < %d",
       
  1364 			$delete_timestamp
       
  1365 		)
       
  1366 	);
  1136 
  1367 
  1137 	foreach ( (array) $menu_items_to_delete as $menu_item_id ) {
  1368 	foreach ( (array) $menu_items_to_delete as $menu_item_id ) {
  1138 		wp_delete_post( $menu_item_id, true );
  1369 		wp_delete_post( $menu_item_id, true );
  1139 	}
  1370 	}
  1140 }
  1371 }
  1141 
  1372 
  1142 /**
  1373 /**
  1143  * Saves nav menu items
  1374  * Saves nav menu items.
  1144  *
  1375  *
  1145  * @since 3.6.0
  1376  * @since 3.6.0
  1146  *
  1377  *
  1147  * @param int|string $nav_menu_selected_id    ID, slug, or name of the currently-selected menu.
  1378  * @param int|string $nav_menu_selected_id    ID, slug, or name of the currently-selected menu.
  1148  * @param string     $nav_menu_selected_title Title of the currently-selected menu.
  1379  * @param string     $nav_menu_selected_title Title of the currently-selected menu.
  1149  * @return array The menu updated message
  1380  * @return string[] The menu updated messages.
  1150  */
  1381  */
  1151 function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) {
  1382 function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) {
  1152 	$unsorted_menu_items = wp_get_nav_menu_items(
  1383 	$unsorted_menu_items = wp_get_nav_menu_items(
  1153 		$nav_menu_selected_id,
  1384 		$nav_menu_selected_id,
  1154 		array(
  1385 		array(
  1197 			$args = array();
  1428 			$args = array();
  1198 			foreach ( $post_fields as $field ) {
  1429 			foreach ( $post_fields as $field ) {
  1199 				$args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : '';
  1430 				$args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : '';
  1200 			}
  1431 			}
  1201 
  1432 
  1202 			$menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][ $_key ] != $_key ? 0 : $_key ), $args );
  1433 			$menu_item_db_id = wp_update_nav_menu_item(
       
  1434 				$nav_menu_selected_id,
       
  1435 				( (int) $_POST['menu-item-db-id'][ $_key ] !== $_key ? 0 : $_key ),
       
  1436 				$args
       
  1437 			);
  1203 
  1438 
  1204 			if ( is_wp_error( $menu_item_db_id ) ) {
  1439 			if ( is_wp_error( $menu_item_db_id ) ) {
  1205 				$messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
  1440 				$messages[] = wp_get_admin_notice(
       
  1441 					$menu_item_db_id->get_error_message(),
       
  1442 					array(
       
  1443 						'id'                 => 'message',
       
  1444 						'additional_classes' => array( 'error' ),
       
  1445 					)
       
  1446 				);
  1206 			} else {
  1447 			} else {
  1207 				unset( $menu_items[ $menu_item_db_id ] );
  1448 				unset( $menu_items[ $menu_item_db_id ] );
  1208 			}
  1449 			}
  1209 		}
  1450 		}
  1210 	}
  1451 	}
  1236 			unset( $nav_menu_option['auto_add'][ $key ] );
  1477 			unset( $nav_menu_option['auto_add'][ $key ] );
  1237 		}
  1478 		}
  1238 	}
  1479 	}
  1239 
  1480 
  1240 	// Remove non-existent/deleted menus.
  1481 	// Remove non-existent/deleted menus.
  1241 	$nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
  1482 	$nav_menu_option['auto_add'] = array_intersect(
       
  1483 		$nav_menu_option['auto_add'],
       
  1484 		wp_get_nav_menus( array( 'fields' => 'ids' ) )
       
  1485 	);
       
  1486 
  1242 	update_option( 'nav_menu_options', $nav_menu_option );
  1487 	update_option( 'nav_menu_options', $nav_menu_option );
  1243 
  1488 
  1244 	wp_defer_term_counting( false );
  1489 	wp_defer_term_counting( false );
  1245 
  1490 
  1246 	/** This action is documented in wp-includes/nav-menu.php */
  1491 	/** This action is documented in wp-includes/nav-menu.php */
  1247 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
  1492 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
  1248 
  1493 
  1249 	$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' .
  1494 	/* translators: %s: Nav menu title. */
  1250 		sprintf(
  1495 	$message     = sprintf( __( '%s has been updated.' ), '<strong>' . $nav_menu_selected_title . '</strong>' );
  1251 			/* translators: %s: Nav menu title. */
  1496 	$notice_args = array(
  1252 			__( '%s has been updated.' ),
  1497 		'id'                 => 'message',
  1253 			'<strong>' . $nav_menu_selected_title . '</strong>'
  1498 		'dismissible'        => true,
  1254 		) . '</p></div>';
  1499 		'additional_classes' => array( 'updated' ),
       
  1500 	);
       
  1501 
       
  1502 	$messages[] = wp_get_admin_notice( $message, $notice_args );
  1255 
  1503 
  1256 	unset( $menu_items, $unsorted_menu_items );
  1504 	unset( $menu_items, $unsorted_menu_items );
  1257 
  1505 
  1258 	return $messages;
  1506 	return $messages;
  1259 }
  1507 }
  1273 
  1521 
  1274 	$data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
  1522 	$data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
  1275 
  1523 
  1276 	if ( ! is_null( $data ) && $data ) {
  1524 	if ( ! is_null( $data ) && $data ) {
  1277 		foreach ( $data as $post_input_data ) {
  1525 		foreach ( $data as $post_input_data ) {
  1278 			// For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
  1526 			/*
  1279 			// derive the array path keys via regex and set the value in $_POST.
  1527 			 * For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
       
  1528 			 * derive the array path keys via regex and set the value in $_POST.
       
  1529 			 */
  1280 			preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
  1530 			preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
  1281 
  1531 
  1282 			$array_bits = array( $matches[1] );
  1532 			$array_bits = array( $matches[1] );
  1283 
  1533 
  1284 			if ( isset( $matches[3] ) ) {
  1534 			if ( isset( $matches[3] ) ) {
  1287 
  1537 
  1288 			$new_post_data = array();
  1538 			$new_post_data = array();
  1289 
  1539 
  1290 			// Build the new array value from leaf to trunk.
  1540 			// Build the new array value from leaf to trunk.
  1291 			for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) {
  1541 			for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) {
  1292 				if ( count( $array_bits ) - 1 == $i ) {
  1542 				if ( count( $array_bits ) - 1 === $i ) {
  1293 					$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
  1543 					$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
  1294 				} else {
  1544 				} else {
  1295 					$new_post_data = array( $array_bits[ $i ] => $new_post_data );
  1545 					$new_post_data = array( $array_bits[ $i ] => $new_post_data );
  1296 				}
  1546 				}
  1297 			}
  1547 			}