Add TOS to Membership registration

I have a membership site set up and really love how it works except for one issue: I can't get the terms and conditions that all users MUST agree to to be presented to the user during registration and to prevent them from signing up without agreeing.

The membership plugin uses its own registration form and not the default WordPress multisite one. Does anyone know a way to incorporate some kind of required terms agreement into THIS registration form? Thanks for the help.

  • Alexander
    • DEV MAN’s Mascot

    Hi @kylem,

    This can be done with a little code. If you're ok with a code solution, here's something I just put together. Just include in a plugin or your theme's functions.php I haven't had a moment to test it yet, but all it does is add a checkbox for TOS agreement, and validates it on signup.

    add_filter('membership_subscription_form_before_registration_process','membership_tos_validate');
    
    function membership_tos_validate($error) {
        if(isset($_POST['tos_agree']) ) {
            return $error; //pass
        }
        else
        {
            $error->add('notos', 'You must agree to the TOS');
        }
    }
    
    add_action('signup_extra_fields','membership_tos_field',10,1);
    
    function membership_tos_field($error) { ?>
                <div class="form-element">
                    <label class="control-label" for="user_email">I Agree to the <a href="#">TOS</a></label>
                    <div class="element">
                        <input type="text" class="checkbox" name="tos_agree" value="1">
                    </div>
                </div>
                <?php
    }

    Let me know if you need any extra help here.

    Best regards

  • kylem
    • Design Lord, Child of Thor

    Hey thanks @Alexander Rohmann. I tried throwing this in my functions.php file to no avail. It didn't add anything for me. Is there a different way to implement this? It looks right to me.

    Hey @Jimmy, I've already looked at that plugin a few times. My problem is that I am trying to use the WPMUDEV membership plugin which uses a different form.

  • Alexander
    • DEV MAN’s Mascot

    Hi @Kylem,

    I'm not sure why this isn't working. Can you try this version instead? I've just changed it to use a different action hook

    add_filter('membership_subscription_form_before_registration_process','membership_tos_validate');
    
    function membership_tos_validate($error) {
        if(isset($_POST['tos_agree']) ) {
            return $error; //pass
        }
        else
        {
            $error->add('notos', 'You must agree to the TOS');
        }
    }
    
    add_action('membership_subscription_form_registration_presubmit_content','membership_tos_field');
    
    function membership_tos_field($error) { ?>
                <div class="form-element">
                    <label class="control-label" for="user_email">I Agree to the <a href="#">TOS</a></label>
                    <div class="element">
                        <input type="checkbox" class="checkbox" name="tos_agree" value="1">
                    </div>
                </div>
                <?php
    }
  • Colleen
    • New Recruit

    Hi @Alexander_Rohmann (or anyone!)

    I am using the Membership plugin and am using the Terms of Service plugin as well. I do not have a Buddypress site though so I can not force the user to check the box.

    I came across this forum and tried your hooks. For some reason the number "1" shows up in the box when you open. It also still works whether or not you check off either of the TOS boxes.

    Any help here would be so appreciated. Thank you.

  • Alexander
    • DEV MAN’s Mascot

    Hi @Colleen,

    I'm sorry about that, I made a mistake in the code and didn't declare it as a checkbox properly. I've updated the post above to correct this.

    To summarize the change:
    <input type="text" class="checkbox" name="tos_agree" value="1">
    is now:
    <input type="checkbox" class="checkbox" name="tos_agree" value="1">

    Let me know how it goes!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.