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
2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 | 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.