As you may have noticed, I upgraded this site to WordPress 1.2 yesterday. You may have noticed because WordPress 1.2 has what I consider to be a very serious bug in that it ‘escapes’, or adds a slash, in front of all apostrophe’s in both comments and RSS. This is commonly referred to as the ‘magic quote’ problem with PHP. (I’m writing a LAMP essay on this for later.)
The rumors of workarounds at the support center talk about adding filters to filter out the slashes, and I did this for comments. But then, thanks to some friends, I found out that the RSS is also featuring escaped slashes. In fact, the built-in page preview is escaped, and the only thing not escaped is the text in the main post.
Since there are new users of WordPress 1.2 that haven’t said anything about this problem, I’m wondering if it has to do with the upgrade from WordPress 1.02 to WordPress 1.2. Or maybe they have a fix. Or maybe they don’t know the problem exists. Or maybe they got the secret decoder ring to wear while writing to their weblog. Mark did you get the secret decoder ring?
I don’t know what’s happened in WP to generate this problem, but you might want to consider postponing a port or upgrade to WordPress 1.2 until an official fix has been created. Having to add these strip slash filters isn’t the best way to deal with this problem.
For those who have ported to WP 1.2 and are having problems, I’ve added filters to the syndication feeds, and the comments that seem to work with the comments at least. We’ll see how it does with syndication.
Add the following to wp-comments.php:
Make sure to add this into an existing PHP block.
Add the following to the PHP code in the syndication feeds:
Let’s say this post is a good test whether these work or not.
More later on the adventures of upgrading and also what hacks I’ve added.
And when I first posted this, I had an opening PHP block, <?php> …<?> that I didn’t convert to HTML escaped characters included in the code. This caused WordPress to fail. This should not happen–the results might look funny, but the application should not fail.
But the stripslashes seem to be working on new entries within the syndication feeds.
Let’s do this the easy way: add the following to your .htaccess file:
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
This solves the problem without having to add all the filters on new or newly saved entries! The slashes are still in the database for the old entries.
In fact, this probably explains why others do not have this problem–either magic quotes are turned off for their installation, or they have these entries in their .htaccess file. However, it does seem as if the magic quote escaping is happening in the upgrade process. Yes? No?
Or was it that WordPress 1.02 and before handled this ‘badly’, and WP 1.2 handles the situation correctly, but the data is already ucky? I didn’t check the data before I did the upgrade (more fool me).
(Yes, that’s a tech term – ucky. )
More later in a LAMP essay on ‘magic quotes’.