| 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.16 |
| 11 |
* Author: Importify |
| 12 |
* Author URI: https://www.importify.com/ |
| 13 |
* License: GPLv3 or later |
| 14 |
* Text Domain: importify-plugin |
| 15 |
* Requires PHP: 7.2 |
| 16 |
* WC requires at least: 5.0 |
| 17 |
*/ |
| 18 |
|
| 19 |
if (!defined('ABSPATH')) { |
| 20 |
die; |
| 21 |
} |
| 22 |
|
| 23 |
define("IMPORTIFY_API_URL", "https://app.importify.net/dashboard"); |
| 24 |
define('IMPORTIFY_VERSION', '1.0.16'); |
| 25 |
define('IMPORTIFY_PATH', dirname(__FILE__)); |
| 26 |
define('IMPORTIFY_FOLDER', basename(IMPORTIFY_PATH)); |
| 27 |
define('IMPORTIFY_URL', plugins_url() . '/' . IMPORTIFY_FOLDER); |
| 28 |
define('IMPORTIFY_API_KEY', get_option('importify_api_key')); |
| 29 |
define("IMPORTIFY_DEBUG", false); |
| 30 |
|
| 31 |
register_activation_hook(__FILE__, 'importify_activation_hook'); |
| 32 |
register_deactivation_hook(__FILE__, 'importify_deactivation_hook'); |
| 33 |
register_uninstall_hook(__FILE__, 'importify_uninstall_hook'); |
| 34 |
add_action('admin_enqueue_scripts', 'importify_add_admin_css_js'); |
| 35 |
add_action('admin_menu', 'importify_admin_menu'); |
| 36 |
add_filter('wp_kses_allowed_html', 'importify_allow_video_tags', 10, 2); |
| 37 |
|
| 38 |
function importify_allow_video_tags($tags, $context) { |
| 39 |
if ($context === 'post') { |
| 40 |
$tags['video'] = ['width' => true, 'height' => true, 'controls' => true, 'playsinline' => true, 'autoplay' => true, 'muted' => true, 'loop' => true, 'preload' => true, 'src' => true, 'class' => true, 'style' => true]; |
| 41 |
$tags['source'] = ['src' => true, 'type' => true]; |
| 42 |
$tags['iframe'] = ['src' => true, 'width' => true, 'height' => true, 'frameborder' => true, 'allowfullscreen' => true, 'allow' => true, 'class' => true, 'style' => true]; |
| 43 |
} |
| 44 |
return $tags; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Helper: Create WooCommerce API keys programmatically. |
| 49 |
* Wrapped in class_exists check to prevent duplicate declaration fatal error. |
| 50 |
*/ |
| 51 |
function importify_create_woo_keys($app_name, $user_id, $scope) |
| 52 |
{ |
| 53 |
if (!class_exists("WC_Auth")) return false; |
| 54 |
|
| 55 |
if (!class_exists("importify_AuthCustom")) { |
| 56 |
class importify_AuthCustom extends WC_Auth |
| 57 |
{ |
| 58 |
public function getKeys($app_name, $user_id, $scope) |
| 59 |
{ |
| 60 |
return parent::create_keys($app_name, $user_id, $scope); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
$auth = new importify_AuthCustom(); |
| 66 |
return $auth->getKeys($app_name, $user_id, $scope); |
| 67 |
} |
| 68 |
|
| 69 |
function importify_activation_hook() |
| 70 |
{ |
| 71 |
$data = array( |
| 72 |
'store' => get_site_url(), |
| 73 |
'email' => get_option('admin_email'), |
| 74 |
'event' => 'install', |
| 75 |
); |
| 76 |
|
| 77 |
$response = importify_send_request('/woocomerce/status', $data); |
| 78 |
|
| 79 |
if ($response) |
| 80 |
{ |
| 81 |
if ($response['success'] > 0) |
| 82 |
{ |
| 83 |
if (!get_option('importify_api_key')) |
| 84 |
{ |
| 85 |
add_option('importify_api_key', $response['api_key']); |
| 86 |
|
| 87 |
$keys = importify_create_woo_keys($response['app_name'], $response['user_id'], $response['scope']); |
| 88 |
if ($keys) |
| 89 |
{ |
| 90 |
$data = array( |
| 91 |
'store' => get_site_url(), |
| 92 |
'keys' => $keys, |
| 93 |
'user_id' => $response['user_id'], |
| 94 |
'event' => 'update_keys' |
| 95 |
); |
| 96 |
$keys_response = importify_send_request('/woocomerce/status', $data); |
| 97 |
|
| 98 |
if ($keys_response && $keys_response['success'] == 0) |
| 99 |
{ |
| 100 |
update_option('importify_error', 'yes'); |
| 101 |
update_option('importify_error_message', $keys_response['message']); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
else |
| 106 |
{ |
| 107 |
update_option('importify_api_key', $response['api_key']); |
| 108 |
} |
| 109 |
} |
| 110 |
else |
| 111 |
{ |
| 112 |
$msg = isset($response['message']) ? $response['message'] : 'Error activation plugin!'; |
| 113 |
update_option('importify_error', 'yes'); |
| 114 |
update_option('importify_error_message', $msg); |
| 115 |
} |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
update_option('importify_error', 'yes'); |
| 120 |
update_option('importify_error_message', 'Could not connect to Importify server. Please check your internet connection and try again.'); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
function importify_deactivation_hook() |
| 125 |
{ |
| 126 |
if (!current_user_can('activate_plugins')) |
| 127 |
{ |
| 128 |
return; |
| 129 |
} |
| 130 |
$data = array( |
| 131 |
'store' => get_site_url(), |
| 132 |
'event' => 'deactivated', |
| 133 |
); |
| 134 |
return importify_send_request('/woocomerce/status', $data); |
| 135 |
} |
| 136 |
|
| 137 |
function importify_uninstall_hook() |
| 138 |
{ |
| 139 |
if (!current_user_can('activate_plugins')) |
| 140 |
{ |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
delete_option('importify_api_key'); |
| 145 |
delete_option('importify_error'); |
| 146 |
delete_option('importify_error_message'); |
| 147 |
delete_option('importify_check'); |
| 148 |
|
| 149 |
importify_clear_all_caches(); |
| 150 |
|
| 151 |
$data = array( |
| 152 |
'store' => get_site_url(), |
| 153 |
'event' => 'uninstall', |
| 154 |
); |
| 155 |
return importify_send_request('/woocomerce/status', $data); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
function importify_add_admin_css_js() |
| 160 |
{ |
| 161 |
wp_register_style('importify_style', IMPORTIFY_URL . '/assets/css/style.css'); |
| 162 |
wp_enqueue_style('importify_style'); |
| 163 |
wp_register_script('importify-admin', IMPORTIFY_URL . '/assets/js/script.js', array('jquery'), '1.0.0'); |
| 164 |
wp_enqueue_script('importify-admin'); |
| 165 |
wp_register_script('importify-admin-feather', IMPORTIFY_URL . '/assets/js/feather.min.js'); |
| 166 |
wp_enqueue_script('importify-admin-feather'); |
| 167 |
} |
| 168 |
|
| 169 |
function importify_admin_menu() |
| 170 |
{ |
| 171 |
add_menu_page('Importify Settings', 'Importify', 'manage_options', 'importify', 'importify_admin_menu_page_html', IMPORTIFY_URL . '/assets/images/importify_icon.png'); |
| 172 |
} |
| 173 |
|
| 174 |
function importify_has_woocommerce() |
| 175 |
{ |
| 176 |
return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))); |
| 177 |
} |
| 178 |
|
| 179 |
function importify_admin_menu_page_html() |
| 180 |
{ |
| 181 |
$data = array( |
| 182 |
'store' => get_site_url(), |
| 183 |
'event' => 'check_status' |
| 184 |
); |
| 185 |
|
| 186 |
$store_connected = false; |
| 187 |
|
| 188 |
$status_response = importify_send_request('/woocomerce/status', $data); |
| 189 |
|
| 190 |
if ($status_response && isset($status_response['success']) && $status_response['success'] == 0) |
| 191 |
{ |
| 192 |
update_option('importify_error', 'yes'); |
| 193 |
update_option('importify_error_message', isset($status_response['message']) ? $status_response['message'] : 'Connection error'); |
| 194 |
} |
| 195 |
|
| 196 |
if ($status_response && isset($status_response['success']) && $status_response['success'] == 1) |
| 197 |
{ |
| 198 |
delete_option('importify_error'); |
| 199 |
delete_option('importify_error_message'); |
| 200 |
|
| 201 |
if (isset($status_response['keys_ok']) && $status_response['keys_ok'] == "no") |
| 202 |
{ |
| 203 |
$keys = importify_create_woo_keys($status_response['app_name'], $status_response['user_id'], $status_response['scope']); |
| 204 |
if ($keys) |
| 205 |
{ |
| 206 |
$data = array( |
| 207 |
'store' => get_site_url(), |
| 208 |
'keys' => $keys, |
| 209 |
'user_id' => $status_response['user_id'], |
| 210 |
'event' => 'update_keys' |
| 211 |
); |
| 212 |
$keys_response = importify_send_request('/woocomerce/status', $data); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
if (!get_option('importify_api_key')) |
| 217 |
{ |
| 218 |
add_option('importify_api_key', $status_response['api_key']); |
| 219 |
} |
| 220 |
else |
| 221 |
{ |
| 222 |
update_option('importify_api_key', $status_response['api_key']); |
| 223 |
} |
| 224 |
|
| 225 |
if (isset($status_response['store_connected']) && $status_response['store_connected'] == "yes") |
| 226 |
{ |
| 227 |
$store_connected = true; |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
$tmp_check_data = array(); |
| 232 |
|
| 233 |
// SSL check |
| 234 |
$tmp_check_data['ssl_active'] = is_ssl() ? "true" : "false"; |
| 235 |
|
| 236 |
// Permalinks check |
| 237 |
$permalinks = get_option('permalink_structure'); |
| 238 |
$tmp_check_data['permalinks'] = is_string($permalinks) ? $permalinks : ''; |
| 239 |
|
| 240 |
// WooCommerce check |
| 241 |
$tmp_check_data['woocomerce_installed'] = importify_has_woocommerce(); |
| 242 |
|
| 243 |
// PHP version check |
| 244 |
$tmp_check_data['php_version'] = phpversion(); |
| 245 |
$tmp_check_data['php_ok'] = version_compare(PHP_VERSION, '7.2', '>='); |
| 246 |
|
| 247 |
// WooCommerce version check |
| 248 |
$tmp_check_data['woo_version'] = ''; |
| 249 |
if ($tmp_check_data['woocomerce_installed'] && function_exists('WC')) { |
| 250 |
$tmp_check_data['woo_version'] = WC()->version; |
| 251 |
} |
| 252 |
|
| 253 |
$tmp_check_data['firewall_active'] = false; |
| 254 |
$tmp_check_data['cloudflare_active'] = false; |
| 255 |
$tmp_check_data['firewall_name'] = ''; |
| 256 |
|
| 257 |
// Check for blocking plugins only if not connected |
| 258 |
if ($store_connected == FALSE) |
| 259 |
{ |
| 260 |
// Cloudflare check |
| 261 |
$data = array( |
| 262 |
'store' => get_site_url(), |
| 263 |
'event' => 'check_cloudflare' |
| 264 |
); |
| 265 |
|
| 266 |
$cloudflare_check = importify_send_request('/woocomerce/status', $data); |
| 267 |
|
| 268 |
if ($cloudflare_check && isset($cloudflare_check['success']) && $cloudflare_check['success'] == 1) |
| 269 |
{ |
| 270 |
if (isset($cloudflare_check['cloudflare_enabled']) && $cloudflare_check['cloudflare_enabled'] == "true") |
| 271 |
{ |
| 272 |
$tmp_check_data['cloudflare_active'] = true; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
// Firewall/security plugin detection (expanded list) |
| 277 |
$firewall_plugins = array( |
| 278 |
'wordfence', 'jetpack', 'sucuri', 'ninjafirewall', |
| 279 |
'ithemes-security', 'better-wp-security', 'solid-security', |
| 280 |
'all-in-one-wp-security', 'aios-security', |
| 281 |
'shield-security', 'wp-simple-firewall', |
| 282 |
'malcare', 'developer-developer', |
| 283 |
'defender-security', 'wp-defender', |
| 284 |
'cerber', 'wp-cerber', |
| 285 |
'bulletproof', 'bulletproof-security', |
| 286 |
'secupress', |
| 287 |
); |
| 288 |
|
| 289 |
$plugin_list = get_plugins(); |
| 290 |
|
| 291 |
foreach ($plugin_list as $key => $value) |
| 292 |
{ |
| 293 |
$plugin_name = strtolower($value['Name']); |
| 294 |
$plugin_slug = strtolower($key); |
| 295 |
|
| 296 |
foreach ($firewall_plugins as $fw) |
| 297 |
{ |
| 298 |
if (strpos($plugin_name, $fw) !== FALSE || strpos($plugin_slug, $fw) !== FALSE) |
| 299 |
{ |
| 300 |
// Only flag if the plugin is actually active |
| 301 |
if (is_plugin_active($key)) |
| 302 |
{ |
| 303 |
$tmp_check_data['firewall_active'] = true; |
| 304 |
$tmp_check_data['firewall_name'] = $value['Name']; |
| 305 |
break 2; |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
update_option('importify_check', $tmp_check_data); |
| 313 |
|
| 314 |
include_once IMPORTIFY_PATH . '/views/importify_admin_page.php'; |
| 315 |
} |
| 316 |
|
| 317 |
function importify_send_request($path, $data) |
| 318 |
{ |
| 319 |
try |
| 320 |
{ |
| 321 |
$headers = array( |
| 322 |
'Content-Type' => 'application/json', |
| 323 |
'User-Agent' => 'Importify Wp Plugin', |
| 324 |
'x-plugin-version' => IMPORTIFY_VERSION, |
| 325 |
'x-site-url' => get_site_url(), |
| 326 |
'x-wp-version' => get_bloginfo('version'), |
| 327 |
); |
| 328 |
|
| 329 |
if (importify_has_woocommerce() && function_exists('WC')) |
| 330 |
{ |
| 331 |
$headers['x-woo-version'] = WC()->version; |
| 332 |
} |
| 333 |
|
| 334 |
$url = IMPORTIFY_API_URL . $path; |
| 335 |
$args = array( |
| 336 |
'headers' => $headers, |
| 337 |
'body' => json_encode($data), |
| 338 |
'method' => 'POST', |
| 339 |
'data_format' => 'body', |
| 340 |
'sslverify' => false, |
| 341 |
'timeout' => 15, |
| 342 |
); |
| 343 |
|
| 344 |
$response = wp_remote_post($url, $args); |
| 345 |
|
| 346 |
if (is_wp_error($response)) |
| 347 |
{ |
| 348 |
// Log the error for diagnostics |
| 349 |
update_option('importify_last_error', $response->get_error_message()); |
| 350 |
return 0; |
| 351 |
} |
| 352 |
|
| 353 |
$decoded_response = json_decode(wp_remote_retrieve_body($response), true); |
| 354 |
return $decoded_response; |
| 355 |
} |
| 356 |
catch (Exception $err) |
| 357 |
{ |
| 358 |
update_option('importify_last_error', $err->getMessage()); |
| 359 |
return 0; |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
function importify_plugin_redirect() |
| 365 |
{ |
| 366 |
exit(wp_redirect("admin.php?page=Importify")); |
| 367 |
} |
| 368 |
|
| 369 |
function importify_clear_all_caches() |
| 370 |
{ |
| 371 |
try |
| 372 |
{ |
| 373 |
global $wp_fastest_cache; |
| 374 |
|
| 375 |
if (function_exists('w3tc_flush_all')) |
| 376 |
{ |
| 377 |
w3tc_flush_all(); |
| 378 |
} |
| 379 |
|
| 380 |
if (function_exists('wp_cache_clean_cache')) |
| 381 |
{ |
| 382 |
global $file_prefix, $supercachedir; |
| 383 |
|
| 384 |
if (empty($supercachedir) && function_exists('get_supercache_dir')) |
| 385 |
{ |
| 386 |
$supercachedir = get_supercache_dir(); |
| 387 |
} |
| 388 |
wp_cache_clean_cache($file_prefix); |
| 389 |
} |
| 390 |
|
| 391 |
if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) |
| 392 |
{ |
| 393 |
$wp_fastest_cache->deleteCache(); |
| 394 |
} |
| 395 |
|
| 396 |
if (function_exists('rocket_clean_domain')) |
| 397 |
{ |
| 398 |
rocket_clean_domain(); |
| 399 |
if (function_exists('run_rocket_sitemap_preload')) { |
| 400 |
run_rocket_sitemap_preload(); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall")) |
| 405 |
{ |
| 406 |
autoptimizeCache::clearall(); |
| 407 |
} |
| 408 |
|
| 409 |
if (class_exists("LiteSpeed_Cache_API") && method_exists("LiteSpeed_Cache_API", "purge_all")) |
| 410 |
{ |
| 411 |
LiteSpeed_Cache_API::purge_all(); |
| 412 |
} |
| 413 |
|
| 414 |
if (class_exists('\Hummingbird\Core\Utils')) |
| 415 |
{ |
| 416 |
$modules = \Hummingbird\Core\Utils::get_active_cache_modules(); |
| 417 |
foreach ($modules as $module => $name) |
| 418 |
{ |
| 419 |
$mod = \Hummingbird\Core\Utils::get_module($module); |
| 420 |
|
| 421 |
if ($mod->is_active()) |
| 422 |
{ |
| 423 |
if ('minify' === $module) |
| 424 |
{ |
| 425 |
$mod->clear_files(); |
| 426 |
} |
| 427 |
else |
| 428 |
{ |
| 429 |
$mod->clear_cache(); |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
catch (Exception $e) |
| 436 |
{ |
| 437 |
return 1; |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
?> |
| 442 |
|