How to add more than 1 user role to sub-menu pages

The easiest way is create 2 custom capabilities and assign both to administrators, one to role coach and one to role player. When you create your roles you do something like this: $coach_caps = array( ‘read’ => true, ‘something_else’ => true, ‘can_open_coach_menu’ => TRUE // this is important for your scope ); add_role( ‘coach’, ‘Coach’, … Read more

Hooking into add_submenu_page

Hook into admin_head, the last action before the menu is rendered, and change the global $menu: add_action( ‘admin_head’, ‘wpse_71303_change_menu_cap’ ); /** * Change the capability to access an admin menu item. * * @wp-hook admin_head * @return void */ function wpse_71303_change_menu_cap() { global $menu; foreach ( $menu as $key => $item ) { // Find … Read more

Add Settings to Custom Post Type

Ok, so I got annoyed with it not working and decided to just rewrite it. I’m not sure what the solution was, but I suspect two things: the wrong endpoint for the form (should be options.php) and the wrong $option_group and $option_name (they were probably not matched correctly). For posterity, I’ll leave my rewrite here … Read more

The seventh parameter passed to add_submenu_page()

I was able to track this down to the culprit function add_theme_page(). There There was an additional parameter, per the codex for add_theme_page() that needed to be removed. Removing that seemed to help. function fivehundred_register_admin_menu() { add_theme_page( ‘500 Settings’, ‘500 Settings’, ‘manage_options’, ‘theme-settings’, ‘fivehundred_admin_menu’, plugins_url( ‘/ignitiondeck/images/ignitiondeck-menu.png’ ) ); } add_action( ‘admin_menu’, ‘fivehundred_register_admin_menu’ ); Fixed code … Read more

Menu capability in WordPress

Capability parameter of add_submenu_page() function can only take a single capability, so if you are using the built in roles you can select a capability fro the long list that both administrators and editors have any of these (use any of these freely): moderate_comments manage_categories manage_links unfiltered_html edit_others_posts edit_pages edit_others_pages edit_published_pages publish_pages delete_pages delete_others_pages delete_published_pages … Read more

How to add a child item to a menu element (using wp_nav_menu_objects)

The WordPress functions changed since the answers here in 2014. As of today (Version 4.6.1) this code will create a main menu named “My Menu” , main item and sub item. To run code just paste and saves in your functions.php file in your child theme. $menu_id = wp_create_nav_menu(‘My Menu’); $parent_item = wp_update_nav_menu_item($menu_id, 0, array( … Read more

How to give position to Submenu under custom post type

If you connect your functions with proper hooks your submenu page will be displayed after your post type and taxonomy. Take a look at my example: /** * Register event post type * * Function is used by init hook */ function wpse_288373_register_event_post_type() { $labels = array( ‘name’ => __( ‘Events’ ), ‘singular_name’ => __( … Read more

How to link a Custom Post Type submenu to a Nextgen Gallery page?

It would go like this (note the absence of the function parameter – and also the capability instead of a role). add_action( ‘admin_menu’, ‘wpse_74421_menu_admin’ ); function wpse_74421_menu_admin() { add_submenu_page( ‘edit.php?post_type=events’, ‘Add Gallery’, ‘Add Gallery’, ‘delete_plugins’, ‘admin.php?page=nggallery-add-gallery’ ); }

How to create sub menu with a URL parameter?

You’d have to manipulate the global $submenu and modify the link in it. Or use jQuery. The following example adds a submenu in the Dashboard menu and changes the destination link just after. The submenu page will dump the contents of the global var. add_action( ‘admin_menu’, function() { add_submenu_page( ‘index.php’, ‘Sandbox Options’, ‘Options’, ‘administrator’, ‘sandbox_options’, … Read more

add_submenu_page not working

Make sure that your add_action hook is set to admin_menu. Here’s a sample code: add_action(‘admin_menu’, ‘wpse149688’); function wpse149688(){ add_menu_page( ‘Wholesale Pricing’, ‘Wholesale’, ‘manage_options’, ‘woo-wholesale’, ‘woo_wholesale_page_call’); add_submenu_page( ‘woo-wholesale’, ‘Registrations’, ‘Registrations’, ‘manage_options’, ‘woo-wholesale-registrations’, ‘wwpr_page_call’ ); } Also check whether user you’ve logged in as has the ability to view this menu. As this menu is set using … Read more