Rob Pearson Posted June 7, 2017 Share Posted June 7, 2017 Hello, I currently want to do a check where if someone is in a certain secondary group then it will change their name on their profile. So far I have something like this. {{if $member->member_group_id === 75}} <h1 class='ipsType_reset'> {$member->name} example example </h1> {{else}} <h1 class='ipsType_reset'> {$member->name} </h1> {{endif}} but I believe the {{if $member->member_group_id === 75}} only checks primary groups. is it possible to run a check of an ID of a secondary group. Thanks Rob Link to comment Share on other sites More sharing options...
Makoto Posted June 7, 2017 Share Posted June 7, 2017 {{if $member->inGroup()}} /** * Is the member in a certain group (including secondary groups) * * @param int|\IPS\Member\Group|array $group The group, or array of groups * @param bool $permissionArray If TRUE, checks the permission array rather than the groups * @return bool */ public function inGroup( $group, $permissionArray=FALSE ) { $group = array_filter( is_array( $group ) ? $group : array( $group ) ); $check = array_filter( $permissionArray ? $this->permissionArray() : $this->groups ); foreach ( $group as $_group ) { $groupId = ( $_group instanceof \IPS\Member\Group ) ? $_group->g_id : $_group; if ( in_array( $groupId, $check ) ) { return TRUE; } } return FALSE; } Link to comment Share on other sites More sharing options...
Rob Pearson Posted June 7, 2017 Author Share Posted June 7, 2017 @Makoto were do you put the secondary group id for it to check. Link to comment Share on other sites More sharing options...
Adriano Faria Posted June 7, 2017 Share Posted June 7, 2017 Examples: {{if \IPS\Member::loggedIn()->inGroup( explode( ',', \IPS\Settings::i()->setting_of_groups ) )}} or directly with IDs: {{if \IPS\Member::loggedIn()->inGroup( array( 4, 6, 9 ) )}} Link to comment Share on other sites More sharing options...
Rob Pearson Posted June 7, 2017 Author Share Posted June 7, 2017 Hey @Adriano Faria thanks once again for your great and swift help. It worked perfectly Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.