• 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.