LLMS_Privacy_Erasers
LifterLMS Privacy Eraser class
Source Source
File: includes/privacy/class-llms-privacy-erasers.php
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 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | class LLMS_Privacy_Erasers extends LLMS_Privacy { /** * Erase student certificate data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return array * @since 3.18.0 * @version 3.18.0 */ public static function achievement_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $messages = array (); $achievements = self::get_student_achievements( $student ); if ( $achievements ) { foreach ( $achievements as $achievement ) { $messages [] = sprintf( 'Achievement %d deleted.' , $achievement ->get( 'id' ) ); $achievement -> delete (); } } return self::get_return( $messages , true, ( $messages ) ); } /** * Setup anonymous values for anonymized data * * @param string $val default anonymous value ('') * @param string $prop key name of the property * @param obj $obj related object * @return mixed * @since 3.18.0 * @version 3.18.0 */ public static function anonymize_prop( $val , $prop , $obj = null ) { switch ( $prop ) { case 'user_id' : $val = 0; break ; } return $val ; } /** * Erase student certificate data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return array * @since 3.18.0 * @version 3.18.0 */ public static function certificate_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $messages = array (); $certs = self::get_student_certificates( $student ); if ( $certs ) { foreach ( $certs as $cert ) { $messages [] = sprintf( 'Certificate %d deleted.' , $cert ->get( 'id' ) ); $cert -> delete (); } } return self::get_return( $messages , true, ( $messages ) ); } /** * Return export data to an exporter * * @param array $messages array of messages * @return array * @since 3.18.0 * @version 3.18.0 */ private static function get_return( $messages = array (), $done = true, $removed = false, $retained = false ) { return array ( 'messages' => $messages , 'done' => $done , 'items_removed' => $removed , 'items_retained' => $retained , ); } /** * Erase notifications for a student * * @param LLMS_Student $student * @return array * @since 3.18.0 * @version 3.18.0 */ private static function erase_notification_data( $student ) { $messages = array (); global $wpdb ; $deleted = $wpdb ->query( $wpdb ->prepare( "DELETE FROM {$wpdb->prefix}lifterlms_notifications WHERE user_id = %d OR subscriber = %d" , $student ->get( 'id' ), $student ->get( 'id' ) ) ); if ( $deleted ) { // Translators: %d = number of notifications. $messages [] = sprintf( __( 'Removed %d notifications.' , 'lifterlms' ), $deleted ); } return apply_filters( 'llms_privacy_erase_notification_data' , $messages , $student ); } /** * Erase and anonymize an order * * @since 3.18.0 * @since 3.30.3 Fixed spelling error. * * @param LLMS_Order $order Order object. * @return void */ private static function erase_order_data( $order ) { // Cancel recurring orders. if ( $order ->is_recurring() && in_array( $order ->get( 'status' ), array ( 'llms-on-hold' , 'llms-active' , 'llms-pending-cancel' ) ) ) { $order ->set_status( 'cancelled' ); $order ->add_note( __( 'Order cancelled during personal data erasure.' , 'lifterlms' ) ); } $props = array_keys ( self::get_order_data_props( 'erasure' ) ); foreach ( $props as $prop ) { $val = self::get_anon_prop_value( $prop ); $order ->set( $prop , $val ); } $order ->set( 'anonymized' , 'yes' ); $order ->add_note( __( 'Personal data removed during personal data erasure.' , 'lifterlms' ) ); } /** * Erase student data * * @param LLMS_Student $student * @return array * @since 3.18.0 * @version 3.18.0 */ private static function erase_student_data( $student ) { $messages = array (); $props = parent::get_student_data_props(); foreach ( $props as $prop => $name ) { $erased = false; $val = $student ->get( $prop ); if ( $val ) { $student ->set( $prop , '' ); $erased = true; } if ( apply_filters( 'llms_privacy_erase_student_data_prop' , $erased , $prop , $student ) ) { /* Translators: %s Prop name. */ $messages [] = sprintf( __( 'Removed student "%s"' , 'lifterlms' ), $name ); } } return apply_filters( 'llms_privacy_erase_student_data' , $messages , $student ); } /** * Erase student notification data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return [type] * @since 3.18.0 * @version 3.18.0 */ public static function notification_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $messages = self::erase_notification_data( $student ); return self::get_return( $messages , true, ( $messages ) ); } /** * Erase student order data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return array * @since 3.18.0 * @version 3.18.0 */ public static function order_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $enabled = llms_parse_bool( get_option( 'llms_erasure_request_removes_order_data' , 'no' ) ); $orders = self::get_student_orders( $student , $page ); foreach ( $orders [ 'orders' ] as $order ) { if ( apply_filters( 'llms_privacy_erase_order_data' , $enabled , $order ) ) { self::erase_order_data( $order ); /* Translators: %d Order number. */ $ret [ 'messages' ][] = sprintf( __( 'Removed personal data from order #%d.' , 'lifterlms' ), $order ->get( 'id' ) ); $ret [ 'items_removed' ] = true; } else { /* Translators: %d Order number. */ $ret [ 'messages' ][] = sprintf( __( 'Personal data within order #%d has been retained.' , 'lifterlms' ), $order ->get( 'id' ) ); $ret [ 'items_retained' ] = true; } } $ret [ 'done' ] = isset( $orders [ 'done' ] ) ? $orders [ 'done' ] : true; return $ret ; } /** * Erase student postmeta data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return [type] * @since 3.18.0 * @version 3.18.0 */ public static function postmeta_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $messages = array (); $enabled = llms_parse_bool( get_option( 'llms_erasure_request_removes_lms_data' , 'no' ) ); if ( apply_filters( 'llms_privacy_erase_postmeta_data' , $enabled , $attempt ) ) { global $wpdb ; $deleted = $wpdb ->query( $wpdb ->prepare( "DELETE FROM {$wpdb->prefix}lifterlms_user_postmeta WHERE user_id = %d" , $student ->get( 'id' ) ) ); $ret [ 'messages' ][] = __( 'Removed all student course and membership enrollment and activity data.' , 'lifterlms' ); $ret [ 'items_removed' ] = true; } else { $ret [ 'messages' ][] = __( 'Retained all student course and membership enrollment and activity data.' , 'lifterlms' ); $ret [ 'items_retained' ] = true; } return $ret ; } /** * Erase student quiz attempt data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return array * @since 3.18.0 * @version 3.18.0 */ public static function quiz_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $enabled = llms_parse_bool( get_option( 'llms_erasure_request_removes_lms_data' , 'no' ) ); $query = self::get_student_quizzes( $student , $page ); foreach ( $query ->get_attempts() as $attempt ) { if ( apply_filters( 'llms_privacy_erase_quiz_data' , $enabled , $attempt ) ) { /* Translators: %d quiz attempt id. */ $ret [ 'messages' ][] = sprintf( __( 'Quiz attempt #%d removed.' , 'lifterlms' ), $attempt ->get_id() ); $ret [ 'items_removed' ] = true; $attempt -> delete (); } else { /* Translators: %d quiz attempt id. */ $ret [ 'messages' ][] = sprintf( __( 'Quiz attempt #%d retained.' , 'lifterlms' ), $attempt ->get_id() ); $ret [ 'items_retained' ] = true; } } $ret [ 'done' ] = $query ->has_results() ? $query ->is_last_page() : true; return $ret ; } /** * Erase student data by email address * * @param string $email_address email address of the user to retrieve data for * @param int $page process page number * @return [type] * @since 3.18.0 * @version 3.18.0 */ public static function student_data( $email_address , $page ) { $ret = self::get_return(); $student = parent::get_student_by_email( $email_address ); if ( ! $student ) { return $ret ; } $messages = self::erase_student_data( $student ); return self::get_return( $messages , true, ( $messages ) ); } } |
Expand full source code Collapse full source code View on GitHub
Methods Methods
- achievement_data — Erase student certificate data by email address
- anonymize_prop — Setup anonymous values for anonymized data
- certificate_data — Erase student certificate data by email address
- erase_notification_data — Erase notifications for a student
- erase_order_data — Erase and anonymize an order
- erase_student_data — Erase student data
- get_return — Return export data to an exporter
- notification_data — Erase student notification data by email address
- order_data — Erase student order data by email address
- postmeta_data — Erase student postmeta data by email address
- quiz_data — Erase student quiz attempt data by email address
- student_data — Erase student data by email address
Changelog Changelog
Version | Description |
---|---|
3.30.3 | Fixed spelling errors. |
3.18.0 | Introduced. |