XF 1.5 How to hide a custom field on Account > Preferences page if member is in specific usergroup?

CTXMedia

Well-known member
I have created a custom field for members to opt-in to our politics forum; ticking the box on the Account > Preferences page adds them to the 'Politics' usergroup.

We also sometimes have to exclude members from the politics forum so we have a 'No Politics' usergroup too, which overrides the 'Politics' group.

Because members who are excluded can no longer control access to the politics forum, I'd like to remove the custom field from view on the account preferences page when someone is in the 'No Politics' group.

How would I go about this please?

Thanks,
Shaun
 
Last edited:
Having had a little look at the templates I'm guessing that I'd need to put a conditional in custom_fields_edit?

This should stop the field displaying for anyone in the No Politics usergroup:
Rich (BB code):
<xen:foreach loop="$customFields" value="$field">
   <xen:if is="!{xen:helper ismemberof, $visitor, 27}">
       <xen:if is="{$field.isEditable}">
           <xen:include template="custom_field_edit" />
       </xen:if>
   </xen:if>
</xen:foreach>

However it will also stop all editable custom fields from displaying for anyone in the no politics group and ideally I only want to stop it displaying the custom field name: politics_opt_in

Any help on how to add that part into the conditional would be helpful.

Thanks,
Shaun
 
Would this do the trick?
Rich (BB code):
<xen:foreach loop="$customFields" value="$field">
   <xen:if is="!{xen:helper ismemberof, $visitor, 27} AND {$field.field_id} != 'politics_opt_in'">
       <xen:if is="{$field.isEditable}">
           <xen:include template="custom_field_edit" />
       </xen:if>
   </xen:if>
</xen:foreach>
 
Last edited:
Approached it a slightly different way - do nothing if in the No Politics group and displaying the Politics opt-in field (else display field if it is editable):
Code:
<xen:foreach loop="$customFields" value="$field">
    <xen:if is="{xen:helper ismemberof, $visitor, 27} AND {$field.field_id} == 'politics_opt_in'">
    <xen:else />
        <xen:if is="{$field.isEditable}">
            <xen:include template="custom_field_edit" />
        </xen:if>
    </xen:if>
</xen:foreach>
 
@CyclingTribe I use; @cclaerhout's Custom User Fields Permissions (free) add-on to allow access to a user field permission (whitelist) and then my User Promotion on Profile Update (free) add-on to allow user promotions to select on a particular custom field being empty. The last add-on also applies the user promo when they change custom fields.

After that it is just juggling of the wording to make things look right
Thanks @Xon - I don't think, in my particular case, @cclaerhout's add-on would help. The field permissions with that add-on are additive, so whilst I might put someone in the 'No Politics' group for a short time, they'd still be in the Registered group too, so it wouldn't stop the field appearing.

I have used your add-on though to instanly apply the change of usergroup when someone opts-in to the politics group, so thanks again for another useful little 'extra'. (y)
 
  • Like
Reactions: Xon
Top Bottom