Commit efdc0f85e6 for wordpress.org

commit efdc0f85e655ea0be6615a6ecb9e4c64248f88ef
Author: westonruter <westonruter@git.wordpress.org>
Date:   Thu Oct 29 18:50:54 2026 +0000

    Menus: Avoid warning when a nav menu item lacks `current`.

    In `Walker_Nav_Menu::start_el()`, the `aria-current` attribute was built by reading `$menu_item->current` directly, but that property is only ever set by `_wp_menu_item_classes_by_context()`. Menu items that bypass it, such as `stdClass` items that plugins add via the `wp_nav_menu_objects` filter, triggered an undefined property warning on every page load. The property is now read behind `empty()`, as the other optional menu item properties in the method already are.

    Since menu items reaching the walker are not always `WP_Post` instances, the menu item parameters of the walker and of the hooks it fires are now documented as `WP_Post|stdClass`, along with an object shape for static analysis that describes the properties `start_el()` actually requires. The admin walkers extending this class read more properties than that shape guarantees, so the resulting parameter type mismatch is recorded in the static analysis baseline rather than hidden.

    Developed in https://github.com/WordPress/wordpress-develop/pull/12805.
    Follow-up to r42808.

    Props deepakbhojwani, babola, im3dabasia1, westonruter.
    See #65817.
    Fixes #65786.

    Built from https://develop.svn.wordpress.org/trunk@65022


    git-svn-id: http://core.svn.wordpress.org/trunk@64172 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-walker-nav-menu.php b/wp-includes/class-walker-nav-menu.php
index 8047047757..1f9bd6bfdd 100644
--- a/wp-includes/class-walker-nav-menu.php
+++ b/wp-includes/class-walker-nav-menu.php
@@ -147,11 +147,22 @@ class Walker_Nav_Menu extends Walker {
 	 *
 	 * @see Walker::start_el()
 	 *
-	 * @param string   $output            Used to append additional content (passed by reference).
-	 * @param WP_Post  $data_object       Menu item data object.
-	 * @param int      $depth             Depth of menu item. Used for padding.
-	 * @param stdClass $args              An object of wp_nav_menu() arguments.
-	 * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
+	 * @param string           $output            Used to append additional content (passed by reference).
+	 * @param WP_Post|stdClass $data_object       Menu item data object.
+	 * @param int              $depth             Depth of menu item. Used for padding.
+	 * @param stdClass         $args              An object of wp_nav_menu() arguments.
+	 * @param int              $current_object_id Optional. ID of the current menu item. Default 0.
+	 *
+	 * @phpstan-param object{
+	 *     ID: int|string,
+	 *     title: string,
+	 *     classes?: string[],
+	 *     target?: string,
+	 *     xfn?: string,
+	 *     url?: string|false,
+	 *     attr_title?: string,
+	 *     current?: bool,
+	 * } $data_object
 	 */
 	public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
 		// Restores the more descriptive, specific name for use within this method.
@@ -174,9 +185,9 @@ class Walker_Nav_Menu extends Walker {
 		 *
 		 * @since 4.4.0
 		 *
-		 * @param stdClass $args      An object of wp_nav_menu() arguments.
-		 * @param WP_Post  $menu_item Menu item data object.
-		 * @param int      $depth     Depth of menu item. Used for padding.
+		 * @param stdClass         $args      An object of wp_nav_menu() arguments.
+		 * @param WP_Post|stdClass $menu_item Menu item data object.
+		 * @param int              $depth     Depth of menu item. Used for padding.
 		 */
 		$args = apply_filters( 'nav_menu_item_args', $args, $menu_item, $depth );

@@ -186,10 +197,10 @@ class Walker_Nav_Menu extends Walker {
 		 * @since 3.0.0
 		 * @since 4.1.0 The `$depth` parameter was added.
 		 *
-		 * @param string[] $classes   Array of the CSS classes that are applied to the menu item's `<li>` element.
-		 * @param WP_Post  $menu_item The current menu item object.
-		 * @param stdClass $args      An object of wp_nav_menu() arguments.
-		 * @param int      $depth     Depth of menu item. Used for padding.
+		 * @param string[]         $classes   Array of the CSS classes that are applied to the menu item's `<li>` element.
+		 * @param WP_Post|stdClass $menu_item The current menu item object.
+		 * @param stdClass         $args      An object of wp_nav_menu() arguments.
+		 * @param int              $depth     Depth of menu item. Used for padding.
 		 */
 		$class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $menu_item, $args, $depth ) );

@@ -199,10 +210,10 @@ class Walker_Nav_Menu extends Walker {
 		 * @since 3.0.1
 		 * @since 4.1.0 The `$depth` parameter was added.
 		 *
-		 * @param string   $menu_item_id The ID attribute applied to the menu item's `<li>` element.
-		 * @param WP_Post  $menu_item    The current menu item.
-		 * @param stdClass $args         An object of wp_nav_menu() arguments.
-		 * @param int      $depth        Depth of menu item. Used for padding.
+		 * @param string           $menu_item_id The ID attribute applied to the menu item's `<li>` element.
+		 * @param WP_Post|stdClass $menu_item    The current menu item.
+		 * @param stdClass         $args         An object of wp_nav_menu() arguments.
+		 * @param int              $depth        Depth of menu item. Used for padding.
 		 */
 		$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $menu_item->ID, $menu_item, $args, $depth );

@@ -221,9 +232,9 @@ class Walker_Nav_Menu extends Walker {
 		 *     @type string $class        HTML CSS class attribute.
 		 *     @type string $id           HTML id attribute.
 		 * }
-		 * @param WP_Post  $menu_item The current menu item object.
-		 * @param stdClass $args      An object of wp_nav_menu() arguments.
-		 * @param int      $depth     Depth of menu item. Used for padding.
+		 * @param WP_Post|stdClass $menu_item The current menu item object.
+		 * @param stdClass         $args      An object of wp_nav_menu() arguments.
+		 * @param int              $depth     Depth of menu item. Used for padding.
 		 */
 		$li_atts       = apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth );
 		$li_attributes = $this->build_atts( $li_atts );
@@ -241,10 +252,10 @@ class Walker_Nav_Menu extends Walker {
 		 *
 		 * @since 4.4.0
 		 *
-		 * @param string   $title     The menu item's title.
-		 * @param WP_Post  $menu_item The current menu item object.
-		 * @param stdClass $args      An object of wp_nav_menu() arguments.
-		 * @param int      $depth     Depth of menu item. Used for padding.
+		 * @param string           $title     The menu item's title.
+		 * @param WP_Post|stdClass $menu_item The current menu item object.
+		 * @param stdClass         $args      An object of wp_nav_menu() arguments.
+		 * @param int              $depth     Depth of menu item. Used for padding.
 		 */
 		$title = apply_filters( 'nav_menu_item_title', $title, $menu_item, $args, $depth );

@@ -262,7 +273,7 @@ class Walker_Nav_Menu extends Walker {
 			$atts['href'] = '';
 		}

-		$atts['aria-current'] = $menu_item->current ? 'page' : '';
+		$atts['aria-current'] = ! empty( $menu_item->current ) ? 'page' : '';

 		// Add title attribute only if it does not match the link text (before or after filtering).
 		if ( ! empty( $menu_item->attr_title )
@@ -290,9 +301,9 @@ class Walker_Nav_Menu extends Walker {
 		 *     @type string $href         The href attribute.
 		 *     @type string $aria-current The aria-current attribute.
 		 * }
-		 * @param WP_Post  $menu_item The current menu item object.
-		 * @param stdClass $args      An object of wp_nav_menu() arguments.
-		 * @param int      $depth     Depth of menu item. Used for padding.
+		 * @param WP_Post|stdClass $menu_item The current menu item object.
+		 * @param stdClass         $args      An object of wp_nav_menu() arguments.
+		 * @param int              $depth     Depth of menu item. Used for padding.
 		 */
 		$atts       = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth );
 		$attributes = $this->build_atts( $atts );
@@ -312,10 +323,10 @@ class Walker_Nav_Menu extends Walker {
 		 *
 		 * @since 3.0.0
 		 *
-		 * @param string   $item_output The menu item's starting HTML output.
-		 * @param WP_Post  $menu_item   Menu item data object.
-		 * @param int      $depth       Depth of menu item. Used for padding.
-		 * @param stdClass $args        An object of wp_nav_menu() arguments.
+		 * @param string           $item_output The menu item's starting HTML output.
+		 * @param WP_Post|stdClass $menu_item   Menu item data object.
+		 * @param int              $depth       Depth of menu item. Used for padding.
+		 * @param stdClass         $args        An object of wp_nav_menu() arguments.
 		 */
 		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $menu_item, $depth, $args );
 	}
@@ -328,10 +339,10 @@ class Walker_Nav_Menu extends Walker {
 	 *
 	 * @see Walker::end_el()
 	 *
-	 * @param string   $output      Used to append additional content (passed by reference).
-	 * @param WP_Post  $data_object Menu item data object. Not used.
-	 * @param int      $depth       Depth of page. Not Used.
-	 * @param stdClass $args        An object of wp_nav_menu() arguments.
+	 * @param string           $output      Used to append additional content (passed by reference).
+	 * @param WP_Post|stdClass $data_object Menu item data object. Not used.
+	 * @param int              $depth       Depth of page. Not Used.
+	 * @param stdClass         $args        An object of wp_nav_menu() arguments.
 	 */
 	public function end_el( &$output, $data_object, $depth = 0, $args = null ) {
 		if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index b85e02cf49..bb4a5ccd43 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-beta3-65021';
+$wp_version = '7.2-beta3-65022';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.