[wp-trac] [WordPress Trac] #38280: Make term count for a specific object type available

WordPress Trac noreply at wordpress.org
Fri Jul 13 08:30:34 UTC 2018


#38280: Make term count for a specific object type available
--------------------------------------+------------------------------
 Reporter:  desrosj                   |       Owner:  (none)
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Taxonomy                  |     Version:  4.7
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------

Comment (by ivankristianto):

 Replying to [comment:24 desrosj]:
 > Replying to [comment:22 boonebgorges]:
 > > I also have questions about the "if" conditions where I put the
 comment `are these right?`. I know that these are meant to be shortcuts,
 but I worry that they have the potential to produce corrupted data. For
 example, the `1 >= count( $taxonomy_object->object_type )` call assumes
 that plugins have properly registered their taxonomies with object types -
 but do we enforce this elsewhere? What if the
 `$taxonomy_object->object_type` is not the same as `$object_type`? It
 seems better to return no data in these cases than to return something
 potentially incorrect. Can anyone help to think through the possibilities
 here?
 >
 > When a taxonomy is registered, no object type validation is performed.
 So, you could register a `foo` object type for a taxonomy even if `foo`
 objects are not registered. Maybe `1 >= count(
 $taxonomy_object->object_type )` could be changed to count the number of
 object types that currently exist instead. This would add a need to
 compare the number of object types stored in `_wp_counted_object_types`
 with the number of active in order to trigger recounting if an object type
 is removed, but could prevent inaccurate counts when an object type is
 removed.

 I agree with @desrosj here, `$taxonomy_object->object_type` could be
 different and we didn't enforced that. I prefer we remove that condition
 and go straight get the count from the meta / recount it. It's more safe
 rather than return false data.

 I did add back the unit testing that missing in previous patch
 [attachment:"38280.17.diff"]. And also rename the function name as well.

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


More information about the wp-trac mailing list