` element. Default 'Log In'.
* @param string $message Optional. Message to display in header. Default empty.
* @param bool $show_logo Optional. Show/hide header logo. Default true.
* @param WP_Error $wp_error Optional. The error to pass. Default empty.
*/
function login_header_otp( $title = 'Log In', $message = '', $show_logo = true, $wp_error = '' ) {
global $error, $interim_login, $action;
if ( empty( $wp_error ) ) {
$wp_error = new WP_Error();
}
// Shake it!
$shake_error_codes = array(
'empty_password',
'empty_email',
'invalid_email',
'invalidcombo',
'empty_username',
'invalid_username',
'incorrect_password',
);
/**
* Filters the error codes array for shaking the login form.
*
* @param array $shake_error_codes Error codes that shake the login form.
*
* @since 3.0.0
*/
$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
if ( $shake_error_codes && $wp_error->get_error_code() && in_array(
$wp_error->get_error_code(),
$shake_error_codes,
true
) ) {
add_action( 'login_head', 'wp_shake_js', 12 );
}
$separator = is_rtl() ? ' › ' : ' ‹ ';
?>
>
add( 'error', $error );
unset( $error );
}
if ( $wp_error->get_error_code() ) {
$errors = '';
$messages = '';
foreach ( $wp_error->get_error_codes() as $code ) {
$severity = $wp_error->get_error_data( $code );
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
if ( 'message' === $severity ) {
$messages .= ' ' . $error_message . "
\n";
} else {
$errors .= ' ' . $error_message . "
\n";
}
}
}
if ( ! empty( $errors ) ) {
/**
* Filters the error messages displayed above the login form.
*
* @param string $errors Login error message.
*
* @since 2.1.0
*/
echo wp_kses_post( sprintf( '
%s
', apply_filters( 'login_errors', $errors ) ) );
}
if ( ! empty( $messages ) ) {
/**
* Filters instructional messages displayed above the login form.
*
* @param string $messages Login messages.
*
* @since 2.5.0
*/
echo wp_kses_post( sprintf( '
%s
', apply_filters( 'login_messages', $messages ) ) );
}
}
}
}
$show_logo = WP_Defender\Model\Setting\Two_Fa::CUSTOM_GRAPHIC_TYPE_NO !== $custom_graphic_type;
if ( isset( $interim_login ) && 'success' === $interim_login ) {
login_header_otp( '', $message, $show_logo );
$modal_close_script = <<<'END'
END;
add_action(
'wp_print_footer_scripts',
function () use ( $modal_close_script ) {
/**
* Ignore WordPress.Security.EscapeOutput.OutputNotEscaped
* Why?
* We don't want to escape scripts here.
*/
echo $modal_close_script; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
);
} else {
login_header_otp( '', '', $show_logo, $error );
if ( ! empty( $providers ) ) {
$nonce = wp_create_nonce( 'verify_otp' );
foreach ( $providers as $slug => $provider ) {
?>
1 ) {
?>
$provider ) { ?>
-
get_login_label(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
jQuery(function ($) {
function two_factor_providers(defaultSlug) {
// Hide all forms and show the one default.
$('.wpdef-2fa-form').hide();
$('#wpdef-2fa-form-' + defaultSlug).show();
// Hide all links and show others except the default.
if ($('.wpdef-2fa-link').length > 0) {
$('.wpdef-2fa-link').hide();
$('.wpdef-2fa-link:not(#wpdef-2fa-link-' + defaultSlug + ')').each(function () {
$(this).show();
});
}
// Focus on the current input-field.
if ($('#wpdef-2fa-form-' + defaultSlug).find('[name="otp"]').length > 0) {
$('#wpdef-2fa-form-' + defaultSlug).find('[name="otp"]').trigger('focus');
}
}
var is_sent = false;
// Logic for FallbackEmail method.
function resend_code() {
// Work with the button 'Resend Code'.
var that = $('#wd-2fa-resend-code');
if (is_sent === false) {
is_sent = true;
}
let data = {
data: JSON.stringify({
'token': '{$token}',
'requested_user': '{$user_id}'
})
};
$.ajax({
type: 'POST',
url: '{$action_fallback_email}',
data: data,
beforeSend: function () {
that.prop('disabled', true);
$('.def-ajaxloader').show();
},
success: function (data) {
that.prop('disabled', false);
$('.def-ajaxloader').hide();
$('#notification').removeClass().addClass('notice notice-success').text(data.data.message).show();
is_sent = false;
}
});
}
$('.def-ajaxloader').hide();
// Hide all forms and show the one default.
var defaultSlug = '{$default_slug}';
if (!defaultSlug && 0 < $('form.wpdef-2fa-form').first().length) {
var twoFaFormId = $('form.wpdef-2fa-form').first().attr('id');
defaultSlug = twoFaFormId.replace('wpdef-2fa-form-', '');
if ('fallback-email' === defaultSlug) {
resend_code();
} else {
$('#notification').hide();
}
}
two_factor_providers(defaultSlug);
// Work with links.
$('body').on('click', '.wpdef-2fa-link', function () {
$('#login_error').remove();
// Clear any previous notification.
var slug = $(this).data('slug');
two_factor_providers(slug);
// Switch to 'Fallback Email' method.
if ('fallback-email' === slug) {
resend_code();
} else {
$('#notification').hide();
}
});
// Resend code.
$('body').on('click', '#wd-2fa-resend-code', function (e) {
e.preventDefault();
resend_code();
});
});
END;
add_action(
'wp_print_footer_scripts',
function () use ( $totp_script ) {
/**
* Ignore WordPress.Security.EscapeOutput.OutputNotEscaped
* Why?
* We don't want to escape scripts here.
*/
echo $totp_script; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
);
?>