v1.6.7
This commit is contained in:
parent
f9c073a582
commit
c3f0eac50c
2 changed files with 84 additions and 14 deletions
|
|
@ -41,6 +41,7 @@ class Grace_Period {
|
|||
public function register_hooks(): void {
|
||||
add_action( 'admin_init', array( $this, 'maybe_redirect_to_setup_wizard' ) );
|
||||
add_action( 'robotstxt_2fa_method_enabled', array( $this, 'clear_pending_setup' ), 10, 2 );
|
||||
add_action( 'admin_notices', array( $this, 'maybe_show_setup_required_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -167,10 +168,45 @@ class Grace_Period {
|
|||
return;
|
||||
}
|
||||
|
||||
wp_safe_redirect( admin_url( 'profile.php#robotstxt-2fa-settings' ) );
|
||||
// The query flag lets the profile show WHY the user was redirected,
|
||||
// so the mandatory setup does not feel like a silent loop.
|
||||
$profile_url = add_query_arg( 'robotstxt-2fa-setup-required', '1', admin_url( 'profile.php' ) );
|
||||
|
||||
wp_safe_redirect( $profile_url . '#robotstxt-2fa-settings' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explain the setup wizard redirect on the profile screen.
|
||||
*
|
||||
* Rendered after {@see self::maybe_redirect_to_setup_wizard()} bounced the
|
||||
* user back to their profile. Without it, users land on a regular profile
|
||||
* page with no hint that 2FA enrollment is mandatory before they can
|
||||
* continue to the dashboard — which reads as a broken redirect loop.
|
||||
*
|
||||
* @since 1.6.7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_show_setup_required_notice(): void {
|
||||
if ( ! $this->is_pending_setup() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only flag; no state change.
|
||||
if ( ! isset( $_GET['robotstxt-2fa-setup-required'] ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="notice notice-warning robotstxt-2fa-setup-required">
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'Two-factor authentication is required.', 'robotstxt-2fa' ); ?></strong>
|
||||
<?php esc_html_e( 'You must activate at least one verification method in the Two-Factor Authentication section of this page, then save, before you can continue to the dashboard.', 'robotstxt-2fa' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the grace period start timestamp, creating it on first call.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -858,6 +858,20 @@ class Profile_Settings {
|
|||
$nonce = sanitize_text_field( wp_unslash( $_POST[ self::NONCE_FIELD ] ) );
|
||||
|
||||
if ( ! wp_verify_nonce( $nonce, self::NONCE_ACTION ) ) {
|
||||
/*
|
||||
* A stale form (nonce expired) previously returned silently, which
|
||||
* left wizard-trapped users clicking Save with no visible result
|
||||
* while the setup-required redirect kept bouncing them back to the
|
||||
* profile. Fail loudly so the user knows to try again.
|
||||
*/
|
||||
$this->focus_section = true;
|
||||
add_settings_error(
|
||||
'robotstxt-2fa',
|
||||
'robotstxt-2fa-nonce-expired',
|
||||
__( 'Your form session expired and nothing was saved. Please try saving again.', 'robotstxt-2fa' ),
|
||||
'error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue