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?
- Login to your blog, like you are going to write a new entry.
- Go to the users tab
- 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
- Necessity, the greatest inspiration of all
- 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:
- How to Style WordPress Author Comments - Accomplished the idea of different responses but I don't like the idea of using email addresses when you have an id readily accessible.
- How to Style Author Comments Differently - Also accomplishes accounting for multiple authors, but doesn't provide a solid solution for distinguishing between each. Again it uses email addresses instead of a user id.
- How to: Style Author Comments in Wordpress - Very simple and accounts only for one instance of an author's name and email address matching.
- I've always wanted to develop a plugin that was useful and in new territory!
Popularity: 44% [?]
the newest discoveries, stories and shared tips!Come on, all the cool kids are doing it ;)



Great plugin, very useful! ...but you really have to check your sample line: it's very-very buggy!! here how it should be:
ciao!
Edited by Terri @ 1/7/08 2:42pm to fix the way the code the commenter was communicating. (Wordpress over formatted)