Script: Update WordPress core and plugins, without touching other dependencies

Hi there! This is a little script I just wrote with the help of ChatGPT that updates only the WP core and plugins to their latest respective versions, including major version jumps (many WP plugins don’t respect Semver!). The script leaves non-WP-dependencies untouched (with those you might want to retain more control about the installed version, whereas with WP deps, you likely always simply want the latest version when updating).

#!/bin/bash

# Step 1: Extract package names into a variable
PACKAGES=$(jq -r '.packages[] | select(.type == "wordpress-plugin" or .type == "wordpress-muplugin") | .name' composer.lock)

# Step 2: Echo the packages to the console
echo "The following packages will be updated to their latest versions:"
echo "$PACKAGES"

# Step 3: Require all WordPress plugins and the core
composer require roots/wordpress $(echo "$PACKAGES") --with-all-dependencies

It’s basically the composer equivalent of the WP CLI command wp core update && wp plugin update --all

Features

  • Updates the WordPress core to the latest version, including major version jumps
  • Updates all installed WP plugins to the latest version, including major version jumps
  • The plugin update part relies on the package type to find WP (mu-)plugins. Should work with wpackagist, direct composer packages, vcs repos and whatnot.

System Requirements

  • jq needs to be installed on your machine.

Installation & Usage

  • Create a script update-wp-deps.sh somewhere in your bedrock project
  • Copy the script into that file
  • Allow execution: chmod +x ./path/to/update-wp-deps.sh
  • Run from your project root: ./path/to/update-wp-deps.sh
  • You might want to commit the script to version control to make it accessible for everyone collaborating on the project (including your future self).

Hope it proves useful to some of you out there :slight_smile:

4 Likes