wp/wp-admin/includes/nav-menu.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-admin/includes/nav-menu.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-admin/includes/nav-menu.php	Fri Sep 05 18:40:08 2025 +0200
@@ -32,15 +32,20 @@
 	}
 
 	if ( 'markup' === $response_format ) {
-		$args['walker'] = new Walker_Nav_Menu_Checklist;
+		$args['walker'] = new Walker_Nav_Menu_Checklist();
 	}
 
 	if ( 'get-post-item' === $type ) {
 		if ( post_type_exists( $object_type ) ) {
 			if ( isset( $request['ID'] ) ) {
 				$object_id = (int) $request['ID'];
+
 				if ( 'markup' === $response_format ) {
-					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
+					echo walk_nav_menu_tree(
+						array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ),
+						0,
+						(object) $args
+					);
 				} elseif ( 'json' === $response_format ) {
 					echo wp_json_encode(
 						array(
@@ -55,8 +60,13 @@
 		} elseif ( taxonomy_exists( $object_type ) ) {
 			if ( isset( $request['ID'] ) ) {
 				$object_id = (int) $request['ID'];
+
 				if ( 'markup' === $response_format ) {
-					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
+					echo walk_nav_menu_tree(
+						array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ),
+						0,
+						(object) $args
+					);
 				} elseif ( 'json' === $response_format ) {
 					$post_obj = get_term( $object_id, $object_type );
 					echo wp_json_encode(
@@ -84,18 +94,26 @@
 					's'                      => $query,
 				)
 			);
+
 			if ( isset( $post_type_obj->_default_query ) ) {
 				$args = array_merge( $args, (array) $post_type_obj->_default_query );
 			}
+
 			$search_results_query = new WP_Query( $args );
 			if ( ! $search_results_query->have_posts() ) {
 				return;
 			}
+
 			while ( $search_results_query->have_posts() ) {
 				$post = $search_results_query->next_post();
+
 				if ( 'markup' === $response_format ) {
 					$var_by_ref = $post->ID;
-					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
+					echo walk_nav_menu_tree(
+						array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ),
+						0,
+						(object) $args
+					);
 				} elseif ( 'json' === $response_format ) {
 					echo wp_json_encode(
 						array(
@@ -116,12 +134,18 @@
 					'hide_empty' => false,
 				)
 			);
+
 			if ( empty( $terms ) || is_wp_error( $terms ) ) {
 				return;
 			}
+
 			foreach ( (array) $terms as $term ) {
 				if ( 'markup' === $response_format ) {
-					echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
+					echo walk_nav_menu_tree(
+						array_map( 'wp_setup_nav_menu_item', array( $term ) ),
+						0,
+						(object) $args
+					);
 				} elseif ( 'json' === $response_format ) {
 					echo wp_json_encode(
 						array(
@@ -145,7 +169,14 @@
 function wp_nav_menu_setup() {
 	// Register meta boxes.
 	wp_nav_menu_post_type_meta_boxes();
-	add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
+	add_meta_box(
+		'add-custom-links',
+		__( 'Custom Links' ),
+		'wp_nav_menu_item_link_meta_box',
+		'nav-menus',
+		'side',
+		'default'
+	);
 	wp_nav_menu_taxonomy_meta_boxes();
 
 	// Register advanced menu items (columns).
@@ -173,7 +204,7 @@
  *
  * @since 3.0.0
  *
- * @global array $wp_meta_boxes
+ * @global array $wp_meta_boxes Global meta box state.
  */
 function wp_initial_nav_menu_meta_boxes() {
 	global $wp_meta_boxes;
@@ -227,11 +258,20 @@
 		 *                                      meta box for.
 		 */
 		$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
+
 		if ( $post_type ) {
 			$id = $post_type->name;
 			// Give pages a higher priority.
 			$priority = ( 'page' === $post_type->name ? 'core' : 'default' );
-			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 );
+			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
+			);
 		}
 	}
 }
@@ -251,9 +291,18 @@
 	foreach ( $taxonomies as $tax ) {
 		/** This filter is documented in wp-admin/includes/nav-menu.php */
 		$tax = apply_filters( 'nav_menu_meta_box_object', $tax );
+
 		if ( $tax ) {
 			$id = $tax->name;
-			add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
+			add_meta_box(
+				"add-{$id}",
+				$tax->labels->name,
+				'wp_nav_menu_item_taxonomy_meta_box',
+				'nav-menus',
+				'side',
+				'default',
+				$tax
+			);
 		}
 	}
 }
@@ -298,17 +347,26 @@
 		<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
 		<p id="menu-item-url-wrap" class="wp-clearfix">
 			<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
-			<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://" />
+			<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://"
+			/>
 		</p>
 
 		<p id="menu-item-name-wrap" class="wp-clearfix">
 			<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
-			<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" />
+			<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"
+			/>
 		</p>
 
 		<p class="button-controls wp-clearfix">
 			<span class="add-to-menu">
-				<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" />
+				<input id="submit-customlinkdiv" name="add-custom-menu-item"
+					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' ); ?>"
+				/>
 				<span class="spinner"></span>
 			</span>
 		</p>
@@ -374,8 +432,12 @@
 		$front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
 
 		$front_page_obj = null;
+
 		if ( ! empty( $front_page ) ) {
-			$front_page_obj                = get_post( $front_page );
+			$front_page_obj = get_post( $front_page );
+		}
+
+		if ( $front_page_obj ) {
 			$front_page_obj->front_or_home = true;
 
 			$important_pages[]   = $front_page_obj;
@@ -402,11 +464,14 @@
 		$posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0;
 
 		if ( ! empty( $posts_page ) ) {
-			$posts_page_obj             = get_post( $posts_page );
-			$posts_page_obj->posts_page = true;
+			$posts_page_obj = get_post( $posts_page );
 
-			$important_pages[]   = $posts_page_obj;
-			$suppress_page_ids[] = $posts_page_obj->ID;
+			if ( $posts_page_obj ) {
+				$front_page_obj->posts_page = true;
+
+				$important_pages[]   = $posts_page_obj;
+				$suppress_page_ids[] = $posts_page_obj->ID;
+			}
 		}
 
 		// Insert Privacy Policy Page.
@@ -414,6 +479,7 @@
 
 		if ( ! empty( $privacy_policy_page_id ) ) {
 			$privacy_policy_page = get_post( $privacy_policy_page_id );
+
 			if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) {
 				$privacy_policy_page->privacy_policy_page = true;
 
@@ -429,14 +495,14 @@
 	}
 
 	// @todo Transient caching of these results with proper invalidation on updating of a post of this type.
-	$get_posts = new WP_Query;
+	$get_posts = new WP_Query();
 	$posts     = $get_posts->query( $args );
 
 	// Only suppress and insert when more than just suppression pages available.
 	if ( ! $get_posts->post_count ) {
 		if ( ! empty( $suppress_page_ids ) ) {
 			unset( $args['post__not_in'] );
-			$get_posts = new WP_Query;
+			$get_posts = new WP_Query();
 			$posts     = $get_posts->query( $args );
 		} else {
 			echo '<p>' . __( 'No items.' ) . '</p>';
@@ -461,6 +527,7 @@
 			'format'             => '',
 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
+			/* translators: Hidden accessibility text. */
 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
 			'total'              => $num_pages,
 			'current'            => $pagenum,
@@ -483,7 +550,7 @@
 		$current_tab = $_REQUEST[ $tab_name ];
 	}
 
-	if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
+	if ( ! empty( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) {
 		$current_tab = 'search';
 	}
 
@@ -499,35 +566,50 @@
 	$most_recent_url = '';
 	$view_all_url    = '';
 	$search_url      = '';
+
 	if ( $nav_menu_selected_id ) {
-		$most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) );
-		$view_all_url    = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
-		$search_url      = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
+		$most_recent_url = add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) );
+		$view_all_url    = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) );
+		$search_url      = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) );
 	}
 	?>
-	<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
-		<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
+	<div id="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>" class="posttypediv">
+		<ul id="<?php echo esc_attr( "posttype-{$post_type_name}-tabs" ); ?>" class="posttype-tabs add-menu-item-tabs">
 			<li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>>
-				<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">
+				<a class="nav-tab-link"
+					data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
+					href="<?php echo esc_url( $most_recent_url . "#tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
+				>
 					<?php _e( 'Most Recent' ); ?>
 				</a>
 			</li>
 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
-				<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">
+				<a class="nav-tab-link"
+					data-type="<?php echo esc_attr( "{$post_type_name}-all" ); ?>"
+					href="<?php echo esc_url( $view_all_url . "#{$post_type_name}-all" ); ?>"
+				>
 					<?php _e( 'View All' ); ?>
 				</a>
 			</li>
 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
-				<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">
+				<a class="nav-tab-link"
+					data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>"
+					href="<?php echo esc_url( $search_url . "#tabs-panel-posttype-{$post_type_name}-search" ); ?>"
+				>
 					<?php _e( 'Search' ); ?>
 				</a>
 			</li>
 		</ul><!-- .posttype-tabs -->
 
-		<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">
-			<ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
+		<div id="<?php echo esc_attr( "tabs-panel-posttype-{$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 esc_attr_e( 'Most Recent' ); ?>" tabindex="0"
+		>
+			<ul id="<?php echo esc_attr( "{$post_type_name}checklist-most-recent" ); ?>"
+				class="categorychecklist form-no-clear"
+			>
 				<?php
-				$recent_args    = array_merge(
+				$recent_args = array_merge(
 					$args,
 					array(
 						'orderby'        => 'post_date',
@@ -535,7 +617,8 @@
 						'posts_per_page' => 15,
 					)
 				);
-				$most_recent    = $get_posts->query( $recent_args );
+				$most_recent = $get_posts->query( $recent_args );
+
 				$args['walker'] = $walker;
 
 				/**
@@ -557,17 +640,30 @@
 				 * @param array     $box         Arguments passed to `wp_nav_menu_item_post_type_meta_box()`.
 				 * @param array     $recent_args An array of `WP_Query` arguments for 'Most Recent' tab.
 				 */
-				$most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box, $recent_args );
+				$most_recent = apply_filters(
+					"nav_menu_items_{$post_type_name}_recent",
+					$most_recent,
+					$args,
+					$box,
+					$recent_args
+				);
 
-				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args );
+				echo walk_nav_menu_tree(
+					array_map( 'wp_setup_nav_menu_item', $most_recent ),
+					0,
+					(object) $args
+				);
 				?>
 			</ul>
 		</div><!-- /.tabs-panel -->
 
-		<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">
+		<div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>"
+			class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
+			role="region" aria-label="<?php echo esc_attr( $post_type->labels->search_items ); ?>" tabindex="0"
+		>
 			<?php
-			if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
-				$searched       = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] );
+			if ( isset( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) {
+				$searched       = esc_attr( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] );
 				$search_results = get_posts(
 					array(
 						's'         => $searched,
@@ -582,17 +678,41 @@
 			}
 			?>
 			<p class="quick-search-wrap">
-				<label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
-				<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; ?>" />
+				<label for="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>" class="screen-reader-text">
+					<?php
+					/* translators: Hidden accessibility text. */
+					_e( 'Search' );
+					?>
+				</label>
+				<input type="search"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
+					class="quick-search" value="<?php echo $searched; ?>"
+					name="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>"
+					id="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>"
+				/>
 				<span class="spinner"></span>
-				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
+				<?php
+				submit_button(
+					__( 'Search' ),
+					'small quick-search-submit hide-if-js',
+					'submit',
+					false,
+					array( 'id' => "submit-quick-search-posttype-{$post_type_name}" )
+				);
+				?>
 			</p>
 
-			<ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
+			<ul id="<?php echo esc_attr( "{$post_type_name}-search-checklist" ); ?>"
+				data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>"
+				class="categorychecklist form-no-clear"
+			>
 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
 				<?php
 				$args['walker'] = $walker;
-				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args );
+				echo walk_nav_menu_tree(
+					array_map( 'wp_setup_nav_menu_item', $search_results ),
+					0,
+					(object) $args
+				);
 				?>
 			<?php elseif ( is_wp_error( $search_results ) ) : ?>
 				<li><?php echo $search_results->get_error_message(); ?></li>
@@ -602,13 +722,20 @@
 			</ul>
 		</div><!-- /.tabs-panel -->
 
-		<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">
+		<div id="<?php echo esc_attr( "{$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 esc_attr( $post_type->labels->all_items ); ?>" tabindex="0"
+		>
 			<?php if ( ! empty( $page_links ) ) : ?>
 				<div class="add-menu-item-pagelinks">
 					<?php echo $page_links; ?>
 				</div>
 			<?php endif; ?>
-			<ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear">
+
+			<ul id="<?php echo esc_attr( "{$post_type_name}checklist" ); ?>"
+				data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>"
+				class="categorychecklist form-no-clear"
+			>
 				<?php
 				$args['walker'] = $walker;
 
@@ -652,13 +779,23 @@
 				 * @param array        $args      An array of `WP_Query` arguments.
 				 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
 				 */
-				$posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
+				$posts = apply_filters(
+					"nav_menu_items_{$post_type_name}",
+					$posts,
+					$args,
+					$post_type
+				);
 
-				$checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args );
+				$checkbox_items = walk_nav_menu_tree(
+					array_map( 'wp_setup_nav_menu_item', $posts ),
+					0,
+					(object) $args
+				);
 
 				echo $checkbox_items;
 				?>
 			</ul>
+
 			<?php if ( ! empty( $page_links ) ) : ?>
 				<div class="add-menu-item-pagelinks">
 					<?php echo $page_links; ?>
@@ -666,14 +803,19 @@
 			<?php endif; ?>
 		</div><!-- /.tabs-panel -->
 
-		<p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
+		<p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>">
 			<span class="list-controls hide-if-no-js">
-				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
+				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
+					id="<?php echo esc_attr( $tab_name ); ?>" class="select-all"
+				/>
 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
 			</span>
 
 			<span class="add-to-menu">
-				<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 ); ?>" />
+				<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}" ); ?>"
+				/>
 				<span class="spinner"></span>
 			</span>
 		</p>
@@ -732,7 +874,7 @@
 		return;
 	}
 
-	$num_pages = ceil(
+	$num_pages = (int) ceil(
 		wp_count_terms(
 			array_merge(
 				$args,
@@ -757,6 +899,7 @@
 			'format'             => '',
 			'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
 			'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
+			/* translators: Hidden accessibility text. */
 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
 			'total'              => $num_pages,
 			'current'            => $pagenum,
@@ -779,7 +922,7 @@
 		$current_tab = $_REQUEST[ $tab_name ];
 	}
 
-	if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
+	if ( ! empty( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) {
 		$current_tab = 'search';
 	}
 
@@ -795,35 +938,50 @@
 	$most_used_url = '';
 	$view_all_url  = '';
 	$search_url    = '';
+
 	if ( $nav_menu_selected_id ) {
-		$most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) );
-		$view_all_url  = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
-		$search_url    = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
+		$most_used_url = add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) );
+		$view_all_url  = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) );
+		$search_url    = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) );
 	}
 	?>
-	<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
-		<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
+	<div id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>" class="taxonomydiv">
+		<ul id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}-tabs" ); ?>" class="taxonomy-tabs add-menu-item-tabs">
 			<li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>>
-				<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">
+				<a class="nav-tab-link"
+					data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>"
+					href="<?php echo esc_url( $most_used_url . "#tabs-panel-{$taxonomy_name}-pop" ); ?>"
+				>
 					<?php echo esc_html( $taxonomy->labels->most_used ); ?>
 				</a>
 			</li>
 			<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
-				<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">
+				<a class="nav-tab-link"
+					data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>"
+					href="<?php echo esc_url( $view_all_url . "#tabs-panel-{$taxonomy_name}-all" ); ?>"
+				>
 					<?php _e( 'View All' ); ?>
 				</a>
 			</li>
 			<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
-				<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; ?>">
+				<a class="nav-tab-link"
+					data-type="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
+					href="<?php echo esc_url( $search_url . "#tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
+				>
 					<?php _e( 'Search' ); ?>
 				</a>
 			</li>
 		</ul><!-- .taxonomy-tabs -->
 
-		<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">
-			<ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
+		<div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>"
+			class="tabs-panel <?php echo ( 'most-used' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
+			role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->most_used ); ?>" tabindex="0"
+		>
+			<ul id="<?php echo esc_attr( "{$taxonomy_name}checklist-pop" ); ?>"
+				class="categorychecklist form-no-clear"
+			>
 				<?php
-				$popular_terms  = get_terms(
+				$popular_terms = get_terms(
 					array(
 						'taxonomy'     => $taxonomy_name,
 						'orderby'      => 'count',
@@ -832,24 +990,41 @@
 						'hierarchical' => false,
 					)
 				);
+
 				$args['walker'] = $walker;
-				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args );
+				echo walk_nav_menu_tree(
+					array_map( 'wp_setup_nav_menu_item', $popular_terms ),
+					0,
+					(object) $args
+				);
 				?>
 			</ul>
 		</div><!-- /.tabs-panel -->
 
-		<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">
+		<div id="<?php echo esc_attr( "tabs-panel-{$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 esc_attr( $taxonomy->labels->all_items ); ?>" tabindex="0"
+		>
 			<?php if ( ! empty( $page_links ) ) : ?>
 				<div class="add-menu-item-pagelinks">
 					<?php echo $page_links; ?>
 				</div>
 			<?php endif; ?>
-			<ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name; ?>" class="categorychecklist form-no-clear">
+
+			<ul id="<?php echo esc_attr( "{$taxonomy_name}checklist" ); ?>"
+				data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>"
+				class="categorychecklist form-no-clear"
+			>
 				<?php
 				$args['walker'] = $walker;
-				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args );
+				echo walk_nav_menu_tree(
+					array_map( 'wp_setup_nav_menu_item', $terms ),
+					0,
+					(object) $args
+				);
 				?>
 			</ul>
+
 			<?php if ( ! empty( $page_links ) ) : ?>
 				<div class="add-menu-item-pagelinks">
 					<?php echo $page_links; ?>
@@ -857,10 +1032,12 @@
 			<?php endif; ?>
 		</div><!-- /.tabs-panel -->
 
-		<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">
+		<div id="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
+			class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
+			role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->search_items ); ?>" tabindex="0">
 			<?php
-			if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
-				$searched       = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] );
+			if ( isset( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) {
+				$searched       = esc_attr( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] );
 				$search_results = get_terms(
 					array(
 						'taxonomy'     => $taxonomy_name,
@@ -877,17 +1054,41 @@
 			}
 			?>
 			<p class="quick-search-wrap">
-				<label for="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
-				<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; ?>" />
+				<label for="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>" class="screen-reader-text">
+					<?php
+					/* translators: Hidden accessibility text. */
+					_e( 'Search' );
+					?>
+				</label>
+				<input type="search"
+					class="quick-search" value="<?php echo $searched; ?>"
+					name="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>"
+					id="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>"
+				/>
 				<span class="spinner"></span>
-				<?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
+				<?php
+				submit_button(
+					__( 'Search' ),
+					'small quick-search-submit hide-if-js',
+					'submit',
+					false,
+					array( 'id' => "submit-quick-search-taxonomy-{$taxonomy_name}" )
+				);
+				?>
 			</p>
 
-			<ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name; ?>" class="categorychecklist form-no-clear">
+			<ul id="<?php echo esc_attr( "{$taxonomy_name}-search-checklist" ); ?>"
+				data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>"
+				class="categorychecklist form-no-clear"
+			>
 			<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
 				<?php
 				$args['walker'] = $walker;
-				echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args );
+				echo walk_nav_menu_tree(
+					array_map( 'wp_setup_nav_menu_item', $search_results ),
+					0,
+					(object) $args
+				);
 				?>
 			<?php elseif ( is_wp_error( $search_results ) ) : ?>
 				<li><?php echo $search_results->get_error_message(); ?></li>
@@ -897,14 +1098,19 @@
 			</ul>
 		</div><!-- /.tabs-panel -->
 
-		<p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
+		<p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>">
 			<span class="list-controls hide-if-no-js">
-				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
+				<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
+					id="<?php echo esc_attr( $tab_name ); ?>" class="select-all"
+				/>
 				<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
 			</span>
 
 			<span class="add-to-menu">
-				<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 ); ?>" />
+				<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}" ); ?>"
+				/>
 				<span class="spinner"></span>
 			</span>
 		</p>
@@ -926,7 +1132,7 @@
 	$menu_id     = (int) $menu_id;
 	$items_saved = array();
 
-	if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
+	if ( 0 === $menu_id || is_nav_menu( $menu_id ) ) {
 
 		// Loop through all the menu items' POST values.
 		foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
@@ -952,7 +1158,7 @@
 			if (
 				empty( $_item_object_data['menu-item-db-id'] ) ||
 				( 0 > $_possible_db_id ) ||
-				$_possible_db_id != $_item_object_data['menu-item-db-id']
+				$_possible_db_id !== (int) $_item_object_data['menu-item-db-id']
 			) {
 				$_actual_db_id = 0;
 			} else {
@@ -979,6 +1185,7 @@
 
 		}
 	}
+
 	return $items_saved;
 }
 
@@ -1059,7 +1266,7 @@
 		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
 
 		if ( class_exists( $walker_class_name ) ) {
-			$walker = new $walker_class_name;
+			$walker = new $walker_class_name();
 		} else {
 			return new WP_Error(
 				'menu_walker_not_exist',
@@ -1073,6 +1280,7 @@
 
 		$some_pending_menu_items = false;
 		$some_invalid_menu_items = false;
+
 		foreach ( (array) $menu_items as $menu_item ) {
 			if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
 				$some_pending_menu_items = true;
@@ -1083,21 +1291,35 @@
 		}
 
 		if ( $some_pending_menu_items ) {
-			$result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>';
+			$message     = __( 'Click Save Menu to make pending menu items public.' );
+			$notice_args = array(
+				'type'               => 'info',
+				'additional_classes' => array( 'notice-alt', 'inline' ),
+			);
+			$result     .= wp_get_admin_notice( $message, $notice_args );
 		}
 
 		if ( $some_invalid_menu_items ) {
-			$result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>';
+			$message     = __( 'There are some invalid menu items. Please check or delete them.' );
+			$notice_args = array(
+				'type'               => 'error',
+				'additional_classes' => array( 'notice-alt', 'inline' ),
+			);
+			$result     .= wp_get_admin_notice( $message, $notice_args );
 		}
 
 		$result .= '<ul class="menu" id="menu-to-edit"> ';
-		$result .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items ), 0, (object) array( 'walker' => $walker ) );
+		$result .= walk_nav_menu_tree(
+			array_map( 'wp_setup_nav_menu_item', $menu_items ),
+			0,
+			(object) array( 'walker' => $walker )
+		);
 		$result .= ' </ul> ';
+
 		return $result;
 	} elseif ( is_wp_error( $menu ) ) {
 		return $menu;
 	}
-
 }
 
 /**
@@ -1129,10 +1351,19 @@
  */
 function _wp_delete_orphaned_draft_menu_items() {
 	global $wpdb;
+
 	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
 
 	// Delete orphaned draft menu items.
-	$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 ) );
+	$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
+		)
+	);
 
 	foreach ( (array) $menu_items_to_delete as $menu_item_id ) {
 		wp_delete_post( $menu_item_id, true );
@@ -1140,13 +1371,13 @@
 }
 
 /**
- * Saves nav menu items
+ * Saves nav menu items.
  *
  * @since 3.6.0
  *
  * @param int|string $nav_menu_selected_id    ID, slug, or name of the currently-selected menu.
  * @param string     $nav_menu_selected_title Title of the currently-selected menu.
- * @return array The menu updated message
+ * @return string[] The menu updated messages.
  */
 function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) {
 	$unsorted_menu_items = wp_get_nav_menu_items(
@@ -1199,10 +1430,20 @@
 				$args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : '';
 			}
 
-			$menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][ $_key ] != $_key ? 0 : $_key ), $args );
+			$menu_item_db_id = wp_update_nav_menu_item(
+				$nav_menu_selected_id,
+				( (int) $_POST['menu-item-db-id'][ $_key ] !== $_key ? 0 : $_key ),
+				$args
+			);
 
 			if ( is_wp_error( $menu_item_db_id ) ) {
-				$messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
+				$messages[] = wp_get_admin_notice(
+					$menu_item_db_id->get_error_message(),
+					array(
+						'id'                 => 'message',
+						'additional_classes' => array( 'error' ),
+					)
+				);
 			} else {
 				unset( $menu_items[ $menu_item_db_id ] );
 			}
@@ -1238,7 +1479,11 @@
 	}
 
 	// Remove non-existent/deleted menus.
-	$nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
+	$nav_menu_option['auto_add'] = array_intersect(
+		$nav_menu_option['auto_add'],
+		wp_get_nav_menus( array( 'fields' => 'ids' ) )
+	);
+
 	update_option( 'nav_menu_options', $nav_menu_option );
 
 	wp_defer_term_counting( false );
@@ -1246,12 +1491,15 @@
 	/** This action is documented in wp-includes/nav-menu.php */
 	do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
 
-	$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' .
-		sprintf(
-			/* translators: %s: Nav menu title. */
-			__( '%s has been updated.' ),
-			'<strong>' . $nav_menu_selected_title . '</strong>'
-		) . '</p></div>';
+	/* translators: %s: Nav menu title. */
+	$message     = sprintf( __( '%s has been updated.' ), '<strong>' . $nav_menu_selected_title . '</strong>' );
+	$notice_args = array(
+		'id'                 => 'message',
+		'dismissible'        => true,
+		'additional_classes' => array( 'updated' ),
+	);
+
+	$messages[] = wp_get_admin_notice( $message, $notice_args );
 
 	unset( $menu_items, $unsorted_menu_items );
 
@@ -1275,8 +1523,10 @@
 
 	if ( ! is_null( $data ) && $data ) {
 		foreach ( $data as $post_input_data ) {
-			// For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
-			// derive the array path keys via regex and set the value in $_POST.
+			/*
+			 * For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
+			 * derive the array path keys via regex and set the value in $_POST.
+			 */
 			preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
 
 			$array_bits = array( $matches[1] );
@@ -1289,7 +1539,7 @@
 
 			// Build the new array value from leaf to trunk.
 			for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) {
-				if ( count( $array_bits ) - 1 == $i ) {
+				if ( count( $array_bits ) - 1 === $i ) {
 					$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
 				} else {
 					$new_post_data = array( $array_bits[ $i ] => $new_post_data );