[wp-trac] [WordPress Trac] #36949: Term exists should use get_terms internally

WordPress Trac noreply at wordpress.org
Wed Jan 9 01:11:21 UTC 2019


#36949: Term exists should use get_terms internally
--------------------------------------------+-----------------------------
 Reporter:  spacedmonkey                    |       Owner:  (none)
     Type:  enhancement                     |      Status:  new
 Priority:  normal                          |   Milestone:  Future Release
Component:  Taxonomy                        |     Version:  2.3
 Severity:  normal                          |  Resolution:
 Keywords:  has-patch has-unit-tests close  |     Focuses:  performance
--------------------------------------------+-----------------------------

Comment (by spacedmonkey):

 There a number of reasons I want this to go into core, here is my
 reasoning.

 1. Constancy
 term_exists one of the few places in core to not use `WP_Term_Query`. Once
 have this is merged, we have one piece of code that generates all the
 queries to the terms tables. That makes future changes to terms table much
 easier, as we need only edit in one place. It would make a ticket like
 #30262 easier.
 2. Maintenance
 Similar to above, but this should reduce maintenance overhead, as there is
 less code in play. Any bugs we find, can be fixeding in `WP_Term_Query`
 and other part of code will see the benefit.
 3. Filters
 Using `WP_Term_Query` add a host of useful filters, that would allow for
 better intergrations with plugins. Take #41246 that would make it possible
 to load terms from external source like elastic search.
 4. Caching
 My idea above, I said that by default, caching would be disable, this
 doesn't mean if you know what you doing, you can't turn it back on. Take
 the for example the following snippet.

 {{{#!php
 add_filter( 'get_terms_args', function( $args ) {
       // Leave disabled if importing
       if( defined('WP_IMPORTING') ) {
             return $args;
       }

       // Leave disabled if using WP CLI
       if( defined('WP_CLI') && WP_CLI) {
             return $args;
       }

       $args['cache'] = true;

       return $args;
 });

 }}}
 This would allow developers to turn off / on caching for `term_exists`
 when they want and put the control in their hands.

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


More information about the wp-trac mailing list