-
Notifications
You must be signed in to change notification settings - Fork 6
/
class-privacypolicy.php
160 lines (139 loc) · 4.71 KB
/
class-privacypolicy.php
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
<?php
namespace H5PXAPIKATCHU;
/**
* Handle privacy policy
*
* @package H5PXAPIKATCHU
* @since 0.2.2
*/
class PrivacyPolicy {
private static $page_size = 25;
/**
* Start up
*/
public function __construct() {
// Data privacy hooks
add_action( 'admin_init', 'add_privacy_policy', 20 );
add_filter( 'wp_privacy_personal_data_exporters', 'register_h5pxapikatchu_exporter', 10 );
add_filter( 'wp_privacy_personal_data_erasers', 'register_h5pxapikatchu_eraser', 10 );
}
/**
* Add privacy policy text to WP.
*/
function add_privacy_policy() {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}
$link_xapi = sprintf(
'<a href="https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md" target="_blank">%s</a>',
__( 'xAPI', 'H5PXAPIKATCHU' )
);
// Intentionally using the WordPress translation here.
$content = '<h2>' . __( 'What personal data we collect and why we collect it' ) . '</h2>';
$content .= '<h3>' . __( 'H5PxAPIkatchu', 'H5PXAPIKATCHU' ) . '</h3>';
$content .= '<p>';
$content .= sprintf(
// translators: %s will be replaced by the name of the service
__(
'When you use interactive content, we may collect data about your interaction using %s.',
'H5PXAPIKATCHU'
),
$link_xapi
) . ' ';
$content .= __( 'The data may e.g. contain what answer was given, how long it took to answer, what score was achieved, etc.', 'H5PXAPIKATCHU' ) . ' ';
$content .= __( 'We use the data to learn about how well the interaction is designed and how it could be adapted to improve the usability and learning outcomes in general.', 'H5PXAPIKATCHU' );
$content .= '</p>';
$content .= '<p>';
$content .= __( 'However, if and only if you are logged in, this data will be tied to your full name, your email address, and your WordPress user id.', 'H5PXAPIKATCHU' ) . ' ';
$content .= __( 'In consequence, your interactions could be linked to you.', 'H5PXAPIKATCHU' ) . ' ';
$content .= __( 'Therefore, all personal data can be stripped to anonymize the data.', 'H5PXAPIKATCHU' );
$content .= '</p>';
wp_add_privacy_policy_content(
__( 'H5PxAPIkatchu', 'H5PXAPIKATCHU' ),
wp_kses_post( wpautop( $content, false ) )
);
}
/**
* Export user data.
* @param string $email Email address.
* @param int $page Page.
* @return array Export data.
*/
function h5pxapikatchu_exporter( $email, $page = 1 ) {
$page_size = self::$page_size; // Limit of xAPI items to process to avoid timeout
$page = (int) $page;
$export_items = array();
$results = array();
$wp_user = get_user_by( 'email', $email );
if ( $wp_user ) {
// Retrieve xAPI data for user
$results = Database::get_user_table( $wp_user->ID, $page, $page_size );
$column_titles = Database::get_column_titles();
// Build items for exporter
foreach ( $results as $result ) {
$data = array();
foreach ( $result as $label => $value ) {
$name = isset( Database::$column_title_names[ $label ] ) ?
Database::$column_title_names[ $label ] :
$label;
$data[] = array(
'name' => $name,
'value' => $value,
);
}
$export_items[] = array(
'group_id' => 'h5pxapikatchu',
'group_label' => __( 'H5PxAPIkatchu', 'H5PXAPIKATCHU' ),
'item_id' => "h5pxapikatchu-{$result->id}",
'data' => $data,
);
}
}
return array(
'data' => $export_items,
'done' => count( $results ) < $page_size,
);
}
/**
* Register the exporter.
* @param array $exporters Previous exporters.
* @return array H5PxAPIkatchu exporters.
*/
function register_h5pxapikatchu_exporter( $exporters ) {
$exporters['h5pxapikatchu'] = array(
'exporter_friendly_name' => __( 'H5PxAPIkatchu', 'H5PXAPIKATCHU' ),
'callback' => 'H5PXAPIKATCHU\PrivacyPolicy::h5pxapikatchu_exporter',
);
return $exporters;
}
/**
* Anonymize/erase user data
*/
function h5pxapikatchu_eraser( $email, $page = 1 ) {
$page_size = self::$page_size;
$wp_user = get_user_by( 'email', $email );
$error = false;
if ( $wp_user ) {
// There should only be one actor with the user ID, but pagination doesn't hurt
$number = Database::anonymize( $wp_user->ID, $page_size );
}
return array(
'items_removed' => $number,
'items_retained' => false,
'messages' => array(),
'done' => $number < $page_size,
);
}
/**
* Register the eraser.
* @param array $erasers Previous erasers.
* @return array H5PxAPIkatchu erasers.
*/
function register_h5pxapikatchu_eraser( $erasers ) {
$erasers['h5pxapikatchu'] = array(
'eraser_friendly_name' => __( 'H5PxAPIkatchu', 'H5PXAPIKATCHU' ),
'callback' => 'H5PXAPIKATCHU\PrivacyPolicy::h5pxapikatchu_eraser',
);
return $erasers;
}
}