Ticket #44466: 44466.3.diff
File 44466.3.diff, 3.1 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/class-wp-terms-list-table.php
470 470 __( 'Delete' ) 471 471 ); 472 472 } 473 if ( $tax->public) {473 if ( is_taxonomy_viewable( $tax ) ) { 474 474 $actions['view'] = sprintf( 475 475 '<a href="%s" aria-label="%s">%s</a>', 476 476 get_term_link( $tag ), -
src/wp-includes/admin-bar.php
728 728 } elseif ( 'term' == $current_screen->base 729 729 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) 730 730 && ( $tax = get_taxonomy( $tag->taxonomy ) ) 731 && $tax->public) {731 && is_taxonomy_viewable( $tax ) ) { 732 732 $wp_admin_bar->add_menu( 733 733 array( 734 734 'id' => 'view', -
src/wp-includes/taxonomy.php
4548 4548 4549 4549 return $parent; 4550 4550 } 4551 4552 /** 4553 * Determines whether a taxonomy is considered "viewable". 4554 * 4555 * @since 5.1.0 4556 * 4557 * @param string|WP_Taxonomy $taxonomy Taxonomy name or object. 4558 * @return bool Whether the taxonomy should be considered viewable. 4559 */ 4560 function is_taxonomy_viewable( $taxonomy ) { 4561 if ( is_scalar( $taxonomy ) ) { 4562 $taxonomy = get_taxonomy( $taxonomy ); 4563 if ( ! $taxonomy ) { 4564 return false; 4565 } 4566 } 4567 4568 return $taxonomy->publicly_queryable; 4569 } -
tests/phpunit/tests/taxonomy/isTaxonomyViewable.php
1 <?php 2 3 /** 4 * @group taxonomy 5 */ 6 class Tests_Taxonomy_IsTaxonomyViewable extends WP_UnitTestCase { 7 public function setUp() { 8 parent::setUp(); 9 10 register_post_type( 'wptests_pt' ); 11 register_taxonomy( 'wptests_tax_viewable', 'wptests_pt', array( 'publicly_queryable' => true ) ); 12 register_taxonomy( 'wptests_tax_non_viewable', 'wptests_pt', array( 'publicly_queryable' => false ) ); 13 } 14 15 /** 16 * @ticket 44466 17 */ 18 public function test_is_taxonomy_viewable_for_querable_taxonomy() { 19 $this->assertTrue( is_taxonomy_viewable( 'wptests_tax_viewable' ) ); 20 } 21 22 /** 23 * @ticket 44466 24 */ 25 public function test_is_taxonomy_viewable_for_non_querable_taxonomy() { 26 $this->assertFalse( is_taxonomy_viewable( 'wptests_tax_non_viewable' ) ); 27 } 28 29 /** 30 * @ticket 44466 31 */ 32 public function test_is_taxonomy_viewable_for_non_existing_taxonomy() { 33 $this->assertFalse( is_taxonomy_viewable( 'wptests_tax_non_existing' ) ); 34 } 35 36 /** 37 * @ticket 44466 38 */ 39 public function test_is_taxonomy_viewable_with_object_given() { 40 $taxonomy = get_taxonomy( 'wptests_tax_viewable' ); 41 42 $this->assertTrue( is_taxonomy_viewable( $taxonomy ) ); 43 } 44 }