PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 2.1.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v2.1.0
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / plugin.php
shopengine Last commit date
assets 4 years ago base 4 years ago compatibility 4 years ago core 4 years ago languages 4 years ago libs 4 years ago modules 4 years ago traits 5 years ago utils 4 years ago widgets 4 years ago autoloader.php 5 years ago plugin.php 4 years ago readme.txt 4 years ago shopengine.php 4 years ago
plugin.php
430 lines
1 <?php
2
3 namespace ShopEngine;
4
5 use ShopEngine\Compatibility\Conflicts\Manifest as Conflict_Manifest;
6 use ShopEngine\Core\Builders\Base;
7 use ShopEngine\Core\Query_Modifier;
8 use ShopEngine\Core\Template_Cpt;
9 use ShopEngine\Libs\License\License_Route;
10 use ShopEngine\Libs\Updater\Init as Updater;
11 use ShopEngine\Modules\Manifest as Module_Manifest;
12 use ShopEngine\Widgets\Manifest;
13
14 defined('ABSPATH') || exit;
15
16 /**
17 * Plugin final Class.
18 * Handles dynamically loading classes only when needed. Check Elementor Plugin, Woocomerce Plugin Loaded or Install.
19 *
20 * @since 1.0.0
21 */
22 final class Plugin {
23
24 private static $instance;
25
26 /**
27 * __construct function
28 * @since 1.0.0
29 */
30 public function __construct() {
31 // load autoload method
32 Autoloader::run();
33 }
34
35
36 /**
37 * Public function init.
38 * call function for all
39 *
40 * @since 1.0.0
41 */
42 public function init() {
43
44 $error = false;
45
46 // check woocommerce plugin
47 if(!did_action('woocommerce_loaded')) {
48 add_action('admin_notices', [$this, 'missing_woocommerce']);
49
50 $error = true;
51 }
52
53 // Check if Elementor installed and activated.
54 if(!did_action('elementor/loaded')) {
55 add_action('admin_notices', [$this, 'missing_elementor']);
56
57 $error = true;
58 }
59
60 // Check for required Elementor version.
61 if(defined('ELEMENTOR_VERSION') && !version_compare(ELEMENTOR_VERSION, '3.0.0', '>=')) {
62 add_action('admin_notices', [$this, 'failed_elementor_version']);
63
64 $error = true;
65 }
66
67 if($error) {
68
69 return;
70 }
71
72 add_filter("plugin_action_links_shopengine/shopengine.php", function ($links) {
73
74 $custom_links[] = '<a href="'.admin_url('edit.php?post_type=shopengine-template#getting-started').'" target="_blank">' . esc_html__('Settings', 'shopengine') . '</a>';
75
76 foreach ($custom_links as $custom_link):
77 array_unshift($links, $custom_link);
78 endforeach;
79
80 if (!is_plugin_active('shopengine-pro/shopengine-pro.php')) {
81 $links[] = '<a href="https://wpmet.com/plugin/shopengine/pricing/" style="color:#FCB214;font-weight:700" target="_blank">' . esc_html__('Go Pro', 'shopengine') . '</a>';
82 }
83 return $links;
84 });
85
86
87 /**
88 * Routes initialization
89 *
90 */
91 new License_Route();
92
93 /**
94 * Run pro plugin updater here....
95 *
96 */
97 add_action('admin_init', function () {
98 if(class_exists('ShopEngine_Pro')) {
99 new Updater();
100 }
101
102 });
103
104 global $pagenow;
105
106 if(is_admin() && $pagenow == 'post.php' && $_REQUEST['action'] === 'edit') {
107
108 $pid = $_REQUEST['post'];
109 $po = get_post($pid);
110
111 if($po->post_type === Template_Cpt::TYPE) {
112
113 $url = get_admin_url() . 'edit.php?post_type=' . Template_Cpt::TYPE . '#' . Template_Cpt::TYPE;
114
115 wp_safe_redirect($url);
116 exit;
117 }
118 }
119
120 add_action('wp_loaded', function () {
121
122 if(isset($_REQUEST['preview']) && $_REQUEST['preview'] == 'true' && !empty($_REQUEST['preview_id'])) {
123
124 $pid = (int)$_REQUEST['preview_id'];
125
126 $po = get_post($pid);
127
128 if($po->post_type === Template_Cpt::TYPE) {
129
130 $template = \ShopEngine\Core\Builders\Templates::get_registered_template_data($pid);
131
132 if(empty($template) || !isset($template['url'])) {
133 return;
134 }
135
136 $param = [
137 'shopengine_template_id' => $pid,
138 'preview_nonce' => wp_create_nonce('template_preview_' . $pid),
139 'change_template' => '1',
140 ];
141
142 $url = \ShopEngine\Utils\Helper::add_to_url($template['url'], $param);
143
144 wp_safe_redirect($url);
145 exit;
146 }
147 }
148 });
149
150
151 // avoid themes for loading woocommerce functions
152 $avoid_themes = ['avada'];
153
154 if( !in_array( strtolower(wp_get_theme()), $avoid_themes) ) {
155 /**
156 * Ensuring woocommerce functions are loaded before theme is modifying those
157 *
158 */
159 require_once WC_ABSPATH . '/includes/wc-template-functions.php';
160 }
161
162 // Load custom elementor controls
163 new \ShopEngine\Core\Elementor_Controls\Init();
164
165 //Loading the scripts and styles
166 add_action('wp_enqueue_scripts', [$this, 'js_css_public']);
167 add_action('elementor/editor/after_enqueue_styles', [$this, 'js_css_elementor']);
168
169 //woocommece theme support
170 if(!current_theme_supports('woocommerce')) {
171 add_theme_support('woocommerce');
172 add_theme_support('wc-product-gallery-zoom');
173 add_theme_support('wc-product-gallery-lightbox');
174 add_theme_support('wc-product-gallery-slider');
175 }
176
177
178 #Registering new post-type & etc
179 Base::instance()->init();
180
181 \ShopEngine\Core\Settings\Base::instance()->init();
182
183 new Libs\Select_Api\Base();
184
185 (new Module_Manifest())->init();
186
187 // working get instance of elementor widget
188 (new Manifest())->init();
189
190 Query_Modifier::instance()->init();
191
192 (new Conflict_Manifest())->init();
193
194 // view count
195 add_action('get_header', [$this, 'shopengine_track_product_views']);
196
197 // database migrations
198 // (new \ShopEngine\Compatibility\Migrations\Migration())->init();
199 (new \ShopEngine\Compatibility\Migrations\Temp_Migration())->init();
200
201
202 // call service providers
203
204 $service_providers = include \ShopEngine::plugin_dir().'core/service-provider-manager.php';
205 $method = 'init';
206 foreach( $service_providers as $service_provider ){
207
208 if(class_exists($service_provider) && method_exists($service_provider, $method)) {
209 $instance = new $service_provider();
210 $instance->$method();
211 }
212
213 }
214
215
216
217 add_filter('script_loader_tag', [$this, 'filter_load_type'], 99, 3);
218 }
219
220
221 // add async and defer attributes to enqueued scripts
222 public function filter_load_type($tag, $handle, $src) {
223
224 if(strpos($handle, '-async') !== false) {
225 $tag = str_replace(' src', ' async="async" src', $tag);
226 }
227
228 if(strpos($handle, '-defer') !== false) {
229 $tag = str_replace('<script ', '<script defer ', $tag);
230 }
231
232 return $tag;
233 }
234
235 /**
236 * Public function shopengine_track_product_views
237 * Adding Product Views Count Meta
238 */
239 public function shopengine_track_product_views() {
240
241 if(class_exists('WooCommerce') && !is_product()) {
242 return;
243 }
244
245 $product_id = get_the_id();
246
247 $cookie_name = "shopengine_recent_viewed_product";
248
249 if(isset($_COOKIE[$cookie_name])) {
250
251 $cookie_ids = $_COOKIE[$cookie_name];
252 $product_ids = explode(',', $cookie_ids);
253
254 if(!is_array($product_ids)) {
255 $product_ids = [$product_ids];
256 }
257
258 $product_ids = array_combine($product_ids, $product_ids);
259 unset($product_ids[$product_id]);
260 $product_ids[] = $product_id;
261
262 $cookie_value = implode(',', $product_ids);
263
264 } else {
265 $cookie_value = $product_id;
266 }
267
268 setcookie($cookie_name, $cookie_value, strtotime('+30 days'), '/' );
269
270 $count_key = 'shopengine_product_views_count';
271 $count = get_post_meta($product_id, $count_key, true);
272
273 if($count == '') {
274 $count = 1;
275 delete_post_meta($product_id, $count_key);
276 add_post_meta($product_id, $count_key, '1');
277 } else {
278 $count++;
279 update_post_meta($product_id, $count_key, $count);
280 }
281 }
282
283 /**
284 * Public function js_css_public .
285 * Include public function
286 *
287 * @since 1.0.0
288 */
289 public function js_css_public() {
290 wp_enqueue_style('shopengine-icon', \ShopEngine::plugin_url() . 'assets/css/shopengine-icon.css', false, \ShopEngine::version());
291 wp_enqueue_style('shopengine-simple-scrollbar-css', \ShopEngine::plugin_url() . 'assets/css/simple-scrollbar.css', false, \ShopEngine::version());
292 wp_enqueue_style('shopengine-public-css', \ShopEngine::plugin_url() . 'assets/css/public-style.css', false, \ShopEngine::version());
293
294 // Modal Stylesheet
295 wp_register_style('shopengine-modal-styles', \ShopEngine::plugin_url() . 'assets/css/shopengine-modal.css', false, \ShopEngine::version());
296
297 // Modal Script
298 wp_register_script('shopengine-modal-script', \ShopEngine::plugin_url() . 'assets/js/shopengine-modal.js', ['jquery'], \ShopEngine::version(), true);
299
300 wp_enqueue_script('shopengine-simple-scrollbar.js-js', \ShopEngine::plugin_url() . 'assets/js/simple-scrollbar.js', [], \ShopEngine::version(), true);
301 wp_enqueue_script('shopengine-filter-js', \ShopEngine::plugin_url() . 'assets/js/filter.js', [], \ShopEngine::version(), true);
302 wp_enqueue_script('shopengine-js', \ShopEngine::plugin_url() . 'assets/js/public.js', [], \ShopEngine::version(), true);
303
304
305 wp_localize_script('shopengine-js', 'shopEngineApiSettings', [
306 'resturl' => get_rest_url(),
307 'rest_nonce' => wp_create_nonce('wp_rest'),
308 ]);
309
310
311 /**
312 * Registering libs css/js
313 *
314 */
315
316 wp_register_style(
317 'lib-sqv-css',
318 \ShopEngine::plugin_url() . '/assets/sqv/smart-quick-view.css',
319 [],
320 \ShopEngine::version()
321 );
322
323 wp_register_script(
324 'lib-sqv-js',
325 \ShopEngine::plugin_url() . 'assets/sqv/smart-quick-view.js',
326 ['jquery', 'wc-single-product'],
327 \ShopEngine::version(),
328 true
329 );
330 }
331
332 public function js_css_elementor() {
333 wp_enqueue_style('shopnegine-panel-icon', \ShopEngine::plugin_url() . 'assets/css/shopengine-icon.css', false, \ShopEngine::version());
334
335 if('shopengine-template' === get_post_type()):
336 wp_enqueue_style('shopnegine-editor-css', \ShopEngine::plugin_url() . 'assets/css/editor.css', false, \ShopEngine::version());
337 endif;
338 }
339
340
341 public function missing_woocommerce() {
342
343 if(isset($_GET['activate'])) {
344 unset($_GET['activate']);
345 }
346
347 if(file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php')) {
348
349 $btn['label'] = esc_html__('Activate WooCommerce', 'shopengine');
350 $btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=all&paged=1', 'activate-plugin_woocommerce/woocommerce.php');
351
352 } else {
353
354 $btn['label'] = esc_html__('Install WooCommerce', 'shopengine');
355 $btn['url'] = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=woocommerce'), 'install-plugin_woocommerce');
356 }
357
358 Utils\Notice::push(
359 [
360 'id' => 'missing-woo',
361 'type' => 'error',
362 'dismissible' => true,
363 'btn' => $btn,
364 'message' => sprintf(esc_html__('ShopEngine requires woocommerce Plugin, which is currently NOT RUNNING.', 'shopengine'), '4.1.0'),
365 ]
366 );
367 }
368
369
370 public function missing_elementor() {
371
372 if(isset($_GET['activate'])) {
373 unset($_GET['activate']);
374 }
375
376 if(file_exists(WP_PLUGIN_DIR . '/elementor/elementor.php')) {
377
378 $btn['label'] = esc_html__('Activate Elementor', 'shopengine');
379 $btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=elementor/elementor.php&plugin_status=all&paged=1', 'activate-plugin_elementor/elementor.php');
380
381 } else {
382
383 $btn['label'] = esc_html__('Install Elementor', 'shopengine');
384 $btn['url'] = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=elementor'), 'install-plugin_elementor');
385 }
386
387 Utils\Notice::push(
388 [
389 'id' => 'missing-elementor',
390 'type' => 'error',
391 'dismissible' => true,
392 'btn' => $btn,
393 'message' => sprintf(esc_html__('ShopEngine requires Elementor version %1$s+, which is currently NOT RUNNING.', 'shopengine'), '3.0.0'),
394 ]
395 );
396 }
397
398
399 public function failed_elementor_version() {
400
401 $btn['label'] = esc_html__('Update Elementor', 'shopengine');
402 $btn['url'] = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=elementor'), 'upgrade-plugin_elementor');
403
404 Utils\Notice::push(
405 [
406 'id' => 'unsupported-elementor-version',
407 'type' => 'error',
408 'dismissible' => true,
409 'btn' => $btn,
410 'message' => sprintf(esc_html__('ShopEngine requires Elementor version %1$s+, which is currently NOT RUNNING.', 'shopengine'), '3.0.0'),
411 ]
412 );
413 }
414
415
416 public function flush_rewrites() {
417 $form_cpt = new Core\Builders\Cpt();
418 $form_cpt->flush_rewrites();
419 }
420
421
422 public static function instance() {
423 if(!self::$instance) {
424 self::$instance = new self();
425 }
426
427 return self::$instance;
428 }
429 }
430