| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codelight\GDPR\Components\WordpressUser; |
| 4 |
|
| 5 |
use Codelight\GDPR\DataSubject\DataSubject; |
| 6 |
use Codelight\GDPR\DataSubject\DataSubjectManager; |
| 7 |
|
| 8 |
class RegistrationForm |
| 9 |
{ |
| 10 |
/* @var DataSubjectManager */ |
| 11 |
protected $dataSubjectManager; |
| 12 |
|
| 13 |
public function __construct(DataSubjectManager $dataSubjectManager) |
| 14 |
{ |
| 15 |
global $gdpr; |
| 16 |
$this->dataSubjectManager = $dataSubjectManager; |
| 17 |
if(!$gdpr->Options->get('register_checkbox')){ |
| 18 |
if ($gdpr->Options->get('policy_page') || $gdpr->Options->get('custom_policy_page')) { |
| 19 |
add_action('register_form', [$this, 'addRegisterFormCheckbox']); |
| 20 |
add_filter('registration_errors', [$this, 'validate'], PHP_INT_MAX); |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function addRegisterFormCheckbox() |
| 26 |
{ |
| 27 |
global $gdpr; |
| 28 |
$privacyPolicyUrl = ! get_permalink( gdpr( 'options' )->get( 'custom_policy_page' ) ) ? get_permalink( gdpr( 'options' )->get( 'policy_page' ) ) : get_permalink( gdpr( 'options' )->get( 'custom_policy_page' ) ); |
| 29 |
add_filter( 'gdpr_custom_policy_link', 'gdprfPrivacyPolicyurl' ); |
| 30 |
$privacyPolicyUrl = apply_filters( 'gdpr_custom_policy_link',$privacyPolicyUrl); |
| 31 |
$termsPage = ! $gdpr->Options->get('custom_terms_page') ? $gdpr->Options->get('terms_page') : $gdpr->Options->get('custom_terms_page'); |
| 32 |
|
| 33 |
if($gdpr->Options->get('custom_terms_page')){ |
| 34 |
$termsPage = $gdpr->Options->get('custom_terms_page'); |
| 35 |
if ($termsPage) { |
| 36 |
$termsUrl = $termsPage; |
| 37 |
} else { |
| 38 |
$termsUrl = false; |
| 39 |
} |
| 40 |
}else{ |
| 41 |
$termsPage = $gdpr->Options->get('terms_page'); |
| 42 |
if ($termsPage) { |
| 43 |
$termsUrl = get_permalink($termsPage); |
| 44 |
} else { |
| 45 |
$termsUrl = false; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
echo gdpr('view')->render( |
| 50 |
'modules/wordpress-user/registration-terms-checkbox', |
| 51 |
compact('privacyPolicyUrl', 'termsUrl') |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
public function validate(\WP_Error $errors) |
| 56 |
{ |
| 57 |
if (empty($_POST['gdpr_terms']) || !$_POST['gdpr_terms']) { |
| 58 |
$errors->add('gdpr_error', __('<strong>ERROR</strong>: You must accept the terms and conditions.', 'gdpr-framework')); |
| 59 |
} else { |
| 60 |
$dataSubject = $this->dataSubjectManager->getByEmail($_POST['user_email']); |
| 61 |
$dataSubject->giveConsent('privacy-policy'); |
| 62 |
} |
| 63 |
|
| 64 |
return $errors; |
| 65 |
} |
| 66 |
} |
| 67 |
|