wp_2fa_login_html_before_end
Fires after the two-factor authentication HTML is rendered on the login form, allowing modifications before its final output.
add_action( 'wp_2fa_login_html_before_end', $callback, 10, 2 );
Description
Fired on the WordPress login form just before the closing `
` tag, this action hook allows developers to inject custom HTML or logic. It provides the current user object and the active two-factor authentication provider, enabling dynamic content based on the login context.
Usage
add_action( 'wp_2fa_login_html_before_end', 'your_function_name', 10, 2 );
Parameters
-
$user(mixed) - This parameter contains information about the user currently attempting to log in.
-
$provider(mixed) - This parameter contains the WordPress user object for the currently logged-in user.
Examples
/**
* Add a custom message or link before the end of the 2FA login form.
*
* This example adds a link to the plugin's settings page if the current user
* is an administrator, providing a quick way to manage 2FA settings directly
* from the login screen.
*
* @param WP_User $user The current user object attempting to log in.
* @param string $provider The 2FA provider currently in use.
*/
add_action( 'wp_2fa_login_html_before_end', function( $user, $provider ) {
// Check if the current user has administrator privileges.
if ( $user instanceof WP_User && user_can( $user, 'manage_options' ) ) {
$settings_url = admin_url( 'admin.php?page=wp-2fa-settings' );
?>
<p class="wp-2fa-custom-message">
Need to manage your Two-Factor Authentication settings?
<a href="<?php echo esc_url( $settings_url ); ?>">Go to settings</a>.
</p>
<?php
}
}, 10, 2 ); // Priority 10, accepts 2 arguments.
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:733
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-4.php:672
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-3.php:641
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-5.php:671
name="<?php echo esc_attr( $this->two_factor::INPUT_NAME_RESEND_CODE ); ?>"
value="<?php esc_attr_e( 'Resend Code', 'wp-2fa' ); ?>"/>
</p>
<?php
endif;
endif; // submit button not disabled
do_action( 'wp_2fa_login_html_before_end', $user, $provider );
?>
</form>
<div class="uo-toolkit-2fa-footer">
<?php