archiver = $archiver; add_action('wp_dashboard_setup', array($this, 'add_dashboard_widget')); add_action('wp_ajax_archiver_dashboard_trigger', array($this, 'ajax_dashboard_trigger')); add_action('wp_ajax_archiver_dashboard_stats', array($this, 'ajax_dashboard_stats')); } /** * Add dashboard widget */ public function add_dashboard_widget() { if (!current_user_can('manage_options')) { return; } // Remove the second callback function to cancel configuration options wp_add_dashboard_widget( 'archiver_dashboard_widget', __('Archive Status', 'archiver'), array($this, 'render_dashboard_widget') // Remove configuration callback // array($this, 'render_dashboard_widget_config') ); } /** * Render dashboard widget */ public function render_dashboard_widget() { $stats = $this->get_dashboard_stats(); $pending_count = count(get_option('archiver_urls_to_update', array())) + count(get_option('archiver_background_queue', array())); // Get pre-calculated display times or timestamps $last_run_display = get_option('archiver_last_run', ''); $last_run_timestamp = get_option('archiver_last_run_timestamp', 0); $next_run = wp_next_scheduled('archiver_process_urls'); // Format last run time if (!empty($last_run_display)) { $last_run_formatted = $last_run_display; } elseif ($last_run_timestamp > 0) { $last_run_formatted = $this->format_timestamp_with_timezone($last_run_timestamp); } else { // If we have a string that might be a date $last_run = get_option('archiver_last_run'); if (!empty($last_run) && ($timestamp = strtotime($last_run)) !== false) { $last_run_formatted = $this->format_timestamp_with_timezone($timestamp); } else { $last_run_formatted = __('Never', 'archiver'); } } // Format next run time $next_run_display = get_option('archiver_next_run_display', ''); if (!empty($next_run_display)) { $next_run_formatted = $next_run_display; } elseif ($next_run) { $next_run_formatted = $this->format_timestamp_with_timezone($next_run); } else { $next_run_formatted = __('Not scheduled', 'archiver'); } ?>

0): ?>

3): ?>
setTimezone($timezone); return $datetime->format(get_option('date_format') . ' ' . get_option('time_format')); } else if ($gmt_offset) { // Use GMT offset $timestamp += $gmt_offset * HOUR_IN_SECONDS; return date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $timestamp); } } catch (Exception $e) { if (defined('WP_DEBUG') && WP_DEBUG) { error_log('[WP Archiver] Date formatting error: ' . $e->getMessage()); } } // Default fallback to WordPress localized date function return date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $timestamp); } /** * Get dashboard statistics */ private function get_dashboard_stats() { return array( 'total_archived' => get_option('archiver_total_archived', 0), 'failed_snapshots' => get_option('archiver_failed_snapshots', 0), 'pending_urls' => count(get_option('archiver_urls_to_update', array())), 'queue_count' => count(get_option('archiver_background_queue', array())) ); } /** * AJAX handler for dashboard trigger */ public function ajax_dashboard_trigger() { check_ajax_referer('archiver_dashboard_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Permission denied', 'archiver'))); } // Process queue if (isset($_POST['process_queue'])) { if ($this->archiver && method_exists($this->archiver, 'process_urls_for_update')) { $processed = $this->archiver->process_urls_for_update(); wp_send_json_success(array( 'message' => sprintf(__('Started processing %d URLs from queue', 'archiver'), $processed) )); } else { wp_send_json_error(array('message' => __('Queue processing not available', 'archiver'))); } return; } // Archive single URL $url = isset($_POST['url']) ? esc_url_raw($_POST['url']) : ''; if (empty($url) || !filter_var($url, FILTER_VALIDATE_URL)) { wp_send_json_error(array('message' => __('Please enter a valid URL', 'archiver'))); } // Add to queue with high priority if ($this->archiver && method_exists($this->archiver, 'trigger_url_snapshot')) { $this->archiver->trigger_url_snapshot($url); wp_send_json_success(array( 'message' => sprintf(__('URL added to archive queue: %s', 'archiver'), $url) )); } else { wp_send_json_error(array('message' => __('Archive functionality not available', 'archiver'))); } } /** * AJAX handler for dashboard stats */ public function ajax_dashboard_stats() { check_ajax_referer('archiver_dashboard_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Permission denied', 'archiver'))); } $stats = $this->get_dashboard_stats(); wp_send_json_success($stats); } }