9

I would like to make sure an extension isn't run, via sessions_end hook, in the control panel.

I'm currently doing this like so:

if ($this->EE->input->get_post('D') == "cp")
{
    return FALSE;
}

My question: is there a better or prefered method of having an extension only run a hook on the frontend and not in the CP?

17

That should work fine, but you can also check the REQ constant (docs) which has the following possible values:

  • CP - Control panel requests
  • PAGE - Frontend template requests
  • ACTION - Module actions, e.g. mysite.com/?ACT=123

For example:

if (REQ == 'CP')
{
    return FALSE;
}
| improve this answer | |
  • 2
    On StackExchange the best answers include code examples even if it's very obvious :) – Victor Gutierrez Nov 15 '12 at 20:26
  • I was just about to say the same thing :) – Natetronn Nov 15 '12 at 20:27
  • Alright nitpickers, edit duly approved. :P – Dom Stubbs Nov 15 '12 at 20:33
  • This is the exact same way that I do it Nate. – madebyhippo Nov 15 '12 at 23:08
  • Cool. I always just tested for $this->EE->cp, but this way seems more solid. – Adrian Macneil Nov 28 '12 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.