Tag Archive for 'Wordpress'

IETester and Javascript Errors

I was playing with IETester, which lets you open Internet Explorer tabs using rendering engines from IE 5.5 up to IE 8 beta 1 for testing compatibility, and noticed for the first time that my blog was throwing a Javascript error only in IE.

Being the pain in the ass IE is, of course the line number it gives isn’t really valid. I looked and looked and couldn’t find the problem. As a last ditch effort, using the IE Developer Toolbar, I hit the menu option to validate the page. Thanks to the W3C Validator, I found that there were some duplicate ID attributes on elements.

After checking out the lines the validator referenced, I found that the Google Analytics plugin for WordPress was improperly tearing apart href attributes for links created by the Footnotes plugin I use, causing it to include long strings of HTML in the onclick attribute for tracking outgoing links1.

Thankfully, the Analytics plugin has an option to turn off outbound link tracking. I’ll miss those stats, but it’s not like I pay all that much attention to them (or care) anyway.

In the end, I don’t really have anything to test with IETester, it was just a fun toy for a few minutes. It also helped me notice a problem I probably wouldn’t have found otherwise, so in the end it was time well spent.

  1. Rather than just the link the user was headed for, as it should - and does for regular links. [back]

New Kick-Ass Wallpapers

I had the opportunity to do some quick WordPress plugin hacking tonight1 for Jim Whimpey. As a “payment” of sorts, he gave me a coupon code for the site he was working on: Panedia Desktop Wallpaper.

Being an Aussie company, obviously, most of their wallpapers are from Australia. Boy do they have some absolutely beautiful scenery down under. Check out the two I selected for my machines:

For my desktop, I got a huge 3200 x 1200 pixel version of Brisbane’s beautiful night skyline:

New Desktop Wallpaper

And for my MacBook Pro, I got a beautiful 1680 x 1050 pixel copy of the Robe Coastline:

New MBP Wallpaper

Stunning wallpapers. Totally worth $25/year to constantly get new beautiful scenes in this kind of quality. I also love the interface that auto-picks the best format for your OS and resolution. Very well done.

  1. I added an additional search option to the Search Everything plugin, enabling it to return all posts in a matching category. [back]

Fresh Garland Release!

It appears somehow the uploads directory I had on my Dreamhost account got wiped out. Nothing important there… except my Garland theme release. Since several people have been asking me about it lately, I thought it was time to wrap up a fresh release.

If you’re looking for the Garland theme for a stand-alone Wordpress blog, you’ve come to the right place!

In theory, this release shouldn’t be any different than the previous one, but I can’t promise that - I don’t recall having made some of these changes previously.

I’ve tried to get in touch with Matt to see if there is any way to get these changes into the Wordpress.com themes repo, but I have not yet heard back from him. In any event, please let me know if you notice any problems!

Changes

In a nuttshell, the changes are purely superficial - URLs mostly. The path for reaching the theme on the Wordpress.com servers differs from that of standalone blogs. Additionally, jQuery is not available on the admin pages of the current Wordpress release by default, while it is on Wordpress.com.

SVN / 2.5 Notes

While testing on the latest copy of trunk, I noticed that the plugin is unable to register its admin page. This is because the page for theme-related config has changed from ‘Presentation’ to ‘Design’ during the admin redesign project. Whether this will be true of the 2.5 release or not, I have no idea.

If you’re trying to run Garland on the bleeding-edge of Wordpress, you’ll want to change ‘Presentation’ to ‘Design’ in the 3rd to last line of functions.php to make sure it knows the proper page to hook into.

Download

Snag ‘er here: garland-standalone_1.5.zip

Missing an Email? It may be Media Temple’s Fault

It started last week when I was trying to sign up for Ron Paul Christmas. For some peculiar reason, I didn’t receive the welcome email. After talking with the site owner, it turned out (mt) was rejecting the email because the email address wordpress@ronpaulchristmas.com didn’t exist on the sending server.

Now, this isn’t particularly unusual. There is no requirement1 that an email address actually exist for a server to send email as if it were from that address. This is especially true from Wordpress blogs, which often send email from wordpress@domain.com accounts on behalf of their owners. Now, since this is only used for outgoing email, in most cases users would never bother setting the email account up. Why would you? You’re never going to be receiving email there2, so what’s the point?

Well, (mt) apparently knows better than you do… For “security reasons”3, their grid service does a “callback” check on every incoming email address. If the server handling mail for domain.com doesn’t recognize that account (such as our wordpress@domain.com example), (mt)’s server will reject the message.

I’ve tried to point out that this kind of behavior can be detrimental, particularly in the age of blogging and web services we now exist in, but the best answer I’ve been able to get out of (mt) is that I should add the sending address to their Mail Protect whitelist. Well great, unless I can add *@* to the whitelist, or at the very least wordpress@*, that’s hardly a viable solution - how do I know the address that’s sending to me if I never get the email?

If you use Media Temple’s grid service4, please contact (mt) immediately and tell them this is an unacceptable situation. I love a lot of aspects of their grid service, but this is clearly not one of them…

  1. In most cases, anyway. [back]
  2. Except for bounces, should someone put in an invalid email address [back]
  3. According to the support representative that responded to my ticket. [back]
  4. Or you want people who do use it to actually receive emails you send to them. [back]

Modifying Allowed Upload Types in Wordpress

Several times recently in #wordpress, I’ve seen people asking how they could modify the list of allowed file types used in the file uploader on the Write Post page.

Since this information isn’t readily available (apparently) and to a lesser degree because I’m tired of not being able to find my previous code (causing me to re-type it all each time), I thought I’d throw together another quick WordPress hack guide.

Introduction

When you attempt to upload a file in WordPress (2.0+ I believe) that is not in the default list of acceptable file types1, you will receive the following error:

WordPress File Upload Error

As of WordPress 2.2, there are 35 allowed file types configured in the default install. While there’s no admin-based tool for editing this list (nor any plugins that I’m aware of), it’s not at all difficult to add your own…

The Code

Upload filetypes are checked by the function wp_check_filetype in wp-includes/functions.php (around line 1,000 in my current copy of trunk). Looking at the code, we see that the default array is passed into the upload_mimes filter, allowing you to easily add and remove types at will using a quick plugin hook.

So how do we do it? Well, first you need to add a new plugin hook. In your theme’s functions.php file, add this line:


add_filter('upload_mimes', 'custom_upload_mimes');

You can, of course, replace custom_upload_mimes with your own preferred function name. Just make sure it’s something unique that ideally won’t cause any naming conflicts later on2.

Now we’ve got a hook that tells WordPress to take the array of file types passed into the upload_mimes hook and hand it to the function custom_upload_mimes. Great, but where’s our function?

No problem, I’ve got it all ready for you. Open back up your theme’s functions.php file and toss in this code:


function custom_upload_mimes ( $existing_mimes=array() ) {

// add your ext => mime to the array
$existing_mimes['extension'] = 'mime/type';

// add as many as you like

// and return the new full result
return $existing_mimes;

}

Note that the function accepts the $existing_mimes array, adds a new file type (with the extension “extension” and of the mime type “mime/type”), and then returns the whole array.

Replace extension with your extension (no period before it, just the textual extension) and then Google to find out its mime type3.

Add as many new types as you like, simply by copying the example line and filling in your values. Also, make sure you name the function the same thing you used in the hook, assuming you don’t like my convention. Save your new functions.php file and you’re good to go!

Removing Existing Types

What if you want to remove an existing allowed type, instead of adding your own new type? Well, that’s even easier!

Replace the line $existing_mimes['extension'] = ‘mime/type’; with unset( $existing_mimes['extension'] ) and you’re done. For example, to prevent users from uploading .exe files, you would use:


unset( $existing_mimes['exe'] );

Good luck, hope this helps!

  1. For example, Microsoft Installer files are not allowed by default, so track down an .msi file and try to upload it for a quick test. [back]
  2. I like to use the prefix ‘custom_’ simply because it’s easy to tell later on that this is a custom modification. [back]
  3. Googling for “.zip mime type”, for example, should give you any number of sites listing a whole slew of mime types. Yours should be in the same <category>/<type> format as the others. Zip is “application/zip”. [back]