๐—ฃ๐—ถ๐—ป๐—ฝ๐—ผ๐—ถ๐—ป๐˜ ๐—ฅ๐—ผ๐—น๐—น๐—ฏ๐—ฎ๐—ฐ๐—ธ ๐—ช๐—ถ๐˜๐—ต ๐—ช๐—ฃ-๐—–๐—Ÿ๐—œ

You update 20 plugins at once. One plugin breaks your site.

Most tools roll back all 20 updates to keep things safe. This is a standard approach. However, you often want to keep the 19 working updates and only revert the one broken plugin.

You can build this logic using WP-CLI.

The core command is: wp plugin install --version=1.2.3 --force --skip-plugins --skip-themes

Here is what these flags do:

โ€ข --version=1.2.3: Installs a specific older version from WP.org. โ€ข --force: Overwrites the current plugin files. โ€ข --skip-plugins --skip-themes: Prevents WP-CLI from loading broken code during the process.

To make this work, you must change your update strategy. Do not update in bulk. Update one plugin at a time and check the site status after each step.

Follow this workflow:

  1. Check site health: GET / returns 200 OK.
  2. Update one plugin: wp plugin update .
  3. Check site health again.
  4. If the site returns a 500 error, that plugin is the cause.
  5. Roll back that specific plugin using the install command with the previous version.
  6. Verify the site is back to 200 OK.
  7. Move to the next plugin.

To automate this, save a list of your current versions before you start: wp plugin list --format=json --skip-plugins --skip-themes > /tmp/plugins_before.json

You can use jq to pull the exact version number of the failed plugin from this file.

This method has three main advantages:

One warning: rolling back files does not always fix a site. If a plugin changed your database schema, replacing the files will not help. If the site stays broken after a rollback, you must move to a full database restore.

Per-plugin rollback is more complex to build than bulk rollback. But it provides much better control over your production environment.

Source: https://dev.to/susumun/pinpoint-rollback-building-per-plugin-revert-with-wp-cli-5go5