PluginProbe
Commerce7 for WordPress / trunk
Commerce7 for WordPress vtrunk
1.8.1 1.8.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.3.4 1.3.5 1.4.0 1.4.1 All 37 releases
wp-commerce7 / includes / elementor / elementor-subscribe.php

elementor-subscribe.php in Commerce7 for WordPress trunk, at includes/elementor/elementor-subscribe.php

229 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor widget: Subscribe Form
4 *
5 * Created Date: Wednesday September 2nd 2020
6 * Author: Michael Bourne
7 * -----
8 * Last Modified: Tuesday, September 16th 2025, 10:35:48 pm
9 * Modified By: Michael Bourne
10 * -----
11 * Copyright (c) 2020 URSA6
12 *
13 * @package wp-commerce7
14 * @author Michael Bourne
15 * @license GPL3
16 * @link https://ursa6.com
17 * @since 1.0.8
18 */
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 return;
22 }
23
24 /**
25 * Widget class
26 */
27 class C7WP_Elementor_Subscribe extends \Elementor\Widget_Base {
28
29
30 /**
31 * Get widget name.
32 *
33 * Retrieve Commerce7 widget name.
34 *
35 * @since 1.0.0
36 * @access public
37 *
38 * @return string Widget name.
39 */
40 public function get_name() {
41 return 'commerce7-subscribe';
42 }
43
44 /**
45 * Get widget title.
46 *
47 * Retrieve Commerce7 widget title.
48 *
49 * @since 1.0.0
50 * @access public
51 *
52 * @return string Widget title.
53 */
54 public function get_title() {
55 return __( 'Subscribe Form', 'wp-commerce7' );
56 }
57
58 /**
59 * Get widget icon.
60 *
61 * Retrieve Commerce7 widget icon.
62 *
63 * @since 1.0.0
64 * @access public
65 *
66 * @return string Widget icon.
67 */
68 public function get_icon() {
69 return 'c7icon-c7sm';
70 }
71
72 /**
73 * Get widget categories.
74 *
75 * Retrieve the list of categories the widget belongs to.
76 *
77 * @since 1.0.0
78 * @access public
79 *
80 * @return array Widget categories.
81 */
82 public function get_categories() {
83 return [ 'commerce7' ];
84 }
85
86 /**
87 * Retrieve widget keywords.
88 *
89 * @since 1.0.0
90 * @access public
91 *
92 * @return array Widget keywords.
93 */
94 public function get_keywords() {
95 return [ 'commerce7', 'subscribe', 'email' ];
96 }
97
98 /**
99 * Register widget controls.
100 *
101 * Adds different input fields to allow the user to change and customize the widget settings.
102 *
103 * @since 1.0.0
104 * @access protected
105 */
106 protected function register_controls() { // phpcs:ignore
107
108 $this->start_controls_section(
109 'content_section',
110 [
111 'label' => __( 'Settings', 'wp-commerce7' ),
112 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
113 ]
114 );
115
116 $this->add_control(
117 'preview_notice',
118 [
119 'type' => \Elementor\Controls_Manager::RAW_HTML,
120 'raw' => '<div style="background: #fff3cd; border: 1px solid #ffeaa7; padding: 10px; border-radius: 4px; margin-bottom: 15px;"><strong>Preview Notice:</strong> The preview shown in your editor is for example purposes only.</div>',
121 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning',
122 ]
123 );
124
125 $this->add_control(
126 'data',
127 [
128 'label' => __( 'Show Name Fields?', 'wp-commerce7' ),
129 'type' => \Elementor\Controls_Manager::CHOOSE,
130 'options' => [
131 'false' => [
132 'title' => __( 'No', 'wp-commerce7' ),
133 'icon' => 'fa fa-times',
134 ],
135 'true' => [
136 'title' => __( 'Yes', 'wp-commerce7' ),
137 'icon' => 'fa fa-check',
138 ],
139 ],
140 'default' => 'false',
141 ]
142 );
143
144 $this->end_controls_section();
145
146 }
147
148 /**
149 * Render Commerce widget output on the frontend.
150 *
151 * Written in PHP and used to generate the final HTML.
152 *
153 * @since 1.0.0
154 * @access protected
155 */
156 protected function render() {
157
158 $settings = $this->get_settings_for_display();
159
160 $data = esc_attr( $settings['data'] );
161
162 // Show preview in Elementor editor, shortcode on frontend
163 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
164 $showNameField = ( $data === 'true' );
165 ?>
166 <div class="c7-subscribe-placeholder" data-has-name-field="<?php echo esc_attr( $data ); ?>">
167 <form class="c7-form">
168 <div class="c7-form__group">
169 <?php if ( $showNameField ) : ?>
170 <div class="c7-form__field">
171 <label class="c7-required">First & Last Name</label>
172 <input name="fullName" type="text" tabindex="-1" disabled value="">
173 </div>
174 <?php endif; ?>
175 <div class="c7-form__field">
176 <label class="c7-required">Email</label>
177 <input name="email" type="email" tabindex="-1" disabled value="">
178 </div>
179 <button type="submit" tabindex="-1" disabled class="c7-btn c7-btn--primary">
180 <span>Subscribe</span>
181 </button>
182 </div>
183 </form>
184 </div>
185 <?php
186 } else {
187 // Frontend - show actual shortcode
188 echo do_shortcode( '[c7wp type="subscribe" data="' . $data . '"]' );
189 }
190
191 }
192
193 /**
194 * Render widget output in the editor.
195 *
196 * Written as a Backbone JavaScript template and used to generate the live preview.
197 *
198 * @since 1.0.0
199 * @access protected
200 */
201 protected function content_template() {
202 ?>
203 <#
204 var showNameField = settings.data === 'true';
205 #>
206 <div class="c7-subscribe-placeholder" data-has-name-field="{{{ settings.data }}}">
207 <form class="c7-form">
208 <div class="c7-form__group">
209 <# if (showNameField) { #>
210 <div class="c7-form__field">
211 <label class="c7-required">First & Last Name</label>
212 <input name="fullName" type="text" tabindex="-1" disabled value="">
213 </div>
214 <# } #>
215 <div class="c7-form__field">
216 <label class="c7-required">Email</label>
217 <input name="email" type="email" tabindex="-1" disabled value="">
218 </div>
219 <button type="submit" tabindex="-1" disabled class="c7-btn c7-btn--primary">
220 <span>Subscribe</span>
221 </button>
222 </div>
223 </form>
224 </div>
225 <?php
226 }
227 public function render_plain_content( $instance = [] ) {}
228
229 }