Skip to content

Instantly share code, notes, and snippets.

@toluaddy
Forked from phoopee3/Buddypress-Group-Check.php
Created February 3, 2020 12:15
Show Gist options
  • Select an option

  • Save toluaddy/359f26f20dda72c548e4d124c7f34dfb to your computer and use it in GitHub Desktop.

Select an option

Save toluaddy/359f26f20dda72c548e4d124c7f34dfb to your computer and use it in GitHub Desktop.
Check if a user is part of an existing buddypress group
<?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