Controllers
11 months ago
Fly-Out
11 months ago
Helpers
11 months ago
Methods
11 months ago
SettingsPages
11 months ago
Views
11 months ago
class-help-contact-us.php
11 months ago
class-plugin-updated-notice.php
11 months ago
class-premium-features.php
11 months ago
class-settings-page.php
11 months ago
class-setup-wizard.php
11 months ago
class-user-listing.php
11 months ago
class-user-notices.php
11 months ago
class-user-profile.php
11 months ago
class-user-registered.php
11 months ago
index.php
11 months ago
class-user-registered.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsible for WP2FA user's grace periods. |
| 4 | * |
| 5 | * @package wp2fa |
| 6 | * @subpackage user-utils |
| 7 | * @copyright 2025 Melapress |
| 8 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 9 | * @link https://wordpress.org/plugins/wp-2fa/ |
| 10 | * @since 3.0.0 |
| 11 | */ |
| 12 | |
| 13 | namespace WP2FA\Admin; |
| 14 | |
| 15 | use WP2FA\Admin\Helpers\User_Helper; |
| 16 | |
| 17 | if ( ! class_exists( '\WP2FA\Admin\User_Registered' ) ) { |
| 18 | /** |
| 19 | * User_Profile - Class for handling user things such as profile settings and admin list views. |
| 20 | */ |
| 21 | class User_Registered { |
| 22 | |
| 23 | /** |
| 24 | * Apply 2FA Grace period |
| 25 | * |
| 26 | * @param int $user_id User id. |
| 27 | * |
| 28 | * @return void |
| 29 | * |
| 30 | * @since 3.0.0 |
| 31 | */ |
| 32 | public static function apply_2fa_grace_period( $user_id ) { |
| 33 | $user_id = intval( $user_id ); |
| 34 | if ( User_Helper::is_user_method_in_role_enabled_methods( $user_id ) ) { |
| 35 | return; |
| 36 | } else { |
| 37 | User_Helper::remove_enabled_method_for_user( $user_id ); |
| 38 | User_Helper::remove_global_settings_hash_for_user( $user_id ); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Checks the user on role change. |
| 44 | * |
| 45 | * @param integer $user_id - The ID of the user. |
| 46 | * @param string $role - The user role. |
| 47 | * @param array $old_roles - Old roles for the user. |
| 48 | * |
| 49 | * @return void |
| 50 | * |
| 51 | * @since 3.0.0 |
| 52 | */ |
| 53 | public static function check_user_upon_role_change( $user_id, $role, $old_roles ) { |
| 54 | $user_id = intval( $user_id ); |
| 55 | $role = sanitize_text_field( $role ); |
| 56 | |
| 57 | self::apply_2fa_grace_period( $user_id ); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |