WordPress.org

Make WordPress Core

Opened 19 months ago

Closed 17 months ago

Last modified 15 months ago

#24962 closed defect (bug) (fixed)

Return the allcaps array from the get_role_caps() function

Reported by: nofearinc Owned by: wonderboymusic
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)

24962.patch (640 bytes) - added by nofearinc 19 months ago.

Download all attachments as: .zip

Change History (8)

@nofearinc19 months ago

comment:1 @markoheijnen19 months ago

  • Milestone changed from Awaiting Review to 3.7

The change make sense if you read the PHPdocs. Tho I do think using the parameter allcaps is better in most cases.

comment:2 @nacin18 months ago

  • Keywords commit added

@return Array list with all capabilities for the user.

should be something like

@return array All capabilities for the user.

comment:3 follow-up: @nacin18 months 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.

comment:4 in reply to: ↑ 3 @DrewAPicture18 months 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?

comment:5 @nofearinc18 months 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.

comment:6 @wonderboymusic17 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 25673:

WP_User::get_role_caps() now returns the caps it was already setting. The method was previously just setting $allprops and requiring that property to be read.

Props nofearinc.
Fixes #24962.

comment:7 @SergeyBiryukov15 months ago

  • Version changed from trunk to 3.7
Note: See TracTickets for help on using tickets.