Make WordPress Core


Ignore:
Timestamp:
03/13/2015 04:56:45 PM (10 years ago)
Author:
azaozz
Message:

PressThis: simplify and restyle the categories drop-down, remove the checkboxes and use JS to get the selected categories on submitting the form.
Part prop: Michael-Arestad. Fixes #31443.

File:
1 edited

Legend:

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

    r31610 r31765  
    8383            $name = 'tax_input[' . $taxonomy . ']';
    8484        }
     85
    8586        $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
    8687        $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
     
    8990
    9091        /** This filter is documented in wp-includes/category-template.php */
    91         $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
    92             '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
    93             checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
    94             disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
    95             esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
     92        if ( ! empty( $args['list_only'] ) ) {
     93            $aria_cheched = 'false';
     94            $inner_class = 'category';
     95
     96            if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
     97                $inner_class .= ' selected';
     98                $aria_cheched = 'true';
     99            }
     100
     101            $output .= "\n" . '<li' . $class . '>' .
     102                '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
     103                ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' .
     104                esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>';
     105        } else {
     106            $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
     107                '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
     108                checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
     109                disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
     110                esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
     111        }
    96112    }
    97113
     
    203219    $tax = get_taxonomy( $taxonomy );
    204220    $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
     221
     222    $args['list_only'] = ! empty( $r['list_only'] );
    205223
    206224    if ( is_array( $r['selected_cats'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.