Change WordPress user roles and capabilities Forums Give user access to plugin – how to How to display admin bar for some user role

Viewing 15 posts - 16 through 30 (of 35 total)
  • Author
    Posts
  • #1619
    bikostudio
    Participant

    ok i will try this now

    #1620
    bikostudio
    Participant

    nothing my friend! .. I hate woocommerce!! 🙁

    #1621
    Vladimir
    Keymaster

    Try to start from more simple code. Comment role checking. May be something wrong is there. Let’s it work for all users for begin.

    #1622
    bikostudio
    Participant

    I 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?

    #1623
    Vladimir
    Keymaster

    The 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.

    #1624
    bikostudio
    Participant

    Look, 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

    #1625
    Vladimir
    Keymaster

    Deactivate all plugins except WooCommerce and try. If that will help activate plugins back one by one. May be something else takes an effect.

    #1626
    Vladimir
    Keymaster

    While it worked for me as it is, try to add filter with lower priority value – 9 instead of 10.

    #1627
    bikostudio
    Participant

    I 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!

    #1628
    Vladimir
    Keymaster

    Ok. I will re-test this code myself.

    #1629
    bikostudio
    Participant

    ok waiting 🙂

    #1630
    Vladimir
    Keymaster

    It 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;
    }
    
    #1634
    bikostudio
    Participant

    aha 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?

    #1635
    Vladimir
    Keymaster

    Good. 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 ....
    }
    
    #1636
    bikostudio
    Participant

    Thank 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
    manager

    thanks for your time 🙂

Viewing 15 posts - 16 through 30 (of 35 total)
  • You must be logged in to reply to this topic.