TGMPA / TGM-Plugin-Activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install, update and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference bundled plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.
http://tgmpluginactivation.com/
GNU General Public License v2.0
1.75k stars 431 forks source link

Force-autoloading `class-tgm-plugin-activation.php` breaks my plugin's tests because its code doesn't account for WordPress not yet loaded #792

Open cliffordp opened 4 years ago

cliffordp commented 4 years ago

Re: https://github.com/TGMPA/TGM-Plugin-Activation/blob/develop/composer.json#L36-L38

"autoload": {
  "files": ["class-tgm-plugin-activation.php"]
}

Force-loading this file causes errors when running Codeception tests on a plugin that implements TGMPA, failing because class-tgm-plugin-activation.php does not have defensive code if did_action function exists or if ABSPATH is not defined.

Screenshot:

image

If ☝️ gets fixed, that's when the ABSPATH one appears. This has to be fixed in the package because TGMPA is installed via Composer.

I'd be willing to submit a PR but am unsure if it'd be received/implemented.

I had bookmarked checking out https://github.com/afragen/wp-dependency-installer anyway so that's what I'm going to try next.

jrfnl commented 4 years ago

@cliffordp I'm not sure I understand the problem.

The file does contain defensive coding for ABSPATH and will return without doing anything if ABSPATH is not defined.

If ABSPATH is defined, WP must be loaded, so did_action() should be available.

jrfnl commented 4 years ago

Only thing I can think of is that that code may not be in the last release. It is in the file in master.

cliffordp commented 4 years ago

I've got v2.6.1 as confirmed by PhpStorm in this screenshot, which is the latest version from https://packagist.org/packages/tgmpa/tgm-plugin-activation image

I see neither v2.6.1 nor master have the ABSPATH check that's present in develop.

Adding that check from develop does fix the issue with my tests. Sounds like a version bump would be the path forward. Thanks for the quick help! :)

cliffordp commented 3 years ago

@jrfnl any idea why https://packagist.org/packages/tgmpa/tgm-plugin-activation has v2.6.1 as latest version still - no version bump yet? Using dev-develop instead is of risk since I don't know what goes into there compared to an official release.

jrfnl commented 3 years ago

@cliffordp Because that is the latest version. See my previous answer to you about releasing a new version: https://github.com/TGMPA/TGM-Plugin-Activation/issues/741#issuecomment-488142682

Also, you can see exactly what has changed between the last release and develop:

cliffordp commented 3 years ago

I understand. How can we get 2.6.2 (or whatever other number, such as 2.6.1.1) released that ONLY has the defensive coding for ABSPATH so dev-develop can be a development branch but Composer installs (including GitHub Actions tests) can specify a version number?

jrfnl commented 3 years ago

See my previous answer and no, that will not be a release just with that fix.

cliffordp commented 3 years ago

boo 😜

thanks for the quick, thorough help nonetheless. appreciate ya!

seothemes commented 1 year ago

One workaround is to use the git repository:

"repositories": [
    {
      "type": "package",
      "package": {
        "name": "tgm/plugin-activation",
        "version": "2.6.1",
        "source": {
          "url": "https://github.com/TGMPA/TGM-Plugin-Activation.git",
          "type": "git",
          "reference": "master"
        }
      }
    }
  ],

And then require the latest:

"require": {
    "tgmpa/tgm-plugin-activation": "*",
  },
XedinUnknown commented 8 months ago

Or, you could define dependency on tgmpa/tgm-plugin-activation:dev-develop to get latest develop branch, provided you have minimum-stability set to dev.