-
Notifications
You must be signed in to change notification settings - Fork 0
/
itsec-local-qr-code.php
71 lines (55 loc) · 2.05 KB
/
itsec-local-qr-code.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
* Plugin Name: iThemes Security Pro – Local QR Codes
* Plugin URI: https://ithemes.com/security
* Description: Generate QR codes locally instead of relying on the iThemes Security API.
* Author: iThemes
* Author URI: https://ithemes.com
* Version: 1.0.1
* Text Domain: it-l10n-iitsec-local-qr-code
* Domain Path: /lang
* Network: True
* License: GPLv2
* iThemes Package: itsec-local-qr-code
*/
function itsec_local_qr_code_load_textdomain() {
if ( function_exists( 'determine_locale' ) ) {
$locale = determine_locale();
} elseif ( function_exists( 'get_user_locale' ) && is_admin() ) {
$locale = get_user_locale();
} else {
$locale = get_locale();
}
$locale = apply_filters( 'plugin_locale', $locale, 'it-l10n-iitsec-local-qr-code' );
load_textdomain( 'it-l10n-iitsec-local-qr-code', WP_LANG_DIR . "/plugins/itsec-local-qr-code/it-l10n-iitsec-local-qr-code-$locale.mo" );
load_plugin_textdomain( 'it-l10n-iitsec-local-qr-code', false, basename( dirname( __FILE__ ) ) . '/lang/' );
}
add_action( 'plugins_loaded', 'itsec_local_qr_code_load_textdomain' );
function ithemes_itsec_local_qr_code_updater_register( $updater ) {
$updater->register( 'itsec-local-qr-code', __FILE__ );
}
add_action( 'ithemes_updater_register', 'ithemes_itsec_local_qr_code_updater_register' );
if ( file_exists( __DIR__ . '/lib/updater/load.php' ) ) {
require( dirname( __FILE__ ) . '/lib/updater/load.php' );
}
function itsec_local_qr_mode_generate_two_factor_totp( $url, $payload ) {
require_once dirname( __FILE__ ) . '/vendor/qr-code.php';
try {
$qr = ITSEC_QRCode::getMinimumQRCode( urldecode( $payload ), ITSEC_QR_ERROR_CORRECT_LEVEL_L );
$image = $qr->createImage( 4, 0 );
ob_start();
imagepng( $image );
$data = ob_get_contents();
ob_end_clean();
if ( ! $data ) {
return $url;
}
if ( ! $b64 = base64_encode( $data ) ) {
return $url;
}
return sprintf( 'data:image/png;base64,%s', $b64 );
} catch ( Exception $e ) {
return $url;
}
}
add_filter( 'itsec_two_factor_qr_code_url', 'itsec_local_qr_mode_generate_two_factor_totp', 10, 2 );