Skip to content
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

wp plugin delete <plugin-name> not working if path has a space or & in it #135

Closed
swiftavl opened this issue Sep 28, 2018 · 5 comments · Fixed by #138
Closed

wp plugin delete <plugin-name> not working if path has a space or & in it #135

swiftavl opened this issue Sep 28, 2018 · 5 comments · Fixed by #138

Comments

@swiftavl
Copy link

If the path to a WordPress install has ' ' or '&' in the pathname, then the command 'wp plugin delete ' does not work. Note that list, install, activate, deactivate all work as expected. Delete says it deletes it, but it doesn't. Not sure if other characters and/or commands have the same issue.

example
using a fresh install of WordPress
if ABSPATH defined: '/Users/userName/development sites/myTestSite/'
the following command will fail to delete the plugin.

wp plugin delete akismet

I can reproduce it using a ' ' or a '&'. I'm sure there are others.
commands that work:

wp plugin list
wp plugin install hello-dolly
wp plugin activate hello-dolly
wp plugin deactivate hello-dolly
but this one does not work if ' ' or '&'
wp plugin delete hello-dolly

Command Line Log
wpBugTest.txt

@schlessera
Copy link
Member

I have looked into the code to see how this is done.

Strangely, while wp theme delete uses the WordPress function delete_theme(), wp plugin delete does not use the WordPress function delete_plugins() and directly uses the shell rm command instead.

@danielbachhuber Looking through the file history I fail to find a reason why this diverging behavior exists other than for historical reasons. Do you have additional insight here?

@schlessera schlessera added the bug label Oct 2, 2018
@schlessera
Copy link
Member

Note: Fixing the above bug is very probably only a matter of properly quoting the folder. However, I'd like to find out first whether we shouldn't rather move to using the Core's built-in delete_plugins() function instead.

@danielbachhuber
Copy link
Member

@schlessera The delete_plugins() WordPress function makes an external request for filesystem access: https://developer.wordpress.org/reference/functions/delete_plugins/#source

image

It looks like this was originally changed in wp-cli/wp-cli@86416ae

@schlessera
Copy link
Member

Ah, thanks, this linked to the missing piece: wp-cli/wp-cli#109 (delete_plugins() also runs uninstall_plugins())!

@schlessera
Copy link
Member

Proposed solution is to pass the $path through escapeshellarg() here: https://github.com/wp-cli/extension-command/blob/v2.0.2/src/Plugin_Command.php#L1135

return ! WP_CLI::launch( $command . escapeshellarg( $path ) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants