Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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
Posted

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) {

 

  • Like 3

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
×
×
  • Create New...