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 / Admin / UserRegistered.php
wp-2fa / includes / classes / Admin Last commit date
SettingsPage.php 5 years ago SetupWizard.php 5 years ago UserNotices.php 5 years ago UserProfile.php 5 years ago UserRegistered.php 5 years ago
UserRegistered.php
58 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 = Authentication::is_user_eligible_for_2fa( $user->ID );
31 $is_user_excluded = WP2FA::is_user_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_grace_period_expiry', $grace_expiry );
46 if ( 'no-grace-period' === $grace_policy ) {
47 update_user_meta( $user->ID, 'wp_2fa_user_enforced_instantly', true );
48 }
49
50 SettingsPage::send_2fa_enforced_email( $user->ID );
51 }
52 }
53
54 public function check_user_upon_role_change( $user_id, $role, $old_roles ) {
55 $this->apply_2fa_grace_period( $user_id );
56 }
57 }
58