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

/**
 * Alerts
 */
bsc_register_shortcode( array(
	'name'			=> 'alerts',
	'title'			=> esc_html__( 'Alerts', 'basic-shortcodes' ),
	'priority'		=> 30,
	'base'			=> 'bsc_alert',
	'autoregister'	=> true,
	'fields' 		=> array(
		array(
			'type'		=> 'section',
			'label'		=> esc_html__( 'Options', 'basic-shortcodes' ),
		),
		array(
			'type'		=> 'radio',
			'name'		=> 'type',
			'label'		=> esc_html__( 'Type', 'basic-shortcodes' ),
			'style'		=> 'vertical',
			'default'	=> 'info',
			'options'	=> array(
				'danger'	=> esc_html__( 'Danger', 'basic-shortcodes' ),
				'info'		=> esc_html__( 'Info', 'basic-shortcodes' ),
				'link'		=> esc_html__( 'Link', 'basic-shortcodes' ),
				'success'	=> esc_html__( 'Success', 'basic-shortcodes' ),
				'warning'	=> esc_html__( 'Warning', 'basic-shortcodes' ),
			),
		),
		array(
			'type'		=> 'checkbox',
			'name'		=> 'dismissible',
			'label'		=> esc_html__( 'Display close button', 'basic-shortcodes' ),
			'default'	=> false,
		),
		array(
			'type'		=> 'section',
			'label'		=> esc_html__( 'Content', 'basic-shortcodes' ),
		),
		array(
			'type'		=> 'content',
			'name'		=> 'content',
			'label'		=> esc_html__( 'Content', 'basic-shortcodes' ),
			'default'	=> '',
			'attrs'		=> array(
				'class'	=> 'widefat',
				'rows'  => 6,
			),
		),
	),
) );


/**
 * Alert 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_alert_shortcode( $output, $atts, $content ) {
	if ( 'true' === $atts['dismissible'] ) {
		$dm_class  = ' alert-dismissible';
		$dm_button = '
					<button type="button" class="close" data-dismiss="alert" aria-label="' . esc_attr__( 'Close', 'basic-shortcodes' ) . '">
						<span aria-hidden="true">&times;</span>
					</button>';
	} else {
		$dm_class  = '';
		$dm_button = '';
	}

	$output = sprintf(
		'<div class="bsc-alert alert alert-%s%s" role="alert" >%s%s</div>',
		$atts['type'],
		$dm_class,
		$dm_button,
		$content
	);

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