Action uncanny-learndash-toolkit

wp_2fa_login_before_submit_button

Fires before the 2FA login submit button is displayed, allowing modification of user and provider data.

add_action( 'wp_2fa_login_before_submit_button', $callback, 10, 2 );

Description

Fires immediately before the two-factor login submit button is rendered. Developers can use this action to add custom content, fields, or modify the submit button's attributes before the user can proceed with their login. The `$user` and `$provider` objects are passed for context.


Usage

add_action( 'wp_2fa_login_before_submit_button', 'your_function_name', 10, 2 );

Parameters

$user (mixed)
The user object is passed to the hook.
$provider (mixed)
The `$user` parameter contains information about the user attempting to log in.

Examples

/**
 * Example callback for the 'wp_2fa_login_before_submit_button' action hook.
 * This example adds a custom message before the login button, but only
 * if the user is trying to log in with a specific two-factor provider (e.g., Google Authenticator).
 *
 * @param WP_User|null $user     The user object if logged in, or null.
 * @param string       $provider The identifier of the two-factor provider being used.
 */
add_action(
	'wp_2fa_login_before_submit_button',
	function ( $user, $provider ) {
		// Check if a specific provider is being used, for example, Google Authenticator.
		// Replace 'google_authenticator' with the actual provider slug if needed.
		if ( 'google_authenticator' === $provider ) {
			// Display a custom message to the user before they submit the form.
			// This could be a reminder about using their authenticator app.
			echo '<p style="color: #888; font-size: 0.9em; margin-bottom: 1em;">' . esc_html__( 'Please ensure you have your authenticator app ready.', 'your-text-domain' ) . '</p>';
		}
	},
	10, // Priority: default
	2  // Accepted args: $user, $provider
);

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:701
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-4.php:640
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-3.php:609
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-5.php:639

do_action( 'wp_2fa_login_form', $user, $provider );
			}
			?>

			<?php $submit_button_disabled = apply_filters( 'wp_2fa_login_disable_submit_button', false, $user, $provider ); ?>

			<?php if ( ! $submit_button_disabled ) : ?>
				<?php do_action( 'wp_2fa_login_before_submit_button', $user, $provider ); ?>
				<p>
					<?php
					if ( function_exists( 'submit_button' ) ) {
						$button_text = apply_filters( 'wp_2fa_login_button_text', esc_html__( 'Log In', 'wp-2fa' ) );
						submit_button( $button_text );
						?>
						<script type="text/javascript">


Scroll to Top