On: 2005/12/23 Viewed: 26838 times
Shorter URL for this page: http://ozh.in/lf

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.

  1. ├───fake-theme
  2. │   │   fake-archive.txt.zip
  3. │   │   fake.js
  4. │   │   porn.php
  5. │   │   random.php
  6. │   │   readme.txt
  7. │   │   sample.css
  8. │   │
  9. │   ├───images
  10. │   │       addpluck.png
  11. │   │       xml.gif
  12. │   │
  13. │   └───very
  14. │       └───deep
  15. │           └───subdir
  16. │                   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 :

The script uses Smiled Soft's phpZIP (the free version), a PHP class to create zip files. Download phpZIP and put it anywhere on your web server (it's actually one 9kb file named ss_zip.class.php)

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.

CSS style
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 :)

Shorter URL

Want to share or tweet this page? Please use this short URL: http://ozh.in/lf


This page "WordPress Theme Zip" was posted on 23/12/2005 at 3:33 pm
Watch this discussion : Comments RSS 2.0.

3 Blablas

  1. […] WordPress Theme Zip: easiest (and laziest) way to generate a zip archive from a WordPress Theme that is being worked on, so you don't have to manually create, update and upload a new zip file every time you modify a file in it. Technorati Tags: php wordpress wordpress hack wordpress theme   […]

  2. Hello.
    Very useful this plugin.
    Thank you!

  3. Dj Flush says:

    Do you have any script that can do the same but for ANY directory?

    I mean create a Zip file for any folder on my web server to download it?

    please contact me its important flush.dj[at]gmail.com

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.