With minor modifications it’s easy to prevent having more than one likes or dislikes per user:
In wti_like_post.php, add the following function:
function HasWtiAlreadyVotedValue($post_id, $ip = null) {
global $wpdb;
if (null == $ip) {
$ip = $_SERVER['REMOTE_ADDR'];
}
$wti_like_count = $wpdb->get_var("SELECT SUM(value) FROM {$wpdb->prefix}wti_like_post WHERE post_id = '$post_id' AND ip = '$ip' AND value >= 0 ");
$wti_unlike_count = $wpdb->get_var("SELECT SUM(value) FROM {$wpdb->prefix}wti_like_post WHERE post_id = '$post_id' AND ip = '$ip' AND value <= 0 ");
$wti_like_count = $wti_like_count + $wti_unlike_count;
return $wti_like_count;
}
In wti_like_post_ajax.php, replace the $can_vote section starting on line 60 by:
if ($can_vote) {
$current_user = wp_get_current_user();
$user_id = (int)$current_user->ID;
$voted_value = HasWtiAlreadyVotedValue($post_id, $ip);
$query = "";
if ($task == "like") {
if ($has_already_voted) {
if ($voted_value<1) {
$query = "UPDATE {$wpdb->prefix}wti_like_post SET ";
$query .= "value = value + 1, ";
$query .= "date_time = '" . date('Y-m-d H:i:s') . "' ";
$query .= "WHERE post_id = '" . $post_id . "' AND ";
$query .= "ip = '$ip'";
} else {$msg = __('You already voted Like.', 'wti-like-post'); } // $voted_value E [-1,0,1]
} else {
$query = "INSERT INTO {$wpdb->prefix}wti_like_post SET ";
$query .= "post_id = '" . $post_id . "', ";
$query .= "value = '1', ";
$query .= "date_time = '" . date('Y-m-d H:i:s') . "', ";
$query .= "ip = '$ip'";
}
} else {
if ($has_already_voted) {
if ($voted_value>-1) {
$query = "UPDATE {$wpdb->prefix}wti_like_post SET ";
$query .= "value = value - 1, ";
$query .= "date_time = '" . date('Y-m-d H:i:s') . "' ";
$query .= "WHERE post_id = '" . $post_id . "' AND ";
$query .= "ip = '$ip'";
} else {$msg = __('You already voted Dislike.', 'wti-like-post'); } // $voted_value E [-1,0,1]
} else {
$query = "INSERT INTO {$wpdb->prefix}wti_like_post SET ";
$query .= "post_id = '" . $post_id . "', ";
$query .= "value = '-1', ";
$query .= "date_time = '" . date('Y-m-d H:i:s') . "', ";
$query .= "ip = '$ip'";
}
}
if ($query != "") {
$success = $wpdb->query($query);
if ($success) {
$error = 0;
$msg = get_option('wti_like_post_thank_message');
} else {
$error = 1;
$msg = __('Could not process your vote.', 'wti-like-post');
}
}
}