Load plugins if not visiting /panel page

Following up on this

still having this error, only when I access the /panel page

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in /www/public/site/plugins/api/api.php on line 3

Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.:') in /www/public/site/plugins/api/api.php on line 3

I put

if (!class_exists('Kirby\Panel')) {
  use \DrewM\MailChimp\MailChimp;

to make load the plugin only when not visiting the panel page, but now I have a problem with the use keyword.

i don’t think i really need to make a new php class only to follow the usage of the usekeyword, but as far as i understand it’s due to that kind of restriction?

alas, i can’t either move up the autoload + use classname up at the top of the file, else when i visit /panel i get the same error again.

how would you selectively load a plugin in this case?

Doing something like this works

use \DrewM\MailChimp\MailChimp;

  if (!class_exists('Kirby\Panel')) {
    etc ...

I guess it’s because use is only an alias to an existing loaded class and if require('vendor/autoload.php') does not load, the use keyword does not get triggered?

Cool :sunglasses: