KB Plugins

The best Wordpress plugins are free

You are viewing the Custom category archive.


Back to KB Plugins main page

Print this post

Graphs: When Spammers Attack

These charts show when spammers like to attack the most. These charts use averages dating back to January 28th, 2008, when KB Spam Blacklist starting operating on this site. These times are in my server's time zone, where it is currently 9:18 am.

The red line indicates the number of spams stopped, on average, for each hour of each day. The blue line is the same data with smoothing applied (to make the trends more obvious).

Spammers' Favorite Days

Spammers' Favorite Hours

Want to shoot spam on site, preventing it from even showing up in your moderation queue? Try out KB Spam Blacklist.

Print this post

KB Comment Links

Here’s a little plugin to fix an annoying problem. Do you ever have commenters paste an entire URL into their comment as plain text, rather than putting it in <a href="..."> tags? Or if they do use the a tags, do they still use the URL as the link text?

Sure looks ugly when people do that. Here’s a little plugin to replace URLs that occur in comments with [link]. We don’t strip the URL–the word [link] will be clickable–we just make the comment prettier. Enjoy:

<?php
/*
Plugin Name: KB Comment Links
Plugin URI: http://adambrown.info/b/widgets/tag/kb-comment-links/
Description: Replaces long, ugly URLs in comments with a short link
Author: Adam R. Brown
Version: 1.0
Author URI: http://adambrown.info/
*/

function kbcl_comment_filter($comment){
	if (false===strpos($comment,'http://'))
		return $comment;
	// links in <a> tags using URL as link text
	$comment = preg_replace('~(<a[^>]+>)(http://\S+)</a>~', '$1[link]</a>', $comment);
	// links that aren't in <a> tags
	$comment = preg_replace('~(\s|<p>)(http://\S+)(\s|</p>)~', '$1<a href="$2">[link]</a>$3', $comment);
	return $comment;
}
add_filter('comment_text', 'kbcl_comment_filter');

?>
Print this post

New Plugin: KB New Posts

Introducing KB New Posts, a plugin inspired by this support thread .

What it does

When somebody visits your blog’s main page, the plugin sets a cookie recording the time of their visit. If they come back a few days later, and you’ve written a new post (or many new posts) since their last visit, the plugin adds a CSS class to the new posts so that you can highlight them, or add a background image, or change the font size, or whatever you want to do to new posts. (Want to read the rest of this post? Click here.)

Keywords:
Print this post

New plugin: KB Spam Blacklist

As if there weren’t enough anti-spam plugins, right? Actually, this isn’t a traditional anti-spam plugin. This is a regular-expression based blacklist plugin. And by blacklist, I mean blacklist. If a comment matches one of your regexes, it gets deleted immediately, not sent to moderation.

Why use this plugin?

So why would you want this? I don’t know about you, but 90% of my Akismet spam is really obvious spam. It contains obscenities, BB code ([url...]), “payday loan” offers, and other things that are really obvious. I don’t want this stuff in my spam queue–I want it shot on sight. That way, the spam queue only has stuff in it that might actually be genuine comments that were miscategorized as spam.

How it works

In short, this plugin takes some of the load off of Akismet by looking for really obvious stuff. It’s easy to use. Just activate the plugin–that’s all. It comes with four regular expressions. You can add to, modify, or remove these if you want. This is the default blacklist:

<?php $kb_spamBlacklist = array(
	// First, let's check for [url]...[/url] markup, a sure sign of a spammer (unless you're using a bb code plugin)
	'~\[[^\]]*url[^\]]*\]http[^\[]+\[/url[^\]]*]~i',

	// profanity and obscenity. Remember that spammers use ! for i, @ for a, * for u. 
	// Also, most of these get surrounded in \W so that, e.g. ASSume doesn't get mistaken for profanity.
	'~(\Wf[u\*]ck|x{3,}|\Ws[u\*]ck[i!]ng|\Wt[i!]ts?\W|\W[a@]s{2}\W|v[a@]g[i!]n[a@]|\Wc[u\*]nt|pen+[i!]s)~i',	// depending on your audience, you might not want this one

	// Now let's check for ... interesting ... pharmaceutical offers
	'~(c[i!][a@]l[i!]s|v[i!][a@]gr[i!]?[a@])~i',	// remember that they sometimes use ! for i and @ for a

	// payday loans, anyone?
	'~(credit|loans?).*(credit|loans?).*(credit|loans?)~Usi',	// if they use "credit" or "loans" too many times in their comment, kill it.
); ?>

Try it out

If a comment gets caught by one of those regexes (or by another that you add), the commenter sees an error message. If you want to try it, write a comment that uses viagra, cialis, or [url]http://buy-junk.com[/url] in it and see what happens.

Also includes a widget, if you’re into that. Look in the sidebar.

Download it

Download KB Spam Blacklist v1.0

Print this post

Truncate Titles

Let’s say you’ve written lots of posts with lengthy titles. But now you’re switching to a theme that doesn’t handle long titles well. Copy this into a file, name it truncateTitle.php (or whatever.php), upload to your plugins directory, and activate it in the usual way. Don’t leave any blank lines or spaces before or after this code (or you’ll get an error).

<?php
/*
Plugin Name: KB Truncate Title
Plugin URI: http://adambrown.info/b/widgets/category/custom/
Description: Truncates titles so they don't break your theme
Version: 1.0
Author: Adam R. Brown
Author URI: http://adambrown.info/
*/

define('KB_TRUNCATE_TITLE', 50); // change 50 to max number of characters to allow

function kb_truncateTitle($title){
	if (!is_int( KB_TRUNCATE_TITLE ) || 1>KB_TRUNCATE_TITLE )
		return $title;
	// rather than just use substr, let's make sure we cut it at the end of a word
	$arr = explode(' ', $title);
	$out = '';
	$count = 0;
	foreach( $arr as $str ){
		$count += ( strlen($str) + 1); // +1 is for the space we removed
		if ($count > KB_TRUNCATE_TITLE)
			break;
		$out .= $str . ' ';
	}
	// make sure we got SOMEthing
	if (!$out)
		$out = $arr[0];
	return $out;
}

// makes the function work
add_filter('the_title','kb_truncateTitle');
?>