Tagged: groups roles
Hello Omar,
Thank you for the acknowledgment. Please try the following code:
add_filter( 'bp_after_group_has_members_parse_args', function ( $args ) { $group = groups_get_current_group(); $types = bp_groups_get_group_type( $group->id, false ); if ( ! $types ) { return $args; } $exclude = array(); if ( in_array( 'A', $types ) && bp_group_has_moderators( $group ) ) { // Exclude moderators. $exclude = bp_group_mod_ids( $group, 'array' ); } elseif ( in_array( 'B', $types ) ) { // Exclude Administrators. $exclude = bp_group_admin_ids( $group, 'array' ); } $args['exclude'] = empty( $args['exclude'] ) ? $exclude : array_merge( (array) $args['exclude'], $exclude ); return $args; } );
Let me know if it helps or not.
Regards
RaviHello Omar,
Try the following solution:
/** * Get group moderator ids. * * @param BP_Groups_Group $group Group object. * * @return array */ function buddydev_get_group_member_ids( $group ) { global $wpdb; $table = buddypress()->groups->table_name_members; $query = $wpdb->prepare( "SELECT user_id FROM {$table} WHERE group_id = %d AND is_admin = 0 AND is_mod = 0 AND is_confirmed = 1", $group->id ); return $wpdb->get_col( $query ); } add_filter( 'bp_after_group_has_members_parse_args', function ( $args ) { $group = groups_get_current_group(); $types = bp_groups_get_group_type( $group->id, false ); if ( ! $types ) { return $args; } $admin_ids = bp_group_admin_ids( $group, 'array' ); $mod_ids = bp_group_has_moderators( $group ) ? bp_group_mod_ids( $group, 'array' ) : array(); $members_ids = buddydev_get_group_member_ids( $group ); $exclude = array(); if ( in_array( 'A', $types ) ) { $exclude = array_merge( $admin_ids, $mod_ids ); } elseif ( in_array( 'B', $types ) ) { $exclude = array_merge( $admin_ids, $members_ids ); } $args['exclude'] = empty( $args['exclude'] ) ? $exclude : array_merge( (array) $args['exclude'], $exclude ); return $args; } );
Regards
RaviTY very much Ravi, it’s working perfectly. One more thing if you can, What should I do if I want to actually show all member roles for a specific group type? Cause now I notice that if I don’t add the group type into the code, that group type won’t show any member roles.
Thanks a lot man! You’re the best!
Hello Omar,
Thank you for the acknowledgment.
Cause now I notice that if I don’t add the group type into the code, that group type won’t show any member roles.
Please post your code for this.
What should I do if I want to actually show all member roles for a specific group type?
if ( in_array( 'A', $types ) ) { $exclude = array_merge( $admin_ids, $mod_ids ); } elseif ( in_array( 'B', $types ) ) { $exclude = array_merge( $admin_ids, $members_ids ); } // Reset excluded array if group of specfic type. if ( in_array( 'C', $types ) ) { $exclude = array(); }
Regards
Ravi
You must be logged in to reply to this topic.