[wp-hackers] Stumped by WordPress' Admin Menus

Mike Schinkel mikeschinkel at newclarity.net
Mon Jan 10 22:32:04 UTC 2011


Hi all,

I'm really hoping one of you can help me solve this problem I am having with the Admin Menu system. Honestly if I didn't know better I'd think that a gremlin was living inside it and actively doing it's best to thwart my every move.

Although there are other issues I've had with the admin menu system (described here[1]) the problem I am having today is that the menu_page seems to inherit the first URL from the submenu_page and no matter what I try I can't get them decoupled. To illustrate the point I've created a very simple example:

add_action('admin_menu','my_admin_menu');
function my_admin_menu() {
	global $submenu;
	unset($submenu['edit.php'][5]);    // Remove 'Posts'
	unset($submenu['edit.php'][10]);   // Remove 'Add New'
	$submenu['edit.php'][15][0] = 'Post Categories';
	unset($submenu['edit.php'][16]);   // Remove 'Post Tags'
}

Here is a screenshot that illustrates the problem:

http://mikeschinkel.com/websnaps/skitched-20110110-165648.png

I was actually able to solve the problem with the following although it's extremely fragile and incredibly hackish; I'm really hoping someone can suggest a more robust alternative:

add_filter('parent_file','my_parent_file');
add_action('adminmenu','my_adminmenu');
function my_parent_file($parent_file) {
	ob_start();
	return $parent_file;
}
function my_adminmenu() {
	$menu = ob_get_clean();
	$parts = explode('edit-tags.php?taxonomy=category',$menu);
	$end = array_pop($parts);
	$menu = implode('edit.php',$parts) . 'edit-tags.php?taxonomy=category' . $end;
	echo $menu;
}

Looking forward to being told I'm a sod and that there is a much easier way to solve this problem.  Thanks in advance.

-Mike

[1] http://andrewnacin.com/2010/12/20/better-admin-menu-controls-custom-post-types-wordpress-3-1/#comment-6377

P.S. Also, here are two track tickets I added the other day that could potentially address the problem with two different angles if there is no solution:

http://core.trac.wordpress.org/ticket/16048
http://core.trac.wordpress.org/ticket/16050




More information about the wp-hackers mailing list