WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/07/2016 04:49:19 PM (21 months ago)
Author:
swissspidy
Message:

Menus: Do not show trashed posts in nav menus.

Trashed posts cannot be accessed by site visitors and thus should not be visible on the front end. By marking menu items of trashed posts as invalid, they are excluded from the output.

Props solarissmoke, swissspidy.
Fixes #19038.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r38523 r38744  
    278278
    279279    /**
     280     * @ticket 19038
     281     */
     282    function test_wp_setup_nav_menu_item_for_trashed_post() {
     283        $post_id = self::factory()->post->create( array(
     284            'post_status' => 'trash',
     285        ) );
     286
     287        $menu_item_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
     288            'menu-item-type'      => 'post_type',
     289            'menu-item-object'    => 'post',
     290            'menu-item-object-id' => $post_id,
     291            'menu-item-status'    => 'publish',
     292        ) );
     293
     294        $menu_item = wp_setup_nav_menu_item( get_post( $menu_item_id ) );
     295
     296        $this->assertTrue( ! _is_valid_nav_menu_item( $menu_item ) );
     297    }
     298
     299    /**
    280300     * @ticket 35206
    281301     */
Note: See TracChangeset for help on using the changeset viewer.