diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 58a5d1133e..16653cab1e 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -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 ); diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index bbcbbabbdf..83edce53cb 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -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 */