Show a User's Capabilities on Their Profile
Adds a collapsible list of everything a user is allowed to do to the user edit screen, which helps when checking what a role or plugin has granted.
Opens WPIDE on
Code
$wpide_caps_panel = function ( $user ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$caps = array_keys( array_filter( (array) $user->allcaps ) );
$caps = array_diff( $caps, array_keys( wp_roles()->roles ) );
sort( $caps );
echo '<h2>Capabilities</h2><details><summary>' . esc_html( sprintf( '%d capabilities from the roles %s', count( $caps ), implode( ', ', $user->roles ) ) ) . '</summary>';
echo '<ul style="columns:3 14em;margin-top:1em">';
foreach ( $caps as $cap ) {
echo '<li><code>' . esc_html( $cap ) . '</code></li>';
}
echo '</ul></details>';
};
add_action( 'show_user_profile', $wpide_caps_panel );
add_action( 'edit_user_profile', $wpide_caps_panel );
Notes
Visible to administrators only; it is read-only and changes nothing.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.