WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#13912 closed defect (bug) (worksforme)

Not aware of post_type so "wp-has-current-submenu" get assigned incorrectly

Reported by: benjitastic Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: General Keywords:
Focuses: Cc:

Description

Using: WP 3.0 RC3

I am creating a plugin and adding 2 submenu pages to appear under two custom content types ('Cars' and 'Trucks'). The issue is that Wordpress assigns the "wp-has-current-submenu' to the first "edit.php" admin sidebar nav item even when another is selected.

add_submenu_page('edit.php?post_type=cars', "Details", "Details", $minlevel,  __FILE__, 'main_details');

add_submenu_page('edit.php?post_type=trucks', "Details", "Details", $minlevel,  __FILE__, 'main_details');

So when I click "Details" under "Trucks" the post_type "Cars" menu item still receives the "wp-has-current-submenu" CSS class.

It looks like the menu needs to be aware of &post_type when assigning the current "wp-has-current-submenu" class instead of just placing it on the first edit.php?post_type.

In the attached screenshot the "Details" page under "Trucks" is active but the "wp-has-current-submenu" class is getting placed on "Cars".

http://i.imgur.com/DQfJy.png

Change History (4)

#1 follow-up: @nacin
10 years ago

I would imagine it is due to your use of the same value, FILE, in the $menu_slug parameter, which needs to be unique.

#2 in reply to: ↑ 1 ; follow-up: @benjitastic
10 years ago

Replying to nacin:

I would imagine it is due to your use of the same value, FILE, in the $menu_slug parameter, which needs to be unique.

Thanks for the quick reply nacin.

The problem is that I am looping through all post_type and adding a menu item under each. It would be tricky to have a unique menu_slug for each since there is not a defined number of post_type and I would like every sub nav item to point to the main .php plugin file - 'FILE'.

foreach(get_post_types('','names') as $r) {
	if(!in_array($r, $excludedPostTypes)) {
		add_submenu_page('edit.php?post_type='.$r.'', "Reorder", "Reorder", $minlevel,  __FILE__, 'reorder_ui');
	}
}	

Do you have any idea how I could accomplish this?

Thanks!

#3 in reply to: ↑ 2 @nacin
10 years ago

Replying to benjitastic:
It would be tricky to have a unique menu_slug for each since there is not a defined number of post_type and I would like every sub nav item to point to the main .php plugin file - 'FILE'.

That's not what FILE is for. That's what your callback is for.

It would be easy to have a menu_slug that is unique, simply use the post_type and add a prefix or something.

#4 @nacin
10 years ago

  • Milestone Unassigned deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.