3

Upon dumping the \WP_User object, I've noticed that there are two properties, which are directly related to capabilities for a particular user.

  1. $user_object->caps
  2. $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.

  1. What's the difference between the two properties $user_object->caps and $user_object->allcaps?
  2. Is there ever a situation where the capabilities listed in $user_object->caps WOULDN'T be found under $user_object->allcaps?
  3. 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 1

5

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.