Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#24962 closed defect (bug) (fixed)

Return the allcaps array from the get_role_caps() function

Reported by: nofearinc's profile nofearinc Owned by: wonderboymusic's profile 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 12 years ago.

Download all attachments as: .zip

Change History (8)

@nofearinc
12 years ago

#1 @markoheijnen
12 years 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.

#2 @nacin
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: @nacin
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 @DrewAPicture
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 @nofearinc
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.

#6 @wonderboymusic
12 years 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.

#7 @SergeyBiryukov
11 years ago

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