The extended answer...
// Add the checkbox to registration form
add_action( 'register_form', 'foo_add_privacy_policy_field' );
function foo_add_privacy_policy_field() {
?>
<p>
<input type="checkbox" name="foo_privacy_policy" id="foo_privacy_policy" class="checkbox" style="float: left; height: 50px;" />
<label for="foo_privacy_policy"><?php _e( 'Privacy Policy', 'foo' ) ?>
</label>
</p>
<?php
}
// Validate the checkbox value in the registration form so that it is required
add_filter( 'registration_errors', 'foo_privacy_policy_auth', 10, 3 );
function foo_privacy_policy_auth( $errors, $sanitized_user_login, $user_email ) {
if ( !isset( $_POST['foo_privacy_policy'] ) ) :
$errors->add( 'policy_error', "<strong>ERROR</strong>: Please accept the privacy policy." );
return $errors;
endif;
return $errors;
}
// Fill the meta 'foo_privacy_policy' with the value of the checkbox
add_action( 'personal_options_update', 'foo_privacy_policy_save' );
add_action( 'edit_user_profile_update', 'foo_privacy_policy_save' );
add_action( 'user_register', 'foo_privacy_policy_save' );
function foo_privacy_policy_save( $user_id ) {
if ( isset( $_POST['foo_privacy_policy'] ) ){
update_user_meta( $user_id, 'foo_privacy_policy', $_POST['foo_privacy_policy'] );
}else{
update_user_meta( $user_id, 'foo_privacy_policy', 'off' );
}
}
// Add the checkbox to user profile home
add_action( 'show_user_profile', 'foo_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'foo_show_extra_profile_fields' );
function foo_show_extra_profile_fields( $user ) {
?>
<h3><?php esc_html_e( 'Privacy Policy', 'foo' ); ?></h3>
<table class="form-table">
<tr>
<td>
<input type="checkbox" name="foo_privacy_policy" id="foo_privacy_policy" class="checkbox" style="float: left; height: 50px;" <?php if(get_the_author_meta('foo_privacy_policy', $user->ID)=='on' ){ echo "checked"; } ?> />
<label for="foo_privacy_policy"><?php _e( 'Privacy Policy', 'foo' ) ?>
</label></td>
</tr>
</table>
<?php
}