Jump to content

How to check if someone is in a certain secondary group?


Rob Pearson

Recommended Posts

Posted

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

Posted

{{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;
	}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...