get_site_vars(); $phone = $vars ? ( $vars['phone_primary'] ?? '' ) : ''; $email = $vars ? ( $vars['email_primary'] ?? '' ) : ''; // ── Content ───────────────────────────────────────────────── $this->start_controls_section( 'content_section', array( 'label' => __( 'Content', 'a1-tools' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ) ); $this->add_control( 'cta_action', array( 'label' => __( 'Action', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'phone', 'options' => array( 'phone' => __( 'Call Phone', 'a1-tools' ), 'email' => __( 'Send Email', 'a1-tools' ), 'url' => __( 'Custom URL', 'a1-tools' ), ), ) ); // Phone notice if ( $phone ) { $this->add_control( 'phone_notice', array( 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => 'Phone: ' . esc_html( $phone ), 'content_classes' => 'elementor-panel-alert elementor-panel-alert-success', 'condition' => array( 'cta_action' => 'phone' ), ) ); } else { $this->add_control( 'phone_notice', array( 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => 'No phone configured. Set it in the A1 Tools app.', 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning', 'condition' => array( 'cta_action' => 'phone' ), ) ); } // Email notice if ( $email ) { $this->add_control( 'email_notice', array( 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => 'Email: ' . esc_html( $email ), 'content_classes' => 'elementor-panel-alert elementor-panel-alert-success', 'condition' => array( 'cta_action' => 'email' ), ) ); } else { $this->add_control( 'email_notice', array( 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => 'No email configured. Set it in the A1 Tools app.', 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning', 'condition' => array( 'cta_action' => 'email' ), ) ); } $this->add_control( 'custom_url', array( 'label' => __( 'URL', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::URL, 'placeholder' => __( 'https://example.com/contact-us', 'a1-tools' ), 'default' => array( 'url' => '' ), 'condition' => array( 'cta_action' => 'url' ), ) ); $this->add_control( 'icon', array( 'label' => __( 'Icon', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::ICONS, 'default' => array( 'value' => 'fas fa-phone-alt', 'library' => 'fa-solid' ), ) ); $this->add_control( 'icon_position', array( 'label' => __( 'Icon Position', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'left', 'options' => array( 'left' => __( 'Before Text', 'a1-tools' ), 'right' => __( 'After Text', 'a1-tools' ), ), ) ); $this->add_control( 'use_custom_text', array( 'label' => __( 'Custom Text', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __( 'Yes', 'a1-tools' ), 'label_off' => __( 'No', 'a1-tools' ), 'return_value' => 'yes', 'default' => '', 'description' => __( 'Replace the default text with custom text.', 'a1-tools' ), ) ); $this->add_control( 'custom_text', array( 'label' => __( 'Button Text', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => __( 'Call Now', 'a1-tools' ), 'label_block' => true, 'condition' => array( 'use_custom_text' => 'yes' ), ) ); $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' ), 'justify' => array( 'title' => __( 'Full Width', 'a1-tools' ), 'icon' => 'eicon-text-align-justify' ), ), 'default' => 'left', 'selectors_dictionary' => array( 'left' => 'flex-start', 'center' => 'center', 'right' => 'flex-end', 'justify' => 'stretch', ), 'selectors' => array( '{{WRAPPER}} .a1tools-cta-wrapper' => 'justify-content: {{VALUE}};', ), ) ); $this->add_control( 'full_width', array( 'label' => __( 'Full Width', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => '', 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'width: 100%; justify-content: center;', ), ) ); $this->add_control( 'animation_heading', array( 'label' => __( 'Animation', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::HEADING, 'separator' => 'before', ) ); $this->add_control( 'button_animation', array( 'label' => __( 'Animation', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => '', 'options' => array( '' => __( 'None', 'a1-tools' ), 'pulse' => __( 'Pulse', 'a1-tools' ), 'heartbeat' => __( 'Heartbeat', 'a1-tools' ), 'bounce' => __( 'Bounce', 'a1-tools' ), 'shake' => __( 'Shake', 'a1-tools' ), 'glow' => __( 'Glow', 'a1-tools' ), 'wiggle' => __( 'Wiggle', 'a1-tools' ), 'flash' => __( 'Flash', 'a1-tools' ), 'swing' => __( 'Swing', 'a1-tools' ), 'rubberband' => __( 'Rubber Band', 'a1-tools' ), 'tada' => __( 'Tada', 'a1-tools' ), ), ) ); $this->add_control( 'animation_speed', array( 'label' => __( 'Speed', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'normal', 'options' => array( 'slow' => __( 'Slow', 'a1-tools' ), 'normal' => __( 'Normal', 'a1-tools' ), 'fast' => __( 'Fast', 'a1-tools' ), ), 'condition' => array( 'button_animation!' => '' ), 'selectors_dictionary' => array( 'slow' => '2.5s', 'normal' => '1.5s', 'fast' => '0.8s', ), 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'animation-duration: {{VALUE}};', ), ) ); $this->add_control( 'animation_hover_only', array( 'label' => __( 'Only on Hover', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => '', 'condition' => array( 'button_animation!' => '' ), ) ); $this->add_control( 'glow_color', array( 'label' => __( 'Glow Color', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '', 'condition' => array( 'button_animation' => 'glow' ), 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => '--a1-glow-color: {{VALUE}};', ), ) ); $this->end_controls_section(); // ── Style: Button ─────────────────────────────────────────── $this->start_controls_section( 'button_style_section', array( 'label' => __( 'Button', 'a1-tools' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ) ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array( 'name' => 'button_typography', 'selector' => '{{WRAPPER}} .a1tools-cta-button', ) ); $this->start_controls_tabs( 'button_style_tabs' ); // ── Normal ── $this->start_controls_tab( 'button_normal_tab', array( 'label' => __( 'Normal', 'a1-tools' ) ) ); $this->add_control( 'text_color', array( 'label' => __( 'Text Color', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'color: {{VALUE}};', '{{WRAPPER}} .a1tools-cta-button svg' => 'fill: {{VALUE}};', ), ) ); $this->add_control( 'bg_color', array( 'label' => __( 'Background Color', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#E53935', 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'background-color: {{VALUE}};', ), ) ); $this->add_group_control( \Elementor\Group_Control_Border::get_type(), array( 'name' => 'button_border', 'selector' => '{{WRAPPER}} .a1tools-cta-button', ) ); $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), array( 'name' => 'button_shadow', 'selector' => '{{WRAPPER}} .a1tools-cta-button', ) ); $this->end_controls_tab(); // ── Hover ── $this->start_controls_tab( 'button_hover_tab', array( 'label' => __( 'Hover', 'a1-tools' ) ) ); $this->add_control( 'hover_text_color', array( 'label' => __( 'Text Color', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button:hover' => 'color: {{VALUE}};', '{{WRAPPER}} .a1tools-cta-button:hover svg' => 'fill: {{VALUE}};', ), ) ); $this->add_control( 'hover_bg_color', array( 'label' => __( 'Background Color', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button:hover' => 'background-color: {{VALUE}};', ), ) ); $this->add_control( 'hover_border_color', array( 'label' => __( 'Border Color', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button:hover' => 'border-color: {{VALUE}};', ), 'condition' => array( 'button_border_border!' => '' ), ) ); $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), array( 'name' => 'button_hover_shadow', 'selector' => '{{WRAPPER}} .a1tools-cta-button:hover', ) ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->add_control( 'border_radius', array( 'label' => __( 'Border Radius', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%' ), 'separator' => 'before', 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ) ); $this->add_control( 'button_padding', array( 'label' => __( 'Padding', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', 'em' ), 'default' => array( 'top' => '12', 'right' => '24', 'bottom' => '12', 'left' => '24', 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ) ); $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_size', array( 'label' => __( 'Size', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => array( 'px' ), 'range' => array( 'px' => array( 'min' => 10, 'max' => 60, 'step' => 1 ), ), 'selectors' => array( '{{WRAPPER}} .a1tools-cta-icon' => 'font-size: {{SIZE}}{{UNIT}};', '{{WRAPPER}} .a1tools-cta-icon svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};', ), ) ); $this->add_control( 'icon_spacing', array( 'label' => __( 'Spacing', 'a1-tools' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => array( 'px' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 30, 'step' => 1 ), ), 'default' => array( 'unit' => 'px', 'size' => 8 ), 'selectors' => array( '{{WRAPPER}} .a1tools-cta-button' => 'gap: {{SIZE}}{{UNIT}};', ), ) ); $this->end_controls_section(); } // ──────────────────────────────────────────────────────────────── // Render // ──────────────────────────────────────────────────────────────── protected function render() { $settings = $this->get_settings_for_display(); $vars = $this->get_site_vars(); $action = $settings['cta_action'] ?? 'phone'; $phone = $vars ? ( $vars['phone_primary'] ?? '' ) : ''; $email = $vars ? ( $vars['email_primary'] ?? '' ) : ''; // Determine link URL and default display text. $link_url = ''; $default_text = ''; if ( 'phone' === $action && $phone ) { $link_url = 'tel:' . preg_replace( '/[^0-9+]/', '', $phone ); $default_text = $phone; } elseif ( 'email' === $action && $email ) { $link_url = 'mailto:' . sanitize_email( $email ); $default_text = $email; } elseif ( 'url' === $action && ! empty( $settings['custom_url']['url'] ) ) { $link_url = $settings['custom_url']['url']; $default_text = $link_url; } $use_custom = 'yes' === ( $settings['use_custom_text'] ?? '' ); $text = $use_custom && ! empty( $settings['custom_text'] ) ? $settings['custom_text'] : $default_text; $icon_pos = $settings['icon_position'] ?? 'left'; $has_icon = ! empty( $settings['icon']['value'] ); $icon_html = ''; if ( $has_icon ) { ob_start(); echo ''; $icon_html = ob_get_clean(); } $animation = $settings['button_animation'] ?? ''; $hover_only = 'yes' === ( $settings['animation_hover_only'] ?? '' ); $btn_class = 'a1tools-cta-button'; if ( $animation ) { if ( $hover_only ) { $btn_class .= ' a1tools-anim-hover a1tools-anim-hover--' . $animation; } else { $btn_class .= ' a1tools-anim--' . $animation; } } // Build link attributes. $link_attrs = ''; if ( $link_url ) { $link_attrs = ' href="' . esc_url( $link_url ) . '"'; if ( 'url' === $action && ! empty( $settings['custom_url']['is_external'] ) ) { $link_attrs .= ' target="_blank"'; } if ( 'url' === $action && ! empty( $settings['custom_url']['nofollow'] ) ) { $link_attrs .= ' rel="nofollow"'; } } echo '