WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.63k stars 248 forks source link

Plugin / Theme installation needs a way to define the path to install into. #1802

Open dd32 opened 1 week ago

dd32 commented 1 week ago

Currently installAsset guesses the path to install an asset into based on two things:

  1. The ZIP name (ie. folder-name.zip => plugins/folder-name)
  2. The Directory contained within the ZIP (ie. zip contains a folder called my-plugin at the root level => plugins/my-plugin)

This is not ideal in some scenario's, especially as some software and plugins expect the plugin to be installed into a very specific path.

For example, Plugin Check expects that the folder that the plugin is installed in is the ultimate slug on WordPress.org. This is usually incorrect, but is sometimes correct.

This becomes a problem when we're loading user-supplied ZIPs into playground, as we can't force the ultimate install path, and it may end up being something like 2024_09_25-uploaded-my-plugin or My-Plugin-For-Review rather than the expected hello-world-example.

Ideally, InstallAssetOptions would expose a slug/installFolder optional property that can be set via InstallPluginOptions, which forces installAsset.assetFolderName rather than the heuristic guess that's presently in place.

An example step after this would be, to install the hello-dolly plugin into a arbitrary hello-world-example path:

{
      "step": "installPlugin",
      "pluginZipFile": {
        "resource": "wordpress.org/plugins",
        "slug": "hello-dolly"
      },
      "options": {
        "activate": true,
        "installFolder": "hello-world-example"
      }
    }

Another option would be that it's a property of the FileReference, but that might overload the FileReference structure to be too asset-central.

{
      "step": "installPlugin",
      "pluginZipFile": {
        "resource": "url",
        "url": "https://example.zip",
        "installSlug": "hello-world-example",
      }
    }
dd32 commented 1 week ago

Note: This can be worked around with a step after the installPlugin step that involves renaming the folder, although that's not ideal longer term, and would also require then re-implementing any activation logic. It's harder when there's multiple plugins installed as well, as we're not able to know for sure which folder it was installed into at the blueprint stage.