Jump to content

Best way to hide 404 page from editors


theo
 Share

Recommended Posts

Hello

I think my "editors" should not see the 404 page in the list (backend).

I guess this page should not be deleted for technical reasons. Is this right?

If so, what is the best way to hide it?

I have written a little module (code below) and this seems to  do what I want. But is it a good way? Is there anything I have overlooked?

Or is this overkill and there is a much simpler way?

Thank you.
 

<?php namespace ProcessWire;

class HideAdminPages extends WireData implements Module {

    public static function getModuleInfo() {

        return array(
            'title' => 'HideAdminPages',
            'author' => 'Theo',
            'version' => 1,
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        if (!$this->user->hasRole('editorrole')) return; //hide for editorrole only
        $this->addHookAfter('ProcessPageList::find', $this, 'pageListFind');
    }

    public function pageListFind(HookEvent $event){
        $pages = $event->return;
        if($this->config->ajax){
            foreach($pages as $p) {
                if($p->id == 27) $pages->remove($p); //27 is the 404 Page
            }
            $event->return = $pages;
        }
    }
}

 

Link to comment
Share on other sites

5 hours ago, theo said:

I guess this page should not be deleted for technical reasons. Is this right?

Nope. You can delete it if you want. In that case, let PW know what to use for 404 config (see below)

5 hours ago, theo said:

Or is this overkill...

Yes. Quite the overkill :).

5 hours ago, theo said:

a much simpler way?

just move page with ID 27 under /admin/ (i.e., re-parent it). Editors will not be able to see it. 

OR

Create a new 404 page under /admin/ (and delete page with ID 27 or reuse it for whatever). Editors will not be able to see it. Add this to /site/config.php

$config->http404PageID = 1234;// ID of your new hidden 404 page.

That's all there is to it.

  • Like 4
Link to comment
Share on other sites

  • 11 months later...
12 hours ago, dragan said:

.role-superuser

In his other post I also recommended this but .role-superuser seems to be added by AdminOnSteroids only...

 

 

Edited by szabesz
typo
  • Like 1
Link to comment
Share on other sites

  • 3 years later...

Just keeping this thread up to date in case anyone is searching for how to do this still (and I know I'll forget so it will probably be me), the ProcessPageList  module now has a configuration option to let you hide pages from users:

 

  • Like 2
  • Thanks 1
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...