I recently had some ProcessWire code that needed to run on the front and back end but I needed to run slightly different logic on each. Here’s how I did it:
if (strpos($_SERVER['REQUEST_URI'], $config->urls->admin) === 0) { return; }
The most reliable way is to check the request for your admin path (which defauls to /processwire/). By using $config->urls->admin it will work even if you have changed the admin path.
All it does is check if the current path starts with (including the trailing slash) the admin path.
Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from
Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.