WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do some capability checks on comment authors using the user_can() function, but for some reason it isn't working at all.

I have a custom capability setup with the Role Manager plugin called "read_citizen".

My check looks like this:

if(user_can($commentAuthor->user_id, 'read_citizen') {
   //do stuff here

I have confirmed that the $commentAuthor object is set correctly.


share|improve this question
"Not working" is not saying much. What does not work? What did you expect? What did actually happen? Is there an error in the error log? – hakre Jul 12 '11 at 15:03
It is supposed to return TRUE if the user has the capability. In this case, nothing is returned. – Pippin Jul 12 '11 at 15:12
What if you use a non-custom cap? Does the conditional return true? Also: by "nothing is returned", do you mean that the conditional returns null, or that it returns false? – Chip Bennett Jul 12 '11 at 15:36
try using current_user_can('read_citizen') instead – Bainternet Jul 12 '11 at 15:42
In PHP the value nothing does not exist. What does the function exactly return? FALSE or NULL or even something else? – hakre Jul 12 '11 at 16:36
up vote 2 down vote accepted

Ok, found the answer. It was just an oversight on my part.

I was using the wrong variable name for the USER ID. In the $wpdb comment object, the user ID is stored as user_id, but in the USER object, the ID is stored just as ID.

So, by using if ( user_can($commentAuthor->ID, 'read_citizen') ), it all works.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.