1

I have added some custom menu using add-menu_page and it is working perfectly with the default administrator admin bar. But when I log in to different user roles, they are not showing. My question is how to show different menu items for different users.

I have added these codes to my plugin main function.php file

function custom_admin_menu()
{
    global $menu, $submenu;
    
    $icon = get_option('cqpim_use_default_icon');
    if(empty($icon)) {
        $adicon = PTO_PLUGIN_URL . '/img/icon.png';
    } else {
        $adicon = '';
    }
    
    // My work
    add_menu_page('My Work', 'My Work', 'read', 'custom-slug', '', $adicon, 28);
    $submenu['custom-slug'][] = array('My Messages', 'manage_options', admin_url().'admin.php?page=pto-messages');
    $submenu['custom-slug'][] = array('All Messages (Admin)', 'manage_options', admin_url().'admin.php?page=pto-messages-admin');
    $submenu['custom-slug'][] = array('My Tasks', 'manage_options', admin_url().'admin.php?page=pto-tasks');
    $submenu['custom-slug'][] = array('My Calender', 'manage_options', admin_url().'admin.php?page=pto-calendar');
    $submenu['custom-slug'][] = array('All Tasks (Admin)', 'manage_options', admin_url().'admin.php?page=pto-alltasks');
    $submenu['custom-slug'][] = array('All Files (Admin)', 'manage_options', admin_url().'admin.php?page=pto-files-admin');
    // Leads
    add_menu_page('Leads', 'Leads', 'read', 'custom-leads', '', $adicon, 29);
    $submenu['custom-leads'][] = array('Leads', 'manage_options', admin_url().'edit.php?post_type=cqpim_lead');
    $submenu['custom-leads'][] = array('Lead Forms', 'manage_options', admin_url().'edit.php?post_type=cqpim_leadform');
    // Clients
    add_menu_page('Leads', 'Clients', 'manage_options', '', '', $adicon, 30);
    $menu[30][2] = admin_url().'edit.php?post_type=cqpim_client';
    // Quotes
    add_menu_page('Quotes', 'Quotes', 'read', 'custom-quotes', '', $adicon, 31);
    $submenu['custom-quotes'][] = array('Quotes', 'manage_options', admin_url().'edit.php?post_type=cqpim_quote');
    $submenu['custom-quotes'][] = array('Quote Forms', 'manage_options', admin_url().'edit.php?post_type=cqpim_forms');
    $submenu['custom-quotes'][] = array('Milestone / Task templates', 'manage_options', admin_url().'edit.php?post_type=cqpim_templates');
    // Projects
    add_menu_page('Projects', 'Projects', 'read', 'custom-projects', '', $adicon, 32);
    $submenu['custom-projects'][] = array('Projects', 'manage_options', admin_url().'edit.php?post_type=cqpim_project');
    $submenu['custom-projects'][] = array('Terms Templates', 'manage_options', admin_url().'edit.php?post_type=cqpim_terms');
    $submenu['custom-projects'][] = array('Milestone / Task Templates', 'manage_options', admin_url().'edit.php?post_type=cqpim_templates');
    $submenu['custom-projects'][] = array('Project Updates', 'manage_options', admin_url().'admin.php?page=pto-updates');
    // Invoices
    add_menu_page('Invoices', 'Invoices', 'read', 'custom-invoices', '', $adicon, 33);
    $submenu['custom-invoices'][] = array('Invoices', 'manage_options', admin_url().'edit.php?post_type=cqpim_invoice');
    $submenu['custom-invoices'][] = array('Recurring Invoices', 'manage_options', admin_url().'admin.php?page=pto-recinvoices');
    // Teams
    add_menu_page('Collaborators', 'Collaborators', 'read', 'custom-teams', '', $adicon, 34);
    $submenu['custom-teams'][] = array('Team Members', 'manage_options', admin_url().'edit.php?post_type=cqpim_teams');
    $submenu['custom-teams'][] = array('Roles & Permissions', 'manage_options', admin_url().'admin.php?page=pto-permissions');
    // Support
    add_menu_page('Support', 'Support', 'read', 'custom-support', '', $adicon, 35);
    $submenu['custom-support'][] = array('Support Tickets', 'manage_options', admin_url().'admin.php?page=pto-tickets');
    $submenu['custom-support'][] = array('FAQ', 'manage_options', admin_url().'edit.php?post_type=cqpim_faq');
    // Settings
    add_menu_page('Settings', 'Settings', 'read', 'custom-settings', '', $adicon, 36);
    $submenu['custom-settings'][] = array('Setting', 'manage_options', admin_url().'admin.php?page=pto-settings');
    $submenu['custom-settings'][] = array('Custom Fields', 'manage_options', admin_url().'admin.php?page=pto-custom-fields');
    $submenu['custom-settings'][] = array('Documentation', 'manage_options',  'http://projectopia.io/');
}
add_action('admin_menu', 'custom_admin_menu');

This code showing the menu items for the default administrator sidebar but not on the different user dashboard sidebar.

Screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.