[MEMBERSHIP] protected image in custom search function

I'm currently making a website with a membership area, where i've developed a custom search function, to search via the wp_query function and thru outputting posts and attachments that are protected by a given membership rule.

That works fine, but when I'm trying to display an attachment, where the link has been obfuscated by the membership plugin, I can't use https://codex.wordpress.org/Function_Reference/wp_get_attachment_url as that function returns the real url to the attachment, which will not work after the link has been taken over by membership.

I hope you can point me in the right direction :slight_smile:
Thank you