Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#4907 closed defect (bug) (fixed)

add_menu_page() create faulty links

Reported by: markjaquith Owned by: markjaquith
Milestone: 2.5 Priority: high
Severity: major Version: 2.3
Component: General Keywords: has-patch needs-testing
Focuses: Cc:


Plugin Name: Menu Test

function cws_add_menu() {
	add_menu_page("Top Level Page", "Top Level Page", 'read', 'cws-top-level-page', 'cws_top_level_page');

function cws_top_level_page() {
	echo "<p>Top Level Page!</p>";

add_action('admin_menu', 'cws_add_menu');


Top level link to "admin.php?page=cws-top-level-page"

Actual result:

Top level link to "cws-top-level-page" (404)

Accessing the correct link manually works.

Attachments (1)

4907.diff (2.2 KB) - added by DD32 13 years ago.

Download all attachments as: .zip

Change History (6)

#1 @markjaquith
14 years ago

  • Milestone changed from 2.3 to 2.4 (next)
  • Owner changed from anonymous to markjaquith
  • Status changed from new to assigned

Seems that for the top level, you need to point to a valid plugin file. For plugins within the plugins directory, FILE works. For plugins outside, you can use a relative path to find the plugins.

Really funky. If it doesn't have ".php" we should just use the string as-is.

#2 @westi
14 years ago

This sounds familiar.
Maybe a due of an earlier ticket.
I will have a search as I recall looking at this before.
I think it exists as example code on the codex as well!

#3 @markjaquith
14 years ago

Yep, it's in the codex. But it didn't work in 2.0 or 2.1 (didn't try 1.5).

#4 @DD32
13 years ago

  • Keywords has-patch needs-testing added

There seems to be a lot of code in the admin menu generation, I'd be supprised if it cant be slimmed down a tad-bit, But its over my head what most of it seems to do.

Regardless, I've spent awhile trying to work out this bug, I was initially supprised to find it considering the plugins i've been writing that use top level menu's have worked perfectly. It seems thats generally because i set '$file' to either the foldername or the files name..

Added a check to the Main plugin section list to check for a callback for the given page. Had to hard-code 'admin.php' into the hook check, I couldnt see any other way about it.

I've tested the patch with a few combinations i could think of, and everything seems to work as expected, However definately needs testing with other combinations.

13 years ago

#5 @westi
13 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [7183]) Work harder to create the correct links for new top level menus. Fixes #4907 props DD32.

Note: See TracTickets for help on using tickets.