How to pass any arguments to an admin page via a new admin menu item?
-
For a plugin I’m writing I need to add a sub menu item to the Comments menu in admin dashboard.
No problem doing this with:
add_submenu_page('edit-comments.php',__('Comments'), 'Aggiungi Commento', 'edit_posts', 'dashboard-write-comments.php', 'write_comment_page');
But I need to pass an argument to the page that I’m calling (let say that I need to pass the post id).
I can’t find a way to do this without raising an error.
If I add any other value to the “file” argument of the add_submenu_page() funcion, WordPress trow out an “You do not have sufficient permissions to access this page.” error.
Example:add_submenu_page('edit-comments.php',__('Comments'), 'Aggiungi Commento', 'edit_posts', 'dashboard-write-comments.php&post='.$post_id, 'write_comment_page');
I tried both
dashboard-write-comments.php&post='.$post_id
anddashboard-write-comments.php?post='.$post_id
without any luck.I checked the core WP files and looks like that the error is triggered in wp-admin/menu.php, at the very end of the file, where it doeas a check with
user_can_access_admin_page()
Can’t understand why if the “link” has no arguments the “can access admin page” is ok but when I add any argument the check stop everithing…
Anyone can help? or suggest an other way?
-
firstly, try to change the capability into ‘read’(the lowest), to see if the problem is really about user capability
but i think the error is more because wordpress failed to initiate $menu. you can debug it by using $global $menu, $submenu to see if your plugin url has been written in the array.
i assume your problem here,
dashboard-write-comments.php&post='.$post_id
i don’t know. I never really have to create such menu url. But i have voodoo here without really know what going on in the core. such as
$url = get_bloginfo('url'); $urllogout = wp_logout_url($url); $urllogout = str_replace($url , "", $urllogout); add_menu_page('mylogout', 'Logout', 'read', "../" . $urllogout , '' );
As you can see i make custom log_out link menu for subscriber here. and it also has value _wpnonce variabel on its url string…
i love to hear your work around, 🙂
Thanks for your help!
Changed the capabilty to ‘
read
‘, but still the same error.
I can confirm that the sub-menu item is initiated: it show in the menues, I can click on it; I also performed the check you suggested withprint_r($submenu);
and it’s ok.I’m pretty confident that the problem is about some sort of wp_nonce that the system can’t validate from one admin page to another if I add some arguments to the menu url link…
Any other idea is really appreciated
Stefano
print_r($submenu); and it’s OK.
by the way, have you check how the $submenu value and its array. where is the url head, the function handle, etc. For example here
Array ( [0] => BuddyPress [1] => 10 <strong>[2] => bp-general-settings</strong> [3] => BuddyPress [4] => menu-top toplevel_page_bp-general-settings menu-top-last [5] => toplevel_page_bp-general-settings [6] => images/generic.png )
where is your submenu url ?
How about using “?” as the $_get value.
dashboard-write-comments.php?post=’.$post_id
Surely, i can not help more. but what i believe those menu is hide in option as serialized value (just like role and capability). i also don’t understand yet how those serialized value decode/encode behind the core.
I’ll try as soon I’ll come back tu the office…
thanks for your help!STefano
So what’s up ?
I ‘ve same problem here …
Did you find your solution ?
- The topic ‘How to pass any arguments to an admin page via a new admin menu item?’ is closed to new replies.