Last active
December 7, 2016 01:02
-
-
Save ptasker/a888549e98c4f443d5550ab7e05f397f to your computer and use it in GitHub Desktop.
Unsplash.it WordPress image importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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