Make WordPress Core

Changeset 38708


Ignore:
Timestamp:
10/03/2016 08:37:27 AM (7 years ago)
Author:
swissspidy
Message:

Toolbar: Be more strict about adding a 'View Posts' link to the toolbar.

After [38634], this adjusts the behaviour to remove redundancy by not displaying the link if the latest posts are shown on the front page. In that scenario, the 'Visit Site' link already points to the latest posts.

Fixes #34113.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r38698 r38708  
    599599            && ( $post_type_object->public )
    600600            && ( $post_type_object->show_in_admin_bar )
    601             && ( get_post_type_archive_link( $post_type_object->name ) ) )
     601            && ( get_post_type_archive_link( $post_type_object->name ) )
     602            && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) )
    602603        {
    603604            $wp_admin_bar->add_node( array(
  • trunk/tests/phpunit/tests/adminbar.php

    r38663 r38708  
    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() {
    387387        set_current_screen( 'edit-post' );
    388388
     
    392392        set_current_screen( 'front' );
    393393
     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' );
     402        set_current_screen( 'edit-post' );
     403
     404        $wp_admin_bar = $this->get_standard_admin_bar();
     405        $node         = $wp_admin_bar->get_node( 'archive' );
     406
     407        set_current_screen( 'front' );
     408
    394409        $this->assertNotNull( $node );
    395410    }
     
    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
     
    473488        $this->assertNotNull( $about_node );
    474489    }
     490
     491    /**
     492     * @ticket 34113
     493     */
     494    public function test_admin_bar_has_no_archives_link_for_non_public_cpt() {
     495        register_post_type( 'foo-non-public', array(
     496            'public'            => false,
     497            'has_archive'       => true,
     498            'show_in_admin_bar' => true,
     499        ) );
     500
     501        set_current_screen( 'edit-foo-non-public' );
     502
     503        $wp_admin_bar = $this->get_standard_admin_bar();
     504        $node         = $wp_admin_bar->get_node( 'archive' );
     505
     506        set_current_screen( 'front' );
     507        unregister_post_type( 'foo-non-public' );
     508
     509        $this->assertNull( $node );
     510    }
     511
     512    /**
     513     * @ticket 34113
     514     */
     515    public function test_admin_bar_has_no_archives_link_for_cpt_without_archive() {
     516        register_post_type( 'foo-non-public', array(
     517            'public'            => true,
     518            'has_archive'       => false,
     519            'show_in_admin_bar' => true,
     520        ) );
     521
     522        set_current_screen( 'edit-foo-non-public' );
     523
     524        $wp_admin_bar = $this->get_standard_admin_bar();
     525        $node         = $wp_admin_bar->get_node( 'archive' );
     526
     527        set_current_screen( 'front' );
     528        unregister_post_type( 'foo-non-public' );
     529
     530        $this->assertNull( $node );
     531    }
     532
     533    /**
     534     * @ticket 34113
     535     */
     536    public function test_admin_bar_has_no_archives_link_for_cpt_not_shown_in_admin_bar() {
     537        register_post_type( 'foo-non-public', array(
     538            'public'            => true,
     539            'has_archive'       => true,
     540            'show_in_admin_bar' => false,
     541        ) );
     542
     543        set_current_screen( 'edit-foo-non-public' );
     544
     545        $wp_admin_bar = $this->get_standard_admin_bar();
     546        $node         = $wp_admin_bar->get_node( 'archive' );
     547
     548        set_current_screen( 'front' );
     549        unregister_post_type( 'foo-non-public' );
     550
     551        $this->assertNull( $node );
     552    }
    475553}
Note: See TracChangeset for help on using the changeset viewer.