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