boxuk / wp-muplugin-loader

A drop-in MU Plugin loader for WordPress
MIT License
19 stars 4 forks source link

PHP Fatal error: Cannot redeclare LkWdwrd\MuPluginLoader\Util\rel_path() #113

Open alapiere opened 1 year ago

alapiere commented 1 year ago

Hi, I've got an error in logs and in specific custom BO page;

Not sure what caused this.

PHP Fatal error: Cannot redeclare LkWdwrd\MuPluginLoader\Util\rel_path() (previously declared in /www/XX/public/vendor/boxuk/wp-muplugin-loader/src/Util/util.php:23) in /www/XX/public/vendor/boxuk/wp-muplugin-loader/src/Util/util.php on line 23"

  "require": {
     (..)
    "boxuk/wp-muplugin-loader": "*",

 "config": {
  "require-all": true,
    "allow-plugins": {
      (..)
      "boxuk/wp-muplugin-loader": true
    }

if I remove mu-require.php from mu-plugins, it works fine. Happy to provide any additional troubleshooting instructions if needed

jdamner commented 1 year ago

Hey @alapiere

Do you have any other mu-plugin loader packages in your composer.json file? And would it be possible you're loading the muplugin-loader twice?

asengerdmk commented 1 year ago

@jdamner Getting the same issue.

error message

PHP Fatal error:  Cannot redeclare LkWdwrd\MuPluginLoader\Util\rel_path() (previously declared in /var/www/html/vendor/boxuk/wp-muplugin-loader/src/Util/util.php:23) in /var/www/html/vendor/boxuk/wp-muplugin-loader/src/Util/util.php on line 23

composer.json

    "require": {
        "composer/installers": "^2.2",
        "johnpbloch/wordpress-core": "6.3.2",
        "wpackagist-plugin/wp-fastest-cache": "^1.2"
    },
    "extra": {
        "force-mu": [
            "wp-fastest-cache"
        ],
     }

Maybe it's because we require the utils here for composer: https://github.com/boxuk/wp-muplugin-loader/blob/master/src/Composer/MuLoaderPlugin.php#L32 And another time when the generated file /wp-content/mu-plugins/mu-require.php calls this file: https://github.com/boxuk/wp-muplugin-loader/blob/master/src/mu-loader.php#L28

After commenting out the latter it worked.

mikemanger commented 1 month ago

For us this seems to be happening when the theme (or plugin) is requiring the vendor/autoload.php file to use other vendored libraries (e.g. tecnickcom/tcpdf). I assume the definitions of this project are getting loaded in then.

I guess a simple, but not very elegant, fix would be to add some class_exists() wrappers.

zimdin12 commented 2 weeks ago

Same problem here.