Change WordPress user roles and capabilities › Forums › Give user access to plugin – how to › How to display admin bar for some user role
- This topic has 34 replies, 2 voices, and was last updated 9 years, 3 months ago by Vladimir.
-
AuthorPosts
-
05/08/2015 at 14:28 #1603bikostudioParticipant
Hi,
I have created a new user role to give it some permission to do some tasks of admin. I’m using another plugin to hide admin bar for logedin users.how to display the admin bar for some user role?
thanks05/08/2015 at 16:54 #1604VladimirKeymasterHi,
This code shows admin top menu bar for the role:
add_action('wp_head', 'show_top_admin_menu_bar', 100); function show_top_admin_menu_bar() { if (current_user_can('some_role')) { show_admin_bar(true); } }
Pay attention for the 100 value of a priority parameter. With this value code should be executed after that other plugin did its work.
You may add it to the functions.php file of your active theme.
06/08/2015 at 23:38 #1606bikostudioParticipantHi Vladimir,
I did put the code in functions.php file of my active theme, but nothing happened. I have put the user role in if (current_user_can(‘some_role’)) but nothing happened. can you help me please?
06/08/2015 at 23:38 #1607bikostudioParticipantI have also disabled the plugin which hide the admin bar
07/08/2015 at 01:51 #1608VladimirKeymasterShow the code after modification.
07/08/2015 at 22:54 #1609bikostudioParticipantI copied the functions.php to the child-theme folder then i pasted in it this code and changed the some_role to the role name at it is in user role editor plugin which is data_entry to be like this :
add_action(‘wp_head’, ‘show_top_admin_menu_bar’, 100);
function show_top_admin_menu_bar() {
if (current_user_can(‘data_entry’)) {
show_admin_bar(true);
}
}08/08/2015 at 01:21 #1610VladimirKeymasterThanks. It seems to be correct.
Please check, if your child theme is really active.
Do you use WooCommerce plugin?08/08/2015 at 01:23 #1611bikostudioParticipantYes I use WooCommerce and I discovered that it coz the problem 🙂
.. it has function or something blocks it. Ho can i fix this please?08/08/2015 at 01:30 #1612VladimirKeymasterThis post will help:
https://www.role-editor.com/woocommerce-admin-bar-access/08/08/2015 at 01:37 #1613bikostudioParticipantThanks i will give it try and tell you 🙂
08/08/2015 at 01:53 #1614bikostudioParticipantI did what post said but no change .. I pasted this code to the function.php in child theme folder and the child theme is activated.
and data entry users can not access admin bar
code :<?php
add_filter(‘woocommerce_disable_admin_bar’, ‘_wc_disable_admin_bar’, 10, 1);
function _wc_disable_admin_bar($prevent_admin_access) {
if (!current_user_can(‘data_entry’)) {
return $prevent_admin_access;
}
return ‘no’;
}add_filter(‘woocommerce_prevent_admin_access’, ‘_wc_prevent_admin_access’, 10, 1);
function _wc_prevent_admin_access($prevent_admin_access) {
if (!current_user_can(‘data_entry’)) {
return $prevent_admin_access;
}
return false;
}/* Start writing your functions here
08/08/2015 at 02:01 #1615VladimirKeymasterTry another variant. Create .php file, open it in editor, start from <?php tag and insert there a code above, save it. Then put that file to the ‘wp-content/mu-plugins/’ folder (“must use” plugins). Will it help?
08/08/2015 at 02:06 #1616bikostudioParticipantand what should i name the file?
08/08/2015 at 02:07 #1617bikostudioParticipantI don’t see mu-plugins folder too
08/08/2015 at 02:11 #1618VladimirKeymasterCreate ‘mu-plugins’ folder. File name does not matter. WordPress executes any .php file it find in this folder.
https://codex.wordpress.org/Must_Use_Plugins -
AuthorPosts
- You must be logged in to reply to this topic.