Last active
October 8, 2015 23:19
-
-
Save stevenkword/c3e490e31af058b35b41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="two-factor-backup-codes-wrapper" style="display:none;"> | |
<ol class="two-factor-backup-codes-unused-codes"></ol> | |
<p class="description"><?php esc_html_e( 'Write these down! Once you navigate away from this page, you will not be able to view these codes again.' ); ?></p> | |
<p> | |
<a class="a" href="javascript:void(0);" id="two-factor-backup-codes-download-link" download="two-factor-backup-codes.txt">Download</a> | |
<button type="button" class="button button-two-factor-backup-codes-download button-secondary hide-if-no-js" download="two-factor-backup-codes2.txt"> | |
<?php esc_html_e( 'Download' ); ?> | |
</button> | |
<p> | |
</div> | |
<script type="text/javascript"> | |
jQuery( document ).ready( function( $ ) { | |
$( '.button-two-factor-backup-codes-download' ).click( function() { | |
//$('#two-factor-backup-codes-download-link').trigger( "click" ); | |
//alert('click'); | |
window.location.href = $( '#two-factor-backup-codes-download-link' ).attr('href'); | |
} ); | |
$( '.button-two-factor-backup-codes-generate' ).click( function() { | |
$.ajax( { | |
method: 'POST', | |
url: ajaxurl, | |
data: { | |
action: 'two_factor_backup_codes_generate', | |
user_id: '<?php echo esc_js( $user->ID ); ?>', | |
nonce: '<?php echo esc_js( $ajax_nonce ); ?>' | |
}, | |
dataType: 'JSON', | |
success: function( response ) { | |
$( '.two-factor-backup-codes-wrapper' ).show(); | |
$( '.two-factor-backup-codes-unused-codes' ).html( '' ); | |
// Append the codes. | |
$.each( response.data.codes, function( key, val ) { | |
$( '.two-factor-backup-codes-unused-codes' ).append( '<li>' + val + '</li>' ); | |
} ); | |
// Update counter. | |
$( '.two-factor-backup-codes-count' ).html( response.data.i18n ); | |
// Build the download link | |
var txt_data = 'data:application/txt;charset=utf-8,' + '\n'; | |
txt_data += 'Two-Factor Backup Codes for <?php echo wp_title(); ?>' + '\n\n'; | |
var count = 1; | |
$.each( response.data.codes, function( key, val ) { | |
txt_data += count + '. ' + val + '\n'; | |
count++; | |
} ); | |
$( '#two-factor-backup-codes-download-link' ).attr( 'href', encodeURI( txt_data ) ); | |
} | |
} ); | |
} ); | |
} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment