` 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() ? ' › ' : ' ‹ '; ?> > <?php printf( '%s%s%s', esc_attr( get_bloginfo( 'name', 'display' ) ), esc_attr( $separator ), esc_attr( $title ) ); ?> get_error_code() ) { ?> site_name; } else { $login_header_url = 'https://wordpress.org/'; $login_header_title = esc_html__( 'Powered by WordPress', 'defender-security' ); } /** * Filters link URL of the header logo above login form. * * @param string $login_header_url Login header logo URL. * * @since 2.1.0 */ $login_header_url = apply_filters( 'login_headerurl', $login_header_url ); /** * Filters the title attribute of the header logo above login form. * * @param string $login_header_title Login header logo title attribute. * * @since 2.1.0 */ $login_header_title = apply_filters( 'login_headertitle', $login_header_title ); $classes = array( 'login-action-' . $action, 'wp-core-ui' ); if ( is_rtl() ) { $classes[] = 'rtl'; } if ( $interim_login ) { $classes[] = 'interim-login'; ?>

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 ) { ?>
authentication_form(); ?>
1 ) { ?>

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 } ); ?>