PluginProbe
The GDPR Framework By Data443 / trunk
The GDPR Framework By Data443 vtrunk
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / Modules / ContactForm7 / ContactForm7.php

ContactForm7.php in The GDPR Framework By Data443 trunk, at src/Modules/ContactForm7/ContactForm7.php

123 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR\Modules\ContactForm7;
4
5 if ( ! defined( 'ABSPATH' ) ) exit;
6
7 use Codelight\GDPR\Components\Consent\ConsentManager;
8 use Codelight\GDPR\DataSubject\DataSubjectManager;
9
10 class ContactForm7
11 {
12 /* @var DataSubjectManager */
13 protected $dataSubjectManager;
14
15 /* @var ConsentManager */
16 protected $consentManager;
17
18 public function __construct(DataSubjectManager $dataSubjectManager, ConsentManager $consentManager)
19 {
20 $this->dataSubjectManager = $dataSubjectManager;
21 $this->consentManager = $consentManager;
22
23 //add_action('wpcf7_init', [$this, 'addFormTags'], 10, 3);
24 //add_action('wpcf7_admin_init', [$this, 'addFormTagGenerators'], 9999, 3);
25
26 add_action('wpcf7_before_send_mail', [$this, 'processFormSubmission'], 10, 3);
27 }
28
29 public function addFormTags()
30 {
31 wpcf7_add_form_tag(
32 ['gdpr_consent_text'],
33 [$this, 'renderPrivacyTag']
34 );
35 }
36
37 public function addFormTagGenerators()
38 {
39 $generator = \WPCF7_TagGenerator::get_instance();
40
41 $generator->add(
42 'gdpr_privacy',
43 _x('gdpr terms txt', '(Admin)', 'gdpr-framework'),
44 [$this, 'generatePrivacyTag']
45 );
46 }
47
48 public function generatePrivacyTag($contactForm, $args)
49 {
50 //$args = wp_parse_args( $args, array() );
51 //$description = _x( "Generate the default text for your Privacy Policy acceptance checkbox. For more details, see %s.", '(Admin)', 'gdpr-framework' );
52 //$descLink = wpcf7_link( _x( 'https://TODO', '(Admin)', 'gdpr-framework' ), _x( 'GDPR Terms', '(Admin)', 'gdpr-framework' ) );
53 //$content = $this->renderPrivacyTag();
54
55 echo gdpr('view')->render(
56 'modules/contact-form-7/generator-privacy',
57 compact('description', 'descLink', 'args', 'content')
58 );
59 }
60
61 public function renderPrivacyTag()
62 {
63 global $gdpr;
64 $privacyPolicyUrl = get_permalink($gdpr->Options->get('policy_page'));
65 add_filter( 'gdpr_custom_policy_link', 'gdprfPrivacyPolicyurl' );
66 $privacyPolicyUrl = apply_filters( 'gdpr_custom_policy_link',$privacyPolicyUrl);
67 return gdpr('view')->render(
68 'modules/contact-form-7/content-privacy',
69 compact('privacyPolicyUrl')
70 );
71 }
72
73 public function processFormSubmission(\WPCF7_ContactForm $form, $abort, \WPCF7_Submission $submission)
74 {
75 $consents = $this->findConsents($form, $submission);
76
77 if (!count($consents)) {
78 return;
79 }
80
81 $email = $this->findEmail($form,$submission);
82
83 if (!$email) {
84 return;
85 }
86
87 $dataSubject = $this->dataSubjectManager->getByEmail($email);
88
89 foreach ($consents as $consent) {
90 $dataSubject->giveConsent($consent);
91 }
92 }
93
94 public function findConsents(\WPCF7_ContactForm $form, \WPCF7_Submission $submission)
95 {
96 $consents = [];
97
98 foreach ($form->scan_form_tags() as $tag) {
99 /* @var $tag \WPCF7_FormTag */
100 if ('acceptance' === $tag->type && $submission->get_posted_data()[$tag->name] && $this->consentManager->isRegisteredConsent($tag->name)) {
101 $consents[] = $tag->name;
102 }
103 }
104
105 return $consents;
106 }
107
108 public function findEmail($form_id,\WPCF7_Submission $submission)
109 {
110 $email_key = get_post_meta($form_id->id(), 'gdpr_cf7_email_field', true );
111 if (isset($submission->get_posted_data()['your-email'])) {
112 return $submission->get_posted_data()['your-email'];
113 }
114 if(isset($email_key)){
115 if($email_key!=""){
116 if (isset($submission->get_posted_data()[$email_key])) {
117 return $submission->get_posted_data()[$email_key];
118 }
119 }
120 }
121 }
122 }
123