Author Comment WordPress Plugin


I just completed my very first official WordPress Plugin that I am going to release to the public. It requires that the authors login to the blog before they leave comments to have the appropriate style applies.

commentisauthor

The Comment Author plugin is a simple one, it just involves one function that takes 3 parameters, 2 of which are optional.

Description

mixed comment_is_author ( int $id [, mixed $output[, bool $echo]] )

Usage

You'll always want to call the function isauthorcomment inside the comment loop, and pass $comment->user_id as the first parameter.

Minimal use

comment_is_author($comment->user_id);
// prints 'author' if registered commenter

Will print 'author' to the page if the commenter is a registered user in that WordPress installation.

Change what it outputs for any author

comment_is_author($comment->user_id, 'Registered Blog Author');
// prints 'Registered Blog Author' if registered commenter

Will print 'Registered Blog Author' to the page if the commenter is a registered user in that WordPress installation.

Custom response for authors: If you have multiple blog authors, and want to return a response for people who are not registered to the blog you'll send an array as the second parameter.

comment_is_author($comment->user_id, array(0=>'visitor',1=>'blog author #1',3='blog author #3'));
// prints 'visitor' if not a registered commenter
// prints 'blog author #1' if registered commenter #1
// prints 'blog author #3' if registered commenter #3
// prints nothing for any other registered commenters

Will print 'visitor' to the page if the commenter is not a registered user in that WordPress installation.
Will print 'blog author #1' to the page if the commenter is the registered user in that WordPress installation with an id of 1.
Will print 'blog author #3' to the page if the commenter is the registered user in that WordPress installation with an id of 3.
If the commenter is the registered user in that WordPress installation with an id of 2, 4 or higher not will print anything to the page.

Make sense?

And the third parameter $echo will change whether the response is returned or printed to screen. This is for advanced users whom have seen, and most likely used, this sort of behavior in the WordPress application before.

Here's a code sample of how I would use it in the loop applying a class to a div:

<div class="<?php commentisauthor($comment->user_id, array(0=>'visitor',1=>'admin',2='terri'));">[...]</div>

And use this in the stylesheet:

div.terri{
    background-color:#66CCCC;
}
div.admin{
    background-color:#99CC66;
}
div.visitor{
    background-color:#CC99CC;
}

Need to know how to find a registered user id?

  1. Login to your blog, like you are going to write a new entry.
  2. Go to the users tab
  3. Use the number in the id column to match up with registered users

Download

Changelog

  • 1.0 - Created & released (October 16, 2007)

Requirements

  • Tested on WordPress 2.3

Installation

Check out the WordPress documentation on Installing Plugins.

Inspired by

  1. Necessity, the greatest inspiration of all
  2. I couldn't find any plugin that accomplished this easily. I did find a bunch of template code samples but they seemed to over complicate the template:
  3. I've always wanted to develop a plugin that was useful and in new territory!

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Similar Entries
Using Wordpress as a CMS
I've now got some tutorials prepped and ready to be published and initially I had intended on putting them as part of www.ninedays.org which will soon be my portfolio, but blog.ninedays.org has really turned into a good home for my more personal than professional content. I really think my tutorials fall under that category. So if they
Clipboard Express WordPress Plugin
Clipboard Express is a multi-user clipboard plugin for WordPress. It allows each user a place to privately store notes, links code snippets and other information they need to have easy access to when logged into WordPress.
Ninedays Is Getting a Makeover
A quick little lesson about how to test a new theme in WordPress and perfect it for your use without making it live to the public. Best part is: you don't have to install a new copy of WordPress!
Block Content and Detect Wordpress Preview
Need to block tracking scripts in your WordPress Template when you preview your entries. I have just the way! Just a few lines into your functions.php file and header/footers and you can block Mint or Analytics in WordPress previews.
Feed Image Wordpress Plugin
My Wordpress plugin to add a main image to your Wordpress generated RSS2 and Atom feed.
Next Post
Smoothie Photo Shoot
Previous Post
Things I can do Tomorrow…

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Great plugin, very useful! ...but you really have to check your sample line: it's very-very buggy!! here how it should be:

<div class="user_id, array(0=>'visitor',1=>'admin',2=>'terri'));?>">

ciao!

Edited by Terri @ 1/7/08 2:42pm to fix the way the code the commenter was communicating. (Wordpress over formatted)

Thanks so much DoZ, I hadn't realized I made that mistake (twice actually) in the sample and explanatory code. It has been update. I appreciate you pointing that out, I feel silly for not spotting that earlier!