WP-Polls - Version 2.77.0

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Polls
Version 2.77.0
Comparing to
See all releases

Code changes from version 2.76.0 to 2.77.0

Files changed (2) hide show
  1. readme.txt +4 -4
  2. wp-polls.php +43 -5
readme.txt CHANGED
@@ -4,16 +4,13 @@ Donate link: https://lesterchan.net/site/donation/
4
  Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
5
  Requires at least: 4.9.6
6
  Tested up to: 6.0
7
- Stable tag: 2.76.0
8
 
9
  Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
10
 
11
  ## Description
12
  WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers.
13
 
14
- ### Build Status
15
- [![Build Status](https://travis-ci.org/lesterchan/wp-polls.svg?branch=master)](https://travis-ci.org/lesterchan/wp-polls)
16
-
17
  ### Development
18
  [https://github.com/lesterchan/wp-polls](https://github.com/lesterchan/wp-polls "https://github.com/lesterchan/wp-polls")
19
 
@@ -25,6 +22,9 @@ I spent most of my free time creating, updating, maintaining and supporting thes
25
 
26
  ## Changelog
27
 
 
 
 
28
  ### Version 2.76.0
29
  * NEW: Supports specifying which header to read the user's IP from. Props Marc Montpas.
30
 
4
  Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
5
  Requires at least: 4.9.6
6
  Tested up to: 6.0
7
+ Stable tag: 2.77.0
8
 
9
  Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
10
 
11
  ## Description
12
  WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers.
13
 
 
 
 
14
  ### Development
15
  [https://github.com/lesterchan/wp-polls](https://github.com/lesterchan/wp-polls "https://github.com/lesterchan/wp-polls")
16
 
22
 
23
  ## Changelog
24
 
25
+ ### Version 2.77.0
26
+ * NEW: Use mutex lock to prevent race condition.
27
+
28
  ### Version 2.76.0
29
  * NEW: Supports specifying which header to read the user's IP from. Props Marc Montpas.
30
 
wp-polls.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-Polls
4
  Plugin URI: https://lesterchan.net/portfolio/programming/php/
5
  Description: Adds an AJAX poll system to your WordPress blog. You can easily include a poll into your WordPress's blog post/page. WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers.
6
- Version: 2.76.0
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
@@ -29,7 +29,7 @@ Text Domain: wp-polls
29
  */
30
 
31
  ### Version
32
- define( 'WP_POLLS_VERSION', '2.76.0' );
33
 
34
 
35
  ### Create Text Domain For Translations
@@ -1347,11 +1347,16 @@ function in_pollarchive() {
1347
  return true;
1348
  }
1349
 
1350
- function vote_poll_process($poll_id, $poll_aid_array = [])
1351
- {
1352
  global $wpdb, $user_identity, $user_ID;
1353
 
1354
- do_action('wp_polls_vote_poll');
 
 
 
 
 
 
1355
 
1356
  $polla_aids = $wpdb->get_col( $wpdb->prepare( "SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = %d", $poll_id ) );
1357
  $is_real = count( array_intersect( $poll_aid_array, $polla_aids ) ) === count( $poll_aid_array );
@@ -1447,6 +1452,10 @@ function vote_poll_process($poll_id, $poll_aid_array = [])
1447
  );
1448
  }
1449
  }
 
 
 
 
1450
  do_action( 'wp_polls_vote_poll_success' );
1451
 
1452
  return display_pollresult($poll_id, $poll_aid_array, false);
@@ -1637,6 +1646,35 @@ function manage_poll() {
1637
  }
1638
  }
1639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1640
 
1641
  function _polls_get_ans_sort() {
1642
  $order_by = get_option( 'poll_ans_sortby' );
3
  Plugin Name: WP-Polls
4
  Plugin URI: https://lesterchan.net/portfolio/programming/php/
5
  Description: Adds an AJAX poll system to your WordPress blog. You can easily include a poll into your WordPress's blog post/page. WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers.
6
+ Version: 2.77.0
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
29
  */
30
 
31
  ### Version
32
+ define( 'WP_POLLS_VERSION', '2.77.0' );
33
 
34
 
35
  ### Create Text Domain For Translations
1347
  return true;
1348
  }
1349
 
1350
+ function vote_poll_process( $poll_id, $poll_aid_array = [] ) {
 
1351
  global $wpdb, $user_identity, $user_ID;
1352
 
1353
+ do_action( 'wp_polls_vote_poll' );
1354
+
1355
+ // Acquire lock
1356
+ $fp_lock = polls_acquire_lock( $poll_id );
1357
+ if ( $fp_lock === false ) {
1358
+ throw new InvalidArgumentException( sprintf( __( 'Unable to obtain lock for Poll ID #%s', 'wp-polls'), $poll_id ) );
1359
+ }
1360
 
1361
  $polla_aids = $wpdb->get_col( $wpdb->prepare( "SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = %d", $poll_id ) );
1362
  $is_real = count( array_intersect( $poll_aid_array, $polla_aids ) ) === count( $poll_aid_array );
1452
  );
1453
  }
1454
  }
1455
+
1456
+ // Release lock
1457
+ polls_release_lock( $fp_lock, $poll_id );
1458
+
1459
  do_action( 'wp_polls_vote_poll_success' );
1460
 
1461
  return display_pollresult($poll_id, $poll_aid_array, false);
1646
  }
1647
  }
1648
 
1649
+ function polls_acquire_lock( $poll_id ) {
1650
+ $fp = fopen( polls_lock_file( $poll_id ), 'w+' );
1651
+
1652
+ if ( ! flock( $fp, LOCK_EX | LOCK_NB ) ) {
1653
+ return false;
1654
+ }
1655
+
1656
+ ftruncate( $fp, 0 );
1657
+ fwrite( $fp, microtime( true ) );
1658
+
1659
+ return $fp;
1660
+ }
1661
+
1662
+ function polls_release_lock( $fp, $poll_id ) {
1663
+ if ( is_resource( $fp ) ) {
1664
+ fflush( $fp );
1665
+ flock( $fp, LOCK_UN );
1666
+ fclose( $fp );
1667
+ unlink( polls_lock_file( $poll_id ) );
1668
+
1669
+ return true;
1670
+ }
1671
+
1672
+ return false;
1673
+ }
1674
+
1675
+ function polls_lock_file( $poll_id ) {
1676
+ return apply_filters( 'wp_polls_lock_file', get_temp_dir() . '/wp-polls-' . $poll_id . '.lock', $poll_id );
1677
+ }
1678
 
1679
  function _polls_get_ans_sort() {
1680
  $order_by = get_option( 'poll_ans_sortby' );