Skip to content

Instantly share code, notes, and snippets.

@BenBroide
Last active December 24, 2019 17:27
Show Gist options
  • Save BenBroide/29deea1d909f31269400571737d8183f to your computer and use it in GitHub Desktop.
Save BenBroide/29deea1d909f31269400571737d8183f to your computer and use it in GitHub Desktop.
This command will add a new multisite with slug demo-X and a editor role user and output site URL, user name and user pass. You must create manually a site with slug "demo-1" before running the script first time
wp site list --allow-root > sites-list.txt
siteslist=`tail -1 sites-list.txt | head -1`
lastsiteurl=`echo $siteslist | egrep -o 'https?://[^ ]+'`
lasturlclean=`echo ${lastsiteurl::-1}`
lastid=`echo $lasturlclean|grep -Eo '[0-9]+$'`
((lastid++))
newslug="demo-${lastid}"
newsiteurl=`wp site create --slug=$newslug --private --allow-root|awk '{print $5}'`
username="demo${lastid}"
useremail="demo${lastid}@demo.com"
timestamp=$( date +%T )
userpass="demo${lastid}${timestamp}"
wp user create $username $useremail --role="editor" --url=$newsiteurl --user_pass=$userpass --allow-root
wp user list --url=$newsiteurl --allow-root
message="Login URL: ${newsiteurl}wp-admin username: ${username} userpass: ${userpass}"
echo $message
echo "All Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment