Problem customising admin menu
-
Hi all, I have started with customising the admin menu for different user roles this weekend and can say that I have surprised myself. With all information I have found on this and other forums, I have achieved what I wanted except for one issue I ran into. It feels as if I have searched the entire internet, but I can’t find the answer.
I have a WP + WC (+WC admin) setup. For a certain user role I want a custom admin menu, showing only the Dashboard, ‘My orders’ and ‘My stock’. I have eliminated access to unwanted items using the AAM plugin.
As I do need to use some functions from WC and WC admin but under different names, I have used the following snippets to achieve what I have now:
To hide menu items:
add_action( 'admin_init', 'remove_menu_pages_for_all_except_admin' ); function remove_menu_pages_for_all_except_admin() { global $user_ID; if ( !current_user_can('administrator') ) { remove_menu_page('woocommerce'); remove_menu_page('wc-admin&path=/analytics/revenue'); } }
To add custom menu items:
add_menu_page('My orders','My orders','enduser', 'edit.php?post_type=shop_order', '','dashicons-archive', 8); add_menu_page('My stock','My stock','enduser', 'admin.php?page=wc-admin&path=/analytics/stock', '','dashicons-pressthis', 9);
Both snippets work and do their job, but I have the issue that the stock report (wc-admin&path=/analytics/stock) is not accessible anymore. The page loads fine, but doesn’t output stock results.
I can’t figure out what I have to do to make this work. Basically all I need is to have the menu item “Analytics” hidden from the menu, just as I did with “Woocommerce”. Only Analytics is not called Analytics.
Any insight into how to solve this is much appreciated!!
- The topic ‘Problem customising admin menu’ is closed to new replies.