time(), 'type' => strtolower( sanitize_key( $type ) ), 'message' => $message, // Saved raw, sanitized on output 'context' => $context, 'details' => is_wp_error( $details ) ? 'WP_Error: ' . $details->get_error_message() : $details, 'metadata' => (array) $metadata, ); // Prepend new entry array_unshift( $logs, $entry ); // Trim log to max entries $logs = array_slice( $logs, 0, self::MAX_LOG_ENTRIES ); // PERFORMANCE FIX: Explicitly set autoload to 'no'. // This prevents the log data from loading on every page view of the website. update_option( self::LOG_OPTION_KEY, $logs, 'no' ); } /** * Generates the HTML representation of the log entries for display. * * @return string HTML for the log list. */ public function get_log_entries_html() { $logs = get_option( self::LOG_OPTION_KEY, array() ); if ( empty( $logs ) ) { return '
' . esc_html__( 'No log entries yet.', 'ainp-ai-native-publisher' ) . '
'; } // Map types to translated labels and icons. $log_type_map = array( 'info' => array( 'label' => __( 'Info', 'ainp-ai-native-publisher' ), 'icon' => 'dashicons-info-outline', ), 'success' => array( 'label' => __( 'Success', 'ainp-ai-native-publisher' ), 'icon' => 'dashicons-yes-alt', ), 'warning' => array( 'label' => __( 'Warning', 'ainp-ai-native-publisher' ), 'icon' => 'dashicons-warning', ), 'error' => array( 'label' => __( 'Error', 'ainp-ai-native-publisher' ), 'icon' => 'dashicons-dismiss', ), ); // Map contexts to translated labels and icons. $log_context_map = array( 'user' => array( 'label' => __( 'Manual', 'ainp-ai-native-publisher' ), 'icon' => 'dashicons-admin-users', ), 'cron' => array( 'label' => __( 'System', 'ainp-ai-native-publisher' ), 'icon' => 'dashicons-admin-generic', ), ); $html = '