WP-Polls - Version 2.75.6

Version Description

Download this release

Release Info

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

Code changes from version 2.75.5 to 2.75.6

Files changed (3) hide show
  1. composer.json +14 -0
  2. readme.txt +44 -3
  3. wp-polls.php +56 -41
composer.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "lesterchan/wp-polls",
3
+ "description": "Adds an AJAX poll system to your WordPress blog.",
4
+ "type": "wordpress-plugin",
5
+ "keywords": ["wordpress", "plugin", "poll"],
6
+ "license": ["GPL-2.0-only"],
7
+ "minimum-stability": "dev",
8
+ "authors": [
9
+ {
10
+ "name": "Lester Chan",
11
+ "email": "lesterchan@gmail.com"
12
+ }
13
+ ]
14
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: GamerZ
3
  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: 5.4
7
- Stable tag: 2.75.5
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
 
@@ -24,8 +24,14 @@ WP-Polls is extremely customizable via templates and css styles and there are to
24
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
25
 
26
  ## Changelog
 
 
 
 
 
 
27
  ### Version 2.75.5
28
- * NEW: New filter for templates: wp_polls_template_resultheader_markup, wp_polls_template_resultbody_markup, wp_polls_template_resultbody2_markup, wp_polls_template_resultfooter_markup, wp_polls_template_resultfooter2_markup. Props @Jaska.
29
 
30
  ### Version 2.75.4
31
  * FIXED: Unable to edit poll because of class-wp-block-parser.php.
@@ -240,3 +246,38 @@ I spent most of my free time creating, updating, maintaining and supporting thes
240
  <?php get_polltime( $poll_id, $date_format ); ?>
241
  <?php endif; ?>
242
  ~~~
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  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: 5.9
7
+ Stable tag: 2.75.6
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
 
24
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
25
 
26
  ## Changelog
27
+
28
+ ### Version 2.75.6
29
+ * NEW: New filter for template variables: wp_polls_template_votebody_variables, wp_polls_template_votefooter, wp_polls_template_resultheader_variables, wp_polls_template_resultbody_variables, wp_polls_template_resultfooter_variables. Props @Liblastic.
30
+ * NEW: composer.json
31
+ * FIXED: Missing space for check_voted_username MySQL query
32
+
33
  ### Version 2.75.5
34
+ * NEW: New filter for templates: wp_polls_template_resultheader_markup, wp_polls_template_resultbody_markup, wp_polls_template_resultbody2_markup, wp_polls_template_resultfooter_markup, wp_polls_template_resultfooter2_markup. Props @Jaska.
35
 
36
  ### Version 2.75.4
37
  * FIXED: Unable to edit poll because of class-wp-block-parser.php.
246
  <?php get_polltime( $poll_id, $date_format ); ?>
247
  <?php endif; ?>
248
  ~~~
249
+
250
+ ### Translating the template
251
+
252
+ The plugin templates can be translated via template variables.
253
+ There are these filters for the custom template variables
254
+ ~~~
255
+ wp_polls_template_votebody_variables
256
+ wp_polls_template_votefooter
257
+ wp_polls_template_resultheader_variables
258
+ wp_polls_template_resultbody_variables
259
+ wp_polls_template_resultfooter_variables
260
+ ~~~
261
+
262
+ Add filter to your theme and register custom variable where you will add your translation.
263
+ Good practice is to name them for example with prefix `STR_` in the example `STR_TOTAL_VOTERS`.
264
+ ~~~
265
+ /**
266
+ * Localize wp_polls_template_resultfooter_variables.
267
+ *
268
+ * @param array $variables An array of template variables.
269
+ * @return array $variables Modified template variables.
270
+ */
271
+ function wp_polls_template_resultfooter_variables( $variables ) {
272
+
273
+ // Add strings.
274
+ $variables['%STR_TOTAL_VOTERS%'] = __( 'Total voters', 'theme-textdomain' );
275
+
276
+ return $variables;
277
+ }
278
+
279
+ // Trigger the filter
280
+ add_filter( 'wp_polls_template_resultfooter_variables', 'wp_polls_template_resultfooter_variables' , 10, 1 );
281
+ ~~~
282
+ In the admin side just call the custom variable like so and the variable has been translated in the front-end.
283
+ `%STR_TOTAL_VOTERS%'`
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.75.5
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
@@ -11,7 +11,7 @@ Text Domain: wp-polls
11
 
12
 
13
  /*
14
- Copyright 2020 Lester Chan (email : lesterchan@gmail.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ Text Domain: wp-polls
29
  */
30
 
31
  ### Version
32
- define( 'WP_POLLS_VERSION', '2.75.5' );
33
 
34
 
35
  ### Create Text Domain For Translations
@@ -395,7 +395,7 @@ function check_voted_username($poll_id) {
395
  $log_expiry = (int) get_option( 'poll_cookielog_expiry' );
396
  $log_expiry_sql = '';
397
  if( $log_expiry > 0 ) {
398
- $log_expiry_sql = 'AND (' . current_time('timestamp') . '-(pollip_timestamp+0)) < ' . $log_expiry;
399
  }
400
  // Check User ID From IP Logging Database
401
  $get_voted_aids = $wpdb->get_col( $wpdb->prepare( "SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_userid = %d", $poll_id, $pollsip_userid ) . $log_expiry_sql );
@@ -445,15 +445,18 @@ function display_pollvote($poll_id, $display_loading = true) {
445
 
446
  $template_question = removeslashes(get_option('poll_template_voteheader'));
447
 
448
- $template_question = apply_filters( 'wp_polls_template_voteheader_markup', $template_question, $poll_question, array(
449
- '%POLL_QUESTION%' => $poll_question_text,
450
- '%POLL_ID%' => $poll_question_id,
451
- '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
452
- '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
453
- '%POLL_START_DATE%' => $poll_start_date,
454
- '%POLL_END_DATE%' => $poll_end_date,
455
- '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
456
- ) );
 
 
 
457
 
458
  // Get Poll Answers Data
459
  list($order_by, $sort_order) = _polls_get_ans_sort();
@@ -479,15 +482,18 @@ function display_pollvote($poll_id, $display_loading = true) {
479
  $poll_multiple_answer_percentage = $poll_question_totalvoters > 0 ? round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 ) : 0;
480
  $template_answer = removeslashes( get_option( 'poll_template_votebody' ) );
481
 
482
- $template_answer = apply_filters( 'wp_polls_template_votebody_markup', $template_answer, $poll_answer, array(
483
- '%POLL_ID%' => $poll_question_id,
484
- '%POLL_ANSWER_ID%' => $poll_answer_id,
485
- '%POLL_ANSWER%' => $poll_answer_text,
486
- '%POLL_ANSWER_VOTES%' => number_format_i18n( $poll_answer_votes ),
487
- '%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage,
488
  '%POLL_MULTIPLE_ANSWER_PERCENTAGE%' => $poll_multiple_answer_percentage,
489
- '%POLL_CHECKBOX_RADIO%' => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
490
- ) );
 
 
 
491
 
492
  // Print Out Voting Form Body Template
493
  $temp_pollvote .= "\t\t$template_answer\n";
@@ -505,13 +511,16 @@ function display_pollvote($poll_id, $display_loading = true) {
505
  // Voting Form Footer Variables
506
  $template_footer = removeslashes(get_option('poll_template_votefooter'));
507
 
508
- $template_footer = apply_filters( 'wp_polls_template_votefooter_markup', $template_footer, $poll_question, array(
509
- '%POLL_ID%' => $poll_question_id,
510
- '%POLL_RESULT_URL%' => $poll_result_url,
511
- '%POLL_START_DATE%' => $poll_start_date,
512
- '%POLL_END_DATE%' => $poll_end_date,
513
  '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
514
- ) );
 
 
 
515
 
516
  // Print Out Voting Form Footer Template
517
  $temp_pollvote .= "\t\t$template_footer\n";
@@ -584,14 +593,15 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
584
  '%POLL_START_DATE%' => $poll_start_date,
585
  '%POLL_END_DATE%' => $poll_end_date
586
  );
587
-
588
- $template_question = apply_filters('wp_polls_template_resultheader_markup', $template_question, $poll_question, $template_variables);
589
-
590
- if($poll_multiple_ans > 0) {
591
- $template_question = str_replace( '%POLL_MULTIPLE_ANS_MAX%', $poll_multiple_ans, $template_question );
592
  } else {
593
- $template_question = str_replace( '%POLL_MULTIPLE_ANS_MAX%', '1', $template_question );
594
  }
 
 
 
 
595
  // Get Poll Answers Data
596
  list( $order_by, $sort_order ) = _polls_get_ans_result_sort();
597
  $poll_answers = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY $order_by $sort_order", $poll_question_id ) );
@@ -645,6 +655,8 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
645
  '%POLL_MULTIPLE_ANSWER_PERCENTAGE%' => $poll_multiple_answer_percentage,
646
  '%POLL_ANSWER_IMAGEWIDTH%' => $poll_answer_imagewidth
647
  );
 
 
648
  // Let User See What Options They Voted
649
  if ( in_array( $poll_answer_id, $user_voted, true ) ) {
650
  // Results Body Variables
@@ -689,18 +701,21 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
689
  '%POLL_LEAST_VOTES%' => number_format_i18n( $poll_least_votes ),
690
  '%POLL_LEAST_PERCENTAGE%' => $poll_least_percentage
691
  );
 
 
 
 
 
 
 
692
  if ( ! empty( $user_voted ) || $poll_question_active === 0 || ! check_allowtovote() ) {
693
  $template_footer = removeslashes( get_option( 'poll_template_resultfooter' ) );
694
- $template_footer = apply_filters('wp_polls_template_resultfooter_markup', $template_footer, $poll_answer, $template_variables);
695
  } else {
696
  $template_footer = removeslashes( get_option( 'poll_template_resultfooter2' ) );
697
- $template_footer = apply_filters('wp_polls_template_resultfooter2_markup', $template_footer, $poll_answer, $template_variables);
698
- }
699
- if ( $poll_multiple_ans > 0 ) {
700
- $template_footer = str_replace( '%POLL_MULTIPLE_ANS_MAX%', $poll_multiple_ans, $template_footer );
701
- } else {
702
- $template_footer = str_replace( '%POLL_MULTIPLE_ANS_MAX%', '1', $template_footer );
703
  }
 
704
  // Print Out Results Footer Template
705
  $temp_pollresult .= "\t\t$template_footer\n";
706
  $temp_pollresult .= "\t\t<input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"".wp_create_nonce('poll_'.$poll_question_id.'-nonce')."\" />\n";
@@ -1344,7 +1359,7 @@ function vote_poll_process($poll_id, $poll_aid_array = [])
1344
  }
1345
 
1346
  if (empty($poll_aid_array)) {
1347
- throw new InvalidArgumentException(sprintf(__('No anwsers given for Poll ID #%s', 'wp-polls'), $poll_id));
1348
  }
1349
 
1350
  if($poll_id === 0) {
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.75.6
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
11
 
12
 
13
  /*
14
+ Copyright 2021 Lester Chan (email : lesterchan@gmail.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
29
  */
30
 
31
  ### Version
32
+ define( 'WP_POLLS_VERSION', '2.75.6' );
33
 
34
 
35
  ### Create Text Domain For Translations
395
  $log_expiry = (int) get_option( 'poll_cookielog_expiry' );
396
  $log_expiry_sql = '';
397
  if( $log_expiry > 0 ) {
398
+ $log_expiry_sql = ' AND (' . current_time('timestamp') . '-(pollip_timestamp+0)) < ' . $log_expiry;
399
  }
400
  // Check User ID From IP Logging Database
401
  $get_voted_aids = $wpdb->get_col( $wpdb->prepare( "SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_userid = %d", $poll_id, $pollsip_userid ) . $log_expiry_sql );
445
 
446
  $template_question = removeslashes(get_option('poll_template_voteheader'));
447
 
448
+ $template_question_variables = array(
449
+ '%POLL_QUESTION%' => $poll_question_text,
450
+ '%POLL_ID%' => $poll_question_id,
451
+ '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
452
+ '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
453
+ '%POLL_START_DATE%' => $poll_start_date,
454
+ '%POLL_END_DATE%' => $poll_end_date,
455
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
456
+ );
457
+ $template_question_variables = apply_filters( 'wp_polls_template_voteheader_variables', $template_question_variables );
458
+ $template_question = apply_filters( 'wp_polls_template_voteheader_markup', $template_question, $poll_question, $template_question_variables );
459
+
460
 
461
  // Get Poll Answers Data
462
  list($order_by, $sort_order) = _polls_get_ans_sort();
482
  $poll_multiple_answer_percentage = $poll_question_totalvoters > 0 ? round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 ) : 0;
483
  $template_answer = removeslashes( get_option( 'poll_template_votebody' ) );
484
 
485
+ $template_answer_variables = array(
486
+ '%POLL_ID%' => $poll_question_id,
487
+ '%POLL_ANSWER_ID%' => $poll_answer_id,
488
+ '%POLL_ANSWER%' => $poll_answer_text,
489
+ '%POLL_ANSWER_VOTES%' => number_format_i18n( $poll_answer_votes ),
490
+ '%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage,
491
  '%POLL_MULTIPLE_ANSWER_PERCENTAGE%' => $poll_multiple_answer_percentage,
492
+ '%POLL_CHECKBOX_RADIO%' => $poll_multiple_ans > 0 ? 'checkbox' : 'radio',
493
+ );
494
+
495
+ $template_answer_variables = apply_filters( 'wp_polls_template_votebody_variables', $template_answer_variables );
496
+ $template_answer = apply_filters( 'wp_polls_template_votebody_markup', $template_answer, $poll_answer, $template_answer_variables );
497
 
498
  // Print Out Voting Form Body Template
499
  $temp_pollvote .= "\t\t$template_answer\n";
511
  // Voting Form Footer Variables
512
  $template_footer = removeslashes(get_option('poll_template_votefooter'));
513
 
514
+ $template_footer_variables = array(
515
+ '%POLL_ID%' => $poll_question_id,
516
+ '%POLL_RESULT_URL%' => $poll_result_url,
517
+ '%POLL_START_DATE%' => $poll_start_date,
518
+ '%POLL_END_DATE%' => $poll_end_date,
519
  '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
520
+ );
521
+
522
+ $template_footer_variables = apply_filters( 'wp_polls_template_votefooter_variables', $template_footer_variables );
523
+ $template_footer = apply_filters( 'wp_polls_template_votefooter_markup', $template_footer, $poll_question, $template_footer_variables );
524
 
525
  // Print Out Voting Form Footer Template
526
  $temp_pollvote .= "\t\t$template_footer\n";
593
  '%POLL_START_DATE%' => $poll_start_date,
594
  '%POLL_END_DATE%' => $poll_end_date
595
  );
596
+ if ( $poll_multiple_ans > 0 ) {
597
+ $template_variables['%POLL_MULTIPLE_ANS_MAX%'] = $poll_multiple_ans;
 
 
 
598
  } else {
599
+ $template_variables['%POLL_MULTIPLE_ANS_MAX%'] = '1';
600
  }
601
+
602
+ $template_variables = apply_filters('wp_polls_template_resultheader_variables', $template_variables );
603
+ $template_question = apply_filters('wp_polls_template_resultheader_markup', $template_question, $poll_question, $template_variables );
604
+
605
  // Get Poll Answers Data
606
  list( $order_by, $sort_order ) = _polls_get_ans_result_sort();
607
  $poll_answers = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY $order_by $sort_order", $poll_question_id ) );
655
  '%POLL_MULTIPLE_ANSWER_PERCENTAGE%' => $poll_multiple_answer_percentage,
656
  '%POLL_ANSWER_IMAGEWIDTH%' => $poll_answer_imagewidth
657
  );
658
+ $template_variables = apply_filters('wp_polls_template_resultbody_variables', $template_variables);
659
+
660
  // Let User See What Options They Voted
661
  if ( in_array( $poll_answer_id, $user_voted, true ) ) {
662
  // Results Body Variables
701
  '%POLL_LEAST_VOTES%' => number_format_i18n( $poll_least_votes ),
702
  '%POLL_LEAST_PERCENTAGE%' => $poll_least_percentage
703
  );
704
+ if ( $poll_multiple_ans > 0 ) {
705
+ $template_variables['%POLL_MULTIPLE_ANS_MAX%'] = $poll_multiple_ans;
706
+ } else {
707
+ $template_variables['%POLL_MULTIPLE_ANS_MAX%'] = '1';
708
+ }
709
+ $template_variables = apply_filters('wp_polls_template_resultfooter_variables', $template_variables );
710
+
711
  if ( ! empty( $user_voted ) || $poll_question_active === 0 || ! check_allowtovote() ) {
712
  $template_footer = removeslashes( get_option( 'poll_template_resultfooter' ) );
713
+ $template_footer = apply_filters('wp_polls_template_resultfooter_markup', $template_footer, $poll_question, $template_variables);
714
  } else {
715
  $template_footer = removeslashes( get_option( 'poll_template_resultfooter2' ) );
716
+ $template_footer = apply_filters('wp_polls_template_resultfooter2_markup', $template_footer, $poll_question, $template_variables);
 
 
 
 
 
717
  }
718
+
719
  // Print Out Results Footer Template
720
  $temp_pollresult .= "\t\t$template_footer\n";
721
  $temp_pollresult .= "\t\t<input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"".wp_create_nonce('poll_'.$poll_question_id.'-nonce')."\" />\n";
1359
  }
1360
 
1361
  if (empty($poll_aid_array)) {
1362
+ throw new InvalidArgumentException(sprintf(__('No answers given for Poll ID #%s', 'wp-polls'), $poll_id));
1363
  }
1364
 
1365
  if($poll_id === 0) {