Accessibility: Introduce category_list_link_attributes filter in Walker_Category::start_el() for the HTML attributes applied to a category list item's anchor element.

This complements the `page_menu_link_attributes` filter in `Walker_Page::start_el()` and the `nav_menu_link_attributes` filter in `Walker_Nav_Menu::start_el()`.

Props pbiron, audrasjb, afercia.
Fixes #40666. See #40359.
Built from https://develop.svn.wordpress.org/trunk@44957


git-svn-id: http://core.svn.wordpress.org/trunk@44788 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-03-21 10:37:57 +00:00
parent eb5c0abc00
commit bbf36b6521
2 changed files with 37 additions and 5 deletions

View File

@ -108,7 +108,9 @@ class Walker_Category extends Walker {
return;
}
$link = '<a href="' . esc_url( get_term_link( $category ) ) . '" ';
$atts = array();
$atts['href'] = get_term_link( $category );
if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {
/**
* Filters the category description for display.
@ -118,11 +120,40 @@ class Walker_Category extends Walker {
* @param string $description Category description.
* @param object $category Category object.
*/
$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
$atts['title'] = strip_tags( apply_filters( 'category_description', $category->description, $category ) );
}
$link .= '>';
$link .= $cat_name . '</a>';
/**
* Filters the HTML attributes applied to a category list item's anchor element.
*
* @since 5.2.0
*
* @param array $atts {
* The HTML attributes applied to the list item's `<a>` element, empty strings are ignored.
*
* @type string $href The href attribute.
* @type string $title The title attribute.
* }
* @param WP_Term $category Term data object.
* @param int $depth Depth of category, used for padding.
* @param array $args An array of arguments.
* @param int $id ID of the current category.
*/
$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$link = sprintf(
'<a%s>%s</a>',
$attributes,
$cat_name
);
if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
$link .= ' ';
@ -134,6 +165,7 @@ class Walker_Category extends Walker {
$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';
if ( empty( $args['feed'] ) ) {
/* translators: %s: category name */
$alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
} else {
$alt = ' alt="' . $args['feed'] . '"';

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.2-alpha-44956';
$wp_version = '5.2-alpha-44957';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.