Amélioration affichage notice admin
This commit is contained in:
parent
ed0371b165
commit
8d0b591665
@ -37,6 +37,9 @@ class PEPPOL_Plugin {
|
|||||||
if (class_exists(\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class)) {
|
if (class_exists(\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::class)) {
|
||||||
\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::register_hooks();
|
\ESI_PEPPOL\controllers\PEPPOL_Woocommerce_controller::register_hooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notice globale pour le numéro de TVA
|
||||||
|
\add_action('admin_notices', [self::class, 'maybe_show_vat_notice']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -761,6 +764,34 @@ class PEPPOL_Plugin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Affiche un message d'avertissement dans l'admin WordPress
|
||||||
|
* si le numéro de TVA de la boutique n'est pas renseigné.
|
||||||
|
*
|
||||||
|
* Hooké sur admin_notices.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function maybe_show_vat_notice(): void {
|
||||||
|
if (!\current_user_can('manage_options')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$vat_notice_message = self::get_vat_notice_message();
|
||||||
|
|
||||||
|
if (empty($vat_notice_message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$api_key = (string) \get_option('esi_peppol_api_key', '');
|
||||||
|
$password = (string) \get_option('esi_peppol_password', '');
|
||||||
|
$notice_class = ($api_key === '' && $password === '') ? 'notice-info' : 'notice-warning';
|
||||||
|
|
||||||
|
echo '<div class="notice ' . \esc_attr($notice_class) . '"><p>' .
|
||||||
|
\esc_html($vat_notice_message) .
|
||||||
|
'</p></div>';
|
||||||
|
}
|
||||||
|
|
||||||
public static function write_log($message, $level = 'INFO') {
|
public static function write_log($message, $level = 'INFO') {
|
||||||
$message = self::format_message_for_log($message);
|
$message = self::format_message_for_log($message);
|
||||||
$log_entry = sprintf("[%s] [%s] %s\n", date('Y-m-d H:i:s'), $level, $message);
|
$log_entry = sprintf("[%s] [%s] %s\n", date('Y-m-d H:i:s'), $level, $message);
|
||||||
|
|||||||
@ -159,7 +159,7 @@ class PEPPOL_Woocommerce_controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Affiche un message d'avertissement dans l'admin WooCommerce
|
* Affiche un message d'avertissement dans l'admin WordPress
|
||||||
* si BACS est activé mais qu'aucun compte bancaire n'est renseigné.
|
* si BACS est activé mais qu'aucun compte bancaire n'est renseigné.
|
||||||
*
|
*
|
||||||
* Hooké sur admin_notices.
|
* Hooké sur admin_notices.
|
||||||
@ -171,18 +171,6 @@ class PEPPOL_Woocommerce_controller {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$screen = \function_exists('get_current_screen') ? \get_current_screen() : null;
|
|
||||||
|
|
||||||
// On cible la page WooCommerce > Réglages > Paiements
|
|
||||||
if (!$screen || (string) $screen->id !== 'woocommerce_page_wc-settings') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tab = isset($_GET['tab']) ? \sanitize_text_field(\wp_unslash($_GET['tab'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
if ($tab !== 'checkout') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$status = self::my_check_bacs_status_and_accounts();
|
$status = self::my_check_bacs_status_and_accounts();
|
||||||
|
|
||||||
// Si BACS n'est pas installé ou pas activé, on ne dit rien
|
// Si BACS n'est pas installé ou pas activé, on ne dit rien
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user