-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanonymize.php
101 lines (80 loc) · 2.36 KB
/
anonymize.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
<?php
use function SafetyNet\Anonymize\anonymize_orders;
use function SafetyNet\Anonymize\copy_and_clear_user_tables;
use function SafetyNet\Anonymize\store_anonymized_user_data;
use function SafetyNet\Anonymize\anonymize_users;
use function SafetyNet\Anonymize\anonymize_customers;
use function SafetyNet\Delete\delete_users_and_orders;
/**
* Anonymizer command line utilities.
*/
class SafetyNet_CLI extends WP_CLI_Command {
/**
* Anonymize a user and their data
*
* ## EXAMPLES
*
* wp safety-net anonymize
*
*/
public function anonymize( $args ) {
$info = WP_CLI::colorize( '%pThis process will anonymize your current users, orders and customers with dummy data.%n ' );
WP_CLI::log( $info );
WP_CLI::warning( 'Please proceed with caution if you have a site with a large number of users/orders/customers' );
WP_CLI::confirm( 'Are you sure you want to do this?' );
WP_CLI::log( '- Copying users to temporary tables ...' );
copy_and_clear_user_tables();
WP_CLI::log( '- Anonymizing users ... ' );
anonymize_users();
WP_CLI::log( '- Storing the anonymized users to the default tables ... ' );
store_anonymized_user_data();
WP_CLI::log( '- Anonymizing orders ... ' );
anonymize_orders();
WP_CLI::log( '- Anonymizing customers ... ' );
anonymize_customers();
update_option( 'anonymized_status', true, false );
WP_CLI::success( __( 'Users and their data have been anonymized' ) );
}
/**
* Delete all non-admin users and their data
*
* ## EXAMPLES
*
* wp safety-net delete
*
*/
public function delete() {
delete_users_and_orders();
WP_CLI::success( __( 'Users and their data have been deleted' ) );
}
/**
* Clear options such as API keys so that plugins won't talk to 3rd parties
*
* ## EXAMPLES
*
* wp safety-net scrub-options
*
* @subcommand scrub-options
*
*/
public function scrub_options() {
\SafetyNet\DeactivatePlugins\scrub_options();
WP_CLI::success( __( 'All options have been scrubbed.' ) );
}
/**
* Deactivate problematic plugins from a denylist
*
* ## EXAMPLES
*
* wp safety-net deactivate-plugins
*
* @subcommand deactivate-plugins
*
*/
public function deactivate_plugins() {
\SafetyNet\DeactivatePlugins\deactivate_plugins();
WP_CLI::success( __( 'Problematic plugins have been deactivated.' ) );
}
}
$instance = new SafetyNet_CLI();
WP_CLI::add_command( 'safety-net', $instance );