From 9375ca61a0dbfe6806f7def185e9499fdb8bbc18 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Sun, 14 Dec 2025 17:17:16 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feature:=20Add=20"Clear=20logs"=20func?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-admin.php | 40 +++++++++++++++++++++++++++++++++++++++ includes/class-logger.php | 9 +++++++++ 2 files changed, 49 insertions(+) diff --git a/includes/class-admin.php b/includes/class-admin.php index ad98670..73b17a2 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -55,6 +55,7 @@ class Admin { add_action( 'admin_post_site_sync_manual', array( $this, 'handle_manual_sync' ) ); add_action( 'admin_post_site_sync_handshake', array( $this, 'handle_handshake' ) ); add_action( 'admin_post_site_sync_reset_state', array( $this, 'handle_reset_state' ) ); + add_action( 'admin_post_site_sync_clear_logs', array( $this, 'handle_clear_logs' ) ); add_action( 'admin_notices', array( $this, 'maybe_render_notices' ) ); } @@ -185,6 +186,12 @@ class Admin { +

+
+ + + +

@@ -387,6 +394,13 @@ class Admin { esc_html__( 'Sync state reset. Next run will resend all items.', 'site-sync' ) ); } + + if ( isset( $_GET['site_sync_status'] ) && 'logs_cleared' === $_GET['site_sync_status'] ) { + printf( + '

%s

', + esc_html__( 'Recent logs cleared.', 'site-sync' ) + ); + } } /** @@ -426,6 +440,32 @@ class Admin { exit; } + /** + * Handles clearing the recent logs from the admin form submission. + * + * @return void + */ + public function handle_clear_logs(): void { + if ( ! current_user_can( 'manage_options' ) ) { + wp_die( esc_html__( 'You do not have permission to do this.', 'site-sync' ) ); + } + + check_admin_referer( 'site_sync_clear_logs', 'site_sync_clear_logs_nonce' ); + + Logger::clear(); + + $redirect = add_query_arg( + array( + 'page' => 'site-sync', + 'site_sync_status' => 'logs_cleared', + ), + admin_url( 'admin.php' ) + ); + + wp_safe_redirect( $redirect ); + exit; + } + /** * Handles the reset state action from the admin form submission. * diff --git a/includes/class-logger.php b/includes/class-logger.php index 85b1983..91f606f 100644 --- a/includes/class-logger.php +++ b/includes/class-logger.php @@ -58,4 +58,13 @@ class Logger { return array_slice( $logs, 0, $limit ); } + + /** + * Clears all stored log entries. + * + * @return void + */ + public static function clear(): void { + delete_option( self::OPTION_KEY ); + } }