### Handling the Event: Mark the Post as Read

Let's go ahead and write the code that will send the ID of the post across. We'll worry about the response later in this article, hence the "TODO" comment in the code.

At this point in development, the full JavaScript source should look like this:

For those of you who have been working through the example code as you've read the article, you'll immediately notice that your browser throws a console error:

Uncaught ReferenceError: ajaxurl is not defined

Oops! And this is where we need to make sure to properly include WordPress' Ajax library.

### Including WordPress' Ajax Library on the Frontend

To do this, we'll need to hook into the wp_head action. Add the following line of code in the constructor of your plugin:

Next, add the following function. This is what's actually responsible for including the Ajax library:

Now, if you try to execute the code, you should have no problem. At this point, we're ready to keep going.

### Handle the Event: Mark the Post as Read

Now that we've got the request being sent to the server, we can write our server-side event handler. This is how the handler should operate:

• Check that the incoming Post ID value is set and that it's a numeric value (this is very rudimentary spoof protection, but it works for all intents and purposes).
• Next, try to update the current user's meta using his/her ID and the post ID.
• If the update fails, we'll return -1; otherwise, we'll return 1. We'll handle these values in the response handler in the JavaScript.

First, we'll add the hook in the constructor of the plugin:

Next, we'll actually implement the handler:

To that end, let's revisit the outstanding TODO in the response function of the JavaScript that we were working on. Here's the full script:

### One More Change

If the user happens to find their way to an individual post page (such as being linked to it), we should check to see if they've previously marked it to be read.

To do this, we need to refactor the add_checkbox function so that it checks to see if the user is logged in and it reads the user meta to determine if the post has been previously marked as read:

### See It in Action!

At this point, you've got a working plugin:

• You should be able to navigate to any post
• If you've not read it, then you should be able to click on the checkbox and have it disappear
• If you reload the page, then you'll see the notification that the post has been marked as read.