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:
testConstructor
testTermChildren
testTermWithNativeMeta
testTermWithNativeMetaFalse
testTermWithNativeMetaNotExisting
testTermEditLink
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.:
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!
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 fromnew Timber\Term($term_id)toTimber::get_term($term_id)will break existing code in most cases, because the currentTimber::get_term()implementation uses a default$taxonomy(second arg) ofpost_tag.The following tests in
tests/test-timber-term.phpfail if the constructor call in each is changed to a directTimber::get_term(...)call without also specifying a$taxonomy:testConstructortestTermChildrentestTermWithNativeMetatestTermWithNativeMetaFalsetestTermWithNativeMetaNotExistingtestTermEditLinkDescribe the solution you’d like
It would be better if the
$taxonomyarg toTimber::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 toTimber::get_term().If possible,
Timber::get_term()should also support things thatTerm::__construct()currently supports, i.e.:Passing a slug as first param::get_term(), for consistency with the new Post/User APIs, we should implement a::get_term_by()method. Timber::get_term_by() #2186Describe alternatives you’ve considered
A sub-optimal solution (which is being incorporated into the refactor on #2085) is to require a second
$taxonomyparam 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\Termconstructor:Note at time of writing this is not on
2.xyet, but hopefully will be soon!