KB Plugins

The best Wordpress plugins are free

FYI, this is the blog archives you're looking at, not the most recent posts.

Back to KB Plugins main page

Print this post

For developers: The WP hooks database

If you’re a plugin developer, you know how difficult it can be to figure out which hooks are available. This WordPress hooks database automatically scans each WP build for apply_filters() and do_action() to figure out exactly which hooks are available in each version.

WordPress hooks database

What is this good for?

  • See what new hooks are available with each new version of WordPress
  • See which hooks have been deprecated (use the “view all hooks” option)
  • Easily learn exactly which WP file(s) use each hook. That way, if the hook is poorly documented, you can just look in the source and figure out what it does.

What is this not good for?

The goal is not to explain what each hook does, but rather to list which are available in each version. If you just want to know what a hook does, check out the official action reference and filter reference , as well as the information at flat earth .

That being said, you’ll notice that those sites fail to include all the hooks. When that’s the case, find the hook here. This site will tell you where in the WP source the hook is applied, making it easy for you to figure out what it does on your own.

Print this post

I’m Feeling Lucky!

In response to this thread on the WP forums, here’s a little plugin to improve WP’s search. If there’s only one result, it will redirect your visitor to it automatically rather than display a search results page. (This is sort of like Google’s “I’m Feeling Lucky” feature, but it autodetects whether to redirect.)

Paste the code into a file, give it a filename ending with .php, upload and activate.

Note that this code works fine in WP 2.3+, but for earlier versions, use v1.01 of the plugin, available here.

<?php
/*
Plugin Name: KB I'm Feeling Lucky
Plugin URI: http://adambrown.info/b/widgets/category/kb-im-feeling-lucky/
Description: If there's only one search result, redirect to it rather than displaying the results page.
Author: Adam R. Brown
Author URI: http://adambrown.info/
Version: 1.0
*/

// To use: Upload to your plugins folder and activate!

function kb_feelingLucky(){
	if (!is_search())
		return;
	global $wp_query;
	if (1 != $wp_query->post_count)
		return;

	// so get_permalink will work:
	the_post();

	// redirection:
	header("Location: " . get_permalink() ); // will work in most cases, but just in case, let's also use a JS redirect:
	echo '
		<html>
			<head>
				<title>Redirecting...</title>
			</head>
			<body>
				<script type="text/javascript"><!–
				window.location = "'.get_permalink().'";
				// –>
				</script>
				<h2>Oops!</h2>
				<h3>You must be using a non-javascript browser.</h3>
				<p>To find the article you searched for, go <a href="'.get_permalink().'">here</a>.</p>
			</body>
		</html>
	';
	die();
}

// makes it work:
add_action('wp','kb_feelingLucky');


?>

Enjoy.

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');
?>
Print this post

New and improved: KB Advanced RSS v 2.0

I uploaded a new, rewritten version of the KB Advanced RSS widget to the wordpress plugins repository today. Features:

  • New options for trimming and formatting elements
  • Better handling of the pubdate field
  • Easier to customize with your own code

Download it here

Check out the updated instructions and FAQ over at WP.org (follow the download link). Although the old syntax will still work, I’ve made a few changes.

Print this post

Wavatars - Plugin of the Year

I’ve just installed the spankin’-new wavatars plugin, and it has my vote for plugin of the year.

Wavatars are an extension of the gravatars concept, but a dramatic improvement. So here’s the backstory:

In the bad old days, if you wanted to put an image (an “avatar”) next to your comments on somebody’s blog, you would have to upload your avatar to that blog. You would have to repeat this process at every blog you visited. As such, avatars were a major pain in the rear, so nobody supported them on their blog.

Then, gravatars came along, with a simple concept: When people comment at your blog, they leave an email address–why not convert that email address into an image? That way, you can just upload an image of your choice to gravatar.com , and whenever you post a comment on any gravatar-enabled blog (like this one), your avatar will show up automatically.

Gravatars were an awesome concept, and they’ve been slowly catching on for the past several months, especially since automattic bought gravatar.com . If you look through comments on this blog, you’ll see that between 25% and 50% of my commenters have created gravatars for themselves.

But turn that math around, and you’ll see the problem with gravatars: Between 50% and 75% of my commenters don’t have a gravatar. So instead of a little picture next to their comment, they get the default gravatar, which is booorrring.

Solution: Wavatars. If you don’t have a gravatar, no problem: The wavatars plugin will convert your email address into a randomly generated avatar. It’s easy to tell wavatars from gravatars on my blog–the wavatars are the cartoony-looking polygons with faces.

What I want to see next: I’d like to see the gravatar folks purchase the wavatars concept and implement it by default. That way, we would need only gravatars and not need the wavatars plugin. This has several benefits. These are the biggies:

  • Gravatars get served from gravatar.com’s fast servers; wavatars, on the other hand, use up my server’s bandwidth
  • Gravatars are cached on gravatar.com’s servers; wavatars get cached on my server, using up my storage space

Plus, if wavatars were offered by gravatar.com, they could have several different “theme” packs of wavatars that website owners could choose from.

So, how about it, gravatar.com?

Print this post

Download KB Backtick Comments

If you want your blog’s commenters to be able to paste code into their comments, go download KB Backtick Comments .

Print this post

Download KB Survey

KB Survey is now available for download over at the WP.org repository.

Download KB Survey

Print this post

Some Problems

Having problems with my server, so I went back from PHP 5 to PHP 4 as a temporary fix. As such, the demos on some of my plugins are down now. If you encounter any PHP errors around my site, please let me know.

« Earlier Entries Later Entries »