WordPress.org

Ready to get started?Download WordPress

Forums

WP Custom Admin Bar
Misuse of current_user_can. (1 post)

  1. Sebastien Duval
    Member
    Posted 1 year ago #

    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/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Sebastien Duval
  • This topic is not resolved
  • WordPress version: 3.5.1