I know that there is a command to verify the integrity of the core files:
$ wp core verify-checksums
In case a file is corrupted or altered, is there any WP-CLI command to automatically restore all those files? E.g. download those files from the official repository and restore.
This could be a useful command to run every 24 hours for example, together with any updates, in order to keep the Wordpress installation intact and safe.
I know that there is a command to verify the integrity of the core files:
$ wp core verify-checksums
In case a file is corrupted or altered, is there any WP-CLI command to automatically restore all those files? E.g. download those files from the official repository and restore.
This could be a useful command to run every 24 hours for example, together with any updates, in order to keep the Wordpress installation intact and safe.
Just reinstall the current version of WordPress Core with:
wp core download --force
For a bash script, you could modify this one from https://dannyvankooten.com/periodically-check-wp-core-file-modifications/. You would need to make it run the download command, rather than send a notification.
#!/bin/bash
cd /my/wp/directory
if [ -e /tmp/wp-core-verify-checksums-notified ]; then
exit
fi
if [ ! $(wp core verify-checksums) ]; then
curl https://api.pushbullet.com/api/pushes \
-u MY_API_KEY: \
-d type=note \
-d title="WP checksum verification failed." \
-d body="Checksum of your WP core files does not match the checksum of original core files. What up with that?" \
-X POST
touch /tmp/wp-core-verify-checksums-notified
fi
Extending on the @RobertoJubet answer you can reinstall the version of Wordpress used by the site with a command like
wp core download --version=$( wp core version ) --force