--- Posted April 13, 2017 Posted April 13, 2017 How can I check if the user is in the admin enviroment of processwire? At the moment I'm using some buggy url check but I figure that there must be something in processwire itself to check for that. I don't want to check if the user has administrator privileges, just if the user is visiting an admin url. Because the admin url can be changed from the admin panel I don't want to check on something hard coded as well. What is the best way to check for an admin page?
LostKobrakai Posted April 13, 2017 Posted April 13, 2017 $isAdmin = $this->page->rootParent->id == 2 1
--- Posted April 13, 2017 Author Posted April 13, 2017 Sorry, forgot to mention; I want to do this inside a module method. When I do `$this->page->rootParent->id`, it will give me the following error: <b>Notice</b>: Trying to get property of non-object in So I've tried $this->wire('page') instead, but that method returns null.
LostKobrakai Posted April 13, 2017 Posted April 13, 2017 It depends on when you call that. Before processwire's ready state the current page might not yet be determined.
--- Posted April 13, 2017 Author Posted April 13, 2017 I use it in a before hook method page::render with prio 1.
LostKobrakai Posted April 13, 2017 Posted April 13, 2017 Then you might want to try: $event->wire('page')->… I'm not sure, but page::render should not be called before ProcessWire::ready.
tpr Posted April 13, 2017 Posted April 13, 2017 What's wrong with $this->wire('page')->template == 'admin' ?
LostKobrakai Posted April 13, 2017 Posted April 13, 2017 There are various pages in the admin, which do not have the "admin" template. These are generally not accessable as backend page per se, but really checking for the rootParent is the most future prove way of handling that even if updates to processwire would change something with the templates. The backend parent page will more likely stay with it's id of 2. 3
adrian Posted April 13, 2017 Posted April 13, 2017 If you do need to do it in init() which is before wire('page') is available, then you can do this: if(strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0) { 3
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now