Jump to content

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

Featured Replies

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

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

 

  • Author

@Makoto were do you put the secondary group id for it to check.

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 ) )}}

 

  • Author

Hey @Adriano Faria thanks once again for your great and swift help. It worked perfectly :D

Archived

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

Recently Browsing 0

  • No registered users viewing this page.