Jump to content
bernhard

Make unpublished pages accessible via GET parameter

Recommended Posts

For advanced needs there is a module from @Robin S : https://processwire.com/talk/topic/21153-access-by-query-string/

 

But if you need something really quick and simple, just put that in your init.php:

if($input->get('code', 'string') === 'YOURSECRET') {
  // remove the unpublished state in memory (non-persistant)
  $pages->get('/yourpage')->removeStatus('unpublished');
}

This makes /yourpage accessible via /yourpage/?code=YOURSECRET 🙂 

PS: I had this need today to show a page to a user that has no login and to make sure that the page is also excluded from search results (that's why just hiding the page would not have been enough).

  • Like 5

Share this post


Link to post
Share on other sites

Nice tip!!

To elaborate on other examples, I do something like this to have this same "code to view" per page (in the sense of one code per page) like this on ready.php:

if(!$user->isLoggedIn()){
  wire()->addHookAfter('Page(template=sometemplate)::viewable', function($event){
          $page = $event->object;
          $pass = wire('input')->get->text('pass');

          if($page->page_pass && $pass){
              if($page->isUnpublished() && $pass == $page->page_pass){
                  $event->return = true;
              }
          }
  });
}

 

  • Like 4

Share this post


Link to post
Share on other sites

What about this? 🙂 

if(!$user->isLoggedin()
  AND $page->template == 'sometemplate'
  AND $input->get('code', 'string') == $page->page_pass) {
  $page->removeStatus('unpublished');
}

 

Edited by bernhard
Didn't read it correctly on first response :)
  • Like 1

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...