Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author webtechideas

    (@webtechideas)

    Sorry this is not a problem rather you are allowing to vote multiple times. Please use the plugin settings to set how many times a user can vote.

    You can only dislike a post after the voting period has passed. Lets say you have set the voting period to 1 day and now just you have voted. Then after 1 day you can revote. If you want to dislike, then you can dislike then.

    Thanks

    Thread Starter prashanta92

    (@prashanta92)

    thanks for the quick response but i need that when someone liked a post he can dislike it whenever he choose to. the user should cast only 1 vote, but can like and only after that he can unlike(if he wants to vote again he has to like or unlike the post first)

    Plugin Author webtechideas

    (@webtechideas)

    This is not possible with the way this plugin is coded.

    Thread Starter prashanta92

    (@prashanta92)

    ok thanks

    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');
    		        }
    			}
    		}

    Just got the same issue. Is it fixed?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘infinite voting’ is closed to new replies.