PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / trunk
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster vtrunk
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 / class.php

class.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster trunk, at includes/elementor/class.php

318 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Elementor;
4
5 use Elementor\Plugin as Elementor;
6 use Elementor\Utils as ElementorUtils;
7
8 defined( 'ABSPATH' ) || die();
9
10 /**
11 * SellKit Elementor class.
12 *
13 * @since 1.1.0
14 */
15 class Sellkit_Elementor {
16
17 /**
18 * Class instance.
19 *
20 * @since 1.1.0
21 * @var Sellkit_Elementor
22 */
23 private static $instance = null;
24
25 /**
26 * Modules.
27 *
28 * @since 1.1.0
29 * @var array
30 */
31 public $modules = [];
32
33 /**
34 * Get a class instance.
35 *
36 * @since 1.1.0
37 *
38 * @return Sellkit_Elementor Class
39 */
40 public static function get_instance() {
41 if ( is_null( self::$instance ) ) {
42 self::$instance = new self();
43 }
44
45 return self::$instance;
46 }
47
48 /**
49 * Class constructor.
50 *
51 * @since 1.1.0
52 */
53 public function __construct() {
54 add_action( 'elementor/init', [ $this, 'init' ] );
55 add_action( 'elementor/controls/register', [ $this, 'register_controls' ], 15 );
56 add_action( 'elementor/frontend/after_register_scripts', [ $this, 'frontend_register_scripts' ], 10 );
57 add_action( 'elementor/frontend/after_register_styles', [ $this, 'frontend_register_styles' ], 10 );
58 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_enqueue_styles' ], 10 );
59 add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'frontend_enqueue_scripts' ], 10 );
60 add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'editor_enqueue_styles' ], 10 );
61 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'editor_enqueue_scripts' ], 20 );
62
63 spl_autoload_register( [ $this, 'autoload' ] );
64 remove_theme_support( 'wc-product-gallery-lightbox' );
65 }
66
67 /**
68 * Initialize.
69 *
70 * @since 1.1.0
71 */
72 public function init() {
73 $this->register_modules();
74
75 // Add this category, after basic category.
76 Elementor::$instance->elements_manager->add_category(
77 'sellkit',
78 [
79 'title' => __( 'Sellkit', 'sellkit' ),
80 'icon' => 'fa fa-plug',
81 ],
82 1
83 );
84 }
85
86 /**
87 * Initialize.
88 *
89 * @since 1.1.0
90 */
91 public function register_modules() {
92 // phpcs:disable
93 $modules = [
94 'base/base-widget',
95 'base/base-module',
96 'base/upsell-base-widget',
97 'modules/checkout',
98 'modules/order-cart-details',
99 'modules/order-details',
100 'modules/dynamic-keywords',
101 'modules/product-price',
102 'modules/product-images',
103 'modules/product-title',
104 'modules/product-description',
105 'modules/product-quantity',
106 'modules/accept-reject-button',
107 'modules/optin',
108 ];
109 // phpcs:enable
110
111 foreach ( $modules as $module ) {
112 // Prepare module data.
113 $module_data = explode( '/', $module );
114 $module_path = $module_data[0];
115 $module_name = $module_data[1];
116
117 // Prepare class name.
118 $class_name = str_replace( '-', ' ', $module_name );
119 $class_name = str_replace( ' ', '_', ucwords( $class_name ) );
120 $class_name = "Sellkit_Elementor_{$class_name}";
121 $class_name .= ( 'base' === $module_path ) ? '' : '_Module';
122
123 // Prepare class path.
124 $class_path = "elementor/{$module}";
125 $class_path .= ( 'base' === $module_path ) ? '' : '/module';
126
127 // Require.
128 sellkit()->load_files( [ $class_path ] );
129
130 if ( 'base' === $module_path ) {
131 continue;
132 }
133
134 // Register.
135 if ( $class_name::is_active() ) {
136 $this->modules[ $module_name ] = $class_name::get_instance();
137 }
138 }
139 }
140
141 /**
142 * Register controls with Elementor by sellkit prefix.
143 *
144 * @since 1.5.0
145 * @access public
146 *
147 * @param object $controls_manager The controls manager.
148 */
149 public function register_controls( $controls_manager ) {
150 $controls = [
151 'file_uploader',
152 ];
153
154 // Register controls.
155 foreach ( $controls as $control ) {
156 $class_path = str_replace( '_', '-', $control );
157 $class_path = "elementor/controls/{$class_path}";
158 sellkit()->load_files( [ $class_path ] );
159
160 $class_name = 'Sellkit_Elementor_Controls_' . $control;
161 $controls_manager->register( new $class_name() );
162 }
163 }
164
165 /**
166 * Autoload classes based on namespace.
167 *
168 * @since 1.1.0
169 * @access public
170 *
171 * @param string $class Name of class.
172 */
173 public function autoload( $class ) {
174 // Return if sellkit name space is not set.
175 if ( class_exists( $class ) || 0 !== stripos( $class, __NAMESPACE__ ) ) {
176 return;
177 }
178
179 $filename = str_replace( __NAMESPACE__ . '\\', '', $class );
180 $filename = str_replace( '\\', DIRECTORY_SEPARATOR, $filename );
181 $filename = str_replace( '_', '-', $filename );
182 $filename = sellkit()->plugin_dir() . '/includes/elementor/' . strtolower( $filename ) . '.php';
183
184 // Return if file is not found.
185 if ( ! file_exists( $filename ) ) {
186 return;
187 }
188
189 include $filename;
190 }
191
192 /**
193 * Register front-end scripts
194 *
195 * @since 1.1.0
196 */
197 public function frontend_register_scripts() {
198 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
199
200 wp_register_script(
201 'sellkit-initialize-widgets',
202 sellkit()->plugin_url() . 'assets/dist/js/elementor-init' . $suffix . '.js',
203 [ 'jquery', 'wc-checkout' ],
204 sellkit()->version(),
205 true
206 );
207
208 wp_localize_script( 'sellkit-initialize-widgets', 'sellkit_elementor', $this->get_localize_data() );
209 }
210
211 /**
212 * Get localize data.
213 *
214 * @return array
215 */
216 public function get_localize_data() {
217 $needs_shipping = '';
218
219 if ( function_exists( 'WC' ) ) {
220 $cart = WC()->cart;
221
222 if ( $cart && method_exists( $cart, 'needs_shipping' ) ) {
223 $needs_shipping = $cart->needs_shipping();
224 }
225 }
226
227 return [
228 'nonce' => wp_create_nonce( 'sellkit_elementor' ),
229 'wcNeedShipping' => $needs_shipping,
230 'url' => [
231 'assets' => sellkit()->plugin_url() . 'assets/',
232 ],
233 ];
234 }
235
236 /**
237 * Registers styles.
238 *
239 * Registers all the front-end styles.
240 *
241 * Fires after Elementor front-end styles are registered.
242 *
243 * @since 1.1.0
244 * @access public
245 */
246 public function frontend_register_styles() {
247 $rtl = is_rtl() ? '-rtl' : '';
248 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
249
250 wp_register_style(
251 'sellkit-frontend',
252 sellkit()->plugin_url() . 'assets/dist/css/frontend' . $rtl . $suffix . '.css',
253 [],
254 sellkit()->version()
255 );
256 }
257
258 /**
259 * Enqueue all the front-end styles.
260 *
261 * Fires after Elementor front-end styles are enqueued.
262 *
263 * @since 1.1.0
264 * @access public
265 */
266 public function frontend_enqueue_styles() {
267 wp_enqueue_style( 'sellkit-frontend' );
268 }
269
270 /**
271 * Enqueue all the front-end scripts.
272 *
273 * Fires after Elementor front-end scripts are enqueued.
274 *
275 * @since 1.1.0
276 * @access public
277 */
278 public function frontend_enqueue_scripts() {
279 wp_enqueue_script( 'sellkit-initialize-widgets' );
280 }
281
282 /**
283 * Enqueue all the editor styles.
284 *
285 * Fires after Elementor editor style are enqueued.
286 *
287 * @since 1.1.0
288 * @access public
289 */
290 public function editor_enqueue_styles() {
291 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
292
293 wp_enqueue_style(
294 'sellkit-element-icons',
295 sellkit()->plugin_url() . 'assets/dist/css/editor' . $suffix . '.css',
296 [],
297 sellkit()->version()
298 );
299 }
300
301 /**
302 * Enqueue editor scripts.
303 *
304 * @since 1.7.4
305 */
306 public function editor_enqueue_scripts() {
307 wp_localize_script(
308 'sellkit-editor',
309 'sellkitPromotion',
310 [
311 'activeTheme' => wp_get_theme()->get( 'Name' ),
312 ]
313 );
314 }
315 }
316
317 Sellkit_Elementor::get_instance();
318