-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground-anonymize-user.php
63 lines (48 loc) · 1.19 KB
/
background-anonymize-user.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
<?php
/**
* Background Anonymize User Class
*
* @package SafetyNet
*/
namespace SafetyNet;
use function SafetyNet\Anonymize\anonymize_users;
use function SafetyNet\Anonymize\store_anonymized_user_data;
/**
* Background Anonymize User class
*/
class Background_Anonymize_User extends \WP_Background_Process {
/**
* @var string
*/
protected $action = 'anonymize_user';
/**
* Anonymizes users in the queue.
*
* @param array $item User to anonymize
*
* @return bool|array
*/
protected function task( $item ) {
$result = anonymize_users( $item['offset'] );
// If there are no more results, return false.
if ( ! $result ) {
return false;
}
// Increase the offset.
$item['offset'] += 500;
return $item;
}
/**
* When all users have been anonymized, and the queue is complete, move all the users and their meta from the temp
* table to the real ones. Also remove the temp tables when that's done.
*/
protected function complete() {
global $wpdb;
// Have to call complete function in the parent's class.
parent::complete();
// Store the anonymized users to the default tables.
store_anonymized_user_data();
// Flush the cache.
wp_cache_flush();
}
}