
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
/**
 * Shortcode Buttons config
 *
 * @link       https://codesupply.co/plugins/basic-shortcodes/
 * @since      1.0.0
 *
 * @package    Basic Shortcodes
 * @subpackage Templates
 */

/**
 * Buttons
 */
bsc_register_shortcode( array(
	'name'			=> 'buttons',
	'title'			=> esc_html__( 'Buttons', 'basic-shortcodes' ),
	'priority'		=> 20,
	'base'			=> 'bsc_button',
	'autoregister'	=> true,
	'fields'		=> array(
		array(
			'type'		=> 'section',
			'label'		=> esc_html__( 'Style Options', 'basic-shortcodes' ),
		),
		array(
			'type'		=> 'radio',
			'name'		=> 'size',
			'label'		=> esc_html__( 'Size', 'basic-shortcodes' ),
			'style'		=> 'horizontal',
			'default'	=> 'md',
			'options'	=> array(
				'sm'	=> esc_html__( 'Small', 'basic-shortcodes' ),
				'md'	=> esc_html__( 'Default', 'basic-shortcodes' ),
				'lg'	=> esc_html__( 'Large', 'basic-shortcodes' ),
			),
		),
		array(
			'type'		=> 'radio',
			'name'		=> 'style',
			'label'		=> esc_html__( 'Style', 'basic-shortcodes' ),
			'style'		=> 'vertical',
			'default'	=> 'primary',
			'options'	=> array(
				'primary'	=> esc_html__( 'Primary', 'basic-shortcodes' ),
				'secondary'	=> esc_html__( 'Secondary', 'basic-shortcodes' ),
				'success'	=> esc_html__( 'Success', 'basic-shortcodes' ),
				'info'		=> esc_html__( 'Info', 'basic-shortcodes' ),
				'warning'	=> esc_html__( 'Warning', 'basic-shortcodes' ),
				'danger'	=> esc_html__( 'Danger', 'basic-shortcodes' ),
				'link'		=> esc_html__( 'Link', 'basic-shortcodes' ),
			),
		),
		array(
			'type'		=> 'checkbox',
			'name'		=> 'block',
			'label'		=> esc_html__( 'Block', 'basic-shortcodes' ),
			'default'	=> false,
		),
		array(
			'type'		=> 'section',
			'label'		=> esc_html__( 'Link Options', 'basic-shortcodes' ),
		),
		array(
			'type'		=> 'input',
			'name'		=> 'title',
			'label'		=> esc_html__( 'Title', 'basic-shortcodes' ),
			'default'	=> 'Button',
		),
		array(
			'type'		=> 'input',
			'name'		=> 'url',
			'label'		=> esc_html__( 'URL', 'basic-shortcodes' ),
			'default'	=> 'http://',
		),
		array(
			'type'		=> 'radio',
			'name'		=> 'target',
			'label'		=> esc_html__( 'Link Target', 'basic-shortcodes' ),
			'style'		=> 'vertical',
			'default'	=> '_self',
			'options'	=> array(
				'_self'		=> esc_html__( 'Open in same window', 'basic-shortcodes' ),
				'_blank'	=> esc_html__( 'Open in new window/tab', 'basic-shortcodes' ),
			),
		),
		array(
			'type'		=> 'checkbox',
			'name'		=> 'nofollow',
			'label'		=> esc_html__( 'Apply "nofollow" attribute', 'basic-shortcodes' ),
			'default'	=> false,
		),
	),
) );


/**
 * Button Shortcode
 *
 * @param array  $output    Shortcode HTML.
 * @param array  $atts      User defined attributes in shortcode tag.
 * @param string $content   Shorcode tag content.
 * @return string           Shortcode result HTML.
 */
function bsc_button_shortcode( $output, $atts, $content ) {
	$nofollow  = ( 'true' === $atts['nofollow'] ) ? 'rel="nofollow"' : '';
	$block  = ( 'true' === $atts['block'] ) ? ' btn-block' : '';

	$output = sprintf(
		'<a class="bsc-button btn btn-%s btn-%s%s" href="%s" target="%s" %s>
			%s
		</a>',
		$atts['size'],
		$atts['style'],
		$block,
		$atts['url'],
		$atts['target'],
		$nofollow,
		$atts['title']
	);

	return $output;
}
add_filter( 'bsc_button_shortcode', 'bsc_button_shortcode', 10, 3 );
