Change WordPress user roles and capabilities Forums How to or FAQ Settings to show WP admin Bar on Front End

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #6634
    wbonadmin
    Participant

    Help needed, please, re accurate set up for showing WP admin Tool Bar on Front end for specific Admin type roles.

    Desired action: for a user with “Membership Manager” role, upon login to site, show WP Admin bar on frontend (do not default to showing WP Admin backend).

    Relevant information:
    Membership Manager role is built on/from “Shop Manager Role”
    WooCommerce is active
    BuddyBoss (built on BuddyPress framework) is active; General Setting for “Show Amin Toolbar for logged in admins” is checked.
    Users can have multiple roles: a membership role tied to their purchase of membership; and for some, an Admin role (Admin, Editor, Membership Manager, Chapter Coordinator).

    Current settings function as desired (Membership Manager can access WP Admin backend and perform needed functions there), except:
    -The WP Admin Toolbar does not show up on the front-end when Membership Manager is logged in
    -Upon logging in Membership Manager is taken to WP Admin Backend. Desire action is to show WP Admin Toolbar & not default to going to WP Admin Backend. (Membership Manager will access site more often as a “Member” than as a “Membership Manager” type of Admin.

    How can I set this up? What do I need to change? Thanks so much!

    #6637
    Vladimir
    Keymaster

    Read this article. Look if it’s related to your task and code below may help you:

    
    add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1);
     
    function _wc_disable_admin_bar($prevent_admin_access) {
     
        return false;
    }
    
    #6638
    Vladimir
    Keymaster

    Code for membership_manager role only will be looked this way:

    
    add_filter( 'woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1 );
    function _wc_disable_admin_bar( $disable ) {
     
        $user = wp_get_current_user();
        if ( !is_a( $user, 'WP_User') || !is_array( $user->roles ) ) {
            return $disable;
        }
        if ( !in_array( 'membership_manager', $user->roles ) ) {
            return $disable;
        }
    
        return false;
    }
    
    #6639
    wbonadmin
    Participant

    Thanks so much for your response.

    I added the code as written above — “code for membership_manager,” using “Code Snippets” Plugin rather than typing directly into functions php file. Deactivated the site – Said there was a “parsing error on line 8”

    add_filter( 'woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1 );
    function _wc_disable_admin_bar( $disable ) {
     
        $user = wp_get_current_user();
        if ( !is_a( $user, 'WP_User') || !is_array( $user->roles ) ) {
            return $disable;
        }
        if ( !in_array( 'membership_manager', $user->roles ) {
            return $disable;
        }
    
        return false;
    }

    I deleted that snippet and as an alternative, copied code from the referenced article and substituted my role name; did not work as desired: does not show admin toolbar on front end for the selected role.

    add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1);
     
    function _wc_disable_admin_bar($prevent_admin_access) {
        if (!current_user_can('membership_manager')) {
            return $prevent_admin_access;
        }
        return false;
    }
     
    add_filter('woocommerce_prevent_admin_access', '_wc_prevent_admin_access', 10, 1);
     
    function _wc_prevent_admin_access($prevent_admin_access) {
        if (!current_user_can('membership_manager')) {
            return $prevent_admin_access;
        }
        return false;
    }

    What am I doing wrong?

    #6642
    Vladimir
    Keymaster

    Yes, I missed a closing bracket at the line 8. Valid code is:

    
    add_filter( 'woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1 );
    function _wc_disable_admin_bar( $disable ) {
     
        $user = wp_get_current_user();
        if ( !is_a( $user, 'WP_User') || !is_array( $user->roles ) ) {
            return $disable;
        }
        if ( !in_array( 'membership_manager', $user->roles ) ) {
            return $disable;
        }
    
        return false;
    }
    

    If filter does not help I suppose that another plugin may have own setting for showing admin bar at the front-end.

    Try to add ‘manage_woocommerce’ to membership_manager role to exclude WooCommerce. Will it help? If it did not help, try to deactivate all plugins and re-test activating them back one by one, to isolate a source of the problem.

    #6644
    wbonadmin
    Participant

    I’ve isolated the source of the problem to the “BuddyBoss” plugin. It is built on the BuddyPress framework. So I’ll see what I can find out about how it controls admin toolbar access and what I need to change. Any suggestions would be welcome.

    Also, is there a way to direct the “membership_manager” to the frontend of the site (which will have the toolbar available, rather than the WP Admin backend?

    #6647
    Vladimir
    Keymaster

    You may redirect membership_manager users after login using another plugin, like this one.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.