-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Blueprints] Ensure plugins and themes are installed in subfolders when using url references in the installPlugin/Theme step #2128
base: trunk
Are you sure you want to change the base?
Conversation
/** | ||
* If the plugin was successfully activated, we can return early. | ||
*/ | ||
if (activatePluginResult.text === 'true') { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't directly related to this PR, but while I was debugging it, I realized that this will make the activatePlugin
step more robust and will avoid the extra check when it's not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it's own this fix would allow the PR test to pass because the plugin would successfully activate inside the plugins
folder.
* the asset folder name exists. | ||
*/ | ||
if (!zipFileName) { | ||
assetNameGuess = `${randomString(32, '')}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this could break if the path already exists, but I wasn't sure if checking the path would overcomplicate the implementation.
We should be able to extract the name when fetching the resource because it's available in the
|
We can't get the name from the response because CORS prevents us from reading response headers for cross-origin requests. |
I'm leaving this as a draft for now, but I would love to get feedback on the direction this PR takes. |
Motivation for the change, related issues
Before this PR, a plugin or theme could be installed to the
wp-content/plugins
andwp-content/themes
folder without a subfolder.This would happen when the plugin/theme resource was installed using references without a name attribute, for example using a URL reference.
This was caused by the install asset code assuming there will always be a name but the name isn't a required attribute in some reference types, so it can be empty.
To fix this we now generate a random asset name in case it doesn't already exist.
There is a chance that a plugin doesn't use a subfolder (for example Hello Dolly), but because we can't assume this it's safer to install it into a subfolder. Otherwise, multiple plugins installed in the
wp-content/plugins
orwp-content/themes
directory could override each other's files.Also today the activate plugin script assumes there is only one plugin in the provided folder.
Potential improvements
This approach isn't ideal because it means the plugin/theme will be installed into a randomly generated folder which isn't expected. We should consider other ways of extracting the name.Exploration conclusionAlso, we could add support for names to other resource types, but this wouldn't fix existing Blueprints.
Testing Instructions (or ideally a Blueprint)