Cookbook

Recipes for the chores that come up on every site

WP-CLI commands and bash scripts for automating WordPress maintenance. Copy one into a terminal, or run it across the fleet from the CaptainCore console.

Activate ACF Pro License Key Replace YOUR_PRO_LICENSE_KEY with your Advanced Custom Fields Pro license key. read -r -d '' php_code << 'heredoc' + 34 more lines Apply HTTPS URLs Changes HTTP references to HTTPS for a certain domain name. domain=my-domain-please-change-me.tld + 8 more lines Backing Up WordPress Site Over SSH Paste the following into terminal while connected over SSH. backup() { + 19 more lines Bulk Convert Images to WebP Create ~/private/bulk-convert-to-webp.sh with the following. Then chmod +x ~/private/bulk-convert-to-webp.sh to grant execute permissions and ~/private/bulk-convert-to-webp.sh to run. Targets images larger then 1MB. #!/bin/bash + 56 more lines Changing WordPress database prefix Changes WordPress database prefix by exporting database, updated references and then re-importing database. Be sure to update db_prefix_new to a new database… db_prefix=$( wp db prefix ) + 10 more lines Cleanup bad text encodings within database In rare case while doing a site migration sometimes characters like “ are replaced with “. This will clean up the most… wp search-replace "“" "“" --all-tables --report-changed-only + 7 more lines Configuring Gravity SMTP with Mailgun Configures Gravity SMTP to use Mailgun via SMTP connection with a fallback option to send out PHP mailer. // Changes the following variables + 29 more lines Convert MyISAM database tables to InnoDB Finds and converts any database tables using MyISAM storage engine to InnoDB. output=$( wp db query "SELECT COUNT(*) FROM information_schema.TABLES WHERE ENGINE = 'MyISAM'" --skip-column-names ) + 6 more lines Debug Slow Plugins Attempts to locate a plugin causing a significant slow down. function debug_slow_plugin { + 11 more lines Delete Inactive Themes Removes all inactive themes keeping only the latest default WordPress theme. echo "🔎 Finding the latest default WordPress theme to preserve..." + 49 more lines Disable Emails Inserts must-use plugin to disable outgoing emails. mkdir wp-content/mu-plugins + 2 more lines Disk Usage Overall disk usage within home WordPress directory. home=$( wp option get home ) + 2 more lines Divi Cache Purge Purge Divi theme static CSS file cache wp eval 'ET_Core_PageResource::remove_static_resources( "all", "all" );' Download file from Google Drive shared link Will download from a Google Drive shared link using wget. Swap out <google-file-id> and <file-name> with Google's unique file ID shown in… wget --no-check-certificate -r 'https://docs.google.com/uc?export=<google-file-id>' -O <file-name> Fetch database autoload size Generally a good idea to keep your database autoload below 1MB in size. You can see the current usage with the following.… echo "$(wp db query "SELECT ROUND(SUM(LENGTH(option_value))/1024/1024, 2) as autoload_size_MB FROM $(wp db prefix)options WHERE autoload='yes';" --skip-column-names --batch ) MB" Fetch PHP memory limit WordPress' memory limit can be independently set to anything however will not go over PHP's own limit. This will retrieve PHP's memory… php_version=$( php -v | head -n1 | cut -d ' ' -f 2 | cut -d '.' -f 1,2 ) + 18 more lines Hunt for certain WordPress user Search for a certain WordPress user. Will only respond if the account was found. Change user to either the login or email… [email protected] + 5 more lines Hunt Unnecessary Files on Kinsta Returns storage usage of debug.log file and private folder on Kinsta. results="" + 6 more lines Identifying Bottleneck Plugins The crude script will loop through each plugin and check load time. See here for an example output: https://app.warp.dev/block/P0mRiYKGhE2B6wQAD7q2x2. function find_slow_plugin() { + 136 more lines Install Events Calendar Pro Installs The Events Calendar and Event Calendar Pro and activates license. wp plugin install the-events-calendar --force --activate + 2 more lines Kinsta Cache Purge Purges cache on Kinsta. wp cache flush + 1 more line MonsterInsights turn off email summaries Turn off MonsterInsights email summaries if admin user is a certain email address. if [[ $( wp option get admin_email ) == "[email protected]" ]]; then + 3 more lines Overriding Recovery Emails Adds RECOVERY_MODE_EMAIL to wp-config.php file. [email protected] + 12 more lines Realtime Monitor Kinsta Access Logs Create ~/private/realtime-access-logs.sh with the following. Then chmod +x ~/private/realtime-access-logs.sh to grant execute permissions and ~/private/realtime-access-logs.sh to run. This will continuously monitor Kinsta's… #!/bin/bash + 49 more lines Search for User by Email Address Searches for a WordPress user account by email address. Will return the name of the site if found. read -r -d '' php_code << heredoc + 12 more lines Send Test Email Sends a test email. wp eval 'wp_mail( "[email protected]", "Verifying Email Health", "Looks like it worked.", ["Content-Type: text/html; charset=UTF-8"] );' Show Kinsta PHP Workers Lists out current PHP workers on a site hosted with Kinsta. ps -e --format "pid uname comm %cpu %mem time" --sort "time" --no-headers | grep php-fpm.* | grep -v "grep" | grep -v "root" Suspend WordPress Injects mu-plugin suspend-wp.php which turns off front end of WordPress. Customize header, description and message variables at the top before running. header="Website Suspended" + 83 more lines Update Everything Updates all plugins, themes, and WordPress core if needed. # Plugin updates + 53 more lines