[wp-trac] [WordPress Trac] #40666: allow arbitrary HTML attributes on <a> produced by Walker_Category

WordPress Trac noreply at wordpress.org
Thu May 4 15:17:19 UTC 2017


#40666: allow arbitrary HTML attributes on <a> produced by Walker_Category
------------------------------------+------------------------------
 Reporter:  pbiron                  |       Owner:
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Taxonomy                |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  dev-feedback has-patch  |     Focuses:  accessibility
------------------------------------+------------------------------
Changes (by pbiron):

 * focuses:   => accessibility


Comment:

 Another thing I noticed while putting together this patch is that there is
 a difference in the way `wp_list_categories()` and `wp_list_pages()`
 invoke `Walker::walk()` (via `walk_category_tree()` and
 `walk_page_tree()`, respectively).

 Namely, `wp_list_pages()` passes the current page as a param to
 `walk_page_tree()`, whereas `wp_list_categories()` does **not** pass the
 current category as a param to `walk_category_tree()`, passing it instead
 `$r['current_category']`.

 As a result, those hooking into the new filter proposed here need to write
 their funcs slightly different than the similar filters for
 `nav_menu_link_attributes` and `page_menu_link_attributes`, as in:

 {{{#!php
 add_filter( 'category_menu_link_attributes', 'add_aria_current_category',
 10, 5 );

 function
 my_category_menu_link_attributes( $atts, $category, $depth, $args, $id )
 {
         if ( $category->term_id == $id ||
                         ( isset( $args['current_category'] ) &&
                         $category->term_id == $args['current_category'] )
 ) {
                 $atts['aria-current'] = 'page' ;
                 }

         return $atts ;
 }
 }}}

 I think it might make sense to include a note about this different in the
 inline docs (resulting in the note appearing in DevHub.  Alternatively,
 the note could be added a "comment" on the DevHub page for the new filter.
 I'd like feedback on this as well.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40666#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list