Make WordPress Core


Ignore:
Timestamp:
05/22/2017 08:23:49 PM (8 years ago)
Author:
afercia
Message:

Widgets: Remove the title attributes used in the Tag cloud widget.

  • improves accessibility using an aria-label attribute to match the information conveyed visually with the one exposed to assistive technologies
  • adds an option in the widget to display the item counts, consistently with what other widgets already do (Archives, Categories)

Props adamsoucie, emirpprime, Samantha Miller., MikeLittle, rianrietveld, sami.keijonen, adamsilverstein, westonruter, afercia.
See #24766.
Fixes #35566.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-tag-cloud.php

    r40806 r40816  
    5454        }
    5555
     56        $show_count = ! empty( $instance['count'] );
     57
    5658        /**
    5759         * Filters the taxonomy used in the Tag Cloud widget.
     
    6567         */
    6668        $tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
    67             'taxonomy' => $current_taxonomy,
    68             'echo' => false
     69            'taxonomy'   => $current_taxonomy,
     70            'echo'       => false,
     71            'show_count' => $show_count,
    6972        ) ) );
    7073
     
    103106        $instance = array();
    104107        $instance['title'] = sanitize_text_field( $new_instance['title'] );
     108        $instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0;
    105109        $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
    106110        return $instance;
     
    118122        $current_taxonomy = $this->_get_current_taxonomy($instance);
    119123        $title_id = $this->get_field_id( 'title' );
     124        $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
    120125        $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    121126
     
    129134        $input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
    130135
     136        $count_checkbox = sprintf(
     137            '<p><input type="checkbox" class="checkbox" id="%1$s" name="%2$s"%3$s /> <label for="%1$s">%4$s</label></p>',
     138            $this->get_field_id( 'count' ),
     139            $this->get_field_name( 'count' ),
     140            checked( $count, true, false ),
     141            __( 'Show tag counts' )
     142        );
     143
    131144        switch ( count( $taxonomies ) ) {
    132145
     
    137150            break;
    138151
    139         // Just a single tag cloud supporting taxonomy found, no need to display options
     152        // Just a single tag cloud supporting taxonomy found, no need to display a select.
    140153        case 1:
    141154            $keys = array_keys( $taxonomies );
    142155            $taxonomy = reset( $keys );
    143156            printf( $input, esc_attr( $taxonomy ) );
     157            echo $count_checkbox;
    144158            break;
    145159
    146         // More than one tag cloud supporting taxonomy found, display options
     160        // More than one tag cloud supporting taxonomy found, display a select.
    147161        default:
    148162            printf(
     
    163177            }
    164178
    165             echo '</select></p>';
     179            echo '</select></p>' . $count_checkbox;
    166180        }
    167181    }
Note: See TracChangeset for help on using the changeset viewer.