Make WordPress Core

Changeset 61658


Ignore:
Timestamp:
02/17/2026 06:46:15 AM (8 months ago)
Author:
audrasjb
Message:

Menus: Prevent error in Menu location checkbox settings.

This changeset avoids throwing a PHP error when an invalid ID is assigned to a menu location, creates a text string to display when using an invalid menu ID, and assigns id and aria-describedby attributes to connect the span element with the related checkbox.

Props skylarkcob, Frozzare, sabernhardt, apermo, SirLouen, audrasjb, mukesh27, westonruter.
Fixes #37026.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/nav-menus.php

    r61648 r61658  
    12011201                                                                                <?php
    12021202                                                                                foreach ( $locations as $location => $description ) :
    1203                                                                                         $checked = false;
     1203                                                                                        $checked               = false;
     1204                                                                                        $theme_location_set_id = '';
    12041205
    12051206                                                                                        if ( isset( $menu_locations[ $location ] )
    … …  
    12071208                                                                                                && $menu_locations[ $location ] === $nav_menu_selected_id
    12081209                                                                                        ) {
    1209                                                                                                         $checked = true;
     1210                                                                                                $checked = true;
     1211                                                                                        }
     1212
     1213                                                                                        if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) {
     1214                                                                                                $theme_location_set_id = "theme-location-set-$location";
    12101215                                                                                        }
    12111216                                                                                        ?>
    12121217                                                                                        <div class="menu-settings-input checkbox-input">
    1213                                                                                                 <input type="checkbox"<?php checked( $checked ); ?> name="menu-locations[<?php echo esc_attr( $location ); ?>]" id="locations-<?php echo esc_attr( $location ); ?>" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
    1214                                                                                                 <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
    1215                                                                                                 <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?>
    1216                                                                                                         <span class="theme-location-set">
    1217                                                                                                         <?php
     1218                                                                                                <input type="checkbox"<?php checked( $checked ); ?>
     1219                                                                                                        name="menu-locations[<?php echo esc_attr( $location ); ?>]"
     1220                                                                                                        id="locations-<?php echo esc_attr( $location ); ?>"
     1221                                                                                                        value="<?php echo esc_attr( $nav_menu_selected_id ); ?>"
     1222                                                                                                        <?php if ( '' !== $theme_location_set_id ) : ?>
     1223                                                                                                                aria-describedby="<?php echo esc_attr( $theme_location_set_id ); ?>"
     1224                                                                                                        <?php endif; ?>
     1225                                                                                                />
     1226                                                                                                <label for="locations-<?php echo esc_attr( $location ); ?>">
     1227                                                                                                        <?php echo esc_html( $description ); ?>
     1228                                                                                                </label>
     1229                                                                                                <?php if ( '' !== $theme_location_set_id ) : ?>
     1230                                                                                                        <span class="theme-location-set" id="<?php echo esc_attr( $theme_location_set_id ); ?>">
     1231                                                                                                                <?php
    12181232                                                                                                                printf(
    1219                                                                                                                         /* translators: %s: Menu name. */
     1233                                                                                                                        /* translators: %s: Menu name, or a message indicating that the menu was not found. */
    12201234                                                                                                                        _x( '(Currently set to: %s)', 'menu location' ),
    1221                                                                                                                         wp_get_nav_menu_object( $menu_locations[ $location ] )->name
     1235                                                                                                                        is_nav_menu( $menu_locations[ $location ] )
     1236                                                                                                                                ? esc_html( wp_get_nav_menu_object( $menu_locations[ $location ] )->name )
     1237                                                                                                                                : __( 'an unknown menu' )
    12221238                                                                                                                );
    1223                                                                                                         ?>
     1239                                                                                                                ?>
    12241240                                                                                                        </span>
    12251241                                                                                                <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.