Created
April 4, 2017 19:56
-
-
Save dcavins/e6891f1c9bbeab75fc1cfe38b33d9435 to your computer and use it in GitHub Desktop.
An example of adding "user can" checks on the "create_subgroup" capability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'bp_user_can', 'my_create_groups_cap_change', 20, 5 ); | |
function my_create_groups_cap_change( $retval, $user_id, $capability, $site_id, $args ) { | |
if ( 'create_subgroups' == $capability ) { | |
// We need to know which group is in question. | |
if ( empty( $args['group_id'] ) ) { | |
return false; | |
} | |
// HGBP has already checked the creator setting. We're just checking the depth. | |
// Probably want to respect a calculated 'false'; only run if retval is true. | |
if ( $retval ) { | |
// Whatever our additional logic is goes here. | |
// For example, if we only want to allow one level of children, | |
// like: top level (has parent_id = 0) > one level below (non-zero parent_id) | |
// we can check if the group's parent_id isn't 0, then return false. | |
$group = groups_get_group( $args['group_id'] ); | |
if ( 0 != $group->parent_id ) { | |
$retval = false; | |
} | |
} | |
} | |
return $retval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment