save_settings(); } // Récupérer les paramètres actuels $settings = get_option('almaweb_settings', array()); // Enqueue inline script pour les actions AJAX $settings_script = 'jQuery(document).ready(function($) { $("#cleanup-old-logs").on("click", function() { if (confirm("' . esc_js(__('Are you sure you want to clean old logs?', 'almaweb-ai-visitor-analytics')) . '")) { $.post(ajaxurl, { action: "Almaweb_cleanup", nonce: "' . wp_create_nonce('Almaweb_cleanup') . '" }, function(response) { if (response.success) { alert(response.data.message); location.reload(); } else { alert("Erreur: " + response.data.message); } }); } }); $("#reset-all-data").on("click", function() { if (confirm("' . esc_js(__('WARNING: This will delete ALL data! Are you absolutely sure?', 'almaweb-ai-visitor-analytics')) . '")) { if (confirm("' . esc_js(__('Final confirmation: This action is IRREVERSIBLE!', 'almaweb-ai-visitor-analytics')) . '")) { var $button = $(this); $button.prop("disabled", true).text("' . esc_js(__('Deleting...', 'almaweb-ai-visitor-analytics')) . '"); $.post(ajaxurl, { action: "Almaweb_reset", nonce: "' . wp_create_nonce('Almaweb_reset') . '" }, function(response) { if (response.success) { alert(response.data.message); location.reload(); } else { alert("Erreur: " + response.data.message); $button.prop("disabled", false).text("' . esc_js(__('Delete all', 'almaweb-ai-visitor-analytics')) . '"); } }).fail(function(xhr, status, error) { alert("Erreur de connexion: " + error); console.error("AJAX Error:", xhr.responseText); $button.prop("disabled", false).text("' . esc_js(__('⚠️ Delete all', 'almaweb-ai-visitor-analytics')) . '"); }); } } }); });'; wp_add_inline_script('almaweb-ai-visitor-analytics-admin', $settings_script); ?>

__('Training', 'almaweb-ai-visitor-analytics'), 'scraping' => __('Scraping', 'almaweb-ai-visitor-analytics'), 'inference' => __('Inference', 'almaweb-ai-visitor-analytics'), 'search' => __('Search', 'almaweb-ai-visitor-analytics')] as $key => $label) : ?>

get_storage_stats(); ?>
db_version()); ?>
MB
isset($_POST['track_enabled']) ? true : false, 'track_registered_users' => isset($_POST['track_registered_users']) ? true : false, 'retention_days' => isset($_POST['retention_days']) ? intval(wp_unslash($_POST['retention_days'])) : 90, 'blocked_intentions' => array_map('sanitize_text_field', $blocked_intentions_raw), 'blocked_families' => array_map('sanitize_text_field', $blocked_families_raw), 'report_enabled' => isset($_POST['report_enabled']) ? true : false, 'report_email' => $report_email, 'report_day' => $report_day, ); // Reschedule weekly report cron when settings change wp_clear_scheduled_hook('almaweb_weekly_report'); if (!empty($settings['report_enabled'])) { $next = $this->get_next_weekday_timestamp($report_day); wp_schedule_event($next, 'weekly', 'almaweb_weekly_report'); } update_option('almaweb_settings', $settings); add_settings_error( 'Almaweb_settings', 'settings_updated', __('Settings saved successfully.', 'almaweb-ai-visitor-analytics'), 'updated' ); settings_errors('Almaweb_settings'); } private function get_next_weekday_timestamp($day) { $now = current_time('timestamp'); $diff = ($day - (int) gmdate('w', $now) + 7) % 7; $diff = $diff === 0 ? 7 : $diff; return strtotime("+{$diff} days midnight", $now); } } // Ajouter les actions AJAX add_action('wp_ajax_Almaweb_cleanup', 'Almaweb_ajax_cleanup'); add_action('wp_ajax_Almaweb_reset', 'Almaweb_ajax_reset'); function Almaweb_ajax_cleanup() { check_ajax_referer('Almaweb_cleanup', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => 'Unauthorized')); } $settings = get_option('almaweb_settings'); $database = new Almaweb_Database(); $deleted = $database->cleanup_old_logs($settings['retention_days'] ?? 90); wp_send_json_success(array( // translators: %d is the number of deleted logs 'message' => sprintf(__('%d logs deleted.', 'almaweb-ai-visitor-analytics'), $deleted) )); } function Almaweb_ajax_reset() { check_ajax_referer('Almaweb_reset', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => 'Unauthorized')); } $database = new Almaweb_Database(); $database->reset_all_data(); wp_send_json_success(array( 'message' => __('All data has been deleted.', 'almaweb-ai-visitor-analytics') )); }