Menus: Avoid a notice when outputting a description for an existing archive menu item for a post type that doesn't.
Props bradyvercher. See [36859]. Fixes #35324. git-svn-id: https://develop.svn.wordpress.org/trunk@36888 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6a8cb09f86
commit
f07f2252fe
@ -762,13 +762,15 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
||||
$object = get_post_type_object( $menu_item->object );
|
||||
if ( $object ) {
|
||||
$menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title;
|
||||
$post_type_description = $object->description;
|
||||
} else {
|
||||
$menu_item->_invalid = true;
|
||||
$post_type_description = '';
|
||||
}
|
||||
|
||||
$menu_item->type_label = __( 'Post Type Archive' );
|
||||
$post_content = wp_trim_words( $menu_item->post_content, 200 );
|
||||
$post_type_description = '' == $post_content ? $object->description : $post_content;
|
||||
$post_type_description = '' == $post_content ? $post_type_description : $post_content;
|
||||
$menu_item->url = get_post_type_archive_link( $menu_item->object );
|
||||
} elseif ( 'taxonomy' == $menu_item->type ) {
|
||||
$object = get_taxonomy( $menu_item->object );
|
||||
|
@ -258,4 +258,21 @@ class Test_Nav_Menus extends WP_UnitTestCase {
|
||||
$this->assertEquals( $post_type_slug , $post_type_archive_item->title );
|
||||
$this->assertEquals( $menu_item_description , $post_type_archive_item->description );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35324
|
||||
*/
|
||||
function test_wp_setup_nav_menu_item_for_unknown_post_type_archive_no_description() {
|
||||
|
||||
$post_type_slug = rand_str( 12 );
|
||||
|
||||
$post_type_archive_item_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type_archive',
|
||||
'menu-item-object' => $post_type_slug,
|
||||
'menu-item-status' => 'publish'
|
||||
) );
|
||||
$post_type_archive_item = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) );
|
||||
|
||||
$this->assertEmpty( $post_type_archive_item->description );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user