Make WordPress Core


Ignore:
Timestamp:
12/09/2019 01:47:12 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Accessibility: Menus: Properly disable form controls on the Menus screen that cannot be used until at least one menu is created.

This ensures that the actual UI controls state matches the visually conveyed state.

Props afercia, audrasjb, dinhtungdu, sathyapulse, simonjanin, welcher, SergeyBiryukov.
Fixes #48409.

File:
1 edited

Legend:

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

    r46826 r46842  
    256256
    257257/**
    258  * Check whether to disable the Menu Locations meta box submit button
     258 * Check whether to disable the Menu Locations meta box submit button and inputs.
    259259 *
    260260 * @since 3.6.0
     261 * @since 5.3.1 The `$echo` parameter was added.
    261262 *
    262263 * @global bool $one_theme_location_no_menus to determine if no menus exist
    263264 *
    264  * @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
    266  */
    267 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) {
     265 * @param int|string $nav_menu_selected_id ID, name, or slug of the currently selected menu.
     266 * @param bool       $echo                 Whether to echo or just return the string.
     267 * @return string|false Disabled attribute if at least one menu exists, false if not.
     268 */
     269function wp_nav_menu_disabled_check( $nav_menu_selected_id, $echo = true ) {
    268270    global $one_theme_location_no_menus;
    269271
     
    272274    }
    273275
    274     return disabled( $nav_menu_selected_id, 0 );
     276    return disabled( $nav_menu_selected_id, 0, $echo );
    275277}
    276278
     
    293295        <p id="menu-item-url-wrap" class="wp-clearfix">
    294296            <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" placeholder="https://" />
     297            <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://" />
    296298        </p>
    297299
    298300        <p id="menu-item-name-wrap" class="wp-clearfix">
    299301            <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" />
     302            <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" />
    301303        </p>
    302304
     
    570572            <p class="quick-search-wrap">
    571573                <label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label>
    572                 <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; ?>" />
     574                <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; ?>" />
    573575                <span class="spinner"></span>
    574576                <?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
     
    652654        <p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
    653655            <span class="list-controls hide-if-no-js">
    654                 <input type="checkbox" id="<?php echo esc_attr( $post_type_name . '-tab' ); ?>" class="select-all" />
     656                <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $post_type_name . '-tab' ); ?>" class="select-all" />
    655657                <label for="<?php echo esc_attr( $post_type_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
    656658            </span>
     
    881883        <p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
    882884            <span class="list-controls hide-if-no-js">
    883                 <input type="checkbox" id="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>" class="select-all" />
     885                <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>" class="select-all" />
    884886                <label for="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
    885887            </span>
Note: See TracChangeset for help on using the changeset viewer.