I have the following function which creates the menus in the admin area for my plugin.
function register_menu_items() {
add_menu_page(null, 'Ebay Motors', 'manage_options', 'ebay-motors-admin', array($this, 'ebay_motors_admin'));
add_submenu_page( 'ebay-motors-admin', 'Upload XML', 'Upload XML', 'manage_options', 'upload-xml', array($this, 'upload_xml'));
add_submenu_page( 'ebay-motors-admin', 'Archive XML', 'Archive XML', 'manage_options', 'archive_xml', array($this, 'archive_xml'));
}
This works, however (expectedly) the main menu item also creates a sub-menu item. Is there a way to create the main menu item without intern creating a submenu item. I'd also like the Main Menu item to link straight to the upload_xml function.
You can set the slug of your sub menu to be the same of the main menu item. This way you can overwrite the first menu item.
Related
I'm currently developing my first plugin in WordPress. Since it's a admin only plugin I only need admin panel things.
I've started creating the plugins menu in the left panel:
I've did this by defining the main page and a submenu page:
add_menu_page( 'My Plugin', 'My Plugin', 'edit', 'my-plugin', null, 'none', '58' );
add_submenu_page( 'my-plugin', 'Settings','Settings', 'edit', 'my-plugin-settings', [
$this,
'settings_page'
] );
Now I have a submenu with 2 entries. So far so good but I want to change the default submenu page of my plugin to Dashboard instead of the plugins name. I can't find anything in the docs so maybe someone of you knows the trick.
You can't change the name of the main entry in the submenu - add_menu_page only lets you set the page title and the main menu title.
What you can do instead is add a new item to the submenu for the main page. Add a new menu item using add_submenu_page, and use the same slug you used in add_menu_page as both the $parent_slug and $menu_slug parameters, e.g.
$plugin_base_slug = 'my-plugin';
add_menu_page( 'My Plugin', 'My Plugin', 'edit', $plugin_base_slug, null, 'none', '58' );
/* Replace the main menu page in submenu with the menu item "Dashboard" */
add_submenu_page( $plugin_base_slug, 'Dashboard', 'Dashboard', 'edit', $plugin_base_slug, null);
/* Add the rest of your submenu pages */
add_submenu_page( $plugin_base_slug, 'Settings','Settings', 'edit', 'my-plugin-settings', [
$this,
'settings_page'
] );
This will replace the main page menu in the submenu (i.e. the one called My Plugin in your example) with the new one you create in add_submenu_page (called Dashboard in this example).
Just make sure you use the same capability and function in your new submenu item so that it does the same thing as the main menu page.
I'm using the following code to create a admin menu in wordpress:
add_menu_page(
"Deliverables",
"Deliverables",
"manage_options",
"deliverables",
"deliverable_create_deliverables_page"
);
add_submenu_page(
'deliverables',
'Review Submissions',
'Review Submissions',
'manage_options',
'manage_deliverables',
'deliverable_create_review_page'
);
This results in a menu that has the following structure:
+ Deliverables
+-- Deliverables
+-- Review Submissions
I.e. There will be a top level menu, and the name of the first sub menu item will be the same as the top menu name. How can I make sure I get to name all the submenu items? I would like the menu to look like this:
+ Deliverables
+-- Manage Deliverables
+-- Review Submissions
This can be done by removing callback function from add_menu_page and placing that callback in add_submenu_page for top level page.
add_menu_page(
"Deliverables",
"Deliverables",
"manage_options",
"deliverables"
);
add_submenu_page(
'deliverables',
'Manage Deliverables',
'Manage Deliverables',
'manage_options',
'deliverables',
'deliverable_create_deliverables_page'
);
add_submenu_page(
'deliverables',
'Review Submissions',
'Review Submissions',
'manage_options',
'manage_deliverables',
'deliverable_create_review_page'
);
Is it possible to add a new admin menu to the woocommerce admin section in Wordpress?
I've done this with WP E-commerce with my custom plugin so am wandering if the same is true for Woo commerce.
Thanks
Well, if you use something like this:
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_submenu_page( 'woocommerce', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
}
function my_custom_submenu_page_callback() {
echo '<h3>My Custom Submenu Page</h3>';
}
Then you will see a submenu under "Woocommerce" admin menu. For some reason you can´t do same using post_type=shop_order.
"shop_order" is the one you should use to put a submenu under "Woocommerce" one.. but, as i said, don´t know why didn´t work with that particual post_type.
http://codex.wordpress.org/Function_Reference/add_submenu_page
For me the following worked:
add_submenu_page(
'edit.php?post_type=product',
PAGE_TITLE,
MENU_TITLE,
'manage_woocommerce',
'custom_wc_menu'
);
Setting the $parent_slug to edit.php?post_type=product
I need to create a new menu and a sub menu item for the wordpress administrators. The menu is working fine but the sub menu items ( a duplicate sub menu for the main menu item is being created automatically.. I don't want that ). Both the sub menu items has their href attribute blank. I don't understand what the menu slug is. Please help..
// create custom plugin settings menu
add_action('admin_menu', 'retail_create_menu');
function retail_create_menu() { //create new top-level menu
add_menu_page('Retailers', 'Retailers', 'administrator', __FILE__, 'generate_retailer_list', 'http://localhost/apsm/wp-content/themes/wp-mediamag/functions/retail.ico');
add_submenu_page( __FILE__, 'Add Retailers', 'Add Retailers', 'administrator', 'add_ratilers.php', 'retailer_submenu_callback');
}
The file are inside a folder in my theme...
One simple hack to hide that duplicate menu:
add_submenu_page(
'__FILE__', // parent slug, same as main menu slug
'', // empty page title
'', // empty menu title
'administrator', // same capability as parent
'__FILE__', // same menu slug as parent slug
'generate_retailer_list', // same function as parent
)
So what i mean by the above is. I've so far made many plugins but i keep getting this issue which i don't know how to describe and that is why i cant search it on google.
What happen is in many plugin a main menu is required and under it several sub-menus that leads to different pages related to the plugin. you can click on the main menu lets say "car" and that will take you to a add car page. and there will also be a sub-menu called add car.
like: posts - when you click on posts for example it takes you to all post, but there is also a sub-menu that is called all post.
What i am having problem with is the main menu is named one thing and when hover it the first sub-menu is also called the same.
My question is:
How can i make it so that either when creating a main menu it will not automatically add a sub menu or if it does. the name will be different then the main menu.
I hope the explanation is clear - i really tried.
Here is how i define my menus:
function my_plugin_menu() {
add_menu_page( 'add_deal', 'Add Deal', 'manage_options', 'add_deal', 'menuload_add_deal', '', '28');
add_submenu_page( 'add_deal', 'deals', 'Deals', 'manage_options', 'deals', 'menuload_deals');
add_submenu_page( 'add_deal', 'orders', 'Order', 'manage_options', 'orders', 'menuload_orders');
add_submenu_page( 'add_deal', 'gc_options', 'Options', 'manage_options', 'gc_options', 'menuload_gc_options');
}
add_action( 'admin_menu', 'my_plugin_menu' );
The above now display for me:
Add Deal - //opens add deal page
Deals
Orders
Options
I would like to change it to:
Shopping Cart - //opens add deal page
add deal - //opens add deal page
deals
orders
options
Ones again i hope that makes sense.. not trying to waste anyone's time but that's why its so hard for me to find info on googble about this issue. (i don't know how to describe the problem well).
I've found a solution incase anyone interested:
function my_plugin_menu() {
add_menu_page( 'add_product', 'Bass Nation', 'manage_options', 'bass-nation-real-shopping-cart', 'menu_load_add_product', '', '28');
add_submenu_page( 'bass-nation-real-shopping-cart', 'add_product', 'Add Product', 'manage_options', 'bass-nation-real-shopping-cart', 'menu_load_add_product');
add_submenu_page( 'bass-nation-real-shopping-cart', 'products', 'Products', 'manage_options', 'products', 'menu_load_products');
add_submenu_page( 'bass-nation-real-shopping-cart', 'orders', 'Orders', 'manage_options', 'orders', 'menu_load_orders');
add_submenu_page( 'bass-nation-real-shopping-cart', 'bnrsc_options', 'Options', 'manage_options', 'bnrsc_options', 'menu_load_options');
}
add_action( 'admin_menu', 'my_plugin_menu' );
You just name the first sub menu's slugen same as the main menu.
Hope this helps someone out there.