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

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

289 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 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/controls_registered', [ $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
62 spl_autoload_register( [ $this, 'autoload' ] );
63 remove_theme_support( 'wc-product-gallery-lightbox' );
64 }
65
66 /**
67 * Initialize.
68 *
69 * @since 1.1.0
70 */
71 public function init() {
72 $this->register_modules();
73
74 // Add this category, after basic category.
75 Elementor::$instance->elements_manager->add_category(
76 'sellkit',
77 [
78 'title' => __( 'Sellkit', 'sellkit' ),
79 'icon' => 'fa fa-plug',
80 ],
81 1
82 );
83 }
84
85 /**
86 * Initialize.
87 *
88 * @since 1.1.0
89 */
90 public function register_modules() {
91 // phpcs:disable
92 $modules = [
93 'base/base-widget',
94 'base/base-module',
95 'base/upsell-base-widget',
96 'modules/checkout',
97 'modules/order-cart-details',
98 'modules/order-details',
99 'modules/dynamic-keywords',
100 'modules/product-price',
101 'modules/product-images',
102 'modules/product-title',
103 'modules/product-description',
104 'modules/product-quantity',
105 'modules/accept-reject-button',
106 'modules/optin',
107 ];
108 // phpcs:enable
109
110 foreach ( $modules as $module ) {
111 // Prepare module data.
112 $module_data = explode( '/', $module );
113 $module_path = $module_data[0];
114 $module_name = $module_data[1];
115
116 // Prepare class name.
117 $class_name = str_replace( '-', ' ', $module_name );
118 $class_name = str_replace( ' ', '_', ucwords( $class_name ) );
119 $class_name = "Sellkit_Elementor_{$class_name}";
120 $class_name .= ( 'base' === $module_path ) ? '' : '_Module';
121
122 // Prepare class path.
123 $class_path = "elementor/{$module}";
124 $class_path .= ( 'base' === $module_path ) ? '' : '/module';
125
126 // Require.
127 sellkit()->load_files( [ $class_path ] );
128
129 if ( 'base' === $module_path ) {
130 continue;
131 }
132
133 // Register.
134 if ( $class_name::is_active() ) {
135 $this->modules[ $module_name ] = $class_name::get_instance();
136 }
137 }
138 }
139
140 /**
141 * Register controls with Elementor by sellkit prefix.
142 *
143 * @since 1.5.0
144 * @access public
145 *
146 * @param object $controls_manager The controls manager.
147 */
148 public function register_controls( $controls_manager ) {
149 $controls = [
150 'file_uploader',
151 ];
152
153 // Register controls.
154 foreach ( $controls as $control ) {
155 $class_path = str_replace( '_', '-', $control );
156 $class_path = "elementor/controls/{$class_path}";
157 sellkit()->load_files( [ $class_path ] );
158
159 $class_name = 'Sellkit_Elementor_Controls_' . $control;
160 $controls_manager->register_control( 'sellkit_' . $control, new $class_name() );
161 }
162 }
163
164 /**
165 * Autoload classes based on namespace.
166 *
167 * @since 1.1.0
168 * @access public
169 *
170 * @param string $class Name of class.
171 */
172 public function autoload( $class ) {
173 // Return if sellkit name space is not set.
174 if ( class_exists( $class ) || 0 !== stripos( $class, __NAMESPACE__ ) ) {
175 return;
176 }
177
178 $filename = str_replace( __NAMESPACE__ . '\\', '', $class );
179 $filename = str_replace( '\\', DIRECTORY_SEPARATOR, $filename );
180 $filename = str_replace( '_', '-', $filename );
181 $filename = sellkit()->plugin_dir() . '/includes/elementor/' . strtolower( $filename ) . '.php';
182
183 // Return if file is not found.
184 if ( ! file_exists( $filename ) ) {
185 return;
186 }
187
188 include $filename;
189 }
190
191 /**
192 * Register front-end scripts
193 *
194 * @since 1.1.0
195 */
196 public function frontend_register_scripts() {
197 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
198
199 wp_register_script(
200 'sellkit-initialize-widgets',
201 sellkit()->plugin_url() . 'assets/dist/js/elementor-init' . $suffix . '.js',
202 [ 'jquery', 'wc-checkout' ],
203 sellkit()->version(),
204 true
205 );
206
207 wp_localize_script( 'sellkit-initialize-widgets', 'sellkit_elementor', $this->get_localize_data() );
208 }
209
210 /**
211 * Get localize data.
212 *
213 * @return array
214 */
215 public function get_localize_data() {
216 return [
217 'nonce' => wp_create_nonce( 'sellkit_elementor' ),
218 'wcNeedShipping' => ( function_exists( 'WC' ) ) ? WC()->cart->needs_shipping() : '',
219 ];
220 }
221
222 /**
223 * Registers styles.
224 *
225 * Registers all the front-end styles.
226 *
227 * Fires after Elementor front-end styles are registered.
228 *
229 * @since 1.1.0
230 * @access public
231 */
232 public function frontend_register_styles() {
233 $rtl = is_rtl() ? '-rtl' : '';
234 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
235
236 wp_register_style(
237 'sellkit-frontend',
238 sellkit()->plugin_url() . 'assets/dist/css/frontend' . $rtl . $suffix . '.css',
239 [],
240 sellkit()->version()
241 );
242 }
243
244 /**
245 * Enqueue all the front-end styles.
246 *
247 * Fires after Elementor front-end styles are enqueued.
248 *
249 * @since 1.1.0
250 * @access public
251 */
252 public function frontend_enqueue_styles() {
253 wp_enqueue_style( 'sellkit-frontend' );
254 }
255
256 /**
257 * Enqueue all the front-end scripts.
258 *
259 * Fires after Elementor front-end scripts are enqueued.
260 *
261 * @since 1.1.0
262 * @access public
263 */
264 public function frontend_enqueue_scripts() {
265 wp_enqueue_script( 'sellkit-initialize-widgets' );
266 }
267
268 /**
269 * Enqueue all the editor styles.
270 *
271 * Fires after Elementor editor style are enqueued.
272 *
273 * @since 1.1.0
274 * @access public
275 */
276 public function editor_enqueue_styles() {
277 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
278
279 wp_enqueue_style(
280 'sellkit-element-icons',
281 sellkit()->plugin_url() . 'assets/dist/css/editor' . $suffix . '.css',
282 [],
283 sellkit()->version()
284 );
285 }
286 }
287
288 Sellkit_Elementor::get_instance();
289