Action uncanny-learndash-toolkit

wp_2fa_login_html_after_backup_providers

Fires after the backup provider options are displayed on the 2FA login form.

add_action( 'wp_2fa_login_html_after_backup_providers', $callback, 10, 5 );

Description

Fires after backup method providers are displayed on the Two-Factor Authentication login screen. This action hook allows developers to inject custom content or modify the display after backup options are rendered, offering flexibility in customizing the user login experience.


Usage

add_action( 'wp_2fa_login_html_after_backup_providers', 'your_function_name', 10, 5 );

Parameters

$user (mixed)
This parameter holds the current user object.
$provider (mixed)
This parameter contains information about the user attempting to log in.
$login_nonce (mixed)
This parameter contains information about the currently active two-factor authentication provider.
$redirect_to (mixed)
This parameter contains a nonce value generated to ensure the security of the login process.
$rememberme (mixed)
This parameter contains the URL the user will be redirected to after a successful login.

Examples

<?php
/**
 * Example function to hook into wp_2fa_login_html_after_backup_providers.
 * This example adds a custom message after the backup provider section on the 2FA login screen.
 *
 * @param WP_User $user The current user object.
 * @param object  $provider The 2FA provider object being used.
 * @param string  $login_nonce The nonce for the login form.
 * @param string  $redirect_to The URL to redirect to after login.
 * @param bool    $rememberme Whether to remember the user.
 */
add_action( 'wp_2fa_login_html_after_backup_providers', 'my_custom_2fa_after_backup_providers', 10, 5 );

function my_custom_2fa_after_backup_providers( $user, $provider, $login_nonce, $redirect_to, $rememberme ) {
	// Ensure we have a valid user object and provider.
	if ( ! $user instanceof WP_User || ! is_object( $provider ) ) {
		return;
	}

	// Display a custom message if a specific provider is not being used.
	if ( $provider->id !== 'google-authenticator' ) {
		?>
		<div class="my-custom-2fa-message">
			<p>
				<?php
				printf(
					esc_html__( 'For enhanced security, consider setting up %s authentication.', 'your-text-domain' ),
					'<a href="' . esc_url( admin_url( 'profile.php' ) ) . '#section-google-authenticator">' . esc_html__( 'Google Authenticator', 'your-text-domain' ) . '</a>'
				);
				?>
			</p>
		</div>
		<?php
	}

	// You can also access and potentially use other parameters like $login_nonce, $redirect_to, and $rememberme if needed.
	// For example, to log the redirect URL for debugging:
	// error_log( '2FA login redirecting to: ' . $redirect_to );
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2.6.php:773
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-4.php:712
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-3.php:681
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-5.php:711

<?php esc_html_e( 'Or, go back to login form.', 'uncanny-learndash-toolkit' ); ?>
					</a>
				</div>
			<?php endif; ?>

		<?php endif; ?>

			<?php do_action( 'wp_2fa_login_html_after_backup_providers', $user, $provider, $login_nonce, $redirect_to, $rememberme ); ?>

			<div class="uo-toolkit-2fa-footer__backto-home">
				<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr_e( 'Are you lost?', 'uncanny-learndash-toolkit' ); ?>">
					<?php
					echo esc_html(
						sprintf(
						// translators: %s: site name.

Scroll to Top