tommcfarlin / ive-read-this Goto Github PK
View Code? Open in Web Editor NEW[Retired-WordPress-Envato] A simple plugin used to demonstrate how to use Ajax on the frontend of WordPress
[Retired-WordPress-Envato] A simple plugin used to demonstrate how to use Ajax on the frontend of WordPress
Hi, that Plugin is exactly what i need.
I installed it and activated it.
But if i check the checkbox, nothing happens. And if i refresh the Post the checkbox is again unchecked.
would be really happy if you could provide some small support...
Hi, I'm trying to add another Checkbox, that calls the php func mark_as_unread. But can't get it work properly.
(function ($) {
$(function () {
// If the "I've Read This Container" is on this page, let's setup the event handler
if(1 === $('#ive-read-this-container').length) {
// We use the change attribute so that the event handler fires
// whenever the checkbox or its associated label is clicked.
$('input[name="ive-read-this"]').change(function (evt) {
alert("markiere als gelesen.");
// We can retrieve the ID of this post from the <article>'s ID. This will be required
// so that we can mark that the user has read this particular post and we can hide it.
var sArticleId, iPostId;
// Get the article ID and split it - the second index is always the post ID in twentyeleven
sArticleId = $("article").attr('id');
iPostId = parseInt(sArticleId.split('-')[1]);
// Initial the request to mark this this particular post as read
$.post(ajaxurl, {
action: 'mark_as_read',
post_id: iPostId
}, function (response) {
console.log(response);
// If the server returns '1', then we can mark this post as read, so we'll hide the checkbox
// container. Next time the user browses the index, this post won't appear
if (1 === parseInt(response)) {
$('#ive-read-this-container').slideUp('fast');
// Otherwise, let's alert the user that there was a problem. In a larger environment, we'd
// want to handle this more gracefully.
} else {
alert("There was an error marking this post as read. Please try again.");
} // end if/else
});
});
// We use the change attribute so that the event handler fires
// whenever the checkbox or its associated label is clicked.
$('input[name="unread"]').change(function (evt) {
alert("markiere als ungelesen.");
// We can retrieve the ID of this post from the <article>'s ID. This will be required
// so that we can mark that the user has read this particular post and we can hide it.
var sArticleId, iPostId;
// Get the article ID and split it - the second index is always the post ID in twentyeleven
sArticleId = $("article").attr('id');
iPostId = parseInt(sArticleId.split('-')[1]);
// Initial the request to mark this this particular post as unread
$.post(ajaxurl, {
action: 'mark_as_unread',
post_id: iPostId
}, function (response) {
console.log(response);
// If the server returns '1', then we can mark this post as read, so we'll hide the checkbox
// container. Next time the user browses the index, this post won't appear
if (1 === parseInt(response)) {
$('#ive-read-this-container').slideUp('fast');
// Otherwise, let's alert the user that there was a problem. In a larger environment, we'd
// want to handle this more gracefully.
} else {
alert("There was an error marking this post as unread. Please try again.");
} // end if/else
});
});
} // end if
});
}(jQuery));
public function mark_as_unread() {
// First, we need to make sure the post ID parameter has been set and that's it's a numeric value
if( isset( $_POST['post_id'] ) && is_numeric( $_POST['post_id'] ) ) {
// If we fail to update the user meta, respond with -1; otherwise, respond with 1.
echo false == update_user_meta( wp_get_current_user()->ID, $_POST['post_id'], 'ive_unread_this' ) ? "-1" : "1";
} // end if
die();
} // end mark_as_unread
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.