An esteem customer asked us over email if it is possible for him to add an accept terms and conditions checkbox to his WordPress site registration form (powered by ProfilePress) which when left unchecked by registering users, prevent WordPress from creating an account for that user. In a nutshell, the account registration in WordPress will only be successfully if it is checked by registering users.

In this tutorial, i will be showing us how to add the checkbox to a ProfilePress powered front-end registration form and finally, provide a code snippet that will ensure the checkbox is checked before WordPress proceeds to creating a user account.

Adding the Checkbox to Registration Form

Firstly, create a custom profile field as shown in the picture.

Having done that, add the shortcode below to the position where you want the checkbox to appear in your registration form by clicking the title of the form to open up the edit screen.

[reg-cpf key="accept_privacy_terms" type="agreeable"]

If your currently active registration form is FlatUI, add the below preferably before the submit button.

<div class="form-group">

<label>[reg-cpf key="accept_privacy_terms" type="agreeable"]</label>

</div>

Ensuring Checkbox Is Checked Before Account Registration

To ensure the “accept terms & condition” checkbox is checked before the user account is created, add “required” to the shortcode like so:

<div class="form-group">

<label>[reg-cpf key="accept_privacy_terms" type="agreeable" required]</label>

</div>

Alternatively, add the code snippet below to your theme’s functions.php file or site specific plugin.

add_filter('pp_registration_validation', function ($reg_errors, $form_id) { if (3 === $form_id) { if ( ! isset($_POST['accept_privacy_terms']) || empty($_POST['accept_privacy_terms'])) { $reg_errors = new WP_Error('accept_privacy_terms', __( 'You must accept our privacy policy and terms.', 'profilepress' )); } } return $reg_errors; }, 10, 2);

Note: ensure you change “3” in the code snippet above to the ID of your registration form.

Tags: accept terms & conditions