Fix WP Gallery Remote plugin for Wordpress 2.7
Jed | January 28, 2009Warning: This post assumes a lot of prior knowledge about Wordpress and the WP-Gallery-Remote plugin. I’m writing this post to help any others out there on the internets who also use this plugin and ran into the same problem I did.
I use the WP-Gallery-Remote plugin to show pictures on this blog. Unfortunately after I upgraded to Wordpress 2.7 it stopped working completely. It would still show pictures if I added the special markup to each post manually, but the handy popup editor would no longer insert the tag automatically into my post.
It turns out the problem and fix are very simple. The JavaScript that inserts the special tag into the page is broken because it relied on the structure of the Add New Post/Edit Post page which has changed in Wordpress 2.7.
The problem is with the index of the forms array on line 63 of wp-content/plugins/wp-gallery-remote/mce_plugin/wp-gallery_remote_mce_plugin.js:
insert_wp_gallery_remote_tag_AtCursor(window.opener.document.forms[0].content, tag);
Starting with Wordpress 2.7, the main post content form is no longer the first form on the page. Now in 2.7 the “Screen Options” dropdown on the top right of the page is the first form. This means that forms[0] no longer points to the post textarea.
So to fix the WP-Gallery-Remote plugin to work with Wordpress 2.7, just edit line 63 of wp-gallery_remote_mce_plugin.js and change that 0 to a 1. Or if you want to get more fancy, you can fix the plugin so it will keep working even if the Add New Post/Edit Post page changes in a later Wordpress release by changing line 63 to this:
insert_wp_gallery_remote_tag_AtCursor(window.opener.document.getElementById('content'), tag);
Presto, working Gallery2 editor in posts!





