[wp-trac] [WordPress Trac] #10676: current-cat-ancestor in wp_list_categories

WordPress Trac noreply at wordpress.org
Fri Jun 20 21:59:44 UTC 2014


#10676: current-cat-ancestor in wp_list_categories
-------------------------------------------------+-------------------------
 Reporter:  spathon                              |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
Component:  Taxonomy                             |  Release
 Severity:  normal                               |     Version:  2.8.5
 Keywords:  has-patch needs-testing 2nd-opinion  |  Resolution:
                                                 |     Focuses:
-------------------------------------------------+-------------------------

Comment (by jrchamp):

 The class name makes sense. It's the logical conclusion given that I
 reimplemented it before finding this ticket.

 I dislike the use of get_ancestors() because it has extra overhead, we
 already have the first term and only need to check the terms until the
 point that it matches. I'm attaching a modified version of this patch that
 doesn't waste time array_reversing and leverages the short circuit
 opportunities to often avoid the get_ancestors() call altogether.

 Really, given the inherent static response given by the get_ancestors()
 call for the provided current_category, if the Walker_Category object
 initialized a private member variable with the get_ancestors() array the
 first time it was needed, you could easily use a simple isset on the
 member variable on all subsequent calls. Additionally, if this path were
 pursued I would recommend an array_flip to allow use of the isset language
 construct on the array of ancestor IDs itself rather than the much slower
 in_array() function.

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


More information about the wp-trac mailing list