Skip to content

Instantly share code, notes, and snippets.

@kongondo
Last active December 10, 2018 03:17
Show Gist options
  • Save kongondo/11109830 to your computer and use it in GitHub Desktop.
Save kongondo/11109830 to your computer and use it in GitHub Desktop.
ProcessWire. Code to hide page tree in the admin
<?php
/*
CODE COPIED FROM https://processwire.com/talk/topic/6142-hide-page-tree-in-the-admin/
One hook returns false for Page::viewable() for the ProcessPageList page.
Another Hook can be used to redirect users to a custom admin page after login.
*/
// This needs to be an autoload module
public function init() {
$this->addHookBefore('ProcessHome::execute', $this, 'rootPage');
$this->addHookAfter('Page::viewable', $this, 'viewable');
}
/**
* Redirect users with custom-role to another page after login
*/
public function rootPage(HookEvent $event) {
if ($this->user->hasRole('custom-role')) {
$this->session->redirect('custom-admin-page/');
}
}
/**
* Don't give users with custom-role access to Pages page
*/
public function viewable(HookEvent $event) {
$page = $event->object;
$user = $this->user;
if ($page->id == 3 && $user->hasRole('custom-role') {
$event->return = false;
}
}
@gebeer
Copy link

gebeer commented Dec 10, 2018

Thanks for the code. Still coming in handy. Ther's a missing closing parantheses ) for the if statement in line 30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment