Skip to content

Instantly share code, notes, and snippets.

@phoopee3
Created January 18, 2018 01:59
Show Gist options
  • Save phoopee3/68fd63bb54e5ba18a9bc130f07439c0a to your computer and use it in GitHub Desktop.
Save phoopee3/68fd63bb54e5ba18a9bc130f07439c0a 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