Skip to content

Instantly share code, notes, and snippets.

@jikamens
Created January 20, 2026 14:00
Show Gist options
  • Select an option

  • Save jikamens/9037496f01a4343578167a99a7ec78e6 to your computer and use it in GitHub Desktop.

Select an option

Save jikamens/9037496f01a4343578167a99a7ec78e6 to your computer and use it in GitHub Desktop.
script to toggle WordPress permissions before and after updates
#!/bin/bash -e
TOPDIR=FILLMEIN
OWNER=FILLMEIN
DIRS="
wp-content/plugins/wordfence/tmp
wp-content/uploads
wp-content/wfcache
wp-content/wflogs
wp-content/cache
wp-content/upgrade-temp-backup
"
### END CONFIG
if [ $(id -u) != 0 ]; then
sudo=sudo
fi
cd $TOPDIR
case "$1" in
lock)
$sudo chown -R $OWNER.$OWNER .
$sudo chmod -R a+rX .
$sudo chown -R apache.apache $DIRS
$sudo chmod -R u+w,g+w $DIRS
$sudo find $DIR -type d -print0 | $sudo xargs -0 chmod g+s
;;
unlock)
$sudo chown -R apache .
;;
*)
echo "Specify 'lock' or 'unlock'" 1>&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment