This post is intended to document the steps to publish or update a WordPress plugin for developers who have never done it before. WordPress has a nice and more complete guide on how to use Subversion if you want to learn more after reading this intro.
To create this post I also created a WordPress plugin called Honking Goose. Check it out, it’s ridiculous! 💙
Checking out the repository
Once WordPress tests and accepts your plugin, you can checkout the empty svn repository at the URL they send you by email. In my case:
svn co http://plugins.svn.wordpress.org/honking-goose/ honking-goose
You will get something like this:
➜ svn svn co http://plugins.svn.wordpress.org/honking-goose/ honking-goose
A honking-goose/assets
A honking-goose/branches
A honking-goose/tags
A honking-goose/trunk
Checked out revision 2183506.
If you ls
on the plugin directory you will see the new folders created:
assets branches tags trunk
Making svn ignore the .git directory
My ideal plugin workflow is to have the git repository in the trunk folder. In this way, I can work on branches on git, and when I am done and sure that my code works, I can merge everything to master
and commit the changes to svn
.
// Cloning master to trunk
➜ trunk git clone https://github.com/imgerson/honking-goose.git .
Cloning into '.'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
➜ honking-goose cd ..
// Seeing what's new
➜ honking-goose svn st
? trunk/.git
? trunk/LICENSE
? trunk/goose.mp3
? trunk/honking-goose.js
? trunk/honking-goose.php
? trunk/readme.txt
The only problem with this approach is that svn shows the .git subdirectory as untracked too. Here’s what I did to make svn ignore the .git folder:
// Telling svn to ignore the '.git' directory inside trunk
➜ honking-goose svn propset svn:ignore '.git' trunk
property 'svn:ignore' set on 'trunk'
// Verifying everything is good
➜ honking-goose svn st
M trunk
? trunk/LICENSE
? trunk/goose.mp3
? trunk/honking-goose.js
? trunk/honking-goose.php
? trunk/readme.txt
svn is now ignoring the .git folder completely, but now it shows the trunk
folder as modified. AFAIK this is fine.
Adding the code
➜ honking-goose svn add trunk/*
A trunk/LICENSE
A (bin) trunk/goose.mp3
A trunk/honking-goose.js
A trunk/honking-goose.php
A trunk/readme.txt
Creating the new tag
➜ honking-goose svn cp trunk tags/1.0
A tags/1.0
➜ honking-goose ls tags
1.0
➜ honking-goose ls tags/1.0
LICENSE honking-goose.js readme.txt
goose.mp3 honking-goose.php
Committing to the WordPress repository
Note: Always double check the changes you’re about to commit with svn stat
or its shorter version svn st
. Once you commit the changes to svn
, these will be deployed to wordpress.org. You should only commit to svn
when you’re fully ready to go live.
➜ honking-goose svn st
A + tags/1.0
A tags/1.0/LICENSE
A tags/1.0/goose.mp3
A tags/1.0/honking-goose.js
A tags/1.0/honking-goose.php
A tags/1.0/readme.txt
M trunk
A trunk/LICENSE
A trunk/goose.mp3
A trunk/honking-goose.js
A trunk/honking-goose.php
A trunk/readme.txt
Everything looks good to go and ready be deployed (committed in svn
terms). Here’s how to:
➜ honking-goose svn ci -m '1.0' --username username
I got an error with the following message:
... Use your WordPress.org login
Password for 'username': ***
Adding tags/1.0
Adding tags/1.0/LICENSE
Adding (bin) tags/1.0/goose.mp3
Adding tags/1.0/honking-goose.js
Adding tags/1.0/honking-goose.php
Adding tags/1.0/readme.txt
Sending trunk
Adding trunk/LICENSE
Adding (bin) trunk/goose.mp3
Adding trunk/honking-goose.js
Adding trunk/honking-goose.php
Adding trunk/readme.txt
Transmitting file data ..........done
Committing transaction...
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
Please provide commit message that describes the changes you are making.
Oops. It looks like the commit message wasn’t what WordPress was expecting. If you get this error, try again with a longer commit message, such as:
➜ honking-goose svn ci -m 'Adding version 1.0' --username username
Success! Here’s what WordPress says about the release:
➜ honking-goose svn ci -m 'Adding version 1.0' --username username
Adding tags/1.0
Adding tags/1.0/LICENSE
Adding (bin) tags/1.0/goose.mp3
Adding tags/1.0/honking-goose.js
Adding tags/1.0/honking-goose.php
Adding tags/1.0/readme.txt
Sending trunk
Adding trunk/LICENSE
Adding (bin) trunk/goose.mp3
Adding trunk/honking-goose.js
Adding trunk/honking-goose.php
Adding trunk/readme.txt
Transmitting file data ..........done
Committing transaction...
Committed revision 2183514.
That’s it. The release is out! You can expect an email from WordPress with a diff of the changes.
PS. The next thing that I want to try is updating a WordPress plugin through GitHub actions.
Security Considerations
Always make sure to use strong credentials to guard your wordpress.org account, if this account is hacked, it’s direct access to the people using your plugin and their websites — especially if they have auto-updates on.
Also remember not to include any sensible files/directories in your plugin releases: .git, .env, .sh, etc. Or any annoying ones, such as the .DS_Store
.
That being said, happy code sharing! 😉