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

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