Modifications to FreePress Recent Comments Plugin

For others that may find it useful, I’ve made two modifications to the FreePress Recent Coments plugin on DLTJ: one to strip out quoted material when using the Quoter plugin and a second to suppress pingback entries that result from links to material within the blog.

Code from the first came from a blog posting about how to get Quoter to work with a different recent comments plugin. It is slightly modified, though, with the use non-greedy wildcard (*?) in the middle. (It is possible to have more than one quoted section in a comment, and the original code would leave just the text beyond the final [/quote] tag.) The context-sensitive diff is:

*** recentCommentsWidget.php.dist	Wed Aug 23 09:52:11 2006
--- recentCommentsWidget.php	Wed Aug 23 11:22:14 2006
***************
*** 135,140 ****
--- 143,149 ----
  				// Comment Content -> Excerpt
  				$comment_content = strip_tags($comment->comment_content);
  				$comment_content = stripslashes($comment_content);
+ 				$comment_content = preg_replace('/\[quote(.|\s)*?\[\/quote\]/i', '', $comment_content); // remove quote tags and quoted text
  				$words=split(" ",$comment_content); 
 
  				if($max_letters_per_word!=0) {

The second is a modification to the SQL statement that pulls up records from the wp_comments table. There is an additional AND conditional clause that eliminates the pingback where the URL of the pingback begins with the URL of the blog. The context-sensitive diff:

*** recentCommentsWidget.php.dist	Wed Aug 23 09:52:11 2006
--- recentCommentsWidget.php	Wed Aug 23 11:22:14 2006
***************
*** 221,227 ****
  	if (get_option('WPTagboardPostID')) {
 
  		$request .= "AND ID <> " . get_option('WPTagboardPostID') . " ";
 
  	}
 
! 
 
  	$request .= "AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $limit";
 
 
  	$comments = $wpdb-&gt;get_results($request);
 
--- 228,235 ----
  	if (get_option('WPTagboardPostID')) {
  		$request .= "AND ID <> " . get_option('WPTagboardPostID') . " ";
  	}
!     // Eliminate pingbacks/tracebacks by registered authors to posts on this blog
! 	$request .= "AND (comment_type = '' OR comment_author_url NOT LIKE \"".get_bloginfo('url')."%\") ";
  	$request .= "AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $limit";
 
  	$comments = $wpdb-&gt;get_results($request);

Share and Enjoy!

(This post was updated on 13-Nov-2012.)