DeleteGracePeriod.php
5 years ago
Enforce2FA.php
5 years ago
RemoveAllUserData.php
5 years ago
RemoveEnabledMethods.php
5 years ago
RemoveEnabledMethods.php
68 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 RemoveEnabledMethods 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_remove_enabled_methods'; |
| 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 | // Grab users from array or create an empty. |
| 34 | $users = isset( $item['users'] ) ? $item['users'] : []; |
| 35 | // Check if we have a method specified. |
| 36 | $method_to_remove = isset( $item['method_to_remove'] ) ? $item['method_to_remove'] : false; |
| 37 | |
| 38 | // If we still have no data, stop here. |
| 39 | if ( empty( $users ) || ! $method_to_remove ) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | if ( ! is_array( $users ) ) { |
| 44 | $users = explode( ',', $users ); |
| 45 | } |
| 46 | |
| 47 | // Remove enabled methods, happens when we disable and once enabled 2FA method. |
| 48 | foreach ( $users as $user ) { |
| 49 | $user_id = is_object( $user ) ? $user->ID : $user; |
| 50 | $enabled = get_user_meta( $user_id, 'wp_2fa_enabled_methods', true ); |
| 51 | if ( ! empty( $method_to_remove ) && $method_to_remove === $enabled ) { |
| 52 | delete_user_meta( $user_id, 'wp_2fa_enabled_methods' ); |
| 53 | update_user_meta( $user_id, 'wp_2fa_user_needs_to_reconfigure_2fa', true ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Fire off event so we know the above tasks have completed. |
| 62 | */ |
| 63 | protected function complete() { |
| 64 | parent::complete(); |
| 65 | } |
| 66 | |
| 67 | } |
| 68 |