1. 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

Discussion in 'XenForo Questions and Support' started by Will, Nov 11, 2011.

  1. Will

    Will Active Member

    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.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. Will

    Will Active Member

  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
    Cyb3r and Michael like this.
  5. Will

    Will Active Member

    That did it. Thanks.
     
  6. Sheldon

    Sheldon Well-Known Member

    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' ?
     
  7. Sheldon

    Sheldon Well-Known Member

    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?
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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>
     
    Cyb3r, ArnyVee and Sheldon like this.
  9. Sheldon

    Sheldon Well-Known Member

    Worked perfectly. Thank you so much. Now, say I continually add... just add in after 'YouTube', 'PSN')) etc, etc...?
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes exactly.
     
  11. Sheldon

    Sheldon Well-Known Member

    (y)

    Again, thanks for your help Jake. I appreciate the reply.
     
  12. Sheldon

    Sheldon Well-Known Member

    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?
     
  13. Will

    Will Active Member


    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>
     
  14. Sheldon

    Sheldon Well-Known Member

    And that would allow group 7 access to YouTube profile field, but not the others?
     
  15. Will

    Will Active Member

    It should but I have not tested it. Have you tried it?
     
  16. Sheldon

    Sheldon Well-Known Member

    I can, but I just didn't see where it is showing the YouTube to be accessible by group 7.
     
  17. Will

    Will Active Member

    Your right. I thought you were using both codes.
     
  18. Sheldon

    Sheldon Well-Known Member

    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>
     
  19. Will

    Will Active Member

    You don't have anything between that if statement which is why nothing is showing. You have the <xen:if> then you close it.
     
  20. Sheldon

    Sheldon Well-Known Member

    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.
     

Share This Page