patch

Improving Will Norris’ Open Graph Plugin

Will Norris put together a nice WordPress plugin to place Open Graph metadata on the page. Today I patched it to address a few bugs I and others have found.

The patch switches functions that depended on globalizing $post to use $wp_query->queried_object and similar.

opengraph_default_url() is changed to try get_permalink() only when is_singlular() is true. Otherwise it uses the blog’s base URL. This isn’t perfect, but it’s better than having the front page and all tag/category/archive pages report their og:url as being the permalink for the first post on the page.

As suggested here, I changed the opengraph_default_description() to use the post’s excerpt if is_singular() and the post includes an excerpt.

I changed opengraph_default_image() to test if the theme supports post thumbnails before calling has_post_thumbnail() to avoid the Fatal error: Call to undefined function has_post_thumbnail() errors.

I submitted it as a bug report in the plugins Trac, but I don’t check there for tickets on my own plugins, so you might apply the patch yourself.

Uploading .docx Files In WordPress

It may be a sign that none of the core WordPress developers much likes or uses Microsoft Office, but the core code hasn’t been updated to recognize the Office 2007 file extensions like .docx, .pptx, or .xlsx. It’s no criticism, wouldn’t have discovered it if a user hadn’t complained, and I stewed a bit before deciding it was a bug.

It’s now ticket #8194 in the WordPress.org Trac. It only affects my MU users now, though, and the same patch works there.

You’ll find a few mentions of doc, ppt, and xls in wp-includes/functions.php (around lines 1613-1615 and 1651-1654 in 2.6.3). Once corrected, those lines should look something like this:

``` 'document' => array('doc','docx','pages','odt','rtf','pdf'), 'spreadsheet' => array('xls','xlsx','numbers','ods'), 'interactive' => array('ppt','pptx','key','odp','swf'), ```
``` 'doc|docx' => 'application/msword', 'pot|pps|ppt|pptx' => 'application/vnd.ms-powerpoint', 'wri' => 'application/vnd.ms-write', 'xla|xls|xlsx|xlt|xlw' => 'application/vnd.ms-excel', ```

Update: Sweet! It’s been accepted and should be in the WP2.7 release.

Catching Bugs Before They Catch You

I got itchy about magic quotes the other day because it’s the cause (through a fairly long cascade of errors) of some performance problems and runaways I’ve been seeing lately (pictured above). But I deserve most of the blame for allowing a query like this to run at all: SELECT type, data, count(*) AS hits […] » about 300 words