Make WordPress Core

Opened 2 years ago

Last modified 2 months ago

#19747 new defect (bug)

Roles add_cap should call update_user_level_from_caps()

Reported by: lgladdy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3.1
Component: Role/Capability Keywords: reporter-feedback needs-unit-tests
Focuses: Cc:


Hey guys,

I've created a new user role, which didn't appear in the Author drop down list due to #16841. The workaround is to add a level_1 capability to that user, but because wordpress doesn't call update_user_level_from_caps() function when you add_cap, that isn't actually applied to existing users on the role, and you have to move them to a different role and back again if you want to apply the changed user role.

I'd suggest adding a call to update_user_level_from_caps() to add_cap (and remove_cap) to fix this in wp-includes/capabilities.php

Change History (4)

comment:1 scottconnerly21 months ago

  • Cc scott@… added

comment:2 BandonRandon17 months ago

  • Cc BandonRandon added

comment:3 nacin2 months ago

  • Keywords reporter-feedback needs-unit-tests added

Hi lgladdy, sorry you never received a reply here. I'm trying to figure out what's going on. update_user_level_from_caps() gets called when you add a role to a user, which is what you'd be doing when you create a new user role. So maybe the API could do a little more, but I'm not quite sure what the bug is.

comment:4 lgladdy2 months ago

Hey Nacin,

It's been a little while since i opened this, so i'm trying to recall our use case, I think it was basically that when you add a deprecated level_x capability to a role, any users who already have that role aren't updated with that capability, because update_user_level_from_caps() isn't called as part of the add_cap.

Looking back, this probably isn't too much of an issue depending on the state of #16841 - I've not needed to do anything with caps in recent releases, but this was back in 3.3 so it may well be something that's changed since then!

Note: See TracTickets for help on using tickets.