DrQuincy Posted September 18 Share Posted September 18 I have a template, product, that has a field, downloads. I want people to be logged in to access downloads but I also want role guest to view the page. When you choose the option to restrict access to a template's files it determines this, rightly, based on the options set in the Access tab. How can I make ProcessWire restrict access to downloads while at the same time making the actual page viewable by guests? So if you had /page/ that has a link to /site/assets/files/999/file.pdf, everyone could view the page but the file would 404 for guest - but be accessible for anyone logged in. Thanks. Link to comment Share on other sites More sharing options...
virtualgadjo Posted September 19 Share Posted September 19 Hi; honestly, i would do this kind of thing in the template file wrapping the display of the link with a simple if user is logged... better SEO and UX than a 404 🙂 have a nice day 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted September 19 Share Posted September 19 (edited) AFAIK ProcessWire’s pagefileSecure feature only works on the page level. So when your page is viewable by guests, its files will be viewable as well. However, when pagefileSecure is active, all files should be routed through the hookable method ProcessPageView::___sendFile(). It’s a short little method you could hook to add your own logic. For example: $this->addHookBefore('ProcessPageView::sendFile(template=MY_SPECIAL_TEMPLATE)', function(HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); $filename = $event->arguments(1); if ($this->wire->user->isGuest()) throw new Wire404Exception('File not found', Wire404Exception::codeFile); }); Edited September 19 by Jan Romero 3 Link to comment Share on other sites More sharing options...
DrQuincy Posted September 20 Author Share Posted September 20 @Jan Romero Thank you for this! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now