Jump to content
Sign in to follow this  
psy

[solved] Where to hook page unpublished

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...