-
Notifications
You must be signed in to change notification settings - Fork 1
/
qr.php
47 lines (45 loc) · 1.83 KB
/
qr.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
<?php
/* Template Name: QR Code */
require __DIR__ . '/inc/QR-CODE/vendor/autoload.php';
use Endroid\QrCode\QrCode;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\Response\QrCodeResponse;
if ( ! is_user_logged_in() ) {
wp_redirect( 'http://nts.wp-vip.com/' );
exit();
} else {
$json = json_encode(
[
'user_name' => wp_get_current_user()->display_name,
'user_email' => wp_get_current_user()->user_email,
'user_is' => get_current_user_id(),
'date' => current_datetime(),
'employee_id' => get_field( 'employee_id', 'user_' . get_current_user_id() ),
'user_package' => get_field( 'meal_courses', 'user_' . get_current_user_id() ),
'user_phone' => get_field( 'phone_number', 'user_' . get_current_user_id() ),
]
);
// Create a basic QR code
$qrCode = new QrCode( $json );
$qrCode->setSize( 300 );
// Set advanced options
$qrCode->setWriterByName( 'png' );
$qrCode->setEncoding( 'UTF-8' );
$qrCode->setErrorCorrectionLevel( ErrorCorrectionLevel::HIGH() );
$qrCode->setForegroundColor( [ 'r' => 0, 'g' => 0, 'b' => 0, 'a' => 0 ] );
$qrCode->setBackgroundColor( [ 'r' => 255, 'g' => 255, 'b' => 255, 'a' => 0 ] );
$qrCode->setLabel( 'Scan the code ' . wp_get_current_user()->display_name, 8, null, LabelAlignment::CENTER() );
$qrCode->setLogoPath( __DIR__ . '/inc/QR-CODE/img/logo.png' );
$qrCode->setLogoSize( 50, 50 );
$qrCode->setRoundBlockSize( true );
$qrCode->setValidateResult( false );
$qrCode->setWriterOptions( [ 'exclude_xml_declaration' => true ] );
// Directly output the QR code
header( 'Content-Type: ' . $qrCode->getContentType() );
echo $qrCode->writeString();
// Save it to a file
$qrCode->writeFile( __DIR__ . '/inc/QR-CODE/img/QR/' . get_current_user_id() . '_logo.png' );
// Create a response object
$response = new QrCodeResponse( $qrCode );
}