Make WordPress Core

Ticket #34113: 34113.5.diff

File 34113.5.diff, 3.6 KB (added by swissspidy, 7 years ago)
  • src/wp-includes/admin-bar.php

    diff --git src/wp-includes/admin-bar.php src/wp-includes/admin-bar.php
    index 4c4765d..178ea2b 100644
    function wp_admin_bar_edit_menu( $wp_admin_bar ) { 
    581581                        && ( $post_type_object = get_post_type_object( $current_screen->post_type ) )
    582582                        && ( $post_type_object->public )
    583583                        && ( $post_type_object->show_in_admin_bar )
    584                         && ( get_post_type_archive_link( $post_type_object->name ) ) )
     584                        && ( get_post_type_archive_link( $post_type_object->name ) )
     585                        && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) )
    585586                {
    586587                        $wp_admin_bar->add_node( array(
    587588                                'id' => 'archive',
  • tests/phpunit/tests/adminbar.php

    diff --git tests/phpunit/tests/adminbar.php tests/phpunit/tests/adminbar.php
    index 32507e3..b6c3572 100644
    class Tests_AdminBar extends WP_UnitTestCase { 
    383383        /**
    384384         * @ticket 34113
    385385         */
    386         public function test_admin_bar_contains_view_archive_link() {
     386        public function test_admin_bar_has_no_archives_link_if_no_static_front_page() {
     387                set_current_screen( 'edit-post' );
     388
     389                $wp_admin_bar = $this->get_standard_admin_bar();
     390                $node         = $wp_admin_bar->get_node( 'archive' );
     391
     392                set_current_screen( 'front' );
     393
     394                $this->assertNull( $node );
     395        }
     396
     397        /**
     398         * @ticket 34113
     399         */
     400        public function test_admin_bar_contains_view_archive_link_if_static_front_page() {
     401                update_option( 'show_on_front', 'page' );
    387402                set_current_screen( 'edit-post' );
    388403
    389404                $wp_admin_bar = $this->get_standard_admin_bar();
    class Tests_AdminBar extends WP_UnitTestCase { 
    397412        /**
    398413         * @ticket 34113
    399414         */
    400         public function test_admin_bar_has_no_archives_link_for_post_types_without_archive() {
     415        public function test_admin_bar_has_no_archives_link_for_pages() {
    401416                set_current_screen( 'edit-page' );
    402417
    403418                $wp_admin_bar = $this->get_standard_admin_bar();
    class Tests_AdminBar extends WP_UnitTestCase { 
    407422
    408423                $this->assertNull( $node );
    409424        }
     425
     426        /**
     427         * @ticket 34113
     428         */
     429        public function test_admin_bar_has_no_archives_link_for_non_public_cpt() {
     430                register_post_type( 'foo-non-public', array(
     431                        'public'            => false,
     432                        'has_archive'       => true,
     433                        'show_in_admin_bar' => true,
     434                ) );
     435
     436                set_current_screen( 'edit-foo-non-public' );
     437
     438                $wp_admin_bar = $this->get_standard_admin_bar();
     439                $node         = $wp_admin_bar->get_node( 'archive' );
     440
     441                set_current_screen( 'front' );
     442                unregister_post_type( 'foo-non-public' );
     443
     444                $this->assertNull( $node );
     445        }
     446
     447        /**
     448         * @ticket 34113
     449         */
     450        public function test_admin_bar_has_no_archives_link_for_cpt_without_archive() {
     451                register_post_type( 'foo-non-public', array(
     452                        'public'            => true,
     453                        'has_archive'       => false,
     454                        'show_in_admin_bar' => true,
     455                ) );
     456
     457                set_current_screen( 'edit-foo-non-public' );
     458
     459                $wp_admin_bar = $this->get_standard_admin_bar();
     460                $node         = $wp_admin_bar->get_node( 'archive' );
     461
     462                set_current_screen( 'front' );
     463                unregister_post_type( 'foo-non-public' );
     464
     465                $this->assertNull( $node );
     466        }
     467
     468        /**
     469         * @ticket 34113
     470         */
     471        public function test_admin_bar_has_no_archives_link_for_cpt_not_shown_in_admin_bar() {
     472                register_post_type( 'foo-non-public', array(
     473                        'public'            => true,
     474                        'has_archive'       => true,
     475                        'show_in_admin_bar' => false,
     476                ) );
     477
     478                set_current_screen( 'edit-foo-non-public' );
     479
     480                $wp_admin_bar = $this->get_standard_admin_bar();
     481                $node         = $wp_admin_bar->get_node( 'archive' );
     482
     483                set_current_screen( 'front' );
     484                unregister_post_type( 'foo-non-public' );
     485
     486                $this->assertNull( $node );
     487        }
    410488}