Local development
To work on your WPCS Product locally there are two things that need to be done: setting up a local dev environment using a snapshot in WPCS and deploying a local installation to WPCS.
This article assumes you have correctly set up your credentials.
Locally develop
Pulling a snapshot
Firstly, let's set up a local development environment based on a snapshot that you have in WPCS.
Run the following to retrieve a list of all the snapshots that are currently in your Product. This command returns some data about the snapshots including the name and their ID:
wpcs snapshots list
Example output:
[
{
id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa',
versionId: '11111111-1111-1111-1111-111111111111',
dateCreated: '2022-01-01T12:00:00.000000+00:00',
name: 'Example snapshot name',
isCustomSnapshot: false,
isTenantSnapshot: false,
statusCode: 1,
statusName: 'Done'
}
]
Take note of the ID, we will use it in the following command to actually download ('pull') the snapshot locally. Make sure to use the ID of the snapshot you wish to download:
wpcs snapshot pull aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa
The output you see is the path of the snapshot file that was downloaded. It will look something like this on MacOS:
> /var/folders/v3/5wckmhvn0wn4bqz7l90pns0r/T/wpcs/snapshots/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa.tgz
Importing a snapshot into a local WordPress installation
For the next part of the process, you need to make sure to run commands from the root directory of the WordPress installation you wish to import the snapshot into. This means that you need to be in the same directory as the wp-config.php
file.
We will use the above output as the example path of the pulled snapshot. The command to import the snapshot file comes down to this:
wpcs local import --path /var/folders/v3/5wckmhvn0wn4bqz7l90pns0r/T/wpcs/snapshots/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa.tgz
If the import was successful you will get a message saying Snapshot successfully imported
after some other output alerting you to progress.
Make sure that when you are using software like Local you run the WPCS CLI via the "Open site shell" button. If you do not, you will not be able to connect to the database of the running WordPress installation.
Deploying
Once you are ready to push your changes to a new WPCS Version, go to the root folder of your WordPress install (the folder where your wp-config.php
is) and run the following command:
wpcs local deploy --name "My new version"
This will create a snapshot and push that snapshot to a new Version in WPCS called "My new version".