This article describes how to use the wp-toolkit program to manage WordPress sites from the command line, as well as how to use it in cron jobs to automate tasks.
It is often quicker and easier to do many tasks at the command line, and WordPress administration is no exception. You can use the wp-toolkit program to back up and restore WordPress sites, install plugins and themes, reset the administrator password, and more. Additionally, you can run wp-toolkit in cron jobs to automate tasks.
wp-toolkit has many commands, and the rest of this article is only an introduction to its capabilities. However, to view the wp-toolkit online help at any time, type the following command:
Alternatively, to view the online help for a specific wp-toolkit subcommand, add the -command option. For example, to view the online help for the wp-toolkit—list command, type the following command:
wp-toolkit --help -command list
To view a listing of the WordPress sites managed by WordPress Toolkit on your account, type the following command:
A listing appears that resembles the following output:
ID Installation Path Owner ID State Hidden Website URL Name Version 1 /public_html/wp 2 Outdated PHP false https://example.com/wp My Website 5.8.1 2 /public_html/wp2 2 Outdated PHP false https://example.com/wp2 My Other Website 5.8.1
To list information about a WordPress installation managed by WordPress Toolkit, type the following command. Replace X with the instance ID of the installation that you want to check:
wp-toolkit --info -instance-id X
This command displays information about the site, such as:
wp-toolkit uses the concept of a set to manage plugins and themes. A set is a custom collection of themes and plugins that you can install on your sites. For example, you could create a “Basic” set that contains plugins and themes you want available on all of your sites, and an “Extras” set that contains additional plugins you may not want to install on every site.
Let's create a simple set that contains one plugin and one theme. The first step is to upload the plugin and theme to the wp-toolkit cache. To upload a plugin, you need the URL to the plugin's zip file. You can obtain this from the wordpress.org site. The following command demonstrates how to upload the “Hello Dolly” plugin to the cache:
wp-toolkit --plugins -operation add -source-url https://downloads.wordpress.org/plugin/hello-dolly.1.7.2.zip
Next, we upload a theme. To upload a theme, you need the URL to the theme's zip file, which you can obtain from the wordpress.org site. The following command demonstrates how to upload the “Twenty Twenty” theme to the cache:
wp-toolkit --themes -operation add -source-url https://downloads.wordpress.org/theme/twentytwenty.1.8.zip
Now we are ready to create a set. Let's call the set “Basic”. To create this set, we run the following command:
wp-toolkit --sets -operation add -name Basic
After we create the set, wp-toolkit shows the set's ID number, which we need for subsequent commands. In this case, the set ID is 7:
ID Name Owner GUID 7 Basic 9475252e-1234-4321-4444-4923d4521ae7
We are ready to add the plugin and theme to the set. To do this, we need the set ID, the plugin's slug, and the theme's slug. The slug is usually the basename of the zip file. For example, the slug of hello-dolly.1.7.2.zip is hello-dolly, and the slug of twentytwenty.1.8.zip is twentytwenty.
Here is the command to add the plugin to the set:
wp-toolkit --sets -operation add-plugin -set-id 7 -plugin-slug hello-dolly
The command to add the theme to the set is similar:
wp-toolkit --sets -operation add-theme -set-id 7 -theme-slug twentytwenty
We now have a “Basic” set that contains the “Hello Dolly” plugin and “Twenty Twenty” theme. To confirm this, run the following command:
wp-toolkit --sets -operation info -set-id 7
wp-toolkit lists the plugins and themes that belong to the set.
To install this set on a WordPress installation, we run the following command, replacing X with the instance ID of the installation on which we want to install the set:
wp-toolkit --sets -operation install -set-id 7 -instance-id X
This is a simple example to give you an idea of how sets work. Typically, a set contains multiple plugins and themes to make site configuration easier.
With wp-toolkit, you can easily configure Smart Updates for your WordPress sites.
To check the Smart Updates status of a WordPress installation, type the following command. Replace X with the instance ID of the installation to check:
wp-toolkit --smart-update -operation status -instance-id X
To enable Smart Updates, type the following command. Replace X with the instance ID of the installation:
wp-toolkit --smart-update -operation enable -instance-id X
To disable Smart Updates, type the following command. Replace X with the instance ID of the installation:
wp-toolkit --smart-update -operation disable -instance-id X
You can quickly and easily back up and restore site content using wp-toolkit. All files and the database (which includes posts, pages, comments, and categories ) are exported to a compressed .tar.gz file. This backup file is located in the /home/username/wordpress-backups directory, where username represents your account username.
To back up a WordPress installation, type the following command. Replace X with the instance ID of the installation to back up:
wp-toolkit --backup -operation backup -instance-id X
When this command finishes, you can transfer the .tar.gz file to a safe location.
To restore a backup, type the following command. Replace X with the instance ID of the installation, and replace filename with the name of the backup file to restore (do not include the full path, specify only the filename):
wp-toolkit --backup -operation restore -instance-id X -filename filename
To obtain a list of backup files available for restoration, type the following command. Replace X with the instance ID of the installation:
wp-toolkit --backup -operation list -instance-id X
You can use wp-toolkit to reset the WordPress administrator password. To do this, type the following command. Replace username with the login name of the administrator, and replace X with the instance ID of the installation:
wp-toolkit --site-admin-reset-password -admin-login username -instance-id X
After you run this command, wp-toolkit displays the new, randomly generated password for the specified administrator.
By combining wp-toolkit's functionality with cron jobs, you can automatically do administrative tasks that are time consuming and repetitive from the graphical administration interface.
For example, the following cron line demonstrates how to back up a WordPress site automatically every day at 2:15 AM by using wp-toolkit:
15 2 * * * /usr/local/bin/wp-toolkit --backup -operation backup -instance-id id >/dev/null 2>&1
For more information about the wp-toolkit program, please visit https://docs.cpanel.net/knowledge-base/cpanel-developed-plugins/wordpress-toolkit-command-line-interface.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.