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 / Components / WordpressUser / WordpressUser.php

WordpressUser.php in The GDPR Framework By Data443 2.1.0, at src/Components/WordpressUser/WordpressUser.php

122 lines 4.2 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\Components\WordpressUser;
4
5 use Codelight\GDPR\DataSubject\DataSubjectManager;
6 use Codelight\GDPR\Components\WordpressUser\Controllers\DashboardDataPageController;
7 use Codelight\GDPR\Components\WordpressUser\Controllers\DashboardProfilePageController;
8
9 /**
10 * Handles everything related to a WordPress user account
11 *
12 * Class WordpressUser
13 *
14 * @package Codelight\GDPR\Modules\WordpressUser
15 */
16 class WordpressUser
17 {
18 /* @var string */
19 protected $name = 'wordpress-user';
20
21 /* @var DataManager */
22 protected $dataManager;
23
24 /* @var DataSubjectManager */
25 protected $dataSubjectManager;
26
27 /**
28 * WordpressUser constructor.
29 *
30 * @param DataSubjectManager $dataSubjectManager
31 * @param DataManager $dataManager
32 */
33 public function __construct(DataSubjectManager $dataSubjectManager, DataManager $dataManager)
34 {
35 global $gdpr;
36 $this->dataSubjectManager = $dataSubjectManager;
37 $this->dataManager = $dataManager;
38
39 new DashboardProfilePageController($dataSubjectManager, $gdpr->DataExporter);
40 new RegistrationForm($dataSubjectManager);
41
42 if ($gdpr->Options->get('enable')) {
43 new DashboardDataPageController($gdpr->DataExporter, $gdpr->DataSubjectAuthenticator);
44
45 // Register Privacy Tools page in admin
46 add_action('admin_menu', [$this, 'registerDashboardDataPage']);
47 }
48
49 // Register render action on Profile edit page
50 add_action('show_user_profile', [$this, 'triggerProfileRenderAction'], PHP_INT_MAX);
51 add_action('edit_user_profile', [$this, 'triggerProfileRenderAction'], PHP_INT_MAX);
52
53 add_filter('gdpr/data-subject/data', [$this, 'getExportData'], 1, 2);
54 add_action('gdpr/data-subject/delete', [$this, 'deleteUser'], 100);
55 add_action('gdpr/data-subject/anonymize', [$this, 'anonymizeUser'], 100, 2);
56 }
57
58 /**
59 * Register Privacy Tools dashboard page under Users
60 */
61 public function registerDashboardDataPage()
62 {
63 add_users_page(
64 _x('Privacy Tools', '(Admin)', 'gdpr-framework'),
65 _x('Privacy Tools', '(Admin)', 'gdpr-framework'),
66 'read',
67 'gdpr-profile',
68 [$this, 'renderDashboardDataPage']
69 );
70 }
71
72 /**
73 * Render the contents of Privacy Tools dashboard page
74 */
75 public function renderDashboardDataPage()
76 {
77 $dataSubject = $this->dataSubjectManager->getByLoggedInUser();
78
79 if ($dataSubject) {
80 do_action('gdpr/dashboard/privacy-tools/content', $dataSubject);
81 }
82 }
83
84 /**
85 * On profile page, trigger an action with the same format as the Router provides
86 * so that we have consistency with the rest of the hooks.
87 */
88 public function triggerProfileRenderAction(\WP_User $user)
89 {
90 if (current_user_can('edit_users') || current_user_can('delete_users')) {
91 $dataSubject = $this->dataSubjectManager->getByEmail($user->user_email);
92 do_action("gdpr/dashboard/profile-page/content", $dataSubject);
93 do_action("gdpr/dashboard/profile-page/userlogs",$dataSubject);
94 }else{
95 $dataSubject = $this->dataSubjectManager->getByEmail($user->user_email);
96 do_action("gdpr/dashboard/profile-page/contentuser", $dataSubject);
97 do_action("gdpr/dashboard/profile-page/userlogs",$dataSubject);
98 }
99 }
100
101 public function getExportData($data, $email)
102 {
103 return $data + $this->dataManager->getData($this->dataSubjectManager->getByEmail($email));
104 }
105
106 public function deleteUser($email)
107 {
108 add_filter( 'send_email_change_email', '__return_false' );
109 add_filter( 'send_password_change_email', '__return_false' );
110 $dataSubject = $this->dataSubjectManager->getByEmail($email);
111 $this->dataManager->deleteUser($dataSubject);
112 }
113
114 public function anonymizeUser($email, $anonymizedId)
115 {
116 add_filter( 'send_email_change_email', '__return_false' );
117 add_filter( 'send_password_change_email', '__return_false' );
118 $dataSubject = $this->dataSubjectManager->getByEmail($email);
119 $this->dataManager->anonymizeUser($dataSubject, $anonymizedId);
120 }
121 }
122