<?php

declare(strict_types=1);

if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}

if (!defined('SHIELDX_PLUGIN_DIR')) {
    define('SHIELDX_PLUGIN_DIR', __DIR__ . '/');
}

if (!defined('SHIELDX_PLUGINS_DIR')) {
    $shieldxPluginsDir = rtrim(str_replace('\\', '/', dirname(__DIR__)), '/') . '/';
    define('SHIELDX_PLUGINS_DIR', $shieldxPluginsDir);
}

if (!defined('SHIELDX_CONTENT_DIR')) {
    $shieldxContentDir = '';
    if (function_exists('wp_upload_dir')) {
        $shieldxUploads = wp_upload_dir(null, false);
        if (is_array($shieldxUploads) && !empty($shieldxUploads['basedir']) && is_scalar($shieldxUploads['basedir'])) {
            $shieldxUploadsDir = rtrim(str_replace('\\', '/', (string) $shieldxUploads['basedir']), '/');
            $shieldxUploadsMarker = '/uploads';
            $shieldxUploadsPos = strpos($shieldxUploadsDir . '/', $shieldxUploadsMarker . '/');
            if ($shieldxUploadsPos !== false) {
                $shieldxContentDir = rtrim(substr($shieldxUploadsDir, 0, (int) $shieldxUploadsPos), '/') . '/';
            }
        }
    }
    if ($shieldxContentDir === '') {
        $shieldxContentDir = rtrim(str_replace('\\', '/', dirname(rtrim((string) SHIELDX_PLUGINS_DIR, '/'))), '/') . '/';
    }
    define('SHIELDX_CONTENT_DIR', $shieldxContentDir);
}

unset($shieldxPluginsDir, $shieldxContentDir, $shieldxUploads, $shieldxUploadsDir, $shieldxUploadsMarker, $shieldxUploadsPos);

require_once SHIELDX_PLUGIN_DIR . 'includes/Autoloader.php';

\ShieldX\Autoloader::register(SHIELDX_PLUGIN_DIR . 'includes');
\ShieldX\Core\Uninstaller::uninstall();
