Skip to content

Commit ab93978

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@61658 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1a7da55 commit ab93978

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

src/wp-admin/nav-menus.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,27 +1200,43 @@ function wp_nav_menu_max_depth( $classes ) {
12001200
<legend class="menu-settings-group-name howto"><?php _e( 'Menu location' ); ?></legend>
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 ] )
12061207
&& 0 !== $nav_menu_selected_id
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; ?>
12261242
</div>

0 commit comments

Comments
 (0)