Question

I'm using wp-polls and need to limit the number of votes per IP. Although this is usually set at 1 by default, I need to limit the number of votes per IP to 2.

I've been reading documentation, playing with the plugin code, and looking around on google and SO and can't seem to find the proper method.

  • I've considered using cookies, but these are harder to catch since I could just as well empty my cookies and voilà, it's done.
  • I need a limit because I don't want people to vote endlessly
  • Looking at the database, I imagine this has something to do with the pollip_ip field (from the (prefix)_pollsip) table, but not being familiar with editing WP Plugins, this is as far I as I got to go.

As a reference, here is some failed code

wp-polls.php, line 1323

// original code
// if($check_voted == 0) { 


// proposed by @birgire
if( $check_voted == 0 || ( is_array( $check_voted ) && 2 >= count( $check_voted ) ) ) {

wp-polls.php, line 1323

// original code
// if($check_voted == 0) { 


// alternative of code proposed by @birgire
if( ($check_voted == 0) || count($check_voted) <= 2)
Was it helpful?

Solution

I couldn't see any available filters for this, when I skimmed through the plugin source.

I wonder if it would work, if you replace line #1323 of the wp-polls.php file:

 if($check_voted == 0) {

with:

 if( $check_voted == 0 
     || ( is_array( $check_voted ) && 2 >= count( $check_voted ) ) ) {

to limit the number of votes per IP to 2.

Additionally:

Replace line #140 with:

if( !is_array($check_voted) && intval($check_voted) > 0  
     || (is_array($check_voted) && sizeof($check_voted) > 1)
     || ($poll_active == 0 && $poll_close == 1)) {

But I don't recommend in general to modify plugin files, since it will be restored in the next plugin update.

Sidenote: The plugin is not using the recommended $wpdb->prepare() when preparing the SQL for $wpdb->query().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top