WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 determine if a piece of content can be edited by a user. I would like all roles contributor and above to be authorized by a single check. Here's my code:

    if( empty( $post_id ) || !current_user_can('edit_post', $post_id) ) { return; }

Unfortunately, the only users that don't get the return are super admins. Any idea why?

share|improve this question
How are you getting $post_id? – two7s_clash Jun 16 '11 at 1:22
Re my comment @HameedullahKhan, I',m afraid I'm not sure why this isn't working. For the benefit of people experiencing a similar problem - you should check that the relevant users have the edit_others_posts capability. – Stephen Harris Dec 4 '11 at 14:59
up vote 0 down vote accepted

And the correct capability name is edit_posts. So the correct way of using current_user_can will be like following:

if( empty( $post_id ) || !current_user_can( 'edit_posts' ) ) { return; }

UPDATE: I have removed the wrong statement, but as the asker mentioned he would like to allow all roles of contributors and above to be authorized for that particular check, I think just checking for edit_posts caps is enough. Sorry for the wrong statement.

share|improve this answer
This is not entirely correct. Looking at the documentation, current_user_can slices the arguments it's given. It sends the inputted capability and other arguments to $current_user->has_cap() which does something similar. This uses map_meta_cap() to check if user can edit_posts and is post author or can edit_other_posts. This is how WordPress deals with these situations. See wp-includes/capabilities.php for the relevant functions. – Stephen Harris Dec 4 '11 at 14:55
Thanks Stephen for pointing out the mistake. I have removed that incorrect statement. – Hameedullah Khan Dec 5 '11 at 15:32

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.