├── README.md ├── wp_cli_helpers ├── wp_core ├── wp_core_config ├── wp_core_download ├── wp_core_install ├── wp_db ├── wp_help ├── wp_menu ├── wp_options ├── wp_plugin ├── wp_post ├── wp_rewrite └── wp_theme /README.md: -------------------------------------------------------------------------------- 1 | WP CLI HELPERS 2 | ============== 3 | 4 | ## Description 5 | WP-CLI Helpers is a bundle of shell time saver aliases and function for wp-cli (http://wp-cli.org/). 6 | 7 | ## Video demos : 8 | See it in action with these short videos : 9 | - [Install wordpress in less than one minute with wp-cli ](https://www.youtube.com/watch?v=UH7gPxQm_1s&index=3&list=PLNKPjf-nKdiaon_IV3r6EI71IdcQ8_nZC 10 | ) 11 | - [wp rewrite rule in 30 seconds with wp-cli ](http://www.youtube.com/watch?v=XhbRkyMww5U&feature=share&list=PLNKPjf-nKdiaon_IV3r6EI71IdcQ8_nZC&index=2) 12 | - [Manage wordpress options in an eye blink](http://youtu.be/dECMEPvTT-c) 13 | - [Update your wordpress plugins in less than 30 seconds with wp-cli](http://youtu.be/zRlrPsdn2vY) 14 | 15 | ## Examples 16 | 17 | - run `cdwpt` to switch to theme directory 18 | - run `cdwpp` to switch to plugin directory 19 | - run `wpcdl` to download wp and choose your locale (language) 20 | - run `wpci` to quickly install WP with default options 21 | - run `wph` followed by any argument(s) to run `wp $myarg(s) --help` 22 | - run `wppli $plugin_slug` to quickly install a plugin $plugin 23 | - run `wpoa` to add an option with a prompter 24 | 25 | 26 | 27 | 28 | ## Installation 29 | Run `wpget https://github.com/kartonnade/wp_cli_helpers/archive/master.zip` or `curl https://github.com/kartonnade/wp_cli_helpers/archive/master.zip` or [download wp_cli_helpers as a zip file](https://github.com/kartonnade/wp_cli_helpers/archive/master.zip). 30 | Plug all the scripts in a folder such as "wp_cli_helpers" in your $HOME directory and source the main file from your .bash_profile like so : 31 | 32 | ```` 33 | if [ -f "${HOME}/wp_cli_helpers/.wp_cli_helpers" ] ; then 34 | source "${HOME}/wp_cli_helpers/.wp_cli_helpers" 35 | fi 36 | ```` 37 | 38 | # Details 39 | 40 | #### WP DB [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_db) 41 | 42 | ```` 43 | alias wpdbd=wp_db_drop 44 | alias wpdbc=wp_db_create 45 | ```` 46 | 47 | #### WP REWRITE [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_rewrite) 48 | Manage rewrite rules by simply running `wprwr` 49 | 50 | 51 | #### WP OPTIONS [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_options) 52 | ```` 53 | alias wpog="wp option get $1" 54 | alias wpou="wp option update $1 $2" 55 | alias wpod="wp option delete $1" 56 | alias wpoa=wp_option_add 57 | alias wpfront="wp option update page_on_front $1" 58 | alias wpfrontpage="wp option update show_on_front page" 59 | alias wpfrontpost="wp option update show_on_front post" 60 | ```` 61 | 62 | 63 | #### WP CORE 64 | - [see wp_core](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_core) 65 | - [see wp_core_download](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_core) 66 | - [see wp_core_config](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_core) 67 | - [see wp_core_install](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_core) 68 | ```` 69 | alias wpcdl=wp_core_download 70 | alias wpcc=wp_core_config 71 | alias wpci=wp_core_install 72 | 73 | alias cdwp=go_to_wp_home_dir 74 | alias wpd=open_wp_home_page_in_browser 75 | ```` 76 | 77 | #### WP CORE DOWNLOAD [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_core_download) 78 | 79 | ```` 80 | wp_core_download() { 81 | download="wp core download " 82 | read -p "Which locale (language) do you need ? (fr=fr_FR / en=en_EN) | default=en_EN : " -n 2 -r 83 | echo # (optional) move to a new line 84 | if [[ $REPLY = "fr" || "FR" ]] 85 | then 86 | download=$download' --locale=fr_FR' 87 | fi 88 | eval $download; 89 | } 90 | ```` 91 | 92 | #### WP HELP [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_help) 93 | 94 | ```` 95 | alias wph="wp $1 --help" 96 | alias wphc="wp core $1 --help" 97 | alias wphr="wp rewrite $1 --help" 98 | alias wphsr="wp search-replace $1 --help" 99 | alias wphcc="wp cache $1 --help" 100 | alias wphdb="wp db $1 --help" 101 | alias wphm="wp menu $1 --help" 102 | alias wpho="wp option $1 --help" 103 | alias wphpl="wp plugin $1 --help" 104 | alias wpht="wp theme $1 --help" 105 | alias wphu="wp user $1 --help" 106 | alias wphp="wp post $1 --help" 107 | alias wphmloc="wp menu location $1" 108 | alias wphmls="wp menu list $1" 109 | ```` 110 | #### WP THEME [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_theme) 111 | 112 | ```` 113 | alias wpt="wp theme $1" 114 | alias wpta="wp theme activate $1" 115 | alias wpte="wp theme enable $1" 116 | alias wptd="wp theme disable $1" 117 | alias wptdel="wp theme delete $1" 118 | alias wptl="wp theme list" 119 | alias wptup="wp theme update $1" 120 | alias wpts="wp theme status $1" 121 | alias wptpath="wp theme path $1" 122 | alias wptsearch="wp theme search $1" 123 | alias wptd=go_to_theme_dir 124 | alias wpatd=go_to_active_theme_dir 125 | ```` 126 | 127 | #### WP PLUGIN [see the file](https://github.com/kartonnade/wp_cli_helpers/blob/master/wp_plugin) 128 | 129 | ```` 130 | alias wppl="wp plugin $1" 131 | alias wpplg="wp plugin get $1" 132 | alias wppla="wp plugin activate $1" 133 | alias wpple="wp plugin enable $1" 134 | alias wppld="wp plugin disable $1" 135 | alias wppldel="wp plugin delete $1" 136 | alias wppll="wp plugin list" 137 | alias wpplup="wp plugin update $1" 138 | alias wppls="wp plugin status $1" 139 | alias wpplpath="wp plugin path $1" 140 | alias wpplsearch="wp plugin search $1" 141 | 142 | alias wpplgacf="wpplg 'Advanced Custom Fields'; wpplg advanced-custom-field-repeater-collapser" 143 | 144 | go_to_plugin(){ 145 | plugin_path=$(wp plugin path) 146 | cd $plugin_path 147 | } 148 | alias cdwppl=go_to_plugin 149 | ```` 150 | 151 | 152 | ## ALL ALIASES 153 | ```` 154 | alias wp_acf='wppli advanced-custom-fields; wppla advanced-custom-fields' 155 | alias wp_seo='wppli advanced-custom-fields, wppla advanced-custom-fields' 156 | alias wpatd='go_to_active_theme_dir' 157 | alias wpcc='wp_core_config' 158 | alias wpcdl='wp_core_download' 159 | alias wpci='wp_core_install' 160 | alias wpd='open_wp_home_page_in_browser' 161 | alias wpdbc='wp_db_create' 162 | alias wpdbd='wp_db_drop' 163 | alias wpfoundationpress='git clone https://github.com/olefredrik/FoundationPress.git;' 164 | alias wpfront='wp option update page_on_front ' 165 | alias wpfrontpage='wp option update show_on_front page' 166 | alias wpfrontpost='wp option update show_on_front post' 167 | alias wph='wp --help' 168 | alias wphc='wp core --help' 169 | alias wphcc='wp cache --help' 170 | alias wphdb='wp db --help' 171 | alias wphm='wp menu --help' 172 | alias wphmloc='wp menu location ' 173 | alias wphmls='wp menu list ' 174 | alias wpho='wp option --help' 175 | alias wphp='wp post --help' 176 | alias wphpl='wp plugin --help' 177 | alias wphr='wp rewrite --help' 178 | alias wphsr='wp search-replace --help' 179 | alias wpht='wp theme --help' 180 | alias wphu='wp user --help' 181 | alias wpmc='wp menu create ' 182 | alias wpmla='wp menu location assign ' 183 | alias wpmll='wp menu location list ' 184 | alias wpmlr='wp menu location remove ' 185 | alias wpmls='wp menu list ' 186 | alias wpoa='wp_option_add' 187 | alias wpod='wp option delete ' 188 | alias wpog='wp option get ' 189 | alias wpou='wp option update ' 190 | alias wppal='wp post list --post_type=page ' 191 | alias wppcff='wp_post_create_from_files' 192 | alias wppdl='wp_post_delete' 193 | alias wppfc='wp_post_file_create' 194 | alias wppg='wp_post_generate' 195 | alias wppl='wp plugin ' 196 | alias wppla='wp plugin activate ' 197 | alias wpplda='wp plugin deactivate ' 198 | alias wpplg='wp plugin get ' 199 | alias wppli='wp plugin install ' 200 | alias wppll='wp plugin list' 201 | alias wpplpath='wp plugin path ' 202 | alias wppls='wp plugin status ' 203 | alias wpplsearch='wp plugin search ' 204 | alias wpplun='wp plugin uninstall ' 205 | alias wpplup='wp plugin update ' 206 | alias wppol='wp post list --post_type=post,wppolpage ' 207 | alias wpreverie='git clone wpgit@github.com:kartonnade/reverie.git' 208 | alias wprwr='rewrite_rules' 209 | alias wpt='wp theme ' 210 | alias wpta='wp theme activate ' 211 | alias wptd='go_to_theme_dir; wpts' 212 | alias wptdel='wp theme delete ' 213 | alias wpte='wp theme enable ' 214 | alias wptl='wp theme list' 215 | alias wptpath='wp theme path ' 216 | alias wpts='wp theme status ' 217 | alias wptsearch='wp theme search ' 218 | alias wptup='wp theme update ' 219 | 220 | ```` 221 | ```` 222 | ```` 223 | ```` 224 | ```` 225 | ```` 226 | ```` 227 | -------------------------------------------------------------------------------- /wp_cli_helpers: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP-cli 4 | ########################################## 5 | 6 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_core" ] ; then 7 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_core" 8 | fi 9 | 10 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_core_download" ] ; then 11 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_core_download" 12 | fi 13 | 14 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_core_config" ] ; then 15 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_core_config" 16 | fi 17 | 18 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_core_install" ] ; then 19 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_core_install" 20 | fi 21 | 22 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_db" ] ; then 23 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_db" 24 | fi 25 | 26 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_plugin" ] ; then 27 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_plugin" 28 | fi 29 | 30 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_menu" ] ; then 31 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_menu" 32 | fi 33 | 34 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_post" ] ; then 35 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_post" 36 | fi 37 | 38 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_help" ] ; then 39 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_help" 40 | fi 41 | 42 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_rewrite" ] ; then 43 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_rewrite" 44 | fi 45 | 46 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_options" ] ; then 47 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_options" 48 | fi 49 | 50 | if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_theme" ] ; then 51 | source "${HOME}/profile_scripts/wp_cli_helpers/wp_theme" 52 | fi 53 | 54 | # if [ -f "${HOME}/profile_scripts/wp_cli_helpers/wp_" ] ; then 55 | # source "${HOME}/profile_scripts/wp_cli_helpers/wp_" 56 | # fi -------------------------------------------------------------------------------- /wp_core: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP CORE 4 | ########################################## 5 | 6 | # CORE 7 | alias wpcdl=wp_core_download 8 | alias wpcc=wp_core_config 9 | alias wpci=wp_core_install 10 | 11 | alias cdwp=go_to_wp_home_dir 12 | alias wpd=open_wp_home_page_in_browser 13 | 14 | go_to_wp_home_dir(){ 15 | home=$(wp option get home) 16 | home_dir=$(basename $home) 17 | # cd to wamp/www 18 | cdwamp 19 | # cd to wp_install/wp_posts_to_create 20 | cd $home_dir 21 | } 22 | 23 | open_wp_home_page_in_browser(){ 24 | home=$(wp option get home) 25 | cygstart $home 26 | } -------------------------------------------------------------------------------- /wp_core_config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP CORE CONFIG 4 | ########################################## 5 | wp_core_config() { 6 | config="wp core config " 7 | 8 | # --dbname= 9 | current_dir="${PWD##*/}" 10 | dbname=$current_dir"_wp" 11 | read -p "db name (default = $dbname) : " 12 | if [[ $REPLY ]] 13 | then 14 | dbname=$REPLY 15 | fi 16 | config=$config" --dbname="$dbname 17 | 18 | # --dbuser= 19 | read -p "User (default = root) : " 20 | user="root" 21 | if [[ $REPLY ]] 22 | then 23 | user=$REPLY 24 | config=$config" --dbuser="$user 25 | else 26 | config=$config" --dbuser=root" 27 | fi 28 | 29 | # --dbpass= 30 | read -p "pass (default = "") : " 31 | if [[ $REPLY ]] 32 | then 33 | pass=$REPLY 34 | config=$config" --dbpass="$pass 35 | fi 36 | 37 | # --dbhost= 38 | read -p "Host (default = localhost) : " 39 | host="localhost" 40 | if [[ $REPLY ]] 41 | then 42 | host=$REPLY 43 | config=$config" --dbhost="$host 44 | else 45 | config=$config" --dbhost=localhost" 46 | fi 47 | 48 | # validation 49 | validate_wp_conf(){ 50 | echo "You're about to setup your worpress site with the following configuration: " 51 | echo $config 52 | read -p" continue ? [y/n] " -n 1 -r 53 | if [[ $REPLY =~ ^[Yy]$ ]] 54 | then 55 | eval $config 56 | else 57 | read -p "You're about to abort configuration. Are you sure ? [y/n] " -n 1 -r 58 | if [[ $REPLY =~ ^[Yy]$ ]] 59 | then 60 | echo 61 | else 62 | validate_wp_conf 63 | fi 64 | fi 65 | } 66 | validate_wp_conf 67 | } 68 | 69 | -------------------------------------------------------------------------------- /wp_core_download: -------------------------------------------------------------------------------- 1 | st #!/bin/bash 2 | ########################################## 3 | # WP CORE DOWNLOAD 4 | ########################################## 5 | wp_core_download() { 6 | download="wp core download " 7 | read -p "Which locale (language) do you need ? (fr=fr_FR / en=en_EN) | default=en_EN : " -n 2 -r 8 | echo # (optional) move to a new line 9 | if [[ $REPLY = "fr" || "FR" ]] 10 | then 11 | download=$download' --locale=fr_FR' 12 | fi 13 | eval $download; 14 | } 15 | -------------------------------------------------------------------------------- /wp_core_install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP CORE INSTALL 4 | ########################################## 5 | 6 | wp_core_install() { 7 | # store base commands of wp in wp core install 8 | 9 | install="wp core install " 10 | current_dir="${PWD##*/}" 11 | 12 | wpci_url(){ 13 | default_url="http://localhost/"$current_dir 14 | read -p "Provide a url ( Default url = "$default_url" ) : " 15 | echo # (optional) move to a new line 16 | 17 | install=$install' --url=' 18 | 19 | if [[ $REPLY ]] 20 | then 21 | if [[ $REPLY =~ $regex_url ]] 22 | then 23 | install=$install$REPLY 24 | else 25 | echo 'Please provide a valid url.' 26 | read -p " Try again ? [y/n] " -n 1 -r 27 | echo # (optional) move to a new line 28 | if [[ $REPLY =~ ^[Yy]$ ]] 29 | then 30 | wpci_url 31 | fi 32 | fi 33 | else 34 | install=$install$default_url 35 | fi 36 | } 37 | 38 | wpci_name(){ 39 | read -p "Provide a title ( Default title = "$current_dir" ) : " 40 | echo # (optional) move to a new line 41 | 42 | install=$install' --title=' 43 | 44 | if [[ $REPLY ]] 45 | then 46 | if [[ $REPLY =~ $regex_wp_site_title ]] 47 | then 48 | REPLY=$(printf %q "$REPLY") 49 | install=$install$REPLY 50 | else 51 | echo 'Please provide a valid url.' 52 | read -p " Try again ? [y/n] " -n 1 -r 53 | echo # (optional) move to a new line 54 | if [[ $REPLY =~ ^[Yy]$ ]] 55 | then 56 | wpci_name 57 | fi 58 | fi 59 | else 60 | install=$install$current_dir 61 | fi 62 | } 63 | wpci_url 64 | wpci_name 65 | install=$install' --admin_user=charles-louis --admin_password=wam --admin_email=charleslouis@lasourisetlepiano.com' 66 | 67 | # run wp core install 68 | eval $install 69 | } -------------------------------------------------------------------------------- /wp_db: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP DB 4 | ########################################## 5 | 6 | # DB 7 | alias wpdbd=wp_db_drop 8 | alias wpdbc=wp_db_create 9 | 10 | wp_db_drop() { 11 | echo "You're about the current WordPress database" 12 | echo 13 | read -p" continue ? [yes] " -n 3 -r 14 | echo 15 | if [[ $REPLY =~ "yes" ]] 16 | then 17 | echo 18 | drop="wp db drop " 19 | eval $drop 20 | echo 21 | fi 22 | } 23 | 24 | wp_db_create() { 25 | echo "You're about the current WordPress database" 26 | echo 27 | read -p" continue ? [yes] " -n 3 -r 28 | echo 29 | if [[ $REPLY =~ "yes" ]] 30 | then 31 | echo 32 | create="wp db create " 33 | eval $create 34 | echo 35 | fi 36 | } -------------------------------------------------------------------------------- /wp_help: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # HELP 4 | ########################################## 5 | alias wph="wp $1 --help" 6 | alias wphc="wp core $1 --help" 7 | alias wphr="wp rewrite $1 --help" 8 | alias wphsr="wp search-replace $1 --help" 9 | alias wphcc="wp cache $1 --help" 10 | alias wphdb="wp db $1 --help" 11 | alias wphm="wp menu $1 --help" 12 | alias wpho="wp option $1 --help" 13 | alias wphpl="wp plugin $1 --help" 14 | alias wpht="wp theme $1 --help" 15 | alias wphu="wp user $1 --help" 16 | alias wphp="wp post $1 --help" 17 | alias wphmloc="wp menu location $1" 18 | alias wphmls="wp menu list $1" -------------------------------------------------------------------------------- /wp_menu: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # MENU 4 | ########################################## 5 | alias wpm="wp menu $1" 6 | alias wpmc="wp menu create $1" 7 | alias wpms="wpmll; wpml" 8 | 9 | # Menus 10 | alias wpml="wp menu list $1" 11 | alias wpmc="wp menu create $1" 12 | alias wpmd="wp menu delete $1" 13 | 14 | # Menu items 15 | alias wpmi="wp menu item $1" 16 | alias wpmil="wp menu item list $1" 17 | alias wpmia=add_item_to_menu 18 | alias wpmid=remove_item_from_menu 19 | 20 | # Menu location 21 | alias wpmll="wp menu location list $1" # --format=(fac.) 22 | alias wpmlr="wp menu location remove $1" 23 | alias wpmla="wp menu location assign $1" 24 | 25 | add_item_to_menu(){ 26 | echo 27 | echo "------------------------------------------------" 28 | echo "Your menus" 29 | echo "==========" 30 | wpml 31 | echo 32 | echo "Which menu do you want to add item(s) to ? " 33 | read -p '[menu id] : ' 34 | menu=$REPLY 35 | echo 36 | echo "============================" 37 | echo "You've selected menu $menu |" 38 | echo "============================" 39 | echo 40 | echo "Pages list" 41 | echo "==========================" 42 | wppal # list pages 43 | echo "Which item/page do you want to add to $menu ? " 44 | echo "You can add several items using comma separated values (ids)." 45 | read -p "ids : " 46 | pages=$REPLY 47 | pages_list=(${pages//,/ }) 48 | echo "------------------------------------------------" 49 | echo "You're up to add these items to menu $menu :" 50 | echo "------------------------------------------------" 51 | for page in "${pages_list[@]}"; do 52 | echo $page 53 | done | column 54 | echo "------------------------------------------------" 55 | echo 56 | read -p "Continue ? [yes] " -n 3 -r 57 | if [[ $REPLY=~'yes' ]]; then 58 | echo 59 | for page in "${pages_list[@]}"; do 60 | wp menu item add-post $menu $page 61 | done 62 | echo 63 | fi 64 | } 65 | 66 | remove_item_from_menu(){ 67 | echo 68 | echo "------------------------------------------------" 69 | echo "Your menus" 70 | echo "==========" 71 | wpml 72 | echo 73 | echo "Which menu do you want to add item(s) to ? " 74 | read -p '[menu id] : ' 75 | menu=$REPLY 76 | echo 77 | echo "============================" 78 | echo "You've selected menu $menu |" 79 | echo "============================" 80 | echo 81 | echo "List menu $menu items" 82 | echo "==========================" 83 | wpmil $menu 84 | echo "Which item/page do you want to remove from $menu ? " 85 | echo "You can remove several items using comma separated values (ids)." 86 | read -p "ids : " 87 | menu_items=$REPLY 88 | menu_items_list=(${menu_items//,/ }) 89 | echo "--------------------------------------------------------------------------" 90 | echo "You're up to remove these menu-items from menu $menu :" 91 | echo "--------------------------------------------------------------------------" 92 | for menu_item in "${menu_items_list[@]}"; do 93 | echo $menu_item 94 | done | column 95 | echo "------------------------------------------------" 96 | echo 97 | read -p "Continue ? [yes] " -n 3 -r 98 | if [[ $REPLY=~'yes' ]]; then 99 | echo 100 | for menu_item in "${menu_items_list[@]}"; do 101 | wp menu item delete $menu_item 102 | done 103 | echo 104 | fi 105 | } 106 | -------------------------------------------------------------------------------- /wp_options: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP OPTIONS 4 | ########################################## 5 | alias wpog="wp option get $1" 6 | alias wpou="wp option update $1 $2" 7 | alias wpod="wp option delete $1" 8 | alias wpoa=wp_option_add 9 | alias wpfront="wp option update page_on_front $1" 10 | alias wpfrontpage="wp option update show_on_front page" 11 | alias wpfrontpost="wp option update show_on_front post" 12 | 13 | regex='^[a-zA-Z0-9_ ]*$' 14 | 15 | wp_option_add(){ 16 | echo "You're about to add an option to your WordPress install. " 17 | echo 18 | read -p"Continue ? [yes] " 19 | echo 20 | if [[ $REPLY =~ "yes" ]] 21 | then 22 | read -p "Please provide a key (the name of the option to add) : " 23 | echo 24 | if [[ $REPLY =~ $regex ]] 25 | then 26 | key=$REPLY 27 | echo "key= "$key 28 | echo 29 | read -p "Please provide a value (The value of the option to add. If ommited, the value is read from STDIN). : " 30 | echo 31 | if [[ $REPLY =~ $regex ]] 32 | then 33 | value=$REPLY 34 | fi 35 | fi 36 | 37 | read -p "Please provide a format - default if ommitted (The serialization format for the value. Default is plaintext.) : " 38 | if [[ $REPLY =~ '' ]] 39 | then 40 | format=" --format=plaintext" 41 | else 42 | format=" --format=$REPLY" 43 | fi 44 | echo 45 | echo $format 46 | echo 47 | 48 | read -p "Should this option be automatically loaded ? [ yes / no ] - Default: [ yes ] " 49 | if [[ $REPLY =~ 'no' ]] 50 | then 51 | autoload='no' 52 | echo 53 | else 54 | autoload='yes' 55 | fi 56 | echo 57 | autoload=" --autoload=$autoload" 58 | echo $autoload 59 | echo 60 | 61 | addoption="wp option add "$key" "$value$format$autoload 62 | echo 63 | echo "------------------------------------------------------------------------" 64 | echo "You're about to run the following => "$addoption 65 | echo "------------------------------------------------------------------------" 66 | echo 67 | read -p "Proceed [yes] ? " 68 | if [[ $REPLY =~ 'yes' ]] 69 | then 70 | eval $addoption 71 | fi 72 | 73 | else 74 | echo "Aborted" 75 | fi 76 | } -------------------------------------------------------------------------------- /wp_plugin: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP PLUGIN 4 | ########################################## 5 | alias wppl="wp plugin $1" 6 | alias wpplg="wp plugin get $1" 7 | alias wppli="wp plugin install $1" 8 | alias wpplun="wp plugin uninstall $1" 9 | alias wppla="wp plugin activate $1" 10 | alias wpplda="wp plugin deactivate $1" 11 | alias wppll="wp plugin list" 12 | alias wppls="wp plugin status $1" 13 | alias wpplup="wp plugin update $1" 14 | alias wpplpath="wp plugin path $1" 15 | alias wpplsearch="wp plugin search $1" 16 | 17 | go_to_plugin(){ 18 | plugin_path=$(wp plugin path) 19 | cd $plugin_path 20 | } 21 | alias cdwpp=go_to_plugin 22 | 23 | alias wp_acf="wppli advanced-custom-fields; wppla advanced-custom-fields" 24 | alias wp_seo="wppli advanced-custom-fields, wppla advanced-custom-fields" -------------------------------------------------------------------------------- /wp_post: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP POST 4 | ########################################## 5 | 6 | # POST 7 | alias wppo="wp post $1" 8 | alias wppol="wp post list --post_type=post,wppolpage $1" 9 | alias wppal="wp post list --post_type=page $1" 10 | alias wppg="wp post generate --count=" 11 | alias wppg=wp_post_generate 12 | alias wppdl=wp_post_delete 13 | alias wppcff=wp_post_create_from_files 14 | alias wppfc=wp_post_file_create 15 | 16 | wp_post_generate(){ 17 | wp_post_generate="wp post generate" 18 | read -p "Number of post to generate ? " 19 | if [[ $REPLY =~ ^[0-9]$ ]] 20 | then 21 | wp_post_generate=$wp_post_generate" --count="$REPLY 22 | fi 23 | 24 | read -p "post_type ? " 25 | if [[ $REPLY ]] 26 | then 27 | wp_post_generate=$wp_post_generate" --post_type="$REPLY 28 | fi 29 | wppg=$wp_post_generate 30 | eval $wppg 31 | } 32 | 33 | wp_post_delete(){ 34 | wp_post_delete="wp post delete " 35 | read -p "Please provide comma separated post ids OR type [batch] : " 36 | if [[ $REPLY =~ "batch" ]] 37 | then 38 | read -p "--post_type=" 39 | post_type=$REPLY 40 | read -p "--format=" 41 | format=$REPLY 42 | wppdl=$wp_post_delete$(wp post list --post_type="$post_type" --format=$format) 43 | else 44 | wppdl=$wp_post_delete$REPLY 45 | fi 46 | read -p "force ?? [yes] " 47 | if [[ $REPLY =~ "yes" ]] 48 | then 49 | wppdl=$wppdl" --force " 50 | fi 51 | 52 | eval $wppdl 53 | } 54 | 55 | wp_post_create_from_files(){ 56 | home=$(wp option get home) 57 | home_dir=$(basename $home) 58 | wp_posts_to_create=$home_dir"/wp_posts_to_create" 59 | 60 | # cd to wamp/www 61 | cdwamp 62 | 63 | # cd to wp_install/wp_posts_to_create 64 | cd $wp_posts_to_create 65 | 66 | # POST_FILES from which we want to create posts are definde by "*.post_type.txt" 67 | POST_FILES="*.txt" 68 | 69 | # lets first display all the files 70 | for file in $POST_FILES 71 | do 72 | printf "%-8s\n" $file 73 | done | column 74 | 75 | 76 | for file in $POST_FILES 77 | do 78 | 79 | # Post title derives from file title 80 | #################################### 81 | filename=$(basename "$file") 82 | extension="${filename##*.}" 83 | 84 | # remove ".txt" 85 | title="${filename%.*}" 86 | 87 | post_type="${title##*.}" 88 | 89 | # remove ".post_type" to get only file name and use it as a title 90 | title_="${title%.*}" 91 | title=${title_//_/ } 92 | title='"'$title'"' 93 | 94 | # Post content derives from file content 95 | ######################################## 96 | read -p "Publish "$title_" ? [y/n] " -n 1 -r 97 | if [[ $REPLY =~ ^[yY]$ ]] 98 | then 99 | publish=' --post_status=publish' 100 | fi 101 | post_create="wp post create "$filename" --post_title="$title" --post_type="$post_type$publish 102 | echo 103 | echo "--------------------------------------------------------------------------------" 104 | echo $post_create 105 | eval $post_create 106 | echo "--------------------------------------------------------------------------------" 107 | done 108 | } 109 | 110 | 111 | wp_post_file_create(){ 112 | 113 | home=$(wp option get home) 114 | home_dir=$(basename $home) 115 | wp_posts_to_create=$home_dir"/wp_posts_to_create" 116 | 117 | # cd to wamp/www 118 | cdwamp 119 | 120 | # cd to wp_install/wp_posts_to_create 121 | cd $wp_posts_to_create 122 | 123 | read -p "File name (corespond to post title) : " 124 | filename=$REPLY 125 | 126 | echo "Post type (default to post) : " 127 | read -p "[0] post [1] page [2] other : " -n 1 -r 128 | 129 | if [[ $REPLY =~ ^[1-9]$ ]]; then 130 | if [[ $REPLY = '1' ]]; then 131 | extension='.page.txt' 132 | else 133 | read -p "Please provide a post type : " 134 | extension=$REPLY'.txt' 135 | fi 136 | else 137 | extension='.post.txt' 138 | fi 139 | echo 140 | echo "----------------------------------------" 141 | 142 | filename=$filename$extension 143 | filename=${filename// /_} 144 | 145 | touch $filename 146 | 147 | echo $filename' created' 148 | 149 | cygstart $filename 150 | 151 | echo "----------------------------------------" 152 | echo 153 | } -------------------------------------------------------------------------------- /wp_rewrite: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################## 3 | # WP REWRITE 4 | ########################################## 5 | 6 | # alias wprwpost="wp rewrite structure %postname% --hard" 7 | 8 | rewrite_rules(){ 9 | permastructs=("%postname%" "%post_id%" "%year%/%monthnum%/%postname%") 10 | # permastructs[0]="%postname%" 11 | # permastructs[1]="%post_id%" 12 | # permastructs[2]="%year%/%monthnum%/%postname%" 13 | echo 14 | echo "What permalink structure do you want ?" 15 | echo "--------------------------------------" 16 | echo 17 | 18 | choose_permastructure(){ 19 | array_size=0 20 | for permastruct in "${permastructs[@]}" 21 | do 22 | element='[ '$array_size' ] '"${permastruct}" 23 | printf "%-8s\n" "$element" 24 | array_size=$(expr $array_size + 1) 25 | done | column 26 | echo 27 | read -p "" 28 | 29 | if [[ $REPLY =~ ^[0-9]*$ ]] 30 | permastructs_index=$REPLY 31 | then 32 | echo 33 | echo "You're about to set permastruct to ${permastructs[$permastructs_index]}" 34 | read -p "Proceed [y] ? Resume [n] ? " 35 | if [[ $REPLY =~ ^[yY]$ ]] 36 | then 37 | new_permastruct=${permastructs[$permastructs_index]} 38 | else 39 | eval choose_permastructure 40 | fi 41 | echo 42 | echo 'new_permastruct = '$new_permastruct 43 | echo 44 | fi 45 | } 46 | 47 | choose_permastructure 48 | 49 | echo 50 | read -p "Category base ? " 51 | if [[ $REPLY ]] 52 | then 53 | category_base="--category-base=" 54 | category_base=$category_base$REPLY' ' 55 | echo $category_base 56 | fi 57 | 58 | echo 59 | read -p "Tag base ? " 60 | if [[ $REPLY ]] 61 | then 62 | tag_base="--tag-base=" 63 | tag_base=$tag_base$REPLY' ' 64 | echo $tag_base 65 | fi 66 | 67 | 68 | echo 69 | read -p "Hard flush ? [y] " 70 | if [[ $REPLY =~ ^[yY]$ ]] 71 | then 72 | flush=" --hard" 73 | fi 74 | echo 75 | 76 | new_rewrite="wp rewrite structure "$new_permastruct" "$category_base$tag_base$flush 77 | 78 | echo "You're about to set rewrte rules to" 79 | echo $new_rewrite 80 | read -p "Proceed [y] ? Resume [n] ? " 81 | if [[ $REPLY =~ ^[yY]$ ]] 82 | then 83 | eval $new_rewrite 84 | else 85 | eval rewrite_rules 86 | fi 87 | } 88 | 89 | alias wprwr=rewrite_rules 90 | -------------------------------------------------------------------------------- /wp_theme: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ########################################## 4 | # WP THEME HELPERS 5 | ########################################## 6 | alias wpt="wp theme $1" 7 | alias wpta="wp theme activate $1" 8 | alias wpte="wp theme enable $1" 9 | alias wptd="wp theme disable $1" 10 | alias wptdel="wp theme delete $1" 11 | alias wptl="wp theme list" 12 | alias wptup="wp theme update $1" 13 | alias wpts="wp theme status $1" 14 | alias wptpath="wp theme path $1" 15 | alias wptsearch="wp theme search $1" 16 | 17 | alias wpreverie="git clone wpgit@github.com:kartonnade/reverie.git" 18 | alias wpfoundationpress="git clone https://github.com/olefredrik/FoundationPress.git;" 19 | 20 | alias wptd='go_to_theme_dir; wpts' 21 | 22 | alias wpatd=go_to_active_theme_dir 23 | 24 | go_to_theme_dir(){ 25 | theme_path=$(wp theme path) 26 | active_theme=$(wp theme list --status=active --field=name) 27 | cd $theme_path 28 | echo 29 | echo "----------------------------------------------------" 30 | echo "Active theme directory : " $active_theme 31 | echo "----------------------------------------------------" 32 | echo 33 | } 34 | 35 | go_to_active_theme_dir(){ 36 | go_to_theme_dir 37 | cd $active_theme 38 | ls 39 | echo 40 | echo "----------------------------------------------------" 41 | echo "----------------------------------------------------" 42 | echo 43 | } 44 | --------------------------------------------------------------------------------