Soma Posted August 1, 2012 Share Posted August 1, 2012 Would this makes sense or even easy possible to add a property, so you could simply check in moules/templates if you're in admin or frontend using: $config->isAdmin; Something like the $config->isAjax; If not, so those are the common checks that can be used to determine this (for reference): if( wire("page")->template == 'admin' ) { // is in admin } if( wire("page")->template != 'admin' ) { // is frontend } if( strpos( $_SERVER['REQUEST_URI'], wire('config')->urls->admin) !== false ) { // in admin } checking for only certain admin processes or areas is also possible // in a autoload module you could also use if( wire("process") == 'ProcessPageEdit' ) { // is editing page } if( strpos( $_SERVER['REQUEST_URI'], wire('config')->urls->admin . 'page/edit' ) !== false ) { // in editing page } 1 Link to comment Share on other sites More sharing options...
ryan Posted August 1, 2012 Share Posted August 1, 2012 That makes sense to me. To add to your list of ways to check, here's another that should be pretty bulletproof: if(strpos($page->url, wire('config')->urls->admin) === 0) { /* hello admin */ } 1 Link to comment Share on other sites More sharing options...
Nico Knoll Posted August 8, 2012 Share Posted August 8, 2012 +1 for $config->isAdmin; I needed it today and solved it like: if(strpos($_SERVER['REQUEST_URI'],wire('pages')->get(wire('config')->adminRootPageID)->url) !== false) 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted August 8, 2012 Share Posted August 8, 2012 (edited) ^^' Edited August 8, 2012 by adamkiss Nevermind, I am an idiot Link to comment Share on other sites More sharing options...
Soma Posted August 8, 2012 Author Share Posted August 8, 2012 Nico, you could also use following to check if in backend. if($page->template == "admin") { .. } Or another way when using a hook function, for example function myhook(HookEvent $event) { $cur_page = $event->object; if($cur_page->template == "admin") { ... } } Link to comment Share on other sites More sharing options...
Nico Knoll Posted August 8, 2012 Share Posted August 8, 2012 Does it work in module's init() ? Link to comment Share on other sites More sharing options...
Soma Posted August 8, 2012 Author Share Posted August 8, 2012 ^^' It's not about the user I think but context. Link to comment Share on other sites More sharing options...
Soma Posted August 8, 2012 Author Share Posted August 8, 2012 Does it work in module's init() ? not really, in the init no page is loaded yet, but you could try to put it in loaded() or was it ready() function maybe or a hook from in the init(). Link to comment Share on other sites More sharing options...
apeisa Posted August 8, 2012 Share Posted August 8, 2012 ready() 2 Link to comment Share on other sites More sharing options...
Shehbaz Posted May 15, 2014 Share Posted May 15, 2014 Thanks, it helped. Link to comment Share on other sites More sharing options...
adrian Posted November 24, 2015 Share Posted November 24, 2015 Just to add to this thread - I needed the check to run during init() and the best option I could think of was: if( wire("process") != 'ProcessPageView' ) { //in the admin } Can anyone think of any situation where this would fail? Perhaps some modules may run ProcessPageView in the admin? Maybe Nico's check for the admin path in the URL is a better option. Anyone have any more recent thoughts on this? 1 Link to comment Share on other sites More sharing options...
Sanyaissues Posted December 30, 2018 Share Posted December 30, 2018 Hi @adrian! I'm using your code to prevent some custom hooks to break things in the back-end. Did you find any case where the code fails? $wire->addHookBefore('InputfieldForm::render', function($event) { if( wire("process") != 'ProcessPageView' ) return; //Prevents classes from being added to the fields in the backend $form = $event->object; $form->addClass('uk-form'); }); Link to comment Share on other sites More sharing options...
adrian Posted December 30, 2018 Share Posted December 30, 2018 1 hour ago, Sanyaissues said: Did you find any case where the code fails? I don't think I found any problems with it, but I have also been using: strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0 1 Link to comment Share on other sites More sharing options...
adrian Posted December 30, 2018 Share Posted December 30, 2018 This should also work: strpos($input->url, $this->wire('config')->urls->admin) === 0 so long the PW version is after this bug was fixed 1 Link to comment Share on other sites More sharing options...
tpr Posted January 1, 2019 Share Posted January 1, 2019 Spoiler alert: I'm building a new module that contains a collection of markup generators and other small helpers, and just added a new "isAdminPage" method. This accepts a Page or a Page ID and defaults to the input url. Here is a screenshot of the tests and the method itself: 5 Link to comment Share on other sites More sharing options...
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