When working on a WordPress Theme, I find one thing very tedious : repacking the theme.zip archive, making sure all paths within the zip file are correct, then upload and replace the archive. Doing this every time I make the slightest modification to a file ("doh ? typo in a .css ?") was too unbearable not to come up with a smart and lazy way to manage this task :)
The 3 line explanation (aka "WTF?")
- I have a theme directory : ozh/wp-content/themes/fake-theme
- I'm too lazy to maintain, update, upload a zip file of the theme each time I modify the .css or anything else.
- One PHP script creates the zip file ready for download : fake-theme.zip…
- … or displays a list of the theme files
Ok, I lied, that's 4 lines.
WordPress Theme Zip creates zip files for you
The script generates on the fly a zip archive from an actual WordPress theme on your blog. Upload your theme, and no longer mind about updating your theme.zip if you ever happen to modify something in it.
For example, I've created a (broken and fake) theme, named Faked Theme, which actually sits into my wp-content/themes directory. It's populated with various useless files in nonsense subdirectories for a demo purpose.
- â”‚ â”‚ fake-archive.txt.zip
- â”‚ â”‚ fake.js
- â”‚ â”‚ porn.php
- â”‚ â”‚ random.php
- â”‚ â”‚ readme.txt
- â”‚ â”‚ sample.css
- â”‚ â”‚
- â”‚ â”œâ”€â”€â”€images
- â”‚ â”‚ addpluck.png
- â”‚ â”‚ xml.gif
- â”‚ â”‚
- â”‚ â””â”€â”€â”€very
- â”‚ â””â”€â”€â”€deep
- â”‚ â””â”€â”€â”€subdir
- â”‚ deep.txt
Now that I explained why I'm too lazy to pack it as a ready-for-use zip file, I'm just linking to a copy of the WordPress Theme Zip script : fake-theme.zip.
You'll notice that a suffix is automatically appended to the zip filename, here with date format "yyyymmdd". It's a customizable option that allows easy file update tracking.
Another customizable feature is that the script can list files the zip contains, so that users don't need to download anything if they just want to see what's inside, or what file has changed since they downloaded it : list fake-theme.zip content.
I made things so that the listing is more or less as usable as your destkop WinZip or similar software : you can sort columns by clicking on headers, and you can view files from within the archive by clicking on their filenames. Text files (php, htm, txt, js and css by default) and images (gif, jpg and png) are shown right into the browser, any other extension is not displayed.
(A note about column sorting : while it seems to be working fine with numbers, it sometimes sorts strings a bit weirdly. Ho well, it's just here to make things prettier, but it's not *that* useful anyway :)
Download WordPress Theme Zip
Get the script while it's hot :
- wordpress-theme-zip.txt (download and save as .php)
- wordpress-theme-zip.php (highlighted code, copy and paste in a blank file, but do not download as is)
Configure and use
You used to have something like yourtheme.zip in a download directory. Delete your regular zip archive, replace it with a copy of the WordPress Theme Zip script and give it a name that will make the user think it is a regular archive : yourtheme.zip.php for example (remember, it's still a PHP script, don't forget the PHP extension)
Now configure a very few options at the beginning of the script :
This is the name of the theme directory you want to zip. This must be a real directory name from your wp-content/themes/ directory, such as "classic" or "default".
Put here a page URL that will be displayed in the footer of the archive file list, so that users that would land directly on the list from a search engine or any other referral would be able to find their way to your theme page or to your blog.
These two options are the mandatory options you need to edit every time you will make a copy of the script (one copy for each theme you want to make available for download)
The next options are more general stuff you won't change too often, if more than once.
This string is a suffix that is automatically appended to generated zip files, and uses PHP's date() syntax.
For example, with $ziptheme['theme_name'] = 'classic',
- $ziptheme['datesuffix'] = " → classic.zip
- $ziptheme['datesuffix'] = 'Ymd' → classic-20051224.zip
- $ziptheme['datesuffix'] = 'Y-m-d-H-i-s' → classic-2005-12-22-03-34-55.zip
- $ziptheme['datesuffix'] = '\a\l\p\h\aY' → classic-alpha2005.zip
Put here the physical path to phpZIP class file, e.g. /home/you/lib/zipfile/ss_zip.class.php
This is the physical path — not URL — of your Themes directory, e.g. /home/you/wordpress/wp-content/themes. No trailing slash please.
This is the URL of your blog, something like http://yourblog.com/wordpress. No trailing slash please.
If for some reason you don't want people to be able to list files by adding ?list=1 to your archive, set this variable to 0 (zero). Leave to 1 (one) otherwise.
Similarly, set this one to 0 (zero) to disable file preview. This option needs $ziptheme['enable_report']
to be set, of course.
$ziptheme['textfiles'] and $ziptheme['imagefiles']
Each of these two options contains an array of common file extension that can be printed in a browser window, i.e. txt, php, htm, html, css, js, xml for text files, and gif, png, jpg for images.
You shouldn't really have to modify this, but the option is here just in case.
While this is not a option as such, you can easily customize the CSS presentation of listings and file viewing. You simply need to edit the very last function of the script, which outputs the CSS declaration.
A word about security
I'm rather confident that my script is absolutely secure regarding access to arbitrary files, and enabling the file list feature or file preview won't compromise your web host security. You cannot see any file outside your theme directory with tricks like ?view=../../../etc/password and such. Since you "hardcode" the directory path in the script itself and do not pass it as an argument, things will be fine.
And if you are of the paranoÃ¯d kind, you can still disable the file listing and viewing options.
Positive feedback, praise trackbacks, love letters and clicking sprees on my PayPal "Donate" button are strongly encouraged, as usual. But if you just have a question or want to report a bug, well, that's possible too :)
Want to share or tweet this page? Please use this short URL: http://ozh.in/lf