Ticket #4907 (closed defect (bug): fixed)
add_menu_page() create faulty links
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | high | Milestone: | 2.5 |
| Component: | General | Version: | 2.3 |
| Severity: | major | Keywords: | has-patch needs-testing |
| 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
Change History
comment:1
markjaquith — 4 years ago
- Owner changed from anonymous to markjaquith
- Status changed from new to assigned
- Milestone changed from 2.3 to 2.4 (next)
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!
comment:3
markjaquith — 4 years ago
Yep, it's in the codex. But it didn't work in 2.0 or 2.1 (didn't try 1.5).
- 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.