I'm trying to put all possible capabilities into a dropdown list. I'm new to this so go easy on me. What I have at the moment is not working in the slightest bit:
$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;
EDIT --
I made it a shortcode just for a quick test:
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;
}
and it DOES create a dropdown. Problem is, it's boolean. It's all 1s. Any way to get it to return the actual cap names?
-- EDIT: It's weird because vardump($user->allcaps); returns the actual values, not boolean. I tried using settype but it didn't affect the output.