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