wp-cli & Shell Command Library
The WordPress command line interface makes the work we do easy. This page also contains shell script commands that do not use wp-cli but are run the same way.
Commands
General
WordPress
File Management
Split a huge log file into smaller files
Breaks a file debug.log in the same directory into files named debug00.log, debug01.log, etc, with 50,000 lines each.
gsplit -l 50000 -d --additional-suffix=.log debug.log debug-
If command not found: gsplit, install it with brew install coreutils
.
Extract all URLs from a File
Copies all URLs in a file page_descriptions.csv pointing at https://example.com and saves them in a new file csv-urls.txt.
grep -Eo "https?://example.com[^\"]+" page_descriptions.csv > csv-urls.txt
Download a File from a Server so Slow rsync and FileZilla Timeout
Downloads public_html/wp-content/debug.log from slow servers without timing out. Assumes key authentication with server.example.net.
ssh [email protected] "cat public_html/wp-content/debug.log" > ~/sites/empty/wp-content/debug.log
Web Crawling
Follow & Print all Redirects
curl -s -L -D - https://example.com/documents -o /dev/null -w '%{url_effective}'
Media Library
Delete Gravity Forms file uploads
Deletes all files uploaded with form submissions. Frees disk space in local copies of sites.
rm -rf wp-content/uploads/gravity_forms/*
Multisite
Activate Plugin on Every Site
wp site list --field=url | xargs -n1 -I % wp --url=% plugin activate wp-api-disable-user-list/wp-api-disable-user-list.php
Find Sites Using a Specific Plugin
Reveals which blogs in a network have activated a specific plugin.
sites=$(wp site list --field=url)
for url in $sites; do
if wp plugin is-active "embed-pdf-gravityforms/embed-pdf-gravityforms.php" --url="${url}" --network; then
echo "${url}"
fi
done
Grant Super Admin to User
wp super-admin add [email protected]
Network-wide Search and Replace
Runs the wp search-replace
command on every site in a network.
wp site list --field=url | xargs -n1 -I % wp --url=% search-replace '[vehicle_form_field]' '[invp_vehicle vehicle]'
Plugins
Activate Plugins According to the Option
Syncs the plugin directory to the database option. Installs and activates plugins using the list stored in the site.
wp plugin list --status=active --field=file | xargs -n1 -I % wp plugin install % -–activate
Gravity Forms
Get Form Name by ID
Requires Gravity Forms add-on called Gravity Forms CLI.
wp gf form get 42 | jq -r '.title'
Posts
Delete All Post Revisions
wp post delete $(wp post list --post_type='revision' --format=ids) --force
Revert Elementor Taking Over a Post
Change the zero to an appropriate post or page ID.
wp post meta delete 0 _elementor_edit_mode
wp post meta delete 0 _elementor_template_type
wp post meta delete 0 _elementor_version
wp post meta delete 0 _elementor_css
Users
Change User Password
wp user update [email protected] --user_pass="h43v#sdsfg)fgh49gh@cY<3Tb4Wfk9ke"