su_shortcode_qrcode

The shortcodes-ultimate su shortcode qrcode function.

Published Date - February 15, 2021

Description

su_shortcode_qrcode( $atts, $content );

Parameters

  1. $atts

  2. $content


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_qrcode' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/qrcode.php';
}

// The input(s). 
$atts = null;
$content = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_qrcode( $atts, $content );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/shortcodes/qrcode.php

function su_shortcode_qrcode( $atts = null, $content = null ) {
	$atts = shortcode_atts(
		array(
			'data'       => '',
			'title'      => '',
			'size'       => 200,
			'margin'     => 0,
			'align'      => 'none',
			'link'       => '',
			'target'     => 'blank',
			'color'      => '#000000',
			'background' => '#ffffff',
			'class'      => '',
		),
		$atts,
		'qrcode'
	);
	// Check the data
	if ( ! $atts['data'] ) {
		return su_error_message( 'QR code', __( 'please specify the data', 'shortcodes-ultimate' ) );
	}
	$atts['data'] = su_do_attribute( $atts['data'] );
	$atts['data'] = sanitize_text_field( $atts['data'] );
	// Prepare link
	$href = ( $atts['link'] ) ? ' href="' . $atts['link'] . '"' : '';
	// Prepare clickable class
	if ( $atts['link'] ) {
		$atts['class'] .= ' su-qrcode-clickable';
	}
	// Prepare title
	$atts['title'] = esc_attr( $atts['title'] );
	// Query assets
	su_query_asset( 'css', 'su-shortcodes' );

	$url = add_query_arg(
		array(
			'data'    => rawurlencode( $atts['data'] ),
			'size'    => sprintf( '%1$sx%1$s', intval( $atts['size'] ) ),
			'format'  => 'png',
			'margin'  => intval( $atts['margin'] ),
			'color'   => ltrim( $atts['color'], '#' ),
			'bgcolor' => ltrim( $atts['background'], '#' ),
		),
		'https://api.qrserver.com/v1/create-qr-code/'
	);

	// Return result
	return '<span class="su-qrcode su-qrcode-align-' . $atts['align'] . su_get_css_class( $atts ) . '"><a' . $href . ' target="_' . $atts['target'] . '" title="' . $atts['title'] . '"><img src="' . esc_url( $url ) . '" alt="' . $atts['title'] . '" /></a></span>';
}