PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 1.5.2
bBlocks – Essential Gutenberg Blocks & Patterns Collection v1.5.2
2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 All 108 releases
b-blocks / inc / qr-code.php

qr-code.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 1.5.2, at inc/qr-code.php

54 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class BBlocksQRCode extends BBlocks{
3 public function __construct(){
4 add_action( 'init', [$this, 'register'] );
5 }
6
7 function register(){
8 $this::registerScripts( 'qr-code', array(
9 'attributes' => $this->attributes(),
10 'render_callback' => [$this, 'render']
11 ) );
12 }
13
14 function attributes(){
15 return array(
16 'align' => array( 'type' => 'string', 'default' => '' ),
17 'cId' => array( 'type' => 'string', 'default' => '' ),
18
19 'qrAlign' => array( 'type' => 'string', 'default' => 'center' ),
20
21 'url' => array( 'type' => 'string', 'default' => '' ),
22 'dimension' => array( 'type' => 'number', 'default' => 180 ),
23
24 'color' => array( 'type' => 'string', 'default' => '#000' ),
25 'bgColor' => array( 'type' => 'string', 'default' => '#fff' )
26 );
27 }
28
29 function render( $attributes ){
30 extract( $attributes );
31
32 // Generate Styles
33 $qrCodeStyle = new BBlocksStyleGenerator();
34 $qrCodeStyle::addStyle( "#bBlocksQRCode-$cId .bBlocksQRCode", array(
35 'text-align' => $qrAlign
36 ) );
37
38 $siteUrl = $url ? $url : 'http://bplugins.com';
39
40 $qrUrl = "https://api.qrserver.com/v1/create-qr-code/?size=". $dimension ."x". $dimension ."&color=". str_replace('#', '', $color) ."&bgcolor=". str_replace('#', '', $bgColor) ."&ecc=L&qzone=1&data=". $siteUrl;
41
42 ob_start(); ?>
43 <div class='wp-block-b-blocks-qr-code <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksQRCode-<?php echo esc_attr( $cId ); ?>'>
44 <style><?php echo wp_kses( $qrCodeStyle::renderStyle(), array() ); ?></style>
45
46 <div class='bBlocksQRCode'>
47 <img src='<?php echo esc_url( $qrUrl ); ?>' alt='<?php echo esc_url( $url ); ?>' />
48 </div>
49 </div>
50 <?php $qrCodeStyle::$styles = array(); // Empty styles
51 return ob_get_clean();
52 }
53 }
54 new BBlocksQRCode();