| @@ -68,23 +68,9 @@ | ||
| 68 | 68 | |
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - add_filter("plugin_action_links_shopengine/shopengine.php", function ($links) { | |
| 73 | 72 | |
| 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 | 73 | /** |
| 88 | 74 | * Routes initialization |
| 89 | 75 | * |
| 90 | 76 | */ |
| @@ -105,24 +91,24 @@ | ||
| 105 | 91 | |
| 106 | 92 | if(is_admin() && $pagenow == 'post.php' && $_REQUEST['action'] === 'edit') { |
| 107 | 93 | |
| 108 | 94 | $pid = $_REQUEST['post']; |
| 109 | - $po = get_post($pid); | |
| 95 | + $po = get_post($pid); | |
| 110 | 96 | |
| 111 | 97 | if($po->post_type === Template_Cpt::TYPE) { |
| 112 | 98 | |
| 113 | - $url = get_admin_url() . 'edit.php?post_type=' . Template_Cpt::TYPE . '#' . Template_Cpt::TYPE; | |
| 99 | + $url = get_admin_url(). 'edit.php?post_type='.Template_Cpt::TYPE.'#'.Template_Cpt::TYPE; | |
| 114 | 100 | |
| 115 | - wp_safe_redirect($url); | |
| 101 | + wp_safe_redirect( $url ); | |
| 116 | 102 | exit; |
| 117 | 103 | } |
| 118 | 104 | } |
| 119 | 105 | |
| 120 | - add_action('wp_loaded', function () { | |
| 106 | + add_action('wp_loaded', function (){ | |
| 121 | 107 | |
| 122 | 108 | if(isset($_REQUEST['preview']) && $_REQUEST['preview'] == 'true' && !empty($_REQUEST['preview_id'])) { |
| 123 | 109 | |
| 124 | - $pid = (int)$_REQUEST['preview_id']; | |
| 110 | + $pid = (int) $_REQUEST['preview_id']; | |
| 125 | 111 | |
| 126 | 112 | $po = get_post($pid); |
| 127 | 113 | |
| 128 | 114 | if($po->post_type === Template_Cpt::TYPE) { |
| @@ -128,21 +114,21 @@ | ||
| 128 | 114 | if($po->post_type === Template_Cpt::TYPE) { |
| 129 | 115 | |
| 130 | 116 | $template = \ShopEngine\Core\Builders\Templates::get_registered_template_data($pid); |
| 131 | 117 | |
| 132 | - if(empty($template) || !isset($template['url'])) { | |
| 118 | + if(empty($template) || !isset($template['url'])){ | |
| 133 | 119 | return; |
| 134 | 120 | } |
| 135 | 121 | |
| 136 | 122 | $param = [ |
| 137 | 123 | 'shopengine_template_id' => $pid, |
| 138 | - 'preview_nonce' => wp_create_nonce('template_preview_' . $pid), | |
| 139 | - 'change_template' => '1', | |
| 124 | + 'preview_nonce' => wp_create_nonce( 'template_preview_' . $pid ), | |
| 125 | + 'change_template' => '1' | |
| 140 | 126 | ]; |
| 141 | 127 | |
| 142 | 128 | $url = \ShopEngine\Utils\Helper::add_to_url($template['url'], $param); |
| 143 | 129 | |
| 144 | - wp_safe_redirect($url); | |
| 130 | + wp_safe_redirect( $url ); | |
| 145 | 131 | exit; |
| 146 | 132 | } |
| 147 | 133 | } |
| 148 | 134 | }); |
| @@ -147,18 +133,14 @@ | ||
| 147 | 133 | } |
| 148 | 134 | }); |
| 149 | 135 | |
| 150 | 136 | |
| 151 | - // avoid themes for loading woocommerce functions | |
| 152 | - $avoid_themes = ['avada']; | |
| 137 | + /** | |
| 138 | + * Ensuring woocommerce functions are loaded before theme is modifying those | |
| 139 | + * | |
| 140 | + */ | |
| 141 | + require_once WC_ABSPATH . '/includes/wc-template-functions.php'; | |
| 153 | 142 | |
| 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 | 143 | |
| 162 | 144 | // Load custom elementor controls |
| 163 | 145 | new \ShopEngine\Core\Elementor_Controls\Init(); |
| 164 | 146 | |
| @@ -176,24 +158,22 @@ | ||
| 176 | 158 | |
| 177 | 159 | |
| 178 | 160 | #Registering new post-type & etc |
| 179 | 161 | Base::instance()->init(); |
| 180 | - | |
| 181 | - \ShopEngine\Core\Settings\Base::instance()->init(); | |
| 182 | 162 | |
| 183 | - new Libs\Select_Api\Base(); | |
| 163 | + \ShopEngine\Core\Settings\Base::instance()->init(); | |
| 184 | 164 | |
| 185 | - (new Module_Manifest())->init(); | |
| 165 | + (new Module_Manifest)->init(); | |
| 186 | 166 | |
| 187 | 167 | // working get instance of elementor widget |
| 188 | - (new Manifest())->init(); | |
| 168 | + (new Manifest)->init(); | |
| 189 | 169 | |
| 190 | 170 | Query_Modifier::instance()->init(); |
| 191 | 171 | |
| 192 | - (new Conflict_Manifest())->init(); | |
| 172 | + (new Conflict_Manifest)->init(); | |
| 193 | 173 | |
| 194 | 174 | // view count |
| 195 | - add_action('get_header', [$this, 'shopengine_track_product_views']); | |
| 175 | + add_action('wp_head', [$this, 'shopengine_track_product_views']); | |
| 196 | 176 | |
| 197 | 177 | // database migrations |
| 198 | 178 | // (new \ShopEngine\Compatibility\Migrations\Migration())->init(); |
| 199 | 179 | (new \ShopEngine\Compatibility\Migrations\Temp_Migration())->init(); |
| @@ -201,60 +181,34 @@ | ||
| 201 | 181 | add_filter('script_loader_tag', [$this, 'filter_load_type'], 99, 3); |
| 202 | 182 | } |
| 203 | 183 | |
| 204 | 184 | |
| 205 | - // add async and defer attributes to enqueued scripts | |
| 206 | - public function filter_load_type($tag, $handle, $src) { | |
| 185 | + // add async and defer attributes to enqueued scripts | |
| 186 | + public function filter_load_type($tag, $handle, $src) { | |
| 207 | 187 | |
| 208 | - if(strpos($handle, '-async') !== false) { | |
| 209 | - $tag = str_replace(' src', ' async="async" src', $tag); | |
| 210 | - } | |
| 188 | + if (strpos($handle, '-async') !== false) { | |
| 189 | + $tag = str_replace(' src', ' async="async" src', $tag); | |
| 190 | + } | |
| 211 | 191 | |
| 212 | - if(strpos($handle, '-defer') !== false) { | |
| 213 | - $tag = str_replace('<script ', '<script defer ', $tag); | |
| 192 | + if (strpos($handle, '-defer') !== false) { | |
| 193 | + $tag = str_replace('<script ', '<script defer ', $tag); | |
| 194 | + } | |
| 195 | + | |
| 196 | + return $tag; | |
| 214 | 197 | } |
| 215 | 198 | |
| 216 | - return $tag; | |
| 217 | - } | |
| 218 | - | |
| 219 | 199 | /** |
| 220 | 200 | * Public function shopengine_track_product_views |
| 221 | 201 | * Adding Product Views Count Meta |
| 222 | 202 | */ |
| 223 | - public function shopengine_track_product_views() { | |
| 224 | - | |
| 203 | + public function shopengine_track_product_views($product_id) { | |
| 225 | 204 | if(class_exists('WooCommerce') && !is_product()) { |
| 226 | 205 | return; |
| 227 | 206 | } |
| 228 | - | |
| 229 | 207 | $product_id = get_the_id(); |
| 230 | 208 | |
| 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 | 209 | $count_key = 'shopengine_product_views_count'; |
| 255 | 210 | $count = get_post_meta($product_id, $count_key, true); |
| 256 | - | |
| 257 | 211 | if($count == '') { |
| 258 | 212 | $count = 1; |
| 259 | 213 | delete_post_meta($product_id, $count_key); |
| 260 | 214 | add_post_meta($product_id, $count_key, '1'); |
| @@ -409,5 +363,6 @@ | ||
| 409 | 363 | } |
| 410 | 364 | |
| 411 | 365 | return self::$instance; |
| 412 | 366 | } |
| 367 | + | |
| 413 | 368 | } |