| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package: importify-plugin |
| 5 |
*/ |
| 6 |
|
| 7 |
/** |
| 8 |
* Plugin Name: Importify |
| 9 |
* Description: Easily import best-selling products, and automate your entire dropshipping process, all with a single click. |
| 10 |
* Version: 1.0.9 |
| 11 |
* Author: Importify |
| 12 |
* Author URI: https://www.importify.com/ |
| 13 |
* License: GPLv3 or later |
| 14 |
* Text Domain: importify-plugin |
| 15 |
*/ |
| 16 |
|
| 17 |
if (!defined('ABSPATH')) { |
| 18 |
die; |
| 19 |
} |
| 20 |
|
| 21 |
define("IMPORTIFY_API_URL", "https://app.importify.net/dashboard"); |
| 22 |
define('IMPORTIFY_VERSION', '1.0.9'); |
| 23 |
define('IMPORTIFY_PATH', dirname(__FILE__)); |
| 24 |
define('IMPORTIFY_FOLDER', basename(IMPORTIFY_PATH)); |
| 25 |
define('IMPORTIFY_URL', plugins_url() . '/' . IMPORTIFY_FOLDER); |
| 26 |
define('IMPORTIFY_API_KEY', get_option('importify_api_key')); |
| 27 |
define("IMPORTIFY_DEBUG", false); |
| 28 |
|
| 29 |
register_activation_hook(__FILE__, 'importify_activation_hook'); |
| 30 |
register_deactivation_hook(__FILE__, 'importify_deactivation_hook'); |
| 31 |
register_uninstall_hook(__FILE__, 'importify_uninstall_hook'); |
| 32 |
add_action('admin_enqueue_scripts', 'importify_add_admin_css_js'); |
| 33 |
add_action('admin_menu', 'importify_admin_menu'); |
| 34 |
|
| 35 |
function importify_activation_hook() |
| 36 |
{ |
| 37 |
$data = array( |
| 38 |
'store' => get_site_url(), |
| 39 |
'email' => get_option('admin_email'), |
| 40 |
'event' => 'install', |
| 41 |
); |
| 42 |
|
| 43 |
|
| 44 |
$response = importify_send_request('/woocomerce/status', $data); |
| 45 |
|
| 46 |
if ($response) |
| 47 |
{ |
| 48 |
if ($response['success'] > 0) |
| 49 |
{ |
| 50 |
|
| 51 |
if (!get_option('importify_api_key')) |
| 52 |
{ |
| 53 |
add_option('importify_api_key',$response['api_key']); |
| 54 |
|
| 55 |
if (class_exists("WC_Auth")) |
| 56 |
{ |
| 57 |
class importify_AuthCustom extends WC_Auth |
| 58 |
{ |
| 59 |
public function getKeys($app_name, $user_id, $scope) |
| 60 |
{ |
| 61 |
return parent::create_keys($app_name, $user_id, $scope); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
$auth = new importify_AuthCustom(); |
| 66 |
$keys = $auth->getKeys($response['app_name'], $response['user_id'], $response['scope']); |
| 67 |
$data = array( |
| 68 |
'store' => get_site_url(), |
| 69 |
'keys' => $keys, |
| 70 |
'user_id' => $response['user_id'], |
| 71 |
'event' => 'update_keys' |
| 72 |
); |
| 73 |
$keys_response = importify_send_request('/woocomerce/status', $data); |
| 74 |
|
| 75 |
if ($keys_response && $keys_response['success'] == 0) |
| 76 |
{ |
| 77 |
add_option('importify_error', 'yes'); |
| 78 |
add_option('importify_error_message', $keys_response['message']); |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
else |
| 83 |
{ |
| 84 |
update_option('importify_api_key', $response['api_key']); |
| 85 |
} |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
|
| 90 |
if (!get_option('importify_error')) |
| 91 |
{ |
| 92 |
add_option('importify_error', 'yes'); |
| 93 |
add_option('importify_error_message', 'Error activation plugin!'); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
|
| 100 |
if (!get_option('importify_error')) |
| 101 |
{ |
| 102 |
add_option('importify_error', 'yes'); |
| 103 |
add_option('importify_error_message', 'Error activation plugin!'); |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
function importify_deactivation_hook() |
| 109 |
{ |
| 110 |
if(!current_user_can('activate_plugins')) |
| 111 |
{ |
| 112 |
return; |
| 113 |
} |
| 114 |
$data = array( |
| 115 |
'store' => get_site_url(), |
| 116 |
'event' => 'deactivated', |
| 117 |
); |
| 118 |
return importify_send_request('/woocomerce/status', $data); |
| 119 |
} |
| 120 |
|
| 121 |
function importify_uninstall_hook() |
| 122 |
{ |
| 123 |
if(!current_user_can('activate_plugins')) |
| 124 |
{ |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
delete_option('importify_api_key'); |
| 129 |
|
| 130 |
if (get_option('importify_error')) |
| 131 |
{ |
| 132 |
delete_option('importify_error'); |
| 133 |
} |
| 134 |
|
| 135 |
if (get_option('importify_error_message')) |
| 136 |
{ |
| 137 |
delete_option('importify_error_message'); |
| 138 |
} |
| 139 |
|
| 140 |
importify_clear_all_caches(); |
| 141 |
|
| 142 |
$data = array( |
| 143 |
'store' => get_site_url(), |
| 144 |
'event' => 'uninstall', |
| 145 |
); |
| 146 |
return importify_send_request('/woocomerce/status', $data); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
function importify_add_admin_css_js() |
| 151 |
{ |
| 152 |
|
| 153 |
wp_register_style('importify_style', IMPORTIFY_URL.'/assets/css/style.css'); |
| 154 |
wp_enqueue_style('importify_style'); |
| 155 |
wp_register_script('importify-admin', IMPORTIFY_URL.'/assets/js/script.js', array('jquery'), '1.0.0'); |
| 156 |
wp_enqueue_script('importify-admin'); |
| 157 |
wp_register_script('importify-admin-feather', IMPORTIFY_URL.'/assets/js/feather.min.js'); |
| 158 |
wp_enqueue_script('importify-admin-feather'); |
| 159 |
} |
| 160 |
|
| 161 |
function importify_admin_menu() |
| 162 |
{ |
| 163 |
add_menu_page('Importify Settings', 'Importify', 'manage_options', 'importify', 'importify_admin_menu_page_html', IMPORTIFY_URL.'/assets/images/importify_icon.png'); |
| 164 |
} |
| 165 |
|
| 166 |
function importify_has_woocommerce() |
| 167 |
{ |
| 168 |
return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))); |
| 169 |
} |
| 170 |
|
| 171 |
function importify_admin_menu_page_html() |
| 172 |
{ |
| 173 |
$data = array( |
| 174 |
'store' => get_site_url(), |
| 175 |
'event' => 'check_status' |
| 176 |
); |
| 177 |
|
| 178 |
$store_connected = false; |
| 179 |
|
| 180 |
$status_response = importify_send_request('/woocomerce/status', $data); |
| 181 |
|
| 182 |
if ($status_response && $status_response['success'] == 0) |
| 183 |
{ |
| 184 |
add_option('importify_error', 'yes'); |
| 185 |
add_option('importify_error_message', $status_response['message']); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
if ($status_response && $status_response['success'] == 1) |
| 190 |
{ |
| 191 |
delete_option('importify_error'); |
| 192 |
delete_option('importify_error_message'); |
| 193 |
|
| 194 |
if(isset($status_response['keys_ok']) && $status_response['keys_ok'] == "no") |
| 195 |
{ |
| 196 |
if (class_exists("WC_Auth")) |
| 197 |
{ |
| 198 |
class importify_AuthCustom extends WC_Auth |
| 199 |
{ |
| 200 |
public function getKeys($app_name, $user_id, $scope) |
| 201 |
{ |
| 202 |
return parent::create_keys($app_name, $user_id, $scope); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
$auth = new importify_AuthCustom(); |
| 207 |
$keys = $auth->getKeys($status_response['app_name'], $status_response['user_id'], $status_response['scope']); |
| 208 |
|
| 209 |
$data = array( |
| 210 |
'store' => get_site_url(), |
| 211 |
'keys' => $keys, |
| 212 |
'user_id' => $status_response['user_id'], |
| 213 |
'event' => 'update_keys' |
| 214 |
); |
| 215 |
$keys_response = importify_send_request('/woocomerce/status', $data); |
| 216 |
|
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
if (!get_option('importify_api_key')) |
| 221 |
{ |
| 222 |
add_option('importify_api_key',$status_response['api_key']); |
| 223 |
} |
| 224 |
else |
| 225 |
{ |
| 226 |
update_option('importify_api_key',$status_response['api_key']); |
| 227 |
} |
| 228 |
|
| 229 |
if(isset($status_response['store_connected']) && $status_response['store_connected'] == "yes") |
| 230 |
{ |
| 231 |
$store_connected = true; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
add_option('importify_check', array()); |
| 236 |
$tmp_check_data = array(); |
| 237 |
|
| 238 |
if(is_ssl()) |
| 239 |
{ |
| 240 |
$tmp_check_data['ssl_active'] = "true"; |
| 241 |
} |
| 242 |
else |
| 243 |
{ |
| 244 |
$tmp_check_data['ssl_active'] = "false"; |
| 245 |
} |
| 246 |
|
| 247 |
$tmp_check_data['permalinks'] = get_option( 'permalink_structure' ); |
| 248 |
$tmp_check_data['woocomerce_installed'] = importify_has_woocommerce(); |
| 249 |
$tmp_check_data['firewall_active'] = false; |
| 250 |
$tmp_check_data['cloudflare_active'] = false; |
| 251 |
|
| 252 |
// Checking if we have a plugin with firewall option if store is not connected |
| 253 |
if($store_connected == FALSE) |
| 254 |
{ |
| 255 |
// Checking for Cloudflare presence |
| 256 |
$data = array( |
| 257 |
'store' => get_site_url(), |
| 258 |
'event' => 'check_cloudflare' |
| 259 |
); |
| 260 |
|
| 261 |
|
| 262 |
$cloudflare_check = importify_send_request('/woocomerce/status', $data); |
| 263 |
|
| 264 |
if($cloudflare_check && $cloudflare_check['success'] == 1) |
| 265 |
{ |
| 266 |
if($cloudflare_check['cloudflare_enabled'] == "true") |
| 267 |
{ |
| 268 |
$tmp_check_data['cloudflare_active'] = true; |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
$plugin_list = get_plugins(); |
| 273 |
|
| 274 |
foreach ($plugin_list as $key => $value) |
| 275 |
{ |
| 276 |
$plugin_name = strtolower($value['Name']); |
| 277 |
|
| 278 |
if(strpos($plugin_name, "wordfence") !== FALSE || strpos($plugin_name, "jetpack") !== FALSE || strpos($plugin_name, "sucuri") !== FALSE || strpos($plugin_name, "ninjafirewall") !== FALSE) |
| 279 |
{ |
| 280 |
$tmp_check_data['firewall_active'] = true; |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
update_option('importify_check', $tmp_check_data); |
| 286 |
|
| 287 |
include_once IMPORTIFY_PATH.'/views/importify_admin_page.php'; |
| 288 |
} |
| 289 |
|
| 290 |
function importify_send_request($path, $data) |
| 291 |
{ |
| 292 |
try |
| 293 |
{ |
| 294 |
$headers = array( |
| 295 |
'Content-Type' => 'application/json', |
| 296 |
'x-plugin-version' => IMPORTIFY_VERSION, |
| 297 |
'x-site-url' => get_site_url(), |
| 298 |
'x-wp-version' => get_bloginfo('version'), |
| 299 |
); |
| 300 |
|
| 301 |
if (importify_has_woocommerce()) |
| 302 |
{ |
| 303 |
$headers['x-woo-version'] = WC()->version; |
| 304 |
} |
| 305 |
|
| 306 |
$url = IMPORTIFY_API_URL.$path; |
| 307 |
$data = array( |
| 308 |
'headers' => $headers, |
| 309 |
'body' => json_encode($data), |
| 310 |
'method' => 'POST', |
| 311 |
'data_format' => 'body', |
| 312 |
'sslverify' => false |
| 313 |
); |
| 314 |
|
| 315 |
$response = wp_remote_post($url, $data); |
| 316 |
|
| 317 |
if (!is_wp_error($response)) |
| 318 |
{ |
| 319 |
$decoded_response = json_decode(wp_remote_retrieve_body($response), true); |
| 320 |
|
| 321 |
return $decoded_response; |
| 322 |
} |
| 323 |
|
| 324 |
return 0; |
| 325 |
} |
| 326 |
catch(Exception $err) |
| 327 |
{ |
| 328 |
if(IMPORTIFY_DEBUG) |
| 329 |
{ |
| 330 |
echo $err; |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
function importify_plugin_redirect() |
| 337 |
{ |
| 338 |
exit(wp_redirect("admin.php?page=Importify")); |
| 339 |
} |
| 340 |
|
| 341 |
function importify_clear_all_caches() |
| 342 |
{ |
| 343 |
try |
| 344 |
{ |
| 345 |
global $wp_fastest_cache; |
| 346 |
|
| 347 |
if (function_exists('w3tc_flush_all')) |
| 348 |
{ |
| 349 |
w3tc_flush_all(); |
| 350 |
} |
| 351 |
|
| 352 |
if (function_exists('wp_cache_clean_cache')) |
| 353 |
{ |
| 354 |
global $file_prefix, $supercachedir; |
| 355 |
|
| 356 |
if (empty($supercachedir) && function_exists('get_supercache_dir')) |
| 357 |
{ |
| 358 |
$supercachedir = get_supercache_dir(); |
| 359 |
} |
| 360 |
wp_cache_clean_cache($file_prefix); |
| 361 |
} |
| 362 |
|
| 363 |
if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) |
| 364 |
{ |
| 365 |
$wp_fastest_cache->deleteCache(); |
| 366 |
} |
| 367 |
|
| 368 |
if (function_exists('rocket_clean_domain')) |
| 369 |
{ |
| 370 |
rocket_clean_domain(); |
| 371 |
// Preload cache. |
| 372 |
if (function_exists('run_rocket_sitemap_preload')) { |
| 373 |
run_rocket_sitemap_preload(); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall")) |
| 378 |
{ |
| 379 |
autoptimizeCache::clearall(); |
| 380 |
} |
| 381 |
|
| 382 |
if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all")) |
| 383 |
{ |
| 384 |
LiteSpeed_Cache_API::purge_all(); |
| 385 |
} |
| 386 |
|
| 387 |
if (class_exists('\Hummingbird\Core\Utils')) |
| 388 |
{ |
| 389 |
$modules= \Hummingbird\Core\Utils::get_active_cache_modules(); |
| 390 |
foreach ($modules as $module => $name) |
| 391 |
{ |
| 392 |
$mod = \Hummingbird\Core\Utils::get_module( $module ); |
| 393 |
|
| 394 |
if ($mod->is_active()) |
| 395 |
{ |
| 396 |
if ('minify' === $module) |
| 397 |
{ |
| 398 |
$mod->clear_files(); |
| 399 |
} |
| 400 |
else |
| 401 |
{ |
| 402 |
$mod->clear_cache(); |
| 403 |
} |
| 404 |
} |
| 405 |
} |
| 406 |
} |
| 407 |
} |
| 408 |
catch (Exception $e) |
| 409 |
{ |
| 410 |
return 1; |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
?> |