WordPress Plugin: Mark as Read

For the first time ever I created my own plugin. Starting out as a hacking attempt, it quickly changed into a prototype plugin.

What it basically does is list the articles that haven’t been read yet by a logged in user. Whenever a change to the post is made or a new comment is posted, the post moves to the top of the unread list.

WordPress Plugin: Mark as Read

Download Get the plugin!

Functionality:

Mark as Read makes it easy for your users to keep track of changes on your blog. Whenever a post is published or updated the post will show up in this list. When a new comment is posted, the post will also go up in this list and will be marked as “unread”.

Features:

  • Keeps track of which articles a logged in user has read.
  • Posts bump on new comments
  • Posts bump on published / updates
  • Customizable output
  • Lists per category or all categories
  • Usable non-output functions

Installation:

  1. Download the plugin
  2. Upload contents of the zip-archive (the folder) to the plugin directory of your WordPress installation (default: wp-content/plugins/)
  3. Enable the plugin through the plugin admin panel
  4. Paste code inside template file
  5. Enjoy!

Usage:

To output the list all you need to do is to put the following code inside a template file of your theme:

<ul>
    <?php the_unread_posts(); ?>
</ul>

This will output all the unread content of all categories.

The following parameters are accepted:

the_unread_posts($categoryID, $noPostsMessage, $updateText, $rowStyle);

$categoryID (Optional, default: "all"):
Supply this parameter if you want to show unread messages from one category only. Give the string "all" if you want to display all categories.

$noPostsMessage (Optional, default: "<li>No unread posts</li>"):
Sets the output of an empty list.

$updateText (Optional, default: array("New comment(s) and changes", "Changes", "New comment(s)")):
Sets the output of the different types. Give an array with 3 values; first one being the output when a post has new comments and is updated, second for updates only and third for new comments only.

$rowStyle (Optional, default: "<li><a href='%link%'>%type% on: %title%</a></li>"):
The HTML in which each post has to be shown. Use %link% to insert a permalink to the post, %title% for the post title and %type% for the type of change.

Liked this article? Sharing is caring!

21 Comments on this subject

  1. hopefullytammy said:

    Hi Gaya,

    I think your plugin might be incompatible with the current version of WordPress? Or am I doing something wrong? I did a fresh install of WP 2.8.2 (latest as of today) but I keep getting these errors:

    Warning: Missing argument 2 for comment_not_read() in /home/mysite/public_html/wp/wp-content/plugins/mark-as-read/storage.php on line 31

    Warning: Cannot modify header information – headers already sent by (output started at /home/mysite/public_html/wp/wp-content/plugins/mark-as-read/storage.php:31) in /home/mysite/public_html/wp/wp-includes/pluggable.php on line 865

    I get this error regardless of whether or not is pasted into the theme.

    Looking at the code in storage.php, the offending variable seems to be $approved:

    //insert the post that has not been read with COMMENT type, will be fired after a comment post
    function comment_not_read($comment_id, $approved) {
    $comment = get_comment($comment_id);

    insert_not_read($comment->comment_post_ID, “comment”);
    }

    Let me know if you have any ideas on this. Thank you!

  2. hopefullytammy said:

    OK, in mark-as-read.php, I changed this line:
    add_action(“comment_post”, “comment_not_read”);

    to this:
    add_action(“comment_post”, “comment_not_read”, 10, 2);

    And that gets rid of the error message. (this fix was based on http://wordpress.org/support/topic/298291)

    However, I noticed that unapproved comments still show up as “unread” even though they are not live on the site.

    Maybe my change caused that? Or (more likely) it was like that before?

  3. Pikkio said:

    awesome plugin!! thanx!

    i have only 2 question2:
    1) can i set it up to get only the new comments displayed and not the post’s changes?

    2) it’s possible to set a maximum number of news displayed?

  4. dai dai hua said:

    Site visitors Mayhem Review- the content on this write-up is definitely a single of probably the most effective substance that i?ve in fact are obtainable throughout. I genuinely like your post, I’ll are accessible once more to verify for new posts.

  5. Mark said:

    Any chance you could get this to work with rolescoper? It should be relatively easy… Rolescoper just allows an administrator to set user access certain posts. It turns out, that all members have the unread notifier, but cannot click the link to clear since they cannot link the page. I’d like the user to only have unread comments/posts if they have access to the posts in a particular category. Here’s the line to get the list of categories a user is allowed to access (taken from RoleScoper website):

    $cat_ids = get_terms( ‘category’, array( ‘fields’ => ‘ids’ ) );

  6. Jonathan said:

    Just a suggestion, it would be really great to be able to define a category to EXCLUDE from displaying. Or even multiple. I have certain posts that only exist to go into a content slider, or that exist to be pulled into other things and are not meant to actually be seen as posts. I can give these all a category of “hidden” and as long as I can select to exclude that category from the unread plugin, then I’m home free and they won’t show up in the list.

    Jonathan

  7. Jonathan said:

    Can’t figure out why this plugin is returning only 5 results no matter what. I don’t see any limit in the code anywhere, yet that’s all I ever get – the last 5 unread updates.

    Is there still any active support for this?

  8. Suraj said:

    Hey Jonathan, I just encountered the same problem. It’s because the wordpress function get_posts() automatically pulls the first 5 posts. Change this in the functions.php: add ‘numberposts’ => 100, or whatever you need.

  9. Jeff said:

    I installed 0.9 of the plugin and the menu option under Settings is not showing up. Has anyone experienced this and found a solution?

    I do have the plugin working fine on another site (i.e. menu option shows).

    Thanks!

Leave your reply

Your email address will not be published. Avatars through Gravatar.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>