wp-cli / extension-command

Manages plugins and themes, including installs, activations, and updates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Referring to "local" for plugin install from zip file is wrong/misleading.

nextgenthemes opened this issue · comments

Basically nobody uses the wp-cli command on a system there the wp installation actually sits.

The most common scenario is that "local" is actually local and remote is the server where WP runs. Even if is a dev site inside a local virtualbox VM like in my case for my dev site its the exact same as for real sites on servers of webhosts or VPS.

The wp plugin install ./my-plugin.zip commands fails because it actually requires the file to be on the server , that is the opposite of "local".

What you actually need to do is:

  1. to transfer the file to the server, via scp or something.
  2. delete the plugin first if it already exits (different wp-cli issue actually, WP core has solved this somewhat recently, you can upgrade plugins with a .zip file upload now, wp-cli apparently does not use the same install functions as wp inside the admin UI)
  3. use the wp command again, preferably with an absolute path. install plugin install /tmp/my-plugin.zip
  4. remove the file if the installation was successful.

That should not be this way, all these extra steps should be done by the command itself. It should be able to install from a "local" file as the readme claims it does.

Same issue I reported recently about the post edit command that launches the editor on the server instead on where you have wp-cli installed locally. The command should actually launch EDITOR locally, not on the server.

Not sure if you can pipe the zip into the command or something but its just non-intuitive.

Ended up writing a script again and it's way to complex already. And this does not even work with zipfiles that are not exactly like plugin-slug.zip so plugins downloaded from wp.org that are like plugin-slug-1.2.3.zip will not work.

So this still does less than what the command should do. It should delete the plugin based on what folder is inside the zip. Not sure how I would do that, probably should rather spend the time on trying to actually do a PR to fix this but here it is:

#!/bin/bash
set -Eeuxo pipefail

readonly zipfile_path=$1                     # ./plugin-slug.zip
zipfile_basename=$(basename "$zipfile_path") # plugin-slug.zip
plugin_slug=$(basename "$zipfile_path" .zip) # plugin-slug
tmp_filename="/tmp/$zipfile_basename"        # /tmp/plugin-slug.zip

scp "$zipfile_path" vagrant@website.test:/tmp
wp plugin delete "$plugin_slug" || true
wp plugin install "$tmp_filename" --activate
ssh vagrant@website.test "rm $tmp_filename"

This lets me do a

for f in ./*.zip; do wp-plugin-install-zip "$f"; done

Thanks for the report, @nextgenthemes

Closing this issue in favor of continuing the discussion on wp-cli/wp-cli#5760 (comment)