Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Ideas?

share|improve this question
1  
"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
1  
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
1  
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
show 7 more comments

1 Answer

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
add comment

Your Answer

 
discard

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.