| 1 |
<?php |
| 2 |
// if uninstall.php is not called by WordPress, die |
| 3 |
|
| 4 |
use ImportWP\Common\Importer\ImporterManager; |
| 5 |
use ImportWP\Common\Migration\Migrations; |
| 6 |
use ImportWP\Container; |
| 7 |
|
| 8 |
if (!defined('WP_UNINSTALL_PLUGIN')) { |
| 9 |
die; |
| 10 |
} |
| 11 |
|
| 12 |
do_action('iwp/uninstall_plugin'); |
| 13 |
|
| 14 |
// Escape if cleanup has not been enabled. |
| 15 |
$uninstall_enabled = get_option('iwp_settings'); |
| 16 |
if (!isset($uninstall_enabled['cleanup']) || true !== $uninstall_enabled['cleanup']) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$iwp_base_path = dirname(__FILE__); |
| 21 |
if (file_exists($iwp_base_path . '/importwp-pro.php')) { |
| 22 |
require_once $iwp_base_path . '/importwp-pro.php'; |
| 23 |
} else { |
| 24 |
require_once $iwp_base_path . '/jc-importer.php'; |
| 25 |
} |
| 26 |
|
| 27 |
// 1. Delete all importers, Delete all importer files |
| 28 |
|
| 29 |
/** |
| 30 |
* @var ImporterManager $importer_manager |
| 31 |
*/ |
| 32 |
$importer_manager = Container::getInstance()->get('importer_manager'); |
| 33 |
$importers = $importer_manager->get_importers(); |
| 34 |
foreach ($importers as $importer) { |
| 35 |
|
| 36 |
$files = $importer->getFiles(); |
| 37 |
foreach ($files as $file) { |
| 38 |
@unlink($file); |
| 39 |
} |
| 40 |
|
| 41 |
$importer->delete(); |
| 42 |
} |
| 43 |
|
| 44 |
// 2. Delete /wp-content/importwp folder |
| 45 |
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; |
| 46 |
$fileSystemDirect = new \WP_Filesystem_Direct(false); |
| 47 |
$upload_dir = wp_upload_dir(); |
| 48 |
|
| 49 |
$fileSystemDirect->rmdir($upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'importwp', true); |
| 50 |
$fileSystemDirect->rmdir($upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'exportwp', true); |
| 51 |
|
| 52 |
|
| 53 |
// 3. Uninstall DB |
| 54 |
$migrations = new Migrations(); |
| 55 |
$migrations->uninstall(); |
| 56 |
|