101 lines
3.4 KiB
PHP
101 lines
3.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace FlysystemOffload\Settings;
|
|
|
|
use FlysystemOffload\Plugin;
|
|
|
|
class SettingsPage
|
|
{
|
|
private const OPTION_KEY = 'flysystem_offload_settings';
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function getSettings(): array
|
|
{
|
|
$settings = get_option(self::OPTION_KEY, []);
|
|
|
|
return is_array($settings) ? $settings : [];
|
|
}
|
|
|
|
public function register(Plugin $plugin): void
|
|
{
|
|
add_action('admin_menu', function () {
|
|
add_options_page(
|
|
__('Flysystem Offload', 'flysystem-offload'),
|
|
__('Flysystem Offload', 'flysystem-offload'),
|
|
'manage_options',
|
|
'flysystem-offload',
|
|
[$this, 'renderPage']
|
|
);
|
|
});
|
|
|
|
add_action('admin_init', [$this, 'registerSettings']);
|
|
}
|
|
|
|
public function renderPage(): void
|
|
{
|
|
if (! current_user_can('manage_options')) {
|
|
wp_die(__('No tienes permisos para acceder a esta página.', 'flysystem-offload'));
|
|
}
|
|
|
|
$settings = $this->getSettings();
|
|
?>
|
|
<div class="wrap">
|
|
<h1><?php esc_html_e('Flysystem Offload', 'flysystem-offload'); ?></h1>
|
|
<p><?php esc_html_e('Configura el almacenamiento remoto para WordPress.', 'flysystem-offload'); ?></p>
|
|
|
|
<form action="options.php" method="post">
|
|
<?php
|
|
settings_fields('flysystem_offload');
|
|
do_settings_sections('flysystem-offload');
|
|
submit_button();
|
|
?>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
public function registerSettings(): void
|
|
{
|
|
register_setting('flysystem_offload', self::OPTION_KEY);
|
|
|
|
add_settings_section(
|
|
'flysystem_offload_general',
|
|
__('Configuración General', 'flysystem-offload'),
|
|
function () {
|
|
echo '<p>' . esc_html__(
|
|
'Introduce las credenciales del proveedor que deseas utilizar.',
|
|
'flysystem-offload'
|
|
) . '</p>';
|
|
},
|
|
'flysystem-offload'
|
|
);
|
|
|
|
add_settings_field(
|
|
'flysystem_offload_driver',
|
|
__('Driver', 'flysystem-offload'),
|
|
[$this, 'renderDriverField'],
|
|
'flysystem-offload',
|
|
'flysystem_offload_general'
|
|
);
|
|
}
|
|
|
|
public function renderDriverField(): void
|
|
{
|
|
$settings = $this->getSettings();
|
|
$driver = $settings['driver'] ?? '';
|
|
?>
|
|
<select name="<?php echo esc_attr(self::OPTION_KEY . '[driver]'); ?>">
|
|
<option value=""><?php esc_html_e('Selecciona un driver', 'flysystem-offload'); ?></option>
|
|
<option value="s3" <?php selected($driver, 's3'); ?>><?php esc_html_e('Amazon S3 / Compatible', 'flysystem-offload'); ?></option>
|
|
<option value="gcs" <?php selected($driver, 'gcs'); ?>><?php esc_html_e('Google Cloud Storage', 'flysystem-offload'); ?></option>
|
|
<option value="azure" <?php selected($driver, 'azure'); ?>><?php esc_html_e('Azure Blob Storage', 'flysystem-offload'); ?></option>
|
|
<option value="sftp" <?php selected($driver, 'sftp'); ?>><?php esc_html_e('SFTP', 'flysystem-offload'); ?></option>
|
|
<option value="webdav" <?php selected($driver, 'webdav'); ?>><?php esc_html_e('WebDAV', 'flysystem-offload'); ?></option>
|
|
</select>
|
|
<?php
|
|
}
|
|
}
|