'',
'link' => 'false',
'target' => '_blank',
'class' => '',
'default' => '',
),
$atts,
'a1tools_var'
);
if ( empty( $atts['key'] ) ) {
return '';
}
$value = a1tools_get_variable( $atts['key'], $atts['default'] );
if ( empty( $value ) ) {
return esc_html( $atts['default'] );
}
// Wrap in link if requested and value is a URL.
if ( 'true' === $atts['link'] && filter_var( $value, FILTER_VALIDATE_URL ) ) {
$class_attr = ! empty( $atts['class'] ) ? ' class="' . esc_attr( $atts['class'] ) . '"' : '';
$rel_attr = '_blank' === $atts['target'] ? ' rel="noopener noreferrer"' : '';
return '' . esc_html( $value ) . '';
}
// Wrap in span if class provided.
if ( ! empty( $atts['class'] ) ) {
return '' . esc_html( $value ) . '';
}
return esc_html( $value );
}
add_shortcode( 'a1tools_var', 'a1tools_shortcode_var' );
/**
* Shortcode: [a1tools_website_url]
* Outputs the website URL as text or a clickable link.
*
* @since 1.5.0
* @param array $atts Shortcode attributes.
* @return string Shortcode output.
*/
function a1tools_shortcode_website_url( $atts ) {
$atts = shortcode_atts(
array(
'link' => 'false',
'target' => '_blank',
'class' => '',
'text' => '',
),
$atts,
'a1tools_website_url'
);
$url = home_url( '/' );
// If link="true", output as a clickable link.
if ( 'true' === $atts['link'] ) {
$link_text = ! empty( $atts['text'] ) ? esc_html( $atts['text'] ) : esc_html( $url );
$class_attr = ! empty( $atts['class'] ) ? ' class="' . esc_attr( $atts['class'] ) . '"' : '';
$rel_attr = '_blank' === $atts['target'] ? ' rel="noopener noreferrer"' : '';
return '' . $link_text . '';
}
// Plain text output.
if ( ! empty( $atts['class'] ) ) {
return '' . esc_html( $url ) . '';
}
return esc_html( $url );
}
add_shortcode( 'a1tools_website_url', 'a1tools_shortcode_website_url' );
/**
* Shortcode: [a1tools_address format="full"]
* Outputs formatted address.
*
* @since 1.0.0
* @param array $atts Shortcode attributes.
* @return string Shortcode output.
*/
function a1tools_shortcode_address( $atts ) {
$atts = shortcode_atts(
array(
'format' => 'full',
'separator' => '
',
),
$atts,
'a1tools_address'
);
$vars = a1tools_get_site_variables();
if ( ! $vars ) {
return '';
}
$parts = array();
switch ( $atts['format'] ) {
case 'street':
$parts = array_filter(
array(
isset( $vars['address_line1'] ) ? $vars['address_line1'] : '',
isset( $vars['address_line2'] ) ? $vars['address_line2'] : '',
)
);
break;
case 'city_state_zip':
$city_state = array_filter(
array(
isset( $vars['city'] ) ? $vars['city'] : '',
isset( $vars['state'] ) ? $vars['state'] : '',
)
);
$zip = isset( $vars['zip'] ) ? $vars['zip'] : '';
$parts = array( implode( ', ', $city_state ) . ' ' . $zip );
break;
case 'full':
default:
$city = isset( $vars['city'] ) ? $vars['city'] : '';
$state = isset( $vars['state'] ) ? $vars['state'] : '';
$zip = isset( $vars['zip'] ) ? $vars['zip'] : '';
$state_zip = trim( $state . ' ' . $zip );
$city_line = $city ? $city . ( $state_zip ? ', ' . $state_zip : '' ) : $state_zip;
$parts = array_filter(
array(
isset( $vars['address_line1'] ) ? $vars['address_line1'] : '',
isset( $vars['address_line2'] ) ? $vars['address_line2'] : '',
$city_line,
isset( $vars['country'] ) ? $vars['country'] : '',
)
);
break;
}
// Handle separator - allow only safe HTML tags.
$allowed_sep_tags = array(
'br' => array(),
'span' => array( 'class' => array(), 'style' => array() ),
'hr' => array( 'class' => array() ),
);
$separator = wp_kses( $atts['separator'], $allowed_sep_tags );
return implode( $separator, array_map( 'esc_html', $parts ) );
}
add_shortcode( 'a1tools_address', 'a1tools_shortcode_address' );
/**
* Shortcode: [a1tools_full_address]
* Outputs the complete address in a single line.
*
* @since 1.2.0
* @param array $atts Shortcode attributes.
* @return string Shortcode output.
*/
function a1tools_shortcode_full_address( $atts ) {
$atts = shortcode_atts(
array(
'separator' => ', ',
'class' => '',
),
$atts,
'a1tools_full_address'
);
$vars = a1tools_get_site_variables();
if ( ! $vars ) {
return '';
}
// Use standalone full_address field if set.
if ( ! empty( $vars['full_address'] ) ) {
$output = esc_html( $vars['full_address'] );
if ( ! empty( $atts['class'] ) ) {
$output = '' . $output . '';
}
return $output;
}
// Fallback: assemble from individual address fields.
$parts = array();
// Address Line 1.
if ( ! empty( $vars['address_line1'] ) ) {
$parts[] = $vars['address_line1'];
}
// Address Line 2.
if ( ! empty( $vars['address_line2'] ) ) {
$parts[] = $vars['address_line2'];
}
// City.
if ( ! empty( $vars['city'] ) ) {
$parts[] = $vars['city'];
}
// State + ZIP (combined).
$state = ! empty( $vars['state'] ) ? $vars['state'] : '';
$zip = ! empty( $vars['zip'] ) ? $vars['zip'] : '';
if ( $state || $zip ) {
$parts[] = trim( $state . ' ' . $zip );
}
if ( empty( $parts ) ) {
return '';
}
$output = esc_html( implode( $atts['separator'], $parts ) );
if ( ! empty( $atts['class'] ) ) {
$output = '' . $output . '';
}
return $output;
}
add_shortcode( 'a1tools_full_address', 'a1tools_shortcode_full_address' );
/**
* Shortcode: [a1tools_hours]
* Outputs formatted operating hours table.
*
* @since 1.0.0
* @param array $atts Shortcode attributes.
* @return string Shortcode output.
*/
function a1tools_shortcode_hours( $atts ) {
$atts = shortcode_atts(
array(
'format' => 'table',
'class' => 'a1tools-hours',
),
$atts,
'a1tools_hours'
);
$vars = a1tools_get_site_variables();
if ( ! $vars || empty( $vars['operating_hours'] ) ) {
return '';
}
$hours = $vars['operating_hours'];
$days = array(
'mon' => __( 'Monday', 'a1-tools' ),
'tue' => __( 'Tuesday', 'a1-tools' ),
'wed' => __( 'Wednesday', 'a1-tools' ),
'thu' => __( 'Thursday', 'a1-tools' ),
'fri' => __( 'Friday', 'a1-tools' ),
'sat' => __( 'Saturday', 'a1-tools' ),
'sun' => __( 'Sunday', 'a1-tools' ),
);
$output = '';
if ( 'list' === $atts['format'] ) {
$output = '
';
foreach ( $days as $key => $label ) {
$time = isset( $hours[ $key ] ) && ! empty( $hours[ $key ] ) ? esc_html( $hours[ $key ] ) : esc_html__( 'Closed', 'a1-tools' );
$output .= '- ' . esc_html( $label ) . ': ' . $time . '
';
}
$output .= '
';
} else {
$output = '';
foreach ( $days as $key => $label ) {
$time = isset( $hours[ $key ] ) && ! empty( $hours[ $key ] ) ? esc_html( $hours[ $key ] ) : esc_html__( 'Closed', 'a1-tools' );
$output .= '| ' . esc_html( $label ) . ' | ' . $time . ' |
';
}
$output .= '
';
}
return $output;
}
add_shortcode( 'a1tools_hours', 'a1tools_shortcode_hours' );
/**
* Get SVG markup for icons not available in Font Awesome 5.
*
* @since 1.5.0
* @param string $icon_key The SVG icon key (e.g. 'svg-x').
* @return string SVG markup or empty string.
*/
function a1tools_get_svg_icon( $icon_key ) {
$svgs = array(
'svg-x' => '',
);
return isset( $svgs[ $icon_key ] ) ? $svgs[ $icon_key ] : '';
}
/**
* Get icon HTML (SVG or Font Awesome tag).
*
* @since 1.5.0
* @param string $icon Icon class or SVG key.
* @return string HTML markup for the icon.
*/
function a1tools_get_icon_html( $icon ) {
$svg = a1tools_get_svg_icon( $icon );
if ( $svg ) {
return $svg;
}
return '';
}
/**
* Allowed-tags array for safely echoing icon HTML.
*
* Permits Font Awesome tags AND inline