Skip to content

Instantly share code, notes, and snippets.

@Ugarz
Last active January 19, 2018 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ugarz/8ab564a7ee480a7ff0019e18aa261dd9 to your computer and use it in GitHub Desktop.
Save Ugarz/8ab564a7ee480a7ff0019e18aa261dd9 to your computer and use it in GitHub Desktop.
I'm fed up of all wordpress magic ! So let's list some Wordpress tips and tricks to level up ! C'mon !

Bash Wordpress tips and tricks

Summary

  1. Bash tricks
    1. Require other bash scripts in a start.sh
  2. Wordpress Tips
    1. Install Wordpress (bash script)
    2. Update Wordpress permissions
    3. Bypass Wordpress Localhost FTP Connection Information
  3. Resources

1) Bash tricks

Require other bash scripts in a start.sh

Split your scripts in more files so that it is more maintanable.

#!/bin/sh
echo "----------------------------"
echo "----- Starting process -----"
echo "----------------------------"

THEME_NAME='beaver'

# Import vars
source $(dirname $0)/scripts/1-variables.sh
source $(dirname $0)/scripts/2-copy-theme.sh

echo "----------------------------"
echo "---------- End -------------"
echo "----------------------------"

2) Wordpress tips

Install Wordpress (bash script)

  • Create a folder mkdir myAwesomeSite && cd myAwesomeSite and switch into.
  • create a wp_install.sh
  • make it executable with chmod +x wp_install.sh
  • fill it with
#!/bin/bash
clear
echo "---------------------------------------------------"
echo "Warning: Enter the wanted Wordpress version"
echo "Example: 4.9.2"
echo "---------------------------------------------------"
read customVersion
stableVersion=4.9.1
lastestWp=""
finalVersion=""
wordpressPath="$( cd "$(dirname "$0")" ; pwd -P )"
if [ "$customVersion" ]; then
    echo "Custom version $customVersion, understood ✓"
    lastestWp="https://fr.wordpress.org/wordpress-$customVersion-fr_FR.tar.gz"
    finalVersion=$customVersion
else
    echo "No custom version, taking stable version !"
    lastestWp="https://fr.wordpress.org/wordpress-$stableVersion-fr_FR.tar.gz"
    finalVersion=$stableVersion
fi

function _clean {
  read -p "Do you approve a hard clean ? (will delete everything around the script), continue ? (y/n)" -n 1 -r
  echo    # (optional) move to a new line
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "Cleaning repository, please wait..."
    find . -not -name 'wp_install.sh' -delete
    echo "Repository Cleaned !"
  fi
}


function getWordpress {
  echo "Looking to the $1 version of Wordpress"
  COMPRESSED_WP=wordpress-$1-fr_FR.tar.gz
  echo "Checking if $COMPRESSED_WP exists in current folder"

  if [ -f $COMPRESSED_WP ]; then
      echo "$COMPRESSED_WP exists"
      echo "Extracting $COMPRESSED_WP, please wait.."
      tar -xf $COMPRESSED_WP
  else
      echo "$COMPRESSED_WP does not exists"
      echo "Downloading the v$finalVersion version of Wordpress"
      wget $lastestWp >/dev/null || curl -O  $lastestWp .
      echo "Extracting $COMPRESSED_WP, please wait.."
      tar -xf $COMPRESSED_WP
  fi

  echo "Removing wordpress folder"
  cp -R wordpress/* . && rm -rf wordpress

  echo "** Wordpress installed ! ✅ **"
  echo "Check it out on $wordpressPath"
}

_clean
getWordpress $finalVersion

echo "---- Script under GNU GPL is written by Ugo Arzur ---"
  • launch it with ./wp_install.sh

source stackoverwflow

source Get script path

source Check if file or folder is here

Update Wordpress permissions

This Little Script is Distributed by www.coding101.in and written by Akash S. Patel.

  • Tutorial on Youtube

  • Create a file wp_permissions.sh in your wordpress root directory.

  • Make it executable with chmod +x wp_permissions.sh.

  • Run the pwd to see the absolute path.

  • Run the script with ./wp_permissions.sh

  • Follow the instructions entering the absolute path and the recommended permissions by wordpress.

echo "---------------------------------------------------"
echo "Warning: Enter Your Wordpress path in proper format as Example shown below:"
echo "Example: var/www/html/wordpress/"
echo "---------------------------------------------------"
read path
echo "enter permission type d (default is 755)"
read perm1
echo "enter permission type f (default is 644)"
read perm2
sudo chown -R www-data:www-data $path
sudo find /$path -type d -exec chmod $perm1 {} \;
sudo find /$path -type f -exec chmod $perm2 {} \;
clear
echo "Done ! Now check wordpress upload/download of theme/plugin !"
echo "---------------------------------------------------"
echo "This Little Script is Distributed by www.coding101.in"
echo "Written by Akash S. Patel"
echo "---------------------------------------------------"

ps : Here another intresting resource even if I could not managed to use it.

Bypass Wordpress Localhost FTP Connection Information

Add the following line into wp-config.php:

define('FS_METHOD', 'direct');

3) Resources

English Ressources

French Ressources

#!/bin/bash
clear
echo "---------------------------------------------------"
echo "Warning: Enter the wanted Wordpress version"
echo "Example: 4.9.2"
echo "---------------------------------------------------"
read customVersion
stableVersion=4.9.1
lastestWp=""
finalVersion=""
wordpressPath="$( cd "$(dirname "$0")" ; pwd -P )"
if [ "$customVersion" ]; then
echo "Custom version $customVersion, understood ✓"
lastestWp="https://fr.wordpress.org/wordpress-$customVersion-fr_FR.tar.gz"
finalVersion=$customVersion
else
echo "No custom version, taking stable version !"
lastestWp="https://fr.wordpress.org/wordpress-$stableVersion-fr_FR.tar.gz"
finalVersion=$stableVersion
fi
function _clean {
read -p "Do you approve a hard clean ? (will delete everything around the script), continue ? (y/n)" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Cleaning repository, please wait..."
find . -not -name 'wp_install.sh' -delete
echo "Repository Cleaned !"
fi
}
function getWordpress {
echo "Looking to the $1 version of Wordpress"
COMPRESSED_WP=wordpress-$1-fr_FR.tar.gz
echo "Checking if $COMPRESSED_WP exists in current folder"
if [ -f $COMPRESSED_WP ]; then
echo "$COMPRESSED_WP exists"
echo "Extracting $COMPRESSED_WP, please wait.."
tar -xf $COMPRESSED_WP
else
echo "$COMPRESSED_WP does not exists"
echo "Downloading the v$finalVersion version of Wordpress"
wget $lastestWp >/dev/null || curl -O $lastestWp .
echo "Extracting $COMPRESSED_WP, please wait.."
tar -xf $COMPRESSED_WP
fi
echo "Removing wordpress folder"
cp -R wordpress/* . && rm -rf wordpress
echo "** Wordpress installed ! **"
echo "Check it out on $wordpressPath"
}
_clean
getWordpress $finalVersion
echo "---- Script under GNU GPL, written by Ugo Arzur ---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment