Make WordPress Core

Opened 15 years ago

Closed 12 years ago

#11635 closed defect (bug) (fixed)

create a function that does this: wp_get_user_role()

Reported by: hakre's profile hakre Owned by: ryan's profile ryan
Milestone: 3.6 Priority: normal
Severity: normal Version: 2.9
Component: Role/Capability Keywords: has-patch close
Focuses: Cc:

Description

There is an TODO task left in the file wp-admin/user-edit.php around line 196. The original author should decide wether or not he wants to implement the noted feature or to just drop it.

Related Code:

// Get the highest/primary role for this user
// TODO: create a function that does this: wp_get_user_role()
$user_roles = $profileuser->roles;
$user_role = array_shift($user_roles);

Attachments (3)

11635.diff (1.4 KB) - added by ericmann 15 years ago.
Adds wp_get_user_role() function that keys off $user_id
wp-get-user-role.diff (2.7 KB) - added by wonderboymusic 13 years ago.
11635.2.diff (1.7 KB) - added by wonderboymusic 12 years ago.

Download all attachments as: .zip

Change History (20)

#1 @hakre
15 years ago

  • Owner set to ryan
  • Status changed from new to assigned

code was comitted by ryan.

#2 @hakre
15 years ago

in [10319] use wp_dropdown_roles(). Props jeremyclarke. fixes #8764

#3 @scribu
15 years ago

wp_get_user_role() would be really handy. +1

@ericmann
15 years ago

Adds wp_get_user_role() function that keys off $user_id

#4 @ericmann
15 years ago

  • Cc eric@… added
  • Keywords has_patch needs_testing added

#5 @scribu
15 years ago

  • Keywords dev-feedback has-patch needs-testing added; developer-feedback has_patch needs_testing removed

#6 @scribu
15 years ago

Does the patch work for if is_user_logged_in() is false?

#7 @ericmann
15 years ago

The patch works when is_user_logged_in() is false at least on my installation. I think it could warrant further tests, though, in case I missed something.

#8 @dd32
15 years ago

  • Component changed from General to Role/Capability
  • Milestone changed from 3.0 to 3.1

Users can have multiple roles. There is no real way to determine which role is the "highest".

I'm proposing we leave this for 3.1, There are a few people who are wanting to clean roles up in 3.1

#9 @nacin
14 years ago

  • Milestone changed from Awaiting Triage to Future Release

#10 @bainternet
13 years ago

  • Cc admin@… added

#11 @wonderboymusic
13 years ago

I'll see your $user_id and raise you a $user object and then default to $current_user - also implemented the function in more places

#12 @scribu
13 years ago

We should really get wp_get_user() in: #21120

#13 @scribu
13 years ago

But other than that, I agree with dd32:

Users can have multiple roles. There is no real way to determine which role is the "highest".

#14 @wonderboymusic
13 years ago

Semantics - return "first" role - the 3 or 4 places it is used were already arbitrarily returning the first role. I know multiple roles per user per blog exists, but I wish it didn't. Joining user_meta to subdivide users completely breaks at scale (over 1M users, many millions of rows of meta)

#15 follow-up: @wonderboymusic
12 years ago

  • Keywords close added; dev-feedback needs-testing removed
  • Milestone changed from Future Release to 3.6

I think the need for this is obsolete. I refreshed the function to return the first role or a passed role if the user has it. But it's only returning the label for the role ('administrator' etc). So the function only returns the first role or does the equiv of a current_user_can - the TODO has been there since the beginning of time: http://core.trac.wordpress.org/browser/trunk/wp-admin/user-edit.php?rev=10935#L251 . Moving to 3.6 so it gets used or closed.

#16 in reply to: ↑ 15 @DrewAPicture
12 years ago

I agree with @wonderboymusic and @dd32. At the least, just remove the TODO, but since users can have multiple roles, this doesn't necessarily return the "highest" role, just the first one. +1 for close.

#17 @ryan
12 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 24247:

Remove obsolete TODO.

Props wonderboymusic
fixes #11635

Note: See TracTickets for help on using tickets.