WordPress.org

Support

Support » Plugins and Hacks » Misuse of current_user_can.

Misuse of current_user_can.

  • This plugin use current_user_can to test if a user has a specific role. As it is written here, this does not always work:
    http://codex.wordpress.org/Function_Reference/current_user_can

    Here is my fix:

    function does_user_have_role($user, $role)
    {
        $result = false;
        if ( $user != NULL )
        {
            $result = in_array( $role, (array) $user->roles );
        }
        return $result;
    }
    
    /*
     * Hide the admin bar based on the list of user roles
     */
    function cab_hide_by_users(){
        $user = wp_get_current_user();
    	$roles = cab_get_disabled_users();
    	foreach($roles as $role)
        {
    	if ( does_user_have_role($user, $role) )
            {
                cab_unshow_adminbar();
                add_action('admin_head', 'cab_unshow_options');
            }
        }
    }

    http://wordpress.org/extend/plugins/wp-custom-admin-bar/

  • The topic ‘Misuse of current_user_can.’ is closed to new replies.