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
This commit is contained in:
John Blackbourn
2022-08-13 22:42:12 +00:00
parent dfcc2f6b18
commit 0a2b35180b
3 changed files with 22 additions and 3 deletions
+1 -1
View File
@@ -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',
+20
View File
@@ -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.
*