PWaddict Posted November 9, 2018 Share Posted November 9, 2018 PW by default allows non-superusers to view unpublished pages on frontend. Is there an option somewhere to prevent that? Link to comment Share on other sites More sharing options...
Tom. Posted November 9, 2018 Share Posted November 9, 2018 1 hour ago, PWaddict said: PW by default allows non-superusers to view unpublished pages on frontend. Is there an option somewhere to prevent that? I never knew that, I wonder why guests have permissions to view unpublished pages? Anyway, I guess put this at the very top of your template file: if($page->isUnpublished() && !$user->isSuperuser()) throw new Wire404Exception(); Link to comment Share on other sites More sharing options...
PWaddict Posted November 9, 2018 Author Share Posted November 9, 2018 6 minutes ago, Tom. said: I never knew that, I wonder why guests have permissions to view unpublished pages? Guests can't view them. I was talking about the site editors (non-superusers). 7 minutes ago, Tom. said: if($page->isUnpublished() && !$user->isSuperuser()) throw new Wire404Exception(); I've already tried that but something isn't right. The site editor can see a 404 page (which is what I want) but lot of pw related content is hidden like titles, other fields content etc. Link to comment Share on other sites More sharing options...
PWaddict Posted November 9, 2018 Author Share Posted November 9, 2018 I've also tried this but isn't working. I'm getting a blank white page. if($page->isUnpublished() && !$user->isSuperuser()) { $error404 = $pages->get("template=404, include=hidden"); $session->redirect($error404->url, false); } Link to comment Share on other sites More sharing options...
PWaddict Posted November 9, 2018 Author Share Posted November 9, 2018 I had to create an alternate template for 404 page and now it works: if($page->isUnpublished() && !$user->isSuperuser()) { $error404 = $pages->get("template=404-alt, include=hidden"); $session->redirect($error404->url, false); } If you know a better way let me know. Thanks. Link to comment Share on other sites More sharing options...
PWaddict Posted November 9, 2018 Author Share Posted November 9, 2018 No need for alt 404 template. if($page->isUnpublished() && !$user->isSuperuser()) { $error404 = $pages->get(27); // ID of 404 page $session->redirect($error404->url, false); // 302 temporary redirect } 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