Opened 6 years ago
Closed 6 years ago
#44466 closed enhancement (fixed)
Have a method to check if a taxonomy is viewable
Reported by: | andizer | Owned by: | pento |
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-unit-tests has-patch |
Focuses: | Cc: |
Description
I was in need of a function that checks if a given taxonomy is viewable. In WordPress there is already a similar function to check this for a post type (is_post_type_viewable).
I think it would be useful to have this for taxonomies as well. Like is_taxonomy_viewable
Attachments (6)
Change History (17)
#1
follow-up:
↓ 2
@
6 years ago
- Keywords needs-patch needs-unit-tests good-first-bug added
- Milestone changed from Awaiting Review to 5.0
#3
@
6 years ago
- Keywords has-patch added; needs-patch removed
- Owner set to andizer
- Status changed from new to assigned
Thanks for the patch @andizer!
I think two small changes are needed:
- For taxonomies, we only need to check
publicly_queryable
in any case. The only reasonis_post_type_viewable()
contains the extra logic is because of the special case of pages being public but not publicly queryable. This doesn't exist for taxonomies in core, so we can simplify here. - We don't need the
isset()
checks as these properties always are set on taxonomy objects.
Let me know if you wanna work on unit tests for this as well. For now I'll assign it to you for further iteration.
#5
@
6 years ago
In 44466.2.diff I assembled the previous patches into one. Everything worked perfectly, I just made a few changes:
- Got rid of the one usage in the REST API controller. While it technically works, that code is getting values for taxonomy properties, so
publicly_queryable
should continue to simply get its value. - Added
5.0.0
version number to the function. - Added missing call to parent
setUp()
method in the test class.
Note: See
TracTickets for help on using
tickets.
This makes complete sense to me, for both parity and solving a common use-case universally. Let's introduce
is_taxonomy_viewable()
.This should be an easy thing, before we implement it though, I'm wondering about
is_post_type_viewable()
: Why does it use$public
for built-in post types and$publicly_queryable
for all the others? I feel like it would make more sense if it only looked at$publicly_queryable
in all cases.