| @@ -1,12 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ShopEngine; |
| 4 | 4 | |
| 5 | +defined('ABSPATH') || exit; | |
| 6 | + | |
| 5 | 7 | use ShopEngine\Compatibility\Conflicts\Manifest as Conflict_Manifest; |
| 6 | 8 | use ShopEngine\Core\Builders\Base; |
| 7 | 9 | use ShopEngine\Compatibility\Migrations\LangMigration; |
| 8 | 10 | use ShopEngine\Core\Query_Modifier; |
| 11 | +use ShopEngine\Core\Wc_Customizer\Register_Settings; | |
| 9 | 12 | use ShopEngine\Core\Template_Cpt; |
| 10 | 13 | use ShopEngine\Libs\License\License_Route; |
| 11 | 14 | use ShopEngine\Libs\Rating\Rating; |
| 12 | 15 | use ShopEngine\Libs\Updater\Init as Updater; |
| @@ -12,9 +15,8 @@ | ||
| 12 | 15 | use ShopEngine\Libs\Updater\Init as Updater; |
| 13 | 16 | use ShopEngine\Modules\Manifest as Module_Manifest; |
| 14 | 17 | use ShopEngine\Widgets\Manifest; |
| 15 | 18 | |
| 16 | -defined('ABSPATH') || exit; | |
| 17 | 19 | |
| 18 | 20 | /** |
| 19 | 21 | * Plugin final Class. |
| 20 | 22 | * Handles dynamically loading classes only when needed. Check Elementor Plugin, Woocomerce Plugin Loaded or Install. |
| @@ -31,11 +33,15 @@ | ||
| 31 | 33 | */ |
| 32 | 34 | public function __construct() { |
| 33 | 35 | // load autoload method |
| 34 | 36 | Autoloader::run(); |
| 37 | + add_action( 'wp_ajax_shopengine_admin_action', [\ShopEngine\Utils\Util::class, 'shopengine_admin_action'] ); | |
| 35 | 38 | } |
| 36 | 39 | |
| 37 | - | |
| 40 | + public function utils_url() | |
| 41 | + { | |
| 42 | + return $this->plugin_url() . 'utils/'; | |
| 43 | + } | |
| 38 | 44 | /** |
| 39 | 45 | * Public function init. |
| 40 | 46 | * call function for all |
| 41 | 47 | * |
| @@ -112,45 +118,16 @@ | ||
| 112 | 118 | }); |
| 113 | 119 | |
| 114 | 120 | |
| 115 | 121 | add_action('wp_loaded', function () { |
| 116 | - //phpcs:ignore WordPress.Security.NonceVerification.Recommended --It's a fronted user part, not possible to verify nonce here | |
| 117 | - if(isset($_REQUEST['preview']) && $_REQUEST['preview'] == 'true' && !empty($_REQUEST['preview_id'])) { | |
| 118 | - | |
| 119 | - $pid = (int)$_REQUEST['preview_id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- It's a fronted user part, not possible to verify nonce here | |
| 120 | - | |
| 121 | - $po = get_post($pid); | |
| 122 | - | |
| 123 | - if($po->post_type === Template_Cpt::TYPE) { | |
| 124 | - | |
| 125 | - $template = \ShopEngine\Core\Builders\Templates::get_registered_template_data($pid); | |
| 126 | - | |
| 127 | - if(empty($template) || !isset($template['url'])) { | |
| 128 | - return; | |
| 129 | - } | |
| 130 | - | |
| 131 | - $param = [ | |
| 132 | - 'shopengine_template_id' => $pid, | |
| 133 | - 'preview_nonce' => wp_create_nonce('template_preview_' . $pid), | |
| 134 | - 'change_template' => '1', | |
| 135 | - ]; | |
| 136 | - | |
| 137 | - $url = \ShopEngine\Utils\Helper::add_to_url($template['url'], $param); | |
| 138 | - | |
| 139 | - wp_safe_redirect($url); | |
| 140 | - exit; | |
| 141 | - } | |
| 142 | - } | |
| 143 | - | |
| 144 | 122 | /** |
| 145 | 123 | * migrate data |
| 146 | - */ | |
| 124 | + */ | |
| 147 | 125 | LangMigration::instance()->init(); |
| 148 | 126 | }); |
| 149 | 127 | |
| 150 | 128 | // avoid themes for loading woocommerce functions |
| 151 | - $avoid_themes = ['avada', 'avada child']; | |
| 152 | - | |
| 129 | + $avoid_themes = ['avada', 'avada child', 'woodmart', 'woodmart child']; | |
| 153 | 130 | if(!in_array(strtolower(wp_get_theme()), $avoid_themes)) { |
| 154 | 131 | /** |
| 155 | 132 | * Ensuring woocommerce functions are loaded before theme is modifying those |
| 156 | 133 | * |
| @@ -178,10 +155,17 @@ | ||
| 178 | 155 | add_theme_support('wc-product-gallery-lightbox'); |
| 179 | 156 | add_theme_support('wc-product-gallery-slider'); |
| 180 | 157 | } |
| 181 | 158 | |
| 159 | + | |
| 160 | + $filter_string = ''; // elementskit,metform-pro | |
| 161 | + $filter_string .= ((!in_array('elementskit/elementskit.php', apply_filters('active_plugins', get_option('active_plugins')))) ? '' : ',elementskit'); | |
| 162 | + $filter_string .= (!class_exists('\MetForm\Plugin') ? '' : ',metform'); | |
| 163 | + $filter_string .= (!class_exists('\MetForm_Pro\Plugin') ? '' : ',metform-pro'); | |
| 164 | + | |
| 182 | 165 | #Registering new post-type & etc |
| 183 | 166 | Base::instance()->init(); |
| 167 | + | |
| 184 | 168 | |
| 185 | 169 | Rating::instance('shopengine') |
| 186 | 170 | ->set_plugin( 'ShopEngine', 'https://wpmet.com/wordpress.org/rating/shopengine' ) |
| 187 | 171 | ->set_plugin_logo( 'https://ps.w.org/shopengine/assets/icon-256x256.gif?rev=2505061', 'width:150px !important' ) |
| @@ -188,13 +172,36 @@ | ||
| 188 | 172 | ->set_priority( 10 ) |
| 189 | 173 | ->set_first_appear_day( 7 ) |
| 190 | 174 | ->set_condition( true ) |
| 191 | 175 | ->call(); |
| 176 | + | |
| 177 | + if ( is_admin() && \ShopEngine\Utils\Util::get_settings( 'shopengine_user_consent_for_banner', 'true' ) == 'true' ) { | |
| 192 | 178 | |
| 179 | + /** | |
| 180 | + * Show WPMET stories widget in dashboard | |
| 181 | + */ | |
| 182 | + | |
| 183 | + \Wpmet\Libs\Stories::instance('shopengine') | |
| 184 | + | |
| 185 | + ->set_filter($filter_string) | |
| 186 | + ->set_plugin('ShopEngine', 'https://wpmet.com/plugin/shopengine/') | |
| 187 | + ->set_api_url('https://api.wpmet.com/public/stories/') | |
| 188 | + ->call(); | |
| 189 | + | |
| 190 | + // banner | |
| 191 | + \Wpmet\Libs\Banner::instance('shopengine') | |
| 192 | + ->set_filter(ltrim($filter_string, ',')) | |
| 193 | + ->set_api_url('https://api.wpmet.com/public/jhanda') | |
| 194 | + ->set_plugin_screens('edit-shopengine-template') | |
| 195 | + ->set_plugin_screens('edit-shopengine-template') | |
| 196 | + ->call(); | |
| 197 | + } | |
| 198 | + | |
| 193 | 199 | \ShopEngine\Core\MultiLanguage\Language::instance()->init(); |
| 194 | 200 | |
| 195 | 201 | \ShopEngine\Core\Settings\Base::instance()->init(); |
| 196 | 202 | |
| 203 | + | |
| 197 | 204 | new Libs\Select_Api\Base(); |
| 198 | 205 | |
| 199 | 206 | (new Module_Manifest())->init(); |
| 200 | 207 | |
| @@ -226,8 +233,11 @@ | ||
| 226 | 233 | |
| 227 | 234 | } |
| 228 | 235 | |
| 229 | 236 | add_filter('script_loader_tag', [$this, 'filter_load_type'], 99, 3); |
| 237 | + | |
| 238 | + //it will register an option in customizer for woocommerce products catelog. It's related with our Arcive Products widget. | |
| 239 | + Register_Settings::instance()->init(); | |
| 230 | 240 | } |
| 231 | 241 | |
| 232 | 242 | |
| 233 | 243 | // add async and defer attributes to enqueued scripts |
| @@ -349,8 +359,12 @@ | ||
| 349 | 359 | |
| 350 | 360 | |
| 351 | 361 | public function missing_woocommerce() { |
| 352 | 362 | |
| 363 | + if(!current_user_can('manage_options')) { | |
| 364 | + return; | |
| 365 | + } | |
| 366 | + | |
| 353 | 367 | if(file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php')) { |
| 354 | 368 | |
| 355 | 369 | $btn['label'] = esc_html__('Activate WooCommerce', 'shopengine'); |
| 356 | 370 | $btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=all&paged=1', 'activate-plugin_woocommerce/woocommerce.php'); |
| @@ -365,8 +379,9 @@ | ||
| 365 | 379 | [ |
| 366 | 380 | 'id' => 'missing-woo', |
| 367 | 381 | 'type' => 'error', |
| 368 | 382 | 'dismissible' => true, |
| 383 | + 'is_required' => true, | |
| 369 | 384 | 'btn' => $btn, |
| 370 | 385 | 'message' => sprintf(esc_html__('ShopEngine requires woocommerce Plugin, which is currently NOT RUNNING.', 'shopengine'), '4.1.0'), |
| 371 | 386 | ] |
| 372 | 387 | ); |
| @@ -374,8 +389,12 @@ | ||
| 374 | 389 | |
| 375 | 390 | |
| 376 | 391 | public function missing_elementor() { |
| 377 | 392 | |
| 393 | + if(!current_user_can('manage_options')) { | |
| 394 | + return; | |
| 395 | + } | |
| 396 | + | |
| 378 | 397 | if(file_exists(WP_PLUGIN_DIR . '/elementor/elementor.php')) { |
| 379 | 398 | |
| 380 | 399 | $btn['label'] = esc_html__('Activate Elementor', 'shopengine'); |
| 381 | 400 | $btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=elementor/elementor.php&plugin_status=all&paged=1', 'activate-plugin_elementor/elementor.php'); |
| @@ -389,8 +408,9 @@ | ||
| 389 | 408 | Utils\Notice::push( |
| 390 | 409 | [ |
| 391 | 410 | 'id' => 'missing-elementor', |
| 392 | 411 | 'type' => 'error', |
| 412 | + 'is_required' => true, | |
| 393 | 413 | 'dismissible' => true, |
| 394 | 414 | 'btn' => $btn, |
| 395 | 415 | 'message' => sprintf(esc_html__('ShopEngine requires Elementor version %1$s+, which is currently NOT RUNNING.', 'shopengine'), '3.0.0'), |
| 396 | 416 | ] |
| @@ -398,8 +418,12 @@ | ||
| 398 | 418 | } |
| 399 | 419 | |
| 400 | 420 | |
| 401 | 421 | public function failed_elementor_version() { |
| 422 | + | |
| 423 | + if(!current_user_can('manage_options')) { | |
| 424 | + return; | |
| 425 | + } | |
| 402 | 426 | |
| 403 | 427 | $btn['label'] = esc_html__('Update Elementor', 'shopengine'); |
| 404 | 428 | $btn['url'] = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=elementor'), 'upgrade-plugin_elementor'); |
| 405 | 429 | |