outlandishideas / wpackagist

WordPress Packagist — manage your plugins with Composer
https://wpackagist.org
MIT License
704 stars 71 forks source link

Require `wordpress/core-implementation` and `php` as defined by the plugin #516

Open alpipego opened 7 months ago

alpipego commented 7 months ago

Hello, I've long noticed a potential area for improvement concerning compatibility checks with PHP versions and specific WordPress core versions. Currently, developers need to manually ensure that their WordPress environment matches the requirements of the plugins and themes they incorporate.

Example

Let's assume my project has this composer.json:

{
  "name": "alpipego/test",
  "description": "Testing core and PHP requirements",
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org",
      "canonical": true,
      "only": [
        "wpackagist-plugin/*",
        "wpackagist-theme/*"
      ]
    }
  ],
  "require": {
    "johnpbloch/wordpress-core": "5.4.*",
    "johnpbloch/wordpress-core-installer": "^2.0",
    "wpackagist-plugin/query-monitor": "^3.2.2"
  },
  "config": {
    "platform": {
      "php": "7.0"
    },
    "allow-plugins": {
      "composer/installers": true,
      "johnpbloch/wordpress-core-installer": true
    }
  },
  "extra": {
    "wordpress-install-dir": "public/wp",
    "installer-paths": {
      "public/wp-content/mu-plugins/{$name}/": [
        "type:wordpress-muplugin"
      ],
      "public/wp-content/plugins/{$name}/": [
        "type:wordpress-plugin"
      ],
      "public/wp-content/themes/{$name}/": [
        "type:wordpress-theme"
      ]
    }
  }
}

As of writing, this will install WordPress core in version 5.4.15 and Query Monitor in version 3.15.0. However, the installed Query Monitor version requires at least WordPress 5.6 and PHP 7.4, neither of which are satisfied in the current project configuration.

This is the header for the installed QM version:

# Query Monitor
Contributors: johnbillion
Tags: debug, debug-bar, development, performance, query monitor, rest-api
Requires at least: 5.6
Tested up to: 6.4
Stable tag: 3.15.0
License: GPLv2 or later
Requires PHP: 7.4
Donate link: https://github.com/sponsors/johnbillion

Suggestion

Potential Breaking Change

While this proposal aims to improve compatibility checks, it's crucial to consider the potential for breaking changes in websites that currently do not install a WordPress core package that provides wordpress/core-implementation.


I haven't looked into https://github.com/WordPress/wp-plugin-dependencies deeply, but I assume it's something that could/should be considered down the line.

NoelLH commented 7 months ago

Definitely sounds like a good improvement, although I suppose it might also cause trouble with stale but working plugins if the compatibility metadata is listed as compulsory (rather than in e.g. suggests)?

I wasn't sure from the main docs if the fields are exposed in the API but this comment suggests they should be.

ethanclevenger91 commented 6 months ago

I believe there are a couple potential packages for pulling in WP core, so it may not be feasible to enforce a specific one.

alpipego commented 6 months ago

@ethanclevenger91 please check the following from my proposal. wordpress/core-implementation is not one specific implementation, but rather a meta package that is provided by other packages. If you click on the link, you can see the packages that provide wordpress/core-implementation.

Require wordpress/core-implementation for WordPress core (https://packagist.org/providers/wordpress/core-implementation)

ethanclevenger91 commented 6 months ago

@alpipego oh sick, learned something new today!