WordPress.org

Make WordPress Core

Changeset 38744


Ignore:
Timestamp:
10/07/16 16:49:19 (9 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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r38369 r38744  
    745745                } else { 
    746746                    $menu_item->type_label = $menu_item->object; 
     747                    $menu_item->_invalid = true; 
     748                } 
     749 
     750                if ( 'trash' === get_post_status( $menu_item->object_id ) ) { 
    747751                    $menu_item->_invalid = true; 
    748752                } 
  • 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.