#24962 closed defect (bug) (fixed)
Return the allcaps array from the get_role_caps() function
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | normal | Version: | 3.7 |
Component: | Users | Keywords: | has-patch 2nd-opinion |
Focuses: | Cc: |
Description
The WP_User
class has a function called get_role_caps()
that is compiling a list with all user capabilities (coming from roles or individual).
It's a great function, but it's just setting the allcaps
object field which has to be taken additionally. For me it makes sense to get that list returned to the user for further use if needed and I was expecting to get the data as a function result (the function starts with 'get' anyway).
Applying a patch for returning the field data from the function.
Attachments (1)
Change History (8)
#2
@
12 years ago
- Keywords commit added
@return Array list with all capabilities for the user.
should be something like
@return array All capabilities for the user.
#3
follow-up:
↓ 4
@
12 years ago
- Keywords 2nd-opinion added; commit removed
Actually, I'm not really sure this is desired. I understand the argument about get_
, but it's probably only going to encourage using this roles/capabilities array directly, when in reality you shouldn't ever do that. More inclined to wontfix now.
#4
in reply to:
↑ 3
@
12 years ago
Replying to nacin:
Actually, I'm not really sure this is desired. I understand the argument about
get_
, but it's probably only going to encourage using this roles/capabilities array directly, when in reality you shouldn't ever do that. More inclined to wontfix now.
Does the method have too much history to just change it from 'get' to 'set' (deprecate get_* and introduce set_*, I guess) and forgo the proposed return value?
#5
@
12 years ago
The Core usage of the function is only in capabilities.php and only to flush the caps, so the naming is incorrect. However the function code is helpful outside of the core in plugins, and personally I don't see a reason to call a get
function and then use a separate field (I generally consider accessing fields through properties an encapsulation best practice).
I would also consider renaming the function but it's since 2.0.0 and who knows how many plugins/scripts have been using that already.
The change make sense if you read the PHPdocs. Tho I do think using the parameter
allcaps
is better in most cases.