This concerns a problem at my blog.
My provider recently required me to upgrade from PHP 5.2 to PHP 5.4. This in turn required me to update WordPress.
Ever since the dual update, all line breaks in comments are rendering as “rn”, so that if you type this:
Hi
<br><br>
Hello
what gets rendered is
HirnHello
If I edit comments to repair them, all of the line breaks I enter are converted back to “rn” as soon as I hit “save”.
A temporary rollback to PHP 5.2 had no effect on this problem.
I briefly thought I could solve the problem by updating my theme (K2). This did not solve the problem and created a slew of new (unrelated) problems, so I’ve rolled back that update.
Browsing around this site, I see a few scattered references to this and similar problems, but no indication that it’s ever been common and nothing that appears to be a solution.
Can someone guess what’s causing this, and even better, how to fix it?
Update: I found a file called wp-comments-post.php
, which contains the following line:
$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
I wrapped the trim($_POST['comment'])
inside a nl2br()
, and this helped a bit. Instead of rendering as
HirnHello
it now renders as
Hi<br>
rn<br>
rnHello
(or something like that; I might have forgotten how many rn
‘s show up).
This is progress, but I’d still like to get rid of the rn
‘s. Presumably I can use str_replace
? But I am an amateur and am not sure of the syntax. My first few guesses didn’t work.
Meanwhile, I still want to know why this problem arose in the first place.
The above answer (“So it turns out”) turns out not to be the answer after all. With the fix described there, comments that I submitted were rendered correctly but comments that others submitted were not (even though I was submitting through the same comment interface that everyone else was). Go figure.
Anyway, the real fix turns out to be to restore wp-comments-post.php to its original form (eliminating the str_replace that I had added per the earlier answer) and to turn to a file called comments.php (which is part of the K2 theme), where the problem was solved by replacing the line
with
This definitely works. Why it was suddenly necessary remains a great mystery.
So it turns out that I solved the problem by editing the file wp-comments-post.php, where the following line appears:
In this line, I changed
to
I discovered this through much trial and error. I still haven’t a clue what caused the problem in the first place (and of course the problem is ongoing; it’s just being fixed automatically each time it occurs).
This experience has done nothing but strengthen my belief that it’s always a bad idea to upgrade software that’s working perfectly well.