v1.6.6
This commit is contained in:
parent
c72a96e2a0
commit
f9c073a582
1 changed files with 93 additions and 17 deletions
|
|
@ -97,6 +97,13 @@ class Profile_Settings {
|
|||
*/
|
||||
private Trusted_Devices $trusted_devices;
|
||||
|
||||
/**
|
||||
* Grace period manager.
|
||||
*
|
||||
* @var Grace_Period
|
||||
*/
|
||||
private Grace_Period $grace_period;
|
||||
|
||||
/**
|
||||
* Whether the post-save redirect should focus the 2FA section.
|
||||
*
|
||||
|
|
@ -113,6 +120,7 @@ class Profile_Settings {
|
|||
$this->otp_manager = new OTP_Manager();
|
||||
$this->recovery_codes = new Recovery_Codes();
|
||||
$this->trusted_devices = new Trusted_Devices();
|
||||
$this->grace_period = new Grace_Period();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -170,6 +178,57 @@ class Profile_Settings {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the forced-enrollment warning on the profile 2FA section.
|
||||
*
|
||||
* Shown when the user's role enforces 2FA but no verification method is
|
||||
* configured yet, so the requirement is visible before the login flow
|
||||
* (grace notice, setup wizard, or login block) kicks in. When a grace
|
||||
* period is active, the number of remaining days is appended.
|
||||
*
|
||||
* @since 1.6.6
|
||||
*
|
||||
* @param \WP_User $user User whose profile section is being rendered.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_forced_enrollment_warning( \WP_User $user ): void {
|
||||
$user_settings = $this->user_settings_repository->get_user_settings( $user->ID );
|
||||
|
||||
if ( empty( $this->config->get_required_methods_for_user( $user ) ) || ! empty( $user_settings['methods'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grace_note = '';
|
||||
$grace_days = $this->config->get_grace_period_days();
|
||||
|
||||
if ( $grace_days > 0 && $this->grace_period->is_active( $user, $grace_days ) ) {
|
||||
$remaining = $this->grace_period->get_days_remaining( $user, $grace_days );
|
||||
|
||||
/* translators: %d: number of days remaining to complete the setup. */
|
||||
$grace_note = sprintf(
|
||||
_n(
|
||||
'You have %d day left to complete the setup.',
|
||||
'You have %d days left to complete the setup.',
|
||||
$remaining,
|
||||
'robotstxt-2fa'
|
||||
),
|
||||
$remaining
|
||||
);
|
||||
}
|
||||
?>
|
||||
<div class="notice notice-warning inline robotstxt-2fa-forced-warning">
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'Two-factor authentication is required for your account.', 'robotstxt-2fa' ); ?></strong>
|
||||
<?php esc_html_e( 'You have not set up any verification method yet. Activate at least one method below to keep access to your account.', 'robotstxt-2fa' ); ?>
|
||||
<?php if ( '' !== $grace_note ) : ?>
|
||||
<em><?php echo esc_html( $grace_note ); ?></em>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render profile settings UI.
|
||||
*
|
||||
|
|
@ -313,6 +372,7 @@ class Profile_Settings {
|
|||
}
|
||||
?>
|
||||
<h2 id="<?php echo esc_attr( self::SECTION_ANCHOR ); ?>"><?php esc_html_e( 'Two-Factor Authentication', 'robotstxt-2fa' ); ?></h2>
|
||||
<?php $this->render_forced_enrollment_warning( $user ); ?>
|
||||
<?php wp_nonce_field( self::NONCE_ACTION, self::NONCE_FIELD ); ?>
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
|
|
|
|||
Loading…
Reference in a new issue