WordPress.org

Make WordPress Core

#35324 closed defect (bug) (fixed)

Post Type Archives support in Nav Menus cannot read description

Reported by: mayukojpn Owned by: jorbin
Milestone: 4.5 Priority: normal
Severity: normal Version: 4.4
Component: Menus Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Saved description data for post type archive nav menu items will be overwritten by empty.

This has been happend since #16075

Attachments (9)

Screenshot_2016_01_06_14_28.png (47.6 KB) - added by mayukojpn 20 months ago.
The words I added here and saved cannot read.
35324.patch (485 bytes) - added by mayukojpn 20 months ago.
Screenshot_2016_01_06_16_12.png (10.3 KB) - added by mayukojpn 20 months ago.
With this bug description field is also invalid on front.
35324-2.patch (2.2 KB) - added by Toro_Unit 18 months ago.
35324-3.patch (2.2 KB) - added by Toro_Unit 18 months ago.
35324-4.patch (2.3 KB) - added by Toro_Unit 18 months ago.
Add Support nav_menu_description filter.
35324-5.patch (1.6 KB) - added by mayukojpn 18 months ago.
35324-6.diff (1.6 KB) - added by mayukojpn 18 months ago.
last file was wrong file format, sorry!
35324.7.diff (2.0 KB) - added by bradyvercher 18 months ago.

Download all attachments as: .zip

Change History (24)

@mayukojpn
20 months ago

The words I added here and saved cannot read.

@mayukojpn
20 months ago

#1 @mayukojpn
20 months ago

  • Keywords has-patch added

#2 @mayukojpn
20 months ago

  • Version changed from trunk to 4.4

@mayukojpn
20 months ago

With this bug description field is also invalid on front.

#3 @johnbillion
20 months ago

  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 4.5

#4 @Toro_Unit
18 months ago

To the description, post type description should be input by default.

<?php

class SampleTest extends WP_UnitTestCase {
        /**
         * @var int
         */
        public $menu_id;

        function setUp() {
                parent::setUp();

                $this->menu_id = wp_create_nav_menu( rand_str() );
        }

        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-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!!!
                
        }
}

Add new patch and Detailed test.

Last edited 18 months ago by Toro_Unit (previous) (diff)

@Toro_Unit
18 months ago

@Toro_Unit
18 months ago

#5 @Toro_Unit
18 months ago

Sorry 35324-2.patch​ is broken. Please Try 34324-3.patch.

@Toro_Unit
18 months ago

Add Support nav_menu_description filter.

#6 @Toro_Unit
18 months ago

  • Keywords has-unit-tests added

#7 @mayukojpn
18 months ago

Thanks Toro_Unit for unit test!

I like your approach, but if CPT has own description, your function will overwrite menu item description even though I want to leave it empty.

Can we fix a bug this time and discuss it at new ticket?

@mayukojpn
18 months ago

@mayukojpn
18 months ago

last file was wrong file format, sorry!

#8 @extendwings
18 months ago

  • Keywords needs-testing removed

Tested 35324-6.diff with trunk, and works well.

#9 @ocean90
18 months ago

#35861 was marked as a duplicate.

#10 @mayukojpn
18 months ago

For anyone who is faced with this bug:
I made a plugin to fix this bug. Try this until the patch is merged.
https://gist.github.com/mayukojpn/6ef62c39dcf48c17ed96

#11 @jorbin
18 months ago

  • Owner set to jorbin
  • Status changed from new to assigned

#12 @jorbin
18 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 36859:

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.

#13 @bradyvercher
18 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

36859 throws a notice when an archive menu item exists for a post type that is no longer registered. 35324.7.diff prevents the notice and adds a test for unregistered post types.

#14 @DrewAPicture
18 months ago

35324.7.diff looks good, thanks @bradyvercher.

#15 @DrewAPicture
18 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 36888:

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.

Note: See TracTickets for help on using tickets.