Skip to content

Instantly share code, notes, and snippets.

@charleslouis
Last active July 8, 2017 03:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save charleslouis/00dd5d17cc86ef7f55f1 to your computer and use it in GitHub Desktop.
Save charleslouis/00dd5d17cc86ef7f55f1 to your computer and use it in GitHub Desktop.
#WP-CLI, #Wordpress, #shell, #Alias, #batch, aliases, helpers and shortcuts for wp-cli,
##########################################
# WP-cli
##########################################
ALIASES
##########################################
alias wpcdl=wp_core_download
alias wpcc=wp_core_config
alias wpci=wp_core_install
alias wpdbd=wp_db_drop
alias wpdcr=wp_db_create
alias wph="wp $1 --help"
alias wphc="wp core $1 --help"
alias wphr="wp rewrite $1 --help"
alias wphsr="wp search-replace $1 --help"
alias wphcc="wp cache $1 --help"
alias wphdb="wp db $1 --help"
alias wphm="wp menu $1 --help"
alias wpho="wp option $1 --help"
alias wphp="wp plugin $1 --help"
alias wpht="wp theme $1 --help"
alias wphu="wp user $1 --help"
alias wphpost="wp post $1 --help"
SHORTCUT FUNCTIONS
##########################################
wp_core_download() {
download="wp core download "
read -p "Which locale (language) do you need ? (fr=fr_FR / en=en_EN) | default=en_EN : " -n 2 -r
echo # (optional) move to a new line
if [[ $REPLY = "fr" || "FR" ]]
then
download=$download' --locale=fr_FR'
fi
eval $download;
}
wp_core_config() {
config="wp core config "
# --dbname=
current_dir="${PWD##*/}"
dbname=$current_dir"_wp"
read -p "db name (default = $dbname) : "
if [[ $REPLY ]]
then
dbname=$REPLY
fi
config=$config" --dbname="$dbname
# --dbuser=
read -p "User (default = root) : "
user="root"
if [[ $REPLY ]]
then
user=$REPLY
config=$config" --dbuser="$user
else
config=$config" --dbuser=root"
fi
# --dbpass=
read -p "pass (default = "") : "
if [[ $REPLY ]]
then
pass=$REPLY
config=$config" --dbpass="$pass
fi
# --dbhost=
read -p "Host (default = localhost) : "
host="localhost"
if [[ $REPLY ]]
then
host=$REPLY
config=$config" --dbhost="$host
else
config=$config" --dbhost=localhost"
fi
# validation
validate_wp_conf(){
echo "You're about to setup your worpress site with the following configuration: "
echo $config
read -p" continue ? [y/n] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
eval $config
else
read -p "You're about to abort configuration. Are you sure ? [y/n] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
else
validate_wp_conf
fi
fi
}
validate_wp_conf
}
wp_core_install() {
# store base commands of wp in wp core install
install="wp core install "
current_dir="${PWD##*/}"
wpci_url(){
default_url="http://localhost/"$current_dir
read -p "Provide a url ( Default url = "$default_url" ) : "
echo # (optional) move to a new line
install=$install' --url='
if [[ $REPLY ]]
then
if [[ $REPLY =~ $regex_url ]]
then
install=$install$REPLY
else
echo 'Please provide a valid url.'
read -p " Try again ? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
wpci_url
fi
fi
else
install=$install$default_url
fi
}
wpci_name(){
read -p "Provide a title ( Default title = "$current_dir" ) : "
echo # (optional) move to a new line
install=$install' --title='
if [[ $REPLY ]]
then
if [[ $REPLY =~ $regex_wp_site_title ]]
then
REPLY=$(printf %q "$REPLY")
install=$install$REPLY
else
echo 'Please provide a valid url.'
read -p " Try again ? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
wpci_name
fi
fi
else
install=$install$current_dir
fi
}
wpci_url
wpci_name
install=$install' --admin_user=charles-louis --admin_password=wam --admin_email=charleslouis@lasourisetlepiano.com'
# run wp core install
eval $install
}
wp_db_drop() {
echo "You're about the current WordPress database"
echo
read -p" continue ? [yes] " -n 3 -r
echo
if [[ $REPLY =~ "yes" ]]
then
echo
drop="wp db drop "
eval $drop
echo
fi
}
wp_db_create() {
echo "You're about the current WordPress database"
echo
read -p" continue ? [yes] " -n 3 -r
echo
if [[ $REPLY =~ "yes" ]]
then
echo
create="wp db create "
eval $create
echo
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment