Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can someone please explain what the purpose of this code is:

$text = str_replace(']]>', ']]>', $text);

I'm referring to a line of code inside wp_trim_excerpt(), but I've seen something very similar in some other wp functions as well.

On the surface, I would say it's not doing anything at all, but I have to give the wordpress developers more credit than that, so I'm sure there's a reason for this. I've looked into the php manual for str_replace to see if there is some special return value but everything is as I would expect.

Is this some sort of ninja data validation technique?

share|improve this question
    
Sorry, my fault with encoding in QueryPosts. :( Added to bugs list. If not sure please double check in linked repositories. –  Rarst Jul 19 '12 at 11:48
1  
Definitely not a ninja data validation technique. –  Brian Fegter Jul 19 '12 at 13:43
    
@Rarst, thanks Rarst. I love QueryPosts :) When are those classes coming? –  Evan Mattson Jul 19 '12 at 14:22
    
@Evan having capacity to work on new parser for those classes is like a light in the end tunnel for me. But it's a long tunnel so far... –  Rarst Jul 19 '12 at 14:28
    
Bugfix live (might take bit more time to wash out of cache). –  Rarst Jul 19 '12 at 15:08
add comment

closed as too localized by Rarst Jul 19 '12 at 12:03

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 2 down vote accepted

The replacement string contains a HTML entity which when displayed on a browser, looks like the needle string. It's converting > to a HTML entity.

Reference: http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/formatting.php#L2119

share|improve this answer
2  
To clarify, since this answer confused me momentarily - it looks like queryposts.com is decoding the HTML entity. Core's sourcecode will show that it turns ]]> into ]]> –  helenhousandi Jul 19 '12 at 11:42
    
@BrianFegter - I see now. Even still, what is the purpose of that replace? It seems like the only thing it would match would be a closing CDATA tag? Shouldn't encoding like this be done before saving rather than right before displaying? –  Evan Mattson Jul 19 '12 at 14:18
    
@EvanMattson CDATA tag closing –  Brian Fegter Jul 19 '12 at 14:23
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.