You can remove unused themes and plugins using WP-CLI (WordPress Command Line Interface) with the following command:
wp plugin delete plugin-name
wp theme delete theme-name
If you want to delete all inactive themes and plugins, you can use the following script:
wp plugin delete $(wp plugin list --status=inactive --field=name)
wp theme delete $(wp theme list --status=inactive --field=name)
You can clean up the database using WP-Optimize or WP-Sweep plugins. Alternatively, you can use WP-CLI with the following command:
wp db optimize
You can remove spam comments using WP-CLI with the following command:
wp comment delete $(wp comment list --status=spam --format=ids)
You can clean up media files that are not attached to any posts or pages using the following script:
wp media regenerate --only-missing
wp media delete $(wp media list --unattached --format=ids)
Remember to always backup your site before running any scripts to ensure that you have a working version to restore to in case anything goes wrong. Do you need help or support? Feel free to contact us!