Jump to content

[SOLVED] How to restrict view access of unpublished pages for non-superusers?


PWaddict
 Share

Recommended Posts

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

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

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

  • PWaddict changed the title to [SOLVED] How to restrict view access of unpublished pages for non-superusers?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...