Uploading Images in Wordpress 2.0

UPDATE: There’s in fact a plugin that restores the Upload tabs and options.

With the introduction of Wordpress 2.0, the Upload tab vanished and reappeared in a very defunct way under “Write Post”. Like many other people, I missed the good old Upload tab in Wordpress 1.5. What can be more easier than choosing the file of your choice, setting thumbnail options and hitting “Upload”? Then the IMG tag appears and I simply copy and pate it to my post.

So since the “Upload” tab is actually the file wp-admin/upload.php in Wordpress 1.5, why not upload to the wp-admin in Wordpress 2? Well, I did that and it does work in fact. All you need to do is simply upload the file. As there’s no such tab in Wordpress 2, you’ll have to access it through http://yourdomain.com/wp-admin/upload.php. Upload functions work exactly like in Wordpress 1.5, all except for a tiny change - thumbnail naming.

In Wordpress 1.5, thumbnails are named myPic-thumb.jpg for example. In Wordpress 2, it’s renamed to myPic.thumbnail.jpg. If you’re already used to the thumbnail naming convention in Wordpress 1.5, like me, you just wont feel at home with myPic.thumbnail.jpg. Old habits die hard. Shrug..

Some prodding revealed that a function called “wp_create_thumbnail” (line 686, WP2) in wp-admin/admin-functions.php. In line 746 you’ll see the following:


	if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )
		$thumb = preg_replace('!(\.[^.]+)?$!’, __(’.thumbnail’).’$1′, basename($file), 1);

.. which basically renames the original filename into the thumbnail. To tell you the truth, I don’t really have a sound understanding of Wordpress’ filter and hook architecture. But it’s not really that hard to change the way a filename is named. All in all, you just need to do the following the your the upload.php codes.

First of all, add the following function to the top of the codes (I added mine after “require_once(’admin-header.php’)”):


/* function to change thumbnail filename */
function changeThumbName($content)
{
	preg_replace('!(\.[^.]+)?$!’, __(’-thumb’).’$1′, basename($file), 1);
	return $content;
}

Next, you need add another line that’ll add that function to the filter. Not being sure where to do so, I tried adding it right before wp_create_thumbnail is called. Use your editor’s Find tool to locate the line that function is called.


// add a filter to change the thumbmail filename (add the next line)
add_filter('thumbnail_filename','changeThumbName');

// Wordpress' original code:
$result = wp_create_thumbnail($pathtofile, $max_side, NULL);

The last line in the code above is Wordpress’ code. If you upgraded to Wordpress 2.0 from 1.5, the upload folder is as specified in Wordpress 1.5’s Options > Misc tab. I’m not really sure if a clean installation of Wordpress 2.0 has the records for upload path. But you could check it out with the following SQL codes:


SELECT * FROM `wp_options` WHERE `option_name` LIKE 'fileupload_url';
SELECT * FROM `wp_options` WHERE `option_name` LIKE 'fileupload_realpath';

Happy new year to y’all folks, and enjoy the “Upload” tab!

Tags:

One Response to “Uploading Images in Wordpress 2.0”

  1. TreeFrog Says:
    February 22nd, 2006 at 11:31 am

    Terrific Blog you have. Peace Out.
    TreeFrog

Leave a Reply