Author Comment WordPress Plugin

by Terri Ann on October 16, 2007

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!

{ 8 trackbacks }

35 Tips Tricks To Manage and Handle Multi-Author Blogs | Wordpress
November 10, 2008 at 6:15 am
35 Tips Tricks To Manage and Handle Multi-Author Blogs | Web Burning Blog
November 29, 2008 at 3:01 am
Все для блога с несколькими авторами - Запись - Андрей aka Лонгот
December 3, 2008 at 5:38 am
35 Tips Tricks To Manage and Handle Multi-Author Blogs | Quest For News, A TUTORIAL Base
June 27, 2009 at 12:53 pm
21 Great Plugins to Manage Multi-Author Blogs Efficiently | The PhenixbluE
August 29, 2009 at 5:40 pm
微博客 / μBlog » 21个 WordPress 多作者博客精品插件
September 5, 2009 at 5:57 pm
35 Tips Tricks To Manage And Handle Multi-Author Blogs « Photoshop.vn – Your Design Resource
September 8, 2009 at 3:09 am
20 Plugins para administrar um blog com vários autores « Temas e Dicas para Wordpress
December 3, 2009 at 7:41 pm

{ 3 comments… read them below or add one }

1 DoZ January 6, 2008 at 5:55 pm

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)

2 Terri Ann January 7, 2008 at 12:33 pm

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!

3 Wendy February 27, 2009 at 4:11 pm

I sort of stumbled across this while looking for something else but I have a friend who could really use this! Didn’t even know such a thing existed. I’ll direct him over. Thanks! Good stuff. :)

Leave a Comment

Previous post:

Next post: