Make WordPress Core

Changeset 55616


Ignore:
Timestamp:
04/01/2023 08:35:16 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Escape the whole attributes in wp-admin/includes/nav-menu.php.

It is best to always escape the complete value of an attribute, not a partial value, as otherwise the escaping could be (partially) undone when the values are joined together.

While the hardcoded prefix/suffix values in this case don't necessarily create that risk, those may change to values which could be problematic, so making it a habit to escape the value in one go is best practice.

Includes:

  • Moving a few esc_url() calls closer to the actual output and escaping the hash parts too.
  • Wrapping a few long lines for better readability.

Follow-up to [14248], [23707], [42217], [55615].

Props jrf, SergeyBiryukov.
Fixes #57110.

File:
1 edited

Legend:

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

    r55615 r55616  
    4040                        if ( isset( $request['ID'] ) ) {
    4141                                $object_id = (int) $request['ID'];
     42
    4243                                if ( 'markup' === $response_format ) {
    43                                         echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
     44                                        echo walk_nav_menu_tree(
     45                                                array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ),
     46                                                0,
     47                                                (object) $args
     48                                        );
    4449                                } elseif ( 'json' === $response_format ) {
    4550                                        echo wp_json_encode(
    … …  
    5661                        if ( isset( $request['ID'] ) ) {
    5762                                $object_id = (int) $request['ID'];
     63
    5864                                if ( 'markup' === $response_format ) {
    59                                         echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
     65                                        echo walk_nav_menu_tree(
     66                                                array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ),
     67                                                0,
     68                                                (object) $args
     69                                        );
    6070                                } elseif ( 'json' === $response_format ) {
    6171                                        $post_obj = get_term( $object_id, $object_type );
    … …  
    8595                                )
    8696                        );
     97
    8798                        if ( isset( $post_type_obj->_default_query ) ) {
    8899                                $args = array_merge( $args, (array) $post_type_obj->_default_query );
    89100                        }
     101
    90102                        $search_results_query = new WP_Query( $args );
    91103                        if ( ! $search_results_query->have_posts() ) {
    92104                                return;
    93105                        }
     106
    94107                        while ( $search_results_query->have_posts() ) {
    95108                                $post = $search_results_query->next_post();
     109
    96110                                if ( 'markup' === $response_format ) {
    97111                                        $var_by_ref = $post->ID;
    98                                         echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
     112                                        echo walk_nav_menu_tree(
     113                                                array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ),
     114                                                0,
     115                                                (object) $args
     116                                        );
    99117                                } elseif ( 'json' === $response_format ) {
    100118                                        echo wp_json_encode(
    … …  
    117135                                )
    118136                        );
     137
    119138                        if ( empty( $terms ) || is_wp_error( $terms ) ) {
    120139                                return;
    121140                        }
     141
    122142                        foreach ( (array) $terms as $term ) {
    123143                                if ( 'markup' === $response_format ) {
    124                                         echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
     144                                        echo walk_nav_menu_tree(
     145                                                array_map( 'wp_setup_nav_menu_item', array( $term ) ),
     146                                                0,
     147                                                (object) $args
     148                                        );
    125149                                } elseif ( 'json' === $response_format ) {
    126150                                        echo wp_json_encode(
    … …  
    146170        // Register meta boxes.
    147171        wp_nav_menu_post_type_meta_boxes();
    148         add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
     172        add_meta_box(
     173                'add-custom-links',
     174                __( 'Custom Links' ),
     175                'wp_nav_menu_item_link_meta_box',
     176                'nav-menus',
     177                'side',
     178                'default'
     179        );
    149180        wp_nav_menu_taxonomy_meta_boxes();
    150181
    … …  
    228259                 */
    229260                $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
     261
    230262                if ( $post_type ) {
    231263                        $id = $post_type->name;
    232264                        // Give pages a higher priority.
    233265                        $priority = ( 'page' === $post_type->name ? 'core' : 'default' );
    234                         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 );
     266                        add_meta_box(
     267                                "add-post-type-{$id}",
     268                                $post_type->labels->name,
     269                                'wp_nav_menu_item_post_type_meta_box',
     270                                'nav-menus',
     271                                'side',
     272                                $priority,
     273                                $post_type
     274                        );
    235275                }
    236276        }
    … …  
    252292                /** This filter is documented in wp-admin/includes/nav-menu.php */
    253293                $tax = apply_filters( 'nav_menu_meta_box_object', $tax );
     294
    254295                if ( $tax ) {
    255296                        $id = $tax->name;
    256                         add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
     297                        add_meta_box(
     298                                "add-{$id}",
     299                                $tax->labels->name,
     300                                'wp_nav_menu_item_taxonomy_meta_box',
     301                                'nav-menus',
     302                                'side',
     303                                'default',
     304                                $tax
     305                        );
    257306                }
    258307        }
    … …  
    299348                <p id="menu-item-url-wrap" class="wp-clearfix">
    300349                        <label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
    301                         <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://" />
     350                        <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]"
     351                                type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     352                                class="code menu-item-textbox form-required" placeholder="https://"
     353                        />
    302354                </p>
    303355
    304356                <p id="menu-item-name-wrap" class="wp-clearfix">
    305357                        <label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
    306                         <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" />
     358                        <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]"
     359                                type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     360                                class="regular-text menu-item-textbox"
     361                        />
    307362                </p>
    308363
    309364                <p class="button-controls wp-clearfix">
    310365                        <span class="add-to-menu">
    311                                 <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" />
     366                                <input id="submit-customlinkdiv" name="add-custom-menu-item"
     367                                        type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     368                                        class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>"
     369                                />
    312370                                <span class="spinner"></span>
    313371                        </span>
    … …  
    415473                if ( ! empty( $privacy_policy_page_id ) ) {
    416474                        $privacy_policy_page = get_post( $privacy_policy_page_id );
     475
    417476                        if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) {
    418477                                $privacy_policy_page->privacy_policy_page = true;
    … …  
    485544        }
    486545
    487         if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
     546        if ( ! empty( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) {
    488547                $current_tab = 'search';
    489548        }
    … …  
    501560        $view_all_url    = '';
    502561        $search_url      = '';
     562
    503563        if ( $nav_menu_selected_id ) {
    504                 $most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) );
    505                 $view_all_url    = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
    506                 $search_url      = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
     564                $most_recent_url = add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) );
     565                $view_all_url    = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) );
     566                $search_url      = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) );
    507567        }
    508568        ?>
    509         <div id="posttype-<?php echo esc_attr( $post_type_name ); ?>" class="posttypediv">
    510                 <ul id="posttype-<?php echo esc_attr( $post_type_name ); ?>-tabs" class="posttype-tabs add-menu-item-tabs">
     569        <div id="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>" class="posttypediv">
     570                <ul id="<?php echo esc_attr( "posttype-{$post_type_name}-tabs" ); ?>" class="posttype-tabs add-menu-item-tabs">
    511571                        <li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>>
    512                                 <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">
     572                                <a class="nav-tab-link"
     573                                        data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
     574                                        href="<?php echo esc_url( $most_recent_url . "#tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
     575                                >
    513576                                        <?php _e( 'Most Recent' ); ?>
    514577                                </a>
    515578                        </li>
    516579                        <li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
    517                                 <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">
     580                                <a class="nav-tab-link"
     581                                        data-type="<?php echo esc_attr( "{$post_type_name}-all" ); ?>"
     582                                        href="<?php echo esc_url( $view_all_url . "#{$post_type_name}-all" ); ?>"
     583                                >
    518584                                        <?php _e( 'View All' ); ?>
    519585                                </a>
    520586                        </li>
    521587                        <li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
    522                                 <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">
     588                                <a class="nav-tab-link"
     589                                        data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>"
     590                                        href="<?php echo esc_url( $search_url . "#tabs-panel-posttype-{$post_type_name}-search" ); ?>"
     591                                >
    523592                                        <?php _e( 'Search' ); ?>
    524593                                </a>
    … …  
    526595                </ul><!-- .posttype-tabs -->
    527596
    528                 <div id="tabs-panel-posttype-<?php echo esc_attr( $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">
    529                         <ul id="<?php echo esc_attr( $post_type_name ); ?>checklist-most-recent" class="categorychecklist form-no-clear">
     597                <div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>"
     598                        class="tabs-panel <?php echo ( 'most-recent' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
     599                        role="region" aria-label="<?php esc_attr_e( 'Most Recent' ); ?>" tabindex="0"
     600                >
     601                        <ul id="<?php echo esc_attr( "{$post_type_name}checklist-most-recent" ); ?>"
     602                                class="categorychecklist form-no-clear"
     603                        >
    530604                                <?php
    531                                 $recent_args    = array_merge(
     605                                $recent_args = array_merge(
    532606                                        $args,
    533607                                        array(
    … …  
    537611                                        )
    538612                                );
    539                                 $most_recent    = $get_posts->query( $recent_args );
     613                                $most_recent = $get_posts->query( $recent_args );
     614
    540615                                $args['walker'] = $walker;
    541616
    … …  
    559634                                 * @param array     $recent_args An array of `WP_Query` arguments for 'Most Recent' tab.
    560635                                 */
    561                                 $most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box, $recent_args );
    562 
    563                                 echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args );
     636                                $most_recent = apply_filters(
     637                                        "nav_menu_items_{$post_type_name}_recent",
     638                                        $most_recent,
     639                                        $args,
     640                                        $box,
     641                                        $recent_args
     642                                );
     643
     644                                echo walk_nav_menu_tree(
     645                                        array_map( 'wp_setup_nav_menu_item', $most_recent ),
     646                                        0,
     647                                        (object) $args
     648                                );
    564649                                ?>
    565650                        </ul>
    566651                </div><!-- /.tabs-panel -->
    567652
    568                 <div class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-search" role="region" aria-label="<?php echo esc_attr( $post_type->labels->search_items ); ?>" tabindex="0">
     653                <div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>"
     654                        class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
     655                        role="region" aria-label="<?php echo esc_attr( $post_type->labels->search_items ); ?>" tabindex="0"
     656                >
    569657                        <?php
    570                         if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) {
    571                                 $searched       = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] );
     658                        if ( isset( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) {
     659                                $searched       = esc_attr( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] );
    572660                                $search_results = get_posts(
    573661                                        array(
    … …  
    584672                        ?>
    585673                        <p class="quick-search-wrap">
    586                                 <label for="quick-search-posttype-<?php echo esc_attr( $post_type_name ); ?>" class="screen-reader-text">
     674                                <label for="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>" class="screen-reader-text">
    587675                                        <?php
    588676                                        /* translators: Hidden accessibility text. */
    … …  
    590678                                        ?>
    591679                                </label>
    592                                 <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 esc_attr( $post_type_name ); ?>" id="quick-search-posttype-<?php echo esc_attr( $post_type_name ); ?>" />
     680                                <input type="search"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     681                                        class="quick-search" value="<?php echo $searched; ?>"
     682                                        name="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>"
     683                                        id="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>"
     684                                />
    593685                                <span class="spinner"></span>
    594                                 <?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
     686                                <?php
     687                                submit_button(
     688                                        __( 'Search' ),
     689                                        'small quick-search-submit hide-if-js',
     690                                        'submit',
     691                                        false,
     692                                        array( 'id' => "submit-quick-search-posttype-{$post_type_name}" )
     693                                );
     694                                ?>
    595695                        </p>
    596696
    597                         <ul id="<?php echo esc_attr( $post_type_name ); ?>-search-checklist" data-wp-lists="list:<?php echo esc_attr( $post_type_name ); ?>" class="categorychecklist form-no-clear">
     697                        <ul id="<?php echo esc_attr( "{$post_type_name}-search-checklist" ); ?>"
     698                                data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>"
     699                                class="categorychecklist form-no-clear"
     700                        >
    598701                        <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
    599702                                <?php
    600703                                $args['walker'] = $walker;
    601                                 echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args );
     704                                echo walk_nav_menu_tree(
     705                                        array_map( 'wp_setup_nav_menu_item', $search_results ),
     706                                        0,
     707                                        (object) $args
     708                                );
    602709                                ?>
    603710                        <?php elseif ( is_wp_error( $search_results ) ) : ?>
    … …  
    609716                </div><!-- /.tabs-panel -->
    610717
    611                 <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">
     718                <div id="<?php echo esc_attr( "{$post_type_name}-all" ); ?>"
     719                        class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
     720                        role="region" aria-label="<?php echo esc_attr( $post_type->labels->all_items ); ?>" tabindex="0"
     721                >
    612722                        <?php if ( ! empty( $page_links ) ) : ?>
    613723                                <div class="add-menu-item-pagelinks">
    … …  
    615725                                </div>
    616726                        <?php endif; ?>
    617                         <ul id="<?php echo esc_attr( $post_type_name ); ?>checklist" data-wp-lists="list:<?php echo esc_attr( $post_type_name ); ?>" class="categorychecklist form-no-clear">
     727
     728                        <ul id="<?php echo esc_attr( "{$post_type_name}checklist" ); ?>"
     729                                data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>"
     730                                class="categorychecklist form-no-clear"
     731                        >
    618732                                <?php
    619733                                $args['walker'] = $walker;
    … …  
    659773                                 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
    660774                                 */
    661                                 $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
    662 
    663                                 $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args );
     775                                $posts = apply_filters(
     776                                        "nav_menu_items_{$post_type_name}",
     777                                        $posts,
     778                                        $args,
     779                                        $post_type
     780                                );
     781
     782                                $checkbox_items = walk_nav_menu_tree(
     783                                        array_map( 'wp_setup_nav_menu_item', $posts ),
     784                                        0,
     785                                        (object) $args
     786                                );
    664787
    665788                                echo $checkbox_items;
    666789                                ?>
    667790                        </ul>
     791
    668792                        <?php if ( ! empty( $page_links ) ) : ?>
    669793                                <div class="add-menu-item-pagelinks">
    … …  
    673797                </div><!-- /.tabs-panel -->
    674798
    675                 <p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
     799                <p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>">
    676800                        <span class="list-controls hide-if-no-js">
    677                                 <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
     801                                <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     802                                        id="<?php echo esc_attr( $tab_name ); ?>" class="select-all"
     803                                />
    678804                                <label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
    679805                        </span>
    680806
    681807                        <span class="add-to-menu">
    682                                 <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 ); ?>" />
     808                                <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     809                                        class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>"
     810                                        name="add-post-type-menu-item" id="<?php echo esc_attr( "submit-posttype-{$post_type_name}" ); ?>"
     811                                />
    683812                                <span class="spinner"></span>
    684813                        </span>
    … …  
    787916        }
    788917
    789         if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
     918        if ( ! empty( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) {
    790919                $current_tab = 'search';
    791920        }
    … …  
    803932        $view_all_url  = '';
    804933        $search_url    = '';
     934
    805935        if ( $nav_menu_selected_id ) {
    806                 $most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) );
    807                 $view_all_url  = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
    808                 $search_url    = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
     936                $most_used_url = add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) );
     937                $view_all_url  = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) );
     938                $search_url    = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) );
    809939        }
    810940        ?>
    811         <div id="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" class="taxonomydiv">
    812                 <ul id="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
     941        <div id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>" class="taxonomydiv">
     942                <ul id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}-tabs" ); ?>" class="taxonomy-tabs add-menu-item-tabs">
    813943                        <li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>>
    814                                 <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 esc_attr( $taxonomy_name ); ?>-pop">
     944                                <a class="nav-tab-link"
     945                                        data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>"
     946                                        href="<?php echo esc_url( $most_used_url . "#tabs-panel-{$taxonomy_name}-pop" ); ?>"
     947                                >
    815948                                        <?php echo esc_html( $taxonomy->labels->most_used ); ?>
    816949                                </a>
    817950                        </li>
    818951                        <li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>>
    819                                 <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 esc_attr( $taxonomy_name ); ?>-all">
     952                                <a class="nav-tab-link"
     953                                        data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>"
     954                                        href="<?php echo esc_url( $view_all_url . "#tabs-panel-{$taxonomy_name}-all" ); ?>"
     955                                >
    820956                                        <?php _e( 'View All' ); ?>
    821957                                </a>
    822958                        </li>
    823959                        <li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>>
    824                                 <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 esc_attr( $taxonomy_name ); ?>">
     960                                <a class="nav-tab-link"
     961                                        data-type="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
     962                                        href="<?php echo esc_url( $search_url . "#tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
     963                                >
    825964                                        <?php _e( 'Search' ); ?>
    826965                                </a>
    … …  
    828967                </ul><!-- .taxonomy-tabs -->
    829968
    830                 <div id="tabs-panel-<?php echo esc_attr( $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">
    831                         <ul id="<?php echo esc_attr( $taxonomy_name ); ?>checklist-pop" class="categorychecklist form-no-clear" >
     969                <div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>"
     970                        class="tabs-panel <?php echo ( 'most-used' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
     971                        role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->most_used ); ?>" tabindex="0"
     972                >
     973                        <ul id="<?php echo esc_attr( "{$taxonomy_name}checklist-pop" ); ?>"
     974                                class="categorychecklist form-no-clear"
     975                        >
    832976                                <?php
    833                                 $popular_terms  = get_terms(
     977                                $popular_terms = get_terms(
    834978                                        array(
    835979                                                'taxonomy'     => $taxonomy_name,
    … …  
    840984                                        )
    841985                                );
     986
    842987                                $args['walker'] = $walker;
    843                                 echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args );
     988                                echo walk_nav_menu_tree(
     989                                        array_map( 'wp_setup_nav_menu_item', $popular_terms ),
     990                                        0,
     991                                        (object) $args
     992                                );
    844993                                ?>
    845994                        </ul>
    846995                </div><!-- /.tabs-panel -->
    847996
    848                 <div id="tabs-panel-<?php echo esc_attr( $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">
     997                <div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>"
     998                        class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
     999                        role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->all_items ); ?>" tabindex="0"
     1000                >
    8491001                        <?php if ( ! empty( $page_links ) ) : ?>
    8501002                                <div class="add-menu-item-pagelinks">
    … …  
    8521004                                </div>
    8531005                        <?php endif; ?>
    854                         <ul id="<?php echo esc_attr( $taxonomy_name ); ?>checklist" data-wp-lists="list:<?php echo esc_attr( $taxonomy_name ); ?>" class="categorychecklist form-no-clear">
     1006
     1007                        <ul id="<?php echo esc_attr( "{$taxonomy_name}checklist" ); ?>"
     1008                                data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>"
     1009                                class="categorychecklist form-no-clear"
     1010                        >
    8551011                                <?php
    8561012                                $args['walker'] = $walker;
    857                                 echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args );
     1013                                echo walk_nav_menu_tree(
     1014                                        array_map( 'wp_setup_nav_menu_item', $terms ),
     1015                                        0,
     1016                                        (object) $args
     1017                                );
    8581018                                ?>
    8591019                        </ul>
     1020
    8601021                        <?php if ( ! empty( $page_links ) ) : ?>
    8611022                                <div class="add-menu-item-pagelinks">
    … …  
    8651026                </div><!-- /.tabs-panel -->
    8661027
    867                 <div class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->search_items ); ?>" tabindex="0">
     1028                <div id="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>"
     1029                        class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"
     1030                        role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->search_items ); ?>" tabindex="0">
    8681031                        <?php
    869                         if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
    870                                 $searched       = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] );
     1032                        if ( isset( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) {
     1033                                $searched       = esc_attr( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] );
    8711034                                $search_results = get_terms(
    8721035                                        array(
    … …  
    8851048                        ?>
    8861049                        <p class="quick-search-wrap">
    887                                 <label for="quick-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" class="screen-reader-text">
     1050                                <label for="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>" class="screen-reader-text">
    8881051                                        <?php
    8891052                                        /* translators: Hidden accessibility text. */
    … …  
    8911054                                        ?>
    8921055                                </label>
    893                                 <input type="search" class="quick-search" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" id="quick-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" />
     1056                                <input type="search"
     1057                                        class="quick-search" value="<?php echo $searched; ?>"
     1058                                        name="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>"
     1059                                        id="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>"
     1060                                />
    8941061                                <span class="spinner"></span>
    895                                 <?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
     1062                                <?php
     1063                                submit_button(
     1064                                        __( 'Search' ),
     1065                                        'small quick-search-submit hide-if-js',
     1066                                        'submit',
     1067                                        false,
     1068                                        array( 'id' => "submit-quick-search-taxonomy-{$taxonomy_name}" )
     1069                                );
     1070                                ?>
    8961071                        </p>
    8971072
    898                         <ul id="<?php echo esc_attr( $taxonomy_name ); ?>-search-checklist" data-wp-lists="list:<?php echo esc_attr( $taxonomy_name ); ?>" class="categorychecklist form-no-clear">
     1073                        <ul id="<?php echo esc_attr( "{$taxonomy_name}-search-checklist" ); ?>"
     1074                                data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>"
     1075                                class="categorychecklist form-no-clear"
     1076                        >
    8991077                        <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
    9001078                                <?php
    9011079                                $args['walker'] = $walker;
    902                                 echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args );
     1080                                echo walk_nav_menu_tree(
     1081                                        array_map( 'wp_setup_nav_menu_item', $search_results ),
     1082                                        0,
     1083                                        (object) $args
     1084                                );
    9031085                                ?>
    9041086                        <?php elseif ( is_wp_error( $search_results ) ) : ?>
    … …  
    9101092                </div><!-- /.tabs-panel -->
    9111093
    912                 <p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
     1094                <p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>">
    9131095                        <span class="list-controls hide-if-no-js">
    914                                 <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
     1096                                <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     1097                                        id="<?php echo esc_attr( $tab_name ); ?>" class="select-all"
     1098                                />
    9151099                                <label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
    9161100                        </span>
    9171101
    9181102                        <span class="add-to-menu">
    919                                 <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 ); ?>" />
     1103                                <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
     1104                                        class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>"
     1105                                        name="add-taxonomy-menu-item" id="<?php echo esc_attr( "submit-taxonomy-{$taxonomy_name}" ); ?>"
     1106                                />
    9201107                                <span class="spinner"></span>
    9211108                        </span>
    … …  
    9921179                }
    9931180        }
     1181
    9941182        return $items_saved;
    9951183}
    … …  
    10861274                $some_pending_menu_items = false;
    10871275                $some_invalid_menu_items = false;
     1276
    10881277                foreach ( (array) $menu_items as $menu_item ) {
    10891278                        if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
    … …  
    10961285
    10971286                if ( $some_pending_menu_items ) {
    1098                         $result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>';
     1287                        $result .= '<div class="notice notice-info notice-alt inline"><p>'
     1288                                . __( 'Click Save Menu to make pending menu items public.' )
     1289                                . '</p></div>';
    10991290                }
    11001291
    11011292                if ( $some_invalid_menu_items ) {
    1102                         $result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>';
     1293                        $result .= '<div class="notice notice-error notice-alt inline"><p>'
     1294                                . __( 'There are some invalid menu items. Please check or delete them.' )
     1295                                . '</p></div>';
    11031296                }
    11041297
    11051298                $result .= '<ul class="menu" id="menu-to-edit"> ';
    1106                 $result .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items ), 0, (object) array( 'walker' => $walker ) );
     1299                $result .= walk_nav_menu_tree(
     1300                        array_map( 'wp_setup_nav_menu_item', $menu_items ),
     1301                        0,
     1302                        (object) array( 'walker' => $walker )
     1303                );
    11071304                $result .= ' </ul> ';
     1305
    11081306                return $result;
    11091307        } elseif ( is_wp_error( $menu ) ) {
    … …  
    11421340function _wp_delete_orphaned_draft_menu_items() {
    11431341        global $wpdb;
     1342
    11441343        $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
    11451344
    11461345        // Delete orphaned draft menu items.
    1147         $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 ) );
     1346        $menu_items_to_delete = $wpdb->get_col(
     1347                $wpdb->prepare(
     1348                        "SELECT ID FROM $wpdb->posts AS p
     1349                        LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
     1350                        WHERE post_type = 'nav_menu_item' AND post_status = 'draft'
     1351                        AND meta_key = '_menu_item_orphaned' AND meta_value < %d",
     1352                        $delete_timestamp
     1353                )
     1354        );
    11481355
    11491356        foreach ( (array) $menu_items_to_delete as $menu_item_id ) {
    … …  
    12551462
    12561463        // Remove non-existent/deleted menus.
    1257         $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
     1464        $nav_menu_option['auto_add'] = array_intersect(
     1465                $nav_menu_option['auto_add'],
     1466                wp_get_nav_menus( array( 'fields' => 'ids' ) )
     1467        );
     1468
    12581469        update_option( 'nav_menu_options', $nav_menu_option );
    12591470
Note: See TracChangeset for help on using the changeset viewer.