(DFFRP)

Defect Fix for RMRH Plugin

May 2, 2009 @ 19:03:44

Over on the post announcing my “Read More Right Here” wordpress plugin, an interesting few comments popped up by Thijs (I love these drawings). He found that the plugin breaks when a domain lets wordpress run its root, but the actual Wordpress files are stored in a subdirectory (see this codex article for the how to).

And awesomely enough, he found the cause of the problem!

The Defect

I was constructing the path to the plugin’s directory using the Wordpress function get_bloginfo, and passing to that function the value 'url'. However, the doc shows that value will result in Wordpress returning the blog home URL, and not the location of the actual core Wordpress files (which is what I needed). To get that path, you have to send in 'wpurl'.

Another Problem

But this fix uncovered another problem. That same path I assumed to be correct is hardcoded in the javascript function used to create the “loading” animated gif that appears while the “read more” content is being pulled. I fixed this issue by having the javascript asynchronously (ajax) ask Wordpress for the correct path (using the now updated function I described in the previous section). But that’s not really how I wanted to do it.

More Ideally

WOW, I FEEL STUPID.. I just typed a whole section here describing how I would rather have the javascript value used as the plugin URL somehow set by Wordpress. I envisioned something similar to wp_enqueue_script that could be used to inject some javascript value to the header along with the linked script sources.

So of course, after I’ve spent loads o’ time trying to find such a solution, figured “maybe next time” and officially updated the plugin, now I find this article (and I quote):

WordPress provides an elegant way to pass parameters to your JavaScript code using wp_localize_script function.

Arg and Doh and all that. Be on the lookout for another release!

6 Comments

Follow Comments