Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56215 closed enhancement (fixed)

Introduce `is_term_publicly_viewable()` function

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile 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 @johnbillion
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 );
}

#3 @johnbillion
2 years ago

  • Milestone changed from Awaiting Review to 6.1

#4 @johnbillion
2 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 53893:

Taxonomy: Introduce the is_term_publicly_viewable() function.

This is the taxonomy term counterpart to the is_post_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.

Props peterwilsoncc, costdev, johnbillion

Fixes #56215

#7 @johnbillion
2 years ago

In 53894:

Taxonomy: Add a test file that was missed in [53893].

See #56215

#8 @peterwilsoncc
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.

#10 in reply to: ↑ 9 @peterwilsoncc
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.

#11 @milana_cap
2 years ago

  • Keywords needs-dev-note added
Note: See TracTickets for help on using tickets.