Annoyed with WordPress

Yesterday I was faced with a problem from a friend who has a wordpress blog hosted at The problem was that the 3GB space on the blog was filled up with the images to his blog posts. The reason that it was already used was due to the fact of that the images were uploaded with their original size, which are of course with todays cameras kind of big.

Got me thinking. WordPress already offers the functionality of scaling images in the Media Library, but doing that one by one is very time consumin, and to be frank, it’s extremely boring :-) , this took me onto google to see if there’s any xmlrpc api function (since WordPress supports this) that would let me do so. No, but I can upload images using wp.uploadFile, and it seems to support overwriting. Great!

Or was it? No. Firstly, the overwrite functionality doesn’t overwrite the particular image you’re interest in overwriting. It creates a new one, and removes the old one not even the name in the database is the same, all of a sudden it includes some sort of reference name to the old file, that you’re obviously interested in.

Piece of code:

if ( !empty($data['overwrite']) && ($data['overwrite'] == true) ) {
			// Get postmeta info on the object.
			$old_file = $wpdb->get_row("
				FROM {$wpdb->posts}
				WHERE post_title = '{$name}'
					AND post_type = 'attachment'

			// Delete previous file.

			// Make sure the new name is different by pre-pending the
			// previous post id.
			$filename = preg_replace('/^wpid\d+-/', '', $name);
			$name = "wpid{$old_file->ID}-{$filename}";

As can be seen here when overwriting, we look up the old image (based on the parameter $name) and deletes the file from the upload directory, but take a look at the next couple of lines. WordPress choses to create a new table row in `posts` with the old filename based on the old id and then adds a new filename.

For me, and everybody else who just wanted to replace/edit their image without  a huge hassle all of a sudden got a lot more work to do. Instead of having the same url to the image there’s a new one, if folder were used for adding images to posts (etc: /wp-content/uploads/2011/09) which results in that we have to edit all the posts who directly link to the image and not just a media library entry.

Why didn’t WP just replace that particular file in the system, as we actually were interested in overwriting it. Ah well, editing the posts shouldn’t be too much of a big mess right? Nah, editing a post isn’t hard at all. Download all the posts with getPages and just replace the old url with the new one for the images (even if a post from 2010 will have image links to 2012, not very stylish)

Oh, and another thing i noticed. When using wp.uploadFile the $name parameter must add a file type prefix, such as ”.jpg”, or it won’t be uploaded. This is not a big problem, unless you wanted to overwrite an image that was uploaded from the web GUI where your description ended up being ”Hello donkey kong” without an file type prefix. That file won’t be able to be overwritten (replaced) by another image.

So basically, I can’t achieve what I want, and it really annoys me.

Of course, the best way of achieving this is to just use  an FTP server, download the images from their folders, scale them with imagemagick or any good piece of software out there and just upload them again. But doens’t support FTP:ing, which I’m totally fine with, and totally understand.

Ok. WordPress is the greatest blog platform out there, so far I’ve never had any hassle myself as I have complete access to the system, but if don’t have that, It lacks some features that I’d like to have :(

I could just write a plugin that does this, but as I cannot upload plugins to that approach also fails. I’m locked out of doing my scaling on the images, unless I want to be a script kiddie and use the AJAX interface with Wireshark traces and somewhat reverse engineering but this isn’t the right way of doing things.

I think I’ll just sit down, add a feature to scale images on class-wp-xmlrpc-server.php and if I’m lucky, it’ll end up on the official release for, and it might work on as well one day, at least that’s what I’m hoping for, so that all the rest of you guys can get your used space down a little bit!


One thought on “Annoyed with WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *