Upon dumping the \WP_User
object, I’ve noticed that there are two properties, which are directly related to capabilities for a particular user.
$user_object->caps
$user_object->allcaps
I’ve instantly noticed that there’s less array values for $user_object->caps
than there are in $user_object->allcaps
. Likely hence the naming convention here.
I currently only observe ONE value under $user_object->caps
. I also have a custom role assigned to this user. The one value in $user_object->caps
happens to be the name of my custom user role. However, that very same value is also listed in $user_object->allcaps
.
- What’s the difference between the two properties
$user_object->caps
and$user_object->allcaps
? - Is there ever a situation where the capabilities listed in
$user_object->caps
WOULDN’T be found under$user_object->allcaps
? - Is there any reason I would need to use
$user_object->caps
or can I rely on checking$user_object->allcaps
for a particular user?
1 Answer
Examining the comments for the properties in the WP_User class reveals that allcaps
is:
All capabilities the user has, including individual and role based.
And caps
is:
The individual capabilities the user has been given.
But you probably shouldn’t be using the properties directly. WP_User
has a has_cap
method that should be used instead, as it checks the appropriate properties and runs the result through the relevant filters.