Ticket #4907 (closed defect (bug): fixed)

Opened 4 years ago

Last modified 4 years ago

add_menu_page() create faulty links

Reported by: markjaquith Owned by: markjaquith
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

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

Change History

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

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.

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!

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

comment:4   DD324 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.

DD324 years ago

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

(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.