There is plugin called Shopp in my WP admin page , this plugin has got top level menu “Shopp” .
This is the top level menu:
$menus['main'] = add_menu_page('Shopp', 'Shopp', SHOPP_USERLEVEL, 'shopp-orders', array(&$this,'orders'));
And I’ve created some plugin which need to add as submenu under “Shopp” top level menu , so it is adding sub menu ( link …..wp-admin/admin.php?page=ach-faq.php ) but when I am clicking on submenu it shows “You do not have sufficient permissions to access this page.”
Debug result:
Pagenow = admin.php
Parent = shopp-orders
Hookname = shopp_page_ach-faq
Menu = Array
Submenu = Array
Menu nopriv = Array
Submenu nopriv =
Plugin page = ach-faq.php
Registered pages =
My code:
function ach_faq_menu(){
add_submenu_page('shopp-orders', 'My FAQ Plugin', 'My FAQ Plugin', 8, __FILE__, 'section_1');
}
function section_1(){
echo 'Text';
}
add_action('admin_menu', 'ach_faq_menu');
How can I fix this ? Please help me !
Menu and submenu pages should be called at the same time, and use the same slugs. For example
This would result in a top-level menu “My Menu” with a child of “My Submenu”.
The invalid permissions error seems to crop up when you use FILE for the submenu-slug.
To add it on one of the plugin’s parent menu, use add_submenu_page() and set the priority of your add_action() to lower i.e, above 10.
Then in add_submenu_page(), replace ‘plugin-parent-menu-slug’ with the slug of the parent menu where you want it to add. Example, you want to add it under an admin page with a slug /wp-admin/admin.php?page=plugin-parent-menu-slug.
You can add submenu to existing custom menu (added by other plugin) with little bit tricky
you can create menu and then remove the menu itself after you add submenu with same slug and callback.
Please try this code:
As Altari stated:
SAME TIME – add_submenu_page must be called from same function as add_menu_page, the function in original plugin. You can not “hack” into another plugins menu from outside of it.
You can by adding the plugin folder name and the home page of the plugin.
For example I hooked to the Newsletter plugin by:
Go to Appearance -> Menus
Then Create Menu under Custom Links, then a new menu created in right side. Now you can just drag that and put under which top level menu you want.