Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for plugins to add support link to login form. #615

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 47 additions & 25 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,37 +804,59 @@ public static function login_html( $user, $login_nonce, $redirect_to, $error_msg
<?php $provider->authentication_page( $user ); ?>
</form>

<?php if ( $backup_providers ) :
$backup_link_args = array(
'action' => $action,
'wp-auth-id' => $user->ID,
'wp-auth-nonce' => $login_nonce,
);
if ( $rememberme ) {
$backup_link_args['rememberme'] = $rememberme;
}
if ( $redirect_to ) {
$backup_link_args['redirect_to'] = $redirect_to;
}
if ( $interim_login ) {
$backup_link_args['interim-login'] = 1;
<?php
$links = [];

if ( $backup_providers ) {
$backup_link_args = array(
'action' => $action,
'wp-auth-id' => $user->ID,
'wp-auth-nonce' => $login_nonce,
);
if ( $rememberme ) {
$backup_link_args['rememberme'] = $rememberme;
}
if ( $redirect_to ) {
$backup_link_args['redirect_to'] = $redirect_to;
}
if ( $interim_login ) {
$backup_link_args['interim-login'] = 1;
}

foreach ( $backup_providers as $backup_provider_key => $backup_provider ) {
$backup_link_args['provider'] = $backup_provider_key;
$links[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( self::login_url( $backup_link_args ) ),
esc_html( $backup_provider->get_alternative_provider_label() )
);
}
}
?>

/**
* Filters the html links displayed on the two-factor login form.
*
* Plugins can use this filter to modify or add links to the two-factor authentication
* login form, allowing users to select backup methods for authentication or provide documentation links.
*
* @since 0.9.2
*
* @param array<string> $links An array of links displayed on the two-factor login form.
*/
$links = apply_filters( 'two_factor_login_backup_links', $links );
?>

<?php if ( ! empty( $links ) ) : ?>
<div class="backup-methods-wrap">
<p>
<?php esc_html_e( 'Having Problems?', 'two-factor' ); ?>
</p>
<ul>
<?php
foreach ( $backup_providers as $backup_provider_key => $backup_provider ) :
$backup_link_args['provider'] = $backup_provider_key;
?>
<li>
<a href="<?php echo esc_url( self::login_url( $backup_link_args ) ); ?>">
<?php echo esc_html( $backup_provider->get_alternative_provider_label() ); ?>
</a>
</li>
<?php endforeach; ?>
<?php
foreach ( $links as $link ) {
echo '<li>' . $link . '</li>';
}
?>
</ul>
</div>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Here is a list of action and filter hooks provided by the plugin:
- `two_factor_enabled_providers_for_user` filter overrides the list of two-factor providers enabled for a user. First argument is an array of enabled provider classnames as values, the second argument is the user ID.
- `two_factor_user_authenticated` action which receives the logged in `WP_User` object as the first argument for determining the logged in user right after the authentication workflow.
- `two_factor_token_ttl` filter overrides the time interval in seconds that an email token is considered after generation. Accepts the time in seconds as the first argument and the ID of the `WP_User` object being authenticated.
- `two_factor_login_backup_links` filters the backup links displayed on the two-factor login form.

== Frequently Asked Questions ==

Expand Down
2 changes: 1 addition & 1 deletion two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Two Factor
* Plugin URI: https://wordpress.org/plugins/two-factor/
* Description: Enable Two-Factor Authentication using time-based one-time passwords, Universal 2nd Factor (FIDO U2F, YubiKey), email, and backup verification codes.
* Version: 0.9.1
* Version: 0.9.2
* Requires at least: 6.3
* Requires PHP: 7.2
* Author: Plugin Contributors
Expand Down