[wp-hackers] current_user_can

Lionel Pointet lionel.pointet at globalis-ms.com
Mon Jun 4 13:48:24 UTC 2012


Hi Rob,

This function takes as many arguments as you want, and send them to the 
"has_cap" method of the WP_User class, which then call "map_meta_cap" 
with these same arguments.
The "edit_user" capability actually exists and calling with this cap 
will return true in 2 cases (for non-multisite installations):

  * the current_user is the user you want to edit
  * the current_user has the "edit_users" capability

So this is valid and recommanded to do this if you know that your code 
will edit one user in particular: this allows plugins to hook and 
disable the edition for some users (for example).

Lionel

Le 04/06/2012 15:30, Robert Lusby a écrit :
> I've seen the following in several plugins, and sure I've seen it in 
> core code somewhere:
>
> if (current_user_can('edit_user', $current_user->ID)) {
>     //do something
> }
>
> Is this valid? A look at the current_user_can function seems to 
> suggest there isn't a second argument to that function. There also 
> doesn't seem to be an 'edit_user' capability listed, only 'edit_users' 
> (plural).
>
> Considering I've seen this used, and it seems to be returning 
> true/false appropriately am I missing something?
>
> Rob.
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list