WP Plugin: Official Comments

I just whipped up a quick WordPress 1.2/1.5/2.0 plugin that allows you to distinguish comments made by WordPress users. It also will automatically approve comments made by WP users.

Current Version: 1.1

How It Works:
If you are logged into your WordPress admin panel, and you make a comment, the plugin will see that you are an official WP user of your blog and mark the comment with your WP User ID.
When the page is rendered, that User ID is called up by the plugin functions, which you can use to change text, change CSS class, add images, whatever your imagination desires.

Installation
Either:

  • RECOMMENDED: Install WordPress Plugin Manager then use the One Click Install for Official Comments. This will also make it easier to install other plugins and upgrade them in the future.
  • OR: Download Official Comments, extract and upload official-comments.php to your wp-content/plugins directory. Log-in to your WP admin panel, go to the Plugins tab and activate the Official Comments plugin.

How to implement:
Simply add this somewhere within the Comments loop in wp-comments.php and/or wp-comments-popup.php:

<?php if(is_wpuser_comment() != 0) {echo "Official ";} ?>

Or get tricky and add a CSS Class to the LI:

<li class="comment <?php echo (is_wpuser_comment() ? ' commentOfficialUser' : ''); ?>" id="comment-<?php comment_ID() ?>">

and this very basic css example:

.commentOfficialUser { border: 1px solid black; background-color: #999999 }

Documentation
View Official Comments Readme.txt

Examples
There is a very basic example on this post, but more exciting examples available at Webfroot.

Known Issues
It only works with official comments made after the point of installation, as WordPress doesn’t automatically add the WP user ids to the comments field it already has.

Bugs and Suggestions
Any bugs or suggestions, please email me — email link in the sidebar (RSS readers: drop by the site 😉 ).

159 thoughts on “WP Plugin: Official Comments

  1. Webfroot » Official Comments plugin

    […] Blogs Hacking   I just whipped up my first public WordPress plugin, called Official Comments. It helps you display comments made by logged-in WordPre […]

  2. Geekpulp » Gotta love the plugins

    […] h all of the cool plugins people make for them. I was reading on inner.geek.nz about a new wordpress comments plugin that Glutnix (aka Brett Taylor) has made. As qui […]

  3. Webfroot » WordPress Plugin: Smart Unread Comments

    […] riting the original functionality – he deserves full credit! Oh and by the way, our Official Comments plugin is also now one-click install compatible! […]

  4. This is a Non-Official Comment

  5. This is an Official Comment!

  6. superporcel

    Hey looks great :), i have to try it. Sorry for my english, i’m spanish 😉

  7. superporcel

    Official Comments
    Official Comments es un plugin para WordPress, creado por Brett Taylor, que distingue los comentarios hechos por personas registradas en nuestro blog, dandole un aspecto diferente a ese comentario.

    La verdad no sirve de mucho si no permitimos que la…

  8. Geekpulp

    Gotta love the plugins
    One of the best things about having a wordpress blog is getting to play with all of the cool plugins people make for them. I was reading on inner.geek.nz about a new wordpress comments plugin that Glutnix (aka Brett Taylor) has made. As quite rightly …

  9. tec

    hiya. was wondering if this works with the Spam Karma plugin (or any other anti-spam plugins) since i saw this line in your code:

    $approved = 1; // change to 0 to put WP user’s comments in the comment moderation queue.

  10. Tec, Sorry I don’t know, because I’ve never used the Spam Karma plugin. Best to try it and tell the world if it doesn’t…

  11. Yup, it works with Spam Karma too 🙂

  12. m » Blog Archive » WordPress First Impressions

    […] , and it’s totally free. I’ve already added several plugins: Spell Checking Official Comments Plugin Manager and I turned Markdown on The next tasks […]

  13. Williams Blog » WP Plugin: Official Comments

    […]

    WP Plugin: Official Comments
    I’m thinking of adding this plugin (WP Plugin: Official Comments, by Brentt Taylor) to my site. I’m also […]

  14. Willful Exposé

    I always have terrible trouble with comment-related plugins that require me to put some line in the comment loop; I can never seem to find the right spot. Can anyone tell me where I should put the php line in my comments loop? I haven’t modified anything much, and I’d be very grateful. Thanks!

  15. If you’re changing the class, you put the php code inside the class attribute of the li tag
    eg in bold: <li class="<?php echo $oddcomment; ?><?php echo (is_wpuser_comment() ? ' commentOfficialUser' : ''); ?>" id="comment-<?php comment_ID() ?>">
    Of course, my blogware is applying true quotes to stuff inside <code>, so make sure you don’t just copy/paste from here.

  16. Glutnix

    let me be ur valentine

  17. You see, my plugin prevents that kind of attempt 🙂

  18. Willful Expose'

    I love the way it works, but actions speak louder than words: It’s installed in my favorite skins.

  19. Philosophy Of

    WordPress Plugins

    I’ve finally got around to doing a list of the plugins I’ve installed for WordPress.

    The WordPress Plugin Database, with a full list of WordPress Plugins can be found here.

    I personally had no problem installing any of them, so if you have had …

  20. Standing Tall » Blog Archive » WordPress プラグイン一覧追加情報(8)

    […] ¨ãŒã§ãã‚‹ã€‚昇格したコメントは昇格した時間順にリストされる。 Official Comments – オフィシャルコメント (ダウロード)( […]

  21. Ennis

    wheres the alignment for the image in your official comments??

  22. Ennis

    I have used your plugin, thanks its great.
    One small question. how would i code in the css to have the word “Says” in white when and only when i the administrator makes a comment.
    Its in this line of the comments.php
    [code]” id=”comment-&lt?php comment_ID() ?>”>
    “> Says: [/code]

  23. Mark

    I can’t seem to get this plug-in working. I’ve done the one-click install and am trying to find exactly where to put the code in to make this work. I’m assuming this is the code to be using:

    I’m using the WP 1.5 “default” theme and I’m assuming that in the admin panel, going into “Presentation > Theme Editor > Comments Template (or Pop-Up Comments Template)” is where I’m supposed to be. I can’t seem to find where to stick the code. Admittedly, I’m new to WordPress and am not sure where to stick this code.

    Could somebody let me know if I’m looking in the right files, and if so, help me find the right place to stick this in.

  24. You could add the user’s name to the name of the class, eg .OfficialCommentAdmin { } which would look more like this:


    <li class="<?php echo (is_wpuser_comment() ? ' CommentOfficial'.comment_wpusername() : ''); ?>" id=”comment-">

    This would work with anyone’s username, and you could set up a different class for each user. Of course, this is assuming there are no spaces in any of your usernames.

  25. First, put a space between alt and admin-comments, and both .alt and .admin-comments will be applied.

    If still .admin-comments is being overridden by .alt, then you’ll want to make .admin-comments more specific. A quick fire way to do this is

    html .admin-comments { ... }

    But you could just try specifying a tag somewhere between html and the li, and it might achieve the same thing.

  26. swim

    completley unrelated, I apologize.
    I’m trying to figure out how to get comments allways shown as they are here on this page… and unlike this page for example: http://binarybonsai.com/playground/
    where you see none of the comments.
    thanks so much
    joshua

  27. swim: If you note that the comments page for that post is: http://binarybonsai.com/playground/index.php?p=1#comments

    And note how index.php suddenly comes into view. That means that http://binarybonsai.com/playground/ is a the root page of the blog.

    If you want your WP blog’s root page to show comments for that post, that’s a very good question… I dunno how I’d do that… Maybe you’d need some kind of plugin that would redirect to the latest post’s permalink?

  28. BeerLuver

    Trying to impliment this into my friend’s blog site I put up for her, but it’s not working. Maybe I’m not putting it in the right section. I wanna impliment the CSS version you have. Any tips on where I should input it into this bit of code:

    to “”

    " title="Visit ">
    comment_author_email); ?>" alt="Get your own gravatar at gravatar.com" class="gravatar" />

    "> " title="Visit ">

    " title=""># ,

  29. BeerLuver

    Crap that didn’t work heh…. here’s the code saved in a txt file:

    http://www.mindwiped.com/temp69/code.txt

    Could ya take a look at that and fill me in on where you think I should put the code for this to work? Thanks in advance if you can 😉

  30. BeerLuver: I took a look at your comments code, and it doesn’t look like you’re putting your comments in s… You need to make sure you’re generating valid XHTML, which it doesn’t look like you are..
    Here’s what I’m doing here on inner.geek: /images/comments.phps

    KarlBedingfield: I’ll assume that those three things you have there are the usernames of the users on your blog. I’ll also assume each comment in it’s own <li></li>. Here’s what you want:

    <li class="<?php echo $oddcomment; ?> <?php if(is_wpuser_comment() != 0) { echo " officialUserComment OfficialUser_".comment_wpusername(); } ?>" id="comment-<?php comment_ID() ?>">

    So, that will generate something like this:

    <li class="alt officialUserComment officialUser_kb" id="comment-1234">

    All three classes will get applied to the li. So to style them, you can create classes like this:

    .officialUserComment {...}
    li.officialUser_kb {...}
    li.officialUser_jg {...}
    li.officialUser_cc {...}

    .officialUserComment would probably have everything that would be the same across the official user classes, and then you might just change the background color for each user.

    Hope that helps!

  31. Brett

    Don’t know, can’t read your code; it got munged when you submitted it… — you’ll need to either properly turn all < into &lt; and the same with > and &gt;… OR post a link a text file containing your source hosted somewhere…

    a .phps (php source) file is good if your server supports PHP — mmm formatted text… for example: /images/comments.phps

  32. Brett

    OR I could just scroll up, look at my code and see that there’s an extra if( in it… i’ve updated my comment, use the code from there… o_O;

  33. beej

    Great plugin! Just wondering if there was a way to specify a generic image for non-registered users/commenters?

  34. Brett

    Beej, write css for normal comments that displays an image, and then write css for the official comment that overrides the normal comment.

  35. empdesign » Blog Archive » Plugins Wp

    […] ecimales y ASCII. Útil para evitar bots en busca de direcciones de correo que spamear. […]

  36. eduardo

    Nice plugin, thanks. May i offer 3 improvement suggestions? First, instead of pre-aproving all users’ comments, you could make it aprove comments by users with a level greater than X and/or with id numbers Y and Z (and make that configurable in an option in the admin area). Second, there could be a way to have a separate class for each user based on his id and/or level number on the blog, that would make the comments appearence even more cofigurable. Third, isn’t there a way to mark old comments too?
    Weel, i’m full of ideas but i know zero PHP, so i’m left with suggesting…

  37. Karl Bedingfield

    Hi there,

    I am back again.

    I just noticed that all my non-admin comment posts are showing up as ‘alt’

    Is there anything wrong in the code you very kindly supplied me?

    Here is is: http://phpfi.com/62371

    Thanks
    Karl

  38. Brett

    Unrelated to my code, but it’ seems to be this code:
    <?php /* Changes every other comment to a different class */
    if ('alt' == $oddcomment) $oddcomment = '';
    else $oddcomment = 'alt ';
    ?>

    if ('alt' == needs to be if 'alt ' ==, it needs that space.

  39. Karl Bedingfield

    OOPs sorry to trouble you and thanks for the heads up 🙂

  40. James Turnbull’s shreddies.org » Blog Archive » Wordpress Plugins

    […] al. Paged Comment Editing – Makes reading all the comments in the admin area a bit easier. Official Comments – It turns out that a lot of people are called ‘Jam […]

  41. Marya

    Hi! I loved this plugin and really would like to use it, but I’m having a bit of trouble. My default comments already have a specific css, so when the author comment css is added it doesn’t show.

    Is there any way to set the code so when it’s a comment of mine it shows, for example, a blue background (like class=autorcomment), and someone else’s comment (class=visitorcomment) a green background?
    Thanks!

  42. Brett

    Marya, what I would do is make your .authorcomment more specific, by tacking html in front of it:

    html .authorcomment {...}

    That way, it will override the .visitorcomment

  43. Marya

    Thanks for your help Brett! I managed to have the author highlight colors to show up, but still they mix with the default colours of the comment, since the html for the official comment is like this:

    Comment


    Is there any way to show only

    Comment


    when it’s an official comment, and only

    Comment


    when it’s a visitor comment? I believe I’ve seen a coding like this before, but still haven’t found out a way to “separate” both css…
    Thanks again!

  44. Marya

    I’m sorry, the coding didn’t show up… They were supposed to look like this:

    Comment

    Comment

    Comment

  45. Brett

    Yeah, HTML is stripped unless it’s a safe tag as mentioned above the comment box. Convert your angle brackets to < and >, and put it all in a <code></code> tag and then submit it as a comment, then we can communicate.

    Alternatively, feel free to contact me via email or an instant messaging system — details on the Contact Me page.

  46. David Russell

    Brett, I don’t know about anyone else but your ‘known issue’ (the plugin only working on posts after it’s installed) hasn’t affected me- I just installed it and its working for all my previous posts.

  47. stream of thoughts » themes

    […]

    It’s just a try. How do you like this one? I also added a few plugins: Official Comments PhotoPress plugin Theme Switcher WP ShortStat Man, […]

  48. Peter / savek

    I have used your plugin, thanks its great.
    Greetings form Koszalin in Poland 🙂

  49. Koen

    Nice work. Please keep them coming.

  50. Ensporet planleggingsblogg » Blog Archive » Publiseringssystem

    […] r. – IP til land – greit Ã¥ kunne bruke til Ã¥ vise flagg fra hvor leseren befinner seg. – Offisiell kommentering – Noe sÃ¥nt kunne vært brukt for kommentarer av fra […]

Comments are closed.