PluginProbe
The GDPR Framework By Data443 / 2.1.0
The GDPR Framework By Data443 v2.1.0
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 / NewsletterGdpr / NewsletterGdpr.php

NewsletterGdpr.php in The GDPR Framework By Data443 2.1.0, at src/Modules/NewsletterGdpr/NewsletterGdpr.php

102 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Codelight\GDPR\Modules\NewsletterGdpr;
3
4 use Codelight\GDPR\Components\Consent\ConsentManager;
5 use Codelight\GDPR\DataSubject\DataSubjectManager;
6
7 if(file_exists(dirname( ES_PLUGIN_FILE ) . '/includes/db/class-es-db-contacts.php'))
8 {
9 include_once dirname( ES_PLUGIN_FILE ) . '/includes/db/class-es-db-contacts.php';
10 }else{
11 include_once dirname( ES_PLUGIN_FILE ) . '/lite/includes/db/class-es-db-contacts.php';
12 }
13
14 // Support plugin name: Email Subscribers & Newsletters
15
16 class NewsletterGdpr
17 {
18 public function __construct(DataSubjectManager $dataSubjectManager, ConsentManager $consentManager)
19 {
20 $this->dataSubjectManager = $dataSubjectManager;
21 $this->consentManager = $consentManager;
22
23 if (!defined('ES_PLUGIN_VERSION'))
24 {
25 return;
26 }
27
28 add_filter('gdpr/data-subject/data', [$this, 'getNewsletterExportData'], 20, 2);
29 add_action('gdpr/data-subject/delete', [$this, 'deleteNewsletterEntries']);
30 add_action('gdpr/data-subject/anonymize', [$this, 'deleteNewsletterEntries']);
31 add_action('ig_es_after_form_fields',[$this, 'newsletter_checkbox_consent']);
32 add_filter('ig_es_add_subscriber_data', [$this, 'newsletter_gdpr_consent']);
33
34 }
35
36 public function newsletter_checkbox_consent($data)
37 {
38 global $gdpr;
39 $policyPage = $gdpr->Options->get('policy_page');
40
41 $policyPageUrl = get_permalink($policyPage);
42
43 add_filter( 'gdpr-framework-consent-policy', 'gdprfPrivacyPolicy' );
44
45 $gdpr_text_policy = apply_filters( 'gdpr-framework-consent-policy','true');
46
47 $data = '<div class="es-field-wrap">
48 <input type="checkbox" name="es-gdpr-agree" id="es-gdpr-agree" value="1" required="required"> ';
49 $data .= sprintf(
50 __($gdpr_text_policy, 'gdpr-framework'),
51 "<a href='{$policyPageUrl}' target='_blank'>",
52 "</a>");
53 $data .='</div>';
54
55 echo $data;
56 }
57
58 public function newsletter_gdpr_consent($data){
59 if($_POST['esfpx_email']){
60
61 $esfpx_email = sanitize_email($_POST['esfpx_email']);
62 $dataSubject = $this->dataSubjectManager->getByEmail($esfpx_email);
63 $dataSubject->giveConsent('privacy-policy');
64 }
65 return $data;
66 }
67
68 public function getNewsletterExportData(array $data, $email)
69 {
70 global $wpdb;
71
72 $results = $wpdb->get_row($wpdb->prepare("SELECT wc.*, GROUP_CONCAT(DISTINCT ls.name ORDER BY ls.name) as list_details FROM {$wpdb->prefix}ig_contacts as wc LEFT JOIN {$wpdb->prefix}ig_lists_contacts as wl ON wc.id = wl.contact_id LEFT JOIN {$wpdb->prefix}ig_lists as ls ON ls.id = wl.list_id WHERE email = %s",sanitize_email($email)),ARRAY_A);
73
74 if (!count($results)) {
75 return $data;
76 }
77
78 unset($results['hash'],$results['is_rolebased'],$results['is_webmail'],$results['is_deliverable'],$results['is_sendsafely'],$results['is_verified'],$results['is_disposable'],$results['id']);
79
80 if($results['email'])
81 {
82 $title = __('Newsletter Form submissions: ', 'gdpr');
83 foreach ($results as $i => $message)
84 {
85 $data[$title][$i] = $message;
86 }
87 }
88
89 return $data;
90 }
91 /*
92 * Delete user information from order by email address.
93 */
94 public function deleteNewsletterEntries($email)
95 {
96 $contact_id = \ES_DB_Contacts::get_contact_id_by_email($email);
97 if($contact_id){
98 \ES_DB_Contacts::delete_subscribers(array($contact_id));
99 }
100 }
101 }
102