From 223704bff88d7e541ff2e79b206618be2b8bd917 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 21 Mar 2025 11:46:07 +0100 Subject: [PATCH 1/2] (chore): refactor variable scope --- openpub-base.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openpub-base.php b/openpub-base.php index c042be2..ff821b0 100644 --- a/openpub-base.php +++ b/openpub-base.php @@ -45,9 +45,8 @@ * and wp_loaded action hooks. */ add_action('plugins_loaded', function () { - $plugin = (new OWC\OpenPub\Base\Foundation\Plugin(__DIR__)); - - add_action('after_setup_theme', function () use ($plugin) { + add_action('after_setup_theme', function () { + $plugin = (new OWC\OpenPub\Base\Foundation\Plugin(__DIR__)); $plugin->boot(); do_action('owc/openpub-base/plugin', $plugin); }); From 6d9e63c8442d4406970f7ad6c94bcd12bc19c5a1 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 21 Mar 2025 11:47:55 +0100 Subject: [PATCH 2/2] (fix): only require autoload.php if not already loaded --- openpub-base.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/openpub-base.php b/openpub-base.php index ff821b0..6ac6054 100644 --- a/openpub-base.php +++ b/openpub-base.php @@ -20,21 +20,20 @@ die; } -/** - * Manual loaded file: the autoloader. - */ -require_once __DIR__ . '/autoloader.php'; -$autoloader = new OWC\OpenPub\Base\Autoloader(); - /** * Not all the members of the OpenWebconcept are using composer in the root of their project. * Therefore they are required to run a composer install inside this plugin directory. * In this case the composer autoload file needs to be required. + * + * If this plugin is not installed with composer a custom autoloader is used. */ -$composerAutoload = __DIR__ . '/vendor/autoload.php'; - -if (file_exists($composerAutoload)) { - require_once $composerAutoload; +if (!class_exists(\OWC\OpenPub\Base\Foundation\Plugin::class)) { + if (file_exists(__DIR__ . '/vendor/autoload.php')) { + require_once __DIR__ . '/vendor/autoload.php'; + } else { + require_once __DIR__ . '/autoloader.php'; + $autoloader = new \OWC\OpenPub\Base\Autoloader(); + } } /**