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 |