get_widget_config();
$vars = function_exists( 'a1tools_get_site_variables' ) ? a1tools_get_site_variables() : null;
if ( ! $vars ) {
return '';
}
$key = $config['var_key'];
if ( 'full_address' === $key ) {
if ( ! empty( $vars['full_address'] ) ) {
return $vars['full_address'];
}
$parts = array_filter( array(
$vars['address_line1'] ?? '',
$vars['city'] ?? '',
$vars['state'] ?? '',
$vars['zip'] ?? '',
) );
return implode( ', ', $parts );
}
return isset( $vars[ $key ] ) ? $vars[ $key ] : '';
}
/**
* Build a link URL for the given value.
*/
protected function build_link_url( $value ) {
$config = $this->get_widget_config();
$prefix = isset( $config['link_prefix'] ) ? $config['link_prefix'] : '';
if ( 'tel:' === $prefix ) {
return 'tel:' . preg_replace( '/[^0-9+]/', '', $value );
} elseif ( 'mailto:' === $prefix ) {
return 'mailto:' . sanitize_email( $value );
} elseif ( 'map:' === $prefix ) {
return 'https://maps.google.com/?q=' . urlencode( $value );
}
return '';
}
// ────────────────────────────────────────────────────────────────
// Controls
// ────────────────────────────────────────────────────────────────
protected function register_controls() {
$config = $this->get_widget_config();
$value = $this->get_variable_value();
// ── Content ─────────────────────────────────────────────────
$this->start_controls_section(
'content_section',
array(
'label' => __( 'Content', 'a1-tools' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
)
);
if ( $value ) {
$this->add_control(
'info_notice',
array(
'type' => \Elementor\Controls_Manager::RAW_HTML,
'raw' => 'Current value: ' . esc_html( $value ) . '
Edit in the A1 Tools app.',
'content_classes' => 'elementor-panel-alert elementor-panel-alert-success',
)
);
} else {
$this->add_control(
'info_notice',
array(
'type' => \Elementor\Controls_Manager::RAW_HTML,
'raw' => 'No ' . esc_html( strtolower( $config['title'] ) ) . ' configured.
Set it in the A1 Tools app.',
'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning',
)
);
}
$this->add_control(
'icon',
array(
'label' => __( 'Icon', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::ICONS,
'default' => $config['default_icon'],
)
);
$this->add_control(
'title_text',
array(
'label' => __( 'Title', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => $config['title'],
'label_block' => true,
)
);
$this->add_control(
'enable_link',
array(
'label' => __( 'Link', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __( 'Yes', 'a1-tools' ),
'label_off' => __( 'No', 'a1-tools' ),
'return_value' => 'yes',
'default' => 'yes',
'description' => isset( $config['link_desc'] ) ? $config['link_desc'] : '',
)
);
$this->end_controls_section();
// ── Style: Icon ─────────────────────────────────────────────
$this->start_controls_section(
'icon_style_section',
array(
'label' => __( 'Icon', 'a1-tools' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
)
);
$this->add_control(
'icon_color',
array(
'label' => __( 'Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#E53935',
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-icon' => 'color: {{VALUE}};',
'{{WRAPPER}} .a1tools-info-box-icon svg' => 'fill: {{VALUE}};',
),
)
);
$this->add_control(
'icon_size',
array(
'label' => __( 'Size', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => array( 'px' ),
'range' => array(
'px' => array( 'min' => 12, 'max' => 80, 'step' => 1 ),
),
'default' => array( 'unit' => 'px', 'size' => 28 ),
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-icon' => 'font-size: {{SIZE}}{{UNIT}};',
'{{WRAPPER}} .a1tools-info-box-icon svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
),
)
);
$this->add_control(
'icon_bg_heading',
array(
'label' => __( 'Background', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
)
);
$this->add_control(
'icon_bg_color',
array(
'label' => __( 'Background Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '',
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-icon' => 'background-color: {{VALUE}};',
),
)
);
$this->add_control(
'icon_padding',
array(
'label' => __( 'Padding', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => array( 'px' ),
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-icon' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
),
)
);
$this->add_control(
'icon_border_heading',
array(
'label' => __( 'Border', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
)
);
$this->add_group_control(
\Elementor\Group_Control_Border::get_type(),
array(
'name' => 'icon_border',
'label' => __( 'Border', 'a1-tools' ),
'selector' => '{{WRAPPER}} .a1tools-info-box-icon',
)
);
$this->add_control(
'icon_border_radius',
array(
'label' => __( 'Border Radius', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => array( 'px', '%' ),
'range' => array(
'px' => array( 'min' => 0, 'max' => 50 ),
'%' => array( 'min' => 0, 'max' => 50 ),
),
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-icon' => 'border-radius: {{SIZE}}{{UNIT}};',
),
)
);
$this->add_control(
'icon_gap',
array(
'label' => __( 'Spacing', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => array( 'px' ),
'range' => array(
'px' => array( 'min' => 0, 'max' => 40, 'step' => 1 ),
),
'default' => array( 'unit' => 'px', 'size' => 12 ),
'separator' => 'before',
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box' => 'gap: {{SIZE}}{{UNIT}};',
),
)
);
$this->end_controls_section();
// ── Style: Content ──────────────────────────────────────────
$this->start_controls_section(
'content_style_section',
array(
'label' => __( 'Content', 'a1-tools' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
)
);
$this->add_responsive_control(
'alignment',
array(
'label' => __( 'Alignment', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::CHOOSE,
'options' => array(
'left' => array(
'title' => __( 'Left', 'a1-tools' ),
'icon' => 'eicon-text-align-left',
),
'center' => array(
'title' => __( 'Center', 'a1-tools' ),
'icon' => 'eicon-text-align-center',
),
'right' => array(
'title' => __( 'Right', 'a1-tools' ),
'icon' => 'eicon-text-align-right',
),
),
'default' => 'left',
'selectors_dictionary' => array(
'left' => 'flex-start',
'center' => 'center',
'right' => 'flex-end',
),
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box' => 'justify-content: {{VALUE}};',
),
)
);
$this->add_responsive_control(
'vertical_alignment',
array(
'label' => __( 'Vertical Alignment', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::CHOOSE,
'options' => array(
'flex-start' => array(
'title' => __( 'Top', 'a1-tools' ),
'icon' => 'eicon-v-align-top',
),
'center' => array(
'title' => __( 'Middle', 'a1-tools' ),
'icon' => 'eicon-v-align-middle',
),
'flex-end' => array(
'title' => __( 'Bottom', 'a1-tools' ),
'icon' => 'eicon-v-align-bottom',
),
),
'default' => 'flex-start',
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box' => 'align-items: {{VALUE}};',
),
)
);
$this->add_control(
'title_heading',
array(
'label' => __( 'Title', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
)
);
$this->add_control(
'title_color',
array(
'label' => __( 'Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-title' => 'color: {{VALUE}};',
),
)
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
array(
'name' => 'title_typography',
'selector' => '{{WRAPPER}} .a1tools-info-box-title',
)
);
$this->add_control(
'value_heading',
array(
'label' => __( 'Value', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
)
);
$this->add_control(
'value_color',
array(
'label' => __( 'Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-value' => 'color: {{VALUE}};',
),
)
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
array(
'name' => 'value_typography',
'selector' => '{{WRAPPER}} .a1tools-info-box-value',
)
);
$this->add_control(
'link_heading',
array(
'label' => __( 'Link', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
'condition' => array( 'enable_link' => 'yes' ),
)
);
$this->add_control(
'link_underline',
array(
'label' => __( 'Underline', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'none',
'options' => array(
'none' => __( 'None', 'a1-tools' ),
'underline' => __( 'Always', 'a1-tools' ),
'hover' => __( 'On Hover', 'a1-tools' ),
),
'condition' => array( 'enable_link' => 'yes' ),
'selectors_dictionary' => array(
'none' => 'none',
'underline' => 'underline',
'hover' => 'none',
),
'selectors' => array(
'{{WRAPPER}} a.a1tools-info-box-link .a1tools-info-box-value' => 'text-decoration: {{VALUE}};',
),
)
);
$this->add_control(
'hover_heading',
array(
'label' => __( 'Hover', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
'condition' => array( 'enable_link' => 'yes' ),
)
);
$this->add_control(
'hover_icon_color',
array(
'label' => __( 'Icon Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'condition' => array( 'enable_link' => 'yes' ),
'selectors' => array(
'{{WRAPPER}} a.a1tools-info-box-link:hover .a1tools-info-box-icon' => 'color: {{VALUE}};',
'{{WRAPPER}} a.a1tools-info-box-link:hover .a1tools-info-box-icon svg' => 'fill: {{VALUE}};',
),
)
);
$this->add_control(
'hover_title_color',
array(
'label' => __( 'Title Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'condition' => array( 'enable_link' => 'yes' ),
'selectors' => array(
'{{WRAPPER}} a.a1tools-info-box-link:hover .a1tools-info-box-title' => 'color: {{VALUE}};',
),
)
);
$this->add_control(
'hover_value_color',
array(
'label' => __( 'Value Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'condition' => array( 'enable_link' => 'yes' ),
'selectors' => array(
'{{WRAPPER}} a.a1tools-info-box-link:hover .a1tools-info-box-value' => 'color: {{VALUE}};',
),
)
);
$this->add_control(
'title_value_gap',
array(
'label' => __( 'Title / Value Gap', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => array( 'px' ),
'range' => array(
'px' => array( 'min' => 0, 'max' => 20, 'step' => 1 ),
),
'default' => array( 'unit' => 'px', 'size' => 2 ),
'separator' => 'before',
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box-content' => 'gap: {{SIZE}}{{UNIT}};',
),
)
);
$this->end_controls_section();
// ── Style: Box ──────────────────────────────────────────────
$this->start_controls_section(
'box_style_section',
array(
'label' => __( 'Box Style', 'a1-tools' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
)
);
$this->add_control(
'box_bg_color',
array(
'label' => __( 'Background Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box' => 'background-color: {{VALUE}};',
),
)
);
$this->add_group_control(
\Elementor\Group_Control_Border::get_type(),
array(
'name' => 'box_border',
'selector' => '{{WRAPPER}} .a1tools-info-box',
)
);
$this->add_control(
'box_border_hover_color',
array(
'label' => __( 'Border Hover Color', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box:hover' => 'border-color: {{VALUE}};',
),
'condition' => array( 'box_border_border!' => '' ),
)
);
$this->add_control(
'box_border_radius',
array(
'label' => __( 'Border Radius', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => array( 'px', '%' ),
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
),
)
);
$this->add_control(
'box_padding',
array(
'label' => __( 'Padding', 'a1-tools' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => array( 'px', 'em' ),
'selectors' => array(
'{{WRAPPER}} .a1tools-info-box' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
),
)
);
$this->add_group_control(
\Elementor\Group_Control_Box_Shadow::get_type(),
array(
'name' => 'box_shadow',
'selector' => '{{WRAPPER}} .a1tools-info-box',
)
);
$this->end_controls_section();
}
// ────────────────────────────────────────────────────────────────
// Render
// ────────────────────────────────────────────────────────────────
protected function render() {
$settings = $this->get_settings_for_display();
$value = $this->get_variable_value();
$enable_link = 'yes' === ( $settings['enable_link'] ?? '' );
$link_url = $enable_link && $value ? $this->build_link_url( $value ) : '';
$underline = $settings['link_underline'] ?? 'none';
$underline_class = 'hover' === $underline ? ' a1tools-underline-hover' : '';
if ( $link_url ) {
echo '';
} else {
echo '';
}
}
protected function content_template() {
$value = $this->get_variable_value();
$config = $this->get_widget_config();
?>
<#
var value = ;
var enableLink = settings.enable_link === 'yes';
var ulClass = settings.link_underline === 'hover' ? ' a1tools-underline-hover' : '';
var tag = ( enableLink && value ) ? 'a' : 'div';
var tagOpen = ( tag === 'a' ) ? '' : '';
var tagClose = ( tag === 'a' ) ? '' : '
';
#>
{{{ tagOpen }}}
<# if ( settings.icon && settings.icon.value ) {
var iconHTML = elementor.helpers.renderIcon( view, settings.icon, { 'aria-hidden': 'true' }, 'i', 'object' );
#>
<# if ( iconHTML && iconHTML.rendered ) { #>{{{ iconHTML.value }}}<# } #>
<# } #>
<# if ( settings.title_text ) { #>
{{ settings.title_text }}
<# } #>
<# if ( value ) { #>
{{ value }}
<# } else { #>
(Not configured)
<# } #>
{{{ tagClose }}}
__( 'Phone', 'a1-tools' ),
'var_key' => 'phone_primary',
'link_prefix' => 'tel:',
'link_desc' => __( 'Wraps the number in a tel: link for click-to-call.', 'a1-tools' ),
'default_icon' => array( 'value' => 'fas fa-phone-alt', 'library' => 'fa-solid' ),
);
}
}
// ═════════════════════════════════════════════════════════════════════
// Email Widget
// ═════════════════════════════════════════════════════════════════════
class A1Tools_Email_Elementor_Widget extends A1Tools_Info_Box_Widget {
public function get_name() {
return 'a1tools_email';
}
public function get_title() {
return __( 'A1 Email', 'a1-tools' );
}
public function get_icon() {
return 'eicon-email-field';
}
public function get_keywords() {
return array( 'email', 'mail', 'contact', 'a1' );
}
protected function get_widget_config() {
return array(
'title' => __( 'Email', 'a1-tools' ),
'var_key' => 'email_primary',
'link_prefix' => 'mailto:',
'link_desc' => __( 'Wraps the address in a mailto: link.', 'a1-tools' ),
'default_icon' => array( 'value' => 'fas fa-envelope', 'library' => 'fa-solid' ),
);
}
}
// ═════════════════════════════════════════════════════════════════════
// Location Widget
// ═════════════════════════════════════════════════════════════════════
class A1Tools_Location_Elementor_Widget extends A1Tools_Info_Box_Widget {
public function get_name() {
return 'a1tools_location';
}
public function get_title() {
return __( 'A1 Location', 'a1-tools' );
}
public function get_icon() {
return 'eicon-map-pin';
}
public function get_keywords() {
return array( 'location', 'address', 'map', 'contact', 'a1' );
}
protected function get_widget_config() {
return array(
'title' => __( 'Location', 'a1-tools' ),
'var_key' => 'full_address',
'link_prefix' => 'map:',
'link_desc' => __( 'Links to Google Maps with the address.', 'a1-tools' ),
'default_icon' => array( 'value' => 'fas fa-map-marker-alt', 'library' => 'fa-solid' ),
);
}
}