Title: Getting and Setting user capabilities
Last modified: August 20, 2016

---

# Getting and Setting user capabilities

 *  [willbro](https://wordpress.org/support/users/willbro/)
 * (@willbro)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/getting-and-setting-user-capabilities/)
 * Wow, this is really hard. Probably because I’m not reading the frickin manual…
 * I can’t figure out how to: Get the array of user capabilities and Loop through
   them
 * Then I will need to figure out how to: Check and then set certain capabilities.
   But I’m this close!
 * global $current_user;
    $user = $current_user; // THIS WORKS AND IS EASY /*if (!
   empty( $user->roles ) && is_array( $user->roles ) ) { foreach ( $user->roles 
   as $role ) echo $role;} // THIS DOESN’T GIVE ME WHAT I WANT if ( !empty( $user-
   >allcaps ) && is_array( $user->allcaps ) ) { foreach ( $user->allcaps as $cap)//
   this line outputs 1 1 1 1 for an admin user echo $cap;
 * But what I need to do I guess is break out the name value pairs?
    or reference
   the display name of the capability in usermeta? yes, i suck at truly understnding
   arrays
 *  $capname = $cap->SOMETHING_HERE;
    echo $cap.’ is ‘ . $capname. ‘ capacity’;}
 * Help is on the way?

The topic ‘Getting and Setting user capabilities’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [capabilities](https://wordpress.org/support/topic-tag/capabilities/)
 * [suck](https://wordpress.org/support/topic-tag/suck/)
 * [wp_user](https://wordpress.org/support/topic-tag/wp_user/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [willbro](https://wordpress.org/support/users/willbro/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/getting-and-setting-user-capabilities/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
