From 0a2b35180b32c8e85cf4e2411840bf15474f98c2 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 13 Aug 2022 22:42:12 +0000 Subject: [PATCH] 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 git-svn-id: https://develop.svn.wordpress.org/trunk@53893 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-terms-list-table.php | 3 +-- src/wp-includes/admin-bar.php | 2 +- src/wp-includes/taxonomy.php | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index bfda4d7544..567f09a0d3 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -460,7 +460,6 @@ class WP_Terms_List_Table extends WP_List_Table { // Restores the more descriptive, specific name for use within this method. $tag = $item; $taxonomy = $this->screen->taxonomy; - $tax = get_taxonomy( $taxonomy ); $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; $edit_link = add_query_arg( @@ -497,7 +496,7 @@ class WP_Terms_List_Table extends WP_List_Table { ); } - if ( is_taxonomy_viewable( $tax ) ) { + if ( is_term_publicly_viewable( $tag ) ) { $actions['view'] = sprintf( '%s', get_term_link( $tag ), diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 5304b45ca8..19322a3451 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -809,7 +809,7 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { ); } elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) { $tax = get_taxonomy( $tag->taxonomy ); - if ( is_taxonomy_viewable( $tax ) ) { + if ( is_term_publicly_viewable( $tag ) ) { $wp_admin_bar->add_node( array( 'id' => 'view', diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index f731e4f46a..b41321b059 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -4992,6 +4992,26 @@ function is_taxonomy_viewable( $taxonomy ) { return $taxonomy->publicly_queryable; } +/** + * Determines whether a term is publicly viewable. + * + * A term is considered publicly viewable if its taxonomy is viewable. + * + * @since 6.1.0 + * + * @param int|WP_Term $term Term ID or term object. + * @return bool Whether the term is publicly viewable. + */ +function is_term_publicly_viewable( $term ) { + $term = get_term( $term ); + + if ( ! $term ) { + return false; + } + + return is_taxonomy_viewable( $term->taxonomy ); +} + /** * Sets the last changed time for the 'terms' cache group. *