wp-otp-profile-display.php 3.39 KB
Newer Older
noplanman's avatar
noplanman committed
1 2 3 4
<?php
/**
 * Render the WP-OTP section in the user profile in WP Admin
 *
5 6 7
 * @package    Wp_Otp
 * @subpackage Admin
 * @since      0.1.0
noplanman's avatar
noplanman committed
8
 */
9

noplanman's avatar
noplanman committed
10 11 12
?>

<a name="wp_otp"></a>
13
<h2><?php esc_html_e( 'Set up WP-OTP (WordPress One Time Password)', 'wp-otp' ); ?></h2>
noplanman's avatar
noplanman committed
14 15
<table class="form-table">
	<tr>
16
		<th scope="row">
17 18
			<?php esc_html_e( 'OTP Secret', 'wp-otp' ); ?>:<br>
			<?php echo esc_html( implode( ' ', str_split( $secret, 4 ) ) ); ?><br><br>
19
			<?php if ( $otp_enabled ) : ?>
20 21
				<?php
				printf(
22
					'<em>%1$s</em><br><a href="%2$s" class="button button-small wp-otp-link-reconfigure">%3$s</a>',
23 24 25
					esc_html__( 'WP-OTP has been configured successfully.', 'wp-otp' ),
					esc_url( add_query_arg( 'wp-otp-reconfigure', 'yes' ) ),
					esc_html_x( 'Reconfigure', 'Link to reset and reconfigure WP-OTP secret', 'wp-otp' )
26 27
				);
				?>
28 29
				<br><br>
				<div class="wp-otp-recovery-codes-box">
30
					<?php esc_html_e( 'Recovery codes', 'wp-otp' ); ?>:<br>
31 32
					<?php
					foreach ( $user_meta_data->get( 'recovery_codes' ) as $code => $unused ) {
33
						printf( '<%1$s>%2$s</%1$s>', $unused ? 'span' : 'del', $code ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
34 35 36
					}
					printf(
						'<a href="%1$s" class="button button-small wp-otp-link-new-recovery-codes">%2$s</a>',
37 38
						esc_url( add_query_arg( 'wp-otp-new-recovery-codes', 'yes' ) ),
						esc_html_x( 'Regenerate', 'Link to regenerate the WP-OTP recovery codes', 'wp-otp' )
39 40 41
					);
					?>
				</div>
42
			<?php else : ?>
43 44
				<em><?php esc_html_e( 'To activate WP-OTP, enter the One Time Password from your authenticator app and save your profile.', 'wp-otp' ); ?></em><br><br>
				<label for="wp_otp_code"><?php esc_html_e( 'One Time Password', 'wp-otp' ); ?></label><br>
45 46
				<input type="text" class="input" name="wp_otp_code" id="wp_otp_code"/>
				<?php wp_nonce_field( 'wp_otp_nonce', 'wp_otp_nonce', false ); ?>
47
			<?php endif; ?>
noplanman's avatar
noplanman committed
48
		</th>
49
		<td>
50
			<img id="wp-otp-qr-code" src="<?php echo esc_attr( $otp_qr_code_img_uri ); ?>" alt="<?php esc_attr_e( 'QR Code to scan with mobile app', 'wp-otp' ); ?>"/><br>
noplanman's avatar
noplanman committed
51 52
		</td>
		<td>
53
			<span class="description">
54
				<?php esc_html_e( 'Download any OTP Authenticator app on your smart phone and scan the QR Code to activate WP-OTP.', 'wp-otp' ); ?>
55 56
			</span><br><br>

57
			<?php foreach ( $otp_apps as $otp_app ) : ?>
58
				<span class="wp-otp-app-box">
59 60 61 62 63
					<strong><?php echo esc_html( $otp_app['name'] ); ?></strong><br>
					<a href="<?php echo esc_html( $otp_app['uri'] ); ?>" target="_blank">
						<img src="<?php echo esc_url( $otp_app['uri_logo'] ); ?>"
							 alt="<?php echo esc_attr( $otp_app['name'] ); ?>"
							 title="<?php echo esc_attr( $otp_app['name'] ); ?>"
noplanman's avatar
noplanman committed
64
						/></a>&nbsp;
65
					<?php foreach ( $app_providers as $app_provider_key => $app_provider ) : ?>
66
						<?php
noplanman's avatar
noplanman committed
67 68 69
						if ( ! array_key_exists( 'uri_' . $app_provider_key, $otp_app ) ) {
							continue;
						}
70 71 72

						// translators: Placeholder is an app provider name.
						$get_it_on_text = sprintf( esc_attr__( 'Get it on %s', 'wp-otp' ), $app_provider['name'] );
73
						?>
74 75 76 77
						<a href="<?php echo esc_url( $otp_app[ 'uri_' . $app_provider_key ] ); ?>" target="_blank">
							<img src="<?php echo esc_url( $app_provider['uri_logo'] ); ?>"
								 alt="<?php echo esc_attr( $get_it_on_text ); ?>"
								 title="<?php echo esc_attr( $get_it_on_text ); ?>"
78 79 80
							/></a>&nbsp;
					<?php endforeach; ?>
				</span>
noplanman's avatar
noplanman committed
81 82 83 84
			<?php endforeach; ?>
		</td>
	</tr>
</table>