| 1 |
<?php |
| 2 |
/** |
| 3 |
* This template is used to display 2FA notices. |
| 4 |
* |
| 5 |
* @package WP_Defender |
| 6 |
*/ |
| 7 |
|
| 8 |
foreach ( $notices as $notice ) { |
| 9 |
$class = array( 'wpdef-notice', $notice['type'], $notice['extra_class'] ); |
| 10 |
$class[] = ! empty( $notice['is_dismissible'] ) ? 'is-dismissible' : ''; |
| 11 |
$class = implode( ' ', array_filter( $class ) ); |
| 12 |
?> |
| 13 |
<div class="<?php echo esc_attr( $class ); ?>" <?php echo $notice['style'] ? 'style="' . esc_attr( $notice['style'] ) . '"' : ''; ?>> |
| 14 |
<p> |
| 15 |
<span class="dashicons dashicons-<?php echo esc_attr( $notice['type'] ); ?>"></span> |
| 16 |
<span class="wpdef-notice-message"><?php echo wp_kses_post( $notice['message'] ); ?></span> |
| 17 |
</p> |
| 18 |
<?php |
| 19 |
if ( ! empty( $notice['is_dismissible'] ) ) { |
| 20 |
?> |
| 21 |
<button type="button" class="notice-dismiss"> |
| 22 |
<span class="screen-reader-text"><?php esc_attr_e( 'Dismiss', 'defender-security' ); ?></span> |
| 23 |
</button> |
| 24 |
<?php |
| 25 |
} |
| 26 |
?> |
| 27 |
</div> |
| 28 |
<?php } ?> |
| 29 |
|
| 30 |
<script type="text/javascript"> |
| 31 |
jQuery(function ($) { |
| 32 |
maybeShowAdditionalAuthMethodNotice(); |
| 33 |
$('body').on('click', '.auth-methods-table .wpdef-ui-toggle', maybeShowAdditionalAuthMethodNotice); |
| 34 |
|
| 35 |
$('.wpdef-notice.has-server-error .browser-incompatible-msg, .wpdef-notice.browser-notice').hide(); |
| 36 |
if (!checkBrowserSupportForWebauthn()) { |
| 37 |
disableWebauthnFeature(); |
| 38 |
$('.wpdef-notice.has-server-error .browser-incompatible-msg, .wpdef-notice.browser-notice').show(); |
| 39 |
} |
| 40 |
|
| 41 |
function checkBrowserSupportForWebauthn() { |
| 42 |
return 'undefined' !== typeof PublicKeyCredential && ('credentials' in navigator); |
| 43 |
} |
| 44 |
|
| 45 |
function disableWebauthnFeature() { |
| 46 |
$('.defender-biometric-wrap .wpdef-device-btn').attr('disabled', 'disabled'); |
| 47 |
} |
| 48 |
|
| 49 |
function maybeShowAdditionalAuthMethodNotice() { |
| 50 |
let $authTable = $('.auth-methods-table'); |
| 51 |
|
| 52 |
if ( |
| 53 |
1 === $authTable.find('.wpdef-ui-toggle:checked').length && |
| 54 |
1 === $authTable.find('#field-webauthn:checked').length |
| 55 |
) { |
| 56 |
$authTable.find('.wpdef-notice.additional-2fa-method').show(); |
| 57 |
} else { |
| 58 |
$authTable.find('.wpdef-notice.additional-2fa-method').hide(); |
| 59 |
} |
| 60 |
} |
| 61 |
}); |
| 62 |
</script> |
| 63 |
|