PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.7.4
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.7.4
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / elementor / modules / optin / widgets / optin.php

optin.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.7.4, at includes/elementor/modules/optin/widgets/optin.php

158 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || die();
4
5 use Sellkit_Elementor_Optin_Tab_Content as Content_Controls;
6 use Sellkit_Elementor_Optin_Tab_Style as Style_Controls;
7 use Sellkit_Elementor_Optin_Module as Module;
8 use Elementor\Plugin as Elementor;
9
10 class Sellkit_Elementor_Optin_Widget extends Sellkit_Elementor_Base_Widget {
11
12 public function get_name() {
13 return 'sellkit-optin';
14 }
15
16 public function get_title() {
17 return esc_html__( 'Opt-In', 'sellkit' );
18 }
19
20 public function get_icon() {
21 return 'sellkit-element-icon sellkit-optin-icon';
22 }
23
24 protected function register_controls() {
25 new Content_Controls( $this );
26 new Style_Controls( $this );
27 }
28
29 protected function render() {
30 $settings = $this->get_settings_for_display();
31 $fields = $settings['fields'];
32 $has_address = false;
33
34 $attr_messages = '';
35 if ( 'yes' === $settings['messages_custom'] ) {
36 $messages = esc_attr( wp_json_encode( [
37 'error' => esc_attr( $settings['messages_error'] ),
38 'required' => esc_attr( $settings['messages_required'] ),
39 ] ) );
40
41 $attr_messages = "data-messages=\"{$messages}\"";
42 }
43
44 ?>
45 <form
46 novalidate
47 method="POST"
48 name="optin-<?php echo $this->get_id(); ?>"
49 onsubmit="(e)=>e.preventDefault()"
50 class="sellkit-optin sellkit-flex sellkit-flex-wrap sellkit-flex-bottom"
51 <?php echo $attr_messages; ?>>
52 <input type="hidden" name="post_id" value="<?php echo self::get_current_post_id(); ?>" />
53 <input type="hidden" name="form_id" value="<?php echo $this->get_id(); ?>" />
54 <?php
55
56 foreach ( $fields as $field ) {
57 if ( 'address' === $field['type'] ) {
58 $has_address = true;
59 }
60
61 Module::render_field( $this, $field );
62 }
63
64 ?>
65 <div <?php echo $this->button_wrapper_attributes( $settings ); ?>>
66 <button type="submit" class="sellkit-submit-button">
67 <?php Module::render_icon( $settings['submit_button_icon'] ); ?>
68 <div class="sellkit-submit-button-texts">
69 <span class="sellkit-submit-button-text">
70 <?php echo esc_html( $settings['submit_button_text'] ); ?>
71 </span>
72 <span class="sellkit-submit-button-subtext">
73 <?php echo esc_html( $settings['submit_button_subtext'] ); ?>
74 </span>
75 </div>
76 </button>
77 </div>
78 </form>
79 <?php
80
81 if ( $has_address ) {
82 $this->enqueue_google_places_api();
83 }
84 }
85
86 private function button_wrapper_attributes( $settings ) {
87 $this->add_render_attribute(
88 'button-wrapper',
89 'class',
90 'sellkit-field-group sellkit-field-type-submit-button elementor-column elementor-col-' . $settings['submit_button_width']
91 );
92
93 // We add responsive widths as css variables and apply them according to "data-elementor-device-mode" attribute of <body> element.
94 foreach ( Module::get_active_breakpoints() as $device => $value ) {
95 if ( 'desktop' !== $device && empty( $settings[ "submit_button_width_{$device}" ] ) ) {
96 continue;
97 }
98
99 $setting_key = 'desktop' === $device ? 'submit_button_width' : "submit_button_width_{$device}";
100
101 $this->add_render_attribute(
102 'button-wrapper',
103 'style',
104 "--sellkit-field-width-{$device}:" . $settings[ $setting_key ] . '%;'
105 );
106 }
107
108 return $this->get_render_attribute_string( 'button-wrapper' );
109 }
110
111 private static function get_current_post_id() {
112 if ( isset( Elementor::$instance->documents ) && ! empty( Elementor::$instance->documents->get_current() ) ) {
113 return Elementor::$instance->documents->get_current()->get_main_id();
114 }
115
116 return get_the_ID();
117 }
118
119 private function enqueue_google_places_api() {
120 $options = get_option( 'sellkit' );
121
122 /**
123 * Let's make a small migration
124 *
125 * When user updates plugin, once we check if optin is filled, we fill google_api_key field with it.
126 * And we set empty value for it, so next time it will be ignored.
127 *
128 * @todo Should be removed at next version
129 * @since 1.5.7
130 */
131 if (
132 empty( $settings['google_api_key'] ) &&
133 array_key_exists( 'google_api_key_optin', $options ) &&
134 ! empty( $options['google_api_key_optin'] )
135 ) {
136 $options['google_api_key'] = $options['google_api_key_optin'];
137 $options['google_api_key_optin'] = '';
138
139 update_option( 'sellkit', $options );
140 }
141
142 if ( empty( $options ) || empty( $options['google_api_key'] ) ) {
143 return;
144 }
145
146 $api_key = $options['google_api_key'];
147
148 wp_enqueue_script(
149 'sellkit_google_places_api',
150 "https://maps.googleapis.com/maps/api/js?key={$api_key}&libraries=places",
151 [],
152 '1.0.0',
153 false
154 );
155 }
156
157 }
158