#56215 closed enhancement (fixed)
Introduce `is_term_publicly_viewable()` function
Reported by: | johnbillion | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-patch has-unit-tests needs-dev-note |
Focuses: | Cc: |
Description
In #49380 the is_post_publicly_viewable()
function was introduced which encapsulates the logic used to determine if a post type is visible to anonymous users.
We should do the same for terms via an is_term_publicly_viewable()
function. Although the logic for terms is more straight forward this serves the same purpose as introducing the corresponding function for posts -- to centralise and reduce the logic needed to validate a term and determine if it's publicly viewable.
There are several places in core that would benefit from an additional "viewable" check before outputting a link to a term, but those changes can happen in a follow-up ticket.
Change History (11)
This ticket was mentioned in PR #2974 on WordPress/wordpress-develop by johnbillion.
2 years ago
#1
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
#2
@
2 years ago
Before:
$term = get_term( $term_id );
if ( ( $term instanceof WP_Term ) && is_taxonomy_viewable( $term->taxonomy ) ) {
$link = get_term_link( $term_id );
}
After:
if ( is_term_publicly_viewable( $term_id ) ) {
$link = get_term_link( $term_id );
}
#4
@
2 years ago
- Owner set to johnbillion
- Resolution set to fixed
- Status changed from new to closed
In 53893:
johnbillion commented on PR #2974:
2 years ago
#5
johnbillion commented on PR #2974:
2 years ago
#6
#8
@
2 years ago
@johnbillion Something that had slipped my mind until recently was the potential for unsplit terms.
This was prompted by #56351 in which a recent change introduced a bug for unsplit terms so we should probably consider them for this new function too. Or deal with unsplit terms in some other way but I don't know what that is -- a topic for the other ticket.
#9
follow-up:
↓ 10
@
2 years ago
There are a few places in core now that don't handle shared terms, ie by only passing a term ID to get_term()
.
Examples:
- https://github.com/WordPress/wordpress-develop/blob/d51b039755431df833162d1a3a72ac5d3812ee24/src/wp-includes/rest-api/search/class-wp-rest-term-search-handler.php#L142-L147
- https://github.com/WordPress/wordpress-develop/blob/d51b039755431df833162d1a3a72ac5d3812ee24/src/wp-includes/rest-api.php#L3138-L3146
Do you think this function needs a $taxonomy
parameter?
#10
in reply to:
↑ 9
@
2 years ago
Replying to johnbillion:
Do you think this function needs a
$taxonomy
parameter?
TBA... I am not sure what I think is best at the moment.
I'm continuing to consider this and will let you know once I cement my thoughts. I'll reopen the ticket if I think it ought to be added.
Trac ticket: https://core.trac.wordpress.org/ticket/56215