Execute code in config.php only, if it's not called by the panel

Hi,

I need to set some HTTP headers, which are the same for each page. In this case, I need to set CSP and HSTS headers.

A year ago I already had some discussions about the headers option in the config, which lead to a PR to add a wildcard option (see GitHub or this thread).
But Bastian replied, that I can simply use the plain PHP function for this use case, which was sufficient until now.

Today I refined my CSP, which lead to issues loading the style of a plugin of mine, because of a quite strict CSP.

So my question is, if it is possible to execute PHP code, which is located in the config file, only if it isn’t the panel, which is executing the config file.
I tried to add my HTTP-header code to a snippet, which is loaded first in every template, but this does not work well with caching enabled.

You could check if the panel is loaded like this

if(function_exists('panel')) {
  ...
}

or alternatively check if class exists class_exists().

Works like a charm. Thank you.