From 295cb0e66db6a5f9b9851f24e7bf2064917f5bc9 Mon Sep 17 00:00:00 2001 From: Matt Way Date: Mon, 12 Aug 2024 09:20:00 +1000 Subject: [PATCH] Add script to bulk upload media --- bulk-upload-media.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 bulk-upload-media.sh diff --git a/bulk-upload-media.sh b/bulk-upload-media.sh new file mode 100644 index 0000000..8c6f144 --- /dev/null +++ b/bulk-upload-media.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Tries to upload media to wordpress and stores a json file with the ID and url of the media. + +# This script uses the jq, and wp commands, make sure they are installed before running this script. + +# Additionally, make sure the wp-cli/restful package is installed in the wp command (via "wp package install wp-cli/restful") + +# Controls the flags that are passed to every usage of the wp command. +WP_FLAGS="--allow-root --path=/var/www/html" + +path="$1" + +if test -d "$path"; then + echo "Found $path, starting upload." + for file in "$path"/*.jpg; do + ./upload-media.sh "$file" + done + for file in "$path"/*.jpeg; do + ./upload-media.sh "$file" + done + for file in "$path"/*.png; do + ./upload-media.sh "$file" + done + for file in "$path"/*.gif; do + ./upload-media.sh "$file" + done +else + echo "Could not find $path" +fi