wp cli - WP-CLI: detect altered core files and restore them automatically

admin2025-01-08  5

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.

Share Improve this question asked Apr 23, 2020 at 22:16 collimarcocollimarco 1113 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

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
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736268863a1308.html

最新回复(0)