WordPress plugin: NextGen DrainHole Compatibility Functions

April 21st, 2010
This plugin turned out to be overkill. The problem that I attempted to solve with this plugin has to do with the .htaccess file that Drain Hole suggests. It assumes that the Apache module mod_rewrite is around. Turns out it is not in my case. If you have the same problem, it can be solved by providing another .htaccess file. See

Still, I let the plugin stay around here if someone prefers that solution.

This plugin provides a function to help combining the plugins NextGen and Drain Hole. Some additional tweaks have to be made by hand. See below.

Download NextGen DrainHole Compatibility Functions

NextGen is a really well thought through plugin handling image galleries. It has one obvious drawback though; It does not allow me to limit the access to the images. Granted, you can limit the access to pages displaying the images using WordPress user settings, but not the images themselves. If you have their URLs, you can still access them. I find this to be a major drawback to an otherwise fantastic plugin. And its author has stated a number of times that he will not supply that ability. Bummer!

Drain Hole is another well thought through plugin that among other things allows you to limit access based on wordpress user status, which is exactly what I wanted to have. It does a lot more if you want it to. For instance, it can generate link lists to folders. It has SVN capabilities, and probably a lot more that I have yet to find.

So, there is one good image gallery handler and one good access limitation provider. Good, then we combine them. Just install them and we’re off. Yeah, right! You could wish it would be that simple. It’s not. To be honest, nobody ever claimed that they were supposed to be compatible. The incompatibility is very simple, though, as far as I can see. It’s their file placements and URLs that do not fit, unless we adjust the way NextGen generates URLs. Therefore I have produced this dead simple plugin that, combined with adjustments to a few of the files in the NextGen plugin, does the trick. Replacement files are included in the download. Note that no files are replaced upon installation. You have to do that yourself following the instructions on this page.

If anyone know of a better way to accomplish this, I am all ears. I am fairly new to both WordPress and PHP. I am certainly not aware of all things that can be done with a plugin. It would be really nice if no files needed to be replaced.


  • Author: Mikael Olofsson
  • License: NiceWare
  • Plugin version: 0.1
  • WordPress version: Tested with: 2.9.2
  • Requires: NextGen and Drain Hole
  • Tested with Nextgen version: 1.5.2
  • Tested with Drain Hole version: 2.2.8


  1. Download the plugin, and unzip it.
  2. Place the nextgen-drainhole-compatibility folder in your wp-content/plugins folder at your website.
  3. Activate the plugin from the plugins tab of your WordPress admin.
  4. Do the necessary tweaks according to the description under “Setting it up” below.

Setting it up

This plugin assumes that you use both NextGen and Drain Hole, and that each NextGen gallery folder is a Drain Hole hole. It is up to you as admin to make sure that that is the case. You need to do some manual labour to make this work.

This plugin so far only defines one function, nextgen_drainhole_url. This function takes one argument, a URL according to NextGen, and outputs the corresponding URL according to Drain Hole. That function has to be used wherever NextGen generates a URL to an image in a gallery. What you need to do to make this work are the following tweaks to the NextGen installation:

  1. For basic functionality: Provide new templates. The simplest use of this plugin is to copy the folder plugins/nextgen-drainhole-compatibility/nggallery to your theme folder. That makes albums, galleries and singlepic shortcodes work as intended. Well, almost. The various slide shows do not work. Therefore, continue with 2 and 3. Note that only the files album-extended.php and album-compact.php are really needed. The other two templates are provided for completeness.
  2. Make PicLense work for galleries: Replace plugins/nextgen-gallery/lib/image.php by plugins/nextgen-drainhole-compatibility/replacements/lib/image.php
  3. Make slideshows work in galleries: Replace plugins/nextgen-gallery/xml/rotateimages.php by plugins/nextgen-drainhole-compatibility/replacements/xml/rotateimages.php

Since this is a dead simple plugin, there are no admin pages, no options to tweak, no settings to change. But manually replacing some files is needed.


It is a bit tedius to set up galleries using the intended combination of plugins. To create a new NextGen gallery in this setup, you have to do the following:

  1. Create the gallery using NextGens admin interface, which results in a folder in wp-contents/gallery.
  2. Populate it using NextGen.
  3. Make it a Drain Hole hole using the admin interface of Drain Hole. Since this folder is in the public part of your web, you need to limit its access, which you do by making sure that you have the correct .htaccess in your gallery folder. Drain Hole will attempt to create that file. If that did not succeed, you need to create it manually. See the admin interface of Drain Hole for the correct contents in that file. Just in case, there is a .htaccess file in plugins/nextgen-drainhole-compatibility/resources if you are unable to find one through Drain Hole. If this is not met, then your images will still be publicly available.
  4. Have Drain Hole scan your directory.
  5. Set access permissions using Drain Holes admin interface. Default is that anyone can access the files.

After that, it should be perfectly possible to use your Nextgen gallery as intended. See NextGen documentation about that.


  • If you update your NextGen galleries, you need to have Drain Hole rescan them.
  • The new template and replacement files provided with this plugin provide the default behaviour if this plugin is deactivated or uninstalled. You can therefore safely forget about the changes made because of this plugin.
  • If you update NextGen, the whole NextGen plugin is updated. All files, also the replacement files provided here. You need to redo that. If those files in the new version of NextGen have been updated in the NextGen plugin, I recommend that you check if a new version of NextGen DrainHole Compatibility Functions is a vailable here.
Comments are closed.