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