145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

Hello,

I use this Ajax Like/Dislike Script: http://www.phpkobo.com/ajax_likes.php My users can register to my wordpress blog and now it would be great if every registered user can vote only once (i already realised that unregistered user don’t see the like/dislike script).

Is there an easy way / script to realize that?

thank you

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says
145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

but every cookie can be deleted by the user, right? My idea was to save variables for every post and user and just show him the like/dislike poll if the logged in user hasn’t already voted

101 posts
  • Elite Author
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
PixelBook says

the most convenient way is to use post meta and store the names of the users (or their ids) in an array

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Well you can do with PHP / WP

In the header.php, set a variable e.g.

$can_vote = '1';

Before the HTML for the vote, check the variable:

<?php
if($variable == '1') {
 // display vote
} else {
 // already voted
}
?>

Now, the fun part, create a new user field in WP and set the default to be 1

When they have voted, you need to change the variable to 0 (or something else, and also edit the user field to be the same.

The WP codex will show up ways to create user fields, but it’s not the simplest and cleanest method to do this.

1401 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

I have done that in WordPress some time ago when I was developing a 9GAG theme for wp, I solved it like this:

In user meta, stor array of post IDs user liked/disliked In post meta, store number of likes

$On init:

Get array of post IDs user liked/disliked, compare them in the loop with the id of the post and apply proper styling

$On like click:

Get post ID, compare it to the user liked/disliked array-s:

$$If user already liked: take away one like from post meta, take away post ID from liked array in user meta, apply proper styling

$$If user already disliked: add two points to post meta ( one for removing unlike and one for adding like ), add post id to user meta liked array, remove post id from user meta disliked id

$$If user did not like/dislike: add post id to user meta liked array, add one like to post meta

$On dislike click:

Get post ID, compare it to the user liked/disliked array-s:

$$If user already liked: remove two points from post meta (one for new dislike and one for like removal), remove post id from user meta liked array, add post id to user meta disliked array

$$If user already disliked: add one point to post meta, remove post id from user meta disliked array

$$If user did not like/dislike: remove one point from post meta, add post id to user meta disliek array

Sorry for this sausage :P

145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

ok thank you. my php skills are not so good.

do you know a specific tutorial? I haven’t found any.

1401 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

ok thank you. my php skills are not so good. do you know a specific tutorial? I haven’t found any.
Unfortunately no, sorry, I did not follow the tutorial, I only used the knowledge I had + logic.
3365 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+4 more
sevenspark Volunteer moderator says

@gareth, you should be using booleans or integers, not strings.

@loveless, why not just use a plugin like zilla Likes?

145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

Zilla Likes also just uses Cookies to prevent double-votes. Users just have to delete cookies to vote again.

I now want to use a facebook/twitter login plugin http://www.sociable.es/facebook-connect-wordpress-plugin-screenshots/

Users have to login with their facebook/twitter account to see the voting.

But does anyone know a detailed instruction on how to realize that every facebook/twitter account can vote only once? The HTML-Code that displays the Vote-Button could just disappear if this fb/tw account has already voted.

would be great. thank you guys.

by
by
by
by
by
by