Reputation: 227
I am trying to create an admin menu for my plugin.
$my_hook = add_menu_page(
'String',
'String',
'manage_options',
'mypage&type=mytype',
'my_function'
);
If i try to acces the page now at
wp-admin/admin.php?page=mypage&type=mytype
via the menu, i get: "You do not have sufficient permissions to access this page.". Is it not possible to include GET parameters like &type=mytype in the menu entry?
Thanks.
Upvotes: 0
Views: 5876
Reputation: 33
You can do something like this to add new menu item
$my_hook = add_menu_page(
'String',
'String',
'manage_options',
'?page=pagename',
'my_function'
);
Upvotes: 0
Reputation: 1685
For manage_options
is a requiered option that specify the capability for this menu to be displayed to the user. more details...
you put the role wich has the sufficient permissions to access or manage this page.
You can try this:
$my_hook = add_menu_page(
'String',
'String',
'administrator',
'mypage&type=mytype',
'my_function'
);
Upvotes: 0
Reputation: 26055
I can't tell for sure why trying to add parameters to a Menu or Submenu slug invalidates the generated link. But the $menu_slug
is used in both functions add_menu_page
and add_submenu_page()
to search of a PHP file (instead of the function callback) and to build the plugin URL.
Trying to add the extra operators ?
or &
does not play nice, ie, it doesn't work either with plugin_basename
or get_plugin_page_hookname
.
Here's a workaround to use the same callback function with various top level admin menus. The URL's will be:
and the callback function checks for $_GET['page']
.
add_action( 'admin_menu', 'menu_so_17406309' );
function menu_so_17406309()
{
add_menu_page(
'First',
'First',
'manage_options',
'myplugin1',
'callback_so_17406309'
);
add_menu_page(
'Second',
'Second',
'manage_options',
'myplugin2',
'callback_so_17406309'
);
}
function callback_so_17406309()
{
switch( $_GET['page'] )
{
case 'myplugin1':
echo 'first page';
break;
case 'myplugin2':
echo 'second page';
break;
default:
echo 'error';
break;
}
}
Relevant search query at WordPress Answers.
Upvotes: 2