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

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

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