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: mikeschinkel 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:

http://screenshots.newclarity.net/skitched-20111029-142108.png

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)

  • 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.3 to 3.2

comment:3 follow-up: ↓ 4   ocean9019 months ago

  • Version changed from 3.2 to 3.1

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

Last edited 19 months ago by ocean90 (previous) (diff)

comment:4 in reply to: ↑ 3   mikeschinkel19 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?

Version 0, edited 19 months ago by mikeschinkel (next)
Note: See TracTickets for help on using tickets.