/**
* Sauvegarde sécurisée des transporteurs
*/
public static function save_settings() {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
if ( empty( $_POST['lmr_settings_nonce'] ) || ! wp_verify_nonce( $_POST['lmr_settings_nonce'], 'lmr_save_settings' ) ) {
return;
}
// ================================
// Récupération ancien config (backup)
// ================================
$old_settings = get_option( 'lmr_exp_settings', [] );
if ( ! is_array( $old_settings ) ) {
$old_settings = [];
}
// Backup automatique
update_option( 'lmr_exp_settings_backup', $old_settings );
// ================================
// Reconstruction POST
// ================================
$new_settings = [
'carriers' => []
];
if ( empty( $_POST['carriers'] ) || ! is_array( $_POST['carriers'] ) ) {
// 🔴 REFUS TOTAL : pas de carriers
add_settings_error(
'lmr_settings',
'invalid_carriers',
'Sauvegarde refusée : aucun transporteur reçu.',
'error'
);
return;
}
foreach ( $_POST['carriers'] as $key => $carrier ) {
if ( empty( $key ) || ! is_array( $carrier ) ) {
continue;
}
// Validation minimale
if ( empty( $carrier['label'] ) ) {
continue;
}
$new_settings['carriers'][ $key ] = [
'enabled' => ! empty( $carrier['enabled'] ),
'label' => sanitize_text_field( $carrier['label'] ),
'type' => sanitize_text_field( $carrier['type'] ?? 'weight' ),
'max_kg' => isset( $carrier['max_kg'] ) ? floatval( $carrier['max_kg'] ) : 0,
];
// ================================
// TIERS (poids)
// ================================
if ( ! empty( $carrier['tiers'] ) && is_array( $carrier['tiers'] ) ) {
$tiers_clean = [];
foreach ( $carrier['tiers'] as $tier ) {
if ( ! is_array( $tier ) ) continue;
$max = isset( $tier['max_kg'] ) ? floatval( $tier['max_kg'] ) : 0;
$price = isset( $tier['price_ttc'] ) ? floatval( $tier['price_ttc'] ) : null;
if ( $max > 0 && $price !== null ) {
$tiers_clean[] = [
'max_kg' => $max,
'price_ttc' => $price
];
}
}
if ( ! empty( $tiers_clean ) ) {
$new_settings['carriers'][ $key ]['tiers'] = $tiers_clean;
}
}
// ================================
// LIMITES
// ================================
if ( ! empty( $carrier['limits'] ) && is_array( $carrier['limits'] ) ) {
$limits = [];
foreach ( $carrier['limits'] as $l_key => $l_val ) {
$limits[ $l_key ] = floatval( $l_val );
}
$new_settings['carriers'][ $key ]['limits'] = $limits;
}
// ================================
// LOCAL PRICING
// ================================
if ( ! empty( $carrier['pricing'] ) && is_array( $carrier['pricing'] ) ) {
$pricing_clean = [];
foreach ( $carrier['pricing'] as $rule ) {
if ( ! is_array( $rule ) ) continue;
$zip = sanitize_text_field( $rule['zip'] ?? '' );
$price = isset( $rule['price'] ) ? floatval( $rule['price'] ) : null;
if ( ! empty( $zip ) && $price !== null ) {
$pricing_clean[] = [
'zip' => $zip,
'price' => $price
];
}
}
if ( ! empty( $pricing_clean ) ) {
$new_settings['carriers'][ $key ]['pricing'] = $pricing_clean;
}
}
}
// ================================
// VALIDATION FINALE
// ================================
if ( empty( $new_settings['carriers'] ) ) {
// 🔴 RESTORE AUTOMATIQUE
update_option( 'lmr_exp_settings', $old_settings );
add_settings_error(
'lmr_settings',
'empty_after_parse',
'Sauvegarde annulée : configuration invalide. Ancienne configuration restaurée.',
'error'
);
return;
}
// ================================
// SAVE OK
// ================================
update_option( 'lmr_exp_settings', $new_settings );
add_settings_error(
'lmr_settings',
'saved_ok',
'Configuration enregistrée avec succès.',
'updated'
);
}
Fatal error: Uncaught Error: Class "LMR_Admin" not found in /home/lemarcx/www/wp-content/plugins/lmr-logistique-admin/lmr-logistique-admin.php:75
Stack trace:
#0 /home/lemarcx/www/wp-includes/class-wp-hook.php(341): {closure}('')
#1 /home/lemarcx/www/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array)
#2 /home/lemarcx/www/wp-includes/plugin.php(522): WP_Hook->do_action(Array)
#3 /home/lemarcx/www/wp-settings.php(593): do_action('plugins_loaded')
#4 /home/lemarcx/www/wp-config.php(93): require_once('/home/lemarcx/w...')
#5 /home/lemarcx/www/wp-load.php(50): require_once('/home/lemarcx/w...')
#6 /home/lemarcx/www/wp-blog-header.php(13): require_once('/home/lemarcx/w...')
#7 /home/lemarcx/www/index.php(17): require('/home/lemarcx/w...')
#8 {main}
thrown in /home/lemarcx/www/wp-content/plugins/lmr-logistique-admin/lmr-logistique-admin.php on line 75
Notice: La fonction _load_textdomain_just_in_time a été appelée de façon incorrecte. Le chargement de la traduction pour le domaine woocommerce a été déclenché trop tôt. Cela indique généralement que du code dans l’extension ou le thème s’exécute trop tôt. Les traductions doivent être chargées au moment de l’action init ou plus tard. Veuillez lire Débogage dans WordPress (en) pour plus d’informations. (Ce message a été ajouté à la version 6.7.0.) in /home/lemarcx/www/wp-includes/functions.php on line 6131