wp/wp-admin/includes/nav-menu.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     6  * @subpackage Nav_Menus
     6  * @subpackage Nav_Menus
     7  * @since 3.0.0
     7  * @since 3.0.0
     8  */
     8  */
     9 
     9 
    10 /** Walker_Nav_Menu_Edit class */
    10 /** Walker_Nav_Menu_Edit class */
    11 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php' );
    11 require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php';
    12 
    12 
    13 /** Walker_Nav_Menu_Checklist class */
    13 /** Walker_Nav_Menu_Checklist class */
    14 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php' );
    14 require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php';
    15 
    15 
    16 /**
    16 /**
    17  * Prints the appropriate response to a menu quick search.
    17  * Prints the appropriate response to a menu quick search.
    18  *
    18  *
    19  * @since 3.0.0
    19  * @since 3.0.0
    23 function _wp_ajax_menu_quick_search( $request = array() ) {
    23 function _wp_ajax_menu_quick_search( $request = array() ) {
    24 	$args            = array();
    24 	$args            = array();
    25 	$type            = isset( $request['type'] ) ? $request['type'] : '';
    25 	$type            = isset( $request['type'] ) ? $request['type'] : '';
    26 	$object_type     = isset( $request['object_type'] ) ? $request['object_type'] : '';
    26 	$object_type     = isset( $request['object_type'] ) ? $request['object_type'] : '';
    27 	$query           = isset( $request['q'] ) ? $request['q'] : '';
    27 	$query           = isset( $request['q'] ) ? $request['q'] : '';
    28 	$response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json';
    28 	$response_format = isset( $request['response-format'] ) ? $request['response-format'] : '';
    29 
    29 
    30 	if ( 'markup' == $response_format ) {
    30 	if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) {
       
    31 		$response_format = 'json';
       
    32 	}
       
    33 
       
    34 	if ( 'markup' === $response_format ) {
    31 		$args['walker'] = new Walker_Nav_Menu_Checklist;
    35 		$args['walker'] = new Walker_Nav_Menu_Checklist;
    32 	}
    36 	}
    33 
    37 
    34 	if ( 'get-post-item' == $type ) {
    38 	if ( 'get-post-item' === $type ) {
    35 		if ( post_type_exists( $object_type ) ) {
    39 		if ( post_type_exists( $object_type ) ) {
    36 			if ( isset( $request['ID'] ) ) {
    40 			if ( isset( $request['ID'] ) ) {
    37 				$object_id = (int) $request['ID'];
    41 				$object_id = (int) $request['ID'];
    38 				if ( 'markup' == $response_format ) {
    42 				if ( 'markup' === $response_format ) {
    39 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
    43 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
    40 				} elseif ( 'json' == $response_format ) {
    44 				} elseif ( 'json' === $response_format ) {
    41 					echo wp_json_encode(
    45 					echo wp_json_encode(
    42 						array(
    46 						array(
    43 							'ID'         => $object_id,
    47 							'ID'         => $object_id,
    44 							'post_title' => get_the_title( $object_id ),
    48 							'post_title' => get_the_title( $object_id ),
    45 							'post_type'  => get_post_type( $object_id ),
    49 							'post_type'  => get_post_type( $object_id ),
    49 				}
    53 				}
    50 			}
    54 			}
    51 		} elseif ( taxonomy_exists( $object_type ) ) {
    55 		} elseif ( taxonomy_exists( $object_type ) ) {
    52 			if ( isset( $request['ID'] ) ) {
    56 			if ( isset( $request['ID'] ) ) {
    53 				$object_id = (int) $request['ID'];
    57 				$object_id = (int) $request['ID'];
    54 				if ( 'markup' == $response_format ) {
    58 				if ( 'markup' === $response_format ) {
    55 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
    59 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
    56 				} elseif ( 'json' == $response_format ) {
    60 				} elseif ( 'json' === $response_format ) {
    57 					$post_obj = get_term( $object_id, $object_type );
    61 					$post_obj = get_term( $object_id, $object_type );
    58 					echo wp_json_encode(
    62 					echo wp_json_encode(
    59 						array(
    63 						array(
    60 							'ID'         => $object_id,
    64 							'ID'         => $object_id,
    61 							'post_title' => $post_obj->name,
    65 							'post_title' => $post_obj->name,
    65 					echo "\n";
    69 					echo "\n";
    66 				}
    70 				}
    67 			}
    71 			}
    68 		}
    72 		}
    69 	} elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) {
    73 	} elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) {
    70 		if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
    74 		if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) {
    71 			$post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) );
    75 			$post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) );
    72 			$args          = array_merge(
    76 			$args          = array_merge(
    73 				$args,
    77 				$args,
    74 				array(
    78 				array(
    75 					'no_found_rows'          => true,
    79 					'no_found_rows'          => true,
    87 			if ( ! $search_results_query->have_posts() ) {
    91 			if ( ! $search_results_query->have_posts() ) {
    88 				return;
    92 				return;
    89 			}
    93 			}
    90 			while ( $search_results_query->have_posts() ) {
    94 			while ( $search_results_query->have_posts() ) {
    91 				$post = $search_results_query->next_post();
    95 				$post = $search_results_query->next_post();
    92 				if ( 'markup' == $response_format ) {
    96 				if ( 'markup' === $response_format ) {
    93 					$var_by_ref = $post->ID;
    97 					$var_by_ref = $post->ID;
    94 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
    98 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
    95 				} elseif ( 'json' == $response_format ) {
    99 				} elseif ( 'json' === $response_format ) {
    96 					echo wp_json_encode(
   100 					echo wp_json_encode(
    97 						array(
   101 						array(
    98 							'ID'         => $post->ID,
   102 							'ID'         => $post->ID,
    99 							'post_title' => get_the_title( $post->ID ),
   103 							'post_title' => get_the_title( $post->ID ),
   100 							'post_type'  => $matches[2],
   104 							'post_type'  => $matches[2],
   101 						)
   105 						)
   102 					);
   106 					);
   103 					echo "\n";
   107 					echo "\n";
   104 				}
   108 				}
   105 			}
   109 			}
   106 		} elseif ( 'taxonomy' == $matches[1] ) {
   110 		} elseif ( 'taxonomy' === $matches[1] ) {
   107 			$terms = get_terms(
   111 			$terms = get_terms(
   108 				array(
   112 				array(
   109 					'taxonomy'   => $matches[2],
   113 					'taxonomy'   => $matches[2],
   110 					'name__like' => $query,
   114 					'name__like' => $query,
   111 					'number'     => 10,
   115 					'number'     => 10,
       
   116 					'hide_empty' => false,
   112 				)
   117 				)
   113 			);
   118 			);
   114 			if ( empty( $terms ) || is_wp_error( $terms ) ) {
   119 			if ( empty( $terms ) || is_wp_error( $terms ) ) {
   115 				return;
   120 				return;
   116 			}
   121 			}
   117 			foreach ( (array) $terms as $term ) {
   122 			foreach ( (array) $terms as $term ) {
   118 				if ( 'markup' == $response_format ) {
   123 				if ( 'markup' === $response_format ) {
   119 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
   124 					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
   120 				} elseif ( 'json' == $response_format ) {
   125 				} elseif ( 'json' === $response_format ) {
   121 					echo wp_json_encode(
   126 					echo wp_json_encode(
   122 						array(
   127 						array(
   123 							'ID'         => $term->term_id,
   128 							'ID'         => $term->term_id,
   124 							'post_title' => $term->name,
   129 							'post_title' => $term->name,
   125 							'post_type'  => $matches[2],
   130 							'post_type'  => $matches[2],
   136  * Register nav menu meta boxes and advanced menu items.
   141  * Register nav menu meta boxes and advanced menu items.
   137  *
   142  *
   138  * @since 3.0.0
   143  * @since 3.0.0
   139  */
   144  */
   140 function wp_nav_menu_setup() {
   145 function wp_nav_menu_setup() {
   141 	// Register meta boxes
   146 	// Register meta boxes.
   142 	wp_nav_menu_post_type_meta_boxes();
   147 	wp_nav_menu_post_type_meta_boxes();
   143 	add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
   148 	add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
   144 	wp_nav_menu_taxonomy_meta_boxes();
   149 	wp_nav_menu_taxonomy_meta_boxes();
   145 
   150 
   146 	// Register advanced menu items (columns)
   151 	// Register advanced menu items (columns).
   147 	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
   152 	add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
   148 
   153 
   149 	// If first time editing, disable advanced items by default.
   154 	// If first time editing, disable advanced items by default.
   150 	if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
   155 	if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
   151 		$user = wp_get_current_user();
   156 		$user = wp_get_current_user();
   182 	$hidden_meta_boxes  = array();
   187 	$hidden_meta_boxes  = array();
   183 
   188 
   184 	foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) {
   189 	foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) {
   185 		foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) {
   190 		foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) {
   186 			foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) {
   191 			foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) {
   187 				if ( in_array( $box['id'], $initial_meta_boxes ) ) {
   192 				if ( in_array( $box['id'], $initial_meta_boxes, true ) ) {
   188 					unset( $box['id'] );
   193 					unset( $box['id'] );
   189 				} else {
   194 				} else {
   190 					$hidden_meta_boxes[] = $box['id'];
   195 					$hidden_meta_boxes[] = $box['id'];
   191 				}
   196 				}
   192 			}
   197 			}
   217 		 * If a falsey value is returned instead of an object, the menu items
   222 		 * If a falsey value is returned instead of an object, the menu items
   218 		 * meta box for the current meta box object will not be added.
   223 		 * meta box for the current meta box object will not be added.
   219 		 *
   224 		 *
   220 		 * @since 3.0.0
   225 		 * @since 3.0.0
   221 		 *
   226 		 *
   222 		 * @param object $meta_box_object The current object to add a menu items
   227 		 * @param WP_Post_Type|false $post_type The current object to add a menu items
   223 		 *                                meta box for.
   228 		 *                                      meta box for.
   224 		 */
   229 		 */
   225 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
   230 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
   226 		if ( $post_type ) {
   231 		if ( $post_type ) {
   227 			$id = $post_type->name;
   232 			$id = $post_type->name;
   228 			// Give pages a higher priority.
   233 			// Give pages a higher priority.
   229 			$priority = ( 'page' == $post_type->name ? 'core' : 'default' );
   234 			$priority = ( 'page' === $post_type->name ? 'core' : 'default' );
   230 			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 );
   235 			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 );
   231 		}
   236 		}
   232 	}
   237 	}
   233 }
   238 }
   234 
   239 
   253 		}
   258 		}
   254 	}
   259 	}
   255 }
   260 }
   256 
   261 
   257 /**
   262 /**
   258  * Check whether to disable the Menu Locations meta box submit button
   263  * Check whether to disable the Menu Locations meta box submit button and inputs.
   259  *
   264  *
   260  * @since 3.6.0
   265  * @since 3.6.0
       
   266  * @since 5.3.1 The `$echo` parameter was added.
   261  *
   267  *
   262  * @global bool $one_theme_location_no_menus to determine if no menus exist
   268  * @global bool $one_theme_location_no_menus to determine if no menus exist
   263  *
   269  *
   264  * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu
   270  * @param int|string $nav_menu_selected_id ID, name, or slug of the currently selected menu.
   265  * @return string Disabled attribute if at least one menu exists, false if not
   271  * @param bool       $echo                 Whether to echo or just return the string.
   266  */
   272  * @return string|false Disabled attribute if at least one menu exists, false if not.
   267 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) {
   273  */
       
   274 function wp_nav_menu_disabled_check( $nav_menu_selected_id, $echo = true ) {
   268 	global $one_theme_location_no_menus;
   275 	global $one_theme_location_no_menus;
   269 
   276 
   270 	if ( $one_theme_location_no_menus ) {
   277 	if ( $one_theme_location_no_menus ) {
   271 		return false;
   278 		return false;
   272 	}
   279 	}
   273 
   280 
   274 	return disabled( $nav_menu_selected_id, 0 );
   281 	return disabled( $nav_menu_selected_id, 0, $echo );
   275 }
   282 }
   276 
   283 
   277 /**
   284 /**
   278  * Displays a meta box for the custom links menu item.
   285  * Displays a meta box for the custom links menu item.
   279  *
   286  *
   290 	?>
   297 	?>
   291 	<div class="customlinkdiv" id="customlinkdiv">
   298 	<div class="customlinkdiv" id="customlinkdiv">
   292 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
   299 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
   293 		<p id="menu-item-url-wrap" class="wp-clearfix">
   300 		<p id="menu-item-url-wrap" class="wp-clearfix">
   294 			<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
   301 			<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
   295 			<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://" />
   302 			<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" placeholder="https://" />
   296 		</p>
   303 		</p>
   297 
   304 
   298 		<p id="menu-item-name-wrap" class="wp-clearfix">
   305 		<p id="menu-item-name-wrap" class="wp-clearfix">
   299 			<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
   306 			<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
   300 			<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" />
   307 			<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" />
   301 		</p>
   308 		</p>
   302 
   309 
   303 		<p class="button-controls wp-clearfix">
   310 		<p class="button-controls wp-clearfix">
   304 			<span class="add-to-menu">
   311 			<span class="add-to-menu">
   305 				<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" />
   312 				<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" />
   323  * @param array  $box {
   330  * @param array  $box {
   324  *     Post type menu item meta box arguments.
   331  *     Post type menu item meta box arguments.
   325  *
   332  *
   326  *     @type string       $id       Meta box 'id' attribute.
   333  *     @type string       $id       Meta box 'id' attribute.
   327  *     @type string       $title    Meta box title.
   334  *     @type string       $title    Meta box title.
   328  *     @type string       $callback Meta box display callback.
   335  *     @type callable     $callback Meta box display callback.
   329  *     @type WP_Post_Type $args     Extra meta box arguments (the post type object for this meta box).
   336  *     @type WP_Post_Type $args     Extra meta box arguments (the post type object for this meta box).
   330  * }
   337  * }
   331  */
   338  */
   332 function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
   339 function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
   333 	global $_nav_menu_placeholder, $nav_menu_selected_id;
   340 	global $_nav_menu_placeholder, $nav_menu_selected_id;
   334 
   341 
   335 	$post_type_name = $box['args']->name;
   342 	$post_type_name = $box['args']->name;
       
   343 	$post_type      = get_post_type_object( $post_type_name );
       
   344 	$tab_name       = $post_type_name . '-tab';
   336 
   345 
   337 	// Paginate browsing for large numbers of post objects.
   346 	// Paginate browsing for large numbers of post objects.
   338 	$per_page = 50;
   347 	$per_page = 50;
   339 	$pagenum  = isset( $_REQUEST[ $post_type_name . '-tab' ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   348 	$pagenum  = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   340 	$offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   349 	$offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   341 
   350 
   342 	$args = array(
   351 	$args = array(
   343 		'offset'                 => $offset,
   352 		'offset'                 => $offset,
   344 		'order'                  => 'ASC',
   353 		'order'                  => 'ASC',
   352 
   361 
   353 	if ( isset( $box['args']->_default_query ) ) {
   362 	if ( isset( $box['args']->_default_query ) ) {
   354 		$args = array_merge( $args, (array) $box['args']->_default_query );
   363 		$args = array_merge( $args, (array) $box['args']->_default_query );
   355 	}
   364 	}
   356 
   365 
   357 	// @todo transient caching of these results with proper invalidation on updating of a post of this type
   366 	/*
       
   367 	 * If we're dealing with pages, let's prioritize the Front Page,
       
   368 	 * Posts Page and Privacy Policy Page at the top of the list.
       
   369 	 */
       
   370 	$important_pages = array();
       
   371 	if ( 'page' === $post_type_name ) {
       
   372 		$suppress_page_ids = array();
       
   373 
       
   374 		// Insert Front Page or custom Home link.
       
   375 		$front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
       
   376 
       
   377 		$front_page_obj = null;
       
   378 		if ( ! empty( $front_page ) ) {
       
   379 			$front_page_obj                = get_post( $front_page );
       
   380 			$front_page_obj->front_or_home = true;
       
   381 
       
   382 			$important_pages[]   = $front_page_obj;
       
   383 			$suppress_page_ids[] = $front_page_obj->ID;
       
   384 		} else {
       
   385 			$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
       
   386 			$front_page_obj        = (object) array(
       
   387 				'front_or_home' => true,
       
   388 				'ID'            => 0,
       
   389 				'object_id'     => $_nav_menu_placeholder,
       
   390 				'post_content'  => '',
       
   391 				'post_excerpt'  => '',
       
   392 				'post_parent'   => '',
       
   393 				'post_title'    => _x( 'Home', 'nav menu home label' ),
       
   394 				'post_type'     => 'nav_menu_item',
       
   395 				'type'          => 'custom',
       
   396 				'url'           => home_url( '/' ),
       
   397 			);
       
   398 
       
   399 			$important_pages[] = $front_page_obj;
       
   400 		}
       
   401 
       
   402 		// Insert Posts Page.
       
   403 		$posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0;
       
   404 
       
   405 		if ( ! empty( $posts_page ) ) {
       
   406 			$posts_page_obj             = get_post( $posts_page );
       
   407 			$posts_page_obj->posts_page = true;
       
   408 
       
   409 			$important_pages[]   = $posts_page_obj;
       
   410 			$suppress_page_ids[] = $posts_page_obj->ID;
       
   411 		}
       
   412 
       
   413 		// Insert Privacy Policy Page.
       
   414 		$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
       
   415 
       
   416 		if ( ! empty( $privacy_policy_page_id ) ) {
       
   417 			$privacy_policy_page = get_post( $privacy_policy_page_id );
       
   418 			if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) {
       
   419 				$privacy_policy_page->privacy_policy_page = true;
       
   420 
       
   421 				$important_pages[]   = $privacy_policy_page;
       
   422 				$suppress_page_ids[] = $privacy_policy_page->ID;
       
   423 			}
       
   424 		}
       
   425 
       
   426 		// Add suppression array to arguments for WP_Query.
       
   427 		if ( ! empty( $suppress_page_ids ) ) {
       
   428 			$args['post__not_in'] = $suppress_page_ids;
       
   429 		}
       
   430 	}
       
   431 
       
   432 	// @todo Transient caching of these results with proper invalidation on updating of a post of this type.
   358 	$get_posts = new WP_Query;
   433 	$get_posts = new WP_Query;
   359 	$posts     = $get_posts->query( $args );
   434 	$posts     = $get_posts->query( $args );
       
   435 
       
   436 	// Only suppress and insert when more than just suppression pages available.
   360 	if ( ! $get_posts->post_count ) {
   437 	if ( ! $get_posts->post_count ) {
   361 		echo '<p>' . __( 'No items.' ) . '</p>';
   438 		if ( ! empty( $suppress_page_ids ) ) {
   362 		return;
   439 			unset( $args['post__not_in'] );
       
   440 			$get_posts = new WP_Query;
       
   441 			$posts     = $get_posts->query( $args );
       
   442 		} else {
       
   443 			echo '<p>' . __( 'No items.' ) . '</p>';
       
   444 			return;
       
   445 		}
       
   446 	} elseif ( ! empty( $important_pages ) ) {
       
   447 		$posts = array_merge( $important_pages, $posts );
   363 	}
   448 	}
   364 
   449 
   365 	$num_pages = $get_posts->max_num_pages;
   450 	$num_pages = $get_posts->max_num_pages;
   366 
   451 
   367 	$page_links = paginate_links(
   452 	$page_links = paginate_links(
   368 		array(
   453 		array(
   369 			'base'               => add_query_arg(
   454 			'base'               => add_query_arg(
   370 				array(
   455 				array(
   371 					$post_type_name . '-tab' => 'all',
   456 					$tab_name     => 'all',
   372 					'paged'                  => '%#%',
   457 					'paged'       => '%#%',
   373 					'item-type'              => 'post_type',
   458 					'item-type'   => 'post_type',
   374 					'item-object'            => $post_type_name,
   459 					'item-object' => $post_type_name,
   375 				)
   460 				)
   376 			),
   461 			),
   377 			'format'             => '',
   462 			'format'             => '',
   378 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   463 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   379 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   464 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   392 	}
   477 	}
   393 
   478 
   394 	$walker = new Walker_Nav_Menu_Checklist( $db_fields );
   479 	$walker = new Walker_Nav_Menu_Checklist( $db_fields );
   395 
   480 
   396 	$current_tab = 'most-recent';
   481 	$current_tab = 'most-recent';
   397 	if ( isset( $_REQUEST[ $post_type_name . '-tab' ] ) && in_array( $_REQUEST[ $post_type_name . '-tab' ], array( 'all', 'search' ) ) ) {
   482 
   398 		$current_tab = $_REQUEST[ $post_type_name . '-tab' ];
   483 	if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) {
       
   484 		$current_tab = $_REQUEST[ $tab_name ];
   399 	}
   485 	}
   400 
   486 
   401 	if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
   487 	if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
   402 		$current_tab = 'search';
   488 		$current_tab = 'search';
   403 	}
   489 	}
   409 		'menu-item',
   495 		'menu-item',
   410 		'page-tab',
   496 		'page-tab',
   411 		'_wpnonce',
   497 		'_wpnonce',
   412 	);
   498 	);
   413 
   499 
   414 	$most_recent_url = $view_all_url = $search_url = '';
   500 	$most_recent_url = '';
       
   501 	$view_all_url    = '';
       
   502 	$search_url      = '';
   415 	if ( $nav_menu_selected_id ) {
   503 	if ( $nav_menu_selected_id ) {
   416 		$most_recent_url = esc_url( add_query_arg( $post_type_name . '-tab', 'most-recent', remove_query_arg( $removed_args ) ) );
   504 		$most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) );
   417 		$view_all_url    = esc_url( add_query_arg( $post_type_name . '-tab', 'all', remove_query_arg( $removed_args ) ) );
   505 		$view_all_url    = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
   418 		$search_url      = esc_url( add_query_arg( $post_type_name . '-tab', 'search', remove_query_arg( $removed_args ) ) );
   506 		$search_url      = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
   419 	}
   507 	}
   420 	?>
   508 	?>
   421 	<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
   509 	<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
   422 		<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
   510 		<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
   423 			<li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>>
   511 			<li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>>
   424 				<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">
   512 				<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">
   425 					<?php _e( 'Most Recent' ); ?>
   513 					<?php _e( 'Most Recent' ); ?>
   426 				</a>
   514 				</a>
   427 			</li>
   515 			</li>
   428 			<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
   516 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
   429 				<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">
   517 				<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">
   430 					<?php _e( 'View All' ); ?>
   518 					<?php _e( 'View All' ); ?>
   431 				</a>
   519 				</a>
   432 			</li>
   520 			</li>
   433 			<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
   521 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
   434 				<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">
   522 				<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">
   435 					<?php _e( 'Search' ); ?>
   523 					<?php _e( 'Search' ); ?>
   436 				</a>
   524 				</a>
   437 			</li>
   525 			</li>
   438 		</ul><!-- .posttype-tabs -->
   526 		</ul><!-- .posttype-tabs -->
   439 
   527 
   440 		<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' ); ?>">
   528 		<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">
   441 			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
   529 			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
   442 				<?php
   530 				<?php
   443 				$recent_args    = array_merge(
   531 				$recent_args    = array_merge(
   444 					$args,
   532 					$args,
   445 					array(
   533 					array(
   470 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args );
   558 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args );
   471 				?>
   559 				?>
   472 			</ul>
   560 			</ul>
   473 		</div><!-- /.tabs-panel -->
   561 		</div><!-- /.tabs-panel -->
   474 
   562 
   475 		<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">
   563 		<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">
   476 			<?php
   564 			<?php
   477 			if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
   565 			if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
   478 				$searched       = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] );
   566 				$searched       = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] );
   479 				$search_results = get_posts(
   567 				$search_results = get_posts(
   480 					array(
   568 					array(
   489 				$search_results = array();
   577 				$search_results = array();
   490 			}
   578 			}
   491 			?>
   579 			?>
   492 			<p class="quick-search-wrap">
   580 			<p class="quick-search-wrap">
   493 				<label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
   581 				<label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
   494 				<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; ?>" />
   582 				<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; ?>" />
   495 				<span class="spinner"></span>
   583 				<span class="spinner"></span>
   496 				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
   584 				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
   497 			</p>
   585 			</p>
   498 
   586 
   499 			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
   587 			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
   508 				<li><?php _e( 'No results found.' ); ?></li>
   596 				<li><?php _e( 'No results found.' ); ?></li>
   509 			<?php endif; ?>
   597 			<?php endif; ?>
   510 			</ul>
   598 			</ul>
   511 		</div><!-- /.tabs-panel -->
   599 		</div><!-- /.tabs-panel -->
   512 
   600 
   513 		<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' ); ?>">
   601 		<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">
   514 			<?php if ( ! empty( $page_links ) ) : ?>
   602 			<?php if ( ! empty( $page_links ) ) : ?>
   515 				<div class="add-menu-item-pagelinks">
   603 				<div class="add-menu-item-pagelinks">
   516 					<?php echo $page_links; ?>
   604 					<?php echo $page_links; ?>
   517 				</div>
   605 				</div>
   518 			<?php endif; ?>
   606 			<?php endif; ?>
   519 			<ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
   607 			<ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
   520 				<?php
   608 				<?php
   521 				$args['walker'] = $walker;
   609 				$args['walker'] = $walker;
   522 
       
   523 				/*
       
   524 				 * If we're dealing with pages, let's put a checkbox for the front
       
   525 				 * page at the top of the list.
       
   526 				 */
       
   527 				if ( 'page' == $post_type_name ) {
       
   528 					$front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
       
   529 					if ( ! empty( $front_page ) ) {
       
   530 						$front_page_obj                = get_post( $front_page );
       
   531 						$front_page_obj->front_or_home = true;
       
   532 						array_unshift( $posts, $front_page_obj );
       
   533 					} else {
       
   534 						$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
       
   535 						array_unshift(
       
   536 							$posts,
       
   537 							(object) array(
       
   538 								'front_or_home' => true,
       
   539 								'ID'            => 0,
       
   540 								'object_id'     => $_nav_menu_placeholder,
       
   541 								'post_content'  => '',
       
   542 								'post_excerpt'  => '',
       
   543 								'post_parent'   => '',
       
   544 								'post_title'    => _x( 'Home', 'nav menu home label' ),
       
   545 								'post_type'     => 'nav_menu_item',
       
   546 								'type'          => 'custom',
       
   547 								'url'           => home_url( '/' ),
       
   548 							)
       
   549 						);
       
   550 					}
       
   551 				}
       
   552 
       
   553 				$post_type = get_post_type_object( $post_type_name );
       
   554 
   610 
   555 				if ( $post_type->has_archive ) {
   611 				if ( $post_type->has_archive ) {
   556 					$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
   612 					$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
   557 					array_unshift(
   613 					array_unshift(
   558 						$posts,
   614 						$posts,
   589 				 */
   645 				 */
   590 				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
   646 				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
   591 
   647 
   592 				$checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args );
   648 				$checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args );
   593 
   649 
   594 				if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
       
   595 					$checkbox_items = preg_replace( '/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items );
       
   596 
       
   597 				}
       
   598 
       
   599 				echo $checkbox_items;
   650 				echo $checkbox_items;
   600 				?>
   651 				?>
   601 			</ul>
   652 			</ul>
   602 			<?php if ( ! empty( $page_links ) ) : ?>
   653 			<?php if ( ! empty( $page_links ) ) : ?>
   603 				<div class="add-menu-item-pagelinks">
   654 				<div class="add-menu-item-pagelinks">
   604 					<?php echo $page_links; ?>
   655 					<?php echo $page_links; ?>
   605 				</div>
   656 				</div>
   606 			<?php endif; ?>
   657 			<?php endif; ?>
   607 		</div><!-- /.tabs-panel -->
   658 		</div><!-- /.tabs-panel -->
   608 
   659 
   609 		<p class="button-controls wp-clearfix">
   660 		<p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
   610 			<span class="list-controls">
   661 			<span class="list-controls hide-if-no-js">
   611 				<a href="
   662 				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
   612 				<?php
   663 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
   613 					echo esc_url(
       
   614 						add_query_arg(
       
   615 							array(
       
   616 								$post_type_name . '-tab' => 'all',
       
   617 								'selectall'              => 1,
       
   618 							),
       
   619 							remove_query_arg( $removed_args )
       
   620 						)
       
   621 					);
       
   622 				?>
       
   623 				#posttype-<?php echo $post_type_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a>
       
   624 			</span>
   664 			</span>
   625 
   665 
   626 			<span class="add-to-menu">
   666 			<span class="add-to-menu">
   627 				<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 ); ?>" />
   667 				<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 ); ?>" />
   628 				<span class="spinner"></span>
   668 				<span class="spinner"></span>
   642  *
   682  *
   643  * @param string $object Not used.
   683  * @param string $object Not used.
   644  * @param array  $box {
   684  * @param array  $box {
   645  *     Taxonomy menu item meta box arguments.
   685  *     Taxonomy menu item meta box arguments.
   646  *
   686  *
   647  *     @type string $id       Meta box 'id' attribute.
   687  *     @type string   $id       Meta box 'id' attribute.
   648  *     @type string $title    Meta box title.
   688  *     @type string   $title    Meta box title.
   649  *     @type string $callback Meta box display callback.
   689  *     @type callable $callback Meta box display callback.
   650  *     @type object $args     Extra meta box arguments (the taxonomy object for this meta box).
   690  *     @type object   $args     Extra meta box arguments (the taxonomy object for this meta box).
   651  * }
   691  * }
   652  */
   692  */
   653 function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
   693 function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
   654 	global $nav_menu_selected_id;
   694 	global $nav_menu_selected_id;
       
   695 
   655 	$taxonomy_name = $box['args']->name;
   696 	$taxonomy_name = $box['args']->name;
   656 	$taxonomy      = get_taxonomy( $taxonomy_name );
   697 	$taxonomy      = get_taxonomy( $taxonomy_name );
       
   698 	$tab_name      = $taxonomy_name . '-tab';
   657 
   699 
   658 	// Paginate browsing for large numbers of objects.
   700 	// Paginate browsing for large numbers of objects.
   659 	$per_page = 50;
   701 	$per_page = 50;
   660 	$pagenum  = isset( $_REQUEST[ $taxonomy_name . '-tab' ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   702 	$pagenum  = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
   661 	$offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   703 	$offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
   662 
   704 
   663 	$args = array(
   705 	$args = array(
       
   706 		'taxonomy'     => $taxonomy_name,
   664 		'child_of'     => 0,
   707 		'child_of'     => 0,
   665 		'exclude'      => '',
   708 		'exclude'      => '',
   666 		'hide_empty'   => false,
   709 		'hide_empty'   => false,
   667 		'hierarchical' => 1,
   710 		'hierarchical' => 1,
   668 		'include'      => '',
   711 		'include'      => '',
   671 		'order'        => 'ASC',
   714 		'order'        => 'ASC',
   672 		'orderby'      => 'name',
   715 		'orderby'      => 'name',
   673 		'pad_counts'   => false,
   716 		'pad_counts'   => false,
   674 	);
   717 	);
   675 
   718 
   676 	$terms = get_terms( $taxonomy_name, $args );
   719 	$terms = get_terms( $args );
   677 
   720 
   678 	if ( ! $terms || is_wp_error( $terms ) ) {
   721 	if ( ! $terms || is_wp_error( $terms ) ) {
   679 		echo '<p>' . __( 'No items.' ) . '</p>';
   722 		echo '<p>' . __( 'No items.' ) . '</p>';
   680 		return;
   723 		return;
   681 	}
   724 	}
   695 
   738 
   696 	$page_links = paginate_links(
   739 	$page_links = paginate_links(
   697 		array(
   740 		array(
   698 			'base'               => add_query_arg(
   741 			'base'               => add_query_arg(
   699 				array(
   742 				array(
   700 					$taxonomy_name . '-tab' => 'all',
   743 					$tab_name     => 'all',
   701 					'paged'                 => '%#%',
   744 					'paged'       => '%#%',
   702 					'item-type'             => 'taxonomy',
   745 					'item-type'   => 'taxonomy',
   703 					'item-object'           => $taxonomy_name,
   746 					'item-object' => $taxonomy_name,
   704 				)
   747 				)
   705 			),
   748 			),
   706 			'format'             => '',
   749 			'format'             => '',
   707 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   750 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
   708 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   751 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
   721 	}
   764 	}
   722 
   765 
   723 	$walker = new Walker_Nav_Menu_Checklist( $db_fields );
   766 	$walker = new Walker_Nav_Menu_Checklist( $db_fields );
   724 
   767 
   725 	$current_tab = 'most-used';
   768 	$current_tab = 'most-used';
   726 	if ( isset( $_REQUEST[ $taxonomy_name . '-tab' ] ) && in_array( $_REQUEST[ $taxonomy_name . '-tab' ], array( 'all', 'most-used', 'search' ) ) ) {
   769 
   727 		$current_tab = $_REQUEST[ $taxonomy_name . '-tab' ];
   770 	if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) {
       
   771 		$current_tab = $_REQUEST[ $tab_name ];
   728 	}
   772 	}
   729 
   773 
   730 	if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
   774 	if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
   731 		$current_tab = 'search';
   775 		$current_tab = 'search';
   732 	}
   776 	}
   738 		'menu-item',
   782 		'menu-item',
   739 		'page-tab',
   783 		'page-tab',
   740 		'_wpnonce',
   784 		'_wpnonce',
   741 	);
   785 	);
   742 
   786 
   743 	$most_used_url = $view_all_url = $search_url = '';
   787 	$most_used_url = '';
       
   788 	$view_all_url  = '';
       
   789 	$search_url    = '';
   744 	if ( $nav_menu_selected_id ) {
   790 	if ( $nav_menu_selected_id ) {
   745 		$most_used_url = esc_url( add_query_arg( $taxonomy_name . '-tab', 'most-used', remove_query_arg( $removed_args ) ) );
   791 		$most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) );
   746 		$view_all_url  = esc_url( add_query_arg( $taxonomy_name . '-tab', 'all', remove_query_arg( $removed_args ) ) );
   792 		$view_all_url  = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
   747 		$search_url    = esc_url( add_query_arg( $taxonomy_name . '-tab', 'search', remove_query_arg( $removed_args ) ) );
   793 		$search_url    = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
   748 	}
   794 	}
   749 	?>
   795 	?>
   750 	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
   796 	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
   751 		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
   797 		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
   752 			<li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>>
   798 			<li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>>
   753 				<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">
   799 				<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">
   754 					<?php echo esc_html( $taxonomy->labels->most_used ); ?>
   800 					<?php echo esc_html( $taxonomy->labels->most_used ); ?>
   755 				</a>
   801 				</a>
   756 			</li>
   802 			</li>
   757 			<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
   803 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
   758 				<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">
   804 				<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">
   759 					<?php _e( 'View All' ); ?>
   805 					<?php _e( 'View All' ); ?>
   760 				</a>
   806 				</a>
   761 			</li>
   807 			</li>
   762 			<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
   808 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
   763 				<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; ?>">
   809 				<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; ?>">
   764 					<?php _e( 'Search' ); ?>
   810 					<?php _e( 'Search' ); ?>
   765 				</a>
   811 				</a>
   766 			</li>
   812 			</li>
   767 		</ul><!-- .taxonomy-tabs -->
   813 		</ul><!-- .taxonomy-tabs -->
   768 
   814 
   769 		<div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?> ">
   815 		<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">
   770 			<ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
   816 			<ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
   771 				<?php
   817 				<?php
   772 				$popular_terms  = get_terms(
   818 				$popular_terms  = get_terms(
   773 					$taxonomy_name,
       
   774 					array(
   819 					array(
       
   820 						'taxonomy'     => $taxonomy_name,
   775 						'orderby'      => 'count',
   821 						'orderby'      => 'count',
   776 						'order'        => 'DESC',
   822 						'order'        => 'DESC',
   777 						'number'       => 10,
   823 						'number'       => 10,
   778 						'hierarchical' => false,
   824 						'hierarchical' => false,
   779 					)
   825 					)
   782 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args );
   828 				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args );
   783 				?>
   829 				?>
   784 			</ul>
   830 			</ul>
   785 		</div><!-- /.tabs-panel -->
   831 		</div><!-- /.tabs-panel -->
   786 
   832 
   787 		<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' ); ?> ">
   833 		<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">
   788 			<?php if ( ! empty( $page_links ) ) : ?>
   834 			<?php if ( ! empty( $page_links ) ) : ?>
   789 				<div class="add-menu-item-pagelinks">
   835 				<div class="add-menu-item-pagelinks">
   790 					<?php echo $page_links; ?>
   836 					<?php echo $page_links; ?>
   791 				</div>
   837 				</div>
   792 			<?php endif; ?>
   838 			<?php endif; ?>
   801 					<?php echo $page_links; ?>
   847 					<?php echo $page_links; ?>
   802 				</div>
   848 				</div>
   803 			<?php endif; ?>
   849 			<?php endif; ?>
   804 		</div><!-- /.tabs-panel -->
   850 		</div><!-- /.tabs-panel -->
   805 
   851 
   806 		<div class="tabs-panel <?php echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>">
   852 		<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">
   807 			<?php
   853 			<?php
   808 			if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
   854 			if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
   809 				$searched       = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] );
   855 				$searched       = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] );
   810 				$search_results = get_terms(
   856 				$search_results = get_terms(
   811 					$taxonomy_name,
       
   812 					array(
   857 					array(
       
   858 						'taxonomy'     => $taxonomy_name,
   813 						'name__like'   => $searched,
   859 						'name__like'   => $searched,
   814 						'fields'       => 'all',
   860 						'fields'       => 'all',
   815 						'orderby'      => 'count',
   861 						'orderby'      => 'count',
   816 						'order'        => 'DESC',
   862 						'order'        => 'DESC',
   817 						'hierarchical' => false,
   863 						'hierarchical' => false,
   841 				<li><?php _e( 'No results found.' ); ?></li>
   887 				<li><?php _e( 'No results found.' ); ?></li>
   842 			<?php endif; ?>
   888 			<?php endif; ?>
   843 			</ul>
   889 			</ul>
   844 		</div><!-- /.tabs-panel -->
   890 		</div><!-- /.tabs-panel -->
   845 
   891 
   846 		<p class="button-controls wp-clearfix">
   892 		<p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
   847 			<span class="list-controls">
   893 			<span class="list-controls hide-if-no-js">
   848 				<a href="
   894 				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
   849 				<?php
   895 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
   850 					echo esc_url(
       
   851 						add_query_arg(
       
   852 							array(
       
   853 								$taxonomy_name . '-tab' => 'all',
       
   854 								'selectall'             => 1,
       
   855 							),
       
   856 							remove_query_arg( $removed_args )
       
   857 						)
       
   858 					);
       
   859 				?>
       
   860 				#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a>
       
   861 			</span>
   896 			</span>
   862 
   897 
   863 			<span class="add-to-menu">
   898 			<span class="add-to-menu">
   864 				<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 ); ?>" />
   899 				<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 ); ?>" />
   865 				<span class="spinner"></span>
   900 				<span class="spinner"></span>
   892 				empty( $_item_object_data['menu-item-object-id'] ) &&
   927 				empty( $_item_object_data['menu-item-object-id'] ) &&
   893 				(
   928 				(
   894 					// And item type either isn't set.
   929 					// And item type either isn't set.
   895 					! isset( $_item_object_data['menu-item-type'] ) ||
   930 					! isset( $_item_object_data['menu-item-type'] ) ||
   896 					// Or URL is the default.
   931 					// Or URL is the default.
   897 					in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) ||
   932 					in_array( $_item_object_data['menu-item-url'], array( 'https://', 'http://', '' ), true ) ||
   898 					! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page)
   933 					// Or it's not a custom menu item (but not the custom home page).
       
   934 					! ( 'custom' === $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) ||
   899 					// Or it *is* a custom menu item that already exists.
   935 					// Or it *is* a custom menu item that already exists.
   900 					! empty( $_item_object_data['menu-item-db-id'] )
   936 					! empty( $_item_object_data['menu-item-db-id'] )
   901 				)
   937 				)
   902 			) {
   938 			) {
   903 				// Then this potential menu item is not getting added to this menu.
   939 				// Then this potential menu item is not getting added to this menu.
   944  * @since 3.0.0
   980  * @since 3.0.0
   945  *
   981  *
   946  * @access private
   982  * @access private
   947  *
   983  *
   948  * @param object $object The post type or taxonomy meta-object.
   984  * @param object $object The post type or taxonomy meta-object.
   949  * @return object The post type of taxonomy object.
   985  * @return object The post type or taxonomy object.
   950  */
   986  */
   951 function _wp_nav_menu_meta_box_object( $object = null ) {
   987 function _wp_nav_menu_meta_box_object( $object = null ) {
   952 	if ( isset( $object->name ) ) {
   988 	if ( isset( $object->name ) ) {
   953 
   989 
   954 		if ( 'page' == $object->name ) {
   990 		if ( 'page' === $object->name ) {
   955 			$object->_default_query = array(
   991 			$object->_default_query = array(
   956 				'orderby'     => 'menu_order title',
   992 				'orderby'     => 'menu_order title',
   957 				'post_status' => 'publish',
   993 				'post_status' => 'publish',
   958 			);
   994 			);
   959 
   995 
   960 			// Posts should show only published items.
   996 			// Posts should show only published items.
   961 		} elseif ( 'post' == $object->name ) {
   997 		} elseif ( 'post' === $object->name ) {
   962 			$object->_default_query = array(
   998 			$object->_default_query = array(
   963 				'post_status' => 'publish',
   999 				'post_status' => 'publish',
   964 			);
  1000 			);
   965 
  1001 
   966 			// Categories should be in reverse chronological order.
  1002 			// Categories should be in reverse chronological order.
   967 		} elseif ( 'category' == $object->name ) {
  1003 		} elseif ( 'category' === $object->name ) {
   968 			$object->_default_query = array(
  1004 			$object->_default_query = array(
   969 				'orderby' => 'id',
  1005 				'orderby' => 'id',
   970 				'order'   => 'DESC',
  1006 				'order'   => 'DESC',
   971 			);
  1007 			);
   972 
  1008 
   985  * Returns the menu formatted to edit.
  1021  * Returns the menu formatted to edit.
   986  *
  1022  *
   987  * @since 3.0.0
  1023  * @since 3.0.0
   988  *
  1024  *
   989  * @param int $menu_id Optional. The ID of the menu to format. Default 0.
  1025  * @param int $menu_id Optional. The ID of the menu to format. Default 0.
   990  * @return string|WP_Error $output The menu formatted to edit or error object on failure.
  1026  * @return string|WP_Error The menu formatted to edit or error object on failure.
   991  */
  1027  */
   992 function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
  1028 function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
   993 	$menu = wp_get_nav_menu_object( $menu_id );
  1029 	$menu = wp_get_nav_menu_object( $menu_id );
   994 
  1030 
   995 	// If the menu exists, get its items.
  1031 	// If the menu exists, get its items.
  1017 		if ( class_exists( $walker_class_name ) ) {
  1053 		if ( class_exists( $walker_class_name ) ) {
  1018 			$walker = new $walker_class_name;
  1054 			$walker = new $walker_class_name;
  1019 		} else {
  1055 		} else {
  1020 			return new WP_Error(
  1056 			return new WP_Error(
  1021 				'menu_walker_not_exist',
  1057 				'menu_walker_not_exist',
  1022 				/* translators: %s: walker class name */
       
  1023 				sprintf(
  1058 				sprintf(
       
  1059 					/* translators: %s: Walker class name. */
  1024 					__( 'The Walker class named %s does not exist.' ),
  1060 					__( 'The Walker class named %s does not exist.' ),
  1025 					'<strong>' . $walker_class_name . '</strong>'
  1061 					'<strong>' . $walker_class_name . '</strong>'
  1026 				)
  1062 				)
  1027 			);
  1063 			);
  1028 		}
  1064 		}
  1029 
  1065 
  1030 		$some_pending_menu_items = $some_invalid_menu_items = false;
  1066 		$some_pending_menu_items = false;
       
  1067 		$some_invalid_menu_items = false;
  1031 		foreach ( (array) $menu_items as $menu_item ) {
  1068 		foreach ( (array) $menu_items as $menu_item ) {
  1032 			if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) {
  1069 			if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
  1033 				$some_pending_menu_items = true;
  1070 				$some_pending_menu_items = true;
  1034 			}
  1071 			}
  1035 			if ( ! empty( $menu_item->_invalid ) ) {
  1072 			if ( ! empty( $menu_item->_invalid ) ) {
  1036 				$some_invalid_menu_items = true;
  1073 				$some_invalid_menu_items = true;
  1037 			}
  1074 			}
  1058 /**
  1095 /**
  1059  * Returns the columns for the nav menus page.
  1096  * Returns the columns for the nav menus page.
  1060  *
  1097  *
  1061  * @since 3.0.0
  1098  * @since 3.0.0
  1062  *
  1099  *
  1063  * @return array Columns.
  1100  * @return string[] Array of column titles keyed by their column name.
  1064  */
  1101  */
  1065 function wp_nav_menu_manage_columns() {
  1102 function wp_nav_menu_manage_columns() {
  1066 	return array(
  1103 	return array(
  1067 		'_title'          => __( 'Show advanced menu properties' ),
  1104 		'_title'          => __( 'Show advanced menu properties' ),
  1068 		'cb'              => '<input type="checkbox" />',
  1105 		'cb'              => '<input type="checkbox" />',
  1097 /**
  1134 /**
  1098  * Saves nav menu items
  1135  * Saves nav menu items
  1099  *
  1136  *
  1100  * @since 3.6.0
  1137  * @since 3.6.0
  1101  *
  1138  *
  1102  * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu
  1139  * @param int|string $nav_menu_selected_id    ID, slug, or name of the currently-selected menu.
  1103  * @param string $nav_menu_selected_title Title of the currently-selected menu
  1140  * @param string     $nav_menu_selected_title Title of the currently-selected menu.
  1104  * @return array $messages The menu updated message
  1141  * @return array The menu updated message
  1105  */
  1142  */
  1106 function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) {
  1143 function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) {
  1107 	$unsorted_menu_items = wp_get_nav_menu_items(
  1144 	$unsorted_menu_items = wp_get_nav_menu_items(
  1108 		$nav_menu_selected_id,
  1145 		$nav_menu_selected_id,
  1109 		array(
  1146 		array(
  1111 			'output'      => ARRAY_A,
  1148 			'output'      => ARRAY_A,
  1112 			'output_key'  => 'ID',
  1149 			'output_key'  => 'ID',
  1113 			'post_status' => 'draft,publish',
  1150 			'post_status' => 'draft,publish',
  1114 		)
  1151 		)
  1115 	);
  1152 	);
  1116 	$messages            = array();
  1153 
  1117 	$menu_items          = array();
  1154 	$messages   = array();
  1118 	// Index menu items by db ID
  1155 	$menu_items = array();
       
  1156 
       
  1157 	// Index menu items by DB ID.
  1119 	foreach ( $unsorted_menu_items as $_item ) {
  1158 	foreach ( $unsorted_menu_items as $_item ) {
  1120 		$menu_items[ $_item->db_id ] = $_item;
  1159 		$menu_items[ $_item->db_id ] = $_item;
  1121 	}
  1160 	}
  1122 
  1161 
  1123 	$post_fields = array(
  1162 	$post_fields = array(
  1135 		'menu-item-classes',
  1174 		'menu-item-classes',
  1136 		'menu-item-xfn',
  1175 		'menu-item-xfn',
  1137 	);
  1176 	);
  1138 
  1177 
  1139 	wp_defer_term_counting( true );
  1178 	wp_defer_term_counting( true );
  1140 	// Loop through all the menu items' POST variables
  1179 
       
  1180 	// Loop through all the menu items' POST variables.
  1141 	if ( ! empty( $_POST['menu-item-db-id'] ) ) {
  1181 	if ( ! empty( $_POST['menu-item-db-id'] ) ) {
  1142 		foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
  1182 		foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
  1143 
  1183 
  1144 			// Menu item title can't be blank
  1184 			// Menu item title can't be blank.
  1145 			if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] ) {
  1185 			if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' === $_POST['menu-item-title'][ $_key ] ) {
  1146 				continue;
  1186 				continue;
  1147 			}
  1187 			}
  1148 
  1188 
  1149 			$args = array();
  1189 			$args = array();
  1150 			foreach ( $post_fields as $field ) {
  1190 			foreach ( $post_fields as $field ) {
  1159 				unset( $menu_items[ $menu_item_db_id ] );
  1199 				unset( $menu_items[ $menu_item_db_id ] );
  1160 			}
  1200 			}
  1161 		}
  1201 		}
  1162 	}
  1202 	}
  1163 
  1203 
  1164 	// Remove menu items from the menu that weren't in $_POST
  1204 	// Remove menu items from the menu that weren't in $_POST.
  1165 	if ( ! empty( $menu_items ) ) {
  1205 	if ( ! empty( $menu_items ) ) {
  1166 		foreach ( array_keys( $menu_items ) as $menu_item_id ) {
  1206 		foreach ( array_keys( $menu_items ) as $menu_item_id ) {
  1167 			if ( is_nav_menu_item( $menu_item_id ) ) {
  1207 			if ( is_nav_menu_item( $menu_item_id ) ) {
  1168 				wp_delete_post( $menu_item_id );
  1208 				wp_delete_post( $menu_item_id );
  1169 			}
  1209 			}
  1171 	}
  1211 	}
  1172 
  1212 
  1173 	// Store 'auto-add' pages.
  1213 	// Store 'auto-add' pages.
  1174 	$auto_add        = ! empty( $_POST['auto-add-pages'] );
  1214 	$auto_add        = ! empty( $_POST['auto-add-pages'] );
  1175 	$nav_menu_option = (array) get_option( 'nav_menu_options' );
  1215 	$nav_menu_option = (array) get_option( 'nav_menu_options' );
       
  1216 
  1176 	if ( ! isset( $nav_menu_option['auto_add'] ) ) {
  1217 	if ( ! isset( $nav_menu_option['auto_add'] ) ) {
  1177 		$nav_menu_option['auto_add'] = array();
  1218 		$nav_menu_option['auto_add'] = array();
  1178 	}
  1219 	}
       
  1220 
  1179 	if ( $auto_add ) {
  1221 	if ( $auto_add ) {
  1180 		if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) {
  1222 		if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) {
  1181 			$nav_menu_option['auto_add'][] = $nav_menu_selected_id;
  1223 			$nav_menu_option['auto_add'][] = $nav_menu_selected_id;
  1182 		}
  1224 		}
  1183 	} else {
  1225 	} else {
  1184 		if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) ) {
  1226 		$key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true );
       
  1227 		if ( false !== $key ) {
  1185 			unset( $nav_menu_option['auto_add'][ $key ] );
  1228 			unset( $nav_menu_option['auto_add'][ $key ] );
  1186 		}
  1229 		}
  1187 	}
  1230 	}
  1188 	// Remove nonexistent/deleted menus
  1231 
       
  1232 	// Remove non-existent/deleted menus.
  1189 	$nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
  1233 	$nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
  1190 	update_option( 'nav_menu_options', $nav_menu_option );
  1234 	update_option( 'nav_menu_options', $nav_menu_option );
  1191 
  1235 
  1192 	wp_defer_term_counting( false );
  1236 	wp_defer_term_counting( false );
  1193 
  1237 
  1194 	/** This action is documented in wp-includes/nav-menu.php */
  1238 	/** This action is documented in wp-includes/nav-menu.php */
  1195 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
  1239 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
  1196 
  1240 
  1197 	$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' .
  1241 	$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' .
  1198 		/* translators: %s: nav menu title */
       
  1199 		sprintf(
  1242 		sprintf(
       
  1243 			/* translators: %s: Nav menu title. */
  1200 			__( '%s has been updated.' ),
  1244 			__( '%s has been updated.' ),
  1201 			'<strong>' . $nav_menu_selected_title . '</strong>'
  1245 			'<strong>' . $nav_menu_selected_title . '</strong>'
  1202 		) . '</p></div>';
  1246 		) . '</p></div>';
  1203 
  1247 
  1204 	unset( $menu_items, $unsorted_menu_items );
  1248 	unset( $menu_items, $unsorted_menu_items );
  1222 	$data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
  1266 	$data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
  1223 
  1267 
  1224 	if ( ! is_null( $data ) && $data ) {
  1268 	if ( ! is_null( $data ) && $data ) {
  1225 		foreach ( $data as $post_input_data ) {
  1269 		foreach ( $data as $post_input_data ) {
  1226 			// For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
  1270 			// For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
  1227 			// derive the array path keys via regex and set the value in $_POST.
  1271 			// derive the array path keys via regex and set the value in $_POST.
  1228 			preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
  1272 			preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
  1229 
  1273 
  1230 			$array_bits = array( $matches[1] );
  1274 			$array_bits = array( $matches[1] );
  1231 
  1275 
  1232 			if ( isset( $matches[3] ) ) {
  1276 			if ( isset( $matches[3] ) ) {
  1234 			}
  1278 			}
  1235 
  1279 
  1236 			$new_post_data = array();
  1280 			$new_post_data = array();
  1237 
  1281 
  1238 			// Build the new array value from leaf to trunk.
  1282 			// Build the new array value from leaf to trunk.
  1239 			for ( $i = count( $array_bits ) - 1; $i >= 0; $i -- ) {
  1283 			for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) {
  1240 				if ( $i == count( $array_bits ) - 1 ) {
  1284 				if ( count( $array_bits ) - 1 == $i ) {
  1241 					$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
  1285 					$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
  1242 				} else {
  1286 				} else {
  1243 					$new_post_data = array( $array_bits[ $i ] => $new_post_data );
  1287 					$new_post_data = array( $array_bits[ $i ] => $new_post_data );
  1244 				}
  1288 				}
  1245 			}
  1289 			}