PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.1.0
WP 2FA – Two-factor authentication for WordPress v2.1.0
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 / Admin / UserRegistered.php
wp-2fa / includes / classes / Admin Last commit date
Controllers 4 years ago SettingsPages 4 years ago Views 4 years ago HelpContactUs.php 4 years ago PremiumFeatures.php 4 years ago SettingsPage.php 4 years ago SetupWizard.php 4 years ago User.php 4 years ago UserListing.php 4 years ago UserNotices.php 4 years ago UserProfile.php 4 years ago UserRegistered.php 4 years ago index.php 5 years ago
UserRegistered.php
56 lines
1 <?php // phpcs:ignore
2
3 namespace WP2FA\Admin;
4
5 use \WP2FA\WP2FA as WP2FA;
6 use \WP2FA\Authenticator\Authentication as Authentication;
7 use \WP2FA\Admin\SettingsPage as SettingsPage;
8
9 /**
10 * UserProfile - Class for handling user things such as profile settings and admin list views.
11 */
12 class UserRegistered {
13
14 /**
15 * Classs constructor
16 */
17 public function __construct() {
18
19 }
20
21 /**
22 * Apply 2FA Grace period
23 *
24 * @param int $user_id User id.
25 */
26 public function apply_2fa_grace_period( $user_id ) {
27 // Get user object.
28 $user = get_user_by( 'id', $user_id );
29 // Check if this user is actually eligible.
30 $is_needed = User::is_enforced( $user->ID );
31 $is_user_excluded = User::is_excluded( $user->ID );
32 // If they are, add grace_period.
33 if ( $is_needed && ! $is_user_excluded ) {
34 $grace_policy = WP2FA::get_wp2fa_setting( 'grace-policy' );
35 // Grab grace period.
36 $create_a_string = WP2FA::get_wp2fa_setting( 'grace-period' ) . ' ' . WP2FA::get_wp2fa_setting( 'grace-period-denominator' );
37
38 // Check if want to apply the custom period, or instant expiry.
39 if ( 'use-grace-period' === $grace_policy ) {
40 $grace_expiry = strtotime( $create_a_string );
41 } else {
42 $grace_expiry = time();
43 }
44
45 update_user_meta( $user->ID, WP_2FA_PREFIX . 'grace_period_expiry', $grace_expiry );
46 if ( 'no-grace-period' === $grace_policy ) {
47 update_user_meta( $user->ID, WP_2FA_PREFIX . 'user_enforced_instantly', true );
48 }
49 }
50 }
51
52 public function check_user_upon_role_change( $user_id, $role, $old_roles ) {
53 $this->apply_2fa_grace_period( $user_id );
54 }
55 }
56