WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#19125 closed defect (bug) (fixed)

CPT as a submenu item does not get the correct classes when adding new

Reported by: helenyhou Owned by: nacin
Milestone: 3.3 Priority: low
Severity: normal Version: 3.3
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

If you register a post type as a submenu item, the parent item does not get the appropriate classes when adding a new item, nor does the submenu item itself. This causes the menu to not be expanded. It is fine when on the list table or editing an existing item, and when the CPT has its own menu item. It seems that $typenow is not being set somehow in just this case.

Attachments (2)

19125.diff (969 bytes) - added by nacin 3 years ago.
19125.2.diff (970 bytes) - added by nacin 3 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 @nacin3 years ago

It's $parent_file not being set properly. I was playing with this last week, but I was struggling to ascertain whether it was a valid bug fix. Patch incoming that *would* fix it.

@nacin3 years ago

comment:2 follow-up: @nacin3 years ago

It should be noted that with 19125.diff, there won't be any submenu added, unless you call add_submenu_page() manually for the post-new.php?post_type=$post_type file.

Or, if you want the main submenu selected, you'd want $submenu_file to equal that edit.php page.

Because this wasn't implemented originally, I'd be somewhat hesitant to do it now. Then again, I think it can be done in a backwards compatible way, as any developer wanting to customize this would set $submenu_file and $parent_file later on. (Or we could wrap it in an isset()).

comment:3 in reply to: ↑ 2 @helenyhou3 years ago

Replying to nacin:

It should be noted that with 19125.diff, there won't be any submenu added, unless you call add_submenu_page() manually for the post-new.php?post_type=$post_type file.

Not quite sure I understand what you mean by this?

Because this wasn't implemented originally, I'd be somewhat hesitant to do it now.

I think it just became more noticeable because menus do not stay expanded anymore, so it's less clear where you are in the admin. You are right, though - it doesn't work in 3.2.1 (or previous) either.

comment:4 @nacin3 years ago

Should have said:

It should be noted that with 19125.diff, there won't be any submenu highlighted, unless you call add_submenu_page() manually for the post-new.php?post_type=$post_type file (and give it something to highlight).

comment:5 @nacin3 years ago

  • Milestone changed from Awaiting Review to 3.3

I want to fix part of this now.

comment:6 @nacin3 years ago

I want to fix $parent_file on post-new.php. The $submenu_file is a separate fix we could probably go through with -- especially since if a plugin is correcting it, they'll just override the value anyway -- but it could wait.

comment:7 @CoenJacobs3 years ago

  • Cc coenjacobs@… added

comment:8 @sabreuse3 years ago

  • Cc sabreuse@… added

comment:9 @nacin3 years ago

  • Keywords has-patch added

comment:10 @nacin3 years ago

In [19374]:

Set $parent_file for post-new.php when show_in_menu is a file. Provides for correct top-level highlighting. $submenu_file remains set to expect a post-new.php menu. see #19125.

comment:11 @nacin3 years ago

  • Component changed from General to Post Types

Ideally, $submenu_file should be set to post-new.php?post_type=$post_type if that's been added, and otherwise be set to edit.php?post_type=$post_type. Since admin_menu has already been fired, there's probably the ability to check for this in a semi-sane way. Here's a patch for review.

@nacin3 years ago

comment:12 @ryan3 years ago

  • Priority changed from normal to low

comment:13 @nacin3 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [19425]:

Select the submenu item for post-new.php when using show_in_menu = 'some-parent-file' for post types. Continue to select the post-new.php submenu item if it has been separately added with add_submenu_page(). fixes #19125.

Note: See TracTickets for help on using tickets.