I often reference this list of useful WordPress CLI commands to enhance or clean up my sites. Please be careful and make backups.
How to install WordPress CLI. Here you can checkout the commands.
List:
- Syncing High-Performance Order Storage
- Recovering WordPress after a fatal error from plugin update
- Cleaning Woocommerce trash products
- WordPress Hacking cleanup
- Cleaning unattached jpegs from the WordPress library
- Creating Dummy content
- Deleting spam comments
- Truly stopping comments
- Cleaning your website
- Checking the config file
- Checking the database size
- Running core update
- Plugins manipulation
- Reseting User Password
- Database Manipulations
wp wc cot syncwp plugin deactivate plugin-says-no --skip-pluginswp post delete $(wp post list --post_type=product --post_status=trash --format=ids) --forceThe following commands will remove any files that may have been created by a hacker. It will also remove any PHP files that are not part of the WordPress core. This is a very dangerous command and should be used with caution. It isn't a 100% guarantee that it will remove all the files that a hacker may have created, but it will remove most of them.
1. Download the script from the repository - /scripts/wp-hacking-cleanup.sh
2. chmod +x scripts/wp-hacking-cleanup.sh
3. ./scripts/wp-hacking-cleanup.shfor id in $(wp db query "SELECT ID FROM wp_posts where post_type='attachment' AND post_parent=0 AND post_mime_type='image/jpeg'" --silent --skip-column-names)
do
wp post delete --force $id
doneCleaning unattached jpegs from the WordPress library in batches. You can change the batch size by changing the value of the batch_size variable.
1. Download the script from the repository - /scripts/batch-delete-unattached-jpegs.sh
2. chmod +x scripts/batch-delete-unattached-jpegs.sh
3. ./scripts/batch-delete-unattached-jpegs.shwp post generate --count=10wp comment list --status=spam --format=ids | xargs wp comment delete --forcewp option update default_comment_status closed
wp option update default_ping_status closed
wp db query "UPDATE wp_posts SET comment_status='closed' WHERE post_status='publish';"
wp db query "UPDATE wp_posts SET ping_status='closed' WHERE post_status='publish';"wp site emptywp config getwp db size --tableswp core updatewp plugin listwp plugin installwp plugin update plugin-namewp plugin deactivate plugin-namewp plugin delete plugin-namewp user update user@example.com --user_pass=new-passwordwp db optimizewp db repairwp db export name.sql