get_setting('show_results', $global['show_results'] ?? 'after_vote'); if (!in_array($show_results, array('after_vote', 'always', 'never'), true)) { $show_results = 'after_vote'; } if (isset($atts['show_voters']) && $atts['show_voters'] !== '') { $show_voters = ($atts['show_voters'] === 'yes'); } else { $show_voters = (bool) $poll->get_setting('show_voters_count', $global['show_voters_count'] ?? true); } $theme = !empty($atts['theme']) ? $atts['theme'] : $poll->get_setting('theme', $global['theme'] ?? 'default'); if (!in_array($theme, array('default', 'minimal', 'rounded', 'square', 'pill'), true)) { $theme = 'default'; } $dark_mode = !empty($atts['dark_mode']) ? $atts['dark_mode'] : $poll->get_setting('dark_mode', $global['dark_mode'] ?? 'no'); if (!in_array($dark_mode, array('auto', 'yes', 'no'), true)) { $dark_mode = 'no'; } $bar_color = sanitize_hex_color($poll->get_style('bar_color', '')) ?: sanitize_hex_color($global['results_bar_color'] ?? ''); $bar_bg = sanitize_hex_color($global['results_bar_bg'] ?? ''); $animation = ($global['animation'] ?? 'grow') === 'none' ? 'none' : 'grow'; return compact('show_results', 'show_voters', 'theme', 'dark_mode', 'bar_color', 'bar_bg', 'animation'); } /** * Whether results may be shown to the current visitor. * * @param TPoll_Poll $poll Poll. * @param string $show_results after_vote, always or never. * @param bool $has_voted Visitor has voted. */ public static function results_visible($poll, $show_results, $has_voted) { if ($show_results === 'never') { return false; } if ($show_results === 'always' || $poll->is_closed()) { return true; } return $has_voted; } /** * Render shortcode */ public function render($atts) { $atts = shortcode_atts(array( 'id' => 0, 'show_results' => '', // after_vote, always, never (empty = use poll setting) 'show_voters' => '', // yes, no (empty = use poll setting) 'theme' => '', // (empty = use poll setting) 'dark_mode' => '' // auto, yes, no (empty = use poll setting) ), $atts, 'tpoll'); $poll_id = absint($atts['id']); if (!$poll_id) { return ''; } $poll = TPoll_Poll::get($poll_id); if (!$poll) { return ''; } if ($poll->status === 'draft' && !current_user_can('edit_tpoll')) { return ''; } wp_enqueue_style('tpoll-frontend'); wp_enqueue_script('tpoll-frontend'); $opt = self::display_options($poll, $atts); $restriction = $poll->get_setting('vote_restriction', 'ip'); $is_closed = $poll->is_closed(); $is_upcoming = !$is_closed && $poll->is_upcoming(); $needs_login = ($restriction === 'user' && !is_user_logged_in()); $show_form = !$is_closed && !$is_upcoming && $poll->status !== 'draft'; $show_results_now = self::results_visible($poll, $opt['show_results'], false); $classes = array( 'tpoll-poll', 'tpoll-type-' . $poll->type, 'tpoll-theme-' . $opt['theme'], ); if ($opt['dark_mode'] === 'yes') { $classes[] = 'tpoll-dark'; } elseif ($opt['dark_mode'] === 'auto') { $classes[] = 'tpoll-dark-auto'; } if ($opt['animation'] === 'none') { $classes[] = 'tpoll-no-animation'; } $style = ''; if ($opt['bar_color']) { $style .= '--tpoll-bar:' . $opt['bar_color'] . ';'; } if ($opt['bar_bg']) { $style .= '--tpoll-bar-bg:' . $opt['bar_bg'] . ';'; } $question_id = 'tpoll-q-' . $poll_id; ob_start(); ?>
style=""> question)) : ?>
question); ?>
start_date)) { printf( /* translators: %s: date and time the poll opens */ esc_html__('This poll opens on %s', '3task-polls'), esc_html(mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $poll->start_date)) ); } else { esc_html_e('This poll is not open yet.', '3task-polls'); } ?>
render_poll_form($poll, $question_id, $show_results_now); ?>
>
get_answers(); if ($poll->get_setting('randomize_answers', false)) { shuffle($answers); } ?>
type) { case 'single': $this->render_single_choice($poll, $answers, $question_id); break; case 'multiple': $this->render_multiple_choice($poll, $answers, $question_id); break; case 'rating': $this->render_rating($poll, $answers, $question_id); break; case 'voting': $this->render_voting($poll, $answers, $question_id, $show_counts); break; } ?> type, array('rating', 'voting'), true)) : ?>
get_setting('max_choices', 0); ?>
data-max-choices="">

id, $poll); if ($results) { $up = (string) $results['up']; $down = (string) $results['down']; } } $answer = isset($answers[0]) ? $answers[0] : null; ?>
type === 'voting') : ?>
type === 'rating') : ?>
 %
type === 'multiple') : ?>