Skip to:
Content

BuddyPress.org

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#6501 closed enhancement (fixed)

Allow additional arguments to be passed to bp_current_user_can()

Reported by: thebrandonallen's profile thebrandonallen Owned by: boonebgorges's profile boonebgorges
Milestone: 2.4 Priority: normal
Severity: normal Version: 1.6
Component: Core Keywords: has-patch
Cc:

Description

This brings bp_current_user_can() in line with it's pals current_user_can_for_blog(), current_user_can(), and user_can().

This also helps pave the way for #5121.

Attachments (2)

6501.01.patch (1.3 KB) - added by thebrandonallen 9 years ago.
6501.02.patch (2.3 KB) - added by r-a-y 9 years ago.

Download all attachments as: .zip

Change History (9)

#1 @DJPaul
9 years ago

  • Milestone changed from Awaiting Review to 2.4

Looks reasonable to me. Thanks for another patch, @thebrandonallen!

@r-a-y
9 years ago

#2 @r-a-y
9 years ago

02.patch changes the second parameter for $blog_id to an array. Older usage should be backward compatible.

This is mostly to address usage of bp_current_user_can() in #5121.

Last edited 9 years ago by r-a-y (previous) (diff)

#3 @boonebgorges
9 years ago

@r-a-y - Thanks for your patch. I was going to suggest the very same thing, in response to thebrandonallen's patch on #5121.

bp_current_user_can() is still slightly different from current_user_can(), because current_user_can() can take a scalar as the item_id/third argument. So,

current_user_can( 'edit_post', $post_id );

vs

bp_current_user_can( 'edit_group', array( 'item_id' => $group_id ) ); // or 'group_id' or whatever

There's probably no way around this, since (a) some caps may require more than one item id, and (b) we need to provide backward compatibility for $blog_id, but just thought I'd raise the point.

#4 @r-a-y
9 years ago

bp_current_user_can() is still slightly different from current_user_can(), because current_user_can() can take a scalar as the item_id/third argument.

True, but I think the array format is easier to read for devs when coding the map_meta_caps portion. I think this beats WP core.

With WP, I don't think you can do multiple item ID checks, so that's another potential positive for BP.

#5 @boonebgorges
9 years ago

In 9956:

Add test demonstrating that an integer passed as the second argument in bp_current_user_can() will be interpereted as a blog_id.

See #6501.

#6 @boonebgorges
9 years ago

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

In 9957:

Convert second parameter of bp_current_user_can() to an $args array.

This makes the syntax simpler for the vast majority of use cases, where an
explicit blog_id doesn't need to be specified. It also makes it possible to
pass additional arguments, such as an item_id, to bp_current_user_can().

An integer passed as the second parameter will trigger the backward-
compatibility layer.

Props thebrandonallen, r-a-y.
See #5121. Fixes #6501.

#7 @DJPaul
8 years ago

  • Component changed from API - Roles/Capability to Core
Note: See TracTickets for help on using tickets.