Jump to content

[solved] Where to hook page unpublished


psy
 Share

Recommended Posts

For pages with a particular template, I would like them to display/redirect to a different page from the normal http404 page when status is unpublished. Can't figure out what to hook and where. Un-working code is:

<?php

// in my auto-loaded custom module

    public function init() {
      // this hook doesn't catch... returns the normal http404 page for unpublished template=profile pages
        $this->addHookBefore('Page("template=profile")::loaded', $this, "unpublishedProfile");
    }

    public function unpublishedProfile (HookEvent $event) {
        $page = $event->arguments(0);
        if ($page->isUnpublished())
            $this->wire('session')->redirect($this->wire('pages')->get(1312)->url);
    }

Also tried to hook After page loaded with same result, ie default Page Not Found shown.

Help & suggestions to fix much appreciated.

Cheers
psy

Edited by psy
solved
Link to comment
Share on other sites

Solved! Thanks @Zeka

Solution:

<?php 

// in my auto-loaded custom module 

    public function init() {
        $this->addHookAfter('ProcessPageView::pageNotFound', $this, "unpublishedProfile");
    }


    public function unpublishedProfile (HookEvent $event) {
        $page = $event->arguments(0);
        if ($page->isUnpublished() && $page->template == 'profile')
            $this->wire('session')->redirect($this->wire('pages')->get(1312)->url);
    }

 

  • Like 2
Link to comment
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
 Share

  • Recently Browsing   0 members

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