Created
November 19, 2025 20:16
-
-
Save csalzano/354c96407ecb1090a27683f239e6b416 to your computer and use it in GitHub Desktop.
Shell script. Creates WordPress plugin zip files ready for distribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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}" |
Author
csalzano
commented
Nov 19, 2025
- Using git archive could make this platform agnostic https://stackoverflow.com/a/28357990/338432
- Detect if the directory is a plugin or a theme
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment