TimThumb is a cool little thumbnail script in vogue for WP theme designers. It’s also notorious for not playing nicely with WPMU. Specifically, the rewrite magic used to run WPMU chokes the script in generating the thumbnail, as it’s looking for “/files/date/filename.ext” instead of “/blogs.dir/X/files/date/filename.ext”–where X is the $blog_id variable.
This is easy enough to fix if you want to hardcode your path into the script, but what if you want to set up a theme on WPMU that utilizes the script and open it to more than one blog? Maybe you’re a Thesis fan, perhaps? Well you can.
Please note: This technique requires hacking the timthumb script and as such, it’s never going to be an ideal solution. However, since many WP themes have timthumb deeply integrated and WPMU admins may well want to make such themes available to their users without requiring a users themes plugin, this IS an option that will allow multiple users to access a single version of the script and have it work properly.
Here’s how:
Towards the top of your script, you’ll need to include the wp-blog-header.php file. This allows you to access WordPress variables from within the external script. This path worked for the Thesis theme setup, where the timthumb script, “thumb.php,” is located in the folder “/wp-content/themes/thesis_16/lib/scripts/” – you will need to adjust the path as appropriate to go from your actual script location up to the root of your WPMU install.1
require_once('../../../../../wp-blog-header.php');
From this:
$src = get_document_root($src) . '/' . $src;
To this:
global $blog_id; $src = get_document_root($src) . '/wp-content/blogs.dir/'. $blog_id.'/' . $src;
And from this:
// check for unix servers if (@file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $src))
To This
global $blog_id; // check for unix servers if (@file_exists($_SERVER['DOCUMENT_ROOT'] .'/wp-content/blogs.dir/'. $blog_id.'/' . $src))
That’s it. You now should have thumbs showing up where they belong!
Troubleshooting quick tips:
- If you get an “failed to open stream: No such file or directory” error, then your path to wp-blog-header file is probably off.
- If you’re getting a “file not found” error, trying replacing the $blog_id variable with a hardcoded number of the blog id to see if the problem is in your code itself or in accessing the variable.
- Code note: There are probably better ways of doing this. I am not a programmer; I am a hack. Feel free to share your wisdom in the comments. Also, I’m squishing the declare global of $blog_id for these two functions we’re editing into the same line as the new code in the interest of keeping line numbers consistent. If that bugs you, then adjust as required. [↩]
Related
{ 1 comment… read it below or add one }
Please note the article at Kristerella.com where she describes an alternative, more robust hack that worked for her if this one doesn’t work for you.
http://www.kristarella.com/2010/05/mod-timthumb-for-wpmu-and-thesis/
{ 3 trackbacks }