Opened 17 years ago
Closed 16 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: |
Description
<?php /* 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'); ?>
Expected:
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)
Change History (6)
#1
@
17 years ago
- Milestone changed from 2.3 to 2.4 (next)
- Owner changed from anonymous to markjaquith
- Status changed from new to assigned
#2
@
17 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!
#4
@
16 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.
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.