• Resolved JamesKoussertari

    (@jameskoussertari)


    Hi, I have set the option in the plugin settings “Show Admin Bar” to Administrators, Editors and Authors. However, it still shows for Subscribers.

    I also have set “Admin area access” to Default. I have also tried every other combination and nothing works.

    The only way I could get it to be hidden was with a custom function:

    // show admin bar only for admins and editors
    if (!current_user_can('edit_posts')) {
    add_filter('show_admin_bar', '__return_false');
    }

    Unfortunately that code above only hides the admin bar, so I can still get to the dashboard by URL. So I added the below function to actually disable it. However, now editing posts on the frontend shows a warning message.

    // Disable admin for subscribers
    add_action('admin_init', 'disable_dashboard');
    function disable_dashboard() {
    if (current_user_can('subscriber') && is_admin()) {
    wp_redirect(home_url());
    exit;
    }
    }

    I’d prefer it if your plugin handled this as now I’m wondering why it didn’t work in the first place and whether I’d be causing some sort of conflict by adding extra functions.

    Please advise how to get the settings working please. Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Saiful Islam

    (@saifislam01)

    Hi @jameskoussertari,

    Thank you for bringing the issues to our attention. We tested the issue and found that your concern was valid. I discovered that those settings are not working.

    We can use the code below in the theme’s functions.php file to restrict subscribers from accessing the admin toolbar.

    function tf_check_user_role( $roles ) {
        if ( is_user_logged_in() ) :
            $user = wp_get_current_user();
            $currentUserRoles = $user->roles;
            $isMatching = array_intersect( $currentUserRoles, $roles);
            $response = false;
            if ( !empty($isMatching) ) :
                $response = true;        
            endif;
            return $response;
        endif;
    }
    
    $roles = [ 'subscriber' ];
    if ( tf_check_user_role($roles) ) :
        add_filter('show_admin_bar', '__return_false');
    endif;
    
    function tf_restrict_admin_access() {
        $roles = [ 'subscriber' ];
    
        if ( tf_check_user_role($roles) ) {
            wp_redirect(home_url());
            exit();
        }
    }
    
    add_action('admin_init', 'tf_restrict_admin_access');

    Hope this will work. Please contact through the website for further assistance.

    Best regards,

    Thread Starter JamesKoussertari

    (@jameskoussertari)

    Thanks, that did the trick. Will the fix be implemented in the next version?

    Plugin Support Saiful Islam

    (@saifislam01)

    You’re welcome. I hope this update will be included in our next version.

    Have a good day 🙂

    Thread Starter JamesKoussertari

    (@jameskoussertari)

    Hi, just wanted to let you know that unfortunately this code breaks the media upload field on frontend forms. Potentially breaks other fields too but only noticed it on media fields.

    Thread Starter JamesKoussertari

    (@jameskoussertari)

    Any update on this?

    It would be great to get this functionality working by using the settings within the plugin.

    Leaving the admin bar visible for subscribers seems like a bit of security concern and also confuses users.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Admin bar visible for subscribers’ is closed to new replies.