bp_include_group_by_context( object|bool $group = false, int|bool $user_id = false, string $context = 'normal' )
Determine whether a group should be included in results sets for a user in a specific context.
Description
Parameters
- $group
-
(Optional) BP_Groups_Group object to check.
Default value: false
- $user_id
-
(Optional) ID of a user to check group visibility for.
Default value: false
- $context
-
(Optional) 'normal' filters hidden groups only that the user doesn't belong to. 'activity' includes only groups for which the user should see the activity streams. 'exclude_hidden' filters all hidden groups out (for directories).
Default value: 'normal'
Return
(bool) True if group meets context requirements.
Source
File: bp-groups/bp-groups-template.php
function bp_include_group_by_context( $group = false, $user_id = false, $context = 'normal' ) {
$include = false;
if ( ! isset( $group->id ) ) {
return $include;
}
if ( current_user_can( 'bp_moderate' ) ) {
$include = true;
}
/*
* 'exclude_hidden' is useful on directories, where hidden groups
* are excluded by BP.
*/
if ( 'exclude_hidden' == $context ) {
if ( 'hidden' != $group->status ) {
$include = true;
}
/*
* 'activity' includes only groups for which the user can view the activity streams.
*/
} elseif ( 'activity' == $context ) {
// For activity stream inclusion, require public status or membership.
if ( 'public' == $group->status || groups_is_user_member( $user_id, $group->id ) ) {
$include = true;
}
/*
* 'mygroups' is useful on user-specific directories, where only groups the
* user belongs to are returned, and the group status is irrelevant.
*/
} elseif ( 'mygroups' == $context ) {
if ( groups_is_user_member( $user_id, $group->id ) ) {
$include = true;
}
} elseif ( 'normal' == $context ) {
if ( 'hidden' != $group->status || groups_is_user_member( $user_id, $group->id ) ) {
$include = true;
}
}
/**
* Filters whether this group should be included for this user and context combination.
*
* @since BuddyBoss 1.0.0
*
* @param bool $include Whether to include this group.
* @param BP_Groups_Group $group The group object in question.
* @param int $user_id ID of user to check.
* @param string $user_id Current context.
*/
return apply_filters( 'bp_include_group_by_context', $include, $group, $user_id, $context );
}
Changelog
| Version | Description |
|---|---|
| BuddyBoss 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.