Loosen typing in cat_is_ancestor_of
|Reported by:||filosofo||Owned by:||ryan|
cat_is_ancestor_of is too strict in checking the type of its arguments; if something is a numeric string rather than an integer per se, it fails silently.
I get caught by this with some regularity. Let's say you get an array of a post's categories like so:
$post_cats = wp_get_post_categories($the_post_id);
$post_cats is an array of cat ids as numeric strings (not integers), which is normally fine with most loosely-typed PHP code.
However, iterate through that array with cat_is_ancestor_of to see if one of those categories is a child of another, and cat_is_ancestor_of will fail to identify any ancestor-descendant relationships, because it checks whether its arguments are integers (which numeric strings aren't).
Since arguments for cat_is_ancestor_of can be either category ids or category objects, instead of checking that something is an integer, we should instead check if something is missing object properties, as my patch does.
Really Cool Side Benefit:
I was concerned about performance, so I tested the time it took to run this comparison over 10,000 different numbers, for both the existing code and my patch. My patch produced consistent performance improvements of 40% on average.