Last active
December 10, 2018 03:17
-
-
Save kongondo/11109830 to your computer and use it in GitHub Desktop.
ProcessWire. Code to hide page tree in the admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code. Still coming in handy. Ther's a missing closing parantheses ) for the if statement in line 30.