145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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

682 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Provided great contribution to our forums
  • Has been a beta tester for an Envato feature
+4 more
Gareth_Gillman says
145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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
  • Has referred 100+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+2 more
PixelBook says

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

682 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Provided great contribution to our forums
  • Has been a beta tester for an Envato feature
+4 more
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.

1485 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
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
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

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

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

1485 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
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.
3451 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

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

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

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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