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