admin管理员组文章数量:1122846
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?
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?
Share Improve this question edited Dec 15, 2016 at 20:09 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Dec 15, 2016 at 20:05 mmorris1mmorris1 291 gold badge1 silver badge4 bronze badges 1- Anybody? Nobody? – mmorris1 Commented Dec 16, 2016 at 13:53
1 Answer
Reset to default 0You 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');
本文标签: Custom Admin Menu Order for all User Roles
版权声明:本文标题:Custom Admin Menu Order for all User Roles 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286086a1927595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论