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. git-svn-id: https://develop.svn.wordpress.org/trunk@38744 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5d4546367a
commit
f683e9aae1
@ -747,6 +747,10 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
||||
$menu_item->_invalid = true;
|
||||
}
|
||||
|
||||
if ( 'trash' === get_post_status( $menu_item->object_id ) ) {
|
||||
$menu_item->_invalid = true;
|
||||
}
|
||||
|
||||
$menu_item->url = get_permalink( $menu_item->object_id );
|
||||
|
||||
$original_object = get_post( $menu_item->object_id );
|
||||
|
@ -276,6 +276,26 @@ class Test_Nav_Menus extends WP_UnitTestCase {
|
||||
$this->assertEmpty( $post_type_archive_item->description );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 19038
|
||||
*/
|
||||
function test_wp_setup_nav_menu_item_for_trashed_post() {
|
||||
$post_id = self::factory()->post->create( array(
|
||||
'post_status' => 'trash',
|
||||
) );
|
||||
|
||||
$menu_item_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
|
||||
$menu_item = wp_setup_nav_menu_item( get_post( $menu_item_id ) );
|
||||
|
||||
$this->assertTrue( ! _is_valid_nav_menu_item( $menu_item ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35206
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user