current_time( 'mysql' ), 'level' => strtoupper( $level ), 'message' => $message, 'context' => $context, ); $logs = get_option( self::OPTION_KEY, array() ); if ( ! is_array( $logs ) ) { $logs = array(); } array_unshift( $logs, $entry ); $logs = array_slice( $logs, 0, self::MAX ); update_option( self::OPTION_KEY, $logs ); } /** * Retrieves the most recent log entries. * * @param int $limit The maximum number of log entries to retrieve. * * @return array The array of recent log entries. */ public static function recent( int $limit = 50 ): array { $logs = get_option( self::OPTION_KEY, array() ); if ( ! is_array( $logs ) ) { return array(); } return array_slice( $logs, 0, $limit ); } /** * Clears all stored log entries. * * @return void */ public static function clear(): void { delete_option( self::OPTION_KEY ); } }