| @@ -1,15 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ShopEngine; |
| 4 | 4 | |
| 5 | -use ShopEngine\Compatibility\Conflicts\Manifest as Conflict_Manifest; | |
| 6 | 5 | use ShopEngine\Core\Builders\Base; |
| 7 | 6 | 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 | 7 | use ShopEngine\Modules\Manifest as Module_Manifest; |
| 8 | +use ShopEngine\Compatibility\Conflicts\Manifest as Conflict_Manifest; | |
| 12 | 9 | use ShopEngine\Widgets\Manifest; |
| 13 | 10 | |
| 14 | 11 | defined('ABSPATH') || exit; |
| 15 | 12 | |
| @@ -27,9 +24,9 @@ | ||
| 27 | 24 | * __construct function |
| 28 | 25 | * @since 1.0.0 |
| 29 | 26 | */ |
| 30 | 27 | public function __construct() { |
| 31 | - // load autoload method | |
| 28 | + // load autoload method | |
| 32 | 29 | Autoloader::run(); |
| 33 | 30 | } |
| 34 | 31 | |
| 35 | 32 | |
| @@ -44,130 +41,53 @@ | ||
| 44 | 41 | $error = false; |
| 45 | 42 | |
| 46 | 43 | // check woocommerce plugin |
| 47 | 44 | if(!did_action('woocommerce_loaded')) { |
| 48 | - add_action('admin_notices', [$this, 'missing_woocommerce']); | |
| 45 | + add_action('admin_notices', array($this, 'missing_woocommerce')); | |
| 49 | 46 | |
| 50 | 47 | $error = true; |
| 51 | 48 | } |
| 52 | 49 | |
| 53 | - $check_elementor_version = false; | |
| 54 | - | |
| 55 | 50 | // Check if Elementor installed and activated. |
| 56 | - if(!did_action('elementor/loaded')) { | |
| 51 | + if(!did_action('elementor/loaded')) { | |
| 52 | + add_action('admin_notices', array($this, 'missing_elementor')); | |
| 57 | 53 | |
| 58 | - if(!did_action('shopengine-gutenberg-addon/before_loaded')) { | |
| 54 | + $error = true; | |
| 55 | + } | |
| 59 | 56 | |
| 60 | - add_action('admin_notices', [$this, 'missing_elementor']); | |
| 61 | - | |
| 62 | - $error = true; | |
| 63 | - } | |
| 64 | - } | |
| 65 | - | |
| 66 | 57 | // Check for required Elementor version. |
| 67 | - if(did_action('elementor/loaded') && defined('ELEMENTOR_VERSION') && !version_compare(ELEMENTOR_VERSION, '3.0.0', '>=')) { | |
| 58 | + if(defined('ELEMENTOR_VERSION') && !version_compare(ELEMENTOR_VERSION, '3.0.0', '>=')) { | |
| 59 | + add_action('admin_notices', array($this, 'failed_elementor_version')); | |
| 68 | 60 | |
| 69 | - add_action('admin_notices', [$this, 'failed_elementor_version']); | |
| 61 | + $error = true; | |
| 62 | + } | |
| 70 | 63 | |
| 71 | - $error = true; | |
| 72 | - } | |
| 64 | + if($error) { | |
| 73 | 65 | |
| 74 | - if($error) { | |
| 75 | 66 | return; |
| 76 | 67 | } |
| 77 | 68 | |
| 78 | - add_filter("plugin_action_links_shopengine/shopengine.php", function ($links) { | |
| 79 | 69 | |
| 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 | 70 | /** |
| 94 | - * Routes initialization | |
| 71 | + * Ensuring woocommerce functions are loaded before theme is modifying those | |
| 95 | 72 | * |
| 96 | 73 | */ |
| 97 | - new License_Route(); | |
| 74 | + require_once WC_ABSPATH . '/includes/wc-template-functions.php'; | |
| 98 | 75 | |
| 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 | 76 | |
| 77 | + // Load custom elementor controls | |
| 78 | + new \ShopEngine\Core\Elementor_Controls\Init(); | |
| 109 | 79 | |
| 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', '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 | |
| 80 | + //Loading the scripts and styles | |
| 162 | 81 | add_action('wp_enqueue_scripts', [$this, 'js_css_public']); |
| 82 | + add_action( 'elementor/editor/after_enqueue_styles', [$this, 'js_css_elementor'] ); | |
| 163 | 83 | |
| 164 | 84 | //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'); | |
| 85 | + if( !current_theme_supports('woocommerce') ) { | |
| 86 | + add_theme_support( 'woocommerce' ); | |
| 87 | + add_theme_support( 'wc-product-gallery-zoom' ); | |
| 88 | + add_theme_support( 'wc-product-gallery-lightbox' ); | |
| 89 | + add_theme_support( 'wc-product-gallery-slider' ); | |
| 170 | 90 | } |
| 171 | 91 | |
| 172 | 92 | |
| 173 | 93 | #Registering new post-type & etc |
| @@ -174,103 +94,40 @@ | ||
| 174 | 94 | Base::instance()->init(); |
| 175 | 95 | |
| 176 | 96 | \ShopEngine\Core\Settings\Base::instance()->init(); |
| 177 | 97 | |
| 178 | - new Libs\Select_Api\Base(); | |
| 98 | + (new Module_Manifest)->init(); | |
| 179 | 99 | |
| 180 | - (new Module_Manifest())->init(); | |
| 181 | - | |
| 182 | 100 | // working get instance of elementor widget |
| 183 | - (new Manifest())->init(); | |
| 101 | + (new Manifest)->init(); | |
| 184 | 102 | |
| 185 | 103 | Query_Modifier::instance()->init(); |
| 186 | 104 | |
| 187 | - (new Conflict_Manifest())->init(); | |
| 105 | + (new Conflict_Manifest)->init(); | |
| 188 | 106 | |
| 189 | 107 | // view count |
| 190 | - add_action('get_header', [$this, 'shopengine_track_product_views']); | |
| 108 | + add_action( 'wp_head', [$this, 'shopengine_track_product_views']); | |
| 191 | 109 | |
| 192 | 110 | // database migrations |
| 193 | 111 | // (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 | 112 | } |
| 113 | + | |
| 214 | 114 | |
| 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 | 115 | /** |
| 231 | 116 | * Public function shopengine_track_product_views |
| 232 | 117 | * Adding Product Views Count Meta |
| 233 | 118 | */ |
| 234 | - public function shopengine_track_product_views() { | |
| 235 | - | |
| 236 | - if(class_exists('WooCommerce') && !is_product()) { | |
| 237 | - return; | |
| 238 | - } | |
| 239 | - | |
| 119 | + public function shopengine_track_product_views($product_id){ | |
| 120 | + if ( class_exists('WooCommerce') && !is_product() ) return; | |
| 240 | 121 | $product_id = get_the_id(); |
| 241 | 122 | |
| 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 | 123 | $count_key = 'shopengine_product_views_count'; |
| 266 | - $count = get_post_meta($product_id, $count_key, true); | |
| 267 | - | |
| 268 | - if($count == '') { | |
| 124 | + $count = get_post_meta($product_id, $count_key, true); | |
| 125 | + if($count==''){ | |
| 269 | 126 | $count = 1; |
| 270 | 127 | delete_post_meta($product_id, $count_key); |
| 271 | 128 | add_post_meta($product_id, $count_key, '1'); |
| 272 | - } else { | |
| 129 | + }else{ | |
| 273 | 130 | $count++; |
| 274 | 131 | update_post_meta($product_id, $count_key, $count); |
| 275 | 132 | } |
| 276 | 133 | } |
| @@ -284,51 +141,22 @@ | ||
| 284 | 141 | public function js_css_public() { |
| 285 | 142 | wp_enqueue_style('shopengine-icon', \ShopEngine::plugin_url() . 'assets/css/shopengine-icon.css', false, \ShopEngine::version()); |
| 286 | 143 | wp_enqueue_style('shopengine-simple-scrollbar-css', \ShopEngine::plugin_url() . 'assets/css/simple-scrollbar.css', false, \ShopEngine::version()); |
| 287 | 144 | wp_enqueue_style('shopengine-public-css', \ShopEngine::plugin_url() . 'assets/css/public-style.css', false, \ShopEngine::version()); |
| 145 | + wp_enqueue_script('shopengine-simple-scrollbar.js-js', \ShopEngine::plugin_url() . 'assets/js/simple-scrollbar.js', array(), \ShopEngine::version(), true); | |
| 146 | + wp_enqueue_script('shopengine-filter-js', \ShopEngine::plugin_url() . 'assets/js/filter.js', array(), \ShopEngine::version(), true); | |
| 147 | + wp_enqueue_script('shopengine-js', \ShopEngine::plugin_url() . 'assets/js/public.js', array(), \ShopEngine::version(), true); | |
| 288 | 148 | |
| 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 | 149 | wp_localize_script('shopengine-js', 'shopEngineApiSettings', [ |
| 301 | 150 | 'resturl' => get_rest_url(), |
| 302 | 151 | 'rest_nonce' => wp_create_nonce('wp_rest'), |
| 303 | 152 | ]); |
| 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 | 153 | } |
| 326 | 154 | |
| 327 | 155 | public function js_css_elementor() { |
| 328 | 156 | wp_enqueue_style('shopnegine-panel-icon', \ShopEngine::plugin_url() . 'assets/css/shopengine-icon.css', false, \ShopEngine::version()); |
| 329 | 157 | |
| 330 | - if('shopengine-template' === get_post_type()): | |
| 158 | + if ( 'shopengine-template' === get_post_type() ): | |
| 331 | 159 | wp_enqueue_style('shopnegine-editor-css', \ShopEngine::plugin_url() . 'assets/css/editor.css', false, \ShopEngine::version()); |
| 332 | 160 | endif; |
| 333 | 161 | } |
| 334 | 162 | |
| @@ -340,14 +168,14 @@ | ||
| 340 | 168 | } |
| 341 | 169 | |
| 342 | 170 | if(file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php')) { |
| 343 | 171 | |
| 344 | - $btn['label'] = esc_html__('Activate WooCommerce', 'shopengine'); | |
| 172 | + $btn['label'] = esc_html__('Activate Woocommerce', 'shopengine'); | |
| 345 | 173 | $btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=all&paged=1', 'activate-plugin_woocommerce/woocommerce.php'); |
| 346 | 174 | |
| 347 | 175 | } else { |
| 348 | 176 | |
| 349 | - $btn['label'] = esc_html__('Install WooCommerce', 'shopengine'); | |
| 177 | + $btn['label'] = esc_html__('Install Woocommerce', 'shopengine'); | |
| 350 | 178 | $btn['url'] = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=woocommerce'), 'install-plugin_woocommerce'); |
| 351 | 179 | } |
| 352 | 180 | |
| 353 | 181 | Utils\Notice::push( |
| @@ -407,8 +235,9 @@ | ||
| 407 | 235 | ); |
| 408 | 236 | } |
| 409 | 237 | |
| 410 | 238 | |
| 239 | + | |
| 411 | 240 | public function flush_rewrites() { |
| 412 | 241 | $form_cpt = new Core\Builders\Cpt(); |
| 413 | 242 | $form_cpt->flush_rewrites(); |
| 414 | 243 | } |
| @@ -420,5 +249,6 @@ | ||
| 420 | 249 | } |
| 421 | 250 | |
| 422 | 251 | return self::$instance; |
| 423 | 252 | } |
| 253 | + | |
| 424 | 254 | } |