PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.0.4
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.0.4
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / loader.php

loader.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 3.0.4, at loader.php

410 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimateStoreKit;
4
5 use Elementor\Plugin;
6 use Elementor\Core\Kits\Documents\Kit;
7 use UltimateStoreKit\Manager;
8 use UltimateStoreKit\Admin\Dashboard;
9
10 if (!defined('ABSPATH'))
11 exit; // Exit if accessed directly
12
13 /**
14 * Main class for element pack
15 */
16 class Ultimate_Store_Kit_Loader {
17 /**
18 * @var Ultimate_Store_Kit_Loader
19 */
20 private static $_instance;
21
22 /**
23 * @var Manager
24 */
25 private $_modules_manager;
26
27 private $classes_aliases = [
28 'UltimateStoreKit\Modules\PanelPostsControl\Module' => 'UltimateStoreKit\Modules\QueryControl\Module',
29 'UltimateStoreKit\Modules\PanelPostsControl\Controls\Group_Control_Posts' => 'UltimateStoreKit\Modules\QueryControl\Controls\Group_Control_Posts',
30 'UltimateStoreKit\Modules\PanelPostsControl\Controls\Query' => 'UltimateStoreKit\Modules\QueryControl\Controls\Query',
31 ];
32
33 public $elements_data = [
34 'sections' => [],
35 'columns' => [],
36 'widgets' => [],
37 ];
38
39 /**
40 * @return string
41 * @deprecated
42 *
43 */
44 public function get_version() {
45 return BDTUSK_VER;
46 }
47
48 /**
49 * return active theme
50 */
51 public function get_theme() {
52 return wp_get_theme();
53 }
54
55 /**
56 * Throw error on object clone
57 *
58 * The whole idea of the singleton design pattern is that there is a single
59 * object therefore, we don't want the object to be cloned.
60 *
61 * @return void
62 * @since 1.0.0
63 */
64 public function __clone() {
65 // Cloning instances of the class is forbidden
66 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&#8217; huh?', 'ultimate-store-kit'), '1.6.0');
67 }
68
69 /**
70 * Disable unserializing of the class
71 *
72 * @return void
73 * @since 1.0.0
74 */
75 public function __wakeup() {
76 // Unserializing instances of the class is forbidden
77 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&#8217; huh?', 'ultimate-store-kit'), '1.6.0');
78 }
79
80 /**
81 * @return Plugin
82 */
83
84 public static function elementor() {
85 return Plugin::$instance;
86 }
87
88 /**
89 * @return Ultimate_Store_Kit_Loader
90 */
91 public static function instance() {
92 if (is_null(self::$_instance)) {
93 self::$_instance = new self();
94 }
95
96 do_action('bdthemes_ultimate_store_kit/init');
97 return self::$_instance;
98 }
99
100
101 /**
102 * we loaded module manager + admin php from here
103 * @return [type] [description]
104 */
105 private function _includes() {
106
107 // require_once BDTUSK_ADMIN_PATH . 'module-settings.php';
108 // ========================
109 // Helper for global usec
110 //==========================
111 require(BDTUSK_PATH . 'base/support/helpers.php');
112 //===========================
113 // WISHLIST
114 //===========================
115 require(BDTUSK_INC_PATH . 'wishlist-compare.php');
116 //===========================
117 // WISHLIST
118 //===========================
119
120
121 // all widgets control from here
122 // require BDTUSK_INC_PATH . 'global-controls.php';
123 require BDTUSK_INC_PATH . 'modules-manager.php';
124 // Dynamic Select control
125 // require BDTUSK_INC_PATH . 'controls/group-query/group-control-query.php';
126 require BDTUSK_INC_PATH . 'controls/select-input/dynamic-select-input-module.php';
127 require BDTUSK_INC_PATH . 'controls/select-input/dynamic-select.php';
128
129
130 require_once 'includes/modal/modal-settings.php';
131
132
133 //GLOBAL CONTROLS
134 require_once BDTUSK_PATH . 'traits/global-widget-controls.php';
135 require_once BDTUSK_PATH . 'traits/global-widget-template.php';
136
137 // GRID TEMPLATES
138 require_once BDTUSK_PATH . 'templates/shiny-grid.php';
139 require_once BDTUSK_PATH . 'templates/florence-grid.php';
140 require_once BDTUSK_PATH . 'templates/glossy-grid.php';
141 if (class_exists('woocommerce')) {
142 require_once BDTUSK_PATH . 'includes/builder/loading-builder.php';
143 }
144 }
145
146 /**
147 * Autoloader function for all classes files
148 * @param [type] string
149 * @return [type] [description]
150 */
151 public function autoload($class) {
152 if (0 !== strpos($class, __NAMESPACE__)) {
153 return;
154 }
155
156 $has_class_alias = isset($this->classes_aliases[$class]);
157
158 // Backward Compatibility: Save old class name for set an alias after the new class is loaded
159 if ($has_class_alias) {
160 $class_alias_name = $this->classes_aliases[$class];
161 $class_to_load = $class_alias_name;
162 } else {
163 $class_to_load = $class;
164 }
165
166 if (!class_exists($class_to_load)) {
167 $filename = strtolower(
168 preg_replace(
169 ['/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/'],
170 ['', '$1-$2', '-', DIRECTORY_SEPARATOR],
171 $class_to_load
172 )
173 );
174 $filename = BDTUSK_PATH . $filename . '.php';
175
176 if (is_readable($filename)) {
177 include($filename);
178 }
179 }
180
181 if ($has_class_alias) {
182 class_alias($class_alias_name, $class);
183 }
184 }
185
186 /**
187 * Register all script that need for any specific widget on call basis.
188 * @return [type] [description]
189 */
190 public function register_site_scripts() {
191 wp_register_script('datatables', BDTUSK_ASSETS_URL . 'vendor/js/datatables.js', [], '1.0.0', true);
192 wp_register_script('micromodal', BDTUSK_ASSETS_URL . 'vendor/js/micromodal.js', [], '1.0.0', true);
193 wp_register_script('usk-accordion', BDTUSK_ASSETS_URL . 'vendor/js/accordion.js', [], '1.0.0', true);
194
195 if (ultimate_store_kit_is_widget_enabled('image-hotspot')) {
196 wp_register_script('popper', BDTUSK_ASSETS_URL . 'vendor/js/popper.min.js', ['jquery'], null, true);
197 wp_register_script('tippyjs', BDTUSK_ASSETS_URL . 'vendor/js/tippy.all.min.js', ['jquery'], null, true);
198 }
199 }
200
201 public function register_site_styles() {
202 $direction_suffix = is_rtl() ? '.rtl' : '';
203 wp_register_style('usk-all-styles', BDTUSK_URL . 'assets/css/all-styles' . $direction_suffix . '.css', [], BDTUSK_VER);
204 wp_register_style('usk-font', BDTUSK_URL . 'assets/css/font' . $direction_suffix . '.css', [], BDTUSK_VER);
205
206 if (ultimate_store_kit_is_widget_enabled('image-hotspot')) {
207 wp_register_style('tippy', BDTUSK_URL . 'assets/css/tippy' . $direction_suffix . '.css', [], BDTUSK_VER);
208 }
209 }
210
211 /**
212 * Loading site related style from here.
213 * @return [type] [description]
214 */
215 public function enqueue_site_styles() {
216
217 $direction_suffix = is_rtl() ? '.rtl' : '';
218
219 wp_register_style('usk-site', BDTUSK_ASSETS_URL . 'css/site' . $direction_suffix . '.css', [], BDTUSK_VER);
220 wp_register_style('slick-modal', BDTUSK_ASSETS_URL . 'vendor/css/slickmodal.css', [], BDTUSK_VER);
221 wp_register_style('toolslide-css', BDTUSK_ASSETS_URL . 'vendor/css/toolslide.css', [], BDTUSK_VER);
222
223 wp_enqueue_style('usk-site');
224 wp_enqueue_style('slick-modal');
225 wp_enqueue_style('toolslide-css');
226 }
227
228
229 /**
230 * Loading site related script that needs all time such as uikit.
231 * @return [type] [description]
232 */
233 public function enqueue_site_scripts() {
234
235 wp_register_script('usk-core', BDTUSK_ASSETS_URL . 'js/core.js', ['jquery'], BDTUSK_VER, true); // tooltip file should be separate
236 wp_register_script('usk-site', BDTUSK_ASSETS_URL . 'js/site.js', ['jquery'], BDTUSK_VER, true); // tooltip file should be separate
237 wp_register_script('slick-modal', BDTUSK_ASSETS_URL . 'vendor/js/jquery.slickmodal.js', ['jquery'], BDTUSK_VER, true); // tooltip file should be separate
238 wp_register_script('toolslide-js', BDTUSK_ASSETS_URL . 'vendor/js/toolslide.js', [], BDTUSK_VER, true); // tooltip file should be separate
239
240 wp_enqueue_script('usk-core');
241 // wp_enqueue_script('usk-site');
242 wp_enqueue_script('slick-modal');
243 wp_enqueue_script('toolslide-js');
244
245 wp_localize_script('usk-core', 'ultimate_store_kit_ajax_config', array(
246 'ajaxurl' => admin_url('admin-ajax.php'),
247 ));
248 }
249
250 public function enqueue_editor_scripts() {
251
252 wp_register_script('usk-editor', BDTUSK_ASSETS_URL . 'js/editor.js', ['backbone-marionette', 'elementor-common-modules', 'elementor-editor-modules',], BDTUSK_VER, true);
253
254 wp_enqueue_script('usk-editor');
255
256 $_is_usk_pro_activated = false;
257 if (function_exists('usk_license_validation') && true === usk_license_validation()) {
258 $_is_usk_pro_activated = true;
259 }
260
261 $localize_data = [
262 'pro_installed' => _is_usk_pro_activated(),
263 'pro_license_activated' => $_is_usk_pro_activated,
264 'promotional_widgets' => [],
265 ];
266
267 if (!$_is_usk_pro_activated) {
268 $pro_widget_map = new \UltimateStoreKit\Includes\Pro_Widget_Map();
269 $localize_data['promotional_widgets'] = $pro_widget_map->get_pro_widget_map();
270 }
271
272 wp_localize_script('usk-editor', 'UltimateStoreKitConfigEditor', $localize_data);
273 }
274
275 public function enqueue_admin_scripts() {
276 wp_register_script('usk-admin', BDTUSK_ASSETS_URL . 'js/admin.js', ['jquery'], BDTUSK_VER, true);
277 wp_enqueue_script('usk-admin');
278 }
279
280 public function enqueue_editor_styles() {
281 $direction_suffix = is_rtl() ? '.rtl' : '';
282
283 wp_register_style('usk-editor', BDTUSK_ASSETS_URL . 'css/editor' . $direction_suffix . '.css', [], BDTUSK_VER);
284 wp_register_style('usk-font', BDTUSK_ASSETS_URL . 'css/font' . $direction_suffix . '.css', [], BDTUSK_VER);
285
286 wp_enqueue_style('usk-editor');
287 wp_enqueue_style('usk-font');
288 }
289
290
291
292 public function ultimate_store_kit_init() {
293 $this->_modules_manager = new Manager();
294 $this->ultimate_store_kit_modal_settings_init();
295 do_action('bdthemes_ultimate_store_kit/init');
296 }
297
298 /**
299 * initialize the category
300 * @return [type] [description]
301 */
302 public function ultimate_store_kit_category_register() {
303
304 $elementor = Plugin::$instance;
305
306 $new_category = [
307 'ultimate-store-kit-single' => [
308 'title' => 'Ultimate Store Kit (Single)',
309 'icon' => 'font',
310 ],
311 'ultimate-store-kit-my-account' => [
312 'title' => 'Ultimate Store Kit (Account)',
313 'icon' => 'font',
314 ],
315 'ultimate-store-kit-checkout' => [
316 'title' => 'Ultimate Store Kit (Checkout)',
317 'icon' => 'font',
318 'active' => false,
319 ],
320 'ultimate-store-kit-order-thankyou' => [
321 'title' => 'Ultimate Store Kit (ThankYou)',
322 'icon' => 'font',
323 'active' => false,
324 ],
325 ];
326
327 $existing_categories = $elementor->elements_manager->get_categories();
328 $merged_categories = $new_category + $existing_categories;
329
330 /**
331 * Override categories using reflection (since it's private)
332 */
333 $reflection = new \ReflectionClass($elementor->elements_manager);
334 $property = $reflection->getProperty('categories');
335 // $property->setAccessible(true);
336 $property->setValue($elementor->elements_manager, $merged_categories);
337
338
339 $elementor->elements_manager->add_category(BDTUSK_SLUG, ['title' => BDTUSK_TITLE, 'icon' => 'font']);
340 }
341
342 /**
343 * Setup all hooks here
344 * @return [type] [description]
345 */
346 private function setup_hooks() {
347 add_filter('body_class', [$this, 'add_body_classes']);
348 add_action('elementor/elements/categories_registered', [$this, 'ultimate_store_kit_category_register'], 1, 1);
349 add_action('elementor/init', [$this, 'ultimate_store_kit_init']);
350 add_action('elementor/editor/after_enqueue_styles', [$this, 'enqueue_editor_styles']);
351
352 add_action('wp_enqueue_scripts', [$this, 'register_site_styles'], 99999);
353 add_action('wp_enqueue_scripts', [$this, 'register_site_scripts'], 99999);
354 add_action('wp_enqueue_scripts', [$this, 'enqueue_site_styles'], 99999);
355 add_action('wp_enqueue_scripts', [$this, 'enqueue_site_scripts'], 99999);
356
357 add_action('elementor/editor/after_enqueue_scripts', [$this, 'enqueue_editor_scripts']);
358 add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
359 }
360
361
362 public function add_body_classes($classes) {
363 $single_page_checkout_classes = ['ultimate-store-kit'];
364 return is_array($classes)
365 ? array_merge($classes, $single_page_checkout_classes)
366 : $classes . ' ' . implode(' ', $single_page_checkout_classes);
367 }
368
369 public function ultimate_store_kit_modal_settings_init() {
370 require 'includes/modal/modal-controls.php';
371 add_action('elementor/kit/register_tabs', function (Kit $kit) {
372 $kit->register_tab('ultimate-store-kit-modal', Includes\Settings\Settings_Modal::class);
373 }, 1, 40);
374 }
375
376 public function init() {
377 if (!defined('BDTUSK_CH') && is_admin()) {
378 Dashboard::get_instance();
379 }
380 }
381
382 /**
383 * Ultimate_Store_Kit_Loader constructor.
384 */
385 private function __construct() {
386 // Register class automatically
387 spl_autoload_register([$this, 'autoload']);
388 // Include some backend files
389 $this->_includes();
390
391 // Finally hooked up all things here
392 $this->setup_hooks();
393
394 // Register REST API routes unconditionally (outside is_admin)
395 \UltimateStoreKit\API\Settings::get_instance();
396
397 add_action('init', [$this, 'init']);
398 }
399 }
400
401 if (!defined('BDTUSK_TESTS')) {
402 // In tests we run the instance manually.
403 Ultimate_Store_Kit_Loader::instance();
404 }
405
406 // handy fundtion for push data
407 function ultimate_store_kit_config() {
408 return Ultimate_Store_Kit_Loader::instance();
409 }
410