| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | use ShopEngine\Compatibility\Conflicts\Manifest as Conflict_Manifest; |
| 6 | 6 | use ShopEngine\Core\Builders\Base; |
| 7 | 7 | use ShopEngine\Core\Query_Modifier; |
| 8 | -use ShopEngine\Core\Template_Cpt; | |
| 9 | 8 | use ShopEngine\Libs\License\License_Route; |
| 10 | 9 | use ShopEngine\Libs\Updater\Init as Updater; |
| 11 | 10 | use ShopEngine\Modules\Manifest as Module_Manifest; |
| 12 | 11 | use ShopEngine\Widgets\Manifest; |
| @@ -49,48 +48,28 @@ | ||
| 49 | 48 | |
| 50 | 49 | $error = true; |
| 51 | 50 | } |
| 52 | 51 | |
| 53 | - $check_elementor_version = false; | |
| 54 | - | |
| 55 | 52 | // Check if Elementor installed and activated. |
| 56 | - if(!did_action('elementor/loaded')) { | |
| 53 | + if(!did_action('elementor/loaded')) { | |
| 54 | + add_action('admin_notices', [$this, 'missing_elementor']); | |
| 57 | 55 | |
| 58 | - if(!did_action('shopengine-gutenberg-addon/before_loaded')) { | |
| 56 | + $error = true; | |
| 57 | + } | |
| 59 | 58 | |
| 60 | - add_action('admin_notices', [$this, 'missing_elementor']); | |
| 61 | - | |
| 62 | - $error = true; | |
| 63 | - } | |
| 64 | - } | |
| 65 | - | |
| 66 | 59 | // Check for required Elementor version. |
| 67 | - if(did_action('elementor/loaded') && defined('ELEMENTOR_VERSION') && !version_compare(ELEMENTOR_VERSION, '3.0.0', '>=')) { | |
| 60 | + if(defined('ELEMENTOR_VERSION') && !version_compare(ELEMENTOR_VERSION, '3.0.0', '>=')) { | |
| 61 | + add_action('admin_notices', [$this, 'failed_elementor_version']); | |
| 68 | 62 | |
| 69 | - add_action('admin_notices', [$this, 'failed_elementor_version']); | |
| 63 | + $error = true; | |
| 64 | + } | |
| 70 | 65 | |
| 71 | - $error = true; | |
| 72 | - } | |
| 66 | + if($error) { | |
| 73 | 67 | |
| 74 | - if($error) { | |
| 75 | 68 | return; |
| 76 | 69 | } |
| 77 | 70 | |
| 78 | - add_filter("plugin_action_links_shopengine/shopengine.php", function ($links) { | |
| 79 | 71 | |
| 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 | 72 | /** |
| 94 | 73 | * Routes initialization |
| 95 | 74 | * |
| 96 | 75 | */ |
| @@ -106,61 +85,21 @@ | ||
| 106 | 85 | } |
| 107 | 86 | }); |
| 108 | 87 | |
| 109 | 88 | |
| 110 | - add_action('wp_loaded', function () { | |
| 89 | + /** | |
| 90 | + * Ensuring woocommerce functions are loaded before theme is modifying those | |
| 91 | + * | |
| 92 | + */ | |
| 93 | + require_once WC_ABSPATH . '/includes/wc-template-functions.php'; | |
| 111 | 94 | |
| 112 | - if(isset($_REQUEST['preview']) && $_REQUEST['preview'] == 'true' && !empty($_REQUEST['preview_id'])) { | |
| 113 | 95 | |
| 114 | - $pid = (int)$_REQUEST['preview_id']; | |
| 96 | + // Load custom elementor controls | |
| 97 | + new \ShopEngine\Core\Elementor_Controls\Init(); | |
| 115 | 98 | |
| 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', 'avada child']; | |
| 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 | |
| 99 | + //Loading the scripts and styles | |
| 162 | 100 | add_action('wp_enqueue_scripts', [$this, 'js_css_public']); |
| 101 | + add_action('elementor/editor/after_enqueue_styles', [$this, 'js_css_elementor']); | |
| 163 | 102 | |
| 164 | 103 | //woocommece theme support |
| 165 | 104 | if(!current_theme_supports('woocommerce')) { |
| 166 | 105 | add_theme_support('woocommerce'); |
| @@ -174,98 +113,38 @@ | ||
| 174 | 113 | Base::instance()->init(); |
| 175 | 114 | |
| 176 | 115 | \ShopEngine\Core\Settings\Base::instance()->init(); |
| 177 | 116 | |
| 178 | - new Libs\Select_Api\Base(); | |
| 117 | + (new Module_Manifest)->init(); | |
| 179 | 118 | |
| 180 | - (new Module_Manifest())->init(); | |
| 181 | - | |
| 182 | 119 | // working get instance of elementor widget |
| 183 | - (new Manifest())->init(); | |
| 120 | + (new Manifest)->init(); | |
| 184 | 121 | |
| 185 | 122 | Query_Modifier::instance()->init(); |
| 186 | 123 | |
| 187 | - (new Conflict_Manifest())->init(); | |
| 124 | + (new Conflict_Manifest)->init(); | |
| 188 | 125 | |
| 189 | 126 | // view count |
| 190 | - add_action('get_header', [$this, 'shopengine_track_product_views']); | |
| 127 | + add_action('wp_head', [$this, 'shopengine_track_product_views']); | |
| 191 | 128 | |
| 192 | 129 | // database migrations |
| 193 | 130 | // (new \ShopEngine\Compatibility\Migrations\Migration())->init(); |
| 194 | 131 | (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 | 132 | } |
| 214 | 133 | |
| 215 | 134 | |
| 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 | 135 | /** |
| 231 | 136 | * Public function shopengine_track_product_views |
| 232 | 137 | * Adding Product Views Count Meta |
| 233 | 138 | */ |
| 234 | - public function shopengine_track_product_views() { | |
| 235 | - | |
| 139 | + public function shopengine_track_product_views($product_id) { | |
| 236 | 140 | if(class_exists('WooCommerce') && !is_product()) { |
| 237 | 141 | return; |
| 238 | 142 | } |
| 239 | - | |
| 240 | 143 | $product_id = get_the_id(); |
| 241 | 144 | |
| 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 | 145 | $count_key = 'shopengine_product_views_count'; |
| 266 | 146 | $count = get_post_meta($product_id, $count_key, true); |
| 267 | - | |
| 268 | 147 | if($count == '') { |
| 269 | 148 | $count = 1; |
| 270 | 149 | delete_post_meta($product_id, $count_key); |
| 271 | 150 | add_post_meta($product_id, $count_key, '1'); |
| @@ -286,12 +165,12 @@ | ||
| 286 | 165 | wp_enqueue_style('shopengine-simple-scrollbar-css', \ShopEngine::plugin_url() . 'assets/css/simple-scrollbar.css', false, \ShopEngine::version()); |
| 287 | 166 | wp_enqueue_style('shopengine-public-css', \ShopEngine::plugin_url() . 'assets/css/public-style.css', false, \ShopEngine::version()); |
| 288 | 167 | |
| 289 | 168 | // Modal Stylesheet |
| 290 | - wp_register_style('shopengine-modal-styles', \ShopEngine::plugin_url() . 'assets/css/shopengine-modal.css', false, \ShopEngine::version()); | |
| 169 | + wp_register_style( 'shopengine-modal-styles', \ShopEngine::plugin_url() . 'assets/css/shopengine-modal.css', false, \ShopEngine::version() ); | |
| 291 | 170 | |
| 292 | 171 | // Modal Script |
| 293 | - wp_register_script('shopengine-modal-script', \ShopEngine::plugin_url() . 'assets/js/shopengine-modal.js', ['jquery'], \ShopEngine::version(), true); | |
| 172 | + wp_register_script( 'shopengine-modal-script', \ShopEngine::plugin_url() . 'assets/js/shopengine-modal.js', ['jquery'], \ShopEngine::version(), true ); | |
| 294 | 173 | |
| 295 | 174 | wp_enqueue_script('shopengine-simple-scrollbar.js-js', \ShopEngine::plugin_url() . 'assets/js/simple-scrollbar.js', [], \ShopEngine::version(), true); |
| 296 | 175 | wp_enqueue_script('shopengine-filter-js', \ShopEngine::plugin_url() . 'assets/js/filter.js', [], \ShopEngine::version(), true); |
| 297 | 176 | wp_enqueue_script('shopengine-js', \ShopEngine::plugin_url() . 'assets/js/public.js', [], \ShopEngine::version(), true); |
| @@ -420,5 +299,6 @@ | ||
| 420 | 299 | } |
| 421 | 300 | |
| 422 | 301 | return self::$instance; |
| 423 | 302 | } |
| 303 | + | |
| 424 | 304 | } |