Here's the deal: I accidentally did a mass find/replace across an entire MySQL table. Specifically, the table containing hundreds of Wordpress posts & pages (wp_posts
).
"D'oh" doesn't even begin to explain the moment after that fateful click. For the record, I blame poor user interface design. Here's a screenshot of what happened:
Consequently, this ruined all my Wordpress posts containing shortcodes (i.e: all of them). For instance...
[my_shortcode]Hello world.[/my_shortcode]
[my_image_shortcode]http://mydomain.com/image.png[/my_image_shortcode]
is now
[my_shortcode]Hello world.my_shortcode]
[my_image_shortcode]http://mydomain.com/image.pngmy_image_shortcode]
You can see how this would be a pain in the ass to fix across a few hundred posts/pages, totaling 160,000+ words of content.
I have a new plugin called "Regex Search" that allows me to do mass regex-based find/replace functions. I just need to figure out the Regex that does this:
Find all instances of my_shortcode]
where the character preceding my_shortcode
is NOT /
. Add a [/
between the character that is NOT a /
and my_shortcode]
.
So this would find:
[my_shortcode]Hello world.my_shortcode]
and replace it with:
[my_shortcode]Hello world.[/my_shortcode]
I'll stop here, since I realize this might be madly confusing already. I can explain further to anyone that thinks that may be able to solve this mess.
David
Written for/with Ruby. Probably easily adaptable for use with your Regex Search plugin.
Seems to work for me. Backup your database before running, caveat emptor, etc.
Hit me up if you're interested in how this works.
http://twitter.com/isaacdudek