Advanced usage
Automation
VIP-CLI can be used for automating common flows and tasks for your team both locally and in CI contexts (e.g. triggering Data Sync on a schedule; running WP-CLI commands across all environments). To do this, you can bypass the authentication prompt by creating a config file.
First, generate a new token from the VIP Dashboard (click on “Set up CLI”). Then create a file called ~/.config/configstore/vip-go-cli.json
with the following:
{
"vip-go-cli": "{YOUR-TOKEN-GOES-HERE}"
}
If the token is valid, you should now be able to run vip app list
or any other authenticated commands.
Note: For any automation, we highly recommend setting up a bot/machine user and generating a token using that account.
Skipping command confirmation
When trying to run a command on a production environment, we prompt you to confirm your actions. If you want to skip this confirmation step (e.g. using the command as part of a script), you can bypass it by passing the --yes
(or -y
) flag before the wp
command.
Example commands on this page include my-site
as the alias of the app and develop
as the app environment:
$ vip @my-site.develop --yes -- wp option get siteurl
Referencing a file input
If you have uploaded a file to your GitHub repository that you’d like to use in a CLI command, you can reference the path of the file via /var/www/wp-content/<path to file>
.
Writing command output to a file
All WP-CLI commands are run on a remote web server. Any file operations during a command will occur on the remote server as well with no way to retrieve the file.
If you do need to write to a file, we suggest writing the output to the console first (using helpers like WP_CLI::line()
and WP_CLI::log()
) and then redirecting it to your desired file:
$ vip @my-site.develop --yes -- wp option get siteurl > output.txt
Nested commands
When running more complex WP-CLI commands such as loops or nested commands, you need to ensure that each reference to wp
uses the remote execution pattern:
❌ This will not work:
$ vip @my-site.develop -- wp post delete $(wp post list --post_type='page' --format=ids)
-bash: xyz: command not found
This is actually two commands, (1) a post list that retrieves a list of ids that is then (2) passed into a delete command. This will not work as intended because the command inside the $()
is referencing the local version of wp
(i.e. on your computer).
At best, a message will appear indicating wp
doesn’t exist locally. At worst, if run from a local WordPress site directory, it will get post_ids from the local WordPress site that will then be passed to the delete command to be run against the remote site.
✅ This will work:
$ vip @my-site.develop -- wp post delete $(vip @my-site.develop -- wp post list --post_type='page' --format=ids)
Looping
Due to the way that shell utilities handle stdin
, commands like xargs
may not always work with WP-CLI as expected. In these cases it might be easier to write the commands to a file and then execute that file.
❌ This will not work:
$ vip @my-site.develop -- wp post list --fields=ID --format=csv --posts_per_page=5 | xargs -I % 'vip @my-site.develop -- wp post update % --post_category=NewCategory '
✅ This will work:
$ vip @my-site.develop -- wp post list --fields=ID --format=csv --posts_per_page=5 | xargs -I % sh -c 'echo "vip @my-site.develop -- wp post update % --post_category=NewCategory" >> commands.sh '
$ chmod +x commands.sh
$ ./commands.sh