Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 798 forks source link

8.6.1 introduces fatal error when using composer autoloader for a site #16399

Closed JPry closed 4 years ago

JPry commented 4 years ago

When installing Jetpack using Composer, a fatal error is triggered when attempting to load a site:

PHP Fatal error:  Uncaught Error: Call to undefined function add_action() in /Users/jpry/Sites/jetpack-test/content/vendor/automattic/jetpack-backup/actions.php:13
Stack trace:
#0 /Users/jpry/Sites/jetpack-test/content/vendor/composer/autoload_real.php(69): require()
#1 /Users/jpry/Sites/jetpack-test/content/vendor/composer/autoload_real.php(59): composerRequire39832e96936c87813e67c175b71e54ff('d4eb94df91a7298...', '/Users/jpry/Sit...')
#2 /Users/jpry/Sites/jetpack-test/content/vendor/autoload.php(7): ComposerAutoloaderInit39832e96936c87813e67c175b71e54ff::getLoader()
#3 /Users/jpry/Sites/jetpack-test/wp-config.php(16): require_once('/Users/jpry/Sit...')
#4 /Users/jpry/Sites/jetpack-test/wp/wp-load.php(42): require_once('/Users/jpry/Sit...')
#5 /Users/jpry/Sites/jetpack-test/wp/wp-blog-header.php(13): require_once('/Users/jpry/Sit...')
#6 /Users/jpry/Sites/jetpack-test/index.php(17): require('/Users/jpry/Sit...')
#7 /Users/jpry/.composer/vendor/weprovide/valet-plus/server.php(131): require('/Users/jpry/Sit...')
#8 {main}
  thr in /Users/jpry/Sites/jetpack-test/content/vendor/automattic/jetpack-backup/actions.php on line 13

Steps to reproduce the issue

Set up a site that uses composer to build the site. I happened to use WP Starter, and this is what my composer.json file looks like:

{
    "name": "jpry/jetpack-test",
    "type": "project",
    "require": {
        "php": "^7.3",
        "automattic/jetpack": "8.6.1",
        "composer/installers": "^1.9",
        "wecodemore/wpstarter": "^2.4"
    },
    "config": {
        "sort-packages": true,
        "vendor-dir": "content/vendor",
        "platform": {
            "php": "7.3"
        }
    },
    "scripts": {
        "post-install-cmd": [
            "@setup"
        ],
        "post-update-cmd": [
            "@setup"
        ],
        "setup": [
            "WCM\\WPStarter\\Setup::run"
        ]
    },
    "extra": {
        "wordpress-install-dir": "wp",
        "wordpress-content-dir": "content",
        "installer-paths": {
            "content/plugins/{$name}": [
                "type:wordpress-plugin"
            ],
            "content/mu-plugins/{$name}": [
                "type:wordpress-muplugin"
            ],
            "content/themes/{$name}": [
                "type:wordpress-theme"
            ]
        }
    }
}

When attempting to load the site, even if the Jetpack plugin is not active, a fatal error will occur. If the version of Jetpack included in the composer.json is set to 8.6, then the fatal error will not occur.

I suspect this has to do with the additions to Jetpack's composer.json file in version 8.6.1.

jeherve commented 4 years ago

That's indeed a known issue. It was previously brought up in #13497. We fixed the problem with a change to our building tools in #14900, but for some reason we still don't understand, that didn't work out for the past release: https://github.com/Automattic/jetpack/commit/e0fde5647795cc257824685833feca1274c3cb70#r39872402

It will be okay for 8.7 though, scheduled to be released tomorrow: https://github.com/Automattic/jetpack/blob/branch-8.7-built/composer.json#L10