Unverified Commit 2e25a734 authored by Lester Chan's avatar Lester Chan
Browse files

Use filter to replace variables

parent 2f6396df
......@@ -4,7 +4,7 @@ Donate link: https://lesterchan.net/site/donation/
Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
Requires at least: 4.9.6
Tested up to: 5.0
Stable tag: 2.75.2
Stable tag: 2.75.3
Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
......@@ -24,6 +24,9 @@ WP-Polls is extremely customizable via templates and css styles and there are to
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.
## Changelog
### VErsion 2.75.3
* FIXED: Broken filter for templates
### Versiob 2.75.2
* FIXED: Missing str_replace for wp_polls_template filter
......
......@@ -3,7 +3,7 @@
Plugin Name: WP-Polls
Plugin URI: https://lesterchan.net/portfolio/programming/php/
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.
Version: 2.75.2
Version: 2.75.3
Author: Lester 'GaMerZ' Chan
Author URI: https://lesterchan.net
Text Domain: wp-polls
......@@ -29,7 +29,7 @@ Text Domain: wp-polls
*/
### Version
define( 'WP_POLLS_VERSION', '2.75.2' );
define( 'WP_POLLS_VERSION', '2.75.3' );
### Create Text Domain For Translations
......@@ -406,17 +406,12 @@ function check_voted_username($poll_id) {
}
}
add_filter('poll_template_voteheader_markup', 'poll_template_vote_markup', 10, 3);
add_filter('poll_template_votebody_markup', 'poll_template_vote_markup', 10, 3);
add_filter('poll_template_votefooter_markup', 'poll_template_vote_markup', 10, 3);
add_filter( 'wp_polls_template_voteheader_markup', 'poll_template_vote_markup', 10, 3 );
add_filter( 'wp_polls_template_votebody_markup', 'poll_template_vote_markup', 10, 3 );
add_filter( 'wp_polls_template_votefooter_markup', 'poll_template_vote_markup', 10, 3) ;
function poll_template_vote_markup($template, $poll_db_object, $variables) {
foreach($variables as $placeholder => $value) {
$template = str_replace($placeholder, $value, $template);
}
return $template;
function poll_template_vote_markup( $template, $object, $variables ) {
return str_replace( array_keys( $variables ), array_values( $variables ), $template ) ;
}
......@@ -445,23 +440,15 @@ function display_pollvote($poll_id, $display_loading = true) {
$template_question = removeslashes(get_option('poll_template_voteheader'));
$template_question = apply_filters( 'wp_polls_template_voteheader_markup', str_replace( array(
'%POLL_QUESTION%',
'%POLL_ID%',
'%POLL_TOTALVOTES%',
'%POLL_TOTALVOTERS%',
'%POLL_START_DATE%',
'%POLL_END_DATE%',
'%POLL_MULTIPLE_ANS_MAX%'
), array(
$poll_question_text,
$poll_question_id,
$poll_question_totalvotes,
$poll_question_totalvoters,
$poll_start_date,
$poll_end_date,
$poll_multiple_ans > 0 ? $poll_multiple_ans : 1
), $template_question ) );
$template_question = apply_filters( 'wp_polls_template_voteheader_markup', $template_question, $poll_question, array(
'%POLL_QUESTION%' => $poll_question_text,
'%POLL_ID%' => $poll_question_id,
'%POLL_TOTALVOTES%' => $poll_question_totalvotes,
'%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
'%POLL_START_DATE%' => $poll_start_date,
'%POLL_END_DATE%' => $poll_end_date,
'%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
) );
// Get Poll Answers Data
list($order_by, $sort_order) = _polls_get_ans_sort();
......@@ -487,23 +474,15 @@ function display_pollvote($poll_id, $display_loading = true) {
$poll_multiple_answer_percentage = $poll_question_totalvoters > 0 ? round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 ) : 0;
$template_answer = removeslashes( get_option( 'poll_template_votebody' ) );
$template_answer = apply_filters( 'wp_polls_template_votebody_markup', str_replace( array(
'%POLL_ID%',
'%POLL_ANSWER_ID%',
'%POLL_ANSWER%',
'%POLL_ANSWER_VOTES%',
'%POLL_ANSWER_PERCENTAGE%',
'%POLL_MULTIPLE_ANSWER_PERCENTAGE%' ,
'%POLL_CHECKBOX_RADIO%'
), array(
$poll_question_id,
$poll_answer_id,
$poll_answer_text,
number_format_i18n( $poll_answer_votes ),
$poll_answer_percentage,
$poll_multiple_answer_percentage,
$poll_multiple_ans > 0 ? 'checkbox' : 'radio'
), $template_answer ) );
$template_answer = apply_filters( 'wp_polls_template_votebody_markup', $template_answer, $poll_answer, array(
'%POLL_ID%' => $poll_question_id,
'%POLL_ANSWER_ID%' => $poll_answer_id,
'%POLL_ANSWER%' => $poll_answer_text,
'%POLL_ANSWER_VOTES%' => number_format_i18n( $poll_answer_votes ),
'%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage,
'%POLL_MULTIPLE_ANSWER_PERCENTAGE%' => $poll_multiple_answer_percentage,
'%POLL_CHECKBOX_RADIO%' => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
) );
// Print Out Voting Form Body Template
$temp_pollvote .= "\t\t$template_answer\n";
......@@ -521,19 +500,13 @@ function display_pollvote($poll_id, $display_loading = true) {
// Voting Form Footer Variables
$template_footer = removeslashes(get_option('poll_template_votefooter'));
$template_footer = apply_filters( 'wp_polls_template_votefooter_markup', str_replace( array(
'%POLL_ID%',
'%POLL_RESULT_URL%',
'%POLL_START_DATE%',
'%POLL_END_DATE%',
'%POLL_MULTIPLE_ANS_MAX%'
), array(
$poll_question_id,
$poll_result_url,
$poll_start_date,
$poll_end_date,
$poll_multiple_ans > 0 ? $poll_multiple_ans : 1
), $template_footer ) );
$template_footer = apply_filters( 'wp_polls_template_votefooter_markup', $template_footer, $poll_question, array(
'%POLL_ID%' => $poll_question_id,
'%POLL_RESULT_URL%' => $poll_result_url,
'%POLL_START_DATE%' => $poll_start_date,
'%POLL_END_DATE%' => $poll_end_date,
'%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
) );
// Print Out Voting Form Footer Template
$temp_pollvote .= "\t\t$template_footer\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment