Filter uncanny-learndash-toolkit

wp_2fa_login_disable_submit_button

Filters whether to disable the submit button during two-factor authentication login.

add_filter( 'wp_2fa_login_disable_submit_button', $callback, 10, 2 );

Description

Filters whether to disable the submit button on the two-factor login page. Allows developers to programmatically control the submit button's state based on user or provider, typically for custom two-factor scenarios.


Usage

add_filter( 'wp_2fa_login_disable_submit_button', 'your_function_name', 10, 2 );

Parameters

$user (mixed)
This parameter is a boolean value, typically `false` by default, which can be used to programmatically disable the submit button on the login form.
$provider (mixed)
This parameter contains the user object for the currently logged-in user.

Return Value

The filtered value.


Examples

/**
 * Disable the submit button on the 2FA login form if the user is a specific role.
 *
 * This filter allows administrators to prevent certain user roles from completing
 * the 2FA login process, perhaps for administrative reasons or for testing.
 *
 * @param bool   $disable_submit_button Whether to disable the submit button.
 * @param WP_User|null $user              The WP_User object if the user is logged in, otherwise null.
 * @param string $provider              The 2FA provider being used.
 * @return bool True to disable the submit button, false otherwise.
 */
add_filter( 'wp_2fa_login_disable_submit_button', function( $disable_submit_button, $user, $provider ) {

	// Only apply this logic if we are dealing with the standard 'wp-2fa' provider.
	if ( 'wp-2fa' !== $provider ) {
		return $disable_submit_button;
	}

	// If the user is not logged in or has no user object, don't disable the button based on role.
	if ( ! $user instanceof WP_User ) {
		return $disable_submit_button;
	}

	// Get the user's roles.
	$user_roles = $user->roles;

	// Check if the user has the 'editor' role. If so, disable the submit button.
	if ( in_array( 'editor', $user_roles, true ) ) {
		return true; // Disable the submit button for editors.
	}

	// For any other roles or conditions, return the original value of the filter.
	return $disable_submit_button;

}, 10, 3 );

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:698
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-4.php:637
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-3.php:606
src/includes/two-factor/providers/wp-2fa/legacy/class-frontend-login-plus-2fa-2-5.php:636

} elseif ( 'backup_codes' === $provider ) {
				$this->two_factor::backup_codes_authentication_page( $user );
			} else {
				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' ) );


Scroll to Top