Skip to content

Commit

Permalink
When mapping meta_cap in groups, don't assume that all event-related …
Browse files Browse the repository at this point in the history
…caps need access to a specific event ID.

The plural caps (the primitives) do not, and PHP notices should be avoided in
these cases.

See #5.
  • Loading branch information
boonebgorges committed May 4, 2015
1 parent eff5b44 commit a69047b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions includes/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,27 @@ function bpeo_rel_canonical_for_group() {
*/
function bpeo_group_event_meta_cap( $caps, $cap, $user_id, $args ) {
// @todo Need real caching in BP for group memberships.
if ( ! in_array( $cap, array( 'read_event' ) ) ) {
if ( false === strpos( $cap, '_event' ) ) {
return $caps;
}

$event = get_post( $args[0] );
if ( 'event' !== $event->post_type ) {
return $caps;
}
// Some caps do not expect a specific event to be passed to the filter.
if ( false === strpos( $cap, '_events' ) ) {
if ( ! isset( $args[0] ) ) {
var_Dump( func_get_args() ); die();
}
$event = get_post( $args[0] );
if ( 'event' !== $event->post_type ) {
return $caps;
}

$event_groups = bpeo_get_event_groups( $event->ID );
$user_groups = groups_get_user_groups( $user_id );
$event_groups = bpeo_get_event_groups( $event->ID );
$user_groups = groups_get_user_groups( $user_id );
}

switch ( $cap ) {
case 'read_event' :
case 'edit_event' :
if ( 'private' !== $event->post_status ) {
// EO uses 'read', which doesn't include non-logged-in users.
$caps = array( 'exist' );
Expand Down

0 comments on commit a69047b

Please sign in to comment.