class-admin-gdpr.php
9.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'um\admin\core\Admin_GDPR' ) ) {
/**
* Class Admin_GDPR
* @package um\admin\core
*/
class Admin_GDPR {
/**
* @var array
*/
var $meta_associations = array();
/**
* Admin_GDPR constructor.
*/
function __construct() {
add_action( 'init', array( &$this, 'init_fields' ), 10 );
add_action( 'admin_init', array( &$this, 'plugin_add_suggested_privacy_content' ), 20 );
add_filter( 'wp_privacy_personal_data_exporters', array( &$this, 'plugin_register_exporters' ) );
add_filter( 'wp_privacy_personal_data_erasers', array( &$this, 'plugin_register_erasers' ) );
add_action( 'um_admin_custom_register_metaboxes', array( &$this, 'add_metabox_register' ) );
}
/**
*
*/
function add_metabox_register() {
add_meta_box(
"um-admin-form-register_gdpr",
__( 'Privacy Policy', 'ultimate-member' ),
array( UM()->metabox(), 'load_metabox_form' ),
'um_form',
'side',
'default'
);
}
/**
*
*/
function init_fields() {
$this->meta_associations = array(
'account_status' => __( 'Account Status', 'ultimate-member' ),
'submitted' => __( 'Submitted data on Registration', 'ultimate-member' ),
'form_id' => __( 'Registration Form ID', 'ultimate-member' ),
'timestamp' => __( 'Registration Timestamp', 'ultimate-member' ),
'request' => __( 'Registration Request', 'ultimate-member' ),
'_wpnonce' => __( 'Registration Nonce', 'ultimate-member' ),
'_wp_http_referer' => __( 'Registration HTTP referer', 'ultimate-member' ),
'role' => __( 'Community Role', 'ultimate-member' ),
'um_user_profile_url_slug_user_login' => __( 'Profile Slug "Username"', 'ultimate-member' ),
'um_user_profile_url_slug_name' => __( 'Profile Slug "First and Last Name with \'.\'"', 'ultimate-member' ),
'um_user_profile_url_slug_name_dash' => __( 'Profile Slug "First and Last Name with \'-\'"', 'ultimate-member' ),
'um_user_profile_url_slug_name_plus' => __( 'Profile Slug "First and Last Name with \'+\'"', 'ultimate-member' ),
'um_user_profile_url_slug_user_id' => __( 'Profile Slug "User ID"', 'ultimate-member' ),
'_um_last_login' => __( 'Last Login Timestamp', 'ultimate-member' ),
//Private content extension
'_um_private_content_post_id' => __( 'Private Content Post ID', 'ultimate-member' ),
//Verified Users extension
'_um_verified' => __( 'Verified Account', 'ultimate-member' ),
//Terms & Conditions extension
'use_terms_conditions_agreement' => __( 'Terms&Conditions Agreement', 'ultimate-member' ),
//GDPR extension
'use_gdpr_agreement' => __( 'Privacy Policy Agreement', 'ultimate-member' ),
);
$all_fields = UM()->builtin()->all_user_fields( null, true );
unset( $all_fields[0] );
$all_fields = array_map( function( $value ) {
return $value['title'];
}, $all_fields );
$this->meta_associations = array_merge( $this->meta_associations, $all_fields );
/**
* UM hook
*
* @type filter
* @title um_gdpr_meta_associations
* @description Exclude taxonomies for UM
* @input_vars
* [{"var":"$meta_associations","type":"array","desc":"Meta Keys Titles"}]
* @change_log
* ["Since: 2.0.14"]
* @usage
* <?php add_filter( 'um_gdpr_meta_associations', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_gdpr_meta_associations', 'my_gdpr_meta_associations', 10, 1 );
* function my_gdpr_meta_associations( $meta_associations ) {
* // your code here
* return $meta_associations;
* }
* ?>
*/
$this->meta_associations = apply_filters( 'um_gdpr_meta_associations', $this->meta_associations );
}
/**
* Return the default suggested privacy policy content.
*
* @return string The default policy content.
*/
function plugin_get_default_privacy_content() {
ob_start();
include UM()->admin()->templates_path . 'gdpr.php';
return ob_get_clean();
}
/**
* Add the suggested privacy policy text to the policy postbox.
*/
function plugin_add_suggested_privacy_content() {
$content = $this->plugin_get_default_privacy_content();
wp_add_privacy_policy_content( ultimatemember_plugin_name, $content );
}
/**
* Register exporter for Plugin user data.
*
* @see https://github.com/allendav/wp-privacy-requests/blob/master/EXPORT.md
*
* @param $exporters
*
* @return array
*/
function plugin_register_exporters( $exporters ) {
$exporters[] = array(
'exporter_friendly_name' => ultimatemember_plugin_name,
'callback' => array( &$this, 'data_exporter' )
);
return $exporters;
}
/**
* Get user metadata in key => value array
*
*
* @param $user_id
*
* @return array
*/
function get_metadata( $user_id ) {
global $wpdb;
$metadata = $wpdb->get_results( $wpdb->prepare(
"SELECT meta_key, meta_value
FROM {$wpdb->usermeta}
WHERE user_id = %d",
$user_id
), ARRAY_A );
$filtered = array();
foreach ( $metadata as $data ) {
if ( in_array( $data['meta_key'], array_keys( $this->meta_associations ) ) ) {
$filtered[] = array(
'key' => $data['meta_key'],
'name' => $this->meta_associations[ $data['meta_key'] ],
//'value' => maybe_unserialize( $data['meta_value'] ),
'value' => $data['meta_value'],
);
}
}
return $filtered;
}
/**
* Exporter for Plugin user data.
*
* @see https://github.com/allendav/wp-privacy-requests/blob/master/EXPORT.md
*
* @param $email_address
* @param int $page
*
* @return array
*/
function data_exporter( $email_address, $page = 1 ) {
$export_items = array();
$user = get_user_by( 'email', $email_address );
if ( $user && $user->ID ) {
// Most item IDs should look like postType-postID
// If you don't have a post, comment or other ID to work with,
// use a unique value to avoid having this item's export
// combined in the final report with other items of the same id
$item_id = "ultimate-member-{$user->ID}";
// Core group IDs include 'comments', 'posts', etc.
// But you can add your own group IDs as needed
$group_id = 'ultimate-member';
// Optional group label. Core provides these for core groups.
// If you define your own group, the first exporter to
// include a label will be used as the group label in the
// final exported report
$group_label = ultimatemember_plugin_name;
// Plugins can add as many items in the item data array as they want
//$data = array();
$data = $this->get_metadata( $user->ID );
if ( ! empty( $data ) ) {
// Add this group of items to the exporters data array.
$export_items[] = array(
'group_id' => $group_id,
'group_label' => $group_label,
'item_id' => $item_id,
'data' => $data,
);
}
}
// Returns an array of exported items for this pass, but also a boolean whether this exporter is finished.
//If not it will be called again with $page increased by 1.
return array(
'data' => $export_items,
'done' => true,
);
}
/**
* Register eraser for Plugin user data.
*
* @param array $erasers
*
* @return array
*/
function plugin_register_erasers( $erasers = array() ) {
$erasers[] = array(
'eraser_friendly_name' => ultimatemember_plugin_name,
'callback' => array( &$this, 'data_eraser' )
);
return $erasers;
}
/**
* Eraser for Plugin user data.
*
* @param $email_address
* @param int $page
*
* @return array
*/
function data_eraser( $email_address, $page = 1 ) {
if ( empty( $email_address ) ) {
return array(
'items_removed' => false,
'items_retained' => false,
'messages' => array(),
'done' => true,
);
}
$user = get_user_by( 'email', $email_address );
$messages = array();
$items_removed = false;
$items_retained = false;
if ( $user && $user->ID ) {
$data = $this->get_metadata( $user->ID );
foreach ( $data as $metadata ) {
$deleted = delete_user_meta( $user->ID, $metadata['key'] );
if ( $deleted ) {
$items_removed = true;
} else {
$messages[] = sprintf( __( 'Your %s was unable to be removed at this time.', 'ultimate-member' ), $metadata['name'] );
$items_retained = true;
}
}
}
// Returns an array of exported items for this pass, but also a boolean whether this exporter is finished.
//If not it will be called again with $page increased by 1.
return array(
'items_removed' => $items_removed,
'items_retained' => $items_retained,
'messages' => $messages,
'done' => true,
);
}
}
}