Skip to content
Solely for the Purpose of Catching $PAMRZ

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 03-Feb-2007.)

Post a Comment

Your email is never published nor shared. Required fields are marked *
Human Detection Scheme
(What's this?)
Comment Preview

Subscribe without commenting

From the Disruptive Library Technology Jester (http://dltj.org/), printed on Thursday the 13th of November 2008 at 8:02:15 AM EST (-0500). The URL to this page is http://dltj.org/article/modified-freepress-recent-comments-plugin/

[Creative Commons Logo] This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.