How to detect if a plugin is loaded in the site or in the panel?

In K2, I was able to detect that with the following code in my plugin PHP file:

if (function_exists('panel')) {
  echo 'in the panel';

In K3, however, that doesn’t seem to work. function_exists('panel') always returns false.


$isPanel = strpos(
) !== false;

Seems to work. Is it reliable, though? Is there a better way to check if the plugin is loaded in the panel or in the site?

1 Like

I don’t have an answer from the top of my head. But maybe you could tell us about your reason/motivation for getting that information - maybe there are other ways to achieve the same goal?

1 Like

Well, I wanted to use that functionality to register a route only when you’re inside the panel because that’s where I need it. However, in my other question, you recommended the custom API routes which seem to be a better solution. Those routes would be available outside the panel as well, but at least they’ll be protected.

I’m pretty sure that site/panel detection could come in handy for something, though.