Ajout sécurité d'activation
This commit is contained in:
parent
3004e3855e
commit
87e80dd93f
130
ESI_peppol.php
130
ESI_peppol.php
@ -1,22 +1,124 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* Plugin Name: ESI_peppol
|
* Plugin Name: ESI_peppol
|
||||||
* Description: Woocommerce peppol gateway
|
* Description: Woocommerce peppol gateway
|
||||||
* Version: 0.1.0
|
* Version: 0.1.0
|
||||||
* Author: Esi informatique
|
* Author: Esi informatique
|
||||||
* Text Domain: esi_peppol
|
* Text Domain: esi_peppol
|
||||||
|
* RequiresPHP: 7.0
|
||||||
|
* RequiresPlugins: woocommerce/woocommerce.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
define('ESI_PEPPOL_VERSION', '0.1.0');
|
|
||||||
define('ESI_PEPPOL_DIR', plugin_dir_path(__FILE__));
|
|
||||||
define('ESI_PEPPOL_URL', plugin_dir_url(__FILE__));
|
|
||||||
|
|
||||||
if (!defined('ABSPATH')) {
|
if (!defined('ABSPATH')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vérification de la version minimale de PHP requise
|
||||||
|
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
|
||||||
|
// Afficher un message d'erreur dans l'admin
|
||||||
|
add_action('admin_notices', function () {
|
||||||
|
if (!function_exists('esc_html__') || !function_exists('esc_html')) {
|
||||||
|
// Fallback si les fonctions WordPress ne sont pas encore chargées
|
||||||
|
echo '<div class="notice notice-error"><p><strong>ESI Peppol</strong> : Ce plugin nécessite PHP 7.0.0 ou supérieur. Vous utilisez actuellement PHP ' . htmlspecialchars(PHP_VERSION, ENT_QUOTES, 'UTF-8') . '. Veuillez mettre à jour votre version de PHP.</p></div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="notice notice-error">
|
||||||
|
<p>
|
||||||
|
<strong><?php esc_html_e('ESI Peppol', 'esi_peppol'); ?></strong> :
|
||||||
|
<?php
|
||||||
|
printf(
|
||||||
|
/* translators: 1: Version PHP actuelle, 2: Version PHP minimale requise */
|
||||||
|
esc_html__('Ce plugin nécessite PHP %2$s ou supérieur. Vous utilisez actuellement PHP %1$s. Veuillez mettre à jour votre version de PHP.', 'esi_peppol'),
|
||||||
|
esc_html(PHP_VERSION),
|
||||||
|
'7.0.0'
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
});
|
||||||
|
|
||||||
|
// Désactiver le plugin si la version PHP est trop ancienne
|
||||||
|
add_action('admin_init', function () {
|
||||||
|
if (function_exists('deactivate_plugins') && function_exists('plugin_basename')) {
|
||||||
|
deactivate_plugins(plugin_basename(__FILE__));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonction pour vérifier si WooCommerce est actif
|
||||||
|
function esi_peppol_is_woocommerce_active(): bool {
|
||||||
|
// Vérifier si la classe WooCommerce existe (WooCommerce chargé)
|
||||||
|
if (class_exists('WooCommerce')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si WooCommerce est dans la liste des plugins actifs
|
||||||
|
if (!function_exists('is_plugin_active')) {
|
||||||
|
if (file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) {
|
||||||
|
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (function_exists('is_plugin_active')) {
|
||||||
|
return is_plugin_active('woocommerce/woocommerce.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback : vérifier dans la liste des plugins actifs
|
||||||
|
$active_plugins = get_option('active_plugins', []);
|
||||||
|
if (in_array('woocommerce/woocommerce.php', $active_plugins, true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier aussi dans les plugins réseau (multisite)
|
||||||
|
if (is_multisite()) {
|
||||||
|
$network_plugins = get_site_option('active_sitewide_plugins', []);
|
||||||
|
if (isset($network_plugins['woocommerce/woocommerce.php'])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérification de la dépendance WooCommerce
|
||||||
|
if (!esi_peppol_is_woocommerce_active()) {
|
||||||
|
// Afficher un message d'erreur dans l'admin
|
||||||
|
add_action('admin_notices', function () {
|
||||||
|
if (!function_exists('esc_html__') || !function_exists('esc_html')) {
|
||||||
|
// Fallback si les fonctions WordPress ne sont pas encore chargées
|
||||||
|
echo '<div class="notice notice-error"><p><strong>ESI Peppol</strong> : Ce plugin nécessite WooCommerce. Veuillez installer et activer WooCommerce avant d\'utiliser ce plugin.</p></div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="notice notice-error">
|
||||||
|
<p>
|
||||||
|
<strong><?php esc_html_e('ESI Peppol', 'esi_peppol'); ?></strong> :
|
||||||
|
<?php esc_html_e('Ce plugin nécessite WooCommerce. Veuillez installer et activer WooCommerce avant d\'utiliser ce plugin.', 'esi_peppol'); ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
});
|
||||||
|
|
||||||
|
// Désactiver le plugin si WooCommerce n'est pas disponible
|
||||||
|
add_action('admin_init', function () {
|
||||||
|
if (function_exists('deactivate_plugins') && function_exists('plugin_basename')) {
|
||||||
|
deactivate_plugins(plugin_basename(__FILE__));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Empêcher le chargement du reste du plugin
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
define('ESI_PEPPOL_VERSION', '0.1.0');
|
||||||
|
define('ESI_PEPPOL_DIR', plugin_dir_path(__FILE__));
|
||||||
|
define('ESI_PEPPOL_URL', plugin_dir_url(__FILE__));
|
||||||
|
|
||||||
use ESI_PEPPOL\controllers\PEPPOL_Plugin;
|
use ESI_PEPPOL\controllers\PEPPOL_Plugin;
|
||||||
|
|
||||||
// Autoloader simple pour les classes PEPPOL (contrôleurs, modèles...) et celles avec namespace
|
// Autoloader simple pour les classes PEPPOL (contrôleurs, modèles...) et celles avec namespace
|
||||||
@ -110,10 +212,22 @@ spl_autoload_register(function ($class) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hook d'activation du plugin : délègue à PEPPOL_Plugin::activate()
|
// Hook d'activation du plugin avec vérification WooCommerce
|
||||||
register_activation_hook(
|
register_activation_hook(
|
||||||
__FILE__,
|
__FILE__,
|
||||||
[PEPPOL_Plugin::class, 'activate']
|
function () {
|
||||||
|
// Vérifier si WooCommerce est actif avant l'activation
|
||||||
|
if (!esi_peppol_is_woocommerce_active()) {
|
||||||
|
deactivate_plugins(plugin_basename(__FILE__));
|
||||||
|
wp_die(
|
||||||
|
esc_html__('ESI Peppol nécessite WooCommerce pour fonctionner. Veuillez installer et activer WooCommerce avant d\'activer ce plugin.', 'esi_peppol'),
|
||||||
|
esc_html__('Dépendance manquante', 'esi_peppol'),
|
||||||
|
['back_link' => true]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Déléguer à PEPPOL_Plugin::activate() si WooCommerce est disponible
|
||||||
|
PEPPOL_Plugin::activate();
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Menu et pages d'administration du plugin
|
// Menu et pages d'administration du plugin
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user