0

I've reordered the admin menu items through:

function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;

return array(
    'index.php', // Dashboard
    'edit.php?post_type=page', // Pages
    'edit.php?post_type=sp_faq', // FAQs
    'gf_edit_forms', // Forms
    'woocommerce', // Woocommerce
    'edit.php?post_type=product', //Products
    'edit.php', // Posts/News
    'edit.php?post_type=event', // Events
    'upload.php', // Media
    'themes.php', // Appearance
    'plugins.php', // Plugins
    'users.php', // Users
    'tools.php', // Tools
    'options-general.php', // Settings
);
}
add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order
add_filter('menu_order', 'custom_menu_order');

This works great for the Admin user role, however, does not work for other roles. How do I extend this custom menu order to all user roles?

1
  • Anybody? Nobody? – mmorris1 Dec 16 '16 at 13:53
0

You don't specify whether you are trying to make all of these items available to all user roles (which would mean having to add custom capabilities) - so I'm assuming you only want the ability to customize menu order by user.

My approach for this was to get all roles available to the currently logged-in user, and then run each role through a switch to get the appropriate order.

function my_custom_menu_order( $menu_ord) {
$curr_id = get_current_user_id();
$user = new WP_User( $curr_id );
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    foreach ( $user->roles as $role ){
        switch($role){
            case 'administrator':
                if (!$menu_ord) return true;
                return array(
                'options-general.php', // Settings
                'index.php', // Dashboard
                'edit.php?post_type=page', // Pages
                'edit.php?post_type=faq', // FAQs
                'options-general.php', // Settings
                'gf_edit_forms', // Forms
                'woocommerce', // Woocommerce
                'edit.php?post_type=product', //Products
                'edit.php', // Posts/News
                'edit.php?post_type=event', // Events
                'upload.php', // Media
                'themes.php', // Appearance
                'plugins.php', // Plugins
                'users.php', // Users
                'tools.php', // Tools   
                );
            break;
            case 'editor':
                if (!$menu_ord) return true;
                return array(
                'edit.php?post_type=event', // Events
                'index.php', // Dashboard
                'edit.php?post_type=page', // Pages
                'edit.php?post_type=faq', // FAQs
                'options-general.php', // Settings
                'gf_edit_forms', // Forms
                'woocommerce', // Woocommerce
                'edit.php?post_type=product', //Products
                'edit.php', // Posts/News
                'upload.php', // Media
                'themes.php', // Appearance
                'plugins.php', // Plugins
                'users.php', // Users
                'options-general.php', // Settings
                'tools.php', // Tools   
                );
            break;

            default:
            break;
            }
       }
}

    add_filter('custom_menu_order', 'my_custom_menu_order');
    add_filter('menu_order', 'my_custom_menu_order');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.