102 lines
3.4 KiB
PHP
102 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Flysystem Offload
|
|
* Plugin URI: https://git.brasdrive.com.br/Brasdrive/flysystem-offload
|
|
* Description: Universal storage offloading for WordPress via Flysystem
|
|
* Version: 3.0.0
|
|
* Requires at least: 6.0
|
|
* Requires PHP: 8.1
|
|
* Author: Brasdrive
|
|
* Author URI: https://brasdrive.com.br
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: flysystem-offload
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
// Evitar acceso directo
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Definir constantes del plugin
|
|
define('FLYSYSTEM_OFFLOAD_VERSION', '3.0.0');
|
|
define('FLYSYSTEM_OFFLOAD_PLUGIN_FILE', __FILE__);
|
|
define('FLYSYSTEM_OFFLOAD_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
define('FLYSYSTEM_OFFLOAD_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
|
|
// Definir ruta de configuración (buscar en config/ del plugin)
|
|
if (!defined('FLYSYSTEM_OFFLOAD_CONFIG_PATH')) {
|
|
define('FLYSYSTEM_OFFLOAD_CONFIG_PATH', FLYSYSTEM_OFFLOAD_PLUGIN_DIR . 'config');
|
|
}
|
|
|
|
// Cargar autoloader de Composer
|
|
$autoloader = FLYSYSTEM_OFFLOAD_PLUGIN_DIR . 'vendor/autoload.php';
|
|
|
|
if (!file_exists($autoloader)) {
|
|
add_action('admin_notices', function (): void {
|
|
printf(
|
|
'<div class="notice notice-error"><p><strong>Flysystem Offload:</strong> %s</p></div>',
|
|
esc_html__('Composer dependencies not installed. Please run: composer install', 'flysystem-offload')
|
|
);
|
|
});
|
|
return;
|
|
}
|
|
|
|
require_once $autoloader;
|
|
|
|
// Inicializar el plugin cuando WordPress esté listo
|
|
add_action('plugins_loaded', function (): void {
|
|
try {
|
|
FlysystemOffload\Plugin::bootstrap();
|
|
} catch (Throwable $e) {
|
|
error_log('[Flysystem Offload] Error al iniciar el plugin: ' . $e->getMessage());
|
|
|
|
// Mostrar error solo a administradores
|
|
if (is_admin() && current_user_can('manage_options')) {
|
|
add_action('admin_notices', function () use ($e): void {
|
|
printf(
|
|
'<div class="notice notice-error"><p><strong>Flysystem Offload:</strong> %s</p></div>',
|
|
esc_html($e->getMessage())
|
|
);
|
|
});
|
|
}
|
|
}
|
|
}, 10);
|
|
|
|
// Hook de activación
|
|
register_activation_hook(__FILE__, function (): void {
|
|
// Verificar requisitos
|
|
if (version_compare(PHP_VERSION, '8.1', '<')) {
|
|
deactivate_plugins(plugin_basename(__FILE__));
|
|
wp_die(
|
|
esc_html__('Flysystem Offload requires PHP 8.1 or higher.', 'flysystem-offload'),
|
|
esc_html__('Plugin Activation Error', 'flysystem-offload'),
|
|
['back_link' => true]
|
|
);
|
|
}
|
|
|
|
// Crear directorio de configuración si no existe
|
|
$configDir = FLYSYSTEM_OFFLOAD_CONFIG_PATH;
|
|
if (!file_exists($configDir)) {
|
|
wp_mkdir_p($configDir);
|
|
}
|
|
|
|
// Copiar archivo de ejemplo si no existe configuración
|
|
$configFile = $configDir . '/flysystem-offload.php';
|
|
$exampleFile = $configDir . '/flysystem-offload.example.php';
|
|
|
|
if (!file_exists($configFile) && file_exists($exampleFile)) {
|
|
copy($exampleFile, $configFile);
|
|
}
|
|
});
|
|
|
|
// Hook de desactivación
|
|
register_deactivation_hook(__FILE__, function (): void {
|
|
// Desregistrar stream wrapper si existe
|
|
if (in_array('fly', stream_get_wrappers(), true)) {
|
|
stream_wrapper_unregister('fly');
|
|
}
|
|
});
|