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-joinnow.php

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

242 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor widget: Magic Club Button
4 *
5 * Created Date: Wednesday September 2nd 2020
6 * Author: Michael Bourne
7 * -----
8 * Last Modified: Thursday, January 9th 2025, 1:51:36 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 /**
26 * Widget class
27 */
28 class C7WP_Elementor_Joinnow extends \Elementor\Widget_Base {
29
30
31 /**
32 * Get widget name.
33 *
34 * Retrieve Commerce7 widget name.
35 *
36 * @since 1.0.0
37 * @access public
38 *
39 * @return string Widget name.
40 */
41 public function get_name() {
42 return 'commerce7-joinnow';
43 }
44
45 /**
46 * Get widget title.
47 *
48 * Retrieve Commerce7 widget title.
49 *
50 * @since 1.0.0
51 * @access public
52 *
53 * @return string Widget title.
54 */
55 public function get_title() {
56 return __( 'Club Join Button', 'wp-commerce7' );
57 }
58
59 /**
60 * Get widget icon.
61 *
62 * Retrieve Commerce7 widget icon.
63 *
64 * @since 1.0.0
65 * @access public
66 *
67 * @return string Widget icon.
68 */
69 public function get_icon() {
70 return 'c7icon-c7sm';
71 }
72
73 /**
74 * Get widget categories.
75 *
76 * Retrieve the list of categories the widget belongs to.
77 *
78 * @since 1.0.0
79 * @access public
80 *
81 * @return array Widget categories.
82 */
83 public function get_categories() {
84 return [ 'commerce7' ];
85 }
86
87 /**
88 * Retrieve widget keywords.
89 *
90 * @since 1.0.0
91 * @access public
92 *
93 * @return array Widget keywords.
94 */
95 public function get_keywords() {
96 return [ 'commerce7', 'join', 'club', 'button' ];
97 }
98
99 /**
100 * Register widget controls.
101 *
102 * Adds different input fields to allow the user to change and customize the widget settings.
103 *
104 * @since 1.0.0
105 * @access protected
106 */
107 protected function register_controls() { // phpcs:ignore
108
109 $this->start_controls_section(
110 'content_section',
111 [
112 'label' => __( 'Settings', 'wp-commerce7' ),
113 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
114 ]
115 );
116
117 $this->add_control(
118 'preview_notice',
119 [
120 'type' => \Elementor\Controls_Manager::RAW_HTML,
121 '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, it does not reflect the club slug you provide nor is it interactive.</div>',
122 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning',
123 ]
124 );
125
126 $this->add_control(
127 'data',
128 [
129 'label' => __( 'Club Slug', 'wp-commerce7' ),
130 'type' => \Elementor\Controls_Manager::TEXT,
131 'placeholder' => __( '12-bottle-reds', 'wp-commerce7' ),
132 ]
133 );
134
135 $this->add_control(
136 'join-text',
137 [
138 'label' => __( 'Join Club Text', 'wp-commerce7' ),
139 'type' => \Elementor\Controls_Manager::TEXT,
140 'placeholder' => __( 'Join Club', 'wp-commerce7' ),
141 ]
142 );
143
144 $this->add_control(
145 'edit-text',
146 [
147 'label' => __( 'Edit Membership Text', 'wp-commerce7' ),
148 'type' => \Elementor\Controls_Manager::TEXT,
149 'placeholder' => __( 'Edit Membership', 'wp-commerce7' ),
150 ]
151 );
152
153 $this->end_controls_section();
154
155 }
156
157 /**
158 * Render Commerce widget output on the frontend.
159 *
160 * Written in PHP and used to generate the final HTML.
161 *
162 * @since 1.0.0
163 * @access protected
164 */
165 protected function render() {
166
167 $settings = $this->get_settings_for_display();
168
169 $data = esc_attr( $settings['data'] );
170
171 // Show preview in Elementor editor, shortcode on frontend
172 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
173 $slugProvided = !empty( $data );
174 $joinText = !empty( $settings['join-text'] ) ? $settings['join-text'] : 'Join Now';
175 $editText = !empty( $settings['edit-text'] ) ? $settings['edit-text'] : 'Edit Membership';
176 ?>
177 <div class="c7-club-join-button-placeholder" data-club-slug="<?php echo esc_attr( $data ); ?>" data-join-text="<?php echo esc_attr( $joinText ); ?>" data-edit-text="<?php echo esc_attr( $editText ); ?>">
178 <?php if ( $slugProvided ) : ?>
179 <a class="c7-btn c7-btn--primary" role="link" tabindex="-1" disabled>
180 <?php echo esc_html( $joinText ); ?>
181 </a>
182 <?php else : ?>
183 <div class="c7-message c7-message--alert-error" role="presentation">
184 <svg aria-hidden="true" focusable="false" role="presentation" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
185 <circle cx="12" cy="12" r="10"></circle>
186 <line x1="12" y1="8" x2="12" y2="12"></line>
187 <line x1="12" y1="16" x2="12.01" y2="16"></line>
188 </svg>
189 Please enter a club slug in the widget settings
190 </div>
191 <?php endif; ?>
192 </div>
193 <?php
194 } else {
195 // Frontend - show actual shortcode
196 $extras = '';
197 if ( ! empty( $settings['join-text'] ) ) {
198 $extras .= ' join-text="' . esc_attr( $settings['join-text'] ) . '"';
199 }
200 if ( ! empty( $settings['edit-text'] ) ) {
201 $extras .= ' edit-text="' . esc_attr( $settings['edit-text'] ) . '"';
202 }
203 echo do_shortcode( '[c7wp type="joinnow" data="' . $data . '"' . $extras . ']' );
204 }
205 }
206
207 /**
208 * Render widget output in the editor.
209 *
210 * Written as a Backbone JavaScript template and used to generate the live preview.
211 *
212 * @since 1.0.0
213 * @access protected
214 */
215 protected function content_template() {
216 ?>
217 <#
218 var slugProvided = settings.data && settings.data.length > 0;
219 var joinText = settings['join-text'] || 'Join Now';
220 var editText = settings['edit-text'] || 'Edit Membership';
221 #>
222 <div class="c7-club-join-button-placeholder" data-club-slug="{{{ settings.data }}}" data-join-text="{{{ joinText }}}" data-edit-text="{{{ editText }}}">
223 <# if (slugProvided) { #>
224 <a class="c7-btn c7-btn--primary" role="link" tabindex="-1" disabled>
225 {{{ joinText }}}
226 </a>
227 <# } else { #>
228 <div class="c7-message c7-message--alert-error" role="presentation">
229 <svg aria-hidden="true" focusable="false" role="presentation" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
230 <circle cx="12" cy="12" r="10"></circle>
231 <line x1="12" y1="8" x2="12" y2="12"></line>
232 <line x1="12" y1="16" x2="12.01" y2="16"></line>
233 </svg>
234 Please enter a club slug in the widget settings
235 </div>
236 <# } #>
237 </div>
238 <?php
239 }
240 public function render_plain_content( $instance = [] ) {}
241
242 }