From fa04b3bde7aed78933f1662c3d4ff063f6e878c3 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Fri, 17 Apr 2015 20:50:44 -0600 Subject: [PATCH 01/24] 87% finished with first draft Rewrote a ton of crap, like seriously --- wpfools/wpfools.sh | 699 +++++++++++++++++++++------------------------ 1 file changed, 323 insertions(+), 376 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 857cdee..8682dd0 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -6,6 +6,8 @@ # # This is a rewrite for wptool. Original source: https://code.google.com/p/wptool/ # Original code by https://code.google.com/p/wptool/people/list +# The idea is to replace as much as possible of the backend for this tool with wpcli +# (https://github.com/wp-cli/wp-cli) # # # As with the original, wptool is suite of bash functions to administer Wordpress installs. @@ -23,12 +25,27 @@ # Differences in functionality # ---------------------------- # -# >'wp-content_stock' won't be kept if there's already a wp-content present, under 'wpcore' -# >old Wordpress files are no longer in 'core_$timestamp', they'll now be in 'oldwp_$timestamp' +# > 'wp-content_stock' won't be kept if there's already a wp-content present, under 'wpcore' +# > old Wordpress files are no longer in 'core_$timestamp', they'll now be in 'oldwp_$timestamp' +# > 'wpstats' does not run tests on index.php or wp-admin/index.php +# > # # # # +### + +### +# +# Things to fix +# ---------------------------- +# +# > replace wpcore() with wpcli core, maybe (more testing required) +# > wpht() in general just needs some serious QA testing, r&d +# > wpfix() needs QA +# +# +# # # ### @@ -293,279 +310,178 @@ Usage: } +######untested code below####### +wptheme() +{ + if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + echo " + activate Activate a theme. + delete Delete a theme. + disable Disable a theme in a multisite install. + enable Enable a theme in a multisite install. + fresh Install twentyfifteen and set as active theme. + get Get a theme. + install Install a theme. + is-installed Check if the theme is installed. + list Get a list of themes. + mod Manage theme mods. + path Get the path to a theme or to the theme directory. + search Search the wordpress.org theme repository. + status See the status of one or all themes. + update Update one or more themes. + use Install and activate a theme. + + -s Set only stylesheet: wptheme -s twentyfifteen + -t Set only template: wptheme -t twentyfifteen + " + elif [[ -z "$1" ]]; then + echo -e "\nCurrent themes:\n" + #wpcli theme list --status="active" #broken + echo -e "\tstylesheet:\t$(wpcli option get stylesheet)" + echo -e "\ttemplate:\t$(wpcli option get template)" + echo -e "\nAvailable themes:\n" + wpcli theme list + elif [[ "$1" == "fresh" ]]; then + wpcli theme install twentyfifteen + wpcli theme activate twentyfifteen + elif [[ "$1" == "use" ]]; then + wpcli theme install "$2" + wpcli theme activate "$2" + elif [[ "$1" == "-s" ]]; then + wpcli option update stylesheet "$2" + elif [[ "$1" == "-t" ]]; then + wpcli option update template "$2" + else + wpcli theme "$@" + fi +} - - - - - - - -# -# -# -# -#Code beyond this point has not been reviewed, enter at your own risk... -# -#Commits welcome :) -# -# -# -# - - - - - - - - - - - - -wpfix() { - echo - if [[ $1 == "--help" || $1 == "-h" ]]; then +wpfix() +{ + if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then echo -e "This tool runs various built-in Wordpress functions and fixes.\n\nUsage:\n\n\twpfix\n" return - elif [[ ! -f wp-config.php || ! -f wp-admin/upgrade-functions.php ]]; then - echo -e "Could not find one or more of the necessary files (wp-config.php or wp-admin/upgrade-functions.php)!\n" - return 9 - fi - php -q <<"EOF" && echo "Ran fix..." || echo Error running fix! -flush_rules(); - echo "Rewrite rules flushed...\n"; - wp_cache_flush(); - echo "Object cache flushed...\n"; -?> -EOF - echo -} + fi -wpht() { - echo - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "This tool generates a new .htaccess file.\n\nUsage:\n\n\twpht\n" - return - elif [[ ! -f wp-config.php || ! -f wp-admin/includes/misc.php ]]; then - echo -e "Could not find one or more of the necessary files:\n" - echo -e "\twp-config.php\n\twp-admin/includes/misc.php\n" - return 9 + wpcli cache flush + wpcli db repair + wpcli db optimize + wpcli core update-db + + #not working? + struct="$( wpcli option get permalink_structure )" + if [[ -n "$struct" ]]; then + wpcli rewrite structure "$struct" --hard + else + #something + sleep 0 fi - temp=$(now) - [[ -f .htaccess ]] && cp .htaccess .htaccess_$temp - php -q <<"EOF" && echo "Generated .htaccess rules..." || echo Error writing to .htaccess! -mod_rewrite_rules() ); - insert_with_markers( '.htaccess', 'WordPress', $rules ); -?> -EOF - echo } -wpconn() { - [[ -z $1 || $1 != wp* ]] && return - if [[ ! -f wp-config.php ]]; then - echo -e "\nCould not find wp-config.php!\n" - return 9 - fi - myconn="" - read -r dbhost dbname dbpass dbuser dbprefix <<< $(cat wp-config.php | egrep "^[^/].*[\"']DB_(NAME|USER|PASSWORD|HOST[^_])|table_prefix" | sort -d | sed "s/.*[\"']\(.*\)[\"'].*;.*/\1/" ) - #[[ -z $dbprefix ]] && dbprefix=$junk #sometimes there isn't a junk entry - q="USE $dbname; " - if [[ $1 == "wpdbimport" ]]; then - echo "Starting import..." - mysql -h "$dbhost" -u "$dbuser" -p"$dbpass" "$dbname" < "$2" && echo -e "Imported file '$2' to database '$dbname'.\n" || echo -e "Failed to import file '$2' to database '$dbname'!\n" - return - elif [[ $1 == "wpdbimportgz" ]]; then - echo "Starting import..." - gunzip < "$2" | mysql -h "$dbhost" -u "$dbuser" -p"$dbpass" "$dbname" && echo -e "Imported gzipped file '$2' to database '$dbname'.\n" || echo -e "Failed to import file '$2' to database '$dbname'!\n" - return - elif [[ $1 == "wpdbexport" ]]; then - echo "Starting export..." - file="$2" - [[ -z "$file" ]] && file="$dbname"_$(now).sql - mysqldump -h "$dbhost" -u "$dbuser" -p"$dbpass" "$dbname" > "$file" && echo -e "Exported database '$dbname' to file '$file'.\n" || echo -e "Failed to export database '$dbname' to file '$file'!\n" - return - elif [[ $1 == "wpdbexportgz" ]]; then - echo "Starting export..." - file="$2" - [[ -z "$file" ]] && file="$dbname"_$(now).sql.gz - mysqldump -h "$dbhost" -u "$dbuser" -p"$dbpass" "$dbname" | gzip > "$file" && echo -e "Exported gzipped database '$dbname' to file '$file'.\n" || echo -e "Failed to export database '$dbname' to file '$file'!\n" - return - elif [[ $1 == "wpdbdrop" ]]; then q='DROP database '$dbname'; CREATE DATABASE '$dbname';'; - elif [[ $1 == "wpdb" ]]; then q=$q'SHOW tables like "'$dbprefix'%";'; - elif [[ $1 == "wpdbver" ]]; then q=$q'SELECT option_value FROM '$dbprefix'options WHERE option_name = "db_version";' - elif [[ $1 == "wpurl" ]]; then q=$q'SELECT option_id, option_name, option_value FROM '$dbprefix'options WHERE option_name = "siteurl" OR option_name = "home";' - elif [[ $1 == "wpurlmod" ]]; then - [[ -z $2 ]] && echo No URL specified! && return 9 - q=$q'UPDATE '$dbprefix'options SET option_value="'$2'" WHERE option_name="siteurl" OR option_name="home";' - elif [[ $1 == "wpplug" ]]; then q=$q'SELECT option_value FROM '$dbprefix'options WHERE option_name = "active_plugins";' - elif [[ $1 == "wptheme" ]]; then q=$q'SELECT option_id, option_name, option_value FROM '$dbprefix'options WHERE option_name = "stylesheet" OR option_name = "template";' - elif [[ $1 == "wpthememod"* ]]; then - [[ -z $2 ]] && echo No theme specified! && return 9 - if [[ $1 == "wpthememod" ]]; then q=$q'UPDATE '$dbprefix'options SET option_value="'$2'" WHERE option_name="stylesheet" OR option_name="template" OR option_name="current_theme";' - elif [[ $1 == "wpthememods" ]]; then q=$q'UPDATE '$dbprefix'options SET option_value="'$2'" WHERE option_name="stylesheet";' - elif [[ $1 == "wpthememodt" ]]; then q=$q'UPDATE '$dbprefix'options SET option_value="'$2'" WHERE option_name="template" OR option_name="current_theme";' - else echo -e "\tInvalid query"! && return 1 - fi - elif [[ $1 == "wpuser" ]]; then q=$q'SELECT * FROM '$dbprefix'users LIMIT 23;' - elif [[ $1 == "wpuser1" ]]; then q=$q'SELECT user_login FROM '$dbprefix'users WHERE ID=1;' - elif [[ $1 == "wpuserinfo" ]]; then q=$q'SELECT ID, user_login, user_email, user_status, umeta_id, meta_key, meta_value FROM '$dbprefix'users JOIN '$dbprefix'usermeta ON ('$dbprefix'users.ID = '$dbprefix'usermeta.user_id) WHERE ID='$2';' - elif [[ $1 == "wpusera" ]]; then q=$q'DELETE FROM '$dbprefix'usermeta WHERE user_id='$2' AND (meta_key="'$dbprefix'capabilities" OR meta_key="'$dbprefix'user_level"); INSERT INTO '$dbprefix'usermeta (user_id,meta_key,meta_value) VALUES ('$2', "'$dbprefix'capabilities", '"'a:1:{s:13:\"administrator\";b:1;}'"'); INSERT INTO '$dbprefix'usermeta (user_id,meta_key,meta_value) VALUES ('$2', "'$dbprefix'user_level", 10); SELECT user_login FROM '$dbprefix'users WHERE ID='$2';' - elif [[ $1 == "wpuserp" ]]; then q=$q'UPDATE '$dbprefix'users SET user_pass=MD5("'$3'") WHERE ID='$2'; SELECT user_login FROM '$dbprefix'users WHERE ID='$2';' - elif [[ $1 == "wpuseru" ]]; then q=$q'SELECT user_login FROM '$dbprefix'users WHERE ID='$2'; UPDATE '$dbprefix'users SET user_login="'$3'" WHERE ID='$2';' - elif [[ $1 == "wpuserd" ]]; then q=$q'SELECT user_login FROM '$dbprefix'users WHERE ID='$2'; DELETE FROM '$dbprefix'users WHERE ID='$2'; DELETE FROM '$dbprefix'usermeta WHERE user_id='$2';' - elif [[ $1 == "wpusernew" ]]; then q=$q'INSERT INTO '$dbprefix'users (user_login, user_pass, user_email) VALUES ("deleteme", MD5("deleteme"), "deleteme@example.com"); SET @new_id=LAST_INSERT_ID(); INSERT INTO '$dbprefix'usermeta (user_id,meta_key,meta_value) VALUES (@new_id, "'$dbprefix'capabilities", '"'a:1:{s:13:\"administrator\";b:1;}'"'); INSERT INTO '$dbprefix'usermeta (user_id,meta_key,meta_value) VALUES (@new_id, "'$dbprefix'user_level", 10); SELECT @new_id;' - else echo -e "\tInvalid query"! && return 1 - fi - myconn=$(mysql -u "$dbuser" -p"$dbpass" -h "$dbhost" -e "$q" 2>&1) - if [[ 1 -eq 0 ]]; then #Debug - echo -e "\nConnected to the database..." - echo -e "Query:\n\n\t$q" - echo -e "$myconn". - elif [[ $myconn == "ERROR"* ]]; then return 9 - fi +#unfinished maybe +wpstats() +{ + echo -e " + WP version: $( wpcli core version ) + UserID 1: $( wpcli "user get 1 --field='display_name'" ) + home: $( wpcli option get home ) + siteurl: $( wpcli option get siteurl ) + stylesheet: $( wpcli option get stylesheet ) + template: $( wpcli option get template ) + " } -wpdb() { - #Need to include a optimize/fix option - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "\nThis tool tests the database connectivity based on settings in the wp-config.php file, and can import/export a database based on its settings.\n" - echo -e "Usage:\n" - echo -e "\twpdb [option [param]]\n" - echo -e "\t-i FILE\n\t\texport current database to file FILE. The specified FILE must end in .sql" - echo -e "\t-e [FILE]\n\t\texport current database to optional file FILE. If a FILE is specified, it must end in .sql\n" - return - elif [[ ! -f wp-config.php ]]; then echo Could not find wp-config.php! && return 9 - fi - wpconn "wpdb" - [[ $1 != "-q" ]] && echo -e "\n\tDB user:\t$dbuser\n\tDB pass:\t$dbpass\n\tDB host:\t$dbhost\n\tDB name:\t$dbname\n\tDB prefix:\t$dbprefix\n" - if [[ -z $myconn ]]; then - [[ $1 == "-q" ]] && echo -e "\tDatabase:\tPrefix?" || echo -e "Connected with no errors, but no tables that match specified prefix"!"\n" - elif [[ $myconn == "ERROR"* ]]; then - [[ $1 == "-q" ]] && echo -e "\tDatabase:\tError"! || echo -e "$myconn\n" - return 9 +wpurl() +{ + if [[ -z "$1" ]]; then + echo -e " + home: $( wpcli option get home ) + siteurl: $( wpcli option get siteurl ) + " + elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + echo -e "This tool returns the current URL settings in the database, or updates them to a specified URL. + +Usage: + + wpurl [URL] + + URL + specify a URL to change the site to. If the URL does not start with 'http://' or 'https://' it will automatically append 'http://'. + " else - [[ $1 == "-q" ]] && echo -e "\tDatabase:\tOK" || echo -e "Database connection settings appear to be fine.\n" - fi - if [[ $1 == "-i" ]]; then - if [[ -z "$2" ]]; then echo -e "No import file specified!\n" - elif [[ ! -f "$2" ]]; then echo -e "File '$2' does not exist!\n" - elif [[ "$2" == *sql ]]; then wpconn "wpdbimport" "$2" - elif [[ "$2" == *sql.gz ]]; then wpconn "wpdbimportgz" "$2" - else echo -e "'$2' is not a valid file!\n" - fi - elif [[ $1 == "-e" ]]; then - if [[ -n "$2" ]]; then - if [[ -f "$2" ]]; then echo -e "File '$2' already exists!\n" - elif [[ "$2" == *sql ]]; then wpconn "wpdbexport" "$2" - elif [[ "$2" == *sql.gz ]]; then wpconn "wpdbexportgz" "$2" - else echo -e "'$2' is not a valid filename!\n" && return - fi + if [[ "$1" =~ (^http[s]?://.*) ]]; then + url="$1" else - wpconn "wpdbexport" - fi - elif [[ $1 == "drop" ]]; then - read -p "$(echo $'\t')Delete database? " -n 1 -r - if [[ $REPLY =~ ^[Yy]$ ]]; then - echo -e "\nDropping database..." - wpconn "wpdbdrop" - [[ $myconn != "ERROR"* ]] && echo -e "Dropped database!\n" || echo -e "Failed to drop database!\n" - else echo -e "\tDeletion of database '$1' cancelled"!"\n" + url="http://$1" fi + wpcli option update siteurl "$url" + wpcli option update home "$url" fi } -wpurl() { - [[ $1 == "-q" ]] && wpconn "wpurl" && echo "$myconn" | tail -n +2 && return - echo - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "This tool returns the current URL settings in the database, or updates them to a specified URL.\n" - echo -e "Usage:\n" - echo -e "\twpurl [URL]\n" - echo -e "\tURL\n\t\tspecify a URL to change the site to. If the URL does not start with 'http://' or 'https://' it will automatically append 'http://'.\n" - return - elif [[ ! -f wp-config.php ]]; then echo Could not find wp-config.php! && return 9 +#FIX +#hopefully this will be replaced by a feature I have requested, quick and dirty until then +wpht() +{ + if [[ -f ./.htaccess ]]; then + cp ./.htaccess ./.htaccess_"$(now)" fi - if [[ -n $1 ]]; then - newurl=$1 - [[ ! $newurl =~ https?://* ]] && newurl="http://"$newurl && echo "No 'http://' or 'https://' in provided URL"! && echo "Using '$newurl' instead..." - wpconn "wpurlmod" $newurl && echo "Updated URLs to $newurl..." + + #double check this + struct="$( wpcli option get permalink_structure )" + if [[ -n "$struct" ]]; then + wpcli rewrite structure "$struct" --hard else - wpconn "wpurl" - [[ -z $myconn ]] && echo -e "\thome:\tnot found\n\tsiteurl:\tnot found\n" && return - echo -e "$myconn" | tail -n +2 | awk '{print "\t"$2"("$1"):\t"$3}' + #remove everything between BEGIN and END + #sed -i '/# BEGIN WordPress/,/# END WordPress/ d' ./.htaccess + sleep 0 fi - echo } -wptheme() { - [[ $1 != "-q" ]] && echo - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "This tool returns the current theme, as well as listing any available ones found in the wp-content/themes folder. It also can change to a specified stylesheet, template, both, or to a new copy of twentytwelve.\n" - echo -e "Usage:\n" - echo -e "\twptheme [THEME [option]]\n" - echo -e "\tTHEME\n\t\tspecify a THEME for both the stylesheet and template. If 'fresh' is specified as the theme, it will download and install the 'twentytwelve' theme." - echo -e "\tTHEME -s\n\t\tchange only the WP stylesheet" - echo -e "\tTHEME -t\n\t\tchange only the WP template\n" - return - elif [[ ! -f wp-config.php ]]; then echo Could not find wp-config.php! && return 9 - fi - folder=wp-content/themes - if [[ $1 == "-q" || -z $1 ]]; then - wpconn "wptheme" - if [[ $myconn == "" ]]; then echo -e "\tstylesheet:\tnot found\n\ttemplate:\tnot found" - elif [[ $myconn != "ERROR"* ]]; then - echo -e "$myconn" | tail -2 | awk '{print "\t"$2"("$1"):\t"$3}' +wpdb() +{ + #FIX + #would like a better way of doing this line + read -r dbhost dbname dbpass dbuser dbprefix <<< "$( cat wp-config.php | egrep "^[^/].*[\"']DB_(NAME|USER|PASSWORD|HOST[^_])|table_prefix" | sort -d | sed "s/.*[\"']\(.*\)[\"'].*;.*/\1/" )" + + #Need to include a optimize/fix option + if [[ -z "$1" ]]; then + echo -e " + DB user:\t$dbuser + DB pass:\t$dbpass + DB host:\t$dbhost + DB name:\t$dbname + DB prefix:\t$dbprefix + " + wpcli core is-installed + echo "SHOW STATUS WHERE variable_name = 'Threads_running';" | wpcli db query | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" + if [ $( wpcli db tables | grep -c ) -lt 1 ]; then + echo 'Connected with no errors, but no tables that match specified prefix!' fi - fi - [[ ! -d $folder && $1 != "-q" ]] && mkdir -p $folder && echo -e "\nCreated $folder..." - if [[ $1 == "-q" ]]; then return - elif [[ -z $1 ]]; then - echo -e "\nAvailable themes:\n" - ls -F $folder |grep "/"|grep -v "^\."|sed "s|^\(.*\)/|\t\1|" #ls -A is overwritten by default $LS_OPTIONS in alias - elif [[ $1 == "fresh" ]]; then - wget -qP $folder https://wordpress.org/extend/themes/download/twentytwelve.1.1.zip && echo "Downloaded twentytwelve.1.1.zip..." || { - echo Unable to download twentytwelve.1.1.zip! - return 9 - } - temp=$(now) - [[ -d $folder/twentytwelve ]] && mv $folder/twentytwelve $folder/twentytwelve_$temp && echo "Moved old twentytwelve files to twentytwelve_$temp..." - unzip $folder/twentytwelve.1.1.zip -d $folder >/dev/null && echo "Extracted new twentytwelve files..." || { - echo "Failed to extract twentytwelve files"! - return 1 - } - wpconn "wpthememod" "twentytwelve" && echo "Changed to theme 'twentytwelve'..." - rm -f $folder/twentytwelve.1.1.zip && echo "Deleted twentytwelve.1.1.zip..." + + elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + echo " + cli Open a mysql console using the WordPress credentials. + create Create the database, as specified in wp-config.php + drop Delete the database. + export Exports the database to a file or to STDOUT. + import Import database from a file or from STDIN. + optimize Optimize the database. + query Execute a query against the database. + repair Repair the database. + reset Remove all tables from the database. + tables List the database tables. + " + return else - [[ ! -d wp-content/themes/$1 ]] && echo -e "No such theme"!"\n" && return 1 - if [[ $2 == "-s" ]]; then wpconn "wpthememods" $1 && echo "Changed to stylesheet '$1'..." - elif [[ $2 == "-t" ]]; then wpconn "wpthememodt" $1 && echo "Changed to template '$1'..." - elif [[ -n $2 ]]; then echo "Invalid option"! - else wpconn "wpthememod" $1 && echo "Changed to theme '$1'..."; fi + wpcli db "$@" fi - echo } -wpver() { +wpver() +{ if [[ $1 == "--help" || $1 == "-h" ]]; then echo -e " This tool returns the current install's file and database versions. @@ -574,72 +490,164 @@ This tool returns the current install's file and database versions. \twpver [option] -\t -q\n\t\tdisplay abbreviated version output \t -h\n\t\tdisplay this help output " return fi - local filever="Unknown" - local dbver="Unknown" - local dbver_files="Unknown" - [[ -f wp-includes/version.php ]] && filever=$(cat wp-includes/version.php | grep "wp_version " | sed "s/.*'\(.*\)'.*/\1/") - wpconn "wpdbver" - if [[ $? == 0 && $myconn != "ERROR"* ]]; then - dbver=$(echo -e "$myconn" | tail -1) - dbver_files=$(curl -Ss https://codex.wordpress.org/FAQ_Installation | grep "= $dbver" | head -1 | awk '{print $1}') - fi - if [[ "$1" == "-q" ]]; then echo -e "$filever $dbver $dbver_files" - else echo -e "\n\tWP version:\t$filever\n\tDB version:\t$dbver (up to $dbver_files)\n" - fi + + echo " + WP version: $( wpcli core version ) + " } -wpuser() { - [[ $1 != "-q" ]] && echo - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "This tool performs various user functions, including returning info for a specified user, changing usernames, passwords, changing a user to an admin, creating new admin users, and deleting users.\n" - echo -e "Usage:\n" - echo -e "\twpuser [param [option [param]]]\n" - echo -e "\tUSERID\n\t\tReturns details about specified user USERID" - echo -e "\tUSERID -u NAME\n\t\tchange username of user USERID to NAME" - echo -e "\tUSERID -p PASS\n\t\tchange password of user USERID to PASS" - echo -e "\tUSERID -a\n\t\tpromote user USERID to admin" - echo -e "\tUSERID -d\n\t\tdelete user USERID" - echo -e "\t-n, new\n\t\tcreate new admin user\n" +wpuser() +{ + + if [[ -z "$1" ]]; then + echo + wpcli user list + echo return - elif [[ ! -f wp-config.php ]]; then echo Could not find wp-config.php! && return 9 - fi - if [[ -z $1 ]]; then wpconn "wpuser" #list users - elif [[ $1 == "-q" ]]; then wpconn "wpuser1" #list first user - elif [[ $1 =~ ^[0-9]+$ ]]; then #if a number... - if [[ $2 == "-p" ]]; then #change password... - if [[ -n $3 ]]; then wpconn "wpuserp" $1 "$3" #...if one is specified... - else echo -e "\tNo password specified"!"\n" && return 1; fi #...otherwise, end. - elif [[ $2 == "-u" ]]; then #change username... - if [[ -n $3 ]]; then wpconn "wpuseru" $1 "$3" #...if one is specified... - else echo -e "\tNo username specified"!"\n" && return 1; fi #...otherwise, end. - elif [[ $2 == "-a" ]]; then wpconn "wpusera" $1 #change to admin - elif [[ $2 == "-d" ]]; then read -p "$(echo $'\t')Delete user '$1'? " -n 1 -r && echo && [[ ! $REPLY =~ ^[Yy]$ ]] && echo -e "\tDeletion of user '$1' cancelled"!"\n" && return 1 || wpconn "wpuserd" $1 #delete user - elif [[ -z $2 ]]; then wpconn "wpuserinfo" $1 #show user info - else echo -e "\tInvalid option"!"\n" && return 1; fi #Otherwise, end. - elif [[ $1 == "new" || $1 == "-n" ]]; then wpconn "wpusernew" #create new admin... - else echo -e "\tInvalid option"!"\n" && return 1; fi #Otherwise, end. - if [[ $myconn == "" ]]; then echo -e "\tUser not found"! - elif [[ $myconn != "ERROR"* ]]; then - if [[ -z $1 ]]; then echo -e "$myconn" | tail -n +2 | awk '{print "\t"$1":\t"$2}' - elif [[ $1 == "-q" ]]; then echo $(echo -e "$myconn" | tail -1) - elif [[ $2 == "-p" ]]; then echo -e "Updated password for user $1 ('$(echo -e "$myconn" | tail -1)') to '$3'..." - elif [[ $2 == "-u" ]]; then echo -e "Updated username for user $1 from '$(echo -e "$myconn" | tail -1)' to '$3'..." - elif [[ $2 == "-a" ]]; then echo -e "Promoted user $1 to admin..." - elif [[ $2 == "-d" ]]; then echo -e "\nDeleted user $1 ('$(echo -e "$myconn" | tail -1)')..." - elif [[ $1 == "new" || $1 == "-n" ]]; then echo -e "Created new admin (user '$(echo -e "$myconn" | tail -1)') with username 'deleteme' and password 'deleteme'...\n\nMake sure to delete or rename this user"! - elif [[ -z $2 ]]; then echo -e "$myconn" | tail -n +2 + elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + echo -e " +This tool performs various user functions, including returning info for a specified user, changing usernames, passwords, changing a user to an admin, creating new admin users, and deleting users.\n +USERID can be the user login, user email, or actual user ID of the user(s) to update. + +Usage: + wpuser [param [option [param]]] + + USERID + Returns details about specified user USERID + USERID -u NAME + change username of user USERID to NAME + USERID -p PASS + change password of user USERID to PASS + USERID -a + promote user USERID to admin + USERID -d [USERID2] + delete user USERID + USERID2 is the (optional) user to reassign posts to. + -n, new + create new admin user + +Additional features: +==================== +add-cap Add a capability for a user. +add-role Add a role for a user. +create Create a user. +delete Delete one or more users from the current site. +generate Generate users. +get Get a single user. +import-csv Import users from a CSV file. +list List users. +list-caps List all user's capabilities. +meta Manage user custom fields. +remove-cap Remove a user's capability. +remove-role Remove a user's role. +set-role Set the user role (for a particular blog). +update Update a user. + " + return + elif [[ "$2" == "-u" ]]; then + #yes, I know this gives a warning and does not work. I'm assuming there's a reason for that warning, + #and not implementing a workaround because I'm also assuming that the reason is a good one. Rather + #than not implementing this feature at all, I'm including the command that should work instead to + #show users that it's not a good idea to update the username. + wpcli "user update "$1" --user_login="$3"" + return + elif [[ "$2" == "-p" ]]; then + wpcli "user update "$1" --user_pass="$3"" + return + elif [[ "$2" == "-a" ]]; then + wpcli "user add-role "$1" administrator" + return + elif [[ "$2" == "-d" ]]; then + if [[ -n "$3" ]]; then + wpcli "user delete "$1" --reassign="$3"" + else + wpcli user delete "$1" + fi + + return + elif [[ "$1" == "-n" || "$1" == "new" ]]; then + echo + + default="deleteme" + unset username + read -rp "Username [$default]: " username + if [[ -z "$username" ]]; then + username="$default" + fi + + default="deleteme@example.com" + unset email + read -rp "Email [$default]: " email + if [[ -z "$email" ]]; then + email="$default" + fi + + unset default + unset password + read -rp "Password [randomly generated]: " password + + if [[ -z "$password" ]]; then + wpcli "user create "$username" "$email" --role=administrator" + else + wpcli "user create "$username" "$email" --role=administrator --user_pass="$password"" fi - else echo "$myconn" + + echo + return + elif [[ -z "$2" ]]; then + wpcli user get "$1" + return + else + #pipe output to sed to fix usage text, but this breaks read prompts like in wpcli user delete :( + wpcli user "$@" # | sed "s|wp user|wpuser|g" + return fi - [[ $1 != "-q" ]] && echo } -wpplug() { + + + + + + + + + + + + +# +# +# +# +#Code beyond this point has not been reviewed, enter at your own risk... +# +#Commits welcome :) +# +# +# +# + + + + + + + + + + + + + + + +wpplug() +{ echo folder=wp-content/plugins if [[ $1 == "--help" || $1 == "-h" ]]; then @@ -666,66 +674,10 @@ wpplug() { echo } -wptests() { - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "This tool does basic tests on the install.\n" - echo -e "Usage:\n" - echo -e "\twptests [param [option param]]\n" - echo -e "\tall\n\t\ttests each item in wp-content/plugins on the server\n" - echo -e "\tall --url URL\n\t\ttests HTTP status code for each item in wp-content/plugins at specified url URL\n" - return - elif [[ ! -f wp-config.php ]]; then echo Could not find wp-config.php! && return 9 - fi - if [[ $2 == "--url" && -n $3 ]]; then status=$(curl -sIL -o /dev/null -w "%{http_code}\n" $3) - else status=$(php index.php >/dev/null && php wp-admin/index.php >/dev/null; echo $?); fi - [[ $1 == "-q" ]] && echo $status && return - echo - [[ $status != "255" && $status != "500" ]] && echo -e "No errors detected..." || echo -e "500 error on page"! - echo - [[ -z $1 ]] && return - [[ $1 == "all" ]] && folders="wp-content/plugins" || folders=$(echo $1|sed "s|/$||g") - temp=$(now) - if [[ $2 == "--url" && -n $3 ]]; then echo -e "*** NOTE: This test doesn't confirm items are fully functional; it simply checks the status code on '$3'. DO NOT INTERRUPT! ***\n" - else echo -e "*** NOTE: This test doesn't confirm items are fully functional; it simply tries to run index.php and wp-admin/index.php in the local shell. DO NOT INTERRUPT! ***\n"; fi - temp=$(now) - for f in $folders; do - [[ ! -d $f ]] && echo "The folder '$f' was not found"! && continue - echo "Testing $f..." - mv $f "$f"_$temp && echo "Moved $f to $f"_$temp... - mkdir $f && echo "Created new $f folder..." - status=$(wptests -q --url $3); [[ $status == "255" || $status == "500" ]] && echo "Renaming the $f folder results in a 500 error...errors below MAY be safe to ignore"! || echo "Renaming the $f folder appears to result in no error..." - for i in "$f"_$temp/*; do - [[ -f $i ]] && continue - plugin=${i##*/} - mv "$f"_$temp/$plugin $f && echo -e "\tTesting ${f%?} '$plugin'..." $( - status=$(wptests -q --url $3) - if [[ $status == "200" || $status == "0" ]]; then echo "OK" - elif [[ $status == 255 ]]; then echo "500" - else echo $status; fi - ) && mv $f/$plugin "$f"_$temp - done - mv "$f"_$temp/* $f && echo "Moved $f back to original folder..." && rm -rf "$f"_$temp && echo "Removed $f"_$temp... - done - echo -} -wpstats() { - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "\nThis tool returns a basic overview of the Wordpress install.\n\nUsage:\n\n\twpstats\n" && return - elif [[ -n $1 ]]; then return - fi - echo - echo -e "\tWP version:\t"$(wpver -q | awk '{print $1}') - echo -e "\tStatus code:\t"$( temp=$(wptests -q); [[ $temp != "255" ]] && echo "OK" || echo "Error"!) - if wpdb -q; then - echo -e "\tUserID 1:\t"$(wpuser -q) - wpurl -q | awk '{print "\t"$2"("$1"):\t"$3}' - wptheme -q - fi - echo -} -wptool() { +wptool() +{ echo -e " _ ______ __ __ | | / / __ \/ /_____ ____ / / @@ -738,20 +690,15 @@ wptool() { It assumes you are running said functions in the site's root folder. Each command listed below each have a -h option for more specific information: -\twpstats: basic overview -\twpurl: URL tools -\twptheme: theme tools -\twpdb: db tools -\twpuser: user tools -\twpplug: plugin tools -\twpht: .htaccess generator -\twpcore: core replacement tools -\twpfix: built-in WP fixes -\twpver: returns version info + wpstats: basic overview + wpurl: URL tools + wptheme: theme tools + wpdb: db tools + wpuser: user tools + wpplug: plugin tools + wpht: .htaccess generator + wpcore: core replacement tools + wpfix: built-in WP fixes + wpver: returns version info " } - -#search, multisite -wptoolv="1.7.1.2" -echo -e "\n Injected WPtool $wptoolv into current session. For details, type 'wptool'.\n" -unset HISTFILE From 1b6688395fc1348ad9ebce8d3255c77488ac6427 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Sat, 18 Apr 2015 00:49:51 -0600 Subject: [PATCH 02/24] 94% finished with first draft --- wpfools/wpfools.sh | 121 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 20 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 8682dd0..74b2fdb 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -28,7 +28,7 @@ # > 'wp-content_stock' won't be kept if there's already a wp-content present, under 'wpcore' # > old Wordpress files are no longer in 'core_$timestamp', they'll now be in 'oldwp_$timestamp' # > 'wpstats' does not run tests on index.php or wp-admin/index.php -# > +# > wpuser -u does not work for reasons. # # # @@ -50,6 +50,32 @@ # ### + + + + + +#set appropriate wp binary env +if [[ -f ./wp-includes/version.php ]]; then + wpver="$( php-cli -r 'require_once("./wp-includes/version.php"); echo "$wp_version";' )" + #non-intuitive, but this checks if the version is greater than or equal to 3.5.2 + if [[ "$( echo -e "3.5.2\n$wpver" | sort -V | head -n 1 )" == "3.5.2" ]]; then + #greater than or equal to 3.5.2 + wpcli() + { + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" + } + else + #less than 3.5.2 + wpcli() + { + /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" + } + fi +else + echo "oops" +fi + version_regex="^([[:digit:]]\.[[:digit:]]{1,2}|[[:digit:]]\.[[:digit:]]\.[[:digit:]]{1,2})$" sha1_regex="\b[[:xdigit:]]{40}\b" @@ -373,16 +399,15 @@ wpfix() #not working? struct="$( wpcli option get permalink_structure )" if [[ -n "$struct" ]]; then - wpcli rewrite structure "$struct" --hard - else - #something - sleep 0 + wpcli rewrite flush fi + wpcli rewrite structure "$struct" --hard } #unfinished maybe wpstats() { + #contains workaround for --option bug echo -e " WP version: $( wpcli core version ) UserID 1: $( wpcli "user get 1 --field='display_name'" ) @@ -442,18 +467,20 @@ wpht() wpdb() { - #FIX - #would like a better way of doing this line - read -r dbhost dbname dbpass dbuser dbprefix <<< "$( cat wp-config.php | egrep "^[^/].*[\"']DB_(NAME|USER|PASSWORD|HOST[^_])|table_prefix" | sort -d | sed "s/.*[\"']\(.*\)[\"'].*;.*/\1/" )" + #get some database variables from wp-config.php + dbuser="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_USER");' )" + dbpass="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_PASSWORD");' )" + dbhost="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_HOST");' )" + dbname="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_NAME");' )" + dbprefix="$( php-cli -r 'require_once("./wp-config.php"); echo "$table_prefix";' )" - #Need to include a optimize/fix option if [[ -z "$1" ]]; then echo -e " - DB user:\t$dbuser - DB pass:\t$dbpass - DB host:\t$dbhost - DB name:\t$dbname - DB prefix:\t$dbprefix + DB user: $dbuser + DB pass: $dbpass + DB host: $dbhost + DB name: $dbname + DB prefix: $dbprefix " wpcli core is-installed echo "SHOW STATUS WHERE variable_name = 'Threads_running';" | wpcli db query | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" @@ -553,17 +580,17 @@ update Update a user. #and not implementing a workaround because I'm also assuming that the reason is a good one. Rather #than not implementing this feature at all, I'm including the command that should work instead to #show users that it's not a good idea to update the username. - wpcli "user update "$1" --user_login="$3"" + wpcli "user update "$1" --user_login="$3"" #contains workaround for --option bug return elif [[ "$2" == "-p" ]]; then - wpcli "user update "$1" --user_pass="$3"" + wpcli "user update "$1" --user_pass="$3"" #contains workaround for --option bug return elif [[ "$2" == "-a" ]]; then - wpcli "user add-role "$1" administrator" + wpcli "user add-role "$1" administrator" #contains workaround for --option bug return elif [[ "$2" == "-d" ]]; then if [[ -n "$3" ]]; then - wpcli "user delete "$1" --reassign="$3"" + wpcli "user delete "$1" --reassign="$3"" #contains workaround for --option bug else wpcli user delete "$1" fi @@ -591,9 +618,9 @@ update Update a user. read -rp "Password [randomly generated]: " password if [[ -z "$password" ]]; then - wpcli "user create "$username" "$email" --role=administrator" + wpcli "user create "$username" "$email" --role=administrator" #contains workaround for --option bug else - wpcli "user create "$username" "$email" --role=administrator --user_pass="$password"" + wpcli "user create "$username" "$email" --role=administrator --user_pass="$password"" #contains workaround for --option bug fi echo @@ -634,7 +661,61 @@ update Update a user. +wpplug() +{ + if [[ -z "$1" ]]; then + #contains workaround for --option bug + echo " +Active plugins: + "$( wpcli "plugin list --status=active --fields=name" | sed -n "2,$ p" )" +Available plugins: + "$( wpcli "plugin list --fields=name" | sed -n "2,$ p" )" + " + return + elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + echo -e " +Basic plugin functions. + + activate Activate a plugin. + active List active plugins + deactivate Deactivate a plugin. + delete Delete plugin files. + get Get a plugin. + install Install a plugin. + is-installed Check if the plugin is installed. + list Get a list of plugins. + path Get the path to a plugin or to the plugin directory. + search Search the wordpress.org plugin repository. + status See the status of one or all plugins. + toggle Toggle a plugin's activation state. + uninstall Uninstall a plugin. + update Update one or more plugins. + " + return + elif [[ "$1" == "active" ]]; then + echo " +Active plugins: + "$( wpcli "plugin list --status=active --fields=name" | sed -n "2,$ p" )" + " + return + elif [[ "$1" == "-d" ]]; then + wpcli plugin deactivate --all + return + elif [[ "$1" == "" ]]; then + + elif [[ "$1" == "" ]]; then + + elif [[ "$1" == "" ]]; then + + elif [[ "$1" == "" ]]; then + + else + #pipe output to sed to fix usage text, but this breaks read prompts like in wpcli user delete :( + wpcli user "$@" # | sed "s|wp user|wpuser|g" + return + fi +} From 650d4560bf1f532e9d1d5b765356e18241e6dc38 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Mon, 20 Apr 2015 01:04:40 -0600 Subject: [PATCH 03/24] First draft complete Second draft will include: > wpcore() > QA testing on each function > wpfix() fixes > Hopefully a much better wpht() > Other stuff I think of, including output formatting changes --- wpfools/wpfools.sh | 385 ++++++++++++++++++++------------------------- 1 file changed, 174 insertions(+), 211 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 74b2fdb..286722a 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -43,8 +43,8 @@ # > replace wpcore() with wpcli core, maybe (more testing required) # > wpht() in general just needs some serious QA testing, r&d # > wpfix() needs QA -# -# +# > be consistent with returns +# > remove -e from echo when not necessary # # # @@ -53,28 +53,34 @@ - - -#set appropriate wp binary env -if [[ -f ./wp-includes/version.php ]]; then - wpver="$( php-cli -r 'require_once("./wp-includes/version.php"); echo "$wp_version";' )" - #non-intuitive, but this checks if the version is greater than or equal to 3.5.2 - if [[ "$( echo -e "3.5.2\n$wpver" | sort -V | head -n 1 )" == "3.5.2" ]]; then - #greater than or equal to 3.5.2 - wpcli() - { - /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" - } +#untested on old versions of wordpress +wpenv() +{ + #set appropriate wp binary env + if [[ -f ./wp-includes/version.php ]]; then + wp_version="$( php-cli -r 'require_once("./wp-includes/version.php"); echo "$wp_version";' )" + #non-intuitive, but this checks if the version is greater than or equal to 3.5.2 + if [[ "$( echo -e "3.5.2\n$wp_version" | sort -V | head -n 1 )" == "3.5.2" ]]; then + #greater than or equal to 3.5.2 + wpcli() + { + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" + } + else + #less than 3.5.2 + wpcli() + { + /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" + } + fi else - #less than 3.5.2 + echo "Unable to detect Wordpress version, assuming > 3.5.2." wpcli() { - /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" } fi -else - echo "oops" -fi +} version_regex="^([[:digit:]]\.[[:digit:]]{1,2}|[[:digit:]]\.[[:digit:]]\.[[:digit:]]{1,2})$" sha1_regex="\b[[:xdigit:]]{40}\b" @@ -130,7 +136,7 @@ Usage: { #Sanitize user input if [[ ! "$arg" =~ $version_regex ]]; then - echo "Version specified is not valid!" + echo 'Version specified is not valid!' return 9 fi @@ -341,7 +347,9 @@ Usage: wptheme() { - if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + wpenv + + if [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then echo " activate Activate a theme. delete Delete a theme. @@ -356,19 +364,20 @@ wptheme() path Get the path to a theme or to the theme directory. search Search the wordpress.org theme repository. status See the status of one or all themes. - update Update one or more themes. + update [--all] Update one or more themes. use Install and activate a theme. -s Set only stylesheet: wptheme -s twentyfifteen -t Set only template: wptheme -t twentyfifteen " elif [[ -z "$1" ]]; then - echo -e "\nCurrent themes:\n" - #wpcli theme list --status="active" #broken - echo -e "\tstylesheet:\t$(wpcli option get stylesheet)" - echo -e "\ttemplate:\t$(wpcli option get template)" - echo -e "\nAvailable themes:\n" - wpcli theme list + echo + wpcli theme status + echo " +Details: + stylesheet: $(wpcli option get stylesheet) + template: $(wpcli option get template) + " elif [[ "$1" == "fresh" ]]; then wpcli theme install twentyfifteen wpcli theme activate twentyfifteen @@ -386,60 +395,75 @@ wptheme() wpfix() { - if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then - echo -e "This tool runs various built-in Wordpress functions and fixes.\n\nUsage:\n\n\twpfix\n" + wpenv + + if [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then + echo -e "This tool runs various built-in Wordpress functions and fixes." return fi wpcli cache flush - wpcli db repair - wpcli db optimize + wpcli db repair | grep -v "OK" + wpcli db optimize | grep -v "OK" wpcli core update-db + #wpcli rewrite flush --hard + wpcli transient delete-expired - #not working? - struct="$( wpcli option get permalink_structure )" - if [[ -n "$struct" ]]; then - wpcli rewrite flush - fi - wpcli rewrite structure "$struct" --hard + +# ###HARD FIXES### +# #probably gonna add a line by line prompt for these. +# +# wpcli role reset +# wpcli media regenerate --yes +# wpcli plugin update --all +# wpcli theme update --all +# wpcli core update +# wpcli transient delete-all +# +# #delete spam comments +# wp comment delete $( wp comment list --status=spam --format=ids ) +# #delete unapproved comments +# wp comment delete $( wp comment list --status=unapproved --format=ids ) } #unfinished maybe wpstats() { - #contains workaround for --option bug + wpenv + + #perhaps do a wpcli core check-update alongside the version + #maybe check some things about the install such as checksums, database connectivity, etc echo -e " - WP version: $( wpcli core version ) - UserID 1: $( wpcli "user get 1 --field='display_name'" ) - home: $( wpcli option get home ) - siteurl: $( wpcli option get siteurl ) - stylesheet: $( wpcli option get stylesheet ) - template: $( wpcli option get template ) + WP version: $( wpcli core version ) + UserID 1: $( wpcli user get 1 --field='display_name' ) + home: $( wpcli option get home ) + siteurl: $( wpcli option get siteurl ) + stylesheet: $( wpcli option get stylesheet ) + template: $( wpcli option get template ) " + wpcli core is-installed || echo } wpurl() { + wpenv + if [[ -z "$1" ]]; then echo -e " - home: $( wpcli option get home ) - siteurl: $( wpcli option get siteurl ) + home: $( wpcli option get home ) + siteurl: $( wpcli option get siteurl ) " - elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then echo -e "This tool returns the current URL settings in the database, or updates them to a specified URL. -Usage: - wpurl [URL] - - URL - specify a URL to change the site to. If the URL does not start with 'http://' or 'https://' it will automatically append 'http://'. " else if [[ "$1" =~ (^http[s]?://.*) ]]; then url="$1" else url="http://$1" + echo "Using: $url" fi wpcli option update siteurl "$url" wpcli option update home "$url" @@ -450,8 +474,10 @@ Usage: #hopefully this will be replaced by a feature I have requested, quick and dirty until then wpht() { + wpenv + if [[ -f ./.htaccess ]]; then - cp ./.htaccess ./.htaccess_"$(now)" + cp ./.htaccess ./.htaccess_"$( now )" fi #double check this @@ -467,28 +493,34 @@ wpht() wpdb() { + wpenv + #get some database variables from wp-config.php - dbuser="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_USER");' )" - dbpass="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_PASSWORD");' )" - dbhost="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_HOST");' )" - dbname="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_NAME");' )" - dbprefix="$( php-cli -r 'require_once("./wp-config.php"); echo "$table_prefix";' )" + if [[ -f "./wp-config.php" ]]; then + dbuser="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_USER");' )" + dbpass="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_PASSWORD");' )" + dbhost="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_HOST");' )" + dbname="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_NAME");' )" + dbprefix="$( php-cli -r 'require_once("./wp-config.php"); echo "$table_prefix";' )" + else + echo "Unable to locate the wp-config.php file, attempting to continue..." + fi if [[ -z "$1" ]]; then echo -e " - DB user: $dbuser - DB pass: $dbpass - DB host: $dbhost - DB name: $dbname - DB prefix: $dbprefix - " - wpcli core is-installed - echo "SHOW STATUS WHERE variable_name = 'Threads_running';" | wpcli db query | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" - if [ $( wpcli db tables | grep -c ) -lt 1 ]; then + DB user: $dbuser + DB pass: $dbpass + DB host: $dbhost + DB name: $dbname + DB prefix: $dbprefix + " + wpcli core is-installed || echo + wpcli db query "SHOW STATUS WHERE variable_name = 'Threads_running';" | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" + if [ $( wpcli db tables | egrep -c "^$dbprefix" ) -lt 1 ]; then echo 'Connected with no errors, but no tables that match specified prefix!' fi - elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then echo " cli Open a mysql console using the WordPress credentials. create Create the database, as specified in wp-config.php @@ -509,35 +541,36 @@ wpdb() wpver() { - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e " -This tool returns the current install's file and database versions. - - Usage: + wpenv -\twpver [option] - -\t -h\n\t\tdisplay this help output -" + if [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then + echo -e " +This tool returns the current install's version. + " return - fi - - echo " + elif [[ "$1" == "-q" ]]; then + wpcli core version + else + echo " WP version: $( wpcli core version ) - " + " + fi } wpuser() { + wpenv if [[ -z "$1" ]]; then echo wpcli user list echo return - elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then echo -e " -This tool performs various user functions, including returning info for a specified user, changing usernames, passwords, changing a user to an admin, creating new admin users, and deleting users.\n +This tool performs various user functions, including returning info for a specified +user, changing usernames, passwords, changing a user to an admin, creating new admin +users, and deleting users. USERID can be the user login, user email, or actual user ID of the user(s) to update. Usage: @@ -545,8 +578,6 @@ Usage: USERID Returns details about specified user USERID - USERID -u NAME - change username of user USERID to NAME USERID -p PASS change password of user USERID to PASS USERID -a @@ -576,21 +607,22 @@ update Update a user. " return elif [[ "$2" == "-u" ]]; then - #yes, I know this gives a warning and does not work. I'm assuming there's a reason for that warning, + #Yes, I know this gives a warning and does not work. I'm assuming there's a reason for that warning, #and not implementing a workaround because I'm also assuming that the reason is a good one. Rather #than not implementing this feature at all, I'm including the command that should work instead to - #show users that it's not a good idea to update the username. - wpcli "user update "$1" --user_login="$3"" #contains workaround for --option bug + #show users that it's not a good idea to update the username. This option is not in the help text + #and should be considered deprecated; it is included only for legacy purposes. + wpcli user update "$1" --user_login="$3" return elif [[ "$2" == "-p" ]]; then - wpcli "user update "$1" --user_pass="$3"" #contains workaround for --option bug + wpcli user update "$1" --user_pass="$3" return elif [[ "$2" == "-a" ]]; then - wpcli "user add-role "$1" administrator" #contains workaround for --option bug + wpcli user add-role "$1" administrator return elif [[ "$2" == "-d" ]]; then if [[ -n "$3" ]]; then - wpcli "user delete "$1" --reassign="$3"" #contains workaround for --option bug + wpcli user delete "$1" --reassign="$3" else wpcli user delete "$1" fi @@ -618,11 +650,12 @@ update Update a user. read -rp "Password [randomly generated]: " password if [[ -z "$password" ]]; then - wpcli "user create "$username" "$email" --role=administrator" #contains workaround for --option bug + wpcli user create "$username" "$email" --role=administrator else - wpcli "user create "$username" "$email" --role=administrator --user_pass="$password"" #contains workaround for --option bug + wpcli user create "$username" "$email" --role=administrator --user_pass="$password" fi + unset password echo return elif [[ -z "$2" ]]; then @@ -635,81 +668,58 @@ update Update a user. fi } - - - - - - - - - - - - -# -# -# -# -#Code beyond this point has not been reviewed, enter at your own risk... -# -#Commits welcome :) -# -# -# -# - - - wpplug() { - if [[ -z "$1" ]]; then - #contains workaround for --option bug - echo " -Active plugins: - "$( wpcli "plugin list --status=active --fields=name" | sed -n "2,$ p" )" + wpenv -Available plugins: - "$( wpcli "plugin list --fields=name" | sed -n "2,$ p" )" - " + if [[ -z "$1" ]]; then + echo + wpcli plugin status + echo return - elif [[ "$1" == "--help" || "$1" == "-h" || "$1" == "help" ]]; then + elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then echo -e " Basic plugin functions. - activate Activate a plugin. - active List active plugins - deactivate Deactivate a plugin. - delete Delete plugin files. - get Get a plugin. - install Install a plugin. - is-installed Check if the plugin is installed. - list Get a list of plugins. - path Get the path to a plugin or to the plugin directory. - search Search the wordpress.org plugin repository. - status See the status of one or all plugins. - toggle Toggle a plugin's activation state. - uninstall Uninstall a plugin. - update Update one or more plugins. - " - return - elif [[ "$1" == "active" ]]; then - echo " -Active plugins: - "$( wpcli "plugin list --status=active --fields=name" | sed -n "2,$ p" )" + -a, activate [--all] Activate one or more plugins. + -d, deactivate [--all] Deactivate one or more plugins. + delete Delete plugin files. + get Get a plugin. + install Install a plugin. + is-installed Check if the plugin is installed. + list Get a list of plugins. + path Get the path to a plugin or to the plugin directory. + search Search the wordpress.org plugin repository. + status See the status of one or all plugins. + toggle Toggle a plugin's activation state. + uninstall Uninstall a plugin. + -u, update [--all] Update one or more plugins. " return - elif [[ "$1" == "-d" ]]; then - wpcli plugin deactivate --all - return - elif [[ "$1" == "" ]]; then - - elif [[ "$1" == "" ]]; then - - elif [[ "$1" == "" ]]; then - - elif [[ "$1" == "" ]]; then - + elif [[ "$1" == "-d" ]] || [[ "$1" == "deactivate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then + active_plugins=( $( wpcli plugin list --status=active --fields=name | sed -n "2,$ p" ) ) + if [[ -z "${active_plugins[@]}" ]]; then + echo 'No plugins active!' + else + wpcli plugin deactivate ${active_plugins[@]} + fi + elif [[ "$1" == "-a" ]] || [[ "$1" == "activate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then + #The point of this is to check if someone ran a deactivate --all already, and if so, reactivate + #only the plugins that were deactivated the first time. Otherwise, activate all plugins. If you + #run this twice, it'll activate all plugins regardless. + inactive_plugins=( $( wpcli plugin list --status=inactive --fields=name | sed -n "2,$ p" ) ) + if [[ -z "${active_plugins[@]}" ]]; then + if [[ -n "${inactive_plugins[@]}" ]]; then + wpcli plugin activate ${inactive_plugins[@]} + else + echo 'All plugins active!' + fi + else + wpcli plugin activate ${active_plugins[@]} + unset active_plugins + fi + elif [[ "$1" == "-u" ]] || [[ "$1" == "update" && "$2" == "-all" ]]; then + wpcli plugin update --all else #pipe output to sed to fix usage text, but this breaks read prompts like in wpcli user delete :( wpcli user "$@" # | sed "s|wp user|wpuser|g" @@ -717,59 +727,12 @@ Active plugins: fi } - - - - - - - - - - -wpplug() -{ - echo - folder=wp-content/plugins - if [[ $1 == "--help" || $1 == "-h" ]]; then - echo -e "This tool does basic plugin functions, such as displaying active and available plugins, or disabling them all.\n" - echo -e "Usage:\n" - echo -e "\twpplug [option]\n" - echo -e "\t-d\n\t\tdisable all plugins by renaming the plugins folder\n" - return - elif [[ ! -d $folder ]]; then echo "The $folder folder was not found"! && return 9 - elif [[ ! -f wp-config.php ]]; then echo Could not find wp-config.php! && return 9 - fi - if [[ $1 == "-d" ]]; then - temp=$(now) - mv $folder "$folder"_$temp && echo "Moved plugins to $folder"_$temp... - elif [[ -z $1 ]]; then - echo -e "Active plugins:\n" - wpconn "wpplug" - active=$(echo "$myconn" | tail -n +2) - php-cli -r "print_r(unserialize('$active'));" | grep "=>" | sed "s|.*=> \(.*\)|\t\1|" - echo - echo -e "Available plugins:\n" - ls -F $folder |grep "/"|grep -v "^\."|sed "s|^\(.*\)/|\t\1|" #ls -A is overwritten by default $LS_OPTIONS in alias - fi - echo -} - - - -wptool() +wphelp() { echo -e " - _ ______ __ __ - | | / / __ \/ /_____ ____ / / - | | /| / / /_/ / __/ __ \/ __ \/ / - | |/ |/ / ____/ /_/ /_/ / /_/ / / - |__/|__/_/ \__/\____/\____/_/ - a toolkit production - - WPtool $wptoolv is suite of bash functions to administer Wordpress installs. - It assumes you are running said functions in the site's root folder. Each - command listed below each have a -h option for more specific information: + The following are bash functions that call /usr/bin/wp to administer Wordpress + installs. It assumes you are running said functions in the site's root folder. + Most commands listed below have a -h option for more specific information: wpstats: basic overview wpurl: URL tools From de1e9812432741f6fa0020ba6ab5199b51923885 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Mon, 20 Apr 2015 01:09:57 -0600 Subject: [PATCH 04/24] First draft complete Now a fully functional wpcore() while I prepare to gut it entirely :frowning: Program is fully functional at this point and ready for QA + second draft --- wpfools/wpfools.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 286722a..981214a 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -29,7 +29,7 @@ # > old Wordpress files are no longer in 'core_$timestamp', they'll now be in 'oldwp_$timestamp' # > 'wpstats' does not run tests on index.php or wp-admin/index.php # > wpuser -u does not work for reasons. -# +# > wpver() does not get db version, and therefore wpcore() can't download db version # # # @@ -111,8 +111,6 @@ Usage: download version VERSION of the Wordpress core cur download new set of files matching current file version - db - download set of files matching current database version -h display this help output " @@ -122,15 +120,15 @@ Usage: #Download new set of files matching current file version fileVersion() { - version="$(wpver -q | awk '{print $1}')" + version="$( wpver -q )" wpfile="wordpress-$version.tar.gz" } #Download new set of files matching current database version - databaseVersion() - { - version="$(wpver -q | awk '{print $3}')" - wpfile="wordpress-$version.tar.gz" - } +# databaseVersion() +# { +# version="$( wpver -q | awk '{print $3}' )" +# wpfile="wordpress-$version.tar.gz" +# } #Download new set of files matching user specified version selectedVersion() { @@ -321,8 +319,8 @@ Usage: return 0 elif [[ "$arg" == "cur" || "$arg" == "file" ]]; then fileVersion - elif [[ "$arg" == "db" || "$arg" == "database" ]]; then - databaseVersion + #elif [[ "$arg" == "db" || "$arg" == "database" ]]; then + # databaseVersion elif [[ "$arg" =~ $version_regex ]]; then selectedVersion elif [[ "$arg" == "latest" || -z "$arg" ]]; then From 95b8762e55e8ead30158e332de4276673baee846 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Mon, 20 Apr 2015 18:51:02 -0600 Subject: [PATCH 05/24] minor fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wpplug() was calling wpcli user ಠ_ಠ --- wpfools/wpfools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 981214a..abea2af 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -720,7 +720,7 @@ Basic plugin functions. wpcli plugin update --all else #pipe output to sed to fix usage text, but this breaks read prompts like in wpcli user delete :( - wpcli user "$@" # | sed "s|wp user|wpuser|g" + wpcli plugin "$@" # | sed "s|wp user|wpuser|g" return fi } From d4a3bc9d3c4da8fe705cc64fc0d48c434faefa83 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Wed, 29 Apr 2015 22:46:51 -0600 Subject: [PATCH 06/24] 92% finished with second draft >hoping to give wpfix --hard a menu >new wpcore & wpstats need testing --- wpfools/wpfools.sh | 531 +++++++++++++++++++++++---------------------- 1 file changed, 267 insertions(+), 264 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index abea2af..5c1d579 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -29,7 +29,7 @@ # > old Wordpress files are no longer in 'core_$timestamp', they'll now be in 'oldwp_$timestamp' # > 'wpstats' does not run tests on index.php or wp-admin/index.php # > wpuser -u does not work for reasons. -# > wpver() does not get db version, and therefore wpcore() can't download db version +# > wpver() does not get db version, and therefore wpcore() can't download db version #note, you can get db version with wpcli core version --extra, possibly implement db version later # # # @@ -40,25 +40,23 @@ # Things to fix # ---------------------------- # -# > replace wpcore() with wpcli core, maybe (more testing required) -# > wpht() in general just needs some serious QA testing, r&d +# > wpht() should be fixed once the feature gets implemented # > wpfix() needs QA -# > be consistent with returns -# > remove -e from echo when not necessary # # # ### - +version_regex="\b([[:digit:]]\.[[:digit:]]{1,2}|[[:digit:]]\.[[:digit:]]\.[[:digit:]]{1,2})\b" +sha1_regex="\b[[:xdigit:]]{40}\b" #untested on old versions of wordpress wpenv() { #set appropriate wp binary env if [[ -f ./wp-includes/version.php ]]; then - wp_version="$( php-cli -r 'require_once("./wp-includes/version.php"); echo "$wp_version";' )" + wp_version="$( egrep -m 1 -o "$version_regex" ./wp-includes/version.php )" #non-intuitive, but this checks if the version is greater than or equal to 3.5.2 if [[ "$( echo -e "3.5.2\n$wp_version" | sort -V | head -n 1 )" == "3.5.2" ]]; then #greater than or equal to 3.5.2 @@ -82,22 +80,24 @@ wpenv() fi } -version_regex="^([[:digit:]]\.[[:digit:]]{1,2}|[[:digit:]]\.[[:digit:]]\.[[:digit:]]{1,2})$" -sha1_regex="\b[[:xdigit:]]{40}\b" - -now() +now() { - date -u +"%Y%m%d-%H%M%S" + date -u +"%Y%m%d-%H%M%S" } wpcore() { arg="$1" + wpenv + + #clean up cache, this is required because there's a bug that causes update to fail when it tries using a cached file + rm -rf /home2/"$(whoami)"/.wp-cli/cache/core/* + #Display help information helpText() { - echo -e " + echo " This tool downloads the latest core, a new core of the current version, or a specified version. @@ -113,6 +113,21 @@ Usage: download new set of files matching current file version -h display this help output + +Additional features: +==================== +check-update Check for update via Version Check API. Returns latest version if there's an update, or empty if no update available. +config [--rebuild] Generate or attempt to rebuild a wp-config.php file. +download Download core WordPress files. +install Create the WordPress tables in the database. +is-installed Determine if the WordPress tables are installed. +language Modify or activate languages. +multisite-convert Transform a single-site install into a multi-site install. +multisite-install Install multisite from scratch. +update Update WordPress. +update-db Update the WordPress database. +verify-checksums Verify WordPress files against WordPress.org's checksums. +version Display the WordPress version. " } @@ -120,8 +135,7 @@ Usage: #Download new set of files matching current file version fileVersion() { - version="$( wpver -q )" - wpfile="wordpress-$version.tar.gz" + version="$( wpcli core version )" } #Download new set of files matching current database version # databaseVersion() @@ -139,184 +153,123 @@ Usage: fi version="$arg" - wpfile="wordpress-$version.tar.gz" } #Download new set of files matching current file version latestVersion() { version="latest" - wpfile="latest.tar.gz" } - #Download Wordpress package - getFile() + updateWordpress() { - #verifies the file with an sha1 checksum - checkSha1() - { - if [[ -f "./$wpfile" ]]; then - sha1_remote="$( curl -sS "https://wordpress.org/$wpfile.sha1" | egrep -o "$sha1_regex" )" - if [[ "$sha1_remote" =~ $sha1_regex ]]; then - #successfully got remote sha1 checksum - sha1_local="$( sha1sum "./$wpfile" | egrep -o "$sha1_regex" )" - if [[ "$sha1_local" =~ $sha1_regex ]]; then - #successfully got local sha1 checksum - if [[ "$sha1_local" == "$sha1_remote" ]]; then - #checksum match - return 0 - else - #checksum mismatch - echo -en '\nChecksum mismatch!' - rm -f "./$wpfile" - ((i++)) - return 9 - fi - else - echo -en "\nError: Unable to get local sha1 checksum" - rm -f "./$wpfile" - return 9 - fi - else - echo -en "\nError: Unable to get remote sha1 checksum" - return 9 - fi + #update if we're currently in a wordpress directory, download otherwise + #basic workaround for incorrectly detected wp installs + #see https://github.com/wp-cli/wp-cli/issues/1811 + if (( $( wp core is-installed &> /dev/null; echo $? ) == 0 )) && [[ -d ./wp-admin/ ]] && [[ -d ./wp-includes/ ]] && [[ -f ./wp-config.php ]]; then + if [[ "$version" == "latest" ]]; then + wpcli core update --force else - #file does not exist - echo -n "Error: Download failed" - ((i++)) - return 9 + wpcli core update --version="$version" --force fi - } - - if [[ "$version" == "latest" ]]; then - echo -n "Downloading latest Wordpress..." else - echo -n "Downloading Wordpress $version..." - fi - - if [[ ! -f "./$wpfile" ]]; then - wget -q "https://wordpress.org/$wpfile" - fi - - TRIES=3 - - i=0 - checkSha1 - #try a few times if it fails - while (( $? != 0 && "$i" < "$TRIES" )); do - echo -en "\nRetrying..." - wget -q "https://wordpress.org/$wpfile" - checkSha1 - done - - #too many retries - if (( "$i" >= "$TRIES" )); then - echo -e "\nFatal Error: Could not download Wordpress." - return 9 + if [[ "$version" == "latest" ]]; then + wpcli core download --force + else + wpcli core download --version="$version" --force + fi fi - - echo "done." - return 0 } - #Extract Wordpress - extractWordpress() + #Rebuild / generate config config + buildConfig() { - ##build list of Wordpress files in pwd - #build list of possible wp files - possible_files=( $( tar -ztf "./$wpfile" | sed -e "s|^wordpress/||g" -e "s|/.*|/|g" -e "/^[[:space:]]*$/d" | sort -u ) ) - possible_files=( "${possible_files[@]}" "wp-config.php" ) - #build list of actual files - for file in "${possible_files[@]}"; do - if [[ -e "./$file" ]]; then - actual_files=( "${actual_files[@]}" "$file" ) + if [[ "$1" == "--rebuild" ]]; then + if [[ ! -f ./wp-config.php ]]; then + echo 'No wp-config.php file available to rebuild!' + echo "Try: wpcore config" + return 9 fi - done - - old_wp="oldwp_$( now )" - - #rebuild a temp array without index.php - actual_files_temp=( ${actual_files[@]/index.php/} ) - - #if there's old stuff that isn't index.php - if (( "${#actual_files_temp[@]}" > 0 )); then - echo -n "Moving old Wordpress files..." - - #create old Wordpress folder - if [[ ! -d "./$old_wp/" ]]; then - mkdir "./$old_wp/" + #harmless fix so we can use cut in a sec even if their quotes are jacked up + sed "s/[‘’]/'/g" -i ./wp-config.php + + dbuser="$( grep "DB_USER" ./wp-config.php | cut -d \' -f 4 )" + dbpass="$( grep "DB_PASSWORD" ./wp-config.php | cut -d \' -f 4 )" + dbhost="$( grep "DB_HOST" ./wp-config.php | cut -d \' -f 4 )" + dbname="$( grep "DB_NAME" ./wp-config.php | cut -d \' -f 4 )" + dbprefix="$( grep "table_prefix" ./wp-config.php | cut -d \' -f 2 )" + + temp="wp-config_$( now )" + mv ./wp-config.php ./"$temp".php + + wpcli core config --dbname="$dbname" --dbuser="$dbuser" --dbpass="$dbpass" --dbhost="$dbhost" --dbprefix="$dbprefix" + if (( $? != 0 )); then + mv ./"$temp".php ./wp-config.php + echo 'Rebuild failed!' fi - - #move old Wordpress files down into a new subdir - for file in "${actual_files[@]}"; do - if [[ -e "./$file" ]]; then - rsync -aq "./$file" "./$old_wp/$file" - if [[ $? == 0 && -e "./$old_wp/$file" ]]; then - rm -rf "./$file" - fi - fi - done - - echo "done." - fi - - echo -n "Extracting Wordpress..." - - #extract the new Wordpress files into pwd - tar -xf "./$wpfile" --strip-components=1 - - didFail="0" - #test for successful extraction - for file in ${possible_files[@]/wp-config.php/}; do - if [[ ! -e "./$file" ]]; then - ##TODO: retry extracting failed file - echo -en "\nError extracting $file"'!' - didFail="1" + else + if [[ -f ./wp-config.php ]]; then + echo 'A wp-config.php file already exists!' + echo "The existing file will be replaced if you continue." + fi + echo + echo "Enter database connection settings below:" + + default="$(whoami)_wp" + unset dbname + read -rp "Database name [$default]: " dbname + if [[ -z "$dbname" ]]; then + dbname="$default" fi - done - - if (( "$didFail" == 1 )); then - echo -e "\nFatal Error: Could not extract $file." - return 9 - fi - #remove $wpfile - rm -f "./$wpfile" + default="$(whoami)_wp" + unset dbuser + read -rp "Username [$default]: " dbuser + if [[ -z "$dbuser" ]]; then + dbuser="$default" + fi - echo "done." + default="strings /dev/urandom | egrep -o "[[:alnum:]]" | head -n 20 | tr -d "\n"" + unset dbpass + read -rp "Password [$default]: " dbpass + if [[ -z "$dbpass" ]]; then + dbpass="$default" + fi - #if there was a wp-content dir in the old install, copy it into pwd and burn stock wp-content - if [[ -d "./$old_wp/wp-content/" ]]; then - echo -n "Moving in old wp-content..." + default="localhost" + unset dbhost + read -rp "Password [$default]: " dbhost + if [[ -z "$dbhost" ]]; then + dbhost="$default" + fi - rm -rf "./wp-content/" - rsync -aq "./$old_wp/wp-content/" "./wp-content/" + default="_wp" + unset dbprefix + read -rp "Password [$default]: " dbprefix + if [[ -z "$dbprefix" ]]; then + dbprefix="$default" + fi - echo "done." - fi - #move in old wp-config.php if it exists - if [[ -f "./$old_wp/wp-config.php" ]]; then - echo -n "Moving in old wp-config.php..." + if [[ -f ./wp-config.php ]]; then + mv ./wp-config.php ./wp-config_"$( now )".php + fi - if [[ -f "./wp-config.php" ]]; then - rm -f "./wp-config.php" + wpcli core config --dbname="$dbname" --dbuser="$dbuser" --dbpass="$dbpass" --dbhost="$dbhost" --dbprefix="$dbprefix" + if (( $? != 0 )); then + wpcli core config --dbname="$dbname" --dbuser="$dbuser" --dbpass="$dbpass" --dbhost="$dbhost" --dbprefix="$dbprefix" --skip-check &> /dev/null fi - rsync -aq "./$old_wp/wp-config.php" "./wp-config.php" - echo "done." - else - #otherwise, move in wp-config-sample.php - mv "./wp-config-sample.php" "./wp-config.php" + unset dbpass fi - - return 0 } #process user input - if [[ "$arg" == "--help" || "$arg" =~ -[hH] ]]; then + if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then helpText return 0 + elif [[ "$1" == "help" && -n "$2" ]]; then + wpcli help core "$@" + return $? elif [[ "$arg" == "cur" || "$arg" == "file" ]]; then fileVersion #elif [[ "$arg" == "db" || "$arg" == "database" ]]; then @@ -325,49 +278,46 @@ Usage: selectedVersion elif [[ "$arg" == "latest" || -z "$arg" ]]; then latestVersion + elif [[ "$arg" == "config" ]]; then + buildConfig "$2" + return $? else - echo 'Unknown Wordpress version specified!' - echo "Wordpress versions can be either #.# or #.#.#" - helpText - return 9 + wpcli core "$@" + return $? fi - getFile - if (( $? != 0 )); then - return 9 - fi - extractWordpress + updateWordpress || return $? + wpcli core update-db } -######untested code below####### - - wptheme() { wpenv - if [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then + if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then echo " - activate Activate a theme. - delete Delete a theme. - disable Disable a theme in a multisite install. - enable Enable a theme in a multisite install. - fresh Install twentyfifteen and set as active theme. - get Get a theme. - install Install a theme. - is-installed Check if the theme is installed. - list Get a list of themes. - mod Manage theme mods. - path Get the path to a theme or to the theme directory. - search Search the wordpress.org theme repository. - status See the status of one or all themes. - update [--all] Update one or more themes. - use Install and activate a theme. - - -s Set only stylesheet: wptheme -s twentyfifteen - -t Set only template: wptheme -t twentyfifteen + activate Activate a theme. + delete Delete a theme. + disable Disable a theme in a multisite install. + enable Enable a theme in a multisite install. + fresh Install twentyfifteen and set as active theme. + get Get a theme. + install Install a theme. + is-installed Check if the theme is installed. + list Get a list of themes. + mod Manage theme mods. + path Get the path to a theme or to the theme directory. + search Search the wordpress.org theme repository. + status See the status of one or all themes. + -u, update [--all] Update one or more themes. + use Install and activate a theme. + + -s Set only stylesheet: wptheme -s twentyfifteen + -t Set only template: wptheme -t twentyfifteen " + elif [[ "$1" == "help" && -n "$2" ]]; then + wpcli help theme "$@" elif [[ -z "$1" ]]; then echo wpcli theme status @@ -386,6 +336,8 @@ Details: wpcli option update stylesheet "$2" elif [[ "$1" == "-t" ]]; then wpcli option update template "$2" + elif [[ "$1" == "-u" ]]; then + wpcli theme update --all else wpcli theme "$@" fi @@ -395,51 +347,105 @@ wpfix() { wpenv - if [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then - echo -e "This tool runs various built-in Wordpress functions and fixes." - return + if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then + echo "This tool runs various built-in Wordpress functions and fixes." + return 0 fi + #not built in, but solves more problems than you'd think + sed "s/[‘’]/'/g" -i ./wp-config.php wpcli cache flush wpcli db repair | grep -v "OK" wpcli db optimize | grep -v "OK" wpcli core update-db - #wpcli rewrite flush --hard wpcli transient delete-expired + wpcore config --rebuild -# ###HARD FIXES### -# #probably gonna add a line by line prompt for these. -# -# wpcli role reset -# wpcli media regenerate --yes -# wpcli plugin update --all -# wpcli theme update --all -# wpcli core update -# wpcli transient delete-all -# -# #delete spam comments -# wp comment delete $( wp comment list --status=spam --format=ids ) -# #delete unapproved comments -# wp comment delete $( wp comment list --status=unapproved --format=ids ) + ###HARD FIXES### + #would be good to get a menu going + if [[ "$1" == "--hard" ]]; then + yes="^[yY][eE]?[sS]?$" + echo "For the following question, the default answer is no." + echo "It is recommended that you know what you're doing before you run these, and have a backup." + unset response + + read -rp "Rewrite htaccess file? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpht + unset response + fi + read -rp "Reset all roles to default capabilities? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli role reset --all + unset response + fi + wpcli media regenerate --yes #prompts on its own + read -rp "Update all plugins? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli plugin update --all + unset response + fi + read -rp "Update all themes? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli theme update --all + unset response + fi + read -rp "Update to latest WordPress version? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli core update + unset response + fi + read -rp "Delete all transients? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli transient delete-all + unset response + fi + read -rp "Delete all comments that have been marked as spam? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + #delete spam comments + wp comment delete $( wp comment list --status=spam --format=ids ) + unset response + fi + read -rp "Delete all comments that have not been approved? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + #delete unapproved comments + wp comment delete $( wp comment list --status=unapproved --format=ids ) + unset response + fi + fi } -#unfinished maybe wpstats() { wpenv - #perhaps do a wpcli core check-update alongside the version - #maybe check some things about the install such as checksums, database connectivity, etc - echo -e " - WP version: $( wpcli core version ) - UserID 1: $( wpcli user get 1 --field='display_name' ) - home: $( wpcli option get home ) - siteurl: $( wpcli option get siteurl ) - stylesheet: $( wpcli option get stylesheet ) - template: $( wpcli option get template ) + available_version="$( wpcli core check-update --field=version | egrep -o $version_regex )" + wp_version="$( wpcli core version )" + if [[ -z "$available_version" ]]; then + version="$wp_version ($available_version available)" + else + version="$wp_version" + fi + echo " + WP version: $version + user: $( wpcli user list --fields=id,user_login | sort -n | sed -n "2p" | cut -f 2 2> /dev/null ) + home: $( wpcli option get home 2> /dev/null ) + siteurl: $( wpcli option get siteurl 2> /dev/null ) + stylesheet: $( wpcli option get stylesheet 2> /dev/null ) + template: $( wpcli option get template 2> /dev/null ) " + + #harmless fix so we can use cut in a sec even if their quotes are jacked up + sed "s/[‘’]/'/g" -i ./wp-config.php + + dbprefix="$( grep "table_prefix" ./wp-config.php | cut -d \' -f 2 )" wpcli core is-installed || echo + wpcli db query "SHOW STATUS WHERE variable_name = 'Threads_running';" | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" + if [[ -z "$dbprefix" ]] && [ $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) -lt 1 ]; then + echo 'Connected with no errors, but no tables that match specified prefix!' + fi + wpcli core verify-checksums 1> /dev/null } wpurl() @@ -447,12 +453,12 @@ wpurl() wpenv if [[ -z "$1" ]]; then - echo -e " + echo " home: $( wpcli option get home ) siteurl: $( wpcli option get siteurl ) " - elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then - echo -e "This tool returns the current URL settings in the database, or updates them to a specified URL. + elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then + echo "This tool returns the current URL settings in the database, or updates them to a specified URL. wpurl [URL] " @@ -474,9 +480,9 @@ wpht() { wpenv - if [[ -f ./.htaccess ]]; then - cp ./.htaccess ./.htaccess_"$( now )" - fi +# if [[ -f ./.htaccess ]]; then +# cp ./.htaccess ./.htaccess_"$( now )" +# fi #double check this struct="$( wpcli option get permalink_structure )" @@ -493,32 +499,37 @@ wpdb() { wpenv - #get some database variables from wp-config.php - if [[ -f "./wp-config.php" ]]; then - dbuser="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_USER");' )" - dbpass="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_PASSWORD");' )" - dbhost="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_HOST");' )" - dbname="$( php-cli -r 'require_once("./wp-config.php"); echo constant("DB_NAME");' )" - dbprefix="$( php-cli -r 'require_once("./wp-config.php"); echo "$table_prefix";' )" - else - echo "Unable to locate the wp-config.php file, attempting to continue..." - fi - if [[ -z "$1" ]]; then - echo -e " + #get some database variables from wp-config.php + if [[ -f "./wp-config.php" ]]; then + #harmless fix so we can use cut in a sec even if their quotes are jacked up + sed "s/[‘’]/'/g" -i ./wp-config.php + + dbuser="$( grep "DB_USER" ./wp-config.php | cut -d \' -f 4 )" + dbpass="$( grep "DB_PASSWORD" ./wp-config.php | cut -d \' -f 4 )" + dbhost="$( grep "DB_HOST" ./wp-config.php | cut -d \' -f 4 )" + dbname="$( grep "DB_NAME" ./wp-config.php | cut -d \' -f 4 )" + dbprefix="$( grep "table_prefix" ./wp-config.php | cut -d \' -f 2 )" + else + echo "Unable to locate the wp-config.php file, attempting to continue..." + fi + + echo " DB user: $dbuser DB pass: $dbpass DB host: $dbhost DB name: $dbname DB prefix: $dbprefix " + wpcli core is-installed || echo wpcli db query "SHOW STATUS WHERE variable_name = 'Threads_running';" | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" - if [ $( wpcli db tables | egrep -c "^$dbprefix" ) -lt 1 ]; then + if [[ -z "$dbprefix" ]] && [ $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) -lt 1 ]; then echo 'Connected with no errors, but no tables that match specified prefix!' fi - - elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then + elif [[ "$1" == "update-db" ]]; then + wpcli core update-db + elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then echo " cli Open a mysql console using the WordPress credentials. create Create the database, as specified in wp-config.php @@ -530,8 +541,11 @@ wpdb() repair Repair the database. reset Remove all tables from the database. tables List the database tables. + update-db Update the WordPress database. " return + elif [[ "$1" == "help" && -n "$2" ]]; then + wpcli help db "$@" else wpcli db "$@" fi @@ -541,8 +555,8 @@ wpver() { wpenv - if [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then - echo -e " + if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then + echo " This tool returns the current install's version. " return @@ -563,9 +577,8 @@ wpuser() echo wpcli user list echo - return - elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then - echo -e " + elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then + echo " This tool performs various user functions, including returning info for a specified user, changing usernames, passwords, changing a user to an admin, creating new admin users, and deleting users. @@ -603,7 +616,8 @@ remove-role Remove a user's role. set-role Set the user role (for a particular blog). update Update a user. " - return + elif [[ "$1" == "help" && -n "$2" ]]; then + wpcli help user "$@" elif [[ "$2" == "-u" ]]; then #Yes, I know this gives a warning and does not work. I'm assuming there's a reason for that warning, #and not implementing a workaround because I'm also assuming that the reason is a good one. Rather @@ -611,21 +625,16 @@ update Update a user. #show users that it's not a good idea to update the username. This option is not in the help text #and should be considered deprecated; it is included only for legacy purposes. wpcli user update "$1" --user_login="$3" - return elif [[ "$2" == "-p" ]]; then wpcli user update "$1" --user_pass="$3" - return elif [[ "$2" == "-a" ]]; then wpcli user add-role "$1" administrator - return elif [[ "$2" == "-d" ]]; then if [[ -n "$3" ]]; then wpcli user delete "$1" --reassign="$3" else wpcli user delete "$1" fi - - return elif [[ "$1" == "-n" || "$1" == "new" ]]; then echo @@ -655,14 +664,10 @@ update Update a user. unset password echo - return elif [[ -z "$2" ]]; then wpcli user get "$1" - return else - #pipe output to sed to fix usage text, but this breaks read prompts like in wpcli user delete :( - wpcli user "$@" # | sed "s|wp user|wpuser|g" - return + wpcli user "$@" fi } @@ -674,9 +679,8 @@ wpplug() echo wpcli plugin status echo - return - elif [[ "$1" == "--help" || "$1" =~ -[hH] || "$1" == "help" ]]; then - echo -e " + elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then + echo " Basic plugin functions. -a, activate [--all] Activate one or more plugins. @@ -693,7 +697,8 @@ Basic plugin functions. uninstall Uninstall a plugin. -u, update [--all] Update one or more plugins. " - return + elif [[ "$1" == "help" && -n "$2" ]]; then + wpcli help user "$@" elif [[ "$1" == "-d" ]] || [[ "$1" == "deactivate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then active_plugins=( $( wpcli plugin list --status=active --fields=name | sed -n "2,$ p" ) ) if [[ -z "${active_plugins[@]}" ]]; then @@ -719,15 +724,13 @@ Basic plugin functions. elif [[ "$1" == "-u" ]] || [[ "$1" == "update" && "$2" == "-all" ]]; then wpcli plugin update --all else - #pipe output to sed to fix usage text, but this breaks read prompts like in wpcli user delete :( - wpcli plugin "$@" # | sed "s|wp user|wpuser|g" - return + wpcli plugin "$@" fi } wphelp() { - echo -e " + echo " The following are bash functions that call /usr/bin/wp to administer Wordpress installs. It assumes you are running said functions in the site's root folder. Most commands listed below have a -h option for more specific information: From a4a118cd7bb055cdf5a07c8a5e8ba38f6ad03653 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Wed, 29 Apr 2015 23:11:16 -0600 Subject: [PATCH 07/24] Update wpfools.sh --- wpfools/wpfools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 5c1d579..b80c306 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -422,7 +422,7 @@ wpstats() available_version="$( wpcli core check-update --field=version | egrep -o $version_regex )" wp_version="$( wpcli core version )" - if [[ -z "$available_version" ]]; then + if [[ -n "$available_version" ]]; then version="$wp_version ($available_version available)" else version="$wp_version" From 0f53762047a242d4bfed1dc6f9f290696cdf50de Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Wed, 29 Apr 2015 23:27:17 -0600 Subject: [PATCH 08/24] Update wpfools.sh --- wpfools/wpfools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index b80c306..47a2aa8 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -420,7 +420,7 @@ wpstats() { wpenv - available_version="$( wpcli core check-update --field=version | egrep -o $version_regex )" + available_version="$( wpcli core check-update --field=version | egrep -m 1 -o $version_regex )" wp_version="$( wpcli core version )" if [[ -n "$available_version" ]]; then version="$wp_version ($available_version available)" From 401a4acc16b6caee72b87fe1385721af3033843b Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Thu, 30 Apr 2015 01:07:05 -0600 Subject: [PATCH 09/24] Second draft complete >Ready for some basic QA, then push to master --- wpfools/wpfools.sh | 191 +++++++++++++++++++++++++++++---------------- 1 file changed, 125 insertions(+), 66 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 47a2aa8..f3646c2 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -41,7 +41,6 @@ # ---------------------------- # # > wpht() should be fixed once the feature gets implemented -# > wpfix() needs QA # # # @@ -92,7 +91,7 @@ wpcore() wpenv #clean up cache, this is required because there's a bug that causes update to fail when it tries using a cached file - rm -rf /home2/"$(whoami)"/.wp-cli/cache/core/* + rm -rf ~/.wp-cli/cache/core/* #Display help information helpText() @@ -237,14 +236,14 @@ version Display the WordPress version. default="localhost" unset dbhost - read -rp "Password [$default]: " dbhost + read -rp "Hostname [$default]: " dbhost if [[ -z "$dbhost" ]]; then dbhost="$default" fi - default="_wp" + default="wp_" unset dbprefix - read -rp "Password [$default]: " dbprefix + read -rp "Table prefix [$default]: " dbprefix if [[ -z "$dbprefix" ]]; then dbprefix="$default" fi @@ -276,6 +275,11 @@ version Display the WordPress version. # databaseVersion elif [[ "$arg" =~ $version_regex ]]; then selectedVersion + elif [[ "$arg" =~ [[:digit:]] ]]; then + echo 'Unknown Wordpress version specified!' + echo "Wordpress versions can be either #.# or #.#.#" + helpText + return 9 elif [[ "$arg" == "latest" || -z "$arg" ]]; then latestVersion elif [[ "$arg" == "config" ]]; then @@ -348,7 +352,26 @@ wpfix() wpenv if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then - echo "This tool runs various built-in Wordpress functions and fixes." + echo " + This tool runs various built-in Wordpress functions and fixes. Running this command by + by itself runs some safe fixes. There are also some unsafe fixes listed below. It is + recommended that you know what you're doing before you run these, and have a backup. + + Usage: wpfix --hard # + + Unsafe Fixes + ============ + [all] Prompt for all options + [0] Rewrite htaccess file + [1] Reset all roles to default capabilities + [2] Regenerate all thumbnail images + [3] Update all plugins + [4] Update all themes + [5] Update to latest WordPress version + [6] Delete all transients + [7] Delete all comments that have been marked as spam + [8] Delete all comments that have not been approved + " return 0 fi #not built in, but solves more problems than you'd think @@ -363,55 +386,92 @@ wpfix() ###HARD FIXES### - #would be good to get a menu going if [[ "$1" == "--hard" ]]; then + if [[ -z "$2" ]]; then + echo + echo "No option given, prompting for all." + ans="all" + else + ans="$2" + fi + yes="^[yY][eE]?[sS]?$" - echo "For the following question, the default answer is no." - echo "It is recommended that you know what you're doing before you run these, and have a backup." - unset response - read -rp "Rewrite htaccess file? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - wpht - unset response - fi - read -rp "Reset all roles to default capabilities? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - wpcli role reset --all - unset response - fi - wpcli media regenerate --yes #prompts on its own - read -rp "Update all plugins? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - wpcli plugin update --all - unset response - fi - read -rp "Update all themes? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - wpcli theme update --all - unset response - fi - read -rp "Update to latest WordPress version? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - wpcli core update - unset response - fi - read -rp "Delete all transients? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - wpcli transient delete-all - unset response - fi - read -rp "Delete all comments that have been marked as spam? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - #delete spam comments - wp comment delete $( wp comment list --status=spam --format=ids ) - unset response - fi - read -rp "Delete all comments that have not been approved? [y/n]: " response - if [[ "$response" =~ $yes ]]; then - #delete unapproved comments - wp comment delete $( wp comment list --status=unapproved --format=ids ) - unset response + fix0() + { + read -rp "Rewrite htaccess file? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpht + fi + } + fix1() + { + read -rp "Reset all roles to default capabilities? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli role reset --all + fi + } + fix2() + { + wpcli media regenerate #prompts on its own + } + fix3() + { + read -rp "Update all plugins? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli plugin update --all + fi + } + fix4() + { + read -rp "Update all themes? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli theme update --all + fi + } + fix5() + { + read -rp "Update to latest WordPress version? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli core update + fi + } + fix6() + { + read -rp "Delete all transients? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + wpcli transient delete-all + fi + } + fix7() + { + read -rp "Delete all comments that have been marked as spam? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + #delete spam comments + wp comment delete $( wp comment list --status=spam --format=ids ) + fi + } + fix8() + { + read -rp "Delete all comments that have not been approved? [y/n]: " response + if [[ "$response" =~ $yes ]]; then + #delete unapproved comments + wp comment delete $( wp comment list --status=unapproved --format=ids ) + fi + } + + echo + unset response + if [[ "$ans" == "all" ]]; then + echo "For the following questions, the default answer is no." + for (( i = 0; i <= 8; i++ )); do + unset response + fix"$i" + done + elif [[ "$ans" =~ [0-8] ]]; then + fix"$ans" + else + echo "Fix not listed." fi fi } @@ -427,14 +487,15 @@ wpstats() else version="$wp_version" fi - echo " - WP version: $version - user: $( wpcli user list --fields=id,user_login | sort -n | sed -n "2p" | cut -f 2 2> /dev/null ) - home: $( wpcli option get home 2> /dev/null ) - siteurl: $( wpcli option get siteurl 2> /dev/null ) - stylesheet: $( wpcli option get stylesheet 2> /dev/null ) - template: $( wpcli option get template 2> /dev/null ) - " + + echo + echo " WP version: $version" + echo " user: $( wpcli user list --fields=id,user_login | sort -n | sed -n "2p" | cut -f 2 2> /dev/null )" + echo " home: $( wpcli option get home 2> /dev/null )" + echo " siteurl: $( wpcli option get siteurl 2> /dev/null )" + echo " stylesheet: $( wpcli option get stylesheet 2> /dev/null )" + echo " template: $( wpcli option get template 2> /dev/null )" + echo #harmless fix so we can use cut in a sec even if their quotes are jacked up sed "s/[‘’]/'/g" -i ./wp-config.php @@ -442,7 +503,7 @@ wpstats() dbprefix="$( grep "table_prefix" ./wp-config.php | cut -d \' -f 2 )" wpcli core is-installed || echo wpcli db query "SHOW STATUS WHERE variable_name = 'Threads_running';" | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" - if [[ -z "$dbprefix" ]] && [ $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) -lt 1 ]; then + if [[ -z "$dbprefix" ]] && (( $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) < 1 )); then echo 'Connected with no errors, but no tables that match specified prefix!' fi wpcli core verify-checksums 1> /dev/null @@ -524,11 +585,9 @@ wpdb() wpcli core is-installed || echo wpcli db query "SHOW STATUS WHERE variable_name = 'Threads_running';" | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" - if [[ -z "$dbprefix" ]] && [ $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) -lt 1 ]; then + if [[ -z "$dbprefix" ]] && (( $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) < 1 )); then echo 'Connected with no errors, but no tables that match specified prefix!' fi - elif [[ "$1" == "update-db" ]]; then - wpcli core update-db elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then echo " cli Open a mysql console using the WordPress credentials. @@ -543,7 +602,8 @@ wpdb() tables List the database tables. update-db Update the WordPress database. " - return + elif [[ "$1" == "update-db" ]]; then + wpcli core update-db elif [[ "$1" == "help" && -n "$2" ]]; then wpcli help db "$@" else @@ -559,7 +619,6 @@ wpver() echo " This tool returns the current install's version. " - return elif [[ "$1" == "-q" ]]; then wpcli core version else From b62a227a0e9fd3f41437cb329de4d2ea6e779cd8 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Thu, 30 Apr 2015 01:18:20 -0600 Subject: [PATCH 10/24] bettery consistency in help text --- wpfools/wpfools.sh | 91 ++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index f3646c2..f5a7e06 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -30,7 +30,7 @@ # > 'wpstats' does not run tests on index.php or wp-admin/index.php # > wpuser -u does not work for reasons. # > wpver() does not get db version, and therefore wpcore() can't download db version #note, you can get db version with wpcli core version --extra, possibly implement db version later -# +# > more things # # ### @@ -97,11 +97,10 @@ wpcore() helpText() { echo " -This tool downloads the latest core, a new core of the current version, or a -specified version. - -Usage: - + This tool downloads the latest core, a new core of the current version, or a + specified version. + + Usage: wpcore [VERSION] @@ -113,21 +112,21 @@ Usage: -h display this help output -Additional features: -==================== -check-update Check for update via Version Check API. Returns latest version if there's an update, or empty if no update available. -config [--rebuild] Generate or attempt to rebuild a wp-config.php file. -download Download core WordPress files. -install Create the WordPress tables in the database. -is-installed Determine if the WordPress tables are installed. -language Modify or activate languages. -multisite-convert Transform a single-site install into a multi-site install. -multisite-install Install multisite from scratch. -update Update WordPress. -update-db Update the WordPress database. -verify-checksums Verify WordPress files against WordPress.org's checksums. -version Display the WordPress version. -" + Additional features: + ==================== + check-update Check for update via Version Check API. Returns latest version if there's an update, or empty if no update available. + config [--rebuild] Generate or attempt to rebuild a wp-config.php file. + download Download core WordPress files. + install Create the WordPress tables in the database. + is-installed Determine if the WordPress tables are installed. + language Modify or activate languages. + multisite-convert Transform a single-site install into a multi-site install. + multisite-install Install multisite from scratch. + update Update WordPress. + update-db Update the WordPress database. + verify-checksums Verify WordPress files against WordPress.org's checksums. + version Display the WordPress version. + " } ##TODO: fix the version stuff, sanitize @@ -638,12 +637,12 @@ wpuser() echo elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then echo " -This tool performs various user functions, including returning info for a specified -user, changing usernames, passwords, changing a user to an admin, creating new admin -users, and deleting users. -USERID can be the user login, user email, or actual user ID of the user(s) to update. - -Usage: + This tool performs various user functions, including returning info for a specified + user, changing usernames, passwords, changing a user to an admin, creating new admin + users, and deleting users. + USERID can be the user login, user email, or actual user ID of the user(s) to update. + + Usage: wpuser [param [option [param]]] USERID @@ -658,22 +657,22 @@ Usage: -n, new create new admin user -Additional features: -==================== -add-cap Add a capability for a user. -add-role Add a role for a user. -create Create a user. -delete Delete one or more users from the current site. -generate Generate users. -get Get a single user. -import-csv Import users from a CSV file. -list List users. -list-caps List all user's capabilities. -meta Manage user custom fields. -remove-cap Remove a user's capability. -remove-role Remove a user's role. -set-role Set the user role (for a particular blog). -update Update a user. + Additional features: + ==================== + add-cap Add a capability for a user. + add-role Add a role for a user. + create Create a user. + delete Delete one or more users from the current site. + generate Generate users. + get Get a single user. + import-csv Import users from a CSV file. + list List users. + list-caps List all user's capabilities. + meta Manage user custom fields. + remove-cap Remove a user's capability. + remove-role Remove a user's role. + set-role Set the user role (for a particular blog). + update Update a user. " elif [[ "$1" == "help" && -n "$2" ]]; then wpcli help user "$@" @@ -740,8 +739,6 @@ wpplug() echo elif [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then echo " -Basic plugin functions. - -a, activate [--all] Activate one or more plugins. -d, deactivate [--all] Deactivate one or more plugins. delete Delete plugin files. @@ -789,7 +786,7 @@ Basic plugin functions. wphelp() { - echo " + echo " The following are bash functions that call /usr/bin/wp to administer Wordpress installs. It assumes you are running said functions in the site's root folder. Most commands listed below have a -h option for more specific information: @@ -804,5 +801,5 @@ wphelp() wpcore: core replacement tools wpfix: built-in WP fixes wpver: returns version info -" + " } From 4a5ac05d4d719a27bbcbb1e1518545ab27a7d1a5 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Sat, 2 May 2015 00:06:17 -0600 Subject: [PATCH 11/24] Optimizations >wpenv now works in subdirectories of wp installs >colored text in wpfix db operations >wpver now detects versions in more scenarios >updateWordpress is better at detecting wordpress installs (and just in general) --- wpfools/wpfools.sh | 86 +++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index f5a7e06..f150f2e 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -47,36 +47,32 @@ ### -version_regex="\b([[:digit:]]\.[[:digit:]]{1,2}|[[:digit:]]\.[[:digit:]]\.[[:digit:]]{1,2})\b" -sha1_regex="\b[[:xdigit:]]{40}\b" - -#untested on old versions of wordpress +#set appropriate wp binary env wpenv() { - #set appropriate wp binary env - if [[ -f ./wp-includes/version.php ]]; then - wp_version="$( egrep -m 1 -o "$version_regex" ./wp-includes/version.php )" - #non-intuitive, but this checks if the version is greater than or equal to 3.5.2 - if [[ "$( echo -e "3.5.2\n$wp_version" | sort -V | head -n 1 )" == "3.5.2" ]]; then - #greater than or equal to 3.5.2 - wpcli() - { - /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" - } - else + #set wp_version if possible + wpver &> /dev/null + + if [[ "$wp_version" =~ $version_regex ]]; then + #non-intuitive, but this checks if the version is less than 3.5.2 + if [[ "$( echo -e "3.5.2\n$wp_version" | sort -V | head -n 1 )" != "3.5.2" ]]; then #less than 3.5.2 wpcli() { /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" } + return $? fi else + #assume new echo "Unable to detect Wordpress version, assuming > 3.5.2." - wpcli() - { - /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" - } fi + + #greater than or equal to 3.5.2 + wpcli() + { + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" + } } now() @@ -133,7 +129,7 @@ wpcore() #Download new set of files matching current file version fileVersion() { - version="$( wpcli core version )" + version="$( wpver -q )" } #Download new set of files matching current database version # databaseVersion() @@ -161,20 +157,16 @@ wpcore() updateWordpress() { #update if we're currently in a wordpress directory, download otherwise - #basic workaround for incorrectly detected wp installs - #see https://github.com/wp-cli/wp-cli/issues/1811 - if (( $( wp core is-installed &> /dev/null; echo $? ) == 0 )) && [[ -d ./wp-admin/ ]] && [[ -d ./wp-includes/ ]] && [[ -f ./wp-config.php ]]; then - if [[ "$version" == "latest" ]]; then - wpcli core update --force - else - wpcli core update --version="$version" --force - fi + if [[ -d ./wp-admin ]] && [[ -d ./wp-includes/ ]]; then + operation="update" else - if [[ "$version" == "latest" ]]; then - wpcli core download --force - else - wpcli core download --version="$version" --force - fi + operation="download" + fi + + if [[ "$version" == "latest" ]]; then + wpcli core "$operation" --force + else + wpcli core "$operation" --version="$version" --force fi } @@ -376,9 +368,12 @@ wpfix() #not built in, but solves more problems than you'd think sed "s/[‘’]/'/g" -i ./wp-config.php + ColorOff=$'\e[0m' # Text Reset + BGreen=$'\e[1;32m' # Bold Green + wpcli cache flush - wpcli db repair | grep -v "OK" - wpcli db optimize | grep -v "OK" + wpcli db repair | grep -v "OK" | sed "s/Success:/${BGreen}Success:${ColorOff}/g" + wpcli db optimize | grep -v "OK" | sed "s/Success:/${BGreen}Success:${ColorOff}/g" wpcli core update-db wpcli transient delete-expired wpcore config --rebuild @@ -612,17 +607,30 @@ wpdb() wpver() { - wpenv + unset wp_version + version_regex="\b([[:digit:]]\.[[:digit:]]{1,2}|[[:digit:]]\.[[:digit:]]\.[[:digit:]]{1,2})\b" + if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then echo " This tool returns the current install's version. " - elif [[ "$1" == "-q" ]]; then - wpcli core version + return 0 + fi + + if [[ -f ./wp-includes/version.php ]]; then + wp_version="$( egrep -m 1 -o "$version_regex" ./wp-includes/version.php )" + fi + if [[ ! "$wp_version" =~ $version_regex ]]; then + #have to call directly because we don't call wpenv in this function; if we do, we get a mean recursive case + wp_version="$( /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version )" + fi + + if [[ "$1" == "-q" ]]; then + echo "$wp_version" else echo " - WP version: $( wpcli core version ) + WP version: $wp_version " fi } From 09ecdd2eaef2b85f607b915153b0143bcee4acdb Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Fri, 8 May 2015 22:23:10 -0600 Subject: [PATCH 12/24] bugfixes > unset sensitive things better > fix for wptheme help install and other command-specific help > wptheme -u takes parameters better > wpplug -u / -a / -d take parameters better > wpuser -u / -a / -d take parameters better > new users are now named techsupport rather than deleteme --- wpfools/wpfools.sh | 117 ++++++++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 38 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index f150f2e..a4194e3 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -170,7 +170,7 @@ wpcore() fi } - #Rebuild / generate config config + #Rebuild / generate config buildConfig() { if [[ "$1" == "--rebuild" ]]; then @@ -249,8 +249,8 @@ wpcore() wpcli core config --dbname="$dbname" --dbuser="$dbuser" --dbpass="$dbpass" --dbhost="$dbhost" --dbprefix="$dbprefix" --skip-check &> /dev/null fi - unset dbpass fi + unset dbpass } #process user input @@ -258,7 +258,7 @@ wpcore() helpText return 0 elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help core "$@" + wpcli help core ${@:2} return $? elif [[ "$arg" == "cur" || "$arg" == "file" ]]; then fileVersion @@ -308,11 +308,11 @@ wptheme() -u, update [--all] Update one or more themes. use Install and activate a theme. - -s Set only stylesheet: wptheme -s twentyfifteen - -t Set only template: wptheme -t twentyfifteen + -s Set only stylesheet: wptheme -s twentyfifteen + -t Set only template: wptheme -t twentyfifteen " elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help theme "$@" + wpcli help theme ${@:2} elif [[ -z "$1" ]]; then echo wpcli theme status @@ -332,7 +332,11 @@ Details: elif [[ "$1" == "-t" ]]; then wpcli option update template "$2" elif [[ "$1" == "-u" ]]; then - wpcli theme update --all + if [[ -n "$2" ]]; then + wpcli theme update ${@:2} + else + wpcli theme update --all + fi else wpcli theme "$@" fi @@ -599,7 +603,7 @@ wpdb() elif [[ "$1" == "update-db" ]]; then wpcli core update-db elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help db "$@" + wpcli help db ${@:2} else wpcli db "$@" fi @@ -683,35 +687,60 @@ wpuser() update Update a user. " elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help user "$@" - elif [[ "$2" == "-u" ]]; then + wpcli help user ${@:2} + elif [[ "$1" == "-u" || "$2" == "-u" ]]; then #Yes, I know this gives a warning and does not work. I'm assuming there's a reason for that warning, #and not implementing a workaround because I'm also assuming that the reason is a good one. Rather #than not implementing this feature at all, I'm including the command that should work instead to #show users that it's not a good idea to update the username. This option is not in the help text #and should be considered deprecated; it is included only for legacy purposes. - wpcli user update "$1" --user_login="$3" - elif [[ "$2" == "-p" ]]; then - wpcli user update "$1" --user_pass="$3" - elif [[ "$2" == "-a" ]]; then - wpcli user add-role "$1" administrator - elif [[ "$2" == "-d" ]]; then + if [[ "$1" == "-u" ]]; then + login="$2" + username="$3" + elif [[ "$2" == "-u" ]]; then + login="$3" + username="$1" + fi + wpcli user update "$username" --user_login="$login" + elif [[ "$1" == "-p" || "$2" == "-p" ]]; then + if [[ "$1" == "-p" ]]; then + password"$2" + username="$3" + elif [[ "$2" == "-p" ]]; then + password"$3" + username="$1" + fi + wpcli user update "$username" --user_pass="$password" + elif [[ "$1" == "-a" || "$2" == "-a" ]]; then + if [[ "$1" == "-a" ]]; then + username="$2" + elif [[ "$2" == "-a" ]]; then + username="$1" + fi + wpcli user add-role "$username" administrator + elif [[ "$1" == "-d" || "$2" == "-d" ]]; then + if [[ "$1" == "-d" ]]; then + username="$2" + elif [[ "$2" == "-d" ]]; then + username="$1" + fi + if [[ -n "$3" ]]; then - wpcli user delete "$1" --reassign="$3" + wpcli user delete "$username" --reassign="$3" else - wpcli user delete "$1" + wpcli user delete "$username" fi elif [[ "$1" == "-n" || "$1" == "new" ]]; then echo - default="deleteme" + default="techsupport" unset username read -rp "Username [$default]: " username if [[ -z "$username" ]]; then username="$default" fi - default="deleteme@example.com" + default="support@example.com" unset email read -rp "Email [$default]: " email if [[ -z "$email" ]]; then @@ -728,13 +757,13 @@ wpuser() wpcli user create "$username" "$email" --role=administrator --user_pass="$password" fi - unset password echo elif [[ -z "$2" ]]; then wpcli user get "$1" else wpcli user "$@" fi + unset password } wpplug() @@ -762,31 +791,43 @@ wpplug() -u, update [--all] Update one or more plugins. " elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help user "$@" + wpcli help plugin ${@:2} elif [[ "$1" == "-d" ]] || [[ "$1" == "deactivate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then - active_plugins=( $( wpcli plugin list --status=active --fields=name | sed -n "2,$ p" ) ) - if [[ -z "${active_plugins[@]}" ]]; then - echo 'No plugins active!' + if [[ "$1" == "-d" ]] && [[ -n "$2" ]]; then + wpcli plugin deactivate ${@:2} else - wpcli plugin deactivate ${active_plugins[@]} + active_plugins=( $( wpcli plugin list --status=active --fields=name | sed -n "2,$ p" ) ) + if [[ -z "${active_plugins[@]}" ]]; then + echo 'No plugins active!' + else + wpcli plugin deactivate ${active_plugins[@]} + fi fi elif [[ "$1" == "-a" ]] || [[ "$1" == "activate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then - #The point of this is to check if someone ran a deactivate --all already, and if so, reactivate - #only the plugins that were deactivated the first time. Otherwise, activate all plugins. If you - #run this twice, it'll activate all plugins regardless. - inactive_plugins=( $( wpcli plugin list --status=inactive --fields=name | sed -n "2,$ p" ) ) - if [[ -z "${active_plugins[@]}" ]]; then - if [[ -n "${inactive_plugins[@]}" ]]; then - wpcli plugin activate ${inactive_plugins[@]} + if [[ "$1" == "-a" ]] && [[ -n "$2" ]]; then + wpcli plugin activate ${@:2} + else + #The point of this is to check if someone ran a deactivate --all already, and if so, reactivate + #only the plugins that were deactivated the first time. Otherwise, activate all plugins. If you + #run this twice, it'll activate all plugins regardless. + inactive_plugins=( $( wpcli plugin list --status=inactive --fields=name | sed -n "2,$ p" ) ) + if [[ -z "${active_plugins[@]}" ]]; then + if [[ -n "${inactive_plugins[@]}" ]]; then + wpcli plugin activate ${inactive_plugins[@]} + else + echo 'All plugins active!' + fi else - echo 'All plugins active!' + wpcli plugin activate ${active_plugins[@]} + unset active_plugins fi - else - wpcli plugin activate ${active_plugins[@]} - unset active_plugins fi elif [[ "$1" == "-u" ]] || [[ "$1" == "update" && "$2" == "-all" ]]; then - wpcli plugin update --all + if [[ "$1" == "-u" ]] && [[ -n "$2" ]]; then + wpcli plugin update ${@:2} + else + wpcli plugin update --all + fi else wpcli plugin "$@" fi From 1b196d135c7df17bde8fd85766dcb1fd0be539f2 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Sat, 9 May 2015 00:50:35 -0600 Subject: [PATCH 13/24] really small bugfixes > biggest thing in this small fix is wpuser() wouldn't run commands without an argument, `wpuser list` for example > second biggest fix: improved user input sanitization in wpfix() --- wpfools/wpfools.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index a4194e3..9732b5b 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -466,7 +466,7 @@ wpfix() unset response fix"$i" done - elif [[ "$ans" =~ [0-8] ]]; then + elif [[ "$ans" =~ ^[0-8]$ ]]; then fix"$ans" else echo "Fix not listed." @@ -479,7 +479,7 @@ wpstats() wpenv available_version="$( wpcli core check-update --field=version | egrep -m 1 -o $version_regex )" - wp_version="$( wpcli core version )" + wp_version="$( wpver -q 2> /dev/null )" if [[ -n "$available_version" ]]; then version="$wp_version ($available_version available)" else @@ -548,7 +548,7 @@ wpht() if [[ -n "$struct" ]]; then wpcli rewrite structure "$struct" --hard else - #remove everything between BEGIN and END + ##remove everything between BEGIN and END #sed -i '/# BEGIN WordPress/,/# END WordPress/ d' ./.htaccess sleep 0 fi @@ -643,6 +643,8 @@ wpuser() { wpenv + functions=" add-cap add-role create delete generate get import-csv list list-caps meta remove-cap remove-role set-role update " + if [[ -z "$1" ]]; then echo wpcli user list @@ -758,7 +760,8 @@ wpuser() fi echo - elif [[ -z "$2" ]]; then + elif [[ ! "$functions" =~ " $1 " ]]; then + #if an argument is passed and it is not one of the functions wpcli user get "$1" else wpcli user "$@" @@ -793,7 +796,7 @@ wpplug() elif [[ "$1" == "help" && -n "$2" ]]; then wpcli help plugin ${@:2} elif [[ "$1" == "-d" ]] || [[ "$1" == "deactivate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then - if [[ "$1" == "-d" ]] && [[ -n "$2" ]]; then + if [[ "$1" == "-d" && -n "$2" ]]; then wpcli plugin deactivate ${@:2} else active_plugins=( $( wpcli plugin list --status=active --fields=name | sed -n "2,$ p" ) ) @@ -804,7 +807,7 @@ wpplug() fi fi elif [[ "$1" == "-a" ]] || [[ "$1" == "activate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then - if [[ "$1" == "-a" ]] && [[ -n "$2" ]]; then + if [[ "$1" == "-a" && -n "$2" ]]; then wpcli plugin activate ${@:2} else #The point of this is to check if someone ran a deactivate --all already, and if so, reactivate @@ -823,7 +826,7 @@ wpplug() fi fi elif [[ "$1" == "-u" ]] || [[ "$1" == "update" && "$2" == "-all" ]]; then - if [[ "$1" == "-u" ]] && [[ -n "$2" ]]; then + if [[ "$1" == "-u" && -n "$2" ]]; then wpcli plugin update ${@:2} else wpcli plugin update --all From da2627e2978cc1012f6eec650dd092062177f33b Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Mon, 11 May 2015 17:41:19 -0600 Subject: [PATCH 14/24] Better help functionality, wpfix() more reliable > added help text for wptheme help use > aliased help text for wptheme help -u > wpfix() rebuilds config first, so that successive functions that require db connectivity have a better chance of being able to run > muted sed / grep in wpstats(), we don't care if it fails > fixed wpdb help update-db > aliased help text for wpplug -a, -d, -u --- wpfools/wpfools.sh | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 9732b5b..2d9f9ab 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -312,7 +312,21 @@ wptheme() -t Set only template: wptheme -t twentyfifteen " elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help theme ${@:2} + if [[ "$2" == "-u" ]]; then + wpcli help theme update ${@:3} + elif [[ "$2" == "use" ]]; then + echo " +Equivalent to the following: + wptheme install + wptheme activate + +It is safe to use this when the theme is already installed, as wptheme install +checks to see whether the theme is installed before attempting to install it. +This means uou can *use* this to activate themes that are already installed. + " + else + wpcli help theme ${@:2} + fi elif [[ -z "$1" ]]; then echo wpcli theme status @@ -375,12 +389,12 @@ wpfix() ColorOff=$'\e[0m' # Text Reset BGreen=$'\e[1;32m' # Bold Green + wpcore config --rebuild wpcli cache flush wpcli db repair | grep -v "OK" | sed "s/Success:/${BGreen}Success:${ColorOff}/g" wpcli db optimize | grep -v "OK" | sed "s/Success:/${BGreen}Success:${ColorOff}/g" wpcli core update-db wpcli transient delete-expired - wpcore config --rebuild ###HARD FIXES### @@ -496,9 +510,9 @@ wpstats() echo #harmless fix so we can use cut in a sec even if their quotes are jacked up - sed "s/[‘’]/'/g" -i ./wp-config.php + sed "s/[‘’]/'/g" -i ./wp-config.php 2> /dev/null - dbprefix="$( grep "table_prefix" ./wp-config.php | cut -d \' -f 2 )" + dbprefix="$( grep "table_prefix" ./wp-config.php 2> /dev/null | cut -d \' -f 2 )" wpcli core is-installed || echo wpcli db query "SHOW STATUS WHERE variable_name = 'Threads_running';" | grep "Threads_running" | sed "s|Threads_running|Active Connections:|g" if [[ -z "$dbprefix" ]] && (( $( wpcli db tables 2> /dev/null | egrep -c "^$dbprefix" ) < 1 )); then @@ -603,7 +617,11 @@ wpdb() elif [[ "$1" == "update-db" ]]; then wpcli core update-db elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help db ${@:2} + if [[ "$2" == "update-db" ]]; then + wpcli help core update-db ${@:3} + else + wpcli help db ${@:2} + fi else wpcli db "$@" fi @@ -794,7 +812,15 @@ wpplug() -u, update [--all] Update one or more plugins. " elif [[ "$1" == "help" && -n "$2" ]]; then - wpcli help plugin ${@:2} + if [[ "$2" == "-a" ]]; then + wpcli help plugin activate ${@:3} + elif [[ "$2" == "-d" ]]; then + wpcli help plugin deactivate ${@:3} + elif [[ "$2" == "-u" ]]; then + wpcli help plugin update ${@:3} + else + wpcli help plugin ${@:2} + fi elif [[ "$1" == "-d" ]] || [[ "$1" == "deactivate" && (( "$2" == "-all" || "$2" == "--all" )) ]]; then if [[ "$1" == "-d" && -n "$2" ]]; then wpcli plugin deactivate ${@:2} From 7357edf89ac85e4b836d64a0c6f84ad9f173c39d Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Tue, 12 May 2015 18:03:24 -0600 Subject: [PATCH 15/24] more flexible wpcore > in wpcore(), if update fails do download instead --- wpfools/wpfools.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 2d9f9ab..95da0f4 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -163,10 +163,21 @@ wpcore() operation="download" fi - if [[ "$version" == "latest" ]]; then - wpcli core "$operation" --force - else - wpcli core "$operation" --version="$version" --force + go() + { + if [[ "$version" == "latest" ]]; then + wpcli core "$operation" --force + else + wpcli core "$operation" --version="$version" --force + fi + } + + go + + if (( $? != 0 )) && [[ "$operation" == update ]]; then + echo "Trying another method..." + operation="download" + go fi } From 77cba4decdcc64afb5f193fdb669463748e22d60 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Tue, 12 May 2015 19:30:45 -0600 Subject: [PATCH 16/24] increase reliability > by adding skip-plugins and skip-themes to all commands, we can still run commands if themes / plugins are corrupted --- wpfools/wpfools.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 95da0f4..6e479ef 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -59,7 +59,7 @@ wpenv() #less than 3.5.2 wpcli() { - /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" + /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" --skip-plugins --skip-themes } return $? fi @@ -71,7 +71,7 @@ wpenv() #greater than or equal to 3.5.2 wpcli() { - /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" --skip-plugins --skip-themes } } @@ -645,9 +645,7 @@ wpver() if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then - echo " -This tool returns the current install's version. - " + wpcli help core version return 0 fi @@ -659,12 +657,14 @@ This tool returns the current install's version. wp_version="$( /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version )" fi - if [[ "$1" == "-q" ]]; then - echo "$wp_version" - else + if [[ -z "$1" ]]; then echo " WP version: $wp_version " + elif [[ "$1" == "-q" ]]; then + echo "$wp_version" + else + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version "$@" fi } From 1d8d3e8fff1b20b914f439b04b8ec503781968fa Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Tue, 12 May 2015 22:55:22 -0600 Subject: [PATCH 17/24] wpcore db is back :D > wpver() skips plugins / themes too > fileversion / databaseversion fail properly --- wpfools/wpfools.sh | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 6e479ef..27703a7 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -99,13 +99,15 @@ wpcore() Usage: wpcore [VERSION] - + download the latest stable version of the Wordpress core - #.#.# + #.#.# download version VERSION of the Wordpress core - cur + cur download new set of files matching current file version - -h + db + download new set of files matching current database version + -h display this help output Additional features: @@ -132,11 +134,19 @@ wpcore() version="$( wpver -q )" } #Download new set of files matching current database version -# databaseVersion() -# { -# version="$( wpver -q | awk '{print $3}' )" -# wpfile="wordpress-$version.tar.gz" -# } + databaseVersion() + { + dbVersion="$( wpver --extra | sed -n "/Database revision/ s/.* //p" )" + if [[ -n "$dbVersion" ]]; then + version="$( curl -Ss https://codex.wordpress.org/WordPress_Versions | grep "$dbVersion" -B 4 | egrep -o -m 1 "title=\"Version .*\"" | egrep -o "$version_regex" )" + if [[ "$version" =~ $version_regex ]]; then + return 0 + fi + fi + + echo "Unable to determine file version based on database version." + return 9 + } #Download new set of files matching user specified version selectedVersion() { @@ -272,9 +282,9 @@ wpcore() wpcli help core ${@:2} return $? elif [[ "$arg" == "cur" || "$arg" == "file" ]]; then - fileVersion - #elif [[ "$arg" == "db" || "$arg" == "database" ]]; then - # databaseVersion + fileVersion || return $? + elif [[ "$arg" == "db" || "$arg" == "database" ]]; then + databaseVersion || return $? elif [[ "$arg" =~ $version_regex ]]; then selectedVersion elif [[ "$arg" =~ [[:digit:]] ]]; then @@ -645,7 +655,7 @@ wpver() if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then - wpcli help core version + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp help core version --skip-plugins --skip-themes return 0 fi @@ -654,7 +664,7 @@ wpver() fi if [[ ! "$wp_version" =~ $version_regex ]]; then #have to call directly because we don't call wpenv in this function; if we do, we get a mean recursive case - wp_version="$( /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version )" + wp_version="$( /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version --skip-plugins --skip-themes )" fi if [[ -z "$1" ]]; then @@ -664,7 +674,7 @@ wpver() elif [[ "$1" == "-q" ]]; then echo "$wp_version" else - /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version "$@" + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp core version "$@" --skip-plugins --skip-themes fi } From 97d22bc68f25b71adf675397615a9fdcb9fc69b0 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Thu, 14 May 2015 21:10:51 -0600 Subject: [PATCH 18/24] wpcore config fix > now actually generates random passwords --- wpfools/wpfools.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 27703a7..2a60398 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -232,14 +232,14 @@ wpcore() dbname="$default" fi - default="$(whoami)_wp" + default="$dbname" unset dbuser read -rp "Username [$default]: " dbuser if [[ -z "$dbuser" ]]; then dbuser="$default" fi - default="strings /dev/urandom | egrep -o "[[:alnum:]]" | head -n 20 | tr -d "\n"" + default="$( strings /dev/urandom | egrep -o "[[:alnum:]]" | head -n 20 | tr -d "\n" )" unset dbpass read -rp "Password [$default]: " dbpass if [[ -z "$dbpass" ]]; then From 0ae94a189cfeb2e018949cce3c30cddc883f9a7b Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Thu, 14 May 2015 23:12:04 -0600 Subject: [PATCH 19/24] fix wpcli function for old wp skip-plugins and skip-themes doesn't actually work on old wpcli apparently --- wpfools/wpfools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 2a60398..3acad2e 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -59,7 +59,7 @@ wpenv() #less than 3.5.2 wpcli() { - /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" --skip-plugins --skip-themes + /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" } return $? fi From a455f4b2ddfd08c02c86acf96dc2663ad0943924 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Fri, 15 May 2015 18:11:08 -0600 Subject: [PATCH 20/24] wpuser -p works now > wpuser -p wasn't getting password input > also now prompts for password if you don't give it one --- wpfools/wpfools.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 3acad2e..f7bff56 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -744,14 +744,23 @@ wpuser() fi wpcli user update "$username" --user_login="$login" elif [[ "$1" == "-p" || "$2" == "-p" ]]; then - if [[ "$1" == "-p" ]]; then - password"$2" - username="$3" - elif [[ "$2" == "-p" ]]; then - password"$3" - username="$1" + if [[ -n "$3" ]]; then + if [[ "$1" == "-p" ]]; then + password="$2" + username="$3" + elif [[ "$2" == "-p" ]]; then + password="$3" + username="$1" + fi + else + if [[ "$1" == "-p" ]]; then + username="$2" + elif [[ "$2" == "-p" ]]; then + username="$1" + fi + read -rp "Password: " password fi - wpcli user update "$username" --user_pass="$password" + wpcli user update "$username" --user_pass="$password" elif [[ "$1" == "-a" || "$2" == "-a" ]]; then if [[ "$1" == "-a" ]]; then username="$2" From c71e2b4d1f5d8eb1d2986a3f86696c96241e83fc Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Thu, 4 Jun 2015 17:56:11 -0600 Subject: [PATCH 21/24] Add support for more paths of wordpress and phpcli --- wpfools/wpfools.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index f7bff56..d55c259 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -69,10 +69,22 @@ wpenv() fi #greater than or equal to 3.5.2 - wpcli() - { - /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" --skip-plugins --skip-themes - } + if [[ -f /usr/php/54/usr/bin/php-cli ]]; then + wpcli() + { + /usr/php/54/usr/bin/php-cli -c /etc/wp-cli/php.ini /usr/php/54/usr/bin/wp "$@" --skip-plugins --skip-themes + } + elif [[ -f /usr/bin/php-cli ]]; then + wpcli() + { + /usr/bin/php-cli /usr/php/54/usr/bin/wp "$@" --skip-plugins #--skip-themes + } + else + wpcli() + { + php-cli /usr/php/54/usr/bin/wp "$@" --skip-plugins --skip-themes + } + fi } now() From f2e4fd33fed31331a40806ab14cca19158a6d606 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Fri, 25 Sep 2015 15:37:18 -0600 Subject: [PATCH 22/24] handle curly double quotes > Small textual changes when replacing core files of the same version --- wpfools/wpfools.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index d55c259..3f687d5 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -179,7 +179,7 @@ wpcore() updateWordpress() { #update if we're currently in a wordpress directory, download otherwise - if [[ -d ./wp-admin ]] && [[ -d ./wp-includes/ ]]; then + if [[ -d ./wp-admin/ ]] && [[ -d ./wp-includes/ ]]; then operation="update" else operation="download" @@ -189,6 +189,10 @@ wpcore() { if [[ "$version" == "latest" ]]; then wpcli core "$operation" --force + elif [[ "$version" == "$( wpver -q )" ]]; then + ColorOff=$'\e[0m' # Text Reset + BGreen=$'\e[1;32m' # Bold Green + wpcli core "$operation" --version="$version" --force | sed -e 's|Updating to|Replacing files for|g' -e 's|Downloading update|Downloading package|g' -e 's|the update...|WordPress...|g' -e "s/Success:/${BGreen}Success:${ColorOff}/g" else wpcli core "$operation" --version="$version" --force fi @@ -213,8 +217,9 @@ wpcore() return 9 fi #harmless fix so we can use cut in a sec even if their quotes are jacked up - sed "s/[‘’]/'/g" -i ./wp-config.php + sed -e "s/[‘’]/'/g" -e "s/[“”]/\"/g" -i ./wp-config.php + #TODO: grep -m 1 "[^//]" dbuser="$( grep "DB_USER" ./wp-config.php | cut -d \' -f 4 )" dbpass="$( grep "DB_PASSWORD" ./wp-config.php | cut -d \' -f 4 )" dbhost="$( grep "DB_HOST" ./wp-config.php | cut -d \' -f 4 )" @@ -417,7 +422,7 @@ wpfix() return 0 fi #not built in, but solves more problems than you'd think - sed "s/[‘’]/'/g" -i ./wp-config.php + sed -e "s/[‘’]/'/g" -e "s/[“”]/\"/g" -i ./wp-config.php ColorOff=$'\e[0m' # Text Reset BGreen=$'\e[1;32m' # Bold Green @@ -543,7 +548,7 @@ wpstats() echo #harmless fix so we can use cut in a sec even if their quotes are jacked up - sed "s/[‘’]/'/g" -i ./wp-config.php 2> /dev/null + sed -e "s/[‘’]/'/g" -e "s/[“”]/\"/g" -i ./wp-config.php 2> /dev/null dbprefix="$( grep "table_prefix" ./wp-config.php 2> /dev/null | cut -d \' -f 2 )" wpcli core is-installed || echo @@ -609,7 +614,7 @@ wpdb() #get some database variables from wp-config.php if [[ -f "./wp-config.php" ]]; then #harmless fix so we can use cut in a sec even if their quotes are jacked up - sed "s/[‘’]/'/g" -i ./wp-config.php + sed -e "s/[‘’]/'/g" -e "s/[“”]/\"/g" -i ./wp-config.php dbuser="$( grep "DB_USER" ./wp-config.php | cut -d \' -f 4 )" dbpass="$( grep "DB_PASSWORD" ./wp-config.php | cut -d \' -f 4 )" @@ -814,7 +819,7 @@ wpuser() read -rp "Password [randomly generated]: " password if [[ -z "$password" ]]; then - wpcli user create "$username" "$email" --role=administrator + wpcli user create "$username" "$email" --role=administrator else wpcli user create "$username" "$email" --role=administrator --user_pass="$password" fi From 02abb4d4dd6453459a6977db4ae4a7ab55fd4e61 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Fri, 22 Jan 2016 23:08:49 -0700 Subject: [PATCH 23/24] Added support for wordpress 4.4 binary paths > hooray --- wpfools/wpfools.sh | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 3f687d5..5b94234 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -61,8 +61,14 @@ wpenv() { /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" } - return $? + elif [[ "$( echo -e "4.4\n$wp_version" | sort -V | head -n 1 )" == "4.4" ]]; then + #greater than or equal to 4.4 + wpcli() + { + /usr/php/54/usr/bin/php-cli /usr/local/bin/wp "$@" --skip-plugins --skip-themes + } fi + return $? else #assume new echo "Unable to detect Wordpress version, assuming > 3.5.2." @@ -97,6 +103,10 @@ wpcore() arg="$1" wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi #clean up cache, this is required because there's a bug that causes update to fail when it tries using a cached file rm -rf ~/.wp-cli/cache/core/* @@ -327,6 +337,11 @@ wpcore() wptheme() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi + if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ ]] || [[ "$1" == "help" && -z "$2" ]]; then echo " @@ -397,6 +412,10 @@ Details: wpfix() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi if [[ "$1" == "--help" || "$1" =~ ^-[hH]$ || "$1" == "help" ]]; then echo " @@ -529,6 +548,10 @@ wpfix() wpstats() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi available_version="$( wpcli core check-update --field=version | egrep -m 1 -o $version_regex )" wp_version="$( wpver -q 2> /dev/null )" @@ -562,6 +585,10 @@ wpstats() wpurl() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi if [[ -z "$1" ]]; then echo " @@ -590,6 +617,10 @@ wpurl() wpht() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi # if [[ -f ./.htaccess ]]; then # cp ./.htaccess ./.htaccess_"$( now )" @@ -609,6 +640,9 @@ wpht() wpdb() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + fi if [[ -z "$1" ]]; then #get some database variables from wp-config.php @@ -698,6 +732,10 @@ wpver() wpuser() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi functions=" add-cap add-role create delete generate get import-csv list list-caps meta remove-cap remove-role set-role update " @@ -837,6 +875,10 @@ wpuser() wpplug() { wpenv + if (( $? == 1 )); then + echo "Unable to set up, or locate, a proper wp-cli environment." + return 1 + fi if [[ -z "$1" ]]; then echo From 1190a2f2ae573a82879b0ebea6ec87ecb46f0519 Mon Sep 17 00:00:00 2001 From: compilingEntropy Date: Tue, 26 Jan 2016 17:54:26 -0700 Subject: [PATCH 24/24] Fix some path detection junk --- wpfools/wpfools.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wpfools/wpfools.sh b/wpfools/wpfools.sh index 5b94234..aa63b9f 100644 --- a/wpfools/wpfools.sh +++ b/wpfools/wpfools.sh @@ -61,20 +61,21 @@ wpenv() { /usr/php/54/usr/bin/php-cli /usr/php/54/usr/bin/wp-compat "$@" } + return $? elif [[ "$( echo -e "4.4\n$wp_version" | sort -V | head -n 1 )" == "4.4" ]]; then #greater than or equal to 4.4 wpcli() { /usr/php/54/usr/bin/php-cli /usr/local/bin/wp "$@" --skip-plugins --skip-themes } + return $? fi - return $? else #assume new echo "Unable to detect Wordpress version, assuming > 3.5.2." fi - #greater than or equal to 3.5.2 + #greater than or equal to 3.5.2, less than 4.4 if [[ -f /usr/php/54/usr/bin/php-cli ]]; then wpcli() {