Skip to content

Instantly share code, notes, and snippets.

@ptasker
Last active December 7, 2016 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptasker/a888549e98c4f443d5550ab7e05f397f to your computer and use it in GitHub Desktop.
Save ptasker/a888549e98c4f443d5550ab7e05f397f to your computer and use it in GitHub Desktop.
Unsplash.it WordPress image importer
#!/usr/bin/env bash
DIR="$1"
COUNT="$2"
WP_DIR="$3"
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
then
echo "Usage: $0 {photos folder dir path} $1 {number of photos} $2 {Absolute directory where WordPress is installed}"
exit 1
fi
if [ ! -d "$DIR" ]
then
echo "Creating folder $DIR\n"
mkdir $DIR
else
echo "$DIR exists\n"
fi
#Loop based on the $COUNT var passed
for ((i=1; i<=$2; i++)); do
wget "https://unsplash.it/500/500/?random" -O "$DIR/image-$i.jpg"
done
echo "Importing images to WordPress installed at $WP_DIR\n"
wp --path="$3" media import $DIR/**.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment