| 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.5 |
| 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.5'); |
| 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 |
$response = importify_send_request('/woocomerce/status', $data); |
| 44 |
|
| 45 |
if ($response) |
| 46 |
{ |
| 47 |
if ($response['success'] > 0) |
| 48 |
{ |
| 49 |
|
| 50 |
if (!get_option('importify_api_key')) |
| 51 |
{ |
| 52 |
add_option('importify_api_key',$response['api_key']); |
| 53 |
|
| 54 |
if (class_exists("WC_Auth")) |
| 55 |
{ |
| 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 |
$auth = new importify_AuthCustom(); |
| 65 |
$keys = $auth->getKeys($response['app_name'], $response['user_id'], $response['scope']); |
| 66 |
$data = array( |
| 67 |
'store' => get_site_url(), |
| 68 |
'keys' => $keys, |
| 69 |
'user_id' => $response['user_id'], |
| 70 |
'event' => 'update_keys' |
| 71 |
); |
| 72 |
$keys_response = importify_send_request('/woocomerce/status', $data); |
| 73 |
|
| 74 |
if ($keys_response && $keys_response['success'] == 0) |
| 75 |
{ |
| 76 |
add_option('importify_error', 'yes'); |
| 77 |
add_option('importify_error_message', $keys_response['message']); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
update_option('importify_api_key', $response['api_key']); |
| 84 |
} |
| 85 |
} |
| 86 |
else |
| 87 |
{ |
| 88 |
|
| 89 |
if (!get_option('importify_error')) |
| 90 |
{ |
| 91 |
add_option('importify_error', 'yes'); |
| 92 |
add_option('importify_error_message', 'Error activation plugin!'); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
else |
| 97 |
{ |
| 98 |
|
| 99 |
if (!get_option('importify_error')) |
| 100 |
{ |
| 101 |
add_option('importify_error', 'yes'); |
| 102 |
add_option('importify_error_message', 'Error activation plugin!'); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
function importify_deactivation_hook() |
| 108 |
{ |
| 109 |
if(!current_user_can('activate_plugins')) |
| 110 |
{ |
| 111 |
return; |
| 112 |
} |
| 113 |
$data = array( |
| 114 |
'store' => get_site_url(), |
| 115 |
'event' => 'deactivated', |
| 116 |
); |
| 117 |
return importify_send_request('/woocomerce/status', $data); |
| 118 |
} |
| 119 |
|
| 120 |
function importify_uninstall_hook() |
| 121 |
{ |
| 122 |
if(!current_user_can('activate_plugins')) |
| 123 |
{ |
| 124 |
return; |
| 125 |
} |
| 126 |
|
| 127 |
delete_option('importify_api_key'); |
| 128 |
|
| 129 |
if (get_option('importify_error')) |
| 130 |
{ |
| 131 |
delete_option('importify_error'); |
| 132 |
} |
| 133 |
|
| 134 |
if (get_option('importify_error_message')) |
| 135 |
{ |
| 136 |
delete_option('importify_error_message'); |
| 137 |
} |
| 138 |
|
| 139 |
importify_clear_all_caches(); |
| 140 |
|
| 141 |
$data = array( |
| 142 |
'store' => get_site_url(), |
| 143 |
'event' => 'uninstall', |
| 144 |
); |
| 145 |
return importify_send_request('/woocomerce/status', $data); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
function importify_add_admin_css_js() |
| 150 |
{ |
| 151 |
wp_register_style('importify_style', IMPORTIFY_URL.'/assets/css/style.css'); |
| 152 |
wp_enqueue_style('importify_style'); |
| 153 |
wp_register_script('importify-admin', IMPORTIFY_URL.'/assets/js/script.js', array('jquery'), '1.0.0'); |
| 154 |
wp_enqueue_script('importify-admin'); |
| 155 |
} |
| 156 |
|
| 157 |
function importify_admin_menu() |
| 158 |
{ |
| 159 |
add_menu_page('Importify Settings', 'Importify', 'manage_options', 'importify', 'importify_admin_menu_page_html', IMPORTIFY_URL.'/assets/images/importify_icon.png'); |
| 160 |
} |
| 161 |
|
| 162 |
function importify_has_woocommerce() |
| 163 |
{ |
| 164 |
return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))); |
| 165 |
} |
| 166 |
|
| 167 |
function importify_admin_menu_page_html() |
| 168 |
{ |
| 169 |
$data = array( |
| 170 |
'store' => get_site_url(), |
| 171 |
'event' => 'check_status' |
| 172 |
); |
| 173 |
|
| 174 |
$status_response = importify_send_request('/woocomerce/status', $data); |
| 175 |
|
| 176 |
if ($status_response && $status_response['success'] == 0) |
| 177 |
{ |
| 178 |
add_option('importify_error', 'yes'); |
| 179 |
add_option('importify_error_message', $status_response['message']); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
if ($status_response && $status_response['success'] == 1) |
| 184 |
{ |
| 185 |
delete_option('importify_error'); |
| 186 |
delete_option('importify_error_message'); |
| 187 |
|
| 188 |
if(isset($status_response['keys_ok']) && $status_response['keys_ok'] == "no") |
| 189 |
{ |
| 190 |
if (class_exists("WC_Auth")) |
| 191 |
{ |
| 192 |
class importify_AuthCustom extends WC_Auth |
| 193 |
{ |
| 194 |
public function getKeys($app_name, $user_id, $scope) |
| 195 |
{ |
| 196 |
return parent::create_keys($app_name, $user_id, $scope); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
$auth = new importify_AuthCustom(); |
| 201 |
$keys = $auth->getKeys($status_response['app_name'], $status_response['user_id'], $status_response['scope']); |
| 202 |
|
| 203 |
$data = array( |
| 204 |
'store' => get_site_url(), |
| 205 |
'keys' => $keys, |
| 206 |
'user_id' => $status_response['user_id'], |
| 207 |
'event' => 'update_keys' |
| 208 |
); |
| 209 |
$keys_response = importify_send_request('/woocomerce/status', $data); |
| 210 |
|
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
if (!get_option('importify_api_key')) |
| 215 |
{ |
| 216 |
add_option('importify_api_key',$status_response['api_key']); |
| 217 |
} |
| 218 |
else |
| 219 |
{ |
| 220 |
update_option('importify_api_key',$status_response['api_key']); |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
include_once IMPORTIFY_PATH.'/views/importify_admin_page.php'; |
| 225 |
} |
| 226 |
|
| 227 |
function importify_send_request($path, $data) |
| 228 |
{ |
| 229 |
try |
| 230 |
{ |
| 231 |
$headers = array( |
| 232 |
'Content-Type' => 'application/json', |
| 233 |
'x-plugin-version' => IMPORTIFY_VERSION, |
| 234 |
'x-site-url' => get_site_url(), |
| 235 |
'x-wp-version' => get_bloginfo('version'), |
| 236 |
); |
| 237 |
|
| 238 |
if (importify_has_woocommerce()) |
| 239 |
{ |
| 240 |
$headers['x-woo-version'] = WC()->version; |
| 241 |
} |
| 242 |
|
| 243 |
$url = IMPORTIFY_API_URL.$path; |
| 244 |
$data = array( |
| 245 |
'headers' => $headers, |
| 246 |
'body' => json_encode($data), |
| 247 |
'method' => 'POST', |
| 248 |
'data_format' => 'body', |
| 249 |
'sslverify' => false |
| 250 |
); |
| 251 |
|
| 252 |
$response = wp_remote_post($url, $data); |
| 253 |
|
| 254 |
if (!is_wp_error($response)) |
| 255 |
{ |
| 256 |
$decoded_response = json_decode(wp_remote_retrieve_body($response), true); |
| 257 |
|
| 258 |
return $decoded_response; |
| 259 |
} |
| 260 |
|
| 261 |
return 0; |
| 262 |
} |
| 263 |
catch(Exception $err) |
| 264 |
{ |
| 265 |
if(IMPORTIFY_DEBUG) |
| 266 |
{ |
| 267 |
echo $err; |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
function importify_plugin_redirect() |
| 274 |
{ |
| 275 |
exit(wp_redirect("admin.php?page=Importify")); |
| 276 |
} |
| 277 |
|
| 278 |
function importify_clear_all_caches() |
| 279 |
{ |
| 280 |
try |
| 281 |
{ |
| 282 |
global $wp_fastest_cache; |
| 283 |
|
| 284 |
if (function_exists('w3tc_flush_all')) |
| 285 |
{ |
| 286 |
w3tc_flush_all(); |
| 287 |
} |
| 288 |
|
| 289 |
if (function_exists('wp_cache_clean_cache')) |
| 290 |
{ |
| 291 |
global $file_prefix, $supercachedir; |
| 292 |
|
| 293 |
if (empty($supercachedir) && function_exists('get_supercache_dir')) |
| 294 |
{ |
| 295 |
$supercachedir = get_supercache_dir(); |
| 296 |
} |
| 297 |
wp_cache_clean_cache($file_prefix); |
| 298 |
} |
| 299 |
|
| 300 |
if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) |
| 301 |
{ |
| 302 |
$wp_fastest_cache->deleteCache(); |
| 303 |
} |
| 304 |
|
| 305 |
if (function_exists('rocket_clean_domain')) |
| 306 |
{ |
| 307 |
rocket_clean_domain(); |
| 308 |
// Preload cache. |
| 309 |
if (function_exists('run_rocket_sitemap_preload')) { |
| 310 |
run_rocket_sitemap_preload(); |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall")) |
| 315 |
{ |
| 316 |
autoptimizeCache::clearall(); |
| 317 |
} |
| 318 |
|
| 319 |
if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all")) |
| 320 |
{ |
| 321 |
LiteSpeed_Cache_API::purge_all(); |
| 322 |
} |
| 323 |
|
| 324 |
if (class_exists('\Hummingbird\Core\Utils')) |
| 325 |
{ |
| 326 |
$modules= \Hummingbird\Core\Utils::get_active_cache_modules(); |
| 327 |
foreach ($modules as $module => $name) |
| 328 |
{ |
| 329 |
$mod = \Hummingbird\Core\Utils::get_module( $module ); |
| 330 |
|
| 331 |
if ($mod->is_active()) |
| 332 |
{ |
| 333 |
if ('minify' === $module) |
| 334 |
{ |
| 335 |
$mod->clear_files(); |
| 336 |
} |
| 337 |
else |
| 338 |
{ |
| 339 |
$mod->clear_cache(); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
catch (Exception $e) |
| 346 |
{ |
| 347 |
return 1; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
?> |