Opened 13 years ago
Closed 13 years ago
#14602 closed enhancement (fixed)
Create user_can, refactor current_user_can, author_can, current_user_can_for_blog
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.0.1 |
Component: | Role/Capability | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Currently we have no function to pass a user ID and a capability/rolewhich will return whether the user can perform that role or has that capability. Further, the functions current_user_can
, author_can
, and current_user_can_for_blog
have some code duplication.
I suggest adding a new function user_can
, which accepts any user_ID or a user object and a capability, and returns a boolean. The other *_can*
functions can then be refactored to use the new function.
See attached patch.
Attachments (1)
Change History (8)
#2
follow-up:
↓ 4
@
13 years ago
- Component changed from Users to Role/Capability
- Milestone changed from Awaiting Review to 3.1
Looking good. +1
#4
in reply to:
↑ 2
;
follow-up:
↓ 5
@
13 years ago
Replying to scribu:
Looking good. +1
Should the user_can
function be using get_userdata
rather than instantiating a new WP_User object every time, so it takes advantage of the cache?
#5
in reply to:
↑ 4
@
13 years ago
Replying to simonwheatley:
Replying to scribu:
Looking good. +1
Should the
user_can
function be usingget_userdata
rather than instantiating a new WP_User object every time, so it takes advantage of the cache?
No, because WP_User calls get_userdata() internally.
Looking at the current patch I wonder whether the
is_int
check in the first line of the newuser_can
function ought to be more like this: