[wp-trac] [WordPress Trac] #37042: Additional filter for has_category function

WordPress Trac noreply at wordpress.org
Wed Jun 8 04:21:09 UTC 2016


#37042: Additional filter for has_category function
-------------------------------+------------------------------
 Reporter:  jakubbis           |       Owner:
     Type:  feature request    |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Taxonomy           |     Version:  4.5.2
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------
Changes (by boonebgorges):

 * keywords:   => reporter-feedback
 * component:  General => Taxonomy


Comment:

 Hi @jakubbis -

 The filter [comment:1 you suggested] looks strange to me - it doesn't
 allow you to filter 'has_term' so much as it allows you to fake the
 parameters that are passed to `has_term()`. This is not a pattern we often
 use in WP filters.

 I think that what you're trying to do can probably already be done using
 the `get_object_terms` array:

 {{{
 function wp37042_match_tags( $terms, $object_ids, $taxonomies, $args ) {
     $all_terms = array( $terms );
     foreach ( $terms as $term ) {
         // Assuming `$term` is an object - you would probably need more
 checks for this
         $the_term_in_other_languages = whatever();
         $all_terms = array_merge( $all_terms, $the_term_in_other_languages
 );
     }

     return $all_terms;
 }
 add_filter( 'get_object_terms', 'wp37042_match_tags', 10, 4 );
 }}}

 In other words: if a term has 'test', get the term corresponding to 'test'
 in all other languages ('test-fr', etc) and add it to the array of terms
 that belong to the object.

 Does that seem right to you?

 If you still think it's necessary and/or easier to have a more specific
 filter, `is_object_in_term()` seems like a more appropriate place for it.

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


More information about the wp-trac mailing list