• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Allowing custom field for specific usergroup

Will

Active member
#1
I want to allow a specific usergroup to be able to see a custom profile field. I know it is not possible without customizing some code so any help would be appreciated.
 

Jake Bunce

XenForo moderator
Staff member
#4
Admin CP -> Appearance -> Templates -> custom_fields_edit

Add the red code:

Code:
<xen:foreach loop="$customFields" value="$field">
	<xen:if is="{$field.isEditable}">
		<xen:if is="{$field.field_id} != 'my_identifier' OR {xen:helper ismemberof, $visitor, 4}">
			<xen:include template="custom_field_edit" />
		</xen:if>
	</xen:if>
</xen:foreach>
You need to enter the field_id of the private field as well as the user_group_id of the privileged group.
 

Sheldon

Well-known member
#6
Admin CP -> Appearance -> Templates -> custom_fields_edit

Add the red code:

Code:
<xen:foreach loop="$customFields" value="$field">
<xen:if is="{$field.isEditable}">
<xen:if is="{$field.field_id} != 'my_identifier' OR {xen:helper ismemberof, $visitor, 4}">
<xen:include template="custom_field_edit" />
</xen:if>
</xen:if>
</xen:foreach>
You need to enter the field_id of the private field as well as the user_group_id of the privileged group.
Jake, if we have multiple fields we don't want edited to usergroups, do we copy the line in red and repeat, or do we add another beside the 'my_identifier' ?
 

Sheldon

Well-known member
#7
Ok, here is the actual code I have:
Code:
<xen:if is="{$field.field_id} != 'pano' OR {xen:helper ismemberof, $visitor, 3, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
I want to add another field beside 'pano', called 'YouTube'. Does anyone know how to add that in also?
 

Jake Bunce

XenForo moderator
Staff member
#8
Ok, here is the actual code I have:
Code:
<xen:if is="{$field.field_id} != 'pano' OR {xen:helper ismemberof, $visitor, 3, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
I want to add another field beside 'pano', called 'YouTube'. Does anyone know how to add that in also?
Try this:

Code:
<xen:if is="!in_array({$field.field_id}, array('pano', 'YouTube')) OR {xen:helper ismemberof, $visitor, 3, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
 

Sheldon

Well-known member
#9
Worked perfectly. Thank you so much. Now, say I continually add... just add in after 'YouTube', 'PSN')) etc, etc...?
 

Sheldon

Well-known member
#12
Jake, one last thing... haha. Came across something else.

Code:
<xen:if is="!in_array({$field.field_id}, array('pano', 'iPG')) OR {xen:helper ismemberof, $visitor, 3, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
That above is my code.

Now, I want to add another, but have it set different. It would be like the first code:
Code:
<xen:if is="{$field.field_id} != 'YouTube' OR {xen:helper ismemberof, $visitor, 3, 7, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
The main thing is, the YouTube field can now be seen by one extra group, but I don't want that same group to see the fields 'pano' or 'iPG'.

Can I just add that code above the first one?
 

Will

Active member
#13
Jake, one last thing... haha. Came across something else.

Code:
<xen:if is="!in_array({$field.field_id}, array('pano', 'iPG')) OR {xen:helper ismemberof, $visitor, 3, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
That above is my code.

Now, I want to add another, but have it set different. It would be like the first code:
Code:
<xen:if is="{$field.field_id} != 'YouTube' OR {xen:helper ismemberof, $visitor, 3, 7, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
The main thing is, the YouTube field can now be seen by one extra group, but I don't want that same group to see the fields 'pano' or 'iPG'.

Can I just add that code above the first one?

I would probably add to the first code to look like this

Code:
<xen:if is="!in_array({$field.field_id}, array('pano', 'iPG')) OR {xen:helper ismemberof, $visitor, 3, 17, 4} OR !{xen:helper ismemberof, $visitor, 7}">
    <xen:if is="{$field.isEditable}">
</xen:if>
 

Sheldon

Well-known member
#18
This is what I have right now:
Code:
<xen:foreach loop="$customFields" value="$field">
<xen:if is="{$field.field_id} != 'YouTube' OR {xen:helper ismemberof, $visitor, 3, 7, 17, 4}">
</xen:if>
<xen:if is="!in_array({$field.field_id}, array('pano', 'mixpod', 'mixpodautoplay', 'mixpodplaylistlink', 'mixpodcolor1', 'mixpodcolor2', 'mixpodcolor3')) OR {xen:helper ismemberof, $visitor, 3, 17, 4}">
    <xen:if is="{$field.isEditable}">
</xen:if>
        <xen:include template="custom_field_edit" />
This part is working as it should ---> <xen:if is="!in_array({$field.field_id}, array('pano', 'mixpod', 'mixpodautoplay', 'mixpodplaylistlink', 'mixpodcolor1', 'mixpodcolor2', 'mixpodcolor3')) OR {xen:helper ismemberof, $visitor, 3, 17, 4}">

This part isn't ---> <xen:if is="{$field.field_id} != 'YouTube' OR {xen:helper ismemberof, $visitor, 3, 7, 17, 4}">
</xen:if>
 

Sheldon

Well-known member
#20
You don't have anything between that if statement which is why nothing is showing. You have the <xen:if> then you close it.
It shows... for every usergroup. I wanted it to show for only this listed: {xen:helper ismemberof, $visitor, 3, 7, 17, 4}

I'm not following what you are saying above. That code will work by itself. I had it like that to begin with. Then Jake helped with the "array" part. Now, when I go to add that same thing back, and include the next <xen: if is> and </xen:if>, both won't work together.