-
-
Save toluaddy/359f26f20dda72c548e4d124c7f34dfb to your computer and use it in GitHub Desktop.
Check if a user is part of an existing buddypress group
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 | |
| // check user against an existing buddypress group | |
| // I needed this in a category.php file to see if | |
| // we were looking at a specific category, and if | |
| // so, check if the user is in a buddypress group | |
| // to ensure they should have access | |
| if ( has_category( 'Some Category') && function_exists( 'groups_is_user_member' ) ) { | |
| $group_id = BP_Groups_Group::group_exists('buddypress-group-slug'); | |
| $is_member = groups_is_user_member( wp_get_current_user()->id, $group_id ); | |
| if ( !$is_member ) { | |
| wp_die( 'Unauthorized User' ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment