[wp-trac] [WordPress Trac] #34055: the_taxonomies lacks a filter

WordPress Trac noreply at wordpress.org
Tue Sep 29 19:50:01 UTC 2015


#34055: the_taxonomies lacks a filter
-------------------------------------------------+-------------------------
 Reporter:  Chouby                               |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
Component:  Taxonomy                             |  Release
 Severity:  normal                               |     Version:  2.5
 Keywords:  needs-patch needs-unit-tests         |  Resolution:
  reporter-feedback                              |     Focuses:  template
-------------------------------------------------+-------------------------
Changes (by boonebgorges):

 * keywords:  has-patch reporter-feedback => needs-patch needs-unit-tests
     reporter-feedback
 * milestone:  Awaiting Review => Future Release


Comment:

 A filter somewhere in `get_the_taxonomies()` makes sense. However, the
 filter suggested in [attachment:34055.patch] doesn't seem right to me. It
 appears within a `foreach ( $taxonomies )` loop, but it doesn't accept the
 taxonomy as a parameter. The filter name itself is a bit odd.

 I realize you probably want to filter the data before the markup is
 generated. I guess my suggestion would be to break up the `foreach()` loop
 into two separate loops, with a filter between. Something like:

 {{{
 foreach ( get_object_taxonomies( $post ) as $taxonomy ) {
     // ...
     $taxonomies[ $taxonomy ] = wp_get_object_terms( $post->ID, $taxonomy,
 $t['args'] );
 }

 $taxonomies = apply_filters( 'get_the_taxonomies', $taxonomies, $post );

 $links = array();
 foreach ( $taxonomies as $taxonomy => $terms ) {
     foreach ( $terms as $term ) {
         $links[] = wp_sprintf( ... );
     }
 }

 // and maybe another filter on the output for good measure
 return apply_filters( 'get_the_taxonomies_links', $links, $post, $args );
 }}}

 This seems much more appropriate for general use, and the filter names
 seem clearer to me. Chouby, will it serve your purposes?

 If we go this way, we'll need unit tests verifying that there are no
 regressions from the refactoring of `get_the_taxonomies()`. (There are
 already some tests, but it's possible that more would be needed.)

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


More information about the wp-trac mailing list