Skip to content

Instantly share code, notes, and snippets.

@csalzano
Created November 19, 2025 20:16
Show Gist options
  • Select an option

  • Save csalzano/354c96407ecb1090a27683f239e6b416 to your computer and use it in GitHub Desktop.

Select an option

Save csalzano/354c96407ecb1090a27683f239e6b416 to your computer and use it in GitHub Desktop.
Shell script. Creates WordPress plugin zip files ready for distribution.
#!/usr/local/bin/bash
#
# plugin-zipper.sh
#
# Shell script. Creates WordPress plugin zip files ready for distribution.
# version 1.1.0
# Corey Salzano <corey@breakfastco.xyz>
# perhaps a plugin directory name name was passed as the first argument
if [ -z "$1" ]
then
# ask the user to type in a site name
echo "Please enter a directory name/plugin slug:"
read slug
else
slug=$1
fi
# extract the version number from the plugin header comment by...
# - copying it to a WordPress installation
# - extract version number with wp-cli
# - delete the plugin copy
# remember the current directory.
dir=$(pwd)
# copy the plugin to a WordPress installation.
cp -r "${slug}" ~/sites/empty/wp-content/plugins
# extract the version number.
cd ~/sites/empty/
version_number="$(wp plugin get "${slug}" --field=version)"
# wp plugin delete "${slug}" --quiet
# go back to the original directory.
cd "${dir}"
# zip the directory.
# do not include .git directories, node_modules directories, or .DS_Store files.
if [ -n "$version_number" ]; then
# put the version number in the file name.
# plugin-slug-v1.0.0.zip
zip_filename="${slug}-v${version_number}.zip"
zip -qr "${zip_filename}" "${slug}" -x "/${slug}/*.git*" -x "/${slug}/node_modules/*" -x "/${slug}/*.DS_Store"
else
# no version number.
# plugin-slug.zip
zip_filename="${slug}.zip"
zip -qr "${zip_filename}" "${slug}" -x "/${slug}/*.git*" -x "/${slug}/node_modules/*" -x "/${slug}/*.DS_Store"
fi
echo "${zip_filename}"
@csalzano
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment