Ensure Description is respected in post type archive menu items.
Tested scenarios include: using the default (which is the post type description), Setting a custom description for that individual menu item, and setting a custom description that is blank. Introduced in r35382. Props Toro_Unit, mayukojpn, extendwings, jorbin. Fixes #35324. See #16075. git-svn-id: https://develop.svn.wordpress.org/trunk@36859 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e5556666cc
commit
4af0645ae8
@ -767,7 +767,8 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
||||
}
|
||||
|
||||
$menu_item->type_label = __( 'Post Type Archive' );
|
||||
$menu_item->description = '';
|
||||
$post_content = wp_trim_words( $menu_item->post_content, 200 );
|
||||
$post_type_description = '' == $post_content ? $object->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 );
|
||||
|
@ -180,4 +180,82 @@ class Test_Nav_Menus extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( $nav_menus_names, $expected_nav_menus_names );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35324
|
||||
*/
|
||||
function test_wp_setup_nav_menu_item_for_post_type_archive() {
|
||||
|
||||
$post_type_slug = rand_str( 12 );
|
||||
$post_type_description = rand_str();
|
||||
register_post_type( $post_type_slug ,array(
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'description' => $post_type_description,
|
||||
'label' => $post_type_slug
|
||||
));
|
||||
|
||||
$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-description' => $post_type_description,
|
||||
'menu-item-status' => 'publish'
|
||||
) );
|
||||
$post_type_archive_item = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) );
|
||||
|
||||
$this->assertEquals( $post_type_slug , $post_type_archive_item->title );
|
||||
$this->assertEquals( $post_type_description , $post_type_archive_item->description );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35324
|
||||
*/
|
||||
function test_wp_setup_nav_menu_item_for_post_type_archive_no_description() {
|
||||
|
||||
$post_type_slug = rand_str( 12 );
|
||||
$post_type_description = '';
|
||||
register_post_type( $post_type_slug ,array(
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'label' => $post_type_slug
|
||||
));
|
||||
|
||||
$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->assertEquals( $post_type_slug , $post_type_archive_item->title );
|
||||
$this->assertEquals( $post_type_description , $post_type_archive_item->description ); //fail!!!
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35324
|
||||
*/
|
||||
function test_wp_setup_nav_menu_item_for_post_type_archive_custom_description() {
|
||||
|
||||
$post_type_slug = rand_str( 12 );
|
||||
$post_type_description = rand_str();
|
||||
register_post_type( $post_type_slug ,array(
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'description' => $post_type_description,
|
||||
'label' => $post_type_slug
|
||||
));
|
||||
|
||||
$menu_item_description = rand_str();
|
||||
|
||||
$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-description' => $menu_item_description,
|
||||
'menu-item-status' => 'publish'
|
||||
) );
|
||||
$post_type_archive_item = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) );
|
||||
|
||||
$this->assertEquals( $post_type_slug , $post_type_archive_item->title );
|
||||
$this->assertEquals( $menu_item_description , $post_type_archive_item->description );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user