PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 1.2.0
WP 2FA – Two-factor authentication for WordPress v1.2.0
4.0.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 / UserNotices.php
wp-2fa / includes / classes / Admin Last commit date
SettingsPage.php 6 years ago SetupWizard.php 6 years ago UserNotices.php 6 years ago UserProfile.php 6 years ago UserRegistered.php 6 years ago
UserNotices.php
121 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
8 /**
9 * UserNotices - Class for displaying notices to our users.
10 */
11 class UserNotices {
12
13 /**
14 * Lets set things up
15 */
16 public function __construct() {
17 if ( ! empty( WP2FA::get_wp2fa_setting( 'enforcment-policy' ) ) ) {
18 // Check we are supposed to, before adding action to show nag.
19 if ( 'all-users' === WP2FA::get_wp2fa_setting( 'enforcment-policy' ) || 'certain-roles-only' === WP2FA::get_wp2fa_setting( 'enforcment-policy' ) || 'certain-users-only' === WP2FA::get_wp2fa_setting( 'enforcment-policy' ) ) {
20 add_action( 'admin_notices', array( $this, 'user_setup_2fa_nag' ) );
21 } elseif ( 'do-not-enforce' === WP2FA::get_wp2fa_setting( 'enforcment-policy' ) ) {
22 add_action( 'admin_notices', array( $this, 'user_reconfigure_2fa_nag' ) );
23 }
24 }
25 }
26
27 /**
28 * The nag content
29 */
30 public function user_setup_2fa_nag() {
31 if ( isset( $_GET['user_id'] ) ) {
32 $current_profile_user_id = (int) $_GET['user_id'];
33 } else {
34 $current_profile_user_id = false;
35 }
36
37 if ( $current_profile_user_id ) {
38 return;
39 }
40
41 $user = wp_get_current_user();
42 $class = 'notice notice-info wp-2fa-nag';
43 $grace_expiry = get_user_meta( $user->ID, 'wp_2fa_grace_period_expiry', true );
44 $reconfigure_2fa = get_user_meta( $user->ID, 'wp_2fa_user_needs_to_reconfigure_2fa', true );
45 if ( $reconfigure_2fa ) {
46 $message = esc_html__( 'The 2FA method you were using is no longer allowed on this website. Please reconfigure 2FA using one of the supported methods within', 'wp-2fa' );
47 } else {
48 $message = esc_html__( 'This website’s administrator requires you to enable 2FA authentication within', 'wp-2fa' );
49 }
50
51 $is_nag_dismissed = get_user_meta( $user->ID, 'wp_2fa_update_nag_dismissed', true );
52 $is_nag_needed = Authentication::is_user_eligible_for_2fa( $user->ID );
53 $is_user_excluded = WP2FA::is_user_excluded( $user->ID );
54 $enabled_methods = get_user_meta( $user->ID, 'wp_2fa_enabled_methods', true );
55
56 // If the nag has not already been dismissed, and of course if the user is eligible, lets show them something.
57 if ( ! $is_nag_dismissed && $is_nag_needed && empty( $enabled_methods ) && ! $is_user_excluded && ! empty( $grace_expiry ) ) {
58 printf(
59 '<div class="%1$s"><p>%2$s <span class="grace-period-countdown" data-countdown-timestamp="%3$s"></span> <a href="%4$s" class="button button-primary">%5$s</a> <a href="#" class="button button-secondary dismiss-user-configure-nag">%6$s</a></p></div>',
60 esc_attr( $class ),
61 esc_html( $message ),
62 esc_attr( $grace_expiry ),
63 esc_url( admin_url( 'options-general.php?page=wp-2fa-setup&current-step=choose_2fa_method&first_time_setup=true' ) ),
64 esc_html__( 'Configure 2FA now', 'wp-2fa' ),
65 esc_html__( 'Remind me on next login', 'wp-2fa' )
66 );
67 }
68 }
69
70 /**
71 * The nag content
72 */
73 public function user_reconfigure_2fa_nag() {
74 $class = 'notice notice-info wp-2fa-nag';
75 $grace_period = WP2FA::get_wp2fa_setting( 'grace-period-expiry-time' );
76 $user = wp_get_current_user();
77 $reconfigure_2fa = get_user_meta( $user->ID, 'wp_2fa_user_needs_to_reconfigure_2fa', true );
78
79 $message = esc_html__( 'The 2FA method you were using is no longer allowed on this website. Please reconfigure 2FA using one of the supported methods.', 'wp-2fa' );
80
81 $enabled_methods = get_user_meta( $user->ID, 'wp_2fa_enabled_methods', true );
82 // If the nag has not already been dismissed, and of course if the user is eligible, lets show them something.
83 if ( ! empty( $reconfigure_2fa ) && empty( $enabled_methods ) ) {
84 printf(
85 '<div class="%1$s"><p>%2$s <a href="%4$s" class="button button-primary">%5$s</a> <a href="#" class="button button-secondary dismiss-user-reconfigure-nag">%6$s</a></p></div>',
86 esc_attr( $class ),
87 esc_html( $message ),
88 esc_attr( $grace_period ),
89 esc_url( admin_url( 'options-general.php?page=wp-2fa-setup&current-step=choose_2fa_method&first_time_setup=true' ) ),
90 esc_html__( 'Configure 2FA now', 'wp-2fa' ),
91 esc_html__( 'I\'ll do it later', 'wp-2fa' )
92 );
93 }
94 }
95
96 /**
97 * Dismiss notice and setup a user meta value so we know its been dismissed
98 */
99 public function dismiss_nag() {
100 $user = wp_get_current_user();
101 $updated = update_user_meta( $user->ID, 'wp_2fa_update_nag_dismissed', true );
102 }
103
104 /**
105 * Dismiss reconfigure nag
106 */
107 public function dismiss_reconfigure_nag() {
108 $user = wp_get_current_user();
109 $updated = delete_user_meta( $user->ID, 'wp_2fa_user_needs_to_reconfigure_2fa' );
110 }
111
112 /**
113 * Reset the nag when the user logs out, so they get it again next time.
114 */
115 public function reset_nag() {
116 $user = wp_get_current_user();
117 $deleted = delete_user_meta( $user->ID, 'wp_2fa_update_nag_dismissed' );
118 }
119
120 }
121