Opened 19 months ago
Last modified 19 months ago
#19085 new defect (bug)
Removing First Submenu Page in Admin Menu breaks URL for Menu Page
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Administration | Version: | 3.1 |
| Severity: | major | Keywords: | needs-patch |
| Cc: | mikeschinkel@… |
Description
If you attempt to remove the Post Type Submenu Page in the Admin it breaks the Menu Page URL; it causes the Menu Page URL to be the same as the new first Submenu Page URL:
Here is a simple class you can drop into the theme's functions.php file to experience this bug. This example is a minimum to trigger the error (I simplified the register_post_type() call so the example code would have fewer lines):
<?php
class Trigger_Admin_Menu_Bug {
static function on_load() {
add_action( 'init', array( __CLASS__, 'init' ) );
add_action( 'parent_file', array( __CLASS__, 'parent_file' ) );
}
static function init() {
global $wpdb;
register_post_type( 'test-cpt', array(
'label' => 'Test CPT',
'show_ui' => true,
));
}
static function parent_file( $parent_file ) {
remove_submenu_page( 'edit.php?post_type=test-cpt',
'edit.php?post_type=test-cpt' );
return $parent_file;
}
}
Trigger_Admin_Menu_Bug::on_load();
I'd provide a patch but the admin menu code is more complex than I can fully understand. Maybe the person who originally wrote it could fix it?
Note: Sadly, this is a blocker for one of my client projects. The client wants the admin menus simplified to reduce the conceptual load on their end users because we are adding many other submenu pages. Plus I've traced through the core WP code with a debugger for many hours looking for hooks that would allow me to get around this issue, but there simply are no hooks where it would be needed to hack a fix for this.
Change History (4)
comment:1
mikeschinkel — 19 months ago
- Cc mikeschinkel@… added
- Summary changed from Deleting First Submenu Page in Admin Menu breaks URL for Menu Page to Removing First Submenu Page in Admin Menu breaks URL for Menu Page
- Version changed from 3.2 to 3.1
comment:4
in reply to:
↑ 3
mikeschinkel — 19 months ago
Replying to ocean90:
"If the first submenu is not the same as the assigned parent, make the first submenu the new parent."
http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/menu.php#L74
Ugh. Good catch.
Obviously unintended side effects?
BTW, that is not the only place that takes control of the admin menus. The _wp_menu_output() function also outputs things that are different from what's in the global $submenu array. I know this because I tried to fix the $submenu array in the 'parent_file' hook, but that only made matters worse.


This also happens for the default post post type.
add_action( 'admin_menu', 'ds_remove_first' ); function ds_remove_first() { remove_submenu_page( 'edit.php', 'edit.php' ); }"If the first submenu is not the same as the assigned parent, make the first submenu the new parent."
http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/menu.php#L74