PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 1.5.2
WP 2FA – Two-factor authentication for WordPress v1.5.2
1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / BackgroundProcessing / RemoveAllUserData.php
wp-2fa / includes / classes / BackgroundProcessing Last commit date
DeleteGracePeriod.php 5 years ago Enforce2FA.php 5 years ago RemoveAllUserData.php 5 years ago RemoveEnabledMethods.php 5 years ago
RemoveAllUserData.php
72 lines
1 <?php // phpcs:ignore
2
3 namespace WP2FA\BackgroundProcessing;
4
5 use \WP2FA\Admin\SettingsPage as SettingsPage;
6 use WP2FA\Utils\DateTimeUtils;
7 use \WP2FA\WP2FA as WP2FA;
8 use \WP2FA\Authenticator\Authentication as Authentication;
9
10 /**
11 * Class for handling our crons.
12 */
13 class RemoveAllUserData extends \WP_Background_Process {
14
15 /**
16 * Name of the cron we are going to attach these to.
17 *
18 * @var string
19 */
20 protected $action = '2fa_bg_wipe_all_user_data';
21
22 /**
23 * Task to perform in the BG
24 *
25 * @param object $item Consists of User ID, name of the job we want to do, and optional extras.
26 */
27 protected function task( $item ) {
28
29 if ( empty( $item ) || ! isset( $item ) ) {
30 return false;
31 }
32
33 // Turn a single user into an array.
34 $users = array();
35 if ( isset( $item['user'] ) ) {
36 $users[] = $item['user'];
37 } elseif ( isset( $item['users'] ) ) {
38 $users = $item['users'];
39 }
40
41 // If we still have no data, stop here.
42 if ( empty( $users ) ) {
43 return false;
44 }
45
46 if ( ! is_array( $users ) ) {
47 $users = explode( ',', $users );
48 }
49
50 foreach ( $users as $user ) {
51 $user_id = is_object( $user ) ? $user->ID : $user;
52 // Wipe all data from user.
53 global $wpdb;
54 $wpdb->query(
55 $wpdb->prepare(
56 "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key LIKE %s", [ $user_id, 'wp_2fa_%' ]
57 )
58 );
59 }
60
61 return false;
62 }
63
64 /**
65 * Fire off event so we know the above tasks have completed.
66 */
67 protected function complete() {
68 parent::complete();
69 }
70
71 }
72