-
-
Notifications
You must be signed in to change notification settings - Fork 513
Timber::get_term() API: clarify taxonomy requirements #2087
Description
Is your feature request related to a problem? Please describe.
Per #2073, we're moving away from direct instantiation of Terms in favor of Timber::get_term(). The problem here is that simply changing from new Timber\Term($term_id) to Timber::get_term($term_id) will break existing code in most cases, because the current Timber::get_term() implementation uses a default $taxonomy (second arg) of post_tag.
The following tests in tests/test-timber-term.php fail if the constructor call in each is changed to a direct Timber::get_term(...) call without also specifying a $taxonomy:
testConstructortestTermChildrentestTermWithNativeMetatestTermWithNativeMetaFalsetestTermWithNativeMetaNotExistingtestTermEditLink
Describe the solution you’d like
It would be better if the $taxonomy arg to Timber::get_term() defaulted to the empty string. This would be more in line with the core API, and I believe it does not constitute a breaking change to existing calls to Timber::get_term().
If possible, Timber::get_term() should also support things that Term::__construct() currently supports, i.e.:
-
Passing a slug as first param - Rather than passing a slug directly to
::get_term(), for consistency with the new Post/User APIs, we should implement a::get_term_by()method. Timber::get_term_by() #2186 - Passing an object as first param
Describe alternatives you’ve considered
A sub-optimal solution (which is being incorporated into the refactor on #2085) is to require a second $taxonomy param in every case. This would likely mean considerably more work for upgrading downstream code, over and above the work required to migrate away from direct instantiation.
Additional context
#2085 introduces a quick way to run tests that call, or did at one point call, the Timber\Term constructor:
phpunit --group called-term-constructor
Note at time of writing this is not on 2.x yet, but hopefully will be soon!