Jump to content

Detect if current page is an admin page


---
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

  • Like 3
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

×
×
  • Create New...