# b-blocks/1.5.2/inc/qr-code.php

bBlocks – Essential Gutenberg Blocks &amp; Patterns Collection, version 1.5.2. 54 lines.

- Page: https://pluginprobe.com/plugins/b-blocks/1.5.2/code/inc/qr-code.php
- Raw: https://pluginprobe.com/plugins/b-blocks/1.5.2/raw/inc/qr-code.php
- Modified: 2021-10-18T14:05:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/b-blocks/1.5.2/code/inc/qr-code.php#L10-L20`.

```php
<?php
class BBlocksQRCode extends BBlocks{
    public function __construct(){
        add_action( 'init', [$this, 'register'] );
    }

    function register(){
        $this::registerScripts( 'qr-code', array(
            'attributes'      => $this->attributes(),
            'render_callback' => [$this, 'render']
        ) );
    }

    function attributes(){
        return array(
            'align' => array( 'type' => 'string', 'default' => '' ),
            'cId' => array( 'type' => 'string', 'default' => '' ),

            'qrAlign' => array( 'type' => 'string', 'default' => 'center' ),

            'url' => array( 'type' => 'string', 'default' => '' ),
            'dimension' => array( 'type' => 'number', 'default' => 180 ),

            'color' => array( 'type' => 'string', 'default' => '#000' ),
            'bgColor' => array( 'type' => 'string', 'default' => '#fff' )
        );
    }

    function render( $attributes ){
        extract( $attributes );

        // Generate Styles
        $qrCodeStyle = new BBlocksStyleGenerator();
        $qrCodeStyle::addStyle( "#bBlocksQRCode-$cId .bBlocksQRCode", array(
            'text-align' => $qrAlign
        ) );

        $siteUrl = $url ? $url : 'http://bplugins.com';

        $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;

        ob_start(); ?>
        <div class='wp-block-b-blocks-qr-code <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksQRCode-<?php echo esc_attr( $cId ); ?>'>
            <style><?php echo wp_kses( $qrCodeStyle::renderStyle(), array() ); ?></style>

            <div class='bBlocksQRCode'>
                <img src='<?php echo esc_url( $qrUrl ); ?>' alt='<?php echo esc_url( $url ); ?>' />
            </div>
        </div>
        <?php $qrCodeStyle::$styles = array(); // Empty styles
        return ob_get_clean();
    }
}
new BBlocksQRCode();
```
