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

308 lines 6.9 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 return [
218 'nonce' => wp_create_nonce( 'sellkit_elementor' ),
219 'wcNeedShipping' => ( function_exists( 'WC' ) ) ? WC()->cart->needs_shipping() : '',
220 'url' => [
221 'assets' => sellkit()->plugin_url() . 'assets/',
222 ],
223 ];
224 }
225
226 /**
227 * Registers styles.
228 *
229 * Registers all the front-end styles.
230 *
231 * Fires after Elementor front-end styles are registered.
232 *
233 * @since 1.1.0
234 * @access public
235 */
236 public function frontend_register_styles() {
237 $rtl = is_rtl() ? '-rtl' : '';
238 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
239
240 wp_register_style(
241 'sellkit-frontend',
242 sellkit()->plugin_url() . 'assets/dist/css/frontend' . $rtl . $suffix . '.css',
243 [],
244 sellkit()->version()
245 );
246 }
247
248 /**
249 * Enqueue all the front-end styles.
250 *
251 * Fires after Elementor front-end styles are enqueued.
252 *
253 * @since 1.1.0
254 * @access public
255 */
256 public function frontend_enqueue_styles() {
257 wp_enqueue_style( 'sellkit-frontend' );
258 }
259
260 /**
261 * Enqueue all the front-end scripts.
262 *
263 * Fires after Elementor front-end scripts are enqueued.
264 *
265 * @since 1.1.0
266 * @access public
267 */
268 public function frontend_enqueue_scripts() {
269 wp_enqueue_script( 'sellkit-initialize-widgets' );
270 }
271
272 /**
273 * Enqueue all the editor styles.
274 *
275 * Fires after Elementor editor style are enqueued.
276 *
277 * @since 1.1.0
278 * @access public
279 */
280 public function editor_enqueue_styles() {
281 $suffix = ElementorUtils::is_script_debug() ? '' : '.min';
282
283 wp_enqueue_style(
284 'sellkit-element-icons',
285 sellkit()->plugin_url() . 'assets/dist/css/editor' . $suffix . '.css',
286 [],
287 sellkit()->version()
288 );
289 }
290
291 /**
292 * Enqueue editor scripts.
293 *
294 * @since NEXT
295 */
296 public function editor_enqueue_scripts() {
297 wp_localize_script(
298 'sellkit-editor',
299 'sellkitPromotion',
300 [
301 'activeTheme' => wp_get_theme()->get( 'Name' ),
302 ]
303 );
304 }
305 }
306
307 Sellkit_Elementor::get_instance();
308