I'm writing a new plugin that will allow visitor to vote. After a visitor rated a post, I'd like to block double voting. I think the better way to do it is using cookie, but of course I can't insert the code in functions.php or in the theme header. In my case it's better to set cookie via jquery or php?

1 Answer 1


If you are looking for user only comments then you could try this one ( http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie). This function can be replaced via plugins. If plugins do not redefine these functions, then this will be used instead.

Sets the authentication cookies based User ID.

The $remember parameter increases the time that the cookie will be kept. The default the cookie is kept without remembering is two days. When $remember is set, the cookies will be kept for 14 days or two weeks. but this can only be comment by logged in user. Also if you are using by cookie then you have to ask the client to store the cookies permission by accepting it. ( http://wordpress.org/plugins/cookie-law-info/faq/ ) according to cookie law.

I think you could do with the IP address blocking as well. There are couple of plugin available where you can take idea how they have implement. for eg : WP-PostRatings ( Adds an AJAX rating system for your WordPress blog's post/page. ) I guess this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.