Why does this check to see if user is authorized to edit a post fail for all but super admins?

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?

1 Answer

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.

Leave a Comment