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 10 years, 3 months ago by
Vladimir.
-
AuthorPosts
-
08/08/2015 at 02:26 #1619
bikostudio
Participantok i will try this now
08/08/2015 at 02:36 #1620bikostudio
Participantnothing my friend! .. I hate woocommerce!! 🙁
08/08/2015 at 02:39 #1621Vladimir
KeymasterTry to start from more simple code. Comment role checking. May be something wrong is there. Let’s it work for all users for begin.
08/08/2015 at 02:42 #1622bikostudio
ParticipantI did past this code tot the file :
<?php
add_filter(‘woocommerce_disable_admin_bar’, ‘_wc_disable_admin_bar’, 10, 1);
function _wc_disable_admin_bar($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) {
return false;
}any wrong here?
08/08/2015 at 03:00 #1623Vladimir
KeymasterThe logic is correct. If it’s exactly the code you paste – it uses wrong quotes, it should use simple single quote character
'for all string constants.08/08/2015 at 03:02 #1624bikostudio
ParticipantLook, when I past this code in the woocommerce/includes/wc-user-functions.php
right after this
unction wc_disable_admin_bar( $show_admin_bar ) {
if ( apply_filters( ‘woocommerce_disable_admin_bar’, get_option( ‘woocommerce_lock_down_admin’, ‘yes’ ) === ‘yes’ ) && ! ( current_user_can( ‘edit_posts’ ) || current_user_can( ‘manage_woocommerce’ ) ) ) {
$show_admin_bar = false;
}return $show_admin_bar;
}
add_filter( ‘show_admin_bar’, ‘wc_disable_admin_bar’, 10, 1 );it shows the admin bar even for the non user, for visitors
08/08/2015 at 03:04 #1625Vladimir
KeymasterDeactivate all plugins except WooCommerce and try. If that will help activate plugins back one by one. May be something else takes an effect.
08/08/2015 at 03:11 #1626Vladimir
KeymasterWhile it worked for me as it is, try to add filter with lower priority value – 9 instead of 10.
08/08/2015 at 03:13 #1627bikostudio
ParticipantI did that the only plugin do this is woocommerce. I think they change the way they block the admin bar in the new virsion. I really don’t know!
08/08/2015 at 03:19 #1628Vladimir
KeymasterOk. I will re-test this code myself.
08/08/2015 at 03:34 #1629bikostudio
Participantok waiting 🙂
08/08/2015 at 04:12 #1630Vladimir
KeymasterIt seems I found a problem with code. Replace ‘no’ to ‘false’. It should help.
add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1); function _wc_disable_admin_bar($prevent_admin_access) { return false; }08/08/2015 at 05:26 #1634bikostudio
Participantaha i see now! .. it’s working .. thank you so much. Now if I want to add more roles I need to copy it many times right?
08/08/2015 at 05:42 #1635Vladimir
KeymasterGood. Thanks for the information.
You may use one complex expression for all roles, like this one:
if (!(current_user_can('role1') || current_user_can('role2'))) { return .... }09/08/2015 at 05:36 #1636bikostudio
ParticipantThank you so much Vladimir but i’m not so good in coding can you please type the this code for me:
roles :
data_entry
operator
managerthanks for your time 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.