How to rewrite wordpress comment links?

matt3

Member
Jun 15, 2009
660
9
18
Searched for a plugin to no avail.... bastards are spamming the shit out of one of my blogs, but it also runs a yahoo answers plugin. Point being, I want some links in the comments for the content to flow naturally.

How do you rewrite any links in comments to a set few urls?

Thanks for your help!
 


Basically, I have an autoblog that pulls rss feeds and yahoo answers comments, and it's getting littered with links I don't want. The yahoo plugin I'm using won't filter out links in the content, plus it wouldn't make sense to do so when people are saying..."go here to see X."

So I figured the next best thing to do is just rewrite all comment links to something of my preference. Dunno if a short code snippet in functions.php that detects html chars and replace would work?
 
Well... the comments are saved in database so you could run some query and change them. I'm not sure about where you could customize the "insert comment" feature in wp so that you could have this feature in all future comments. May be in functions.php....
 
Yeah, I was thinkin the same. Tried to start with this snippet as a base (removes ALL links when html chars are present) and mod it out, but it appears to not be working on 2.8.

Anymore ideas?

Code:
function plc_comment_post( $incoming_comment ) {
    $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
    $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
    return( $incoming_comment );
}

function plc_comment_display( $comment_to_display ) {
    $comment_to_display = str_replace( ''', "'", $comment_to_display );
    return $comment_to_display;
}

add_filter('preprocess_comment', 'plc_comment_post', '', 1);
add_filter('comment_text', 'plc_comment_display', '', 1);
add_filter('comment_text_rss', 'plc_comment_display', '', 1);
add_filter('comment_excerpt', 'plc_comment_display', '', 1);
 
Would on-the-fly be an option, as opposed to storing it in the db? In comments.php, you could replace the default comment loop with e.g. get_comments(). With some str_replace action, it would be a dirty hack but it would get the job done.