Trying to put a list of all possible caps in a dropdown. I can only get it to return 1s (boolean true). If I use var_dump($user->allcaps); it does produce the actual cap names, but when I plug this into my function, it goes to boolean. Have tried using various settype statements; nothing has worked. Here’s the function currently:
add_shortcode('capsdropdown', 'sc_capsdropdown');
function sc_capsdropdown($attr) {
$user = get_user_by('id', '1');
$capslist = $user->allcaps;
$dropdown = '<select>';
foreach($capslist as $cap){
$dropdown .= '<option value="'.$cap.'">'.$cap.'</option>';
}
$dropdown .= '</select>';
return $dropdown;
}
Resolved. This works:
foreach($capslist as $cap=>$caps){ $dropdown .= '<option value="'.$cap.'">'.$cap.'</option>'; }
Solved with this Answer at Stack Overflow.