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 comment_is_author($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!

This site runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

{ 4 comments }

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
Twitter:
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. :)

4 Rasel Rony
Twitter:
March 7, 2012 at 2:05 am

really awesome plugin, thanks for the plugin

Comments on this entry are closed.

{ 16 trackbacks }

Previous post:

Next post: