I think I'm pretty close to what I need, but just need a little direction.
I'm trying to show a content widget in the backend to users of a certain role. Right now, I'm just testing it out with a user that has a role of subscriber.

1 Answer
1

current_user_can() function needs an input of a capability not user role, though it works sometime but we should not use user role as a input to this function.

you're passing the subscriber object to function which is a lowest possible role we can have on Wordpress. That's why !current_user_can('subscriber') makes it unavailable for all.

Have a look at Wordpress Documentation of Capabilities Vs Roles table, Use that table to determine which capability you can use to hide it or show to particular role. To show the box to Editor you can use capability moderate_comments .

E.g - if ( current_user_can ('moderate_comments') )
{
//To see this visible you should have at-least Editor privileges
}

Note -

I recommend using wp_get_current_user() function. This can be used to grab user role and show specific content. The content will be available to that user only, Not even users with higher privileges can see it.

Ok, great! Thank you! The first example with using if current_user_can works great, and thank you for explaining it to me. I did try to use your noted, bottom recommendation, but it didn't work, really. It shows to all users, plus didn't echo out the full html.
–
Anthony MyersAug 6 '12 at 2:50